summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorSusu <bruant.bastien@gmail.com>2013-07-29 15:09:42 +0200
committerSusu <bruant.bastien@gmail.com>2013-07-29 15:09:42 +0200
commit9ac2cf7bc508248450ddd9f3eaca32cb6fe715a4 (patch)
treeaa2ba2e5eec4e8fae70c11c71545b7123504c395 /src/map
parent4f441379e35619da60ddd94d44d3a5b5bb8a49b4 (diff)
downloadhercules-9ac2cf7bc508248450ddd9f3eaca32cb6fe715a4.tar.gz
hercules-9ac2cf7bc508248450ddd9f3eaca32cb6fe715a4.tar.bz2
hercules-9ac2cf7bc508248450ddd9f3eaca32cb6fe715a4.tar.xz
hercules-9ac2cf7bc508248450ddd9f3eaca32cb6fe715a4.zip
Added chat interface
Diffstat (limited to 'src/map')
-rw-r--r--src/map/chat.c871
-rw-r--r--src/map/chat.h99
-rw-r--r--src/map/clif.c14
-rw-r--r--src/map/npc.c2
-rw-r--r--src/map/script.c10
-rw-r--r--src/map/unit.c2
6 files changed, 517 insertions, 481 deletions
diff --git a/src/map/chat.c b/src/map/chat.c
index c0452f2c5..a6a5d2c8b 100644
--- a/src/map/chat.c
+++ b/src/map/chat.c
@@ -1,424 +1,447 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
-
-#include "../common/cbasetypes.h"
-#include "../common/malloc.h"
-#include "../common/nullpo.h"
-#include "../common/showmsg.h"
-#include "../common/strlib.h"
-#include "../common/mmo.h"
-#include "atcommand.h" // msg_txt()
-#include "battle.h" // struct battle_config
-#include "clif.h"
-#include "map.h"
-#include "npc.h" // npc_event_do()
-#include "pc.h"
-#include "skill.h" // ext_skill_unit_onplace()
-#include "chat.h"
-
-#include <stdio.h>
-#include <string.h>
-
-
-int chat_triggerevent(struct chat_data *cd); // forward declaration
-
-/// 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* cd;
- nullpo_retr(NULL, bl);
-
- cd = (struct chat_data *) aMalloc(sizeof(struct chat_data));
-
- safestrncpy(cd->title, title, sizeof(cd->title));
- safestrncpy(cd->pass, pass, sizeof(cd->pass));
- cd->pub = pub;
- cd->users = 0;
- cd->limit = min(limit, ARRAYLENGTH(cd->usersd));
- cd->trigger = trigger;
- cd->zeny = zeny;
- cd->minLvl = minLvl;
- cd->maxLvl = maxLvl;
- memset(cd->usersd, 0, sizeof(cd->usersd));
- cd->owner = bl;
- safestrncpy(cd->npc_event, ev, sizeof(cd->npc_event));
-
- cd->bl.id = iMap->get_new_object_id();
- cd->bl.m = bl->m;
- cd->bl.x = bl->x;
- cd->bl.y = bl->y;
- cd->bl.type = BL_CHAT;
- cd->bl.next = cd->bl.prev = NULL;
-
- if( cd->bl.id == 0 )
- {
- aFree(cd);
- cd = NULL;
- }
-
- iMap->addiddb(&cd->bl);
-
- if( bl->type != BL_NPC )
- cd->kick_list = idb_alloc(DB_OPT_BASE);
-
- return cd;
-}
-
-/*==========================================
- * player chatroom creation
- *------------------------------------------*/
-int chat_createpcchat(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub)
-{
- struct chat_data* cd;
- nullpo_ret(sd);
-
- if( sd->chatID )
- return 0; //Prevent people abusing the chat system by creating multiple chats, as pointed out by End of Exam. [Skotlex]
-
- if( sd->state.vending || sd->state.buyingstore )
- {// not chat, when you already have a store open
- return 0;
- }
-
- if( map[sd->bl.m].flag.nochat )
- {
- clif->message(sd->fd, msg_txt(281));
- return 0; //Can't create chatrooms on this map.
- }
-
- if( iMap->getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOCHAT) )
- {
- clif->message (sd->fd, msg_txt(665));
- return 0;
- }
-
- pc_stop_walking(sd,1);
-
- cd = chat_createchat(&sd->bl, title, pass, limit, pub, 0, "", 0, 1, MAX_LEVEL);
- if( cd ) {
- cd->users = 1;
- cd->usersd[0] = sd;
- pc_setchatid(sd,cd->bl.id);
- pc_stop_attack(sd);
- clif->createchat(sd,0);
- clif->dispchat(cd,0);
- } else
- clif->createchat(sd,1);
-
- return 0;
-}
-
-/*==========================================
- * join an existing chatroom
- *------------------------------------------*/
-int chat_joinchat(struct map_session_data* sd, int chatid, const char* pass)
-{
- struct chat_data* cd;
-
- nullpo_ret(sd);
- cd = (struct chat_data*)iMap->id2bl(chatid);
-
- if( cd == NULL || cd->bl.type != BL_CHAT || cd->bl.m != sd->bl.m || sd->state.vending || sd->state.buyingstore || sd->chatID || ((cd->owner->type == BL_NPC) ? cd->users+1 : cd->users) >= cd->limit )
- {
- clif->joinchatfail(sd,0);
- return 0;
- }
-
- if( !cd->pub && strncmp(pass, cd->pass, sizeof(cd->pass)) != 0 && !pc_has_permission(sd, PC_PERM_JOIN_ALL_CHAT) )
- {
- clif->joinchatfail(sd,1);
- return 0;
- }
-
- if( sd->status.base_level < cd->minLvl || sd->status.base_level > cd->maxLvl ) {
- if(sd->status.base_level < cd->minLvl)
- clif->joinchatfail(sd,5);
- else
- clif->joinchatfail(sd,6);
-
- return 0;
- }
-
- if( sd->status.zeny < cd->zeny ) {
- clif->joinchatfail(sd,4);
- return 0;
- }
-
- if( cd->owner->type != BL_NPC && idb_exists(cd->kick_list,sd->status.char_id) ) {
- clif->joinchatfail(sd,2);//You have been kicked out of the room.
- return 0;
- }
-
- pc_stop_walking(sd,1);
- cd->usersd[cd->users] = sd;
- cd->users++;
-
- pc_setchatid(sd,cd->bl.id);
-
- clif->joinchatok(sd, cd); //To the person who newly joined the list of all
- 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
-
- return 0;
-}
-
-
-/*==========================================
- * leave a chatroom
- *------------------------------------------*/
-int chat_leavechat(struct map_session_data* sd, bool kicked)
-{
- struct chat_data* cd;
- int i;
- int leavechar;
-
- nullpo_retr(1, sd);
-
- cd = (struct chat_data*)iMap->id2bl(sd->chatID);
- if( cd == NULL )
- {
- pc_setchatid(sd, 0);
- return 1;
- }
-
- ARR_FIND( 0, cd->users, i, cd->usersd[i] == sd );
- if ( i == cd->users )
- { // Not found in the chatroom?
- pc_setchatid(sd, 0);
- return -1;
- }
-
- clif->leavechat(cd, sd, kicked);
- pc_setchatid(sd, 0);
- cd->users--;
-
- leavechar = i;
-
- for( i = leavechar; i < cd->users; i++ )
- cd->usersd[i] = cd->usersd[i+1];
-
-
- if( cd->users == 0 && cd->owner->type == BL_PC ) { // Delete empty chatroom
- struct skill_unit* unit;
- struct skill_unit_group* group;
-
- clif->clearchat(cd, 0);
- db_destroy(cd->kick_list);
- iMap->deliddb(&cd->bl);
- iMap->delblock(&cd->bl);
- iMap->freeblock(&cd->bl);
-
- unit = iMap->find_skill_unit_oncell(&sd->bl, sd->bl.x, sd->bl.y, AL_WARP, NULL, 0);
- group = (unit != NULL) ? unit->group : NULL;
- if (group != NULL)
- skill->unit_onplace(unit, &sd->bl, group->tick);
-
- return 1;
- }
-
- if( leavechar == 0 && cd->owner->type == BL_PC )
- { // Set and announce new owner
- cd->owner = (struct block_list*) cd->usersd[0];
- clif->changechatowner(cd, cd->usersd[0]);
- clif->clearchat(cd, 0);
-
- //Adjust Chat location after owner has been changed.
- iMap->delblock( &cd->bl );
- cd->bl.x=cd->usersd[0]->bl.x;
- cd->bl.y=cd->usersd[0]->bl.y;
- iMap->addblock( &cd->bl );
-
- clif->dispchat(cd,0);
- }
- else
- clif->dispchat(cd,0); // refresh chatroom
-
- return 0;
-}
-
-/*==========================================
- * change a chatroom's owner
- *------------------------------------------*/
-int chat_changechatowner(struct map_session_data* sd, const char* nextownername)
-{
- struct chat_data* cd;
- struct map_session_data* tmpsd;
- int i;
-
- nullpo_retr(1, sd);
-
- cd = (struct chat_data*)iMap->id2bl(sd->chatID);
- if( cd == NULL || (struct block_list*) sd != cd->owner )
- return 1;
-
- ARR_FIND( 1, cd->users, i, strncmp(cd->usersd[i]->status.name, nextownername, NAME_LENGTH) == 0 );
- if( i == cd->users )
- return -1; // name not found
-
- // erase temporarily
- clif->clearchat(cd,0);
-
- // set new owner
- cd->owner = (struct block_list*) cd->usersd[i];
- clif->changechatowner(cd,cd->usersd[i]);
-
- // swap the old and new owners' positions
- tmpsd = cd->usersd[i];
- cd->usersd[i] = cd->usersd[0];
- cd->usersd[0] = tmpsd;
-
- // set the new chatroom position
- iMap->delblock( &cd->bl );
- cd->bl.x = cd->owner->x;
- cd->bl.y = cd->owner->y;
- iMap->addblock( &cd->bl );
-
- // and display again
- clif->dispchat(cd,0);
-
- return 0;
-}
-
-/*==========================================
- * change a chatroom's status (title, etc)
- *------------------------------------------*/
-int chat_changechatstatus(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub)
-{
- struct chat_data* cd;
-
- nullpo_retr(1, sd);
-
- cd = (struct chat_data*)iMap->id2bl(sd->chatID);
- if( cd==NULL || (struct block_list *)sd != cd->owner )
- return 1;
-
- safestrncpy(cd->title, title, CHATROOM_TITLE_SIZE);
- safestrncpy(cd->pass, pass, CHATROOM_PASS_SIZE);
- cd->limit = min(limit, ARRAYLENGTH(cd->usersd));
- cd->pub = pub;
-
- clif->changechatstatus(cd);
- clif->dispchat(cd,0);
-
- return 0;
-}
-
-/*==========================================
- * kick an user from a chatroom
- *------------------------------------------*/
-int chat_kickchat(struct map_session_data* sd, const char* kickusername)
-{
- struct chat_data* cd;
- int i;
-
- nullpo_retr(1, sd);
-
- cd = (struct chat_data *)iMap->id2bl(sd->chatID);
-
- if( cd==NULL || (struct block_list *)sd != cd->owner )
- return -1;
-
- ARR_FIND( 0, cd->users, i, strncmp(cd->usersd[i]->status.name, kickusername, NAME_LENGTH) == 0 );
- if( i == cd->users )
- return -1;
-
- if (pc_has_permission(cd->usersd[i], PC_PERM_NO_CHAT_KICK))
- return 0; //gm kick protection [Valaris]
-
- idb_put(cd->kick_list,cd->usersd[i]->status.char_id,(void*)1);
-
- chat_leavechat(cd->usersd[i],1);
- return 0;
-}
-
-/// Creates a chat room for the npc.
-int chat_createnpcchat(struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl)
-{
- struct chat_data* cd;
- nullpo_ret(nd);
-
- if( nd->chat_id ) {
- ShowError("chat_createnpcchat: npc '%s' already has a chatroom, cannot create new one!\n", nd->exname);
- return 0;
- }
-
- if( zeny > MAX_ZENY || maxLvl > MAX_LEVEL ) {
- ShowError("chat_createnpcchat: npc '%s' has a required lvl or amount of zeny over the max limit!\n", nd->exname);
- return 0;
- }
-
- cd = chat_createchat(&nd->bl, title, "", limit, pub, trigger, ev, zeny, minLvl, maxLvl);
-
- if( cd ) {
- nd->chat_id = cd->bl.id;
- clif->dispchat(cd,0);
- }
-
- return 0;
-}
-
-/// Removes the chatroom from the npc.
-int chat_deletenpcchat(struct npc_data* nd)
-{
- struct chat_data *cd;
- nullpo_ret(nd);
-
- cd = (struct chat_data*)iMap->id2bl(nd->chat_id);
- if( cd == NULL )
- return 0;
-
- chat_npckickall(cd);
- clif->clearchat(cd, 0);
- iMap->deliddb(&cd->bl);
- iMap->delblock(&cd->bl);
- iMap->freeblock(&cd->bl);
- nd->chat_id = 0;
-
- return 0;
-}
-
-/*==========================================
- * Trigger npc event when we enter the chatroom
- *------------------------------------------*/
-int chat_triggerevent(struct chat_data *cd)
-{
- nullpo_ret(cd);
-
- if( cd->users >= cd->trigger && cd->npc_event[0] )
- npc_event_do(cd->npc_event);
- return 0;
-}
-
-/// Enables the event of the chat room.
-/// At most, 127 users are needed to trigger the event.
-int chat_enableevent(struct chat_data* cd)
-{
- nullpo_ret(cd);
-
- cd->trigger &= 0x7f;
- chat_triggerevent(cd);
- return 0;
-}
-
-/// Disables the event of the chat room
-int chat_disableevent(struct chat_data* cd)
-{
- nullpo_ret(cd);
-
- cd->trigger |= 0x80;
- return 0;
-}
-
-/// Kicks all the users from the chat room.
-int chat_npckickall(struct chat_data* cd)
-{
- nullpo_ret(cd);
-
- while( cd->users > 0 )
- chat_leavechat(cd->usersd[cd->users-1],0);
-
- return 0;
-}
+// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
+// For more information, see LICENCE in the main folder
+
+#include "../common/cbasetypes.h"
+#include "../common/malloc.h"
+#include "../common/nullpo.h"
+#include "../common/showmsg.h"
+#include "../common/strlib.h"
+#include "../common/mmo.h"
+#include "atcommand.h" // msg_txt()
+#include "battle.h" // struct battle_config
+#include "clif.h"
+#include "map.h"
+#include "npc.h" // npc_event_do()
+#include "pc.h"
+#include "skill.h" // ext_skill_unit_onplace()
+#include "chat.h"
+
+#include <stdio.h>
+#include <string.h>
+
+
+int chat_triggerevent(struct chat_data *cd); // forward declaration
+
+/// 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* cd;
+ nullpo_retr(NULL, bl);
+
+ cd = (struct chat_data *) aMalloc(sizeof(struct chat_data));
+
+ safestrncpy(cd->title, title, sizeof(cd->title));
+ safestrncpy(cd->pass, pass, sizeof(cd->pass));
+ cd->pub = pub;
+ cd->users = 0;
+ cd->limit = min(limit, ARRAYLENGTH(cd->usersd));
+ cd->trigger = trigger;
+ cd->zeny = zeny;
+ cd->minLvl = minLvl;
+ cd->maxLvl = maxLvl;
+ memset(cd->usersd, 0, sizeof(cd->usersd));
+ cd->owner = bl;
+ safestrncpy(cd->npc_event, ev, sizeof(cd->npc_event));
+
+ cd->bl.id = iMap->get_new_object_id();
+ cd->bl.m = bl->m;
+ cd->bl.x = bl->x;
+ cd->bl.y = bl->y;
+ cd->bl.type = BL_CHAT;
+ cd->bl.next = cd->bl.prev = NULL;
+
+ if( cd->bl.id == 0 )
+ {
+ aFree(cd);
+ cd = NULL;
+ }
+
+ iMap->addiddb(&cd->bl);
+
+ if( bl->type != BL_NPC )
+ cd->kick_list = idb_alloc(DB_OPT_BASE);
+
+ return cd;
+}
+
+/*==========================================
+ * player chatroom creation
+ *------------------------------------------*/
+int chat_createpcchat(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub)
+{
+ struct chat_data* cd;
+ nullpo_ret(sd);
+
+ if( sd->chatID )
+ return 0; //Prevent people abusing the chat system by creating multiple chats, as pointed out by End of Exam. [Skotlex]
+
+ if( sd->state.vending || sd->state.buyingstore )
+ {// not chat, when you already have a store open
+ return 0;
+ }
+
+ if( map[sd->bl.m].flag.nochat )
+ {
+ clif->message(sd->fd, msg_txt(281));
+ return 0; //Can't create chatrooms on this map.
+ }
+
+ if( iMap->getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOCHAT) )
+ {
+ clif->message (sd->fd, msg_txt(665));
+ return 0;
+ }
+
+ pc_stop_walking(sd,1);
+
+ cd = chat_createchat(&sd->bl, title, pass, limit, pub, 0, "", 0, 1, MAX_LEVEL);
+ if( cd ) {
+ cd->users = 1;
+ cd->usersd[0] = sd;
+ pc_setchatid(sd,cd->bl.id);
+ pc_stop_attack(sd);
+ clif->createchat(sd,0);
+ clif->dispchat(cd,0);
+ } else
+ clif->createchat(sd,1);
+
+ return 0;
+}
+
+/*==========================================
+ * join an existing chatroom
+ *------------------------------------------*/
+int chat_joinchat(struct map_session_data* sd, int chatid, const char* pass)
+{
+ struct chat_data* cd;
+
+ nullpo_ret(sd);
+ cd = (struct chat_data*)iMap->id2bl(chatid);
+
+ if( cd == NULL || cd->bl.type != BL_CHAT || cd->bl.m != sd->bl.m || sd->state.vending || sd->state.buyingstore || sd->chatID || ((cd->owner->type == BL_NPC) ? cd->users+1 : cd->users) >= cd->limit )
+ {
+ clif->joinchatfail(sd,0);
+ return 0;
+ }
+
+ if( !cd->pub && strncmp(pass, cd->pass, sizeof(cd->pass)) != 0 && !pc_has_permission(sd, PC_PERM_JOIN_ALL_CHAT) )
+ {
+ clif->joinchatfail(sd,1);
+ return 0;
+ }
+
+ if( sd->status.base_level < cd->minLvl || sd->status.base_level > cd->maxLvl ) {
+ if(sd->status.base_level < cd->minLvl)
+ clif->joinchatfail(sd,5);
+ else
+ clif->joinchatfail(sd,6);
+
+ return 0;
+ }
+
+ if( sd->status.zeny < cd->zeny ) {
+ clif->joinchatfail(sd,4);
+ return 0;
+ }
+
+ if( cd->owner->type != BL_NPC && idb_exists(cd->kick_list,sd->status.char_id) ) {
+ clif->joinchatfail(sd,2);//You have been kicked out of the room.
+ return 0;
+ }
+
+ pc_stop_walking(sd,1);
+ cd->usersd[cd->users] = sd;
+ cd->users++;
+
+ pc_setchatid(sd,cd->bl.id);
+
+ clif->joinchatok(sd, cd); //To the person who newly joined the list of all
+ 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
+
+ return 0;
+}
+
+
+/*==========================================
+ * leave a chatroom
+ *------------------------------------------*/
+int chat_leavechat(struct map_session_data* sd, bool kicked)
+{
+ struct chat_data* cd;
+ int i;
+ int leavechar;
+
+ nullpo_retr(1, sd);
+
+ cd = (struct chat_data*)iMap->id2bl(sd->chatID);
+ if( cd == NULL )
+ {
+ pc_setchatid(sd, 0);
+ return 1;
+ }
+
+ ARR_FIND( 0, cd->users, i, cd->usersd[i] == sd );
+ if ( i == cd->users )
+ { // Not found in the chatroom?
+ pc_setchatid(sd, 0);
+ return -1;
+ }
+
+ clif->leavechat(cd, sd, kicked);
+ pc_setchatid(sd, 0);
+ cd->users--;
+
+ leavechar = i;
+
+ for( i = leavechar; i < cd->users; i++ )
+ cd->usersd[i] = cd->usersd[i+1];
+
+
+ if( cd->users == 0 && cd->owner->type == BL_PC ) { // Delete empty chatroom
+ struct skill_unit* unit;
+ struct skill_unit_group* group;
+
+ clif->clearchat(cd, 0);
+ db_destroy(cd->kick_list);
+ iMap->deliddb(&cd->bl);
+ iMap->delblock(&cd->bl);
+ iMap->freeblock(&cd->bl);
+
+ unit = iMap->find_skill_unit_oncell(&sd->bl, sd->bl.x, sd->bl.y, AL_WARP, NULL, 0);
+ group = (unit != NULL) ? unit->group : NULL;
+ if (group != NULL)
+ skill->unit_onplace(unit, &sd->bl, group->tick);
+
+ return 1;
+ }
+
+ if( leavechar == 0 && cd->owner->type == BL_PC )
+ { // Set and announce new owner
+ cd->owner = (struct block_list*) cd->usersd[0];
+ clif->changechatowner(cd, cd->usersd[0]);
+ clif->clearchat(cd, 0);
+
+ //Adjust Chat location after owner has been changed.
+ iMap->delblock( &cd->bl );
+ cd->bl.x=cd->usersd[0]->bl.x;
+ cd->bl.y=cd->usersd[0]->bl.y;
+ iMap->addblock( &cd->bl );
+
+ clif->dispchat(cd,0);
+ }
+ else
+ clif->dispchat(cd,0); // refresh chatroom
+
+ return 0;
+}
+
+/*==========================================
+ * change a chatroom's owner
+ *------------------------------------------*/
+int chat_changechatowner(struct map_session_data* sd, const char* nextownername)
+{
+ struct chat_data* cd;
+ struct map_session_data* tmpsd;
+ int i;
+
+ nullpo_retr(1, sd);
+
+ cd = (struct chat_data*)iMap->id2bl(sd->chatID);
+ if( cd == NULL || (struct block_list*) sd != cd->owner )
+ return 1;
+
+ ARR_FIND( 1, cd->users, i, strncmp(cd->usersd[i]->status.name, nextownername, NAME_LENGTH) == 0 );
+ if( i == cd->users )
+ return -1; // name not found
+
+ // erase temporarily
+ clif->clearchat(cd,0);
+
+ // set new owner
+ cd->owner = (struct block_list*) cd->usersd[i];
+ clif->changechatowner(cd,cd->usersd[i]);
+
+ // swap the old and new owners' positions
+ tmpsd = cd->usersd[i];
+ cd->usersd[i] = cd->usersd[0];
+ cd->usersd[0] = tmpsd;
+
+ // set the new chatroom position
+ iMap->delblock( &cd->bl );
+ cd->bl.x = cd->owner->x;
+ cd->bl.y = cd->owner->y;
+ iMap->addblock( &cd->bl );
+
+ // and display again
+ clif->dispchat(cd,0);
+
+ return 0;
+}
+
+/*==========================================
+ * change a chatroom's status (title, etc)
+ *------------------------------------------*/
+int chat_changechatstatus(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub)
+{
+ struct chat_data* cd;
+
+ nullpo_retr(1, sd);
+
+ cd = (struct chat_data*)iMap->id2bl(sd->chatID);
+ if( cd==NULL || (struct block_list *)sd != cd->owner )
+ return 1;
+
+ safestrncpy(cd->title, title, CHATROOM_TITLE_SIZE);
+ safestrncpy(cd->pass, pass, CHATROOM_PASS_SIZE);
+ cd->limit = min(limit, ARRAYLENGTH(cd->usersd));
+ cd->pub = pub;
+
+ clif->changechatstatus(cd);
+ clif->dispchat(cd,0);
+
+ return 0;
+}
+
+/*==========================================
+ * kick an user from a chatroom
+ *------------------------------------------*/
+int chat_kickchat(struct map_session_data* sd, const char* kickusername)
+{
+ struct chat_data* cd;
+ int i;
+
+ nullpo_retr(1, sd);
+
+ cd = (struct chat_data *)iMap->id2bl(sd->chatID);
+
+ if( cd==NULL || (struct block_list *)sd != cd->owner )
+ return -1;
+
+ ARR_FIND( 0, cd->users, i, strncmp(cd->usersd[i]->status.name, kickusername, NAME_LENGTH) == 0 );
+ if( i == cd->users )
+ return -1;
+
+ if (pc_has_permission(cd->usersd[i], PC_PERM_NO_CHAT_KICK))
+ return 0; //gm kick protection [Valaris]
+
+ idb_put(cd->kick_list,cd->usersd[i]->status.char_id,(void*)1);
+
+ chat->leavechat(cd->usersd[i],1);
+ return 0;
+}
+
+/// Creates a chat room for the npc.
+int chat_createnpcchat(struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl)
+{
+ struct chat_data* cd;
+ nullpo_ret(nd);
+
+ if( nd->chat_id ) {
+ ShowError("chat_createnpcchat: npc '%s' already has a chatroom, cannot create new one!\n", nd->exname);
+ return 0;
+ }
+
+ if( zeny > MAX_ZENY || maxLvl > MAX_LEVEL ) {
+ ShowError("chat_createnpcchat: npc '%s' has a required lvl or amount of zeny over the max limit!\n", nd->exname);
+ return 0;
+ }
+
+ cd = chat_createchat(&nd->bl, title, "", limit, pub, trigger, ev, zeny, minLvl, maxLvl);
+
+ if( cd ) {
+ nd->chat_id = cd->bl.id;
+ clif->dispchat(cd,0);
+ }
+
+ return 0;
+}
+
+/// Removes the chatroom from the npc.
+int chat_deletenpcchat(struct npc_data* nd)
+{
+ struct chat_data *cd;
+ nullpo_ret(nd);
+
+ cd = (struct chat_data*)iMap->id2bl(nd->chat_id);
+ if( cd == NULL )
+ return 0;
+
+ chat->npckickall(cd);
+ clif->clearchat(cd, 0);
+ iMap->deliddb(&cd->bl);
+ iMap->delblock(&cd->bl);
+ iMap->freeblock(&cd->bl);
+ nd->chat_id = 0;
+
+ return 0;
+}
+
+/*==========================================
+ * Trigger npc event when we enter the chatroom
+ *------------------------------------------*/
+int chat_triggerevent(struct chat_data *cd)
+{
+ nullpo_ret(cd);
+
+ if( cd->users >= cd->trigger && cd->npc_event[0] )
+ npc_event_do(cd->npc_event);
+ return 0;
+}
+
+/// Enables the event of the chat room.
+/// At most, 127 users are needed to trigger the event.
+int chat_enableevent(struct chat_data* cd)
+{
+ nullpo_ret(cd);
+
+ cd->trigger &= 0x7f;
+ chat_triggerevent(cd);
+ return 0;
+}
+
+/// Disables the event of the chat room
+int chat_disableevent(struct chat_data* cd)
+{
+ nullpo_ret(cd);
+
+ cd->trigger |= 0x80;
+ return 0;
+}
+
+/// Kicks all the users from the chat room.
+int chat_npckickall(struct chat_data* cd)
+{
+ nullpo_ret(cd);
+
+ while( cd->users > 0 )
+ chat->leavechat(cd->usersd[cd->users-1],0);
+
+ return 0;
+}
+
+/*=====================================
+* Default Functions : chat.h
+* Generated by HerculesInterfaceMaker
+* created by Susu
+*-------------------------------------*/
+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;
+}
diff --git a/src/map/chat.h b/src/map/chat.h
index cb2e6ecd9..ff78d8617 100644
--- a/src/map/chat.h
+++ b/src/map/chat.h
@@ -1,43 +1,56 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
-
-#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
- char pass[CHATROOM_PASS_SIZE]; // password
- bool pub; // private/public flag
- uint8 users; // current user count
- uint8 limit; // join limit
- uint8 trigger; // number of users needed to trigger event
- uint32 zeny; // required zeny to join
- uint32 minLvl; // minimum base level to join
- uint32 maxLvl; // maximum base level allowed to join
- struct map_session_data* usersd[20];
- struct block_list* owner;
- char npc_event[EVENT_NAME_LENGTH];
- DBMap* kick_list; //DBMap of users who were kicked from this chat
-};
-
-
-int chat_createpcchat(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub);
-int chat_joinchat(struct map_session_data* sd, int chatid, const char* pass);
-int chat_leavechat(struct map_session_data* sd, bool kicked);
-int chat_changechatowner(struct map_session_data* sd, const char* nextownername);
-int chat_changechatstatus(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub);
-int chat_kickchat(struct map_session_data* sd, const char* kickusername);
-
-int chat_createnpcchat(struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl);
-int chat_deletenpcchat(struct npc_data* nd);
-int chat_enableevent(struct chat_data* cd);
-int chat_disableevent(struct chat_data* cd);
-int chat_npckickall(struct chat_data* cd);
-
-#endif /* _CHAT_H_ */
+// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
+// For more information, see LICENCE in the main folder
+#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
+ char pass[CHATROOM_PASS_SIZE]; // password
+ bool pub; // private/public flag
+ uint8 users; // current user count
+ uint8 limit; // join limit
+ uint8 trigger; // number of users needed to trigger event
+ uint32 zeny; // required zeny to join
+ uint32 minLvl; // minimum base level to join
+ uint32 maxLvl; // maximum base level allowed to join
+ struct map_session_data* usersd[20];
+ struct block_list* owner;
+ char npc_event[EVENT_NAME_LENGTH];
+ 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;
+
+struct chat_interface *chat;
+
+void chat_defaults(void);
+
+#endif /* _CHAT_H_ */
diff --git a/src/map/clif.c b/src/map/clif.c
index 718b98bc5..8377eed5c 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -8573,7 +8573,7 @@ void clif_refresh(struct map_session_data *sd)
iMap->foreachinrange(clif->getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
clif->weather_check(sd);
if( sd->chatID )
- chat_leavechat(sd,0);
+ chat->leavechat(sd,0);
if( sd->state.vending )
clif->openvending(sd, sd->bl.id, sd->vending);
if( pc_issit(sd) )
@@ -10966,7 +10966,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->createpcchat(sd, s_title, s_password, limit, pub);
}
@@ -10977,7 +10977,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->joinchat(sd,chatid,password);
}
@@ -11002,7 +11002,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->changechatstatus(sd, s_title, s_password, limit, pub);
}
@@ -11013,7 +11013,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->changechatowner(sd,(char*)RFIFOP(fd,6));
}
@@ -11021,7 +11021,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->kickchat(sd,(char*)RFIFOP(fd,2));
}
@@ -11029,7 +11029,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->leavechat(sd,0);
}
diff --git a/src/map/npc.c b/src/map/npc.c
index 911fbe1d4..6bb058229 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -1817,7 +1817,7 @@ int npc_unload(struct npc_data* nd, bool single) {
strdb_remove(npcname_db, nd->exname);
if (nd->chat_id) // remove npc chatroom object and kick users
- chat_deletenpcchat(nd);
+ chat->deletenpcchat(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 865673630..0827eb497 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -10017,7 +10017,7 @@ BUILDIN(waitingroom)
nd = (struct npc_data *)iMap->id2bl(st->oid);
if( nd != NULL )
- chat_createnpcchat(nd, title, limit, pub, trigger, ev, zeny, minLvl, maxLvl);
+ chat->createnpcchat(nd, title, limit, pub, trigger, ev, zeny, minLvl, maxLvl);
return true;
}
@@ -10034,7 +10034,7 @@ BUILDIN(delwaitingroom)
else
nd = (struct npc_data *)iMap->id2bl(st->oid);
if( nd != NULL )
- chat_deletenpcchat(nd);
+ chat->deletenpcchat(nd);
return true;
}
@@ -10053,7 +10053,7 @@ BUILDIN(waitingroomkickall)
nd = (struct npc_data *)iMap->id2bl(st->oid);
if( nd != NULL && (cd=(struct chat_data *)iMap->id2bl(nd->chat_id)) != NULL )
- chat_npckickall(cd);
+ chat->npckickall(cd);
return true;
}
@@ -10072,7 +10072,7 @@ BUILDIN(enablewaitingroomevent)
nd = (struct npc_data *)iMap->id2bl(st->oid);
if( nd != NULL && (cd=(struct chat_data *)iMap->id2bl(nd->chat_id)) != NULL )
- chat_enableevent(cd);
+ chat->enableevent(cd);
return true;
}
@@ -10091,7 +10091,7 @@ BUILDIN(disablewaitingroomevent)
nd = (struct npc_data *)iMap->id2bl(st->oid);
if( nd != NULL && (cd=(struct chat_data *)iMap->id2bl(nd->chat_id)) != NULL )
- chat_disableevent(cd);
+ chat->disableevent(cd);
return true;
}
diff --git a/src/map/unit.c b/src/map/unit.c
index b1ed24666..38606230f 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -2131,7 +2131,7 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
}
//Leave/reject all invitations.
if(sd->chatID)
- chat_leavechat(sd,0);
+ chat->leavechat(sd,0);
if(sd->trade_partner)
trade->cancel(sd);
buyingstore->close(sd);