[1] | 1 | // Copyright (c) Athena Dev Teams - Licensed under GNU GPL |
---|
| 2 | // For more information, see LICENCE in the main folder |
---|
| 3 | |
---|
| 4 | #include "../common/cbasetypes.h" |
---|
| 5 | #include "../common/mmo.h" |
---|
| 6 | #include "../common/malloc.h" |
---|
| 7 | #include "../common/socket.h" |
---|
| 8 | #include "../common/db.h" |
---|
| 9 | #include "../common/lock.h" |
---|
| 10 | #include "../common/showmsg.h" |
---|
| 11 | #include "../common/strlib.h" |
---|
| 12 | #include "char.h" |
---|
| 13 | #include "inter.h" |
---|
| 14 | #include "int_storage.h" |
---|
| 15 | #include "int_guild.h" |
---|
| 16 | |
---|
| 17 | #include <string.h> |
---|
| 18 | #include <stdio.h> |
---|
| 19 | #include <stdlib.h> |
---|
| 20 | |
---|
| 21 | char guild_txt[1024] = "save/guild.txt"; |
---|
| 22 | char castle_txt[1024] = "save/castle.txt"; |
---|
| 23 | |
---|
| 24 | #ifndef TXT_SQL_CONVERT |
---|
| 25 | static DBMap* guild_db; // int guild_id -> struct guild* |
---|
| 26 | static DBMap* castle_db; // int castle_id -> struct guild_castle* |
---|
| 27 | |
---|
| 28 | static int guild_newid = 10000; |
---|
| 29 | |
---|
| 30 | static unsigned int guild_exp[100]; |
---|
| 31 | |
---|
| 32 | int mapif_guild_broken(int guild_id, int flag); |
---|
| 33 | static bool guild_check_empty(struct guild *g); |
---|
| 34 | int guild_calcinfo(struct guild *g); |
---|
| 35 | int mapif_guild_basicinfochanged(int guild_id, int type, const void *data, int len); |
---|
| 36 | int mapif_guild_info(int fd, struct guild *g); |
---|
| 37 | int guild_break_sub(DBKey key, void *data, va_list ap); |
---|
| 38 | |
---|
| 39 | /// serializes the guild data structure into the provided string |
---|
| 40 | int inter_guild_tostr(char* str, struct guild* g) |
---|
| 41 | { |
---|
| 42 | int i, c, len; |
---|
| 43 | |
---|
| 44 | // save guild base info |
---|
| 45 | len = sprintf(str, "%d\t%s\t%s\t%d,%d,%u,%d,%d\t%s#\t%s#\t", |
---|
| 46 | g->guild_id, g->name, g->master, g->guild_lv, g->max_member, g->exp, g->skill_point, 0, g->mes1, g->mes2); |
---|
| 47 | |
---|
| 48 | // save guild member info |
---|
| 49 | for(i = 0; i < g->max_member; i++) |
---|
| 50 | { |
---|
| 51 | struct guild_member *m = &g->member[i]; |
---|
| 52 | len += sprintf(str + len, "%d,%d,%d,%d,%d,%d,%d,%u,%d,%d\t%s\t", |
---|
| 53 | m->account_id, m->char_id, |
---|
| 54 | m->hair, m->hair_color, m->gender, |
---|
| 55 | m->class_, m->lv, m->exp, m->exp_payper, m->position, |
---|
| 56 | ((m->account_id > 0) ? m->name : "-")); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | // save guild position info |
---|
| 60 | for(i = 0; i < MAX_GUILDPOSITION; i++) { |
---|
| 61 | struct guild_position *p = &g->position[i]; |
---|
| 62 | len += sprintf(str + len, "%d,%d\t%s#\t", p->mode, p->exp_mode, p->name); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | // save guild emblem |
---|
| 66 | len += sprintf(str + len, "%d,%d,", g->emblem_len, g->emblem_id); |
---|
| 67 | for(i = 0; i < g->emblem_len; i++) { |
---|
| 68 | len += sprintf(str + len, "%02x", (unsigned char)(g->emblem_data[i])); |
---|
| 69 | } |
---|
| 70 | len += sprintf(str + len, "$\t"); |
---|
| 71 | |
---|
| 72 | // save guild alliance info |
---|
| 73 | c = 0; |
---|
| 74 | for(i = 0; i < MAX_GUILDALLIANCE; i++) |
---|
| 75 | if (g->alliance[i].guild_id > 0) |
---|
| 76 | c++; |
---|
| 77 | len += sprintf(str + len, "%d\t", c); |
---|
| 78 | for(i = 0; i < MAX_GUILDALLIANCE; i++) { |
---|
| 79 | struct guild_alliance *a = &g->alliance[i]; |
---|
| 80 | if (a->guild_id > 0) |
---|
| 81 | len += sprintf(str + len, "%d,%d\t%s\t", a->guild_id, a->opposition, a->name); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | // save guild expulsion info |
---|
| 85 | c = 0; |
---|
| 86 | for(i = 0; i < MAX_GUILDEXPULSION; i++) |
---|
| 87 | if (g->expulsion[i].account_id > 0) |
---|
| 88 | c++; |
---|
| 89 | len += sprintf(str + len, "%d\t", c); |
---|
| 90 | for(i = 0; i < MAX_GUILDEXPULSION; i++) { |
---|
| 91 | struct guild_expulsion *e = &g->expulsion[i]; |
---|
| 92 | if (e->account_id > 0) |
---|
| 93 | len += sprintf(str + len, "%d,%d,%d,%d\t%s\t%s\t%s#\t", |
---|
| 94 | e->account_id, 0, 0, 0, e->name, "#", e->mes ); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | // save guild skill info |
---|
| 98 | for(i = 0; i < MAX_GUILDSKILL; i++) { |
---|
| 99 | len += sprintf(str + len, "%d,%d ", g->skill[i].id, g->skill[i].lv); |
---|
| 100 | } |
---|
| 101 | len += sprintf(str + len, "\t"); |
---|
| 102 | |
---|
| 103 | return 0; |
---|
| 104 | } |
---|
| 105 | #endif //TXT_SQL_CONVERT |
---|
| 106 | |
---|
| 107 | /// parses the guild data string into a guild data structure |
---|
| 108 | int inter_guild_fromstr(char* str, struct guild* g) |
---|
| 109 | { |
---|
| 110 | int i, c; |
---|
| 111 | char *pstr; |
---|
| 112 | |
---|
| 113 | memset(g, 0, sizeof(struct guild)); |
---|
| 114 | |
---|
| 115 | {// load guild base info |
---|
| 116 | int guildid; |
---|
| 117 | char name[256]; // only 24 used |
---|
| 118 | char master[256]; // only 24 used |
---|
| 119 | int guildlv; |
---|
| 120 | int max_member; |
---|
| 121 | unsigned int exp; |
---|
| 122 | int skpoint; |
---|
| 123 | char mes1[256]; // only 60 used |
---|
| 124 | char mes2[256]; // only 120 used |
---|
| 125 | int len; |
---|
| 126 | |
---|
| 127 | if( sscanf(str, "%d\t%[^\t]\t%[^\t]\t%d,%d,%u,%d,%*d\t%[^\t]\t%[^\t]\t%n", |
---|
| 128 | &guildid, name, master, &guildlv, &max_member, &exp, &skpoint, mes1, mes2, &len) < 9 ) |
---|
| 129 | return 1; |
---|
| 130 | |
---|
| 131 | // remove '#' |
---|
| 132 | mes1[strlen(mes1)-1] = '\0'; |
---|
| 133 | mes2[strlen(mes2)-1] = '\0'; |
---|
| 134 | |
---|
| 135 | g->guild_id = guildid; |
---|
| 136 | g->guild_lv = guildlv; |
---|
| 137 | g->max_member = max_member; |
---|
| 138 | g->exp = exp; |
---|
| 139 | g->skill_point = skpoint; |
---|
| 140 | safestrncpy(g->name, name, sizeof(g->name)); |
---|
| 141 | safestrncpy(g->master, master, sizeof(g->master)); |
---|
| 142 | safestrncpy(g->mes1, mes1, sizeof(g->mes1)); |
---|
| 143 | safestrncpy(g->mes2, mes2, sizeof(g->mes2)); |
---|
| 144 | |
---|
| 145 | str+= len; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | {// load guild member info |
---|
| 149 | int accountid; |
---|
| 150 | int charid; |
---|
| 151 | int hair, hair_color, gender; |
---|
| 152 | int class_, lv; |
---|
| 153 | unsigned int exp; |
---|
| 154 | int exp_payper; |
---|
| 155 | int position; |
---|
| 156 | char name[256]; // only 24 used |
---|
| 157 | int len; |
---|
| 158 | int i; |
---|
| 159 | |
---|
| 160 | for( i = 0; i < g->max_member; i++ ) |
---|
| 161 | { |
---|
| 162 | struct guild_member* m = &g->member[i]; |
---|
| 163 | if (sscanf(str, "%d,%d,%d,%d,%d,%d,%d,%u,%d,%d\t%[^\t]\t%n", |
---|
| 164 | &accountid, &charid, &hair, &hair_color, &gender, |
---|
| 165 | &class_, &lv, &exp, &exp_payper, &position, |
---|
| 166 | name, &len) < 11) |
---|
| 167 | return 1; |
---|
| 168 | |
---|
| 169 | m->account_id = accountid; |
---|
| 170 | m->char_id = charid; |
---|
| 171 | m->hair = hair; |
---|
| 172 | m->hair_color = hair_color; |
---|
| 173 | m->gender = gender; |
---|
| 174 | m->class_ = class_; |
---|
| 175 | m->lv = lv; |
---|
| 176 | m->exp = exp; |
---|
| 177 | m->exp_payper = exp_payper; |
---|
| 178 | m->position = position; |
---|
| 179 | safestrncpy(m->name, name, NAME_LENGTH); |
---|
| 180 | |
---|
| 181 | str+= len; |
---|
| 182 | } |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | {// load guild position info |
---|
| 186 | int mode, exp_mode; |
---|
| 187 | char name[256]; // only 24 used |
---|
| 188 | int len; |
---|
| 189 | int i = 0; |
---|
| 190 | int j; |
---|
| 191 | |
---|
| 192 | while (sscanf(str, "%d,%d%n", &mode, &exp_mode, &j) == 2 && str[j] == '\t') |
---|
| 193 | { |
---|
| 194 | struct guild_position *p = &g->position[i]; |
---|
| 195 | if (sscanf(str, "%d,%d\t%[^\t]\t%n", &mode, &exp_mode, name, &len) < 3) |
---|
| 196 | return 1; |
---|
| 197 | |
---|
| 198 | p->mode = mode; |
---|
| 199 | p->exp_mode = exp_mode; |
---|
| 200 | name[strlen(name)-1] = 0; |
---|
| 201 | safestrncpy(p->name, name, NAME_LENGTH); |
---|
| 202 | |
---|
| 203 | i++; |
---|
| 204 | str+= len; |
---|
| 205 | } |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | {// load guild emblem |
---|
| 209 | int emblemlen; |
---|
| 210 | int emblemid; |
---|
| 211 | char emblem[4096]; |
---|
| 212 | int len; |
---|
| 213 | |
---|
| 214 | emblemid = 0; |
---|
| 215 | if( sscanf(str, "%d,%d,%[^\t]\t%n", &emblemlen, &emblemid, emblem, &len) < 3 ) |
---|
| 216 | if( sscanf(str, "%d,%[^\t]\t%n", &emblemlen, emblem, &len) < 2 ) //! pre-svn format |
---|
| 217 | return 1; |
---|
| 218 | |
---|
| 219 | g->emblem_len = emblemlen; |
---|
| 220 | g->emblem_id = emblemid; |
---|
| 221 | for(i = 0, pstr = emblem; i < g->emblem_len; i++, pstr += 2) { |
---|
| 222 | int c1 = pstr[0], c2 = pstr[1], x1 = 0, x2 = 0; |
---|
| 223 | if (c1 >= '0' && c1 <= '9') x1 = c1 - '0'; |
---|
| 224 | if (c1 >= 'a' && c1 <= 'f') x1 = c1 - 'a' + 10; |
---|
| 225 | if (c1 >= 'A' && c1 <= 'F') x1 = c1 - 'A' + 10; |
---|
| 226 | if (c2 >= '0' && c2 <= '9') x2 = c2 - '0'; |
---|
| 227 | if (c2 >= 'a' && c2 <= 'f') x2 = c2 - 'a' + 10; |
---|
| 228 | if (c2 >= 'A' && c2 <= 'F') x2 = c2 - 'A' + 10; |
---|
| 229 | g->emblem_data[i] = (x1<<4) | x2; |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | str+= len; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | {// load guild alliance info |
---|
| 236 | int guildid; |
---|
| 237 | int opposition; |
---|
| 238 | char name[256]; // only 24 used |
---|
| 239 | int len; |
---|
| 240 | |
---|
| 241 | if (sscanf(str, "%d\t%n", &c, &len) < 1) |
---|
| 242 | return 1; |
---|
| 243 | str+= len; |
---|
| 244 | |
---|
| 245 | for(i = 0; i < c; i++) |
---|
| 246 | { |
---|
| 247 | struct guild_alliance* a = &g->alliance[i]; |
---|
| 248 | if (sscanf(str, "%d,%d\t%[^\t]\t%n", &guildid, &opposition, name, &len) < 3) |
---|
| 249 | return 1; |
---|
| 250 | |
---|
| 251 | a->guild_id = guildid; |
---|
| 252 | a->opposition = opposition; |
---|
| 253 | safestrncpy(a->name, name, NAME_LENGTH); |
---|
| 254 | |
---|
| 255 | str+= len; |
---|
| 256 | } |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | {// load guild expulsion info |
---|
| 260 | int accountid; |
---|
| 261 | char name[256]; // only 24 used |
---|
| 262 | char message[256]; // only 40 used |
---|
| 263 | int len; |
---|
| 264 | int i; |
---|
| 265 | |
---|
| 266 | if (sscanf(str, "%d\t%n", &c, &len) < 1) |
---|
| 267 | return 1; |
---|
| 268 | str+= len; |
---|
| 269 | |
---|
| 270 | for(i = 0; i < c; i++) |
---|
| 271 | { |
---|
| 272 | struct guild_expulsion *e = &g->expulsion[i]; |
---|
| 273 | if (sscanf(str, "%d,%*d,%*d,%*d\t%[^\t]\t%*[^\t]\t%[^\t]\t%n", &accountid, name, message, &len) < 3) |
---|
| 274 | return 1; |
---|
| 275 | |
---|
| 276 | e->account_id = accountid; |
---|
| 277 | safestrncpy(e->name, name, sizeof(e->name)); |
---|
| 278 | message[strlen(message)-1] = 0; // remove '#' |
---|
| 279 | safestrncpy(e->mes, message, sizeof(e->mes)); |
---|
| 280 | |
---|
| 281 | str+= len; |
---|
| 282 | } |
---|
| 283 | } |
---|
| 284 | |
---|
| 285 | {// load guild skill info |
---|
| 286 | int skillid; |
---|
| 287 | int skilllv; |
---|
| 288 | int len; |
---|
| 289 | int i; |
---|
| 290 | |
---|
| 291 | for(i = 0; i < MAX_GUILDSKILL; i++) |
---|
| 292 | { |
---|
| 293 | if (sscanf(str, "%d,%d %n", &skillid, &skilllv, &len) < 2) |
---|
| 294 | break; |
---|
| 295 | g->skill[i].id = skillid; |
---|
| 296 | g->skill[i].lv = skilllv; |
---|
| 297 | |
---|
| 298 | str+= len; |
---|
| 299 | } |
---|
| 300 | str = strchr(str, '\t'); |
---|
| 301 | } |
---|
| 302 | |
---|
| 303 | return 0; |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | #ifndef TXT_SQL_CONVERT |
---|
| 307 | // Mhéf[^̶ñÖÌÏ· |
---|
| 308 | int inter_guildcastle_tostr(char *str, struct guild_castle *gc) |
---|
| 309 | { |
---|
| 310 | int len; |
---|
| 311 | |
---|
| 312 | len = sprintf(str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", |
---|
| 313 | gc->castle_id, gc->guild_id, gc->economy, gc->defense, gc->triggerE, |
---|
| 314 | gc->triggerD, gc->nextTime, gc->payTime, gc->createTime, gc->visibleC, |
---|
| 315 | gc->guardian[0].visible, gc->guardian[1].visible, gc->guardian[2].visible, gc->guardian[3].visible, |
---|
| 316 | gc->guardian[4].visible, gc->guardian[5].visible, gc->guardian[6].visible, gc->guardian[7].visible); |
---|
| 317 | |
---|
| 318 | return 0; |
---|
| 319 | } |
---|
| 320 | #endif ///TXT_SQL_CONVERT |
---|
| 321 | |
---|
| 322 | // Mhéf[^̶ñ©çÌÏ· |
---|
| 323 | int inter_guildcastle_fromstr(char *str, struct guild_castle *gc) |
---|
| 324 | { |
---|
| 325 | int castleid, guildid, economy, defense, triggerE, triggerD, nextTime, payTime, createTime, visibleC; |
---|
| 326 | int guardian[8]; |
---|
| 327 | int dummy; |
---|
| 328 | |
---|
| 329 | memset(gc, 0, sizeof(struct guild_castle)); |
---|
| 330 | // structure of guild castle with the guardian hp included |
---|
| 331 | if( sscanf(str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", |
---|
| 332 | &castleid, &guildid, &economy, &defense, &triggerE, &triggerD, &nextTime, &payTime, &createTime, &visibleC, |
---|
| 333 | &guardian[0], &guardian[1], &guardian[2], &guardian[3], &guardian[4], &guardian[5], &guardian[6], &guardian[7], |
---|
| 334 | &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) != 26 ) |
---|
| 335 | // structure of guild castle without the hps (current one) |
---|
| 336 | if( sscanf(str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", |
---|
| 337 | &castleid, &guildid, &economy, &defense, &triggerE, &triggerD, &nextTime, &payTime, &createTime, &visibleC, |
---|
| 338 | &guardian[0], &guardian[1], &guardian[2], &guardian[3], &guardian[4], &guardian[5], &guardian[6], &guardian[7]) != 18 ) |
---|
| 339 | return 1; |
---|
| 340 | |
---|
| 341 | gc->castle_id = castleid; |
---|
| 342 | gc->guild_id = guildid; |
---|
| 343 | gc->economy = economy; |
---|
| 344 | gc->defense = defense; |
---|
| 345 | gc->triggerE = triggerE; |
---|
| 346 | gc->triggerD = triggerD; |
---|
| 347 | gc->nextTime = nextTime; |
---|
| 348 | gc->payTime = payTime; |
---|
| 349 | gc->createTime = createTime; |
---|
| 350 | gc->visibleC = visibleC; |
---|
| 351 | gc->guardian[0].visible = guardian[0]; |
---|
| 352 | gc->guardian[1].visible = guardian[1]; |
---|
| 353 | gc->guardian[2].visible = guardian[2]; |
---|
| 354 | gc->guardian[3].visible = guardian[3]; |
---|
| 355 | gc->guardian[4].visible = guardian[4]; |
---|
| 356 | gc->guardian[5].visible = guardian[5]; |
---|
| 357 | gc->guardian[6].visible = guardian[6]; |
---|
| 358 | gc->guardian[7].visible = guardian[7]; |
---|
| 359 | |
---|
| 360 | return 0; |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | #ifndef TXT_SQL_CONVERT |
---|
| 364 | // MhÖAf[^x[XÇÝÝ |
---|
| 365 | int inter_guild_readdb(void) |
---|
| 366 | { |
---|
| 367 | int i; |
---|
| 368 | FILE *fp; |
---|
| 369 | char line[1024]; |
---|
| 370 | char path[1024]; |
---|
| 371 | |
---|
| 372 | sprintf(path, "%s%s", db_path, "/exp_guild.txt"); |
---|
| 373 | fp = fopen(path, "r"); |
---|
| 374 | if (fp == NULL) { |
---|
| 375 | ShowError("can't read db/exp_guild.txt\n"); |
---|
| 376 | return 1; |
---|
| 377 | } |
---|
| 378 | i = 0; |
---|
| 379 | while(fgets(line, sizeof(line), fp) && i < 100) |
---|
| 380 | { |
---|
| 381 | if (line[0] == '/' && line[1] == '/') |
---|
| 382 | continue; |
---|
| 383 | guild_exp[i] = (unsigned int)atof(line); |
---|
| 384 | i++; |
---|
| 385 | } |
---|
| 386 | fclose(fp); |
---|
| 387 | |
---|
| 388 | return 0; |
---|
| 389 | } |
---|
| 390 | |
---|
| 391 | // Mhf[^ÌÇÝÝ |
---|
| 392 | int inter_guild_init() |
---|
| 393 | { |
---|
| 394 | char line[16384]; |
---|
| 395 | struct guild *g; |
---|
| 396 | struct guild_castle *gc; |
---|
| 397 | FILE *fp; |
---|
| 398 | int i, j, c = 0; |
---|
| 399 | |
---|
| 400 | inter_guild_readdb(); |
---|
| 401 | |
---|
| 402 | guild_db = idb_alloc(DB_OPT_RELEASE_DATA); |
---|
| 403 | castle_db = idb_alloc(DB_OPT_RELEASE_DATA); |
---|
| 404 | |
---|
| 405 | if ((fp = fopen(guild_txt,"r")) == NULL) |
---|
| 406 | return 1; |
---|
| 407 | while(fgets(line, sizeof(line), fp)) |
---|
| 408 | { |
---|
| 409 | j = 0; |
---|
| 410 | if (sscanf(line, "%d\t%%newid%%\n%n", &i, &j) == 1 && j > 0 && guild_newid <= i) { |
---|
| 411 | guild_newid = i; |
---|
| 412 | continue; |
---|
| 413 | } |
---|
| 414 | |
---|
| 415 | g = (struct guild *) aCalloc(sizeof(struct guild), 1); |
---|
| 416 | if(g == NULL){ |
---|
| 417 | ShowFatalError("int_guild: out of memory!\n"); |
---|
| 418 | exit(EXIT_FAILURE); |
---|
| 419 | } |
---|
| 420 | // memset(g, 0, sizeof(struct guild)); not needed... |
---|
| 421 | if (inter_guild_fromstr(line, g) == 0 && g->guild_id > 0) { |
---|
| 422 | if (g->guild_id >= guild_newid) |
---|
| 423 | guild_newid = g->guild_id + 1; |
---|
| 424 | idb_put(guild_db, g->guild_id, g); |
---|
| 425 | guild_check_empty(g); |
---|
| 426 | guild_calcinfo(g); |
---|
| 427 | } else { |
---|
| 428 | ShowError("int_guild: broken data [%s] line %d\n", guild_txt, c); |
---|
| 429 | aFree(g); |
---|
| 430 | } |
---|
| 431 | c++; |
---|
| 432 | } |
---|
| 433 | fclose(fp); |
---|
| 434 | |
---|
| 435 | c = 0;//JE^ú» |
---|
| 436 | |
---|
| 437 | if ((fp = fopen(castle_txt, "r")) == NULL) { |
---|
| 438 | return 1; |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | while(fgets(line, sizeof(line), fp)) |
---|
| 442 | { |
---|
| 443 | gc = (struct guild_castle *) aCalloc(sizeof(struct guild_castle), 1); |
---|
| 444 | if(gc == NULL){ |
---|
| 445 | ShowFatalError("int_guild: out of memory!\n"); |
---|
| 446 | exit(EXIT_FAILURE); |
---|
| 447 | } |
---|
| 448 | // memset(gc, 0, sizeof(struct guild_castle)); No need... |
---|
| 449 | if (inter_guildcastle_fromstr(line, gc) == 0) { |
---|
| 450 | idb_put(castle_db, gc->castle_id, gc); |
---|
| 451 | } else { |
---|
| 452 | ShowError("int_guild: broken data [%s] line %d\n", castle_txt, c); |
---|
| 453 | aFree(gc); |
---|
| 454 | } |
---|
| 455 | c++; |
---|
| 456 | } |
---|
| 457 | |
---|
| 458 | fclose(fp); |
---|
| 459 | |
---|
| 460 | if (!c) { |
---|
| 461 | ShowStatus(" %s - making Default Data...\n", castle_txt); |
---|
| 462 | //ftHgf[^ðì¬ |
---|
| 463 | for(i = 0; i < MAX_GUILDCASTLE; i++) { |
---|
| 464 | gc = (struct guild_castle *) aCalloc(sizeof(struct guild_castle), 1); |
---|
| 465 | if (gc == NULL) { |
---|
| 466 | ShowFatalError("int_guild: out of memory!\n"); |
---|
| 467 | exit(EXIT_FAILURE); |
---|
| 468 | } |
---|
| 469 | gc->castle_id = i; |
---|
| 470 | idb_put(castle_db, gc->castle_id, gc); |
---|
| 471 | } |
---|
| 472 | ShowStatus(" %s - making done\n",castle_txt); |
---|
| 473 | return 0; |
---|
| 474 | } |
---|
| 475 | |
---|
| 476 | return 0; |
---|
| 477 | } |
---|
| 478 | |
---|
| 479 | void inter_guild_final() |
---|
| 480 | { |
---|
| 481 | castle_db->destroy(castle_db, NULL); |
---|
| 482 | guild_db->destroy(guild_db, NULL); |
---|
| 483 | return; |
---|
| 484 | } |
---|
| 485 | |
---|
| 486 | struct guild *inter_guild_search(int guild_id) |
---|
| 487 | { |
---|
| 488 | return (struct guild*)idb_get(guild_db, guild_id); |
---|
| 489 | } |
---|
| 490 | |
---|
| 491 | // Mhf[^ÌZ[u |
---|
| 492 | int inter_guild_save() |
---|
| 493 | { |
---|
| 494 | FILE *fp; |
---|
| 495 | int lock; |
---|
| 496 | DBIterator* iter; |
---|
| 497 | struct guild* g; |
---|
| 498 | struct guild_castle* gc; |
---|
| 499 | |
---|
| 500 | // save guild data |
---|
| 501 | if ((fp = lock_fopen(guild_txt, &lock)) == NULL) { |
---|
| 502 | ShowError("int_guild: can't write [%s] !!! data is lost !!!\n", guild_txt); |
---|
| 503 | return 1; |
---|
| 504 | } |
---|
| 505 | |
---|
| 506 | iter = guild_db->iterator(guild_db); |
---|
| 507 | for( g = (struct guild*)iter->first(iter,NULL); iter->exists(iter); g = (struct guild*)iter->next(iter,NULL) ) |
---|
| 508 | { |
---|
| 509 | char line[16384]; |
---|
| 510 | inter_guild_tostr(line, g); |
---|
| 511 | fprintf(fp, "%s\n", line); |
---|
| 512 | } |
---|
| 513 | iter->destroy(iter); |
---|
| 514 | |
---|
| 515 | // fprintf(fp, "%d\t%%newid%%\n", guild_newid); |
---|
| 516 | lock_fclose(fp, guild_txt, &lock); |
---|
| 517 | |
---|
| 518 | // save castle data |
---|
| 519 | if ((fp = lock_fopen(castle_txt,&lock)) == NULL) { |
---|
| 520 | ShowError("int_guild: can't write [%s] !!! data is lost !!!\n", castle_txt); |
---|
| 521 | return 1; |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | iter = castle_db->iterator(castle_db); |
---|
| 525 | for( gc = (struct guild_castle*)iter->first(iter,NULL); iter->exists(iter); gc = (struct guild_castle*)iter->next(iter,NULL) ) |
---|
| 526 | { |
---|
| 527 | char line[16384]; |
---|
| 528 | inter_guildcastle_tostr(line, gc); |
---|
| 529 | fprintf(fp, "%s\n", line); |
---|
| 530 | } |
---|
| 531 | iter->destroy(iter); |
---|
| 532 | |
---|
| 533 | lock_fclose(fp, castle_txt, &lock); |
---|
| 534 | |
---|
| 535 | return 0; |
---|
| 536 | } |
---|
| 537 | |
---|
| 538 | // MhΛ |
---|
| 539 | struct guild* search_guildname(char *str) |
---|
| 540 | { |
---|
| 541 | DBIterator* iter; |
---|
| 542 | struct guild* g; |
---|
| 543 | |
---|
| 544 | iter = guild_db->iterator(guild_db); |
---|
| 545 | for( g = (struct guild*)iter->first(iter,NULL); iter->exists(iter); g = (struct guild*)iter->next(iter,NULL) ) |
---|
| 546 | { |
---|
| 547 | if (strcmpi(g->name, str) == 0) |
---|
| 548 | break; |
---|
| 549 | } |
---|
| 550 | iter->destroy(iter); |
---|
| 551 | |
---|
| 552 | return g; |
---|
| 553 | } |
---|
| 554 | |
---|
| 555 | // Mhªó©Ç€©`FbN |
---|
| 556 | static bool guild_check_empty(struct guild *g) |
---|
| 557 | { |
---|
| 558 | int i; |
---|
| 559 | ARR_FIND( 0, g->max_member, i, g->member[i].account_id > 0 ); |
---|
| 560 | if( i < g->max_member) |
---|
| 561 | return false; // not empty |
---|
| 562 | |
---|
| 563 | // Nà¢È¢ÌÅðU |
---|
| 564 | guild_db->foreach(guild_db, guild_break_sub, g->guild_id); |
---|
| 565 | inter_guild_storage_delete(g->guild_id); |
---|
| 566 | mapif_guild_broken(g->guild_id, 0); |
---|
| 567 | idb_remove(guild_db, g->guild_id); |
---|
| 568 | return true; |
---|
| 569 | } |
---|
| 570 | |
---|
| 571 | unsigned int guild_nextexp(int level) |
---|
| 572 | { |
---|
| 573 | if (level == 0) |
---|
| 574 | return 1; |
---|
| 575 | if (level > 0 && level < 100) |
---|
| 576 | return guild_exp[level-1]; |
---|
| 577 | |
---|
| 578 | return 0; |
---|
| 579 | } |
---|
| 580 | |
---|
| 581 | // MhXLª é©mF |
---|
| 582 | int guild_checkskill(struct guild *g, int id) |
---|
| 583 | { |
---|
| 584 | int idx = id - GD_SKILLBASE; |
---|
| 585 | |
---|
| 586 | |
---|
| 587 | if(idx < 0 || idx >= MAX_GUILDSKILL) |
---|
| 588 | |
---|
| 589 | return 0; |
---|
| 590 | |
---|
| 591 | return g->skill[idx].lv; |
---|
| 592 | } |
---|
| 593 | |
---|
| 594 | // MhÌîñÌÄvZ |
---|
| 595 | int guild_calcinfo(struct guild *g) |
---|
| 596 | { |
---|
| 597 | int i, c; |
---|
| 598 | unsigned int nextexp; |
---|
| 599 | struct guild before = *g; |
---|
| 600 | |
---|
| 601 | // XLIDÌÝè |
---|
| 602 | for(i = 0; i < MAX_GUILDSKILL; i++) |
---|
| 603 | g->skill[i].id=i+GD_SKILLBASE; |
---|
| 604 | |
---|
| 605 | // Mhx |
---|
| 606 | if (g->guild_lv <= 0) |
---|
| 607 | g->guild_lv = 1; |
---|
| 608 | nextexp = guild_nextexp(g->guild_lv); |
---|
| 609 | if (nextexp > 0) { |
---|
| 610 | while(g->exp >= nextexp && nextexp > 0) { //fixed guild exp overflow [Kevin] |
---|
| 611 | g->exp -= nextexp; |
---|
| 612 | g->guild_lv++; |
---|
| 613 | g->skill_point++; |
---|
| 614 | nextexp = guild_nextexp(g->guild_lv); |
---|
| 615 | } |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | // MhÌÌo±l |
---|
| 619 | g->next_exp = guild_nextexp(g->guild_lv); |
---|
| 620 | |
---|
| 621 | // oãÀiMhg£Kpj |
---|
| 622 | g->max_member = 16 + guild_checkskill(g, GD_EXTENSION) * 6; //Guild Extention skill - currently adds 6 to max per skill lv. |
---|
| 623 | if(g->max_member > MAX_GUILD) |
---|
| 624 | { |
---|
| 625 | ShowError("Guild %d:%s has capacity for too many guild members (%d), max supported is %d\n", g->guild_id, g->name, g->max_member, MAX_GUILD); |
---|
| 626 | g->max_member = MAX_GUILD; |
---|
| 627 | } |
---|
| 628 | |
---|
| 629 | // œÏxÆICl |
---|
| 630 | g->average_lv = 0; |
---|
| 631 | g->connect_member = 0; |
---|
| 632 | c = 0; |
---|
| 633 | for(i = 0; i < g->max_member; i++) { |
---|
| 634 | if (g->member[i].account_id > 0) { |
---|
| 635 | g->average_lv += g->member[i].lv; |
---|
| 636 | c++; |
---|
| 637 | if (g->member[i].online > 0) |
---|
| 638 | g->connect_member++; |
---|
| 639 | } |
---|
| 640 | } |
---|
| 641 | if(c) g->average_lv /= c; |
---|
| 642 | |
---|
| 643 | // Sf[^ðéKvª 軀 |
---|
| 644 | if (g->max_member != before.max_member || |
---|
| 645 | g->guild_lv != before.guild_lv || |
---|
| 646 | g->skill_point != before.skill_point) { |
---|
| 647 | mapif_guild_info(-1, g); |
---|
| 648 | return 1; |
---|
| 649 | } |
---|
| 650 | |
---|
| 651 | return 0; |
---|
| 652 | } |
---|
| 653 | |
---|
| 654 | //------------------------------------------------------------------- |
---|
| 655 | // map serverÖÌÊM |
---|
| 656 | |
---|
| 657 | // Mhì¬ÂÛ |
---|
| 658 | int mapif_guild_created(int fd, int account_id, struct guild *g) |
---|
| 659 | { |
---|
| 660 | WFIFOHEAD(fd, 10); |
---|
| 661 | WFIFOW(fd,0) = 0x3830; |
---|
| 662 | WFIFOL(fd,2) = account_id; |
---|
| 663 | if (g != NULL) { |
---|
| 664 | WFIFOL(fd,6) = g->guild_id; |
---|
| 665 | ShowInfo("Created Guild (%d %s)\n", g->guild_id, g->name); |
---|
| 666 | }else{ |
---|
| 667 | WFIFOL(fd,6) = 0; |
---|
| 668 | } |
---|
| 669 | WFIFOSET(fd,10); |
---|
| 670 | return 0; |
---|
| 671 | } |
---|
| 672 | |
---|
| 673 | // Mhîñ©Â©çž |
---|
| 674 | int mapif_guild_noinfo(int fd, int guild_id) |
---|
| 675 | { |
---|
| 676 | WFIFOHEAD(fd, 8); |
---|
| 677 | WFIFOW(fd,0) = 0x3831; |
---|
| 678 | WFIFOW(fd,2) = 8; |
---|
| 679 | WFIFOL(fd,4) = guild_id; |
---|
| 680 | WFIFOSET(fd,8); |
---|
| 681 | ShowNotice("int_guild: info not found %d\n", guild_id); |
---|
| 682 | |
---|
| 683 | return 0; |
---|
| 684 | } |
---|
| 685 | |
---|
| 686 | // MhîñÜÆßè |
---|
| 687 | int mapif_guild_info(int fd, struct guild *g) |
---|
| 688 | { |
---|
| 689 | unsigned char buf[8+sizeof(struct guild)]; |
---|
| 690 | |
---|
| 691 | WBUFW(buf,0) = 0x3831; |
---|
| 692 | memcpy(buf + 4, g, sizeof(struct guild)); |
---|
| 693 | WBUFW(buf,2) = 4 + sizeof(struct guild); |
---|
| 694 | if (fd < 0) |
---|
| 695 | mapif_sendall(buf, WBUFW(buf,2)); |
---|
| 696 | else |
---|
| 697 | mapif_send(fd, buf, WBUFW(buf,2)); |
---|
| 698 | |
---|
| 699 | return 0; |
---|
| 700 | } |
---|
| 701 | |
---|
| 702 | // oÇÁÂÛ |
---|
| 703 | int mapif_guild_memberadded(int fd, int guild_id, int account_id, int char_id, int flag) |
---|
| 704 | { |
---|
| 705 | WFIFOHEAD(fd, 15); |
---|
| 706 | WFIFOW(fd,0) = 0x3832; |
---|
| 707 | WFIFOL(fd,2) = guild_id; |
---|
| 708 | WFIFOL(fd,6) = account_id; |
---|
| 709 | WFIFOL(fd,10) = char_id; |
---|
| 710 | WFIFOB(fd,14) = flag; |
---|
| 711 | WFIFOSET(fd, 15); |
---|
| 712 | |
---|
| 713 | return 0; |
---|
| 714 | } |
---|
| 715 | |
---|
| 716 | // EÞ/ÇúÊm |
---|
| 717 | int mapif_guild_leaved(int guild_id, int account_id, int char_id, int flag, const char *name, const char *mes) |
---|
| 718 | { |
---|
| 719 | unsigned char buf[79]; |
---|
| 720 | |
---|
| 721 | WBUFW(buf, 0) = 0x3834; |
---|
| 722 | WBUFL(buf, 2) = guild_id; |
---|
| 723 | WBUFL(buf, 6) = account_id; |
---|
| 724 | WBUFL(buf,10) = char_id; |
---|
| 725 | WBUFB(buf,14) = flag; |
---|
| 726 | memcpy(WBUFP(buf,15), mes, 40); |
---|
| 727 | memcpy(WBUFP(buf,55), name, NAME_LENGTH); |
---|
| 728 | mapif_sendall(buf, 55+NAME_LENGTH); |
---|
| 729 | // mapif_sendall(buf, 79); |
---|
| 730 | ShowInfo("Character left guild (Guild %d, %d - %s: %s)\n", guild_id, account_id, name, mes); |
---|
| 731 | |
---|
| 732 | return 0; |
---|
| 733 | } |
---|
| 734 | |
---|
| 735 | // ICóÔÆLvXVÊm |
---|
| 736 | int mapif_guild_memberinfoshort(struct guild *g, int idx) |
---|
| 737 | { |
---|
| 738 | unsigned char buf[19]; |
---|
| 739 | |
---|
| 740 | WBUFW(buf, 0) = 0x3835; |
---|
| 741 | WBUFL(buf, 2) = g->guild_id; |
---|
| 742 | WBUFL(buf, 6) = g->member[idx].account_id; |
---|
| 743 | WBUFL(buf,10) = g->member[idx].char_id; |
---|
| 744 | WBUFB(buf,14) = (unsigned char)g->member[idx].online; |
---|
| 745 | WBUFW(buf,15) = g->member[idx].lv; |
---|
| 746 | WBUFW(buf,17) = g->member[idx].class_; |
---|
| 747 | mapif_sendall(buf, 19); |
---|
| 748 | return 0; |
---|
| 749 | } |
---|
| 750 | |
---|
| 751 | // ðUÊm |
---|
| 752 | int mapif_guild_broken(int guild_id, int flag) |
---|
| 753 | { |
---|
| 754 | unsigned char buf[7]; |
---|
| 755 | |
---|
| 756 | WBUFW(buf,0) = 0x3836; |
---|
| 757 | WBUFL(buf,2) = guild_id; |
---|
| 758 | WBUFB(buf,6) = flag; |
---|
| 759 | mapif_sendall(buf, 7); |
---|
| 760 | ShowInfo("Guild Break (%d)\n", guild_id); |
---|
| 761 | |
---|
| 762 | return 0; |
---|
| 763 | } |
---|
| 764 | |
---|
| 765 | // MhàŸ |
---|
| 766 | int mapif_guild_message(int guild_id, int account_id, char *mes, int len, int sfd) |
---|
| 767 | { |
---|
| 768 | unsigned char buf[2048]; |
---|
| 769 | |
---|
| 770 | WBUFW(buf,0) = 0x3837; |
---|
| 771 | WBUFW(buf,2) = len + 12; |
---|
| 772 | WBUFL(buf,4) = guild_id; |
---|
| 773 | WBUFL(buf,8) = account_id; |
---|
| 774 | memcpy(WBUFP(buf,12), mes, len); |
---|
| 775 | mapif_sendallwos(sfd, buf, len + 12); |
---|
| 776 | |
---|
| 777 | return 0; |
---|
| 778 | } |
---|
| 779 | |
---|
| 780 | // Mhî{îñÏXÊm |
---|
| 781 | int mapif_guild_basicinfochanged(int guild_id, int type, const void *data, int len) |
---|
| 782 | { |
---|
| 783 | unsigned char buf[2048]; |
---|
| 784 | |
---|
| 785 | WBUFW(buf,0) = 0x3839; |
---|
| 786 | WBUFW(buf,2) = len+10; |
---|
| 787 | WBUFL(buf,4) = guild_id; |
---|
| 788 | WBUFW(buf,8) = type; |
---|
| 789 | memcpy(WBUFP(buf,10),data,len); |
---|
| 790 | mapif_sendall(buf,len+10); |
---|
| 791 | return 0; |
---|
| 792 | } |
---|
| 793 | |
---|
| 794 | // MhoîñÏXÊm |
---|
| 795 | int mapif_guild_memberinfochanged(int guild_id, int account_id, int char_id, int type, const void *data, int len) |
---|
| 796 | { |
---|
| 797 | unsigned char buf[4096]; |
---|
| 798 | |
---|
| 799 | WBUFW(buf, 0) = 0x383a; |
---|
| 800 | WBUFW(buf, 2) = len + 18; |
---|
| 801 | WBUFL(buf, 4) = guild_id; |
---|
| 802 | WBUFL(buf, 8) = account_id; |
---|
| 803 | WBUFL(buf,12) = char_id; |
---|
| 804 | WBUFW(buf,16) = type; |
---|
| 805 | memcpy(WBUFP(buf,18), data, len); |
---|
| 806 | mapif_sendall(buf,len+18); |
---|
| 807 | |
---|
| 808 | return 0; |
---|
| 809 | } |
---|
| 810 | |
---|
| 811 | // MhXLAbvÊm |
---|
| 812 | int mapif_guild_skillupack(int guild_id, int skill_num, int account_id) |
---|
| 813 | { |
---|
| 814 | unsigned char buf[14]; |
---|
| 815 | |
---|
| 816 | WBUFW(buf, 0) = 0x383c; |
---|
| 817 | WBUFL(buf, 2) = guild_id; |
---|
| 818 | WBUFL(buf, 6) = skill_num; |
---|
| 819 | WBUFL(buf,10) = account_id; |
---|
| 820 | mapif_sendall(buf, 14); |
---|
| 821 | |
---|
| 822 | return 0; |
---|
| 823 | } |
---|
| 824 | |
---|
| 825 | // Mh¯¿/GÎÊm |
---|
| 826 | int mapif_guild_alliance(int guild_id1, int guild_id2, int account_id1, int account_id2, int flag, const char *name1, const char *name2) |
---|
| 827 | { |
---|
| 828 | unsigned char buf[67]; |
---|
| 829 | |
---|
| 830 | WBUFW(buf, 0) = 0x383d; |
---|
| 831 | WBUFL(buf, 2) = guild_id1; |
---|
| 832 | WBUFL(buf, 6) = guild_id2; |
---|
| 833 | WBUFL(buf,10) = account_id1; |
---|
| 834 | WBUFL(buf,14) = account_id2; |
---|
| 835 | WBUFB(buf,18) = flag; |
---|
| 836 | memcpy(WBUFP(buf,19), name1, NAME_LENGTH); |
---|
| 837 | memcpy(WBUFP(buf,19+NAME_LENGTH), name2, NAME_LENGTH); |
---|
| 838 | mapif_sendall(buf,19+2*NAME_LENGTH); |
---|
| 839 | /* |
---|
| 840 | memcpy(WBUFP(buf,43), name2, NAME_LENGTH); |
---|
| 841 | mapif_sendall(buf, 67); |
---|
| 842 | */ |
---|
| 843 | return 0; |
---|
| 844 | } |
---|
| 845 | |
---|
| 846 | // MhðEÏXÊm |
---|
| 847 | int mapif_guild_position(struct guild *g, int idx) |
---|
| 848 | { |
---|
| 849 | unsigned char buf[2048]; |
---|
| 850 | |
---|
| 851 | WBUFW(buf,0) = 0x383b; |
---|
| 852 | WBUFW(buf,2) = sizeof(struct guild_position) + 12; |
---|
| 853 | WBUFL(buf,4) = g->guild_id; |
---|
| 854 | WBUFL(buf,8) = idx; |
---|
| 855 | memcpy(WBUFP(buf,12), &g->position[idx], sizeof(struct guild_position)); |
---|
| 856 | mapif_sendall(buf, WBUFW(buf,2)); |
---|
| 857 | |
---|
| 858 | return 0; |
---|
| 859 | } |
---|
| 860 | |
---|
| 861 | // MhmÏXÊm |
---|
| 862 | int mapif_guild_notice(struct guild *g) |
---|
| 863 | { |
---|
| 864 | unsigned char buf[186]; |
---|
| 865 | |
---|
| 866 | WBUFW(buf,0) = 0x383e; |
---|
| 867 | WBUFL(buf,2) = g->guild_id; |
---|
| 868 | memcpy(WBUFP(buf,6), g->mes1, 60); |
---|
| 869 | memcpy(WBUFP(buf,66), g->mes2, 120); |
---|
| 870 | mapif_sendall(buf, 186); |
---|
| 871 | |
---|
| 872 | return 0; |
---|
| 873 | } |
---|
| 874 | |
---|
| 875 | // MhGuÏXÊm |
---|
| 876 | int mapif_guild_emblem(struct guild *g) |
---|
| 877 | { |
---|
| 878 | unsigned char buf[2048]; |
---|
| 879 | |
---|
| 880 | WBUFW(buf,0) = 0x383f; |
---|
| 881 | WBUFW(buf,2) = g->emblem_len + 12; |
---|
| 882 | WBUFL(buf,4) = g->guild_id; |
---|
| 883 | WBUFL(buf,8) = g->emblem_id; |
---|
| 884 | memcpy(WBUFP(buf,12), g->emblem_data, g->emblem_len); |
---|
| 885 | mapif_sendall(buf, WBUFW(buf,2)); |
---|
| 886 | |
---|
| 887 | return 0; |
---|
| 888 | } |
---|
| 889 | |
---|
| 890 | int mapif_guild_master_changed(struct guild *g, int aid, int cid) |
---|
| 891 | { |
---|
| 892 | unsigned char buf[14]; |
---|
| 893 | WBUFW(buf,0)=0x3843; |
---|
| 894 | WBUFL(buf,2)=g->guild_id; |
---|
| 895 | WBUFL(buf,6)=aid; |
---|
| 896 | WBUFL(buf,10)=cid; |
---|
| 897 | mapif_sendall(buf,14); |
---|
| 898 | return 0; |
---|
| 899 | } |
---|
| 900 | |
---|
| 901 | int mapif_guild_castle_dataload(int castle_id, int index, int value) |
---|
| 902 | { |
---|
| 903 | unsigned char buf[9]; |
---|
| 904 | |
---|
| 905 | WBUFW(buf,0) = 0x3840; |
---|
| 906 | WBUFW(buf,2) = castle_id; |
---|
| 907 | WBUFB(buf,4) = index; |
---|
| 908 | WBUFL(buf,5) = value; |
---|
| 909 | mapif_sendall(buf,9); |
---|
| 910 | |
---|
| 911 | return 0; |
---|
| 912 | } |
---|
| 913 | |
---|
| 914 | int mapif_guild_castle_datasave(int castle_id, int index, int value) |
---|
| 915 | { |
---|
| 916 | unsigned char buf[9]; |
---|
| 917 | |
---|
| 918 | WBUFW(buf,0) = 0x3841; |
---|
| 919 | WBUFW(buf,2) = castle_id; |
---|
| 920 | WBUFB(buf,4) = index; |
---|
| 921 | WBUFL(buf,5) = value; |
---|
| 922 | mapif_sendall(buf,9); |
---|
| 923 | |
---|
| 924 | return 0; |
---|
| 925 | } |
---|
| 926 | |
---|
| 927 | int mapif_guild_castle_alldataload(int fd) |
---|
| 928 | { |
---|
| 929 | DBIterator* iter; |
---|
| 930 | struct guild_castle* gc; |
---|
| 931 | int len = 4; |
---|
| 932 | |
---|
| 933 | WFIFOHEAD(fd, 4 + MAX_GUILDCASTLE*sizeof(struct guild_castle)); |
---|
| 934 | WFIFOW(fd,0) = 0x3842; |
---|
| 935 | iter = castle_db->iterator(castle_db); |
---|
| 936 | for( gc = (struct guild_castle*)iter->first(iter,NULL); iter->exists(iter); gc = (struct guild_castle*)iter->next(iter,NULL) ) |
---|
| 937 | { |
---|
| 938 | memcpy(WFIFOP(fd,len), gc, sizeof(struct guild_castle)); |
---|
| 939 | len += sizeof(struct guild_castle); |
---|
| 940 | } |
---|
| 941 | iter->destroy(iter); |
---|
| 942 | WFIFOW(fd,2) = len; |
---|
| 943 | WFIFOSET(fd, len); |
---|
| 944 | |
---|
| 945 | return 0; |
---|
| 946 | } |
---|
| 947 | |
---|
| 948 | //------------------------------------------------------------------- |
---|
| 949 | // map server©çÌÊM |
---|
| 950 | |
---|
| 951 | // Mhì¬v |
---|
| 952 | int mapif_parse_CreateGuild(int fd, int account_id, char *name, struct guild_member *master) |
---|
| 953 | { |
---|
| 954 | struct guild *g; |
---|
| 955 | int i; |
---|
| 956 | |
---|
| 957 | for(i = 0; i < NAME_LENGTH && name[i]; i++) { |
---|
| 958 | if (!(name[i] & 0xe0) || name[i] == 0x7f) { |
---|
| 959 | ShowInfo("Create Guild: illegal guild name [%s]\n", name); |
---|
| 960 | mapif_guild_created(fd, account_id, NULL); |
---|
| 961 | return 0; |
---|
| 962 | } |
---|
| 963 | } |
---|
| 964 | |
---|
| 965 | if ((g = search_guildname(name)) != NULL) { |
---|
| 966 | ShowInfo("Create Guild: same name guild exists [%s]\n", name); |
---|
| 967 | mapif_guild_created(fd, account_id, NULL); |
---|
| 968 | return 0; |
---|
| 969 | } |
---|
| 970 | |
---|
| 971 | // Check Authorised letters/symbols in the name of the character |
---|
| 972 | if (char_name_option == 1) { // only letters/symbols in char_name_letters are authorised |
---|
| 973 | for (i = 0; i < NAME_LENGTH && name[i]; i++) |
---|
| 974 | if (strchr(char_name_letters, name[i]) == NULL) { |
---|
| 975 | mapif_guild_created(fd,account_id,NULL); |
---|
| 976 | return 0; |
---|
| 977 | } |
---|
| 978 | } else if (char_name_option == 2) { // letters/symbols in char_name_letters are forbidden |
---|
| 979 | for (i = 0; i < NAME_LENGTH && name[i]; i++) |
---|
| 980 | if (strchr(char_name_letters, name[i]) != NULL) { |
---|
| 981 | mapif_guild_created(fd,account_id,NULL); |
---|
| 982 | return 0; |
---|
| 983 | } |
---|
| 984 | } |
---|
| 985 | |
---|
| 986 | g = (struct guild *) aCalloc(sizeof(struct guild), 1); |
---|
| 987 | if (g == NULL) { |
---|
| 988 | ShowFatalError("int_guild: CreateGuild: out of memory !\n"); |
---|
| 989 | mapif_guild_created(fd, account_id, NULL); |
---|
| 990 | exit(EXIT_FAILURE); |
---|
| 991 | } |
---|
| 992 | // memset(g, 0, sizeof(struct guild)); Meh... |
---|
| 993 | g->guild_id = guild_newid++; |
---|
| 994 | memcpy(g->name, name, NAME_LENGTH); |
---|
| 995 | memcpy(g->master, master->name, NAME_LENGTH); |
---|
| 996 | memcpy(&g->member[0], master, sizeof(struct guild_member)); |
---|
| 997 | |
---|
| 998 | g->position[0].mode = 0x11; |
---|
| 999 | strcpy(g->position[ 0].name, "GuildMaster"); |
---|
| 1000 | strcpy(g->position[MAX_GUILDPOSITION-1].name, "Newbie"); |
---|
| 1001 | for(i = 1; i < MAX_GUILDPOSITION-1; i++) |
---|
| 1002 | sprintf(g->position[i].name, "Position %d", i + 1); |
---|
| 1003 | |
---|
| 1004 | // ±±ÅMhîñvZªKvÆvíêé |
---|
| 1005 | g->max_member = 16; |
---|
| 1006 | g->average_lv = master->lv; |
---|
| 1007 | g->connect_member = 1; |
---|
| 1008 | for(i = 0; i < MAX_GUILDSKILL; i++) |
---|
| 1009 | g->skill[i].id=i + GD_SKILLBASE; |
---|
| 1010 | |
---|
| 1011 | idb_put(guild_db, g->guild_id, g); |
---|
| 1012 | |
---|
| 1013 | mapif_guild_created(fd, account_id, g); |
---|
| 1014 | mapif_guild_info(fd, g); |
---|
| 1015 | |
---|
| 1016 | if(log_inter) |
---|
| 1017 | inter_log("guild %s (id=%d) created by master %s (id=%d)\n", |
---|
| 1018 | name, g->guild_id, master->name, master->account_id); |
---|
| 1019 | |
---|
| 1020 | return 0; |
---|
| 1021 | } |
---|
| 1022 | |
---|
| 1023 | // Mhîñv |
---|
| 1024 | int mapif_parse_GuildInfo(int fd, int guild_id) |
---|
| 1025 | { |
---|
| 1026 | struct guild *g; |
---|
| 1027 | |
---|
| 1028 | g = (struct guild*)idb_get(guild_db, guild_id); |
---|
| 1029 | if (g != NULL){ |
---|
| 1030 | guild_calcinfo(g); |
---|
| 1031 | mapif_guild_info(fd, g); |
---|
| 1032 | } else |
---|
| 1033 | mapif_guild_noinfo(fd, guild_id); |
---|
| 1034 | |
---|
| 1035 | return 0; |
---|
| 1036 | } |
---|
| 1037 | |
---|
| 1038 | // MhoÇÁv |
---|
| 1039 | int mapif_parse_GuildAddMember(int fd, int guild_id, struct guild_member *m) |
---|
| 1040 | { |
---|
| 1041 | struct guild *g; |
---|
| 1042 | int i; |
---|
| 1043 | |
---|
| 1044 | g = (struct guild*)idb_get(guild_db, guild_id); |
---|
| 1045 | if (g == NULL) { |
---|
| 1046 | mapif_guild_memberadded(fd, guild_id, m->account_id, m->char_id, 1); |
---|
| 1047 | return 0; |
---|
| 1048 | } |
---|
| 1049 | |
---|
| 1050 | ARR_FIND( 0, g->max_member, i, g->member[i].account_id == 0 ); |
---|
| 1051 | if( i < g->max_member ) |
---|
| 1052 | { |
---|
| 1053 | memcpy(&g->member[i], m, sizeof(struct guild_member)); |
---|
| 1054 | mapif_guild_memberadded(fd, guild_id, m->account_id, m->char_id, 0); |
---|
| 1055 | guild_calcinfo(g); |
---|
| 1056 | mapif_guild_info(-1, g); |
---|
| 1057 | } |
---|
| 1058 | else |
---|
| 1059 | mapif_guild_memberadded(fd, guild_id, m->account_id, m->char_id, 1); |
---|
| 1060 | |
---|
| 1061 | return 0; |
---|
| 1062 | } |
---|
| 1063 | |
---|
| 1064 | // Delete member from guild |
---|
| 1065 | int mapif_parse_GuildLeave(int fd, int guild_id, int account_id, int char_id, int flag, const char *mes) |
---|
| 1066 | { |
---|
| 1067 | int i, j; |
---|
| 1068 | |
---|
| 1069 | struct guild* g = (struct guild*)idb_get(guild_db, guild_id); |
---|
| 1070 | if( g == NULL ) |
---|
| 1071 | { |
---|
| 1072 | //TODO |
---|
| 1073 | return 0; |
---|
| 1074 | } |
---|
| 1075 | |
---|
| 1076 | // Find the member |
---|
| 1077 | ARR_FIND( 0, g->max_member, i, g->member[i].account_id == account_id && g->member[i].char_id == char_id ); |
---|
| 1078 | if( i == g->max_member ) |
---|
| 1079 | { |
---|
| 1080 | //TODO |
---|
| 1081 | return 0; |
---|
| 1082 | } |
---|
| 1083 | |
---|
| 1084 | if( flag ) |
---|
| 1085 | { // ÇúÌêÇúXgÉüêé |
---|
| 1086 | ARR_FIND( 0, MAX_GUILDEXPULSION, j, g->expulsion[j].account_id == 0 ); |
---|
| 1087 | if (j == MAX_GUILDEXPULSION) |
---|
| 1088 | { // êtÈÌÅâÌðÁ· |
---|
| 1089 | for(j = 0; j < MAX_GUILDEXPULSION - 1; j++) |
---|
| 1090 | g->expulsion[j] = g->expulsion[j+1]; |
---|
| 1091 | j = MAX_GUILDEXPULSION - 1; |
---|
| 1092 | } |
---|
| 1093 | // Save the expulsion entry |
---|
| 1094 | g->expulsion[j].account_id = account_id; |
---|
| 1095 | safestrncpy(g->expulsion[j].name, g->member[i].name, NAME_LENGTH); |
---|
| 1096 | safestrncpy(g->expulsion[j].mes, mes, 40); |
---|
| 1097 | } |
---|
| 1098 | |
---|
| 1099 | mapif_guild_leaved(guild_id, account_id, char_id, flag, g->member[i].name, mes); |
---|
| 1100 | |
---|
| 1101 | memset(&g->member[i], 0, sizeof(struct guild_member)); |
---|
| 1102 | |
---|
| 1103 | if (guild_check_empty(g) == 0) |
---|
| 1104 | mapif_guild_info(-1,g);// ÜŸlª¢éÌÅf[^M |
---|
| 1105 | |
---|
| 1106 | return 0; |
---|
| 1107 | } |
---|
| 1108 | |
---|
| 1109 | // IC/LvXV |
---|
| 1110 | int mapif_parse_GuildChangeMemberInfoShort(int fd, int guild_id, int account_id, int char_id, int online, int lv, int class_) |
---|
| 1111 | { |
---|
| 1112 | struct guild *g; |
---|
| 1113 | int i, sum, c; |
---|
| 1114 | |
---|
| 1115 | g = (struct guild*)idb_get(guild_db, guild_id); |
---|
| 1116 | if (g == NULL) |
---|
| 1117 | return 0; |
---|
| 1118 | |
---|
| 1119 | ARR_FIND( 0, g->max_member, i, g->member[i].account_id == account_id && g->member[i].char_id == char_id ); |
---|
| 1120 | if( i < g->max_member ) |
---|
| 1121 | { |
---|
| 1122 | g->member[i].online = online; |
---|
| 1123 | g->member[i].lv = lv; |
---|
| 1124 | g->member[i].class_ = class_; |
---|
| 1125 | mapif_guild_memberinfoshort(g, i); |
---|
| 1126 | } |
---|
| 1127 | |
---|
| 1128 | g->average_lv = 0; |
---|
| 1129 | g->connect_member = 0; |
---|
| 1130 | c = 0; // member count |
---|
| 1131 | sum = 0; // total sum of base levels |
---|
| 1132 | |
---|
| 1133 | for(i = 0; i < g->max_member; i++) |
---|
| 1134 | { |
---|
| 1135 | if( g->member[i].account_id > 0 ) |
---|
| 1136 | { |
---|
| 1137 | sum += g->member[i].lv; |
---|
| 1138 | c++; |
---|
| 1139 | } |
---|
| 1140 | if( g->member[i].online ) |
---|
| 1141 | g->connect_member++; |
---|
| 1142 | } |
---|
| 1143 | |
---|
| 1144 | if( c ) // this check should always succeed... |
---|
| 1145 | g->average_lv = sum / c; |
---|
| 1146 | |
---|
| 1147 | //FIXME: how about sending a mapif_guild_info() update to the mapserver? [ultramage] |
---|
| 1148 | |
---|
| 1149 | return 0; |
---|
| 1150 | } |
---|
| 1151 | |
---|
| 1152 | // MhðUpi¯¿/GÎððj |
---|
| 1153 | int guild_break_sub(DBKey key, void *data, va_list ap) |
---|
| 1154 | { |
---|
| 1155 | struct guild *g = (struct guild *)data; |
---|
| 1156 | int guild_id = va_arg(ap, int); |
---|
| 1157 | int i; |
---|
| 1158 | |
---|
| 1159 | for(i = 0; i < MAX_GUILDALLIANCE; i++) { |
---|
| 1160 | if (g->alliance[i].guild_id == guild_id) |
---|
| 1161 | g->alliance[i].guild_id = 0; |
---|
| 1162 | } |
---|
| 1163 | return 0; |
---|
| 1164 | } |
---|
| 1165 | |
---|
| 1166 | // MhðUv |
---|
| 1167 | int mapif_parse_BreakGuild(int fd, int guild_id) |
---|
| 1168 | { |
---|
| 1169 | struct guild *g; |
---|
| 1170 | |
---|
| 1171 | g = (struct guild*)idb_get(guild_db, guild_id); |
---|
| 1172 | if(g == NULL) |
---|
| 1173 | return 0; |
---|
| 1174 | |
---|
| 1175 | guild_db->foreach(guild_db, guild_break_sub, guild_id); |
---|
| 1176 | inter_guild_storage_delete(guild_id); |
---|
| 1177 | mapif_guild_broken(guild_id, 0); |
---|
| 1178 | |
---|
| 1179 | if(log_inter) |
---|
| 1180 | inter_log("guild %s (id=%d) broken\n", g->name, guild_id); |
---|
| 1181 | |
---|
| 1182 | idb_remove(guild_db, guild_id); |
---|
| 1183 | return 0; |
---|
| 1184 | } |
---|
| 1185 | |
---|
| 1186 | // MhbZ[WM |
---|
| 1187 | int mapif_parse_GuildMessage(int fd, int guild_id, int account_id, char *mes, int len) |
---|
| 1188 | { |
---|
| 1189 | return mapif_guild_message(guild_id, account_id, mes, len, fd); |
---|
| 1190 | } |
---|
| 1191 | |
---|
| 1192 | // Mhî{f[^ÏXv |
---|
| 1193 | int mapif_parse_GuildBasicInfoChange(int fd, int guild_id, int type, const char *data, int len) |
---|
| 1194 | { |
---|
| 1195 | struct guild *g; |
---|
| 1196 | short dw = *((short *)data); |
---|
| 1197 | |
---|
| 1198 | g = (struct guild*)idb_get(guild_db, guild_id); |
---|
| 1199 | if (g == NULL) |
---|
| 1200 | return 0; |
---|
| 1201 | |
---|
| 1202 | switch(type) { |
---|
| 1203 | case GBI_GUILDLV: |
---|
| 1204 | if (dw > 0 && g->guild_lv + dw <= 50) { |
---|
| 1205 | g->guild_lv+=dw; |
---|
| 1206 | g->skill_point+=dw; |
---|
| 1207 | } else if (dw < 0 && g->guild_lv + dw >= 1) |
---|
| 1208 | g->guild_lv += dw; |
---|
| 1209 | mapif_guild_info(-1, g); |
---|
| 1210 | return 0; |
---|
| 1211 | default: |
---|
| 1212 | ShowError("int_guild: GuildBasicInfoChange: Unknown type %d\n", type); |
---|
| 1213 | break; |
---|
| 1214 | } |
---|
| 1215 | mapif_guild_basicinfochanged(guild_id, type, data, len); |
---|
| 1216 | |
---|
| 1217 | return 0; |
---|
| 1218 | } |
---|
| 1219 | |
---|
| 1220 | // Mhof[^ÏXv |
---|
| 1221 | int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int char_id, int type, const char *data, int len) |
---|
| 1222 | { |
---|
| 1223 | int i; |
---|
| 1224 | struct guild *g; |
---|
| 1225 | |
---|
| 1226 | g = (struct guild*)idb_get(guild_db, guild_id); |
---|
| 1227 | if(g == NULL) |
---|
| 1228 | return 0; |
---|
| 1229 | |
---|
| 1230 | for(i = 0; i < g->max_member; i++) |
---|
| 1231 | if (g->member[i].account_id == account_id && g->member[i].char_id == char_id) |
---|
| 1232 | break; |
---|
| 1233 | if (i == g->max_member) { |
---|
| 1234 | ShowWarning("int_guild: GuildMemberChange: Not found %d,%d in %d[%s]\n", account_id, char_id, guild_id, g->name); |
---|
| 1235 | return 0; |
---|
| 1236 | } |
---|
| 1237 | switch(type) { |
---|
| 1238 | case GMI_POSITION: // ðE |
---|
| 1239 | g->member[i].position = *((int *)data); |
---|
| 1240 | break; |
---|
| 1241 | case GMI_EXP: // EXP |
---|
| 1242 | { |
---|
| 1243 | unsigned int exp, old_exp=g->member[i].exp; |
---|
| 1244 | g->member[i].exp=*((unsigned int *)data); |
---|
| 1245 | if (g->member[i].exp > old_exp) |
---|
| 1246 | { |
---|
| 1247 | exp = g->member[i].exp - old_exp; |
---|
| 1248 | if (guild_exp_rate != 100) |
---|
| 1249 | exp = exp*guild_exp_rate/100; |
---|
| 1250 | if (exp > UINT_MAX - g->exp) |
---|
| 1251 | g->exp = UINT_MAX; |
---|
| 1252 | else |
---|
| 1253 | g->exp+=exp; |
---|
| 1254 | guild_calcinfo(g); |
---|
| 1255 | mapif_guild_basicinfochanged(guild_id,GBI_EXP,&g->exp,4); |
---|
| 1256 | } |
---|
| 1257 | break; |
---|
| 1258 | } |
---|
| 1259 | case GMI_HAIR: |
---|
| 1260 | { |
---|
| 1261 | g->member[i].hair=*((int *)data); |
---|
| 1262 | mapif_guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); |
---|
| 1263 | break; |
---|
| 1264 | } |
---|
| 1265 | case GMI_HAIR_COLOR: |
---|
| 1266 | { |
---|
| 1267 | g->member[i].hair_color=*((int *)data); |
---|
| 1268 | mapif_guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); |
---|
| 1269 | break; |
---|
| 1270 | } |
---|
| 1271 | case GMI_GENDER: |
---|
| 1272 | { |
---|
| 1273 | g->member[i].gender=*((int *)data); |
---|
| 1274 | mapif_guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); |
---|
| 1275 | break; |
---|
| 1276 | } |
---|
| 1277 | case GMI_CLASS: |
---|
| 1278 | { |
---|
| 1279 | g->member[i].class_=*((int *)data); |
---|
| 1280 | mapif_guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); |
---|
| 1281 | break; |
---|
| 1282 | } |
---|
| 1283 | case GMI_LEVEL: |
---|
| 1284 | { |
---|
| 1285 | g->member[i].lv=*((int *)data); |
---|
| 1286 | mapif_guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); |
---|
| 1287 | break; |
---|
| 1288 | } |
---|
| 1289 | |
---|
| 1290 | default: |
---|
| 1291 | ShowError("int_guild: GuildMemberInfoChange: Unknown type %d\n", type); |
---|
| 1292 | break; |
---|
| 1293 | } |
---|
| 1294 | mapif_guild_memberinfochanged(guild_id, account_id, char_id, type, data, len); |
---|
| 1295 | |
---|
| 1296 | return 0; |
---|
| 1297 | } |
---|
| 1298 | |
---|
| 1299 | int inter_guild_sex_changed(int guild_id,int account_id,int char_id, int gender) |
---|
| 1300 | { |
---|
| 1301 | return mapif_parse_GuildMemberInfoChange(0, guild_id, account_id, char_id, GMI_GENDER, (const char*)&gender, sizeof(gender)); |
---|
| 1302 | } |
---|
| 1303 | |
---|
| 1304 | // MhðEŒÏXv |
---|
| 1305 | int mapif_parse_GuildPosition(int fd, int guild_id, int idx, struct guild_position *p) |
---|
| 1306 | { |
---|
| 1307 | struct guild *g = (struct guild*)idb_get(guild_db, guild_id); |
---|
| 1308 | |
---|
| 1309 | if (g == NULL || idx < 0 || idx >= MAX_GUILDPOSITION) { |
---|
| 1310 | return 0; |
---|
| 1311 | } |
---|
| 1312 | memcpy(&g->position[idx], p, sizeof(struct guild_position)); |
---|
| 1313 | mapif_guild_position(g, idx); |
---|
| 1314 | ShowInfo("int_guild: position [%d] changed\n", idx); |
---|
| 1315 | |
---|
| 1316 | return 0; |
---|
| 1317 | } |
---|
| 1318 | |
---|
| 1319 | // MhXLAbvv |
---|
| 1320 | int mapif_parse_GuildSkillUp(int fd, int guild_id, int skill_num, int account_id) |
---|
| 1321 | { |
---|
| 1322 | struct guild *g = (struct guild*)idb_get(guild_db, guild_id); |
---|
| 1323 | int idx = skill_num - GD_SKILLBASE; |
---|
| 1324 | |
---|
| 1325 | if (g == NULL || idx < 0 || idx >= MAX_GUILDSKILL) |
---|
| 1326 | return 0; |
---|
| 1327 | |
---|
| 1328 | if (g->skill_point > 0 && g->skill[idx].id > 0 && g->skill[idx].lv < 10) { |
---|
| 1329 | g->skill[idx].lv++; |
---|
| 1330 | g->skill_point--; |
---|
| 1331 | if (guild_calcinfo(g) == 0) |
---|
| 1332 | mapif_guild_info(-1, g); |
---|
| 1333 | mapif_guild_skillupack(guild_id, skill_num, account_id); |
---|
| 1334 | } |
---|
| 1335 | |
---|
| 1336 | return 0; |
---|
| 1337 | } |
---|
| 1338 | |
---|
| 1339 | //Manual deletion of an alliance when partnering guild does not exists. [Skotlex] |
---|
| 1340 | static int mapif_parse_GuildDeleteAlliance(struct guild *g, int guild_id, int account_id1, int account_id2, int flag) |
---|
| 1341 | { |
---|
| 1342 | int i; |
---|
| 1343 | char name[NAME_LENGTH]; |
---|
| 1344 | for(i=0;i<MAX_GUILDALLIANCE;i++) |
---|
| 1345 | if(g->alliance[i].guild_id == guild_id) |
---|
| 1346 | { |
---|
| 1347 | strcpy(name, g->alliance[i].name); |
---|
| 1348 | g->alliance[i].guild_id=0; |
---|
| 1349 | break; |
---|
| 1350 | } |
---|
| 1351 | if (i == MAX_GUILDALLIANCE) |
---|
| 1352 | return -1; |
---|
| 1353 | |
---|
| 1354 | mapif_guild_alliance(g->guild_id,guild_id,account_id1,account_id2,flag,g->name,name); |
---|
| 1355 | return 0; |
---|
| 1356 | } |
---|
| 1357 | |
---|
| 1358 | // Mh¯¿v |
---|
| 1359 | int mapif_parse_GuildAlliance(int fd, int guild_id1, int guild_id2, int account_id1, int account_id2, int flag) |
---|
| 1360 | { |
---|
| 1361 | struct guild *g[2]; |
---|
| 1362 | int j, i; |
---|
| 1363 | |
---|
| 1364 | g[0] = (struct guild*)idb_get(guild_db, guild_id1); |
---|
| 1365 | g[1] = (struct guild*)idb_get(guild_db, guild_id2); |
---|
| 1366 | |
---|
| 1367 | if(g[0] && g[1]==NULL && (flag&0x8)) //Requested to remove an alliance with a not found guild. |
---|
| 1368 | return mapif_parse_GuildDeleteAlliance(g[0], guild_id2, |
---|
| 1369 | account_id1, account_id2, flag); //Try to do a manual removal of said guild. |
---|
| 1370 | |
---|
| 1371 | if (g[0] == NULL || g[1] == NULL) |
---|
| 1372 | return 0; |
---|
| 1373 | |
---|
| 1374 | if (!(flag & 0x8)) { |
---|
| 1375 | for(i = 0; i < 2 - (flag & 1); i++) { |
---|
| 1376 | for(j = 0; j < MAX_GUILDALLIANCE; j++) |
---|
| 1377 | if (g[i]->alliance[j].guild_id == 0) { |
---|
| 1378 | g[i]->alliance[j].guild_id = g[1-i]->guild_id; |
---|
| 1379 | memcpy(g[i]->alliance[j].name, g[1-i]->name, NAME_LENGTH); |
---|
| 1380 | g[i]->alliance[j].opposition = flag & 1; |
---|
| 1381 | break; |
---|
| 1382 | } |
---|
| 1383 | } |
---|
| 1384 | } else { // ÖWðÁ |
---|
| 1385 | for(i = 0; i < 2 - (flag & 1); i++) { |
---|
| 1386 | for(j = 0; j < MAX_GUILDALLIANCE; j++) |
---|
| 1387 | if (g[i]->alliance[j].guild_id == g[1-i]->guild_id && g[i]->alliance[j].opposition == (flag & 1)) { |
---|
| 1388 | g[i]->alliance[j].guild_id = 0; |
---|
| 1389 | break; |
---|
| 1390 | } |
---|
| 1391 | } |
---|
| 1392 | } |
---|
| 1393 | mapif_guild_alliance(guild_id1, guild_id2, account_id1, account_id2, flag, g[0]->name, g[1]->name); |
---|
| 1394 | |
---|
| 1395 | return 0; |
---|
| 1396 | } |
---|
| 1397 | |
---|
| 1398 | // MhmÏXv |
---|
| 1399 | int mapif_parse_GuildNotice(int fd, int guild_id, const char *mes1, const char *mes2) |
---|
| 1400 | { |
---|
| 1401 | struct guild *g; |
---|
| 1402 | |
---|
| 1403 | g = (struct guild*)idb_get(guild_db, guild_id); |
---|
| 1404 | if (g == NULL) |
---|
| 1405 | return 0; |
---|
| 1406 | memcpy(g->mes1, mes1, 60); |
---|
| 1407 | memcpy(g->mes2, mes2, 120); |
---|
| 1408 | |
---|
| 1409 | return mapif_guild_notice(g); |
---|
| 1410 | } |
---|
| 1411 | |
---|
| 1412 | // MhGuÏXv |
---|
| 1413 | int mapif_parse_GuildEmblem(int fd, int len, int guild_id, int dummy, const char *data) |
---|
| 1414 | { |
---|
| 1415 | struct guild *g; |
---|
| 1416 | |
---|
| 1417 | g = (struct guild*)idb_get(guild_db, guild_id); |
---|
| 1418 | if (g == NULL) |
---|
| 1419 | return 0; |
---|
| 1420 | memcpy(g->emblem_data, data, len); |
---|
| 1421 | g->emblem_len = len; |
---|
| 1422 | g->emblem_id++; |
---|
| 1423 | |
---|
| 1424 | return mapif_guild_emblem(g); |
---|
| 1425 | } |
---|
| 1426 | |
---|
| 1427 | int mapif_parse_GuildCastleDataLoad(int fd, int castle_id, int index) |
---|
| 1428 | { |
---|
| 1429 | struct guild_castle *gc = (struct guild_castle*)idb_get(castle_db, castle_id); |
---|
| 1430 | |
---|
| 1431 | if (gc == NULL) { |
---|
| 1432 | return mapif_guild_castle_dataload(castle_id, 0, 0); |
---|
| 1433 | } |
---|
| 1434 | switch(index) { |
---|
| 1435 | case 1: return mapif_guild_castle_dataload(gc->castle_id, index, gc->guild_id); |
---|
| 1436 | case 2: return mapif_guild_castle_dataload(gc->castle_id, index, gc->economy); |
---|
| 1437 | case 3: return mapif_guild_castle_dataload(gc->castle_id, index, gc->defense); |
---|
| 1438 | case 4: return mapif_guild_castle_dataload(gc->castle_id, index, gc->triggerE); |
---|
| 1439 | case 5: return mapif_guild_castle_dataload(gc->castle_id, index, gc->triggerD); |
---|
| 1440 | case 6: return mapif_guild_castle_dataload(gc->castle_id, index, gc->nextTime); |
---|
| 1441 | case 7: return mapif_guild_castle_dataload(gc->castle_id, index, gc->payTime); |
---|
| 1442 | case 8: return mapif_guild_castle_dataload(gc->castle_id, index, gc->createTime); |
---|
| 1443 | case 9: return mapif_guild_castle_dataload(gc->castle_id, index, gc->visibleC); |
---|
| 1444 | case 10: |
---|
| 1445 | case 11: |
---|
| 1446 | case 12: |
---|
| 1447 | case 13: |
---|
| 1448 | case 14: |
---|
| 1449 | case 15: |
---|
| 1450 | case 16: |
---|
| 1451 | case 17: |
---|
| 1452 | return mapif_guild_castle_dataload(gc->castle_id, index, gc->guardian[index-10].visible); |
---|
| 1453 | default: |
---|
| 1454 | ShowError("mapif_parse_GuildCastleDataLoad ERROR!! (Not found index=%d)\n", index); |
---|
| 1455 | return 0; |
---|
| 1456 | } |
---|
| 1457 | |
---|
| 1458 | return 0; |
---|
| 1459 | } |
---|
| 1460 | |
---|
| 1461 | int mapif_parse_GuildCastleDataSave(int fd, int castle_id, int index, int value) |
---|
| 1462 | { |
---|
| 1463 | struct guild_castle *gc = (struct guild_castle*)idb_get(castle_db, castle_id); |
---|
| 1464 | |
---|
| 1465 | if (gc == NULL) |
---|
| 1466 | return mapif_guild_castle_datasave(castle_id, index, value); |
---|
| 1467 | |
---|
| 1468 | switch(index) { |
---|
| 1469 | case 1: |
---|
| 1470 | if (gc->guild_id != value) { |
---|
| 1471 | int gid = (value) ? value : gc->guild_id; |
---|
| 1472 | struct guild *g = (struct guild*)idb_get(guild_db, gid); |
---|
| 1473 | if(log_inter) |
---|
| 1474 | inter_log("guild %s (id=%d) %s castle id=%d\n", |
---|
| 1475 | (g) ? g->name : "??", gid, (value) ? "occupy" : "abandon", castle_id); |
---|
| 1476 | } |
---|
| 1477 | gc->guild_id = value; |
---|
| 1478 | if(gc->guild_id == 0) { |
---|
| 1479 | //Delete guardians. |
---|
| 1480 | memset(&gc->guardian, 0, sizeof(gc->guardian)); |
---|
| 1481 | } |
---|
| 1482 | break; |
---|
| 1483 | case 2: gc->economy = value; break; |
---|
| 1484 | case 3: gc->defense = value; break; |
---|
| 1485 | case 4: gc->triggerE = value; break; |
---|
| 1486 | case 5: gc->triggerD = value; break; |
---|
| 1487 | case 6: gc->nextTime = value; break; |
---|
| 1488 | case 7: gc->payTime = value; break; |
---|
| 1489 | case 8: gc->createTime = value; break; |
---|
| 1490 | case 9: gc->visibleC = value; break; |
---|
| 1491 | case 10: |
---|
| 1492 | case 11: |
---|
| 1493 | case 12: |
---|
| 1494 | case 13: |
---|
| 1495 | case 14: |
---|
| 1496 | case 15: |
---|
| 1497 | case 16: |
---|
| 1498 | case 17: |
---|
| 1499 | gc->guardian[index-10].visible = value; break; |
---|
| 1500 | default: |
---|
| 1501 | ShowError("mapif_parse_GuildCastleDataSave ERROR!! (Not found index=%d)\n", index); |
---|
| 1502 | return 0; |
---|
| 1503 | } |
---|
| 1504 | |
---|
| 1505 | return mapif_guild_castle_datasave(gc->castle_id, index, value); |
---|
| 1506 | } |
---|
| 1507 | |
---|
| 1508 | int mapif_parse_GuildMasterChange(int fd, int guild_id, const char* name, int len) |
---|
| 1509 | { |
---|
| 1510 | struct guild *g = (struct guild*)idb_get(guild_db, guild_id); |
---|
| 1511 | struct guild_member gm; |
---|
| 1512 | int pos; |
---|
| 1513 | |
---|
| 1514 | if(g==NULL || g->guild_id<=0 || len > NAME_LENGTH) |
---|
| 1515 | return 0; |
---|
| 1516 | |
---|
| 1517 | for (pos = 0; pos < g->max_member && strncmp(g->member[pos].name, name, len); pos++); |
---|
| 1518 | |
---|
| 1519 | if (pos == g->max_member) |
---|
| 1520 | return 0; //Character not found?? |
---|
| 1521 | |
---|
| 1522 | memcpy(&gm, &g->member[pos], sizeof (struct guild_member)); |
---|
| 1523 | memcpy(&g->member[pos], &g->member[0], sizeof(struct guild_member)); |
---|
| 1524 | memcpy(&g->member[0], &gm, sizeof(struct guild_member)); |
---|
| 1525 | |
---|
| 1526 | g->member[pos].position = g->member[0].position; |
---|
| 1527 | g->member[0].position = 0; //Position 0: guild Master. |
---|
| 1528 | safestrncpy(g->master, name, NAME_LENGTH); |
---|
| 1529 | |
---|
| 1530 | ShowInfo("int_guild: Guildmaster Changed to %s (Guild %d - %s)\n",name, guild_id, g->name); |
---|
| 1531 | return mapif_guild_master_changed(g, g->member[0].account_id, g->member[0].char_id); |
---|
| 1532 | } |
---|
| 1533 | |
---|
| 1534 | // map server ©çÌÊM |
---|
| 1535 | // EPpPbgÌÝðÍ·é±Æ |
---|
| 1536 | // EpPbg·f[^Íinter.cÉZbgµÄ𱯠|
---|
| 1537 | // EpPbg·`FbNâARFIFOSKIPÍÄÑoµ³ÅsíêéÌÅsÁÄÍÈçÈ¢ |
---|
| 1538 | // EG[Èç0(false)A»€ÅÈ¢Èç1(true)𩊳ȯêÎÈçÈ¢ |
---|
| 1539 | int inter_guild_parse_frommap(int fd) |
---|
| 1540 | { |
---|
| 1541 | RFIFOHEAD(fd); |
---|
| 1542 | switch(RFIFOW(fd,0)) { |
---|
| 1543 | case 0x3030: mapif_parse_CreateGuild(fd, RFIFOL(fd,4), (char*)RFIFOP(fd,8), (struct guild_member *)RFIFOP(fd,32)); break; |
---|
| 1544 | case 0x3031: mapif_parse_GuildInfo(fd, RFIFOL(fd,2)); break; |
---|
| 1545 | case 0x3032: mapif_parse_GuildAddMember(fd, RFIFOL(fd,4), (struct guild_member *)RFIFOP(fd,8)); break; |
---|
| 1546 | case 0x3033: mapif_parse_GuildMasterChange(fd,RFIFOL(fd,4),(const char*)RFIFOP(fd,8),RFIFOW(fd,2)-8); break; |
---|
| 1547 | case 0x3034: mapif_parse_GuildLeave(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOB(fd,14), (const char*)RFIFOP(fd,15)); break; |
---|
| 1548 | case 0x3035: mapif_parse_GuildChangeMemberInfoShort(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOB(fd,14), RFIFOW(fd,15), RFIFOW(fd,17)); break; |
---|
| 1549 | case 0x3036: mapif_parse_BreakGuild(fd, RFIFOL(fd,2)); break; |
---|
| 1550 | case 0x3037: mapif_parse_GuildMessage(fd, RFIFOL(fd,4), RFIFOL(fd,8), (char*)RFIFOP(fd,12), RFIFOW(fd,2)-12); break; |
---|
| 1551 | case 0x3039: mapif_parse_GuildBasicInfoChange(fd, RFIFOL(fd,4), RFIFOW(fd,8), (const char*)RFIFOP(fd,10), RFIFOW(fd,2)-10); break; |
---|
| 1552 | case 0x303A: mapif_parse_GuildMemberInfoChange(fd, RFIFOL(fd,4), RFIFOL(fd,8), RFIFOL(fd,12), RFIFOW(fd,16), (const char*)RFIFOP(fd,18), RFIFOW(fd,2)-18); break; |
---|
| 1553 | case 0x303B: mapif_parse_GuildPosition(fd, RFIFOL(fd,4), RFIFOL(fd,8), (struct guild_position *)RFIFOP(fd,12)); break; |
---|
| 1554 | case 0x303C: mapif_parse_GuildSkillUp(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)); break; |
---|
| 1555 | case 0x303D: mapif_parse_GuildAlliance(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOL(fd,14), RFIFOB(fd,18)); break; |
---|
| 1556 | case 0x303E: mapif_parse_GuildNotice(fd, RFIFOL(fd,2), (const char*)RFIFOP(fd,6), (const char*)RFIFOP(fd,66)); break; |
---|
| 1557 | case 0x303F: mapif_parse_GuildEmblem(fd, RFIFOW(fd,2)-12, RFIFOL(fd,4), RFIFOL(fd,8), (const char*)RFIFOP(fd,12)); break; |
---|
| 1558 | case 0x3040: mapif_parse_GuildCastleDataLoad(fd, RFIFOW(fd,2), RFIFOB(fd,4)); break; |
---|
| 1559 | case 0x3041: mapif_parse_GuildCastleDataSave(fd, RFIFOW(fd,2), RFIFOB(fd,4), RFIFOL(fd,5)); break; |
---|
| 1560 | |
---|
| 1561 | default: |
---|
| 1562 | return 0; |
---|
| 1563 | } |
---|
| 1564 | |
---|
| 1565 | return 1; |
---|
| 1566 | } |
---|
| 1567 | |
---|
| 1568 | // processes a mapserver connection event |
---|
| 1569 | int inter_guild_mapif_init(int fd) |
---|
| 1570 | { |
---|
| 1571 | return mapif_guild_castle_alldataload(fd); |
---|
| 1572 | } |
---|
| 1573 | |
---|
| 1574 | // T[o[©çEÞviLípj |
---|
| 1575 | int inter_guild_leave(int guild_id, int account_id, int char_id) |
---|
| 1576 | { |
---|
| 1577 | return mapif_parse_GuildLeave(-1, guild_id, account_id, char_id, 0, "** Character Deleted **"); |
---|
| 1578 | } |
---|
| 1579 | #endif //TXT_SQL_CONVERT |
---|