From 9a2bce66fdf6a737b58c7167cc6e7118b0277cfc Mon Sep 17 00:00:00 2001 From: Arkshine Date: Fri, 2 May 2014 19:13:15 +0200 Subject: [PATCH 1/6] Add client_printex stock --- plugins/include/message_stocks.inc | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/plugins/include/message_stocks.inc b/plugins/include/message_stocks.inc index 41fafaf1..226b2791 100644 --- a/plugins/include/message_stocks.inc +++ b/plugins/include/message_stocks.inc @@ -56,3 +56,53 @@ stock make_deathmsg(killer, victim, headshot, const weapon[]) return 1; } + +/** + * Sends a custom or predefined text message to player. + * Predefined texts are default game messages which will be translated + * to player's game language. + * + * @note Set index to 0 to send text globally. + * + * @note There does not necessarily have to be a total of 6 arguments. + * It will depend if message takes arguments, e.g.: + * Predefined message: client_printex(id, print_chat, "#Game_join_ct", "Pimp Daddy") + * Custom message : client_printex(id, print_chat, "%s is joining the Counter-Terrorist force", "Pimp Daddy") + * + * @param index Index of the player, use 0 to send to all players. + * @param type The message destination. See print_* constants. + * @param msg_name The custom or predefined message to send. + * @param msg_param1 Optionnal message argument. + * @param msg_param2 Optionnal message argument. + * @param msg_param3 Optionnal message argument. + * @param msg_param4 Optionnal message argument. + * + * @noreturn + */ +client_printex(index, type, const msg_name[], const msg_param1[] = "", const msg_param2[] = "", const msg_param3[] = "", const msg_param4[] = "") +{ + static msgTextMsg; + + if (!msgTextMsg) + { + msgTextMsg = get_user_msgid("TextMsg"); + } + + message_begin(index > 0 ? MSG_ONE : MSG_ALL, msgTextMsg, .player = index); + write_byte(type); + write_string(msg_name); + + if (msg_param1[0]) + write_string(msg_param1); + + if (msg_param2[0]) + write_string(msg_param2); + + if (msg_param3[0]) + write_string(msg_param3); + + if (msg_param4[0]) + write_string(msg_param4); + + message_end(); +} From 3b0ce189ea58d818d7600ff11108417634048791 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Fri, 2 May 2014 19:13:38 +0200 Subject: [PATCH 2/6] Add print_radio constant (counter-strike only) --- plugins/include/amxconst.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/include/amxconst.inc b/plugins/include/amxconst.inc index 8684397f..eac08b16 100755 --- a/plugins/include/amxconst.inc +++ b/plugins/include/amxconst.inc @@ -180,6 +180,7 @@ enum { print_console, print_chat, print_center, + print_radio /* Counter-Strike only */ }; /* Color types for client_print_color() */ From d0b335dc6e34f6784e32c94a25f5b9b0c5df9176 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Sun, 4 May 2014 18:32:15 +0200 Subject: [PATCH 3/6] Add missing 'stock' keyword. --- plugins/include/message_stocks.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/include/message_stocks.inc b/plugins/include/message_stocks.inc index 226b2791..26892208 100644 --- a/plugins/include/message_stocks.inc +++ b/plugins/include/message_stocks.inc @@ -60,7 +60,7 @@ stock make_deathmsg(killer, victim, headshot, const weapon[]) /** * Sends a custom or predefined text message to player. * Predefined texts are default game messages which will be translated - * to player's game language. + * to player's game language, e.g. #Game_join_ct. * * @note Set index to 0 to send text globally. * @@ -79,7 +79,7 @@ stock make_deathmsg(killer, victim, headshot, const weapon[]) * * @noreturn */ -client_printex(index, type, const msg_name[], const msg_param1[] = "", const msg_param2[] = "", const msg_param3[] = "", const msg_param4[] = "") +stock client_printex(index, type, const msg_name[], const msg_param1[] = "", const msg_param2[] = "", const msg_param3[] = "", const msg_param4[] = "") { static msgTextMsg; From f691d2ed795dea86e0325518bd5736c5c8444dbc Mon Sep 17 00:00:00 2001 From: Arkshine Date: Mon, 5 May 2014 00:59:36 +0200 Subject: [PATCH 4/6] Fix english --- plugins/include/message_stocks.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/include/message_stocks.inc b/plugins/include/message_stocks.inc index 26892208..d9f0258e 100644 --- a/plugins/include/message_stocks.inc +++ b/plugins/include/message_stocks.inc @@ -72,10 +72,10 @@ stock make_deathmsg(killer, victim, headshot, const weapon[]) * @param index Index of the player, use 0 to send to all players. * @param type The message destination. See print_* constants. * @param msg_name The custom or predefined message to send. - * @param msg_param1 Optionnal message argument. - * @param msg_param2 Optionnal message argument. - * @param msg_param3 Optionnal message argument. - * @param msg_param4 Optionnal message argument. + * @param msg_param1 Optional message argument. + * @param msg_param2 Optional message argument. + * @param msg_param3 Optional message argument. + * @param msg_param4 Optional message argument. * * @noreturn */ From f5921a353571d26c5520475c259771a1b8307151 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Mon, 5 May 2014 20:42:51 +0200 Subject: [PATCH 5/6] Refactor code It would seem I was wrong (was I drunk?). It doesn't support custom message using formating (%s). This simplifies things, as this stock is now meant to be used only on predefined message. * If not a predefined message, we redirect to client_print, as there is more checks and can deal with ML. * If length goes above known limits, we redirect to client_print to be cut properly. * Changed MSG_ONE to MSG_UNRELIABLE and MSG_ALL to MSG_BROADCAST. * Updated documention. --- plugins/include/message_stocks.inc | 50 ++++++++++++++++++------------ 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/plugins/include/message_stocks.inc b/plugins/include/message_stocks.inc index d9f0258e..7552648a 100644 --- a/plugins/include/message_stocks.inc +++ b/plugins/include/message_stocks.inc @@ -58,7 +58,7 @@ stock make_deathmsg(killer, victim, headshot, const weapon[]) } /** - * Sends a custom or predefined text message to player. + * Sends a predefined text message to player. * Predefined texts are default game messages which will be translated * to player's game language, e.g. #Game_join_ct. * @@ -66,8 +66,8 @@ stock make_deathmsg(killer, victim, headshot, const weapon[]) * * @note There does not necessarily have to be a total of 6 arguments. * It will depend if message takes arguments, e.g.: - * Predefined message: client_printex(id, print_chat, "#Game_join_ct", "Pimp Daddy") - * Custom message : client_printex(id, print_chat, "%s is joining the Counter-Terrorist force", "Pimp Daddy") + * client_printex(id, print_chat, "#Game_join_ct", "Pimp Daddy") + * client_printex(id, print_chat, "1", "#Game_radio", "Pimp Daddy", "Hello world!") * * @param index Index of the player, use 0 to send to all players. * @param type The message destination. See print_* constants. @@ -81,28 +81,38 @@ stock make_deathmsg(killer, victim, headshot, const weapon[]) */ stock client_printex(index, type, const msg_name[], const msg_param1[] = "", const msg_param2[] = "", const msg_param3[] = "", const msg_param4[] = "") { - static msgTextMsg; + new ch = msg_name[0]; - if (!msgTextMsg) + // If not a predefined message, we don't care about it and forward directly to client_print. + // Special case for radio message. msg_name is an index, msg_param1 #Game_radio*, etc. Checking index should be enough. + if (ch != '#' && (type != print_radio || !strtol(msg_name))) { - msgTextMsg = get_user_msgid("TextMsg"); + return client_print(index, type, msg_name, msg_param1, msg_param2, msg_param3, msg_param4); } - message_begin(index > 0 ? MSG_ONE : MSG_ALL, msgTextMsg, .player = index); + // Even if message starts with '#', we should check its length for safety. + new length = strlen(msg_name); + + // If string is larger than expected, we forward to client_print which will cut message properly. + // This means also this can't be a predefined game message. + // Max console length: 128 = \n (126) + \0 (127) + // Max SayText length: 192 = \n (190) + \0 (191) + if ((length > 126 && (print_notify <= type <= print_console)) + || ( length > 190 && (print_chat <= type <= print_radio))) + { + return client_print(index, type, msg_name, msg_param1, msg_param2, msg_param3, msg_param4); + } + + static msgTextMsg; msgTextMsg || (msgTextMsg = get_user_msgid("TextMsg")); + + message_begin(index > 0 ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, msgTextMsg, .player = index); write_byte(type); write_string(msg_name); - - if (msg_param1[0]) - write_string(msg_param1); - - if (msg_param2[0]) - write_string(msg_param2); - - if (msg_param3[0]) - write_string(msg_param3); - - if (msg_param4[0]) - write_string(msg_param4); - + if (msg_param1[0]) { write_string(msg_param1); } + if (msg_param2[0]) { write_string(msg_param2); } + if (msg_param3[0]) { write_string(msg_param3); } + if (msg_param4[0]) { write_string(msg_param4); } message_end(); + + return 1; } From 1c13d0dd6bb21ad40fecea1deb0c725091dc0dd6 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Tue, 13 May 2014 14:09:45 +0200 Subject: [PATCH 6/6] Use a more standard if conditionnal way. --- plugins/include/message_stocks.inc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/include/message_stocks.inc b/plugins/include/message_stocks.inc index 7552648a..6c39e33f 100644 --- a/plugins/include/message_stocks.inc +++ b/plugins/include/message_stocks.inc @@ -103,7 +103,11 @@ stock client_printex(index, type, const msg_name[], const msg_param1[] = "", con return client_print(index, type, msg_name, msg_param1, msg_param2, msg_param3, msg_param4); } - static msgTextMsg; msgTextMsg || (msgTextMsg = get_user_msgid("TextMsg")); + static msgTextMsg; + if (!msgTextMsg) + { + msgTextMsg = get_user_msgid("TextMsg"); + } message_begin(index > 0 ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, msgTextMsg, .player = index); write_byte(type);