Some more tweaks to the guild code

- unrolling of foreach()/_sub() pairs using db iterators
- usage of ARR_FIND instead of for()/break;
- old function header adjustment

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@11896 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
ultramage 2007-12-12 14:18:46 +00:00
parent 8be1c4d48c
commit 2af4a7f61b
2 changed files with 298 additions and 252 deletions

View File

@ -29,9 +29,8 @@ static int guild_newid = 10000;
static unsigned int guild_exp[100]; static unsigned int guild_exp[100];
int mapif_parse_GuildLeave(int fd, int guild_id, int account_id, int char_id, int flag, const char *mes);
int mapif_guild_broken(int guild_id, int flag); int mapif_guild_broken(int guild_id, int flag);
bool guild_check_empty(struct guild *g); static bool guild_check_empty(struct guild *g);
int guild_calcinfo(struct guild *g); int guild_calcinfo(struct guild *g);
int mapif_guild_basicinfochanged(int guild_id, int type, const void *data, int len); int mapif_guild_basicinfochanged(int guild_id, int type, const void *data, int len);
int mapif_guild_info(int fd, struct guild *g); int mapif_guild_info(int fd, struct guild *g);
@ -306,7 +305,8 @@ int inter_guild_fromstr(char* str, struct guild* g)
#ifndef TXT_SQL_CONVERT #ifndef TXT_SQL_CONVERT
// ギルド城データの文字列への変換 // ギルド城データの文字列への変換
int inter_guildcastle_tostr(char *str, struct guild_castle *gc) { int inter_guildcastle_tostr(char *str, struct guild_castle *gc)
{
int len; int len;
len = sprintf(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", // added Guardian HP [Valaris] len = sprintf(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", // added Guardian HP [Valaris]
@ -320,8 +320,10 @@ int inter_guildcastle_tostr(char *str, struct guild_castle *gc) {
return 0; return 0;
} }
#endif ///TXT_SQL_CONVERT #endif ///TXT_SQL_CONVERT
// ギルド城データの文字列からの変換 // ギルド城データの文字列からの変換
int inter_guildcastle_fromstr(char *str, struct guild_castle *gc) { int inter_guildcastle_fromstr(char *str, struct guild_castle *gc)
{
int tmp_int[26]; int tmp_int[26];
memset(gc, 0, sizeof(struct guild_castle)); memset(gc, 0, sizeof(struct guild_castle));
@ -396,9 +398,11 @@ int inter_guildcastle_fromstr(char *str, struct guild_castle *gc) {
return 0; return 0;
} }
#ifndef TXT_SQL_CONVERT #ifndef TXT_SQL_CONVERT
// ギルド関連データベース読み込み // ギルド関連データベース読み込み
int inter_guild_readdb(void) { int inter_guild_readdb(void)
{
int i; int i;
FILE *fp; FILE *fp;
char line[1024]; char line[1024];
@ -424,7 +428,8 @@ int inter_guild_readdb(void) {
} }
// ギルドデータの読み込み // ギルドデータの読み込み
int inter_guild_init() { int inter_guild_init()
{
char line[16384]; char line[16384];
struct guild *g; struct guild *g;
struct guild_castle *gc; struct guild_castle *gc;
@ -511,79 +516,79 @@ int inter_guild_init() {
return 0; return 0;
} }
void inter_guild_final() { void inter_guild_final()
{
castle_db->destroy(castle_db, NULL); castle_db->destroy(castle_db, NULL);
guild_db->destroy(guild_db, NULL); guild_db->destroy(guild_db, NULL);
return; return;
} }
struct guild *inter_guild_search(int guild_id) { struct guild *inter_guild_search(int guild_id)
{
return idb_get(guild_db, guild_id); return idb_get(guild_db, guild_id);
} }
// ギルドデータのセーブ用
int inter_guild_save_sub(DBKey key,void *data,va_list ap) {
char line[16384];
FILE *fp;
inter_guild_tostr(line,(struct guild *)data);
fp=va_arg(ap,FILE *);
fprintf(fp,"%s\n",line);
return 0;
}
// ギルド城データのセーブ用
int inter_castle_save_sub(DBKey key, void *data, va_list ap) {
char line[16384];
FILE *fp;
inter_guildcastle_tostr(line, (struct guild_castle *)data);
fp = va_arg(ap, FILE *);
fprintf(fp, "%s\n", line);
return 0;
}
// ギルドデータのセーブ // ギルドデータのセーブ
int inter_guild_save() { int inter_guild_save()
{
FILE *fp; FILE *fp;
int lock; int lock;
DBIterator* iter;
struct guild* g;
struct guild_castle* gc;
// save guild data
if ((fp = lock_fopen(guild_txt, &lock)) == NULL) { if ((fp = lock_fopen(guild_txt, &lock)) == NULL) {
ShowError("int_guild: can't write [%s] !!! data is lost !!!\n", guild_txt); ShowError("int_guild: can't write [%s] !!! data is lost !!!\n", guild_txt);
return 1; return 1;
} }
guild_db->foreach(guild_db, inter_guild_save_sub, fp);
iter = guild_db->iterator(guild_db);
for( g = iter->first(iter,NULL); iter->exists(iter); g = iter->next(iter,NULL) )
{
char line[16384];
inter_guild_tostr(line, g);
fprintf(fp, "%s\n", line);
}
iter->destroy(iter);
// fprintf(fp, "%d\t%%newid%%\n", guild_newid); // fprintf(fp, "%d\t%%newid%%\n", guild_newid);
lock_fclose(fp, guild_txt, &lock); lock_fclose(fp, guild_txt, &lock);
// save castle data
if ((fp = lock_fopen(castle_txt,&lock)) == NULL) { if ((fp = lock_fopen(castle_txt,&lock)) == NULL) {
ShowError("int_guild: can't write [%s] !!! data is lost !!!\n", castle_txt); ShowError("int_guild: can't write [%s] !!! data is lost !!!\n", castle_txt);
return 1; return 1;
} }
castle_db->foreach(castle_db, inter_castle_save_sub, fp);
iter = castle_db->iterator(castle_db);
for( gc = iter->first(iter,NULL); iter->exists(iter); gc = iter->next(iter,NULL) )
{
char line[16384];
inter_guildcastle_tostr(line, gc);
fprintf(fp, "%s\n", line);
}
iter->destroy(iter);
lock_fclose(fp, castle_txt, &lock); lock_fclose(fp, castle_txt, &lock);
return 0; return 0;
} }
// ギルド名検索用
int search_guildname_sub(DBKey key, void *data, va_list ap) {
struct guild *g = (struct guild *)data, **dst;
char *str;
str = va_arg(ap, char *);
dst = va_arg(ap, struct guild **);
if (strcmpi(g->name, str) == 0)
*dst = g;
return 0;
}
// ギルド名検索 // ギルド名検索
struct guild* search_guildname(char *str) { struct guild* search_guildname(char *str)
struct guild *g = NULL; {
guild_db->foreach(guild_db, search_guildname_sub, str, &g); DBIterator* iter;
struct guild* g;
iter = guild_db->iterator(guild_db);
for( g = iter->first(iter,NULL); iter->exists(iter); g = iter->next(iter,NULL) )
{
if (strcmpi(g->name, str) == 0)
break;
}
iter->destroy(iter);
return g; return g;
} }
@ -603,7 +608,7 @@ static bool guild_check_empty(struct guild *g)
return true; return true;
} }
unsigned int guild_nextexp (int level) unsigned int guild_nextexp(int level)
{ {
if (level == 0) if (level == 0)
return 1; return 1;
@ -614,7 +619,8 @@ unsigned int guild_nextexp (int level)
} }
// ギルドスキルがあるか確認 // ギルドスキルがあるか確認
int guild_checkskill(struct guild *g, int id) { int guild_checkskill(struct guild *g, int id)
{
int idx = id - GD_SKILLBASE; int idx = id - GD_SKILLBASE;
@ -626,7 +632,8 @@ int guild_checkskill(struct guild *g, int id) {
} }
// ギルドの情報の再計算 // ギルドの情報の再計算
int guild_calcinfo(struct guild *g) { int guild_calcinfo(struct guild *g)
{
int i, c; int i, c;
unsigned int nextexp; unsigned int nextexp;
struct guild before = *g; struct guild before = *g;
@ -688,7 +695,8 @@ int guild_calcinfo(struct guild *g) {
// map serverへの通信 // map serverへの通信
// ギルド作成可否 // ギルド作成可否
int mapif_guild_created(int fd, int account_id, struct guild *g) { int mapif_guild_created(int fd, int account_id, struct guild *g)
{
WFIFOHEAD(fd, 10); WFIFOHEAD(fd, 10);
WFIFOW(fd,0) = 0x3830; WFIFOW(fd,0) = 0x3830;
WFIFOL(fd,2) = account_id; WFIFOL(fd,2) = account_id;
@ -703,7 +711,8 @@ int mapif_guild_created(int fd, int account_id, struct guild *g) {
} }
// ギルド情報見つからず // ギルド情報見つからず
int mapif_guild_noinfo(int fd, int guild_id) { int mapif_guild_noinfo(int fd, int guild_id)
{
WFIFOHEAD(fd, 8); WFIFOHEAD(fd, 8);
WFIFOW(fd,0) = 0x3831; WFIFOW(fd,0) = 0x3831;
WFIFOW(fd,2) = 8; WFIFOW(fd,2) = 8;
@ -715,24 +724,24 @@ int mapif_guild_noinfo(int fd, int guild_id) {
} }
// ギルド情報まとめ送り // ギルド情報まとめ送り
int mapif_guild_info(int fd, struct guild *g) { int mapif_guild_info(int fd, struct guild *g)
{
unsigned char buf[8+sizeof(struct guild)]; unsigned char buf[8+sizeof(struct guild)];
WBUFW(buf,0) = 0x3831; WBUFW(buf,0) = 0x3831;
memcpy(buf + 4, g, sizeof(struct guild)); memcpy(buf + 4, g, sizeof(struct guild));
WBUFW(buf,2) = 4 + sizeof(struct guild); WBUFW(buf,2) = 4 + sizeof(struct guild);
// printf("int_guild: sizeof(guild)=%d\n", sizeof(struct guild));
if (fd < 0) if (fd < 0)
mapif_sendall(buf, WBUFW(buf,2)); mapif_sendall(buf, WBUFW(buf,2));
else else
mapif_send(fd, buf, WBUFW(buf,2)); mapif_send(fd, buf, WBUFW(buf,2));
// printf("int_guild: info %d %s\n", p->guild_id, p->name);
return 0; return 0;
} }
// メンバ追加可否 // メンバ追加可否
int mapif_guild_memberadded(int fd, int guild_id, int account_id, int char_id, int flag) { int mapif_guild_memberadded(int fd, int guild_id, int account_id, int char_id, int flag)
{
WFIFOHEAD(fd, 15); WFIFOHEAD(fd, 15);
WFIFOW(fd,0) = 0x3832; WFIFOW(fd,0) = 0x3832;
WFIFOL(fd,2) = guild_id; WFIFOL(fd,2) = guild_id;
@ -745,7 +754,8 @@ int mapif_guild_memberadded(int fd, int guild_id, int account_id, int char_id, i
} }
// 脱退/追放通知 // 脱退/追放通知
int mapif_guild_leaved(int guild_id, int account_id, int char_id, int flag, const char *name, const char *mes) { int mapif_guild_leaved(int guild_id, int account_id, int char_id, int flag, const char *name, const char *mes)
{
unsigned char buf[79]; unsigned char buf[79];
WBUFW(buf, 0) = 0x3834; WBUFW(buf, 0) = 0x3834;
@ -763,7 +773,8 @@ int mapif_guild_leaved(int guild_id, int account_id, int char_id, int flag, cons
} }
// オンライン状態とLv更新通知 // オンライン状態とLv更新通知
int mapif_guild_memberinfoshort(struct guild *g, int idx) { int mapif_guild_memberinfoshort(struct guild *g, int idx)
{
unsigned char buf[19]; unsigned char buf[19];
WBUFW(buf, 0) = 0x3835; WBUFW(buf, 0) = 0x3835;
@ -778,7 +789,8 @@ int mapif_guild_memberinfoshort(struct guild *g, int idx) {
} }
// 解散通知 // 解散通知
int mapif_guild_broken(int guild_id, int flag) { int mapif_guild_broken(int guild_id, int flag)
{
unsigned char buf[7]; unsigned char buf[7];
WBUFW(buf,0) = 0x3836; WBUFW(buf,0) = 0x3836;
@ -791,7 +803,8 @@ int mapif_guild_broken(int guild_id, int flag) {
} }
// ギルド内発言 // ギルド内発言
int mapif_guild_message(int guild_id, int account_id, char *mes, int len, int sfd) { int mapif_guild_message(int guild_id, int account_id, char *mes, int len, int sfd)
{
unsigned char buf[2048]; unsigned char buf[2048];
WBUFW(buf,0) = 0x3837; WBUFW(buf,0) = 0x3837;
@ -805,7 +818,8 @@ int mapif_guild_message(int guild_id, int account_id, char *mes, int len, int sf
} }
// ギルド基本情報変更通知 // ギルド基本情報変更通知
int mapif_guild_basicinfochanged(int guild_id, int type, const void *data, int len) { int mapif_guild_basicinfochanged(int guild_id, int type, const void *data, int len)
{
unsigned char buf[2048]; unsigned char buf[2048];
WBUFW(buf,0) = 0x3839; WBUFW(buf,0) = 0x3839;
@ -818,7 +832,8 @@ int mapif_guild_basicinfochanged(int guild_id, int type, const void *data, int l
} }
// ギルドメンバ情報変更通知 // ギルドメンバ情報変更通知
int mapif_guild_memberinfochanged(int guild_id, int account_id, int char_id, int type, const void *data, int len) { int mapif_guild_memberinfochanged(int guild_id, int account_id, int char_id, int type, const void *data, int len)
{
unsigned char buf[4096]; unsigned char buf[4096];
WBUFW(buf, 0) = 0x383a; WBUFW(buf, 0) = 0x383a;
@ -834,7 +849,8 @@ int mapif_guild_memberinfochanged(int guild_id, int account_id, int char_id, int
} }
// ギルドスキルアップ通知 // ギルドスキルアップ通知
int mapif_guild_skillupack(int guild_id, int skill_num, int account_id) { int mapif_guild_skillupack(int guild_id, int skill_num, int account_id)
{
unsigned char buf[14]; unsigned char buf[14];
WBUFW(buf, 0) = 0x383c; WBUFW(buf, 0) = 0x383c;
@ -847,7 +863,8 @@ int mapif_guild_skillupack(int guild_id, int skill_num, int account_id) {
} }
// ギルド同盟/敵対通知 // ギルド同盟/敵対通知
int mapif_guild_alliance(int guild_id1, int guild_id2, int account_id1, int account_id2, int flag, const char *name1, const char *name2) { int mapif_guild_alliance(int guild_id1, int guild_id2, int account_id1, int account_id2, int flag, const char *name1, const char *name2)
{
unsigned char buf[67]; unsigned char buf[67];
WBUFW(buf, 0) = 0x383d; WBUFW(buf, 0) = 0x383d;
@ -867,7 +884,8 @@ int mapif_guild_alliance(int guild_id1, int guild_id2, int account_id1, int acco
} }
// ギルド役職変更通知 // ギルド役職変更通知
int mapif_guild_position(struct guild *g, int idx) { int mapif_guild_position(struct guild *g, int idx)
{
unsigned char buf[2048]; unsigned char buf[2048];
WBUFW(buf,0) = 0x383b; WBUFW(buf,0) = 0x383b;
@ -881,7 +899,8 @@ int mapif_guild_position(struct guild *g, int idx) {
} }
// ギルド告知変更通知 // ギルド告知変更通知
int mapif_guild_notice(struct guild *g) { int mapif_guild_notice(struct guild *g)
{
unsigned char buf[186]; unsigned char buf[186];
WBUFW(buf,0) = 0x383e; WBUFW(buf,0) = 0x383e;
@ -894,7 +913,8 @@ int mapif_guild_notice(struct guild *g) {
} }
// ギルドエンブレム変更通知 // ギルドエンブレム変更通知
int mapif_guild_emblem(struct guild *g) { int mapif_guild_emblem(struct guild *g)
{
unsigned char buf[2048]; unsigned char buf[2048];
WBUFW(buf,0) = 0x383f; WBUFW(buf,0) = 0x383f;
@ -918,7 +938,8 @@ int mapif_guild_master_changed(struct guild *g, int aid, int cid)
return 0; return 0;
} }
int mapif_guild_castle_dataload(int castle_id, int index, int value) { int mapif_guild_castle_dataload(int castle_id, int index, int value)
{
unsigned char buf[9]; unsigned char buf[9];
WBUFW(buf,0) = 0x3840; WBUFW(buf,0) = 0x3840;
@ -930,7 +951,8 @@ int mapif_guild_castle_dataload(int castle_id, int index, int value) {
return 0; return 0;
} }
int mapif_guild_castle_datasave(int castle_id, int index, int value) { int mapif_guild_castle_datasave(int castle_id, int index, int value)
{
unsigned char buf[9]; unsigned char buf[9];
WBUFW(buf,0) = 0x3841; WBUFW(buf,0) = 0x3841;
@ -942,23 +964,30 @@ int mapif_guild_castle_datasave(int castle_id, int index, int value) {
return 0; return 0;
} }
int mapif_guild_castle_alldataload_sub(DBKey key, void *data, va_list ap) { int mapif_guild_castle_alldataload_sub(DBKey key, void *data, va_list ap)
{
int fd = va_arg(ap, int); int fd = va_arg(ap, int);
int *p = va_arg(ap, int*); int *p = va_arg(ap, int*);
WFIFOHEAD(fd, sizeof(struct guild_castle));
memcpy(WFIFOP(fd,*p), (struct guild_castle*)data, sizeof(struct guild_castle));
(*p) += sizeof(struct guild_castle);
return 0; return 0;
} }
int mapif_guild_castle_alldataload(int fd) { int mapif_guild_castle_alldataload(int fd)
{
DBIterator* iter;
struct guild_castle* gc;
int len = 4; int len = 4;
WFIFOHEAD(fd, 0); WFIFOHEAD(fd, 4 + MAX_GUILDCASTLE*sizeof(struct guild_castle));
WFIFOW(fd,0) = 0x3842; WFIFOW(fd,0) = 0x3842;
castle_db->foreach(castle_db, mapif_guild_castle_alldataload_sub, fd, &len); iter = castle_db->iterator(castle_db);
for( gc = iter->first(iter,NULL); iter->exists(iter); gc = iter->next(iter,NULL) )
{
memcpy(WFIFOP(fd,len), gc, sizeof(struct guild_castle));
len += sizeof(struct guild_castle);
}
iter->destroy(iter);
WFIFOW(fd,2) = len; WFIFOW(fd,2) = len;
WFIFOSET(fd, len); WFIFOSET(fd, len);
@ -969,7 +998,8 @@ int mapif_guild_castle_alldataload(int fd) {
// map serverからの通信 // map serverからの通信
// ギルド作成要求 // ギルド作成要求
int mapif_parse_CreateGuild(int fd, int account_id, char *name, struct guild_member *master) { int mapif_parse_CreateGuild(int fd, int account_id, char *name, struct guild_member *master)
{
struct guild *g; struct guild *g;
int i; int i;
@ -1039,7 +1069,8 @@ int mapif_parse_CreateGuild(int fd, int account_id, char *name, struct guild_mem
} }
// ギルド情報要求 // ギルド情報要求
int mapif_parse_GuildInfo(int fd, int guild_id) { int mapif_parse_GuildInfo(int fd, int guild_id)
{
struct guild *g; struct guild *g;
g = idb_get(guild_db, guild_id); g = idb_get(guild_db, guild_id);
@ -1053,7 +1084,8 @@ int mapif_parse_GuildInfo(int fd, int guild_id) {
} }
// ギルドメンバ追加要求 // ギルドメンバ追加要求
int mapif_parse_GuildAddMember(int fd, int guild_id, struct guild_member *m) { int mapif_parse_GuildAddMember(int fd, int guild_id, struct guild_member *m)
{
struct guild *g; struct guild *g;
int i; int i;
@ -1063,16 +1095,15 @@ int mapif_parse_GuildAddMember(int fd, int guild_id, struct guild_member *m) {
return 0; return 0;
} }
for(i = 0; i < g->max_member; i++) { ARR_FIND( 0, g->max_member, i, g->member[i].account_id == 0 );
if (g->member[i].account_id == 0) { if( i < g->max_member )
{
memcpy(&g->member[i], m, sizeof(struct guild_member)); memcpy(&g->member[i], m, sizeof(struct guild_member));
mapif_guild_memberadded(fd, guild_id, m->account_id, m->char_id, 0); mapif_guild_memberadded(fd, guild_id, m->account_id, m->char_id, 0);
guild_calcinfo(g); guild_calcinfo(g);
mapif_guild_info(-1, g); mapif_guild_info(-1, g);
return 0;
}
} }
else
mapif_guild_memberadded(fd, guild_id, m->account_id, m->char_id, 1); mapif_guild_memberadded(fd, guild_id, m->account_id, m->char_id, 1);
return 0; return 0;
@ -1124,42 +1155,51 @@ int mapif_parse_GuildLeave(int fd, int guild_id, int account_id, int char_id, in
} }
// オンライン/Lv更新 // オンライン/Lv更新
int mapif_parse_GuildChangeMemberInfoShort(int fd, int guild_id, int account_id, int char_id, int online, int lv, int class_) { int mapif_parse_GuildChangeMemberInfoShort(int fd, int guild_id, int account_id, int char_id, int online, int lv, int class_)
{
struct guild *g; struct guild *g;
int i, alv, c; int i, sum, c;
g = idb_get(guild_db, guild_id); g = idb_get(guild_db, guild_id);
if (g == NULL) if (g == NULL)
return 0; return 0;
g->connect_member = 0; 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 )
alv = 0; {
c = 0;
for(i = 0; i < MAX_GUILD; i++) {
if (g->member[i].account_id == account_id && g->member[i].char_id == char_id) {
g->member[i].online = online; g->member[i].online = online;
g->member[i].lv = lv; g->member[i].lv = lv;
g->member[i].class_ = class_; g->member[i].class_ = class_;
mapif_guild_memberinfoshort(g, i); mapif_guild_memberinfoshort(g, i);
} }
if (g->member[i].account_id > 0) {
alv += g->member[i].lv; g->average_lv = 0;
g->connect_member = 0;
c = 0; // member count
sum = 0; // total sum of base levels
for(i = 0; i < g->max_member; i++)
{
if( g->member[i].account_id > 0 )
{
sum += g->member[i].lv;
c++; c++;
} }
if (g->member[i].online) if( g->member[i].online )
g->connect_member++; g->connect_member++;
} }
if (c) if( c ) // this check should always succeed...
// 平均レベル g->average_lv = sum / c;
g->average_lv = alv / c;
//FIXME: how about sending a mapif_guild_info() update to the mapserver? [ultramage]
return 0; return 0;
} }
// ギルド解散処理用(同盟/敵対を解除) // ギルド解散処理用(同盟/敵対を解除)
int guild_break_sub(DBKey key, void *data, va_list ap) { int guild_break_sub(DBKey key, void *data, va_list ap)
{
struct guild *g = (struct guild *)data; struct guild *g = (struct guild *)data;
int guild_id = va_arg(ap, int); int guild_id = va_arg(ap, int);
int i; int i;
@ -1172,7 +1212,8 @@ int guild_break_sub(DBKey key, void *data, va_list ap) {
} }
// ギルド解散要求 // ギルド解散要求
int mapif_parse_BreakGuild(int fd, int guild_id) { int mapif_parse_BreakGuild(int fd, int guild_id)
{
struct guild *g; struct guild *g;
g = idb_get(guild_db, guild_id); g = idb_get(guild_db, guild_id);
@ -1191,12 +1232,14 @@ int mapif_parse_BreakGuild(int fd, int guild_id) {
} }
// ギルドメッセージ送信 // ギルドメッセージ送信
int mapif_parse_GuildMessage(int fd, int guild_id, int account_id, char *mes, int len) { int mapif_parse_GuildMessage(int fd, int guild_id, int account_id, char *mes, int len)
{
return mapif_guild_message(guild_id, account_id, mes, len, fd); return mapif_guild_message(guild_id, account_id, mes, len, fd);
} }
// ギルド基本データ変更要求 // ギルド基本データ変更要求
int mapif_parse_GuildBasicInfoChange(int fd, int guild_id, int type, const char *data, int len) { int mapif_parse_GuildBasicInfoChange(int fd, int guild_id, int type, const char *data, int len)
{
struct guild *g; struct guild *g;
short dw = *((short *)data); short dw = *((short *)data);
@ -1223,7 +1266,8 @@ int mapif_parse_GuildBasicInfoChange(int fd, int guild_id, int type, const char
} }
// ギルドメンバデータ変更要求 // ギルドメンバデータ変更要求
int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int char_id, int type, const char *data, int len) { int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int char_id, int type, const char *data, int len)
{
int i; int i;
struct guild *g; struct guild *g;
@ -1306,7 +1350,8 @@ int inter_guild_sex_changed(int guild_id,int account_id,int char_id, int gender)
} }
// ギルド役職名変更要求 // ギルド役職名変更要求
int mapif_parse_GuildPosition(int fd, int guild_id, int idx, struct guild_position *p) { int mapif_parse_GuildPosition(int fd, int guild_id, int idx, struct guild_position *p)
{
struct guild *g = idb_get(guild_db, guild_id); struct guild *g = idb_get(guild_db, guild_id);
if (g == NULL || idx < 0 || idx >= MAX_GUILDPOSITION) { if (g == NULL || idx < 0 || idx >= MAX_GUILDPOSITION) {
@ -1320,7 +1365,8 @@ int mapif_parse_GuildPosition(int fd, int guild_id, int idx, struct guild_positi
} }
// ギルドスキルアップ要求 // ギルドスキルアップ要求
int mapif_parse_GuildSkillUp(int fd, int guild_id, int skill_num, int account_id) { int mapif_parse_GuildSkillUp(int fd, int guild_id, int skill_num, int account_id)
{
struct guild *g = idb_get(guild_db, guild_id); struct guild *g = idb_get(guild_db, guild_id);
int idx = skill_num - GD_SKILLBASE; int idx = skill_num - GD_SKILLBASE;
@ -1356,8 +1402,10 @@ static int mapif_parse_GuildDeleteAlliance(struct guild *g, int guild_id, int ac
mapif_guild_alliance(g->guild_id,guild_id,account_id1,account_id2,flag,g->name,name); mapif_guild_alliance(g->guild_id,guild_id,account_id1,account_id2,flag,g->name,name);
return 0; return 0;
} }
// ギルド同盟要求 // ギルド同盟要求
int mapif_parse_GuildAlliance(int fd, int guild_id1, int guild_id2, int account_id1, int account_id2, int flag) { int mapif_parse_GuildAlliance(int fd, int guild_id1, int guild_id2, int account_id1, int account_id2, int flag)
{
struct guild *g[2]; struct guild *g[2];
int j, i; int j, i;
@ -1396,7 +1444,8 @@ int mapif_parse_GuildAlliance(int fd, int guild_id1, int guild_id2, int account_
} }
// ギルド告知変更要求 // ギルド告知変更要求
int mapif_parse_GuildNotice(int fd, int guild_id, const char *mes1, const char *mes2) { int mapif_parse_GuildNotice(int fd, int guild_id, const char *mes1, const char *mes2)
{
struct guild *g; struct guild *g;
g = idb_get(guild_db, guild_id); g = idb_get(guild_db, guild_id);
@ -1409,7 +1458,8 @@ int mapif_parse_GuildNotice(int fd, int guild_id, const char *mes1, const char *
} }
// ギルドエンブレム変更要求 // ギルドエンブレム変更要求
int mapif_parse_GuildEmblem(int fd, int len, int guild_id, int dummy, const char *data) { int mapif_parse_GuildEmblem(int fd, int len, int guild_id, int dummy, const char *data)
{
struct guild *g; struct guild *g;
g = idb_get(guild_db, guild_id); g = idb_get(guild_db, guild_id);
@ -1422,7 +1472,8 @@ int mapif_parse_GuildEmblem(int fd, int len, int guild_id, int dummy, const char
return mapif_guild_emblem(g); return mapif_guild_emblem(g);
} }
int mapif_parse_GuildCastleDataLoad(int fd, int castle_id, int index) { int mapif_parse_GuildCastleDataLoad(int fd, int castle_id, int index)
{
struct guild_castle *gc = idb_get(castle_db, castle_id); struct guild_castle *gc = idb_get(castle_db, castle_id);
if (gc == NULL) { if (gc == NULL) {

View File

@ -40,48 +40,54 @@ static unsigned int guild_exp[100];
int mapif_parse_GuildLeave(int fd,int guild_id,int account_id,int char_id,int flag,const char *mes); int mapif_parse_GuildLeave(int fd,int guild_id,int account_id,int char_id,int flag,const char *mes);
int mapif_guild_broken(int guild_id,int flag); int mapif_guild_broken(int guild_id,int flag);
bool guild_check_empty(struct guild *g); static bool guild_check_empty(struct guild *g);
int guild_calcinfo(struct guild *g); int guild_calcinfo(struct guild *g);
int mapif_guild_basicinfochanged(int guild_id,int type,const void *data,int len); int mapif_guild_basicinfochanged(int guild_id,int type,const void *data,int len);
int mapif_guild_info(int fd,struct guild *g); int mapif_guild_info(int fd,struct guild *g);
int guild_break_sub(int key,void *data,va_list ap); int guild_break_sub(int key,void *data,va_list ap);
int inter_guild_tosql(struct guild *g,int flag); int inter_guild_tosql(struct guild *g,int flag);
static int guild_save(DBKey key, void *data, va_list ap) { static int guild_save_timer(int tid, unsigned int tick, int id, int data)
struct guild *g = (struct guild*) data; {
int *last_id = va_arg(ap, int *); static int last_id = 0; //To know in which guild we were.
int *state = va_arg(ap, int *); int state = 0; //0: Have not reached last guild. 1: Reached last guild, ready for save. 2: Some guild saved, don't do further saving.
DBIterator* iter;
DBKey key;
struct guild* g;
if ((*state) == 0 && g->guild_id == (*last_id)) if( last_id == 0 ) //Save the first guild in the list.
(*state)++; //Save next guild in the list. state = 1;
else if (g->save_flag&GS_MASK && (*state) == 1) {
iter = guild_db_->iterator(guild_db_);
for( g = iter->first(iter,&key); iter->exists(iter); g = iter->next(iter,&key) )
{
if( state == 0 && g->guild_id == last_id )
state++; //Save next guild in the list.
else
if( state == 1 && g->save_flag&GS_MASK )
{
inter_guild_tosql(g, g->save_flag&GS_MASK); inter_guild_tosql(g, g->save_flag&GS_MASK);
g->save_flag &= ~GS_MASK; g->save_flag &= ~GS_MASK;
//Some guild saved. //Some guild saved.
(*last_id) = g->guild_id; last_id = g->guild_id;
(*state)++; state++;
} }
if(g->save_flag == GS_REMOVE) { //Nothing to save, guild is ready for removal. if( g->save_flag == GS_REMOVE )
{// Nothing to save, guild is ready for removal.
if (save_log) if (save_log)
ShowInfo("Guild Unloaded (%d - %s)\n", g->guild_id, g->name); ShowInfo("Guild Unloaded (%d - %s)\n", g->guild_id, g->name);
db_remove(guild_db_, key); db_remove(guild_db_, key);
} }
return 0; }
} iter->destroy(iter);
static int guild_save_timer(int tid, unsigned int tick, int id, int data) { if( state != 2 ) //Reached the end of the guild db without saving.
static int last_id = 0; //To know in which guild we were.
int state = 0; //0: Have not reached last guild. 1: Reached last guild, ready for save. 2: Some guild saved, don't do further saving.
if (!last_id) //Save the first guild in the list.
state = 1;
guild_db_->foreach(guild_db_, guild_save, &last_id, &state);
if (state != 2) //Reached the end of the guild db without saving.
last_id = 0; //Reset guild saved, return to beginning. last_id = 0; //Reset guild saved, return to beginning.
state = guild_db_->size(guild_db_); state = guild_db_->size(guild_db_);
if (state < 1) state = 1; //Calculate the time slot for the next save. if( state < 1 ) state = 1; //Calculate the time slot for the next save.
add_timer(tick + autosave_interval/state, guild_save_timer, 0, 0); add_timer(tick + autosave_interval/state, guild_save_timer, 0, 0);
return 0; return 0;
} }
@ -95,6 +101,7 @@ int inter_guild_removemember_tosql(int account_id, int char_id)
return 0; return 0;
} }
#endif //TXT_SQL_CONVERT #endif //TXT_SQL_CONVERT
// Save guild into sql // Save guild into sql
int inter_guild_tosql(struct guild *g,int flag) int inter_guild_tosql(struct guild *g,int flag)
{ {
@ -543,9 +550,10 @@ struct guild * inter_guild_fromsql(int guild_id)
return g; return g;
} }
#endif //TXT_SQL_CONVERT #endif //TXT_SQL_CONVERT
int inter_guildcastle_tosql(struct guild_castle *gc){
int inter_guildcastle_tosql(struct guild_castle *gc)
{
// `guild_castle` (`castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, `triggerD`, `nextTime`, `payTime`, `createTime`, `visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`) // `guild_castle` (`castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, `triggerD`, `nextTime`, `payTime`, `createTime`, `visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`)
if (gc==NULL) return 0; if (gc==NULL) return 0;
@ -570,8 +578,8 @@ ShowDebug("Save guild_castle (%d)\n", gc->castle_id);
#endif //TXT_SQL_CONVERT #endif //TXT_SQL_CONVERT
return 0; return 0;
} }
#ifndef TXT_SQL_CONVERT
#ifndef TXT_SQL_CONVERT
// Read guild_castle from sql // Read guild_castle from sql
int inter_guildcastle_fromsql(int castle_id,struct guild_castle *gc) int inter_guildcastle_fromsql(int castle_id,struct guild_castle *gc)
{ {
@ -676,8 +684,8 @@ int inter_guild_ReadEXP(void)
} }
int inter_guild_CharOnline(int char_id, int guild_id) { int inter_guild_CharOnline(int char_id, int guild_id)
{
struct guild *g; struct guild *g;
int i; int i;
@ -716,21 +724,23 @@ int inter_guild_CharOnline(int char_id, int guild_id) {
g->save_flag &= ~GS_REMOVE; g->save_flag &= ~GS_REMOVE;
//Set member online //Set member online
for(i=0; i<g->max_member; i++) { ARR_FIND( 0, g->max_member, i, g->member[i].char_id == char_id );
if (g->member[i].char_id == char_id) { if( i < g->max_member )
{
g->member[i].online = 1; g->member[i].online = 1;
g->member[i].modified = GS_MEMBER_MODIFIED; g->member[i].modified = GS_MEMBER_MODIFIED;
break;
}
} }
return 1; return 1;
} }
int inter_guild_CharOffline(int char_id, int guild_id) { int inter_guild_CharOffline(int char_id, int guild_id)
{
struct guild *g=NULL; struct guild *g=NULL;
int online_count=0, i; int online_count, i;
if (guild_id == -1) { if (guild_id == -1)
{
//Get guild_id from the database //Get guild_id from the database
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT guild_id FROM `%s` WHERE char_id='%d'", char_db, char_id) ) if( SQL_ERROR == Sql_Query(sql_handle, "SELECT guild_id FROM `%s` WHERE char_id='%d'", char_db, char_id) )
{ {
@ -760,18 +770,20 @@ int inter_guild_CharOffline(int char_id, int guild_id) {
return 0; return 0;
//Set member offline //Set member offline
for(i=0; i<g->max_member; i++) { ARR_FIND( 0, g->max_member, i, g->member[i].char_id == char_id );
if(g->member[i].char_id == char_id) if( i < g->max_member )
{ {
g->member[i].online = 0; g->member[i].online = 0;
g->member[i].modified = GS_MEMBER_MODIFIED; g->member[i].modified = GS_MEMBER_MODIFIED;
} }
if(g->member[i].online && !online_count)
online_count = 0;
for( i = 0; i < g->max_member; i++ )
if( g->member[i].online )
online_count++; online_count++;
}
// Remove guild from memory if no players online // Remove guild from memory if no players online
if(online_count == 0) if( online_count == 0 )
g->save_flag |= GS_REMOVE; g->save_flag |= GS_REMOVE;
return 1; return 1;
@ -859,8 +871,8 @@ unsigned int guild_nextexp(int level)
return 0; return 0;
} }
int guild_checkskill(struct guild *g,int id) { int guild_checkskill(struct guild *g,int id)
{
int idx = id - GD_SKILLBASE; int idx = id - GD_SKILLBASE;
if(idx < 0 || idx >= MAX_GUILDSKILL) if(idx < 0 || idx >= MAX_GUILDSKILL)
@ -951,6 +963,7 @@ int mapif_guild_created(int fd,int account_id,struct guild *g)
WFIFOSET(fd,10); WFIFOSET(fd,10);
return 0; return 0;
} }
// Guild not found // Guild not found
int mapif_guild_noinfo(int fd,int guild_id) int mapif_guild_noinfo(int fd,int guild_id)
{ {
@ -1096,8 +1109,7 @@ int mapif_guild_skillupack(int guild_id,int skill_num,int account_id)
} }
// ACK guild alliance // ACK guild alliance
int mapif_guild_alliance(int guild_id1,int guild_id2,int account_id1,int account_id2, int mapif_guild_alliance(int guild_id1,int guild_id2,int account_id1,int account_id2,int flag,const char *name1,const char *name2)
int flag,const char *name1,const char *name2)
{ {
unsigned char buf[19+2*NAME_LENGTH]; unsigned char buf[19+2*NAME_LENGTH];
WBUFW(buf, 0)=0x383d; WBUFW(buf, 0)=0x383d;
@ -1161,7 +1173,7 @@ int mapif_guild_master_changed(struct guild *g, int aid, int cid)
return 0; return 0;
} }
int mapif_guild_castle_dataload(int castle_id,int index,int value) // <Agit> int mapif_guild_castle_dataload(int castle_id,int index,int value)
{ {
unsigned char buf[9]; unsigned char buf[9];
WBUFW(buf, 0)=0x3840; WBUFW(buf, 0)=0x3840;
@ -1172,7 +1184,7 @@ int mapif_guild_castle_dataload(int castle_id,int index,int value) // <Agit
return 0; return 0;
} }
int mapif_guild_castle_datasave(int castle_id,int index,int value) // <Agit> int mapif_guild_castle_datasave(int castle_id,int index,int value)
{ {
unsigned char buf[9]; unsigned char buf[9];
WBUFW(buf, 0)=0x3841; WBUFW(buf, 0)=0x3841;
@ -1188,7 +1200,7 @@ int mapif_guild_castle_alldataload(int fd)
struct guild_castle s_gc; struct guild_castle s_gc;
struct guild_castle* gc = &s_gc; struct guild_castle* gc = &s_gc;
int i; int i;
int off; int len;
char* data; char* data;
WFIFOHEAD(fd, 4 + MAX_GUILDCASTLE*sizeof(struct guild_castle)); WFIFOHEAD(fd, 4 + MAX_GUILDCASTLE*sizeof(struct guild_castle));
@ -1197,7 +1209,7 @@ int mapif_guild_castle_alldataload(int fd)
"`visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`," "`visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`,"
"`Ghp0`, `Ghp1`, `Ghp2`, `Ghp3`, `Ghp4`, `Ghp5`, `Ghp6`, `Ghp7` FROM `%s` ORDER BY `castle_id`", guild_castle_db) ) "`Ghp0`, `Ghp1`, `Ghp2`, `Ghp3`, `Ghp4`, `Ghp5`, `Ghp6`, `Ghp7` FROM `%s` ORDER BY `castle_id`", guild_castle_db) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
for( i = 0, off = 4; i < MAX_GUILDCASTLE && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) for( i = 0, len = 4; i < MAX_GUILDCASTLE && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i )
{ {
memset(gc, 0, sizeof(struct guild_castle)); memset(gc, 0, sizeof(struct guild_castle));
@ -1228,12 +1240,12 @@ int mapif_guild_castle_alldataload(int fd)
Sql_GetData(sql_handle, 24, &data, NULL); gc->guardian[6].hp = atoi(data); Sql_GetData(sql_handle, 24, &data, NULL); gc->guardian[6].hp = atoi(data);
Sql_GetData(sql_handle, 25, &data, NULL); gc->guardian[7].hp = atoi(data); Sql_GetData(sql_handle, 25, &data, NULL); gc->guardian[7].hp = atoi(data);
memcpy(WFIFOP(fd, off), gc, sizeof(struct guild_castle)); memcpy(WFIFOP(fd, len), gc, sizeof(struct guild_castle));
off += sizeof(struct guild_castle); len += sizeof(struct guild_castle);
} }
Sql_FreeResult(sql_handle); Sql_FreeResult(sql_handle);
WFIFOW(fd, 2) = off; WFIFOW(fd, 2) = len;
WFIFOSET(fd, off); WFIFOSET(fd, len);
return 0; return 0;
} }
@ -1425,57 +1437,52 @@ int mapif_parse_GuildLeave(int fd, int guild_id, int account_id, int char_id, in
} }
// Change member info // Change member info
int mapif_parse_GuildChangeMemberInfoShort(int fd,int guild_id, int mapif_parse_GuildChangeMemberInfoShort(int fd,int guild_id,int account_id,int char_id,int online,int lv,int class_)
int account_id,int char_id,int online,int lv,int class_)
{ {
// Could speed up by manipulating only guild_member // Could speed up by manipulating only guild_member
struct guild * g; struct guild * g;
int i,alv,c; int i,sum,c;
int prev_count; int prev_count, prev_alv;
g = inter_guild_fromsql(guild_id); g = inter_guild_fromsql(guild_id);
if(g==NULL) if(g==NULL)
return 0; return 0;
prev_count = g->connect_member; ARR_FIND( 0, g->max_member, i, g->member[i].account_id == account_id && g->member[i].char_id == char_id );
g->connect_member=0; if( i < g->max_member )
for(i=0,alv=0,c=0;i<g->max_member;i++)
{ {
// Found the member g->member[i].online = online;
if(g->member[i].account_id==account_id && g->member[i].char_id==char_id) g->member[i].lv = lv;
{ g->member[i].class_ = class_;
g->member[i].online=online;
g->member[i].lv=lv;
g->member[i].class_=class_;
g->member[i].modified = GS_MEMBER_MODIFIED; g->member[i].modified = GS_MEMBER_MODIFIED;
mapif_guild_memberinfoshort(g,i); mapif_guild_memberinfoshort(g,i);
} }
if( g->member[i].account_id>0 )
prev_count = g->connect_member;
prev_alv = g->average_lv;
g->average_lv = 0;
g->connect_member = 0;
c = 0;
sum = 0;
for( i = 0; i < g->max_member; i++ )
{ {
if (g->member[i].lv > 0) if( g->member[i].account_id > 0 )
{ {
alv+=g->member[i].lv; sum += g->member[i].lv;
c++; c++;
} }
else
{
ShowWarning("Guild %d:%s, member %d:%s has an invalid level %d\n", g->guild_id, g->name, g->member[i].char_id, g->member[i].name, g->member[i].lv);
}
}
if( g->member[i].online ) if( g->member[i].online )
g->connect_member++; g->connect_member++;
} }
if (c) if( c ) // this check should always succeed...
{ {
alv = alv/c; g->average_lv = sum / c;
if (g->connect_member != prev_count || g->average_lv != alv) if( g->connect_member != prev_count || g->average_lv != prev_alv )
{
g->average_lv=alv;
g->save_flag |= GS_CONNECT; g->save_flag |= GS_CONNECT;
} if( g->save_flag & GS_REMOVE )
if (g->save_flag & GS_REMOVE)
g->save_flag &= ~GS_REMOVE; g->save_flag &= ~GS_REMOVE;
} }
g->save_flag |= GS_MEMBER; //Update guild member data g->save_flag |= GS_MEMBER; //Update guild member data
@ -1568,8 +1575,7 @@ int mapif_parse_GuildBasicInfoChange(int fd,int guild_id,int type,const char *da
} }
// Modification of the guild // Modification of the guild
int mapif_parse_GuildMemberInfoChange(int fd,int guild_id,int account_id,int char_id, int mapif_parse_GuildMemberInfoChange(int fd,int guild_id,int account_id,int char_id,int type,const char *data,int len)
int type,const char *data,int len)
{ {
// Could make some improvement in speed, because only change guild_member // Could make some improvement in speed, because only change guild_member
int i; int i;
@ -1725,15 +1731,13 @@ static int mapif_parse_GuildDeleteAlliance(struct guild *g, int guild_id, int ac
{ {
int i; int i;
char name[NAME_LENGTH]; char name[NAME_LENGTH];
for(i=0;i<MAX_GUILDALLIANCE;i++)
if(g->alliance[i].guild_id == guild_id) ARR_FIND( 0, MAX_GUILDALLIANCE, i, g->alliance[i].guild_id == guild_id );
{ if( i == MAX_GUILDALLIANCE )
return -1;
strcpy(name, g->alliance[i].name); strcpy(name, g->alliance[i].name);
g->alliance[i].guild_id=0; g->alliance[i].guild_id=0;
break;
}
if (i == MAX_GUILDALLIANCE)
return -1;
mapif_guild_alliance(g->guild_id,guild_id,account_id1,account_id2,flag,g->name,name); mapif_guild_alliance(g->guild_id,guild_id,account_id1,account_id2,flag,g->name,name);
g->save_flag |= GS_ALLIANCE; g->save_flag |= GS_ALLIANCE;
@ -1741,8 +1745,7 @@ static int mapif_parse_GuildDeleteAlliance(struct guild *g, int guild_id, int ac
} }
// Alliance modification // Alliance modification
int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2, int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,int account_id1,int account_id2,int flag)
int account_id1,int account_id2,int flag)
{ {
// Could speed up // Could speed up
struct guild *g[2]; struct guild *g[2];
@ -1761,14 +1764,9 @@ int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,
// Remove alliance/opposition, in case of alliance, remove on both side // Remove alliance/opposition, in case of alliance, remove on both side
for(i=0;i<2-(flag&GUILD_ALLIANCE_TYPE_MASK);i++) for(i=0;i<2-(flag&GUILD_ALLIANCE_TYPE_MASK);i++)
{ {
for(j=0;j<MAX_GUILDALLIANCE;j++) ARR_FIND( 0, MAX_GUILDALLIANCE, j, g[i]->alliance[j].guild_id == g[1-i]->guild_id && g[i]->alliance[j].opposition == (flag&GUILD_ALLIANCE_TYPE_MASK) );
{ if( j < MAX_GUILDALLIANCE )
if(g[i]->alliance[j].guild_id == g[1-i]->guild_id && g[i]->alliance[j].opposition == (flag&GUILD_ALLIANCE_TYPE_MASK)) g[i]->alliance[j].guild_id = 0;
{
g[i]->alliance[j].guild_id=0;
break;
}
}
} }
} }
else else
@ -1777,16 +1775,13 @@ int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,
for(i=0;i<2-(flag&GUILD_ALLIANCE_TYPE_MASK);i++) for(i=0;i<2-(flag&GUILD_ALLIANCE_TYPE_MASK);i++)
{ {
// Search an empty slot // Search an empty slot
for(j=0;j<MAX_GUILDALLIANCE;j++) ARR_FIND( 0, MAX_GUILDALLIANCE, j, g[i]->alliance[j].guild_id == 0 );
{ if( j < MAX_GUILDALLIANCE )
if(g[i]->alliance[j].guild_id==0)
{ {
g[i]->alliance[j].guild_id=g[1-i]->guild_id; g[i]->alliance[j].guild_id=g[1-i]->guild_id;
memcpy(g[i]->alliance[j].name,g[1-i]->name,NAME_LENGTH); memcpy(g[i]->alliance[j].name,g[1-i]->name,NAME_LENGTH);
// Set alliance type // Set alliance type
g[i]->alliance[j].opposition = flag&GUILD_ALLIANCE_TYPE_MASK; g[i]->alliance[j].opposition = flag&GUILD_ALLIANCE_TYPE_MASK;
break;
}
} }
} }
} }
@ -1833,7 +1828,7 @@ int mapif_parse_GuildEmblem(int fd,int len,int guild_id,int dummy,const char *da
return mapif_guild_emblem(g); return mapif_guild_emblem(g);
} }
int mapif_parse_GuildCastleDataLoad(int fd,int castle_id,int index) // <Agit> int mapif_parse_GuildCastleDataLoad(int fd,int castle_id,int index)
{ {
struct guild_castle gc; struct guild_castle gc;
if (!inter_guildcastle_fromsql(castle_id, &gc)) { if (!inter_guildcastle_fromsql(castle_id, &gc)) {
@ -1873,7 +1868,7 @@ int mapif_parse_GuildCastleDataLoad(int fd,int castle_id,int index) // <Agit
} }
} }
int mapif_parse_GuildCastleDataSave(int fd,int castle_id,int index,int value) // <Agit> int mapif_parse_GuildCastleDataSave(int fd,int castle_id,int index,int value)
{ {
struct guild_castle gc; struct guild_castle gc;
if(!inter_guildcastle_fromsql(castle_id, &gc)) if(!inter_guildcastle_fromsql(castle_id, &gc))