From: Mario Date: Sun, 4 Dec 2016 02:14:22 +0000 (+1000) Subject: Add mutator hooks to control who chat messages are sent to X-Git-Tag: xonotic-v0.8.2~395 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4a1ec6c7dc03302a9208c3f360e646955aa4d634;p=xonotic%2Fxonotic-data.pk3dir.git Add mutator hooks to control who chat messages are sent to --- diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index b6e8c7f4b..cab67d0c6 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -891,3 +891,18 @@ MUTATOR_HOOKABLE(ForbidWeaponUse, EV_ForbidWeaponUse); /** keepvelocity? */ i(bool, MUTATOR_ARGV_2_bool) \ /**/ MUTATOR_HOOKABLE(CopyBody, EV_CopyBody); + +/** called when sending a chat message, ret argument can be changed to prevent the message */ +#define EV_ChatMessage(i, o) \ + /** sender */ i(entity, MUTATOR_ARGV_0_entity) \ + /** ret */ i(int, MUTATOR_ARGV_1_int) \ + /**/ o(int, MUTATOR_ARGV_1_int) \ + /**/ +MUTATOR_HOOKABLE(ChatMessage, EV_ChatMessage); + +/** return true to prevent sending a chat (private, team or regular) message from reaching a certain player */ +#define EV_ChatMessageTo(i, o) \ + /** destination player */ i(entity, MUTATOR_ARGV_0_entity) \ + /** sender */ i(entity, MUTATOR_ARGV_1_entity) \ + /**/ +MUTATOR_HOOKABLE(ChatMessageTo, EV_ChatMessageTo); diff --git a/qcsrc/server/player.qc b/qcsrc/server/player.qc index 9125b50d7..0ebd0e087 100644 --- a/qcsrc/server/player.qc +++ b/qcsrc/server/player.qc @@ -909,6 +909,9 @@ int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodc ret = 1; } + MUTATOR_CALLHOOK(ChatMessage, source, ret); + ret = M_ARGV(1, int); + if(sourcemsgstr != "" && ret != 0) { if(ret < 0) // faked message, because the player is muted @@ -919,17 +922,20 @@ int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodc } else if(privatesay) // private message, between 2 people only { - sprint(source, sourcemsgstr); - sprint(privatesay, msgstr); - if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled - if(cmsgstr != "") - centerprint(privatesay, cmsgstr); + if(!MUTATOR_CALLHOOK(ChatMessageTo, privatesay, source)) + { + sprint(source, sourcemsgstr); + sprint(privatesay, msgstr); + if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled + if(cmsgstr != "") + centerprint(privatesay, cmsgstr); + } } else if ( teamsay && source.active_minigame ) { sprint(source, sourcemsgstr); dedicated_print(msgstr); // send to server console too - FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source && it.active_minigame == source.active_minigame, sprint(it, msgstr)); + FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source && it.active_minigame == source.active_minigame && !MUTATOR_CALLHOOK(ChatMessageTo, it, source), sprint(it, msgstr)); } else if(teamsay > 0) // team message, only sent to team mates { @@ -937,7 +943,7 @@ int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodc dedicated_print(msgstr); // send to server console too if(sourcecmsgstr != "") centerprint(source, sourcecmsgstr); - FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source && it.team == source.team, { + FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source && it.team == source.team && !MUTATOR_CALLHOOK(ChatMessageTo, it, source), { sprint(it, msgstr); if(cmsgstr != "") centerprint(it, cmsgstr); @@ -947,7 +953,7 @@ int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodc { sprint(source, sourcemsgstr); dedicated_print(msgstr); // send to server console too - FOREACH_CLIENT(!IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source, sprint(it, msgstr)); + FOREACH_CLIENT(!IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source && !MUTATOR_CALLHOOK(ChatMessageTo, it, source), sprint(it, msgstr)); } else { @@ -956,7 +962,7 @@ int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodc dedicated_print(msgstr); // send to server console too MX_Say(strcat(playername(source), "^7: ", msgin)); } - FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source, sprint(it, msgstr)); + FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source && !MUTATOR_CALLHOOK(ChatMessageTo, it, source), sprint(it, msgstr)); } }