diff options
author | shennetsind <ind@henn.et> | 2013-03-30 23:08:08 -0300 |
---|---|---|
committer | shennetsind <ind@henn.et> | 2013-03-30 23:08:08 -0300 |
commit | 7ec1e8fdff6adad1979d750774f9003f223bf3ef (patch) | |
tree | 65553e83135c5f5f983c106914d0a35ea2f62588 /src/map/guild.c | |
parent | 87373047cd4aaf8b0c2425133b9b907e3ea4d122 (diff) | |
download | hercules-7ec1e8fdff6adad1979d750774f9003f223bf3ef.tar.gz hercules-7ec1e8fdff6adad1979d750774f9003f223bf3ef.tar.bz2 hercules-7ec1e8fdff6adad1979d750774f9003f223bf3ef.tar.xz hercules-7ec1e8fdff6adad1979d750774f9003f223bf3ef.zip |
Hercules Renewal: clif.c complete
Added the last missing functions into the interface, all functions in clif.c are now wired to the interface.
http://hercules.ws/board/topic/237-hercules-renewal/
Also shortened clif->displaymessage to clif->message, removed the old clif->message and merged its functionality with clif->disp_overhead (both use the same packet and do the same thing :P)
-
and a gazillion other stuff:
http://hercules.ws/board/topic/316-introducing-hercules-channel-system/
Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map/guild.c')
-rw-r--r-- | src/map/guild.c | 153 |
1 files changed, 110 insertions, 43 deletions
diff --git a/src/map/guild.c b/src/map/guild.c index fa06f7f4c..ec5b42af2 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -259,7 +259,7 @@ int guild_getposition(struct guild* g, struct map_session_data* sd) { int i; - if( g == NULL && (g=guild_search(sd->status.guild_id)) == NULL ) + if( g == NULL && (g=sd->guild) == NULL ) return -1; ARR_FIND( 0, g->max_member, i, g->member[i].account_id == sd->status.account_id && g->member[i].char_id == sd->status.char_id ); @@ -481,8 +481,7 @@ int guild_recv_noinfo(int guild_id) struct s_mapiterator* iter; iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) - { + for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) { if( sd->status.guild_id == guild_id ) sd->status.guild_id = 0; // erase guild } @@ -492,27 +491,58 @@ int guild_recv_noinfo(int guild_id) } //Get and display information for all member -int guild_recv_info(struct guild *sg) -{ +int guild_recv_info(struct guild *sg) { struct guild *g,before; int i,bm,m; DBData data; struct map_session_data *sd; bool guild_new = false; + void *aChSysSave = NULL; nullpo_ret(sg); - if((g = (struct guild*)idb_get(guild_db,sg->guild_id))==NULL) - { + if((g = (struct guild*)idb_get(guild_db,sg->guild_id))==NULL) { guild_new = true; g=(struct guild *)aCalloc(1,sizeof(struct guild)); idb_put(guild_db,sg->guild_id,g); - before=*sg; + if( hChSys.ally ) { + struct hChSysCh *channel; + + CREATE(channel, struct hChSysCh , 1); + safestrncpy(channel->name, hChSys.ally_name, HCHSYS_NAME_LENGTH); + channel->type = hChSys_ALLY; + + clif->chsys_create(channel,NULL,NULL,hChSys.ally_color); + if( hChSys.ally_autojoin ) { + struct s_mapiterator* iter = mapit_getallusers(); + + for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) { + if( sd->status.guild_id ) { + if( sd->status.guild_id == sg->guild_id ) { + clif->chsys_join(channel,sd); + sd->guild = g; + continue; + } + + for (i = 0; i < MAX_GUILDALLIANCE; i++) { + if( sg->alliance[i].guild_id == sd->status.guild_id ) { + clif->chsys_join(channel,sd); + break; + } + } + } + } + + mapit_free(iter); + } + + aChSysSave = (void*)channel; + } + before=*sg; //Perform the check on the user because the first load guild_check_member(sg); - if ((sd = map_nick2sd(sg->master)) != NULL) - { + if ((sd = map_nick2sd(sg->master)) != NULL) { //If the guild master is online the first time the guild_info is received, //that means he was the first to join, so apply guild skill blocking here. if( battle_config.guild_skill_relog_delay ) @@ -523,12 +553,16 @@ int guild_recv_info(struct guild *sg) clif->charnameupdate(sd); // [LuzZza] clif->guild_masterormember(sd); } - }else + } else { before=*g; + if( g->channel ) + aChSysSave = g->channel; + } memcpy(g,sg,sizeof(struct guild)); - - if(g->max_member > MAX_GUILD) - { + + g->channel = aChSysSave; + + if(g->max_member > MAX_GUILD) { ShowError("guild_recv_info: Received guild with %d members, but MAX_GUILD is only %d. Extra guild-members have been lost!\n", g->max_member, MAX_GUILD); g->max_member = MAX_GUILD; } @@ -570,10 +604,9 @@ int guild_recv_info(struct guild *sg) } //Occurrence of an event - if (guild_infoevent_db->remove(guild_infoevent_db, db_i2key(sg->guild_id), &data)) - { + if (guild_infoevent_db->remove(guild_infoevent_db, db_i2key(sg->guild_id), &data)) { struct eventlist *ev = db_data2ptr(&data), *ev2; - while(ev){ + while(ev) { npc_event_do(ev->name); ev2=ev->next; aFree(ev); @@ -593,7 +626,7 @@ int guild_invite(struct map_session_data *sd, struct map_session_data *tsd) { nullpo_ret(sd); - g=guild_search(sd->status.guild_id); + g=sd->guild; if(tsd==NULL || g==NULL) return 0; @@ -705,8 +738,7 @@ void guild_member_joined(struct map_session_data *sd) guild_request_info(sd->status.guild_id); return; } - if (strcmp(sd->status.name,g->master) == 0) - { // set the Guild Master flag + if (strcmp(sd->status.name,g->master) == 0) { // set the Guild Master flag sd->state.gmaster_flag = g; // prevent Guild Skills from being used directly after relog if( battle_config.guild_skill_relog_delay ) @@ -715,8 +747,24 @@ void guild_member_joined(struct map_session_data *sd) i = guild_getindex(g, sd->status.account_id, sd->status.char_id); if (i == -1) sd->status.guild_id = 0; - else + else { + g->member[i].sd = sd; + sd->guild = g; + + if( hChSys.ally && hChSys.ally_autojoin ) { + struct guild* sg = NULL; + clif->chsys_join((struct hChSysCh*)g->channel,sd); + + for (i = 0; i < MAX_GUILDALLIANCE; i++) { + if( g->alliance[i].guild_id && (sg = guild_search(g->alliance[i].guild_id) ) ) { + clif->chsys_join((struct hChSysCh*)sg->channel,sd); + break; + } + } + } + + } } /*========================================== @@ -775,7 +823,7 @@ int guild_leave(struct map_session_data* sd, int guild_id, int account_id, int c nullpo_ret(sd); - g = guild_search(sd->status.guild_id); + g = sd->guild; if(g==NULL) return 0; @@ -800,7 +848,7 @@ int guild_expulsion(struct map_session_data* sd, int guild_id, int account_id, i nullpo_ret(sd); - g = guild_search(sd->status.guild_id); + g = sd->guild; if(g==NULL) return 0; @@ -859,8 +907,14 @@ int guild_member_withdraw(int guild_id, int account_id, int char_id, int flag, c if (sd->state.storage_flag == 2) //Close the guild storage. storage_guild_storageclose(sd); guild_send_dot_remove(sd); - + if( hChSys.ally ) { + for (i = 0; i < sd->channel_count; i++) { + if( sd->channels[i] && sd->channels[i]->type == hChSys_ALLY ) + clif->chsys_left(sd->channels[i],sd); + } + } sd->status.guild_id = 0; + sd->guild = NULL; sd->guild_emblem_id = 0; clif->charnameupdate(sd); //Update display name [Skotlex] @@ -878,7 +932,7 @@ int guild_send_memberinfoshort(struct map_session_data *sd,int online) if(sd->status.guild_id <= 0) return 0; - if(!(g = guild_search(sd->status.guild_id))) + if(!(g = sd->guild)) return 0; intif_guild_memberinfoshort(g->guild_id, @@ -1097,7 +1151,7 @@ int guild_change_emblem(struct map_session_data *sd,int len,const char *data) nullpo_ret(sd); if (battle_config.require_glory_guild && - !((g = guild_search(sd->status.guild_id)) && guild_checkskill(g, GD_GLORYGUILD)>0)) { + !((g = sd->guild) && guild_checkskill(g, GD_GLORYGUILD)>0)) { clif->skill_fail(sd,GD_GLORYGUILD,USESKILL_FAIL_LEVEL,0); return 0; } @@ -1196,7 +1250,7 @@ unsigned int guild_payexp(struct map_session_data *sd,unsigned int exp) if (!exp) return 0; if (sd->status.guild_id == 0 || - (g = guild_search(sd->status.guild_id)) == NULL || + (g = sd->guild) == NULL || (per = guild_getposition(g,sd)) < 0 || (per = g->position[per].exp_mode) < 1) return 0; @@ -1226,7 +1280,7 @@ int guild_getexp(struct map_session_data *sd,int exp) struct guild_expcache *c; nullpo_ret(sd); - if (sd->status.guild_id == 0 || guild_search(sd->status.guild_id) == NULL) + if (sd->status.guild_id == 0 || sd->guild == NULL) return 0; c = db_data2ptr(guild_expcache_db->ensure(guild_expcache_db, db_i2key(sd->status.char_id), create_expcache, sd)); @@ -1249,7 +1303,7 @@ int guild_skillup(TBL_PC* sd, uint16 skill_id) nullpo_ret(sd); if( idx < 0 || idx >= MAX_GUILDSKILL || // not a guild skill - sd->status.guild_id == 0 || (g=guild_search(sd->status.guild_id)) == NULL || // no guild + sd->status.guild_id == 0 || (g=sd->guild) == NULL || // no guild strcmp(sd->status.name, g->master) ) // not the guild master return 0; @@ -1370,7 +1424,7 @@ int guild_reqalliance(struct map_session_data *sd,struct map_session_data *tsd) int i; if(agit_flag || agit2_flag) { // Disable alliance creation during woe [Valaris] - clif->displaymessage(sd->fd,msg_txt(676)); //"Alliances cannot be made during Guild Wars!" + clif->message(sd->fd,msg_txt(676)); //"Alliances cannot be made during Guild Wars!" return 0; } // end addition [Valaris] @@ -1380,8 +1434,8 @@ int guild_reqalliance(struct map_session_data *sd,struct map_session_data *tsd) if(tsd==NULL || tsd->status.guild_id<=0) return 0; - g[0]=guild_search(sd->status.guild_id); - g[1]=guild_search(tsd->status.guild_id); + g[0]=sd->guild; + g[1]=tsd->guild; if(g[0]==NULL || g[1]==NULL) return 0; @@ -1440,8 +1494,8 @@ int guild_reply_reqalliance(struct map_session_data *sd,int account_id,int flag) int i; struct guild *g, *tg; // Reconfirm the number of alliance - g=guild_search(sd->status.guild_id); - tg=guild_search(tsd->status.guild_id); + g=sd->guild; + tg=tsd->guild; if(g==NULL || guild_get_alliance_count(g,0) >= battle_config.max_guild_alliance){ clif->guild_allianceack(sd,4); @@ -1488,7 +1542,7 @@ int guild_delalliance(struct map_session_data *sd,int guild_id,int flag) nullpo_ret(sd); if(agit_flag || agit2_flag) { // Disable alliance breaking during woe [Valaris] - clif->displaymessage(sd->fd,msg_txt(677)); //"Alliances cannot be broken during Guild Wars!" + clif->message(sd->fd,msg_txt(677)); //"Alliances cannot be broken during Guild Wars!" return 0; } // end addition [Valaris] @@ -1506,7 +1560,7 @@ int guild_opposition(struct map_session_data *sd,struct map_session_data *tsd) nullpo_ret(sd); - g=guild_search(sd->status.guild_id); + g=sd->guild; if(g==NULL || tsd==NULL) return 0; @@ -1683,6 +1737,7 @@ int guild_broken(int guild_id,int flag) if(sd->state.storage_flag == 2) storage_guild_storage_quit(sd,1); sd->status.guild_id=0; + sd->guild = NULL; clif->guild_broken(g->member[i].sd,0); clif->charnameupdate(sd); // [LuzZza] } @@ -1691,6 +1746,11 @@ int guild_broken(int guild_id,int flag) guild_db->foreach(guild_db,guild_broken_sub,guild_id); castle_db->foreach(castle_db,castle_guild_broken_sub,guild_id); guild_storage_delete(guild_id); + if( hChSys.ally ) { + if( g->channel != NULL ) { + clif->chsys_delete(( struct hChSysCh * )g->channel); + } + } idb_remove(guild_db,guild_id); return 0; } @@ -1743,15 +1803,13 @@ int guild_gm_changed(int guild_id, int account_id, int char_id) g->member[0].position = 0; //Position 0: guild Master. strcpy(g->master, g->member[0].name); - if (g->member[pos].sd && g->member[pos].sd->fd) - { - clif->displaymessage(g->member[pos].sd->fd, msg_txt(678)); //"You no longer are the Guild Master." + if (g->member[pos].sd && g->member[pos].sd->fd) { + clif->message(g->member[pos].sd->fd, msg_txt(678)); //"You no longer are the Guild Master." g->member[pos].sd->state.gmaster_flag = 0; } - if (g->member[0].sd && g->member[0].sd->fd) - { - clif->displaymessage(g->member[0].sd->fd, msg_txt(679)); //"You have become the Guild Master!" + if (g->member[0].sd && g->member[0].sd->fd) { + clif->message(g->member[0].sd->fd, msg_txt(679)); //"You have become the Guild Master!" g->member[0].sd->state.gmaster_flag = g; //Block his skills for 5 minutes to prevent abuse. guild_block_skill(g->member[0].sd, 300000); @@ -1780,7 +1838,7 @@ int guild_break(struct map_session_data *sd,char *name) nullpo_ret(sd); - if( (g=guild_search(sd->status.guild_id))==NULL ) + if( (g=sd->guild)==NULL ) return 0; if(strcmp(g->name,name)!=0) return 0; @@ -2136,6 +2194,15 @@ void do_init_guild(void) { } void do_final_guild(void) { + DBIterator *iter = db_iterator(guild_db); + struct guild *g; + + for( g = dbi_first(iter); dbi_exists(iter); g = dbi_next(iter) ) { + if( g->channel != NULL ) + clif->chsys_delete((struct hChSysCh *)g->channel); + } + + dbi_destroy(iter); db_destroy(guild_db); castle_db->destroy(castle_db,guild_castle_db_final); |