summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-04-21 23:03:43 +0200
committerHaru <haru@dotalux.com>2016-04-23 09:52:31 +0200
commit7aa70331b7dcfb21533c3806a694819e70f936c2 (patch)
treef92b7137a7f0cf65ffbe5553b0075181b5b5891c /src/map
parentccfd0549ce64e84e41069ec8e040ce9806b963f2 (diff)
downloadhercules-7aa70331b7dcfb21533c3806a694819e70f936c2.tar.gz
hercules-7aa70331b7dcfb21533c3806a694819e70f936c2.tar.bz2
hercules-7aa70331b7dcfb21533c3806a694819e70f936c2.tar.xz
hercules-7aa70331b7dcfb21533c3806a694819e70f936c2.zip
Removed some code duplication in chat processing functions
Moved non-clif code that handles chat delay, atcommand detection, idle timers to pc.c Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map')
-rw-r--r--src/map/clif.c77
-rw-r--r--src/map/pc.c31
-rw-r--r--src/map/pc.h1
3 files changed, 37 insertions, 72 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index abb08d498..2dea386be 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -8931,6 +8931,8 @@ const char *clif_process_chat_message(struct map_session_data *sd, const struct
safestrncpy(out_buf, packet->message, textlen+1); // [!] packet->message is not necessarily NUL terminated
message = out_buf + namelen + 3;
+ if (!pc->process_chat_message(sd, message))
+ return NULL;
return message;
}
@@ -8993,6 +8995,9 @@ bool clif_process_whisper_message(struct map_session_data *sd, const struct pack
safestrncpy(out_name, packet->name, namelen+1); // [!] packet->name is not NUL terminated
safestrncpy(out_message, packet->message, messagelen+1); // [!] packet->message is not necessarily NUL terminated
+ if (!pc->process_chat_message(sd, out_message))
+ return false;
+
return true;
}
@@ -9767,22 +9772,8 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data *sd)
if (message == NULL)
return;
- if( atcommand->exec(fd, sd, message, true) )
- return;
-
- if( !pc->can_talk(sd) )
- return;
-
- if( battle_config.min_chat_delay ) { //[Skotlex]
- if (DIFF_TICK(sd->cantalk_tick, timer->gettick()) > 0)
- return;
- sd->cantalk_tick = timer->gettick() + battle_config.min_chat_delay;
- }
-
pc->check_supernovice_call(sd, message);
- pc->update_idle_time(sd, BCIDLE_CHAT);
-
if (sd->gcbind != NULL) {
channel->send(sd->gcbind, sd, message);
return;
@@ -10151,22 +10142,6 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
if (!clif->process_whisper_message(sd, packet, target, message, sizeof message))
return;
- if ( atcommand->exec(fd, sd, message, true) )
- return;
-
- // Statuses that prevent the player from whispering
- if( !pc->can_talk(sd) )
- return;
-
- if (battle_config.min_chat_delay) { //[Skotlex]
- if (DIFF_TICK(sd->cantalk_tick, timer->gettick()) > 0) {
- return;
- }
- sd->cantalk_tick = timer->gettick() + battle_config.min_chat_delay;
- }
-
- pc->update_idle_time(sd, BCIDLE_CHAT);
-
// Chat logging type 'W' / Whisper
logs->chat(LOG_CHAT_WHISPER, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
@@ -11985,20 +11960,6 @@ void clif_parse_PartyMessage(int fd, struct map_session_data *sd)
if (clif->process_chat_message(sd, packet, message, sizeof message) == NULL)
return;
- if( atcommand->exec(fd, sd, message, true) )
- return;
-
- if( !pc->can_talk(sd) )
- return;
-
- if (battle_config.min_chat_delay) {
- if (DIFF_TICK(sd->cantalk_tick, timer->gettick()) > 0)
- return;
- sd->cantalk_tick = timer->gettick() + battle_config.min_chat_delay;
- }
-
- pc->update_idle_time(sd, BCIDLE_CHAT);
-
party->send_message(sd, message, (int)strlen(message));
}
@@ -13097,20 +13058,6 @@ void clif_parse_GuildMessage(int fd, struct map_session_data *sd)
if (clif->process_chat_message(sd, packet, message, sizeof message) == NULL)
return;
- if( atcommand->exec(fd, sd, message, true) )
- return;
-
- if( !pc->can_talk(sd) )
- return;
-
- if (battle_config.min_chat_delay) {
- if (DIFF_TICK(sd->cantalk_tick, timer->gettick()) > 0)
- return;
- sd->cantalk_tick = timer->gettick() + battle_config.min_chat_delay;
- }
-
- pc->update_idle_time(sd, BCIDLE_CHAT);
-
if (sd->bg_id)
bg->send_message(sd, message, (int)strlen(message));
else
@@ -16215,20 +16162,6 @@ void clif_parse_BattleChat(int fd, struct map_session_data *sd)
if (clif->process_chat_message(sd, packet, message, sizeof message) == NULL)
return;
- if( atcommand->exec(fd, sd, message, true) )
- return;
-
- if( !pc->can_talk(sd) )
- return;
-
- if( battle_config.min_chat_delay ) {
- if( DIFF_TICK(sd->cantalk_tick, timer->gettick()) > 0 )
- return;
- sd->cantalk_tick = timer->gettick() + battle_config.min_chat_delay;
- }
-
- pc->update_idle_time(sd, BCIDLE_CHAT);
-
bg->send_message(sd, message, (int)strlen(message));
}
diff --git a/src/map/pc.c b/src/map/pc.c
index 2edb09d85..8fe9ddd6e 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -11517,6 +11517,36 @@ int pc_have_magnifier(struct map_session_data *sd)
}
/**
+ * Verifies a chat message, searching for atcommands, checking if the sender
+ * character can chat, and updating the idle timer.
+ *
+ * @param sd The sender character.
+ * @param message The message text.
+ * @return Whether the message is a valid chat message.
+ */
+bool pc_process_chat_message(struct map_session_data *sd, const char *message)
+{
+ if (atcommand->exec(sd->fd, sd, message, true)) {
+ return false;
+ }
+
+ if (!pc->can_talk(sd)) {
+ return false;
+ }
+
+ if (battle_config.min_chat_delay != 0) {
+ if (DIFF_TICK(sd->cantalk_tick, timer->gettick()) > 0) {
+ return false;
+ }
+ sd->cantalk_tick = timer->gettick() + battle_config.min_chat_delay;
+ }
+
+ pc->update_idle_time(sd, BCIDLE_CHAT);
+
+ return true;
+}
+
+/**
* Checks a chat message, scanning for the Super Novice prayer sequence.
*
* If a match is found, the angel is invoked or the counter is incremented as
@@ -11923,6 +11953,7 @@ void pc_defaults(void) {
pc->validate_levels = pc_validate_levels;
pc->check_supernovice_call = pc_check_supernovice_call;
+ pc->process_chat_message = pc_process_chat_message;
/**
* Autotrade persistency [Ind/Hercules <3]
diff --git a/src/map/pc.h b/src/map/pc.h
index 05cb16a60..5d35fd1cc 100644
--- a/src/map/pc.h
+++ b/src/map/pc.h
@@ -1092,6 +1092,7 @@ END_ZEROED_BLOCK; /* End */
int (*have_magnifier) (struct map_session_data *sd);
+ bool (*process_chat_message) (struct map_session_data *sd, const char *message);
void (*check_supernovice_call) (struct map_session_data *sd, const char *message);
};