// Delete member from guild int mapif_parse_GuildLeave(int fd, int guild_id, int account_id, int char_id, int flag, const char *mes) { int i, j; struct guild* g = (struct guild*)idb_get(guild_db, guild_id); if( g == NULL ) { //TODO return 0; } // Find the member ARR_FIND( 0, g->max_member, i, g->member[i].account_id == account_id && g->member[i].char_id == char_id ); if( i == g->max_member ) { //TODO return 0; } if( flag ) { // 追放の場合追放リストに入れる ARR_FIND( 0, MAX_GUILDEXPULSION, j, g->expulsion[j].account_id == 0 ); if (j == MAX_GUILDEXPULSION) { // 一杯なので古いのを消す for(j = 0; j < MAX_GUILDEXPULSION - 1; j++) g->expulsion[j] = g->expulsion[j+1]; j = MAX_GUILDEXPULSION - 1; } // Save the expulsion entry g->expulsion[j].account_id = account_id; safestrncpy(g->expulsion[j].name, g->member[i].name, NAME_LENGTH); safestrncpy(g->expulsion[j].mes, mes, 40); } mapif_guild_withdraw(guild_id, account_id, char_id, flag, g->member[i].name, mes); memset(&g->member[i], 0, sizeof(struct guild_member)); if (guild_check_empty(g) == 0) mapif_guild_info(-1,g);// まだ人がいるのでデ??送信 return 0; }
// ギルド脱退/追放要求 int mapif_parse_GuildLeave(int fd, int guild_id, int account_id, int char_id, int flag, const char *mes) { struct guild *g = NULL; int i, j; g = idb_get(guild_db, guild_id); if (g != NULL) { for(i = 0; i < MAX_GUILD; i++) { if (g->member[i].account_id == account_id && g->member[i].char_id == char_id) { // printf("%d %d\n", i, (int)(&g->member[i])); // printf("%d %s\n", i, g->member[i].name); if (flag) { // 追放の場合追放リストに入れる for(j = 0; j < MAX_GUILDEXPULSION; j++) { if (g->expulsion[j].account_id == 0) break; } if (j == MAX_GUILDEXPULSION) { // 一杯なので古いのを消す for(j = 0; j < MAX_GUILDEXPULSION - 1; j++) g->expulsion[j] = g->expulsion[j+1]; j = MAX_GUILDEXPULSION - 1; } g->expulsion[j].account_id = account_id; memcpy(g->expulsion[j].acc, "dummy", NAME_LENGTH-1); memcpy(g->expulsion[j].name, g->member[i].name, NAME_LENGTH-1); memcpy(g->expulsion[j].mes, mes, 40); } mapif_guild_leaved(guild_id, account_id, char_id, flag, g->member[i].name, mes); // printf("%d %d\n", i, (int)(&g->member[i])); // printf("%d %s\n", i, (&g->member[i])->name); memset(&g->member[i], 0, sizeof(struct guild_member)); if (guild_check_empty(g) == 0) mapif_guild_info(-1,g);// まだ人がいるのでデータ送信 return 0; } } } return 0; }
// ギルドデータの読み込み int inter_guild_init() { char line[16384]; struct guild *g; struct guild_castle *gc; FILE *fp; int i, j, c = 0; inter_guild_readdb(); guild_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int)); castle_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int)); if ((fp = fopen(guild_txt,"r")) == NULL) return 1; while(fgets(line, sizeof(line)-1, fp)) { j = 0; if (sscanf(line, "%d\t%%newid%%\n%n", &i, &j) == 1 && j > 0 && guild_newid <= i) { guild_newid = i; continue; } g = (struct guild *) aCalloc(sizeof(struct guild), 1); if(g == NULL){ ShowFatalError("int_guild: out of memory!\n"); exit(0); } // memset(g, 0, sizeof(struct guild)); not needed... if (inter_guild_fromstr(line, g) == 0 && g->guild_id > 0) { if (g->guild_id >= guild_newid) guild_newid = g->guild_id + 1; idb_put(guild_db, g->guild_id, g); guild_check_empty(g); guild_calcinfo(g); } else { ShowError("int_guild: broken data [%s] line %d\n", guild_txt, c); aFree(g); } c++; } fclose(fp); // printf("int_guild: %s read done (%d guilds)\n", guild_txt, c); c = 0;//カウンタ初期化 if ((fp = fopen(castle_txt, "r")) == NULL) { return 1; } while(fgets(line, sizeof(line)-1, fp)) { gc = (struct guild_castle *) aCalloc(sizeof(struct guild_castle), 1); if(gc == NULL){ ShowFatalError("int_guild: out of memory!\n"); exit(0); } // memset(gc, 0, sizeof(struct guild_castle)); No need... if (inter_guildcastle_fromstr(line, gc) == 0) { idb_put(castle_db, gc->castle_id, gc); } else { ShowError("int_guild: broken data [%s] line %d\n", castle_txt, c); aFree(gc); } c++; } if (!c) { ShowStatus(" %s - making Default Data...\n", castle_txt); //デフォルトデータを作成 for(i = 0; i < MAX_GUILDCASTLE; i++) { gc = (struct guild_castle *) aCalloc(sizeof(struct guild_castle), 1); if (gc == NULL) { ShowFatalError("int_guild: out of memory!\n"); exit(0); } gc->castle_id = i; idb_put(castle_db, gc->castle_id, gc); } ShowStatus(" %s - making done\n",castle_txt); return 0; } fclose(fp); return 0; }