diff options
author | shennetsind <ind@henn.et> | 2013-09-27 14:31:26 -0300 |
---|---|---|
committer | shennetsind <ind@henn.et> | 2013-09-27 14:32:05 -0300 |
commit | a4c5e17bba98d65bedf917c03bb60bf0550af688 (patch) | |
tree | add761fae1d3a240922ee6398305d35e4d1fce7d /src | |
parent | c08c02223390b162de6863a56ee7c823339654c4 (diff) | |
download | hercules-a4c5e17bba98d65bedf917c03bb60bf0550af688.tar.gz hercules-a4c5e17bba98d65bedf917c03bb60bf0550af688.tar.bz2 hercules-a4c5e17bba98d65bedf917c03bb60bf0550af688.tar.xz hercules-a4c5e17bba98d65bedf917c03bb60bf0550af688.zip |
HPM: Chat.c Completed
Moved missing vars and declarations of interest into the interface, removed duplicate mentions of chat within calls to shorten wherever it made sense to, and renamed some members to ease reading.
Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src')
-rw-r--r-- | src/map/chat.c | 52 | ||||
-rw-r--r-- | src/map/chat.h | 42 | ||||
-rw-r--r-- | src/map/clif.c | 14 | ||||
-rw-r--r-- | src/map/npc.c | 2 | ||||
-rw-r--r-- | src/map/script.c | 10 | ||||
-rw-r--r-- | src/map/unit.c | 2 |
6 files changed, 63 insertions, 59 deletions
diff --git a/src/map/chat.c b/src/map/chat.c index 3886b69da..d6fad4d94 100644 --- a/src/map/chat.c +++ b/src/map/chat.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/cbasetypes.h" #include "../common/malloc.h" @@ -19,16 +20,16 @@ #include <stdio.h> #include <string.h> - -int chat_triggerevent(struct chat_data *cd); // forward declaration +struct chat_interface chat_s; /// Initializes a chatroom object (common functionality for both pc and npc chatrooms). /// Returns a chatroom object on success, or NULL on failure. -static struct chat_data* chat_createchat(struct block_list* bl, const char* title, const char* pass, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl) +struct chat_data* chat_createchat(struct block_list* bl, const char* title, const char* pass, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl) { struct chat_data* cd; nullpo_retr(NULL, bl); + /* Given the overhead and the numerous instances (npc allocatted or otherwise) wouldn't it be benefitial to have it use ERS? [Ind] */ cd = (struct chat_data *) aMalloc(sizeof(struct chat_data)); safestrncpy(cd->title, title, sizeof(cd->title)); @@ -91,7 +92,7 @@ int chat_createpcchat(struct map_session_data* sd, const char* title, const char pc_stop_walking(sd,1); - cd = chat_createchat(&sd->bl, title, pass, limit, pub, 0, "", 0, 1, MAX_LEVEL); + cd = chat->create(&sd->bl, title, pass, limit, pub, 0, "", 0, 1, MAX_LEVEL); if( cd ) { cd->users = 1; cd->usersd[0] = sd; @@ -155,7 +156,7 @@ int chat_joinchat(struct map_session_data* sd, int chatid, const char* pass) { clif->addchat(cd, sd); //Reports To the person who already in the chat clif->dispchat(cd, 0); //Reported number of changes to the people around - chat_triggerevent(cd); //Event + chat->trigger_event(cd); //Event return 0; } @@ -319,7 +320,7 @@ int chat_kickchat(struct map_session_data* sd, const char* kickusername) { idb_put(cd->kick_list,cd->usersd[i]->status.char_id,(void*)1); - chat->leavechat(cd->usersd[i],1); + chat->leave(cd->usersd[i],1); return 0; } @@ -339,7 +340,7 @@ int chat_createnpcchat(struct npc_data* nd, const char* title, int limit, bool p return 0; } - cd = chat_createchat(&nd->bl, title, "", limit, pub, trigger, ev, zeny, minLvl, maxLvl); + cd = chat->create(&nd->bl, title, "", limit, pub, trigger, ev, zeny, minLvl, maxLvl); if( cd ) { nd->chat_id = cd->bl.id; @@ -358,7 +359,7 @@ int chat_deletenpcchat(struct npc_data* nd) { if( cd == NULL ) return 0; - chat->npckickall(cd); + chat->npc_kick_all(cd); clif->clearchat(cd, 0); map->deliddb(&cd->bl); map->delblock(&cd->bl); @@ -387,7 +388,7 @@ int chat_enableevent(struct chat_data* cd) nullpo_ret(cd); cd->trigger &= 0x7f; - chat_triggerevent(cd); + chat->trigger_event(cd); return 0; } @@ -406,7 +407,7 @@ int chat_npckickall(struct chat_data* cd) nullpo_ret(cd); while( cd->users > 0 ) - chat->leavechat(cd->usersd[cd->users-1],0); + chat->leave(cd->usersd[cd->users-1],0); return 0; } @@ -418,18 +419,19 @@ int chat_npckickall(struct chat_data* cd) *-------------------------------------*/ void chat_defaults(void) { chat = &chat_s; - /* funcs */ - chat->createpcchat = chat_createpcchat; - chat->joinchat = chat_joinchat; - chat->leavechat = chat_leavechat; - chat->changechatowner = chat_changechatowner; - chat->changechatstatus = chat_changechatstatus; - chat->kickchat = chat_kickchat; - - chat->createnpcchat = chat_createnpcchat; - chat->deletenpcchat = chat_deletenpcchat; - chat->enableevent = chat_enableevent; - chat->disableevent = chat_disableevent; - chat->npckickall = chat_npckickall; + /* funcs */ + chat->create_pc_chat = chat_createpcchat; + chat->join = chat_joinchat; + chat->leave = chat_leavechat; + chat->change_owner = chat_changechatowner; + chat->change_status = chat_changechatstatus; + chat->kick = chat_kickchat; + chat->create_npc_chat = chat_createnpcchat; + chat->delete_npc_chat = chat_deletenpcchat; + chat->enable_event = chat_enableevent; + chat->disable_event = chat_disableevent; + chat->npc_kick_all = chat_npckickall; + chat->trigger_event = chat_triggerevent; + chat->create = chat_createchat; } diff --git a/src/map/chat.h b/src/map/chat.h index a7736e9f3..695e59b6e 100644 --- a/src/map/chat.h +++ b/src/map/chat.h @@ -1,12 +1,15 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams + #ifndef _CHAT_H_ #define _CHAT_H_ + #include "map.h" // struct block_list, CHATROOM_TITLE_SIZE + struct map_session_data; struct chat_data; - struct chat_data { struct block_list bl; // data for this map object char title[CHATROOM_TITLE_SIZE]; // room title @@ -21,33 +24,32 @@ struct chat_data { struct map_session_data* usersd[20]; struct block_list* owner; char npc_event[EVENT_NAME_LENGTH]; + /* isn't this a waste? there is a enormous overhead, wouldn't something like skill_blockpc_start be better here? [Ind] */ DBMap* kick_list; //DBMap of users who were kicked from this chat }; - - - /*===================================== * Interface : chat.h * Generated by HerculesInterfaceMaker * created by Susu *-------------------------------------*/ struct chat_interface { - /* funcs */ - - int (*createpcchat) (struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub); - int (*joinchat) (struct map_session_data* sd, int chatid, const char* pass); - int (*leavechat) (struct map_session_data* sd, bool kicked); - int (*changechatowner) (struct map_session_data* sd, const char* nextownername); - int (*changechatstatus) (struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub); - int (*kickchat) (struct map_session_data* sd, const char* kickusername); - int (*createnpcchat) (struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl); - int (*deletenpcchat) (struct npc_data* nd); - int (*enableevent) (struct chat_data* cd); - int (*disableevent) (struct chat_data* cd); - int (*npckickall) (struct chat_data* cd); -} chat_s; + /* funcs */ + int (*create_pc_chat) (struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub); + int (*join) (struct map_session_data* sd, int chatid, const char* pass); + int (*leave) (struct map_session_data* sd, bool kicked); + int (*change_owner) (struct map_session_data* sd, const char* nextownername); + int (*change_status) (struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub); + int (*kick) (struct map_session_data* sd, const char* kickusername); + int (*create_npc_chat) (struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl); + int (*delete_npc_chat) (struct npc_data* nd); + int (*enable_event) (struct chat_data* cd); + int (*disable_event) (struct chat_data* cd); + int (*npc_kick_all) (struct chat_data* cd); + int (*trigger_event) (struct chat_data *cd); + struct chat_data* (*create) (struct block_list* bl, const char* title, const char* pass, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl); +}; struct chat_interface *chat; diff --git a/src/map/clif.c b/src/map/clif.c index f248449a5..ed75e9aa0 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -8507,7 +8507,7 @@ void clif_refresh(struct map_session_data *sd) map->foreachinrange(clif->getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd); clif->weather_check(sd); if( sd->chatID ) - chat->leavechat(sd,0); + chat->leave(sd,0); if( sd->state.vending ) clif->openvending(sd, sd->bl.id, sd->vending); if( pc_issit(sd) ) @@ -10937,7 +10937,7 @@ void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd) safestrncpy(s_password, password, CHATROOM_PASS_SIZE); safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte - chat->createpcchat(sd, s_title, s_password, limit, pub); + chat->create_pc_chat(sd, s_title, s_password, limit, pub); } @@ -10948,7 +10948,7 @@ void clif_parse_ChatAddMember(int fd, struct map_session_data* sd) int chatid = RFIFOL(fd,2); const char* password = (char*)RFIFOP(fd,6); // not zero-terminated - chat->joinchat(sd,chatid,password); + chat->join(sd,chatid,password); } @@ -10973,7 +10973,7 @@ void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd) safestrncpy(s_password, password, CHATROOM_PASS_SIZE); safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte - chat->changechatstatus(sd, s_title, s_password, limit, pub); + chat->change_status(sd, s_title, s_password, limit, pub); } @@ -10984,7 +10984,7 @@ void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd) /// 1 = normal void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd) { - chat->changechatowner(sd,(char*)RFIFOP(fd,6)); + chat->change_owner(sd,(char*)RFIFOP(fd,6)); } @@ -10992,7 +10992,7 @@ void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd) /// 00e2 <name>.24B void clif_parse_KickFromChat(int fd,struct map_session_data *sd) { - chat->kickchat(sd,(char*)RFIFOP(fd,2)); + chat->kick(sd,(char*)RFIFOP(fd,2)); } @@ -11000,7 +11000,7 @@ void clif_parse_KickFromChat(int fd,struct map_session_data *sd) /// 00e3 void clif_parse_ChatLeave(int fd, struct map_session_data* sd) { - chat->leavechat(sd,0); + chat->leave(sd,0); } diff --git a/src/map/npc.c b/src/map/npc.c index eff80efce..21e4221da 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -1773,7 +1773,7 @@ int npc_unload(struct npc_data* nd, bool single) { strdb_remove(npc->name_db, nd->exname); if (nd->chat_id) // remove npc chatroom object and kick users - chat->deletenpcchat(nd); + chat->delete_npc_chat(nd); #ifdef PCRE_SUPPORT npc_chat->finalize(nd); // deallocate npc PCRE data structures diff --git a/src/map/script.c b/src/map/script.c index 992f9da94..06c97bbe6 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -9988,7 +9988,7 @@ BUILDIN(waitingroom) { nd = (struct npc_data *)map->id2bl(st->oid); if( nd != NULL ) - chat->createnpcchat(nd, title, limit, pub, trigger, ev, zeny, minLvl, maxLvl); + chat->create_npc_chat(nd, title, limit, pub, trigger, ev, zeny, minLvl, maxLvl); return true; } @@ -10004,7 +10004,7 @@ BUILDIN(delwaitingroom) { else nd = (struct npc_data *)map->id2bl(st->oid); if( nd != NULL ) - chat->deletenpcchat(nd); + chat->delete_npc_chat(nd); return true; } @@ -10022,7 +10022,7 @@ BUILDIN(waitingroomkickall) { nd = (struct npc_data *)map->id2bl(st->oid); if( nd != NULL && (cd=(struct chat_data *)map->id2bl(nd->chat_id)) != NULL ) - chat->npckickall(cd); + chat->npc_kick_all(cd); return true; } @@ -10040,7 +10040,7 @@ BUILDIN(enablewaitingroomevent) { nd = (struct npc_data *)map->id2bl(st->oid); if( nd != NULL && (cd=(struct chat_data *)map->id2bl(nd->chat_id)) != NULL ) - chat->enableevent(cd); + chat->enable_event(cd); return true; } @@ -10058,7 +10058,7 @@ BUILDIN(disablewaitingroomevent) { nd = (struct npc_data *)map->id2bl(st->oid); if( nd != NULL && (cd=(struct chat_data *)map->id2bl(nd->chat_id)) != NULL ) - chat->disableevent(cd); + chat->disable_event(cd); return true; } diff --git a/src/map/unit.c b/src/map/unit.c index 44bb1970c..9d6f107e3 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -2128,7 +2128,7 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i } //Leave/reject all invitations. if(sd->chatID) - chat->leavechat(sd,0); + chat->leave(sd,0); if(sd->trade_partner) trade->cancel(sd); buyingstore->close(sd); |