diff options
Diffstat (limited to 'src/map/chat.c')
-rw-r--r-- | src/map/chat.c | 92 |
1 files changed, 57 insertions, 35 deletions
diff --git a/src/map/chat.c b/src/map/chat.c index d60b9bece..097fbdca4 100644 --- a/src/map/chat.c +++ b/src/map/chat.c @@ -2,8 +2,8 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team - * Copyright (C) Athena Dev Teams + * Copyright (C) 2012-2020 Hercules Dev Team + * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,6 +29,7 @@ #include "map/npc.h" // npc_event_do() #include "map/pc.h" #include "map/skill.h" // ext_skill_unit_onplace() +#include "map/achievement.h" #include "common/cbasetypes.h" #include "common/memmgr.h" #include "common/mmo.h" @@ -39,12 +40,12 @@ #include <stdio.h> #include <string.h> -struct chat_interface chat_s; +static struct chat_interface chat_s; struct chat_interface *chat; /// Initializes a chatroom object (common functionality for both pc and npc chatrooms). /// Returns a chatroom object on success, or NULL on failure. -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) +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 min_level, int max_level) { struct chat_data* cd; nullpo_retr(NULL, bl); @@ -62,8 +63,8 @@ struct chat_data* chat_createchat(struct block_list* bl, const char* title, cons cd->limit = min(limit, ARRAYLENGTH(cd->usersd)); cd->trigger = trigger; cd->zeny = zeny; - cd->minLvl = minLvl; - cd->maxLvl = maxLvl; + cd->min_level = min_level; + cd->max_level = max_level; memset(cd->usersd, 0, sizeof(cd->usersd)); cd->owner = bl; safestrncpy(cd->npc_event, ev, sizeof(cd->npc_event)); @@ -91,23 +92,24 @@ struct chat_data* chat_createchat(struct block_list* bl, const char* title, cons /*========================================== * player chatroom creation *------------------------------------------*/ -bool chat_createpcchat(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub) { +static bool chat_createpcchat(struct map_session_data *sd, const char *title, const char *pass, int limit, bool pub) +{ struct chat_data* cd; nullpo_ret(sd); nullpo_ret(title); nullpo_ret(pass); - if( sd->chatID ) + if (sd->chat_id != 0) return false; //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 ) + if (sd->state.vending || sd->state.prevend || sd->state.buyingstore) {// not chat, when you already have a store open return false; } if( map->list[sd->bl.m].flag.nochat ) { - clif->message(sd->fd, msg_sd(sd,281)); - return false; //Can't create chatrooms on this map. + clif->message(sd->fd, msg_sd(sd,281)); // You can't create chat rooms in this map + return false; } if (map->getcell(sd->bl.m, &sd->bl, sd->bl.x, sd->bl.y, CELL_CHKNOCHAT) ) { @@ -125,6 +127,7 @@ bool chat_createpcchat(struct map_session_data* sd, const char* title, const cha pc_stop_attack(sd); clif->createchat(sd,0); // 0 = success clif->dispchat(cd,0); + achievement->validate_chatroom_create(sd); // Achievements [Smokexyz/Hercules] return true; } clif->createchat(sd,1); // 1 = Room limit exceeded @@ -135,15 +138,18 @@ bool chat_createpcchat(struct map_session_data* sd, const char* title, const cha /*========================================== * join an existing chatroom *------------------------------------------*/ -bool chat_joinchat(struct map_session_data* sd, int chatid, const char* pass) { +static bool chat_joinchat(struct map_session_data *sd, int chatid, const char *pass) +{ struct chat_data* cd; nullpo_ret(sd); nullpo_ret(pass); cd = map->id2cd(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 ) - { + if (cd == NULL || cd->bl.type != BL_CHAT || cd->bl.m != sd->bl.m + || sd->state.vending || sd->state.prevend || sd->state.buyingstore || sd->chat_id != 0 + || ((cd->owner->type == BL_NPC) ? cd->users+1 : cd->users) >= cd->limit + ) { clif->joinchatfail(sd,0); // room full return false; } @@ -154,8 +160,8 @@ bool chat_joinchat(struct map_session_data* sd, int chatid, const char* pass) { return false; } - if( sd->status.base_level < cd->minLvl || sd->status.base_level > cd->maxLvl ) { - if(sd->status.base_level < cd->minLvl) + if (sd->status.base_level < cd->min_level || sd->status.base_level > cd->max_level) { + if(sd->status.base_level < cd->min_level) clif->joinchatfail(sd,5); // too low level else clif->joinchatfail(sd,6); // too high level @@ -177,6 +183,9 @@ bool chat_joinchat(struct map_session_data* sd, int chatid, const char* pass) { cd->usersd[cd->users] = sd; cd->users++; + if (cd->owner->type == BL_PC) + achievement->validate_chatroom_members(BL_UCAST(BL_PC, cd->owner), cd->users); + pc_setchatid(sd,cd->bl.id); clif->joinchatok(sd, cd); //To the person who newly joined the list of all @@ -188,7 +197,6 @@ bool chat_joinchat(struct map_session_data* sd, int chatid, const char* pass) { return true; } - /*========================================== * Leave a chatroom * Return @@ -197,15 +205,16 @@ bool chat_joinchat(struct map_session_data* sd, int chatid, const char* pass) { * 2: Chat room deleted (chat room empty) * 3: Owner changed (Owner left and a new one as assigned) *------------------------------------------*/ -int chat_leavechat(struct map_session_data* sd, bool kicked) { +static int chat_leavechat(struct map_session_data *sd, bool kicked) +{ struct chat_data* cd; int i; int leavechar; nullpo_retr(0, sd); - cd = map->id2cd(sd->chatID); - if( cd == NULL ) { + cd = map->id2cd(sd->chat_id); + if (cd == NULL) { pc_setchatid(sd, 0); return 0; } @@ -246,6 +255,14 @@ int chat_leavechat(struct map_session_data* sd, bool kicked) { } if( leavechar == 0 && cd->owner->type == BL_PC ) { + + // check if new location are CELL_CHKNOCHAT + if (map->getcell(cd->usersd[0]->bl.m, NULL, cd->usersd[0]->bl.x, cd->usersd[0]->bl.y, CELL_CHKNOCHAT)) { + for (i = (cd->users - 1); i >= 0; i--) + chat->leave(cd->usersd[i], false); + return 2; + } + // Set and announce new owner cd->owner = &cd->usersd[0]->bl; clif->changechatowner(cd, cd->usersd[0]); @@ -271,7 +288,8 @@ int chat_leavechat(struct map_session_data* sd, bool kicked) { * 0: User not found/Missing data * 1: Success *------------------------------------------*/ -bool chat_changechatowner(struct map_session_data* sd, const char* nextownername) { +static bool chat_changechatowner(struct map_session_data *sd, const char *nextownername) +{ struct chat_data* cd; struct map_session_data* tmpsd; int i; @@ -279,7 +297,7 @@ bool chat_changechatowner(struct map_session_data* sd, const char* nextownername nullpo_ret(sd); nullpo_ret(nextownername); - cd = map->id2cd(sd->chatID); + cd = map->id2cd(sd->chat_id); if (cd == NULL || &sd->bl != cd->owner) return false; @@ -317,14 +335,15 @@ bool chat_changechatowner(struct map_session_data* sd, const char* nextownername * 0: Missing data * 1: Success *------------------------------------------*/ -bool chat_changechatstatus(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub) { +static bool chat_changechatstatus(struct map_session_data *sd, const char *title, const char *pass, int limit, bool pub) +{ struct chat_data* cd; nullpo_ret(sd); nullpo_ret(title); nullpo_ret(pass); - cd = map->id2cd(sd->chatID); + cd = map->id2cd(sd->chat_id); if (cd == NULL || &sd->bl != cd->owner) return false; @@ -345,14 +364,15 @@ bool chat_changechatstatus(struct map_session_data* sd, const char* title, const * 0: User cannot be kicked (is gm)/Missing data * 1: Success *------------------------------------------*/ -bool chat_kickchat(struct map_session_data* sd, const char* kickusername) { +static bool chat_kickchat(struct map_session_data *sd, const char *kickusername) +{ struct chat_data* cd; int i; nullpo_ret(sd); nullpo_ret(kickusername); - cd = map->id2cd(sd->chatID); + cd = map->id2cd(sd->chat_id); if (cd == NULL || &sd->bl != cd->owner) return false; @@ -373,7 +393,7 @@ bool chat_kickchat(struct map_session_data* sd, const char* kickusername) { /*========================================== * Creates a chat room for the npc *------------------------------------------*/ -bool chat_createnpcchat(struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl) +static bool chat_createnpcchat(struct npc_data *nd, const char *title, int limit, bool pub, int trigger, const char *ev, int zeny, int min_level, int max_level) { struct chat_data* cd; nullpo_ret(nd); @@ -383,12 +403,12 @@ bool chat_createnpcchat(struct npc_data* nd, const char* title, int limit, bool return false; } - if( zeny > MAX_ZENY || maxLvl > MAX_LEVEL ) { + if (zeny > MAX_ZENY || max_level > MAX_LEVEL) { ShowError("chat_createnpcchat: npc '%s' has a required lvl or amount of zeny over the max limit!\n", nd->exname); return false; } - cd = chat->create(&nd->bl, title, "", limit, pub, trigger, ev, zeny, minLvl, maxLvl); + cd = chat->create(&nd->bl, title, "", limit, pub, trigger, ev, zeny, min_level, max_level); if( cd ) { nd->chat_id = cd->bl.id; @@ -405,7 +425,8 @@ bool chat_createnpcchat(struct npc_data* nd, const char* title, int limit, bool * 0: Missing data * 1: Success *------------------------------------------*/ -bool chat_deletenpcchat(struct npc_data* nd) { +static bool chat_deletenpcchat(struct npc_data *nd) +{ struct chat_data *cd; nullpo_ret(nd); @@ -429,7 +450,7 @@ bool chat_deletenpcchat(struct npc_data* nd) { * 0: Couldn't trigger / Missing data * 1: Success *------------------------------------------*/ -bool chat_triggerevent(struct chat_data *cd) +static bool chat_triggerevent(struct chat_data *cd) { nullpo_ret(cd); @@ -443,7 +464,7 @@ bool chat_triggerevent(struct chat_data *cd) /// Enables the event of the chat room. /// At most, 127 users are needed to trigger the event. -bool chat_enableevent(struct chat_data* cd) +static bool chat_enableevent(struct chat_data *cd) { nullpo_ret(cd); @@ -453,7 +474,7 @@ bool chat_enableevent(struct chat_data* cd) } /// Disables the event of the chat room -bool chat_disableevent(struct chat_data* cd) +static bool chat_disableevent(struct chat_data *cd) { nullpo_ret(cd); @@ -462,7 +483,7 @@ bool chat_disableevent(struct chat_data* cd) } /// Kicks all the users from the chat room. -bool chat_npckickall(struct chat_data* cd) +static bool chat_npckickall(struct chat_data *cd) { nullpo_ret(cd); @@ -477,7 +498,8 @@ bool chat_npckickall(struct chat_data* cd) * Generated by HerculesInterfaceMaker * created by Susu *-------------------------------------*/ -void chat_defaults(void) { +void chat_defaults(void) +{ chat = &chat_s; /* funcs */ |