From e443f846c610d870b8d3d38526d09f0ec00ad44f Mon Sep 17 00:00:00 2001 From: Lemongrass3110 Date: Wed, 12 Oct 2016 22:52:40 +0200 Subject: [PATCH] Increased EVENT_NAME_LENGTH and some more cleanups Fixed an invalid reference in clif.c(follow up to 008be23) Moved the OnWhisperGlobal name definition to the other special event name declarations Increased EVENT_NAME_LENGTH from 51 to 77 characters because it uses NPCs exname which can be up to 50 characters now Added a warning when an NPCs exname is too long for an OnWhisperEvent --- src/map/clif.c | 4 ++-- src/map/map.h | 4 ++-- src/map/npc.c | 8 ++++++++ src/map/script.c | 2 ++ src/map/script.h | 1 + 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/map/clif.c b/src/map/clif.c index 11bd1b6901..b76197668a 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -11035,7 +11035,7 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd) set_var(sd,variablename,(char *) split_data[i]); } - safesnprintf(event,sizeof(event),"%s::OnWhisperGlobal", npc->exname); + safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name); npc_event(sd,event,0); // Calls the NPC label return; @@ -14119,7 +14119,7 @@ void clif_friendslist_send(struct map_session_data *sd) for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) { WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id; WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id; - safestrncpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH); + safestrncpy(WFIFOP(fd, 4 + 32 * i + 8), sd->status.friends[i].name, NAME_LENGTH); } if (i) { diff --git a/src/map/map.h b/src/map/map.h index b61980d030..8f2ec969fe 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -211,8 +211,8 @@ enum e_mapid { #define CHATROOM_PASS_SIZE (8 + 1) //Max allowed chat text length #define CHAT_SIZE_MAX (255 + 1) -//24 for npc name + 24 for label + 2 for a "::" and 1 for EOS -#define EVENT_NAME_LENGTH ( NAME_LENGTH * 2 + 3 ) +// for npc name + 2 for a "::" + for label + 1 for EOS +#define EVENT_NAME_LENGTH ( NPC_NAME_LENGTH + 2 + NAME_LENGTH + 1 ) #define DEFAULT_AUTOSAVE_INTERVAL 5*60*1000 diff --git a/src/map/npc.c b/src/map/npc.c index 33ad7c3903..b005f4c4cf 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -336,6 +336,14 @@ static int npc_event_export(struct npc_data *nd, int i) if ((lname[0] == 'O' || lname[0] == 'o') && (lname[1] == 'N' || lname[1] == 'n')) { struct event_data *ev; char buf[EVENT_NAME_LENGTH]; + + // NPC: the prefix uses 4 characters + if( !strncasecmp( lname, script_config.onwhisper_event_name, NAME_LENGTH ) && strlen(nd->exname) > ( NAME_LENGTH - 4 ) ){ + // The client only allows that many character so that NPC could not be whispered by unmodified clients + ShowWarning( "Whisper event in npc '"CL_WHITE"%s"CL_RESET"' was ignored, because it's name is too long.\n", nd->exname ); + return 0; + } + snprintf(buf, ARRAYLENGTH(buf), "%s::%s", nd->exname, lname); // generate the data and insert it CREATE(ev, struct event_data, 1); diff --git a/src/map/script.c b/src/map/script.c index b42486cf07..73f8c452ff 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -185,6 +185,7 @@ struct Script_Config script_config = { 1, // warn_func_mismatch_argtypes 1, 65535, 2048, //warn_func_mismatch_paramnum/check_cmdcount/check_gotocount 0, INT_MAX, // input_min_value/input_max_value + // NOTE: None of these event labels should be longer than characters "OnPCDieEvent", //die_event_name "OnPCKillEvent", //kill_pc_event_name "OnNPCKillEvent", //kill_mob_event_name @@ -196,6 +197,7 @@ struct Script_Config script_config = { "OnPCStatCalcEvent", //stat_calc_event_name "OnTouch_", //ontouch_name (runs on first visible char to enter area, picks another char if the first char leaves) "OnTouch", //ontouch2_name (run whenever a char walks into the OnTouch area) + "OnWhisperGlobal", //onwhisper_event_name (is executed when a player sends a whisper message to the NPC) }; static jmp_buf error_jump; diff --git a/src/map/script.h b/src/map/script.h index 1e07e2774f..8a1ee42813 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -160,6 +160,7 @@ extern struct Script_Config { const char* ontouch_name; const char* ontouch2_name; + const char* onwhisper_event_name; } script_config; typedef enum c_op {