From: TimePath Date: Sat, 7 Apr 2018 02:01:00 +0000 (+1000) Subject: Chat: refactor to module, it will be more than just a few commands X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e876aff0eb053c7483e902e8b27f27c44ba92193;p=xonotic%2Fxonotic-data.pk3dir.git Chat: refactor to module, it will be more than just a few commands --- diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 163bbce22..2d8483c83 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -29,7 +29,7 @@ #include #include #include -#include +#include // -------------------------------------------------------------------------- // BEGIN REQUIRED CSQC FUNCTIONS @@ -909,8 +909,6 @@ void CSQC_Parse_StuffCmd(string strMessage) localcmd(strMessage); } -string autocvar__cl_hook_print; - // CSQC_Parse_Print : Provides the print string in the first parameter that the server provided. To execute standard behavior, simply execute print with the string. void CSQC_Parse_Print(string strMessage) { diff --git a/qcsrc/menu/_mod.inc b/qcsrc/menu/_mod.inc index d2a8d702f..fd956463b 100644 --- a/qcsrc/menu/_mod.inc +++ b/qcsrc/menu/_mod.inc @@ -7,5 +7,6 @@ #include #include #include +#include #include #include diff --git a/qcsrc/menu/_mod.qh b/qcsrc/menu/_mod.qh index da8675831..2e36d7285 100644 --- a/qcsrc/menu/_mod.qh +++ b/qcsrc/menu/_mod.qh @@ -7,5 +7,6 @@ #include #include #include +#include #include #include diff --git a/qcsrc/menu/command/_mod.inc b/qcsrc/menu/command/_mod.inc index 9b9dc0bf1..0bcef50de 100644 --- a/qcsrc/menu/command/_mod.inc +++ b/qcsrc/menu/command/_mod.inc @@ -1,3 +1,2 @@ // generated file; do not modify #include -#include diff --git a/qcsrc/menu/command/_mod.qh b/qcsrc/menu/command/_mod.qh index 3633b94d9..91c0a8f35 100644 --- a/qcsrc/menu/command/_mod.qh +++ b/qcsrc/menu/command/_mod.qh @@ -1,3 +1,2 @@ // generated file; do not modify #include -#include diff --git a/qcsrc/menu/command/notice.qc b/qcsrc/menu/command/notice.qc deleted file mode 100644 index 8fee54d4e..000000000 --- a/qcsrc/menu/command/notice.qc +++ /dev/null @@ -1,41 +0,0 @@ -#include "notice.qh" - -#include - -noref string autocvar__cl_hook_print = "menu_cmd notice"; - -int notice_buffer; -int notice_buffer_idx; - -STATIC_INIT(notice_buffer) { - notice_buffer = buf_create(); -} - -GENERIC_COMMAND(notice, "Append a notice to chat") -{ - switch(request) - { - case CMD_REQUEST_COMMAND: - { - string s = console_decode(substring(command, argv_start_index(1), argv_end_index(1) - argv_start_index(1))); - int flags = stoi(argv(2)); - s = ColorTranslateRGB(s); - string prefix = (flags & NOTICE_CHAT) ? "\{3}" : ""; - if (!(flags & NOTICE_SILENT)) { - entity snd = (flags & NOTICE_PRIVATE) ? SND_TALK2 : SND_TALK; - localsound(Sound_fixpath(snd)); - } - bufstr_set(notice_buffer, notice_buffer_idx++, s); - print(prefix, "^7", s, "\n"); - return; - } - - default: - case CMD_REQUEST_USAGE: - { - LOG_INFO("Usage:^3 ", GetProgramCommandPrefix(), " notice message"); - LOG_INFO(" Where 'message' is the message to append."); - return; - } - } -} diff --git a/qcsrc/menu/command/notice.qh b/qcsrc/menu/command/notice.qh deleted file mode 100644 index dd585830a..000000000 --- a/qcsrc/menu/command/notice.qh +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -enum { - NOTICE_CHAT = BIT(0), - NOTICE_SILENT = BIT(1), - NOTICE_PRIVATE = BIT(2), -}; diff --git a/qcsrc/menu/modules/_mod.inc b/qcsrc/menu/modules/_mod.inc new file mode 100644 index 000000000..8b11cef8c --- /dev/null +++ b/qcsrc/menu/modules/_mod.inc @@ -0,0 +1,3 @@ +// generated file; do not modify + +#include diff --git a/qcsrc/menu/modules/_mod.qh b/qcsrc/menu/modules/_mod.qh new file mode 100644 index 000000000..026d48278 --- /dev/null +++ b/qcsrc/menu/modules/_mod.qh @@ -0,0 +1,3 @@ +// generated file; do not modify + +#include diff --git a/qcsrc/menu/modules/chat/_mod.inc b/qcsrc/menu/modules/chat/_mod.inc new file mode 100644 index 000000000..b8c8810be --- /dev/null +++ b/qcsrc/menu/modules/chat/_mod.inc @@ -0,0 +1,2 @@ +// generated file; do not modify +#include diff --git a/qcsrc/menu/modules/chat/_mod.qh b/qcsrc/menu/modules/chat/_mod.qh new file mode 100644 index 000000000..8eaea0a7a --- /dev/null +++ b/qcsrc/menu/modules/chat/_mod.qh @@ -0,0 +1,2 @@ +// generated file; do not modify +#include diff --git a/qcsrc/menu/modules/chat/commands.qc b/qcsrc/menu/modules/chat/commands.qc new file mode 100644 index 000000000..668ff651d --- /dev/null +++ b/qcsrc/menu/modules/chat/commands.qc @@ -0,0 +1,41 @@ +#include "commands.qh" + +#include + +noref string autocvar__cl_hook_print = "menu_cmd notice"; + +int notice_buffer; +int notice_buffer_idx; + +STATIC_INIT(notice_buffer) { + notice_buffer = buf_create(); +} + +GENERIC_COMMAND(notice, "Append a notice to chat") +{ + switch(request) + { + case CMD_REQUEST_COMMAND: + { + string s = console_decode(substring(command, argv_start_index(1), argv_end_index(1) - argv_start_index(1))); + int flags = stoi(argv(2)); + s = ColorTranslateRGB(s); + string prefix = (flags & NOTICE_CHAT) ? "\{3}" : ""; + if (!(flags & NOTICE_SILENT)) { + entity snd = (flags & NOTICE_PRIVATE) ? SND_TALK2 : SND_TALK; + localsound(Sound_fixpath(snd)); + } + bufstr_set(notice_buffer, notice_buffer_idx++, s); + print(prefix, "^7", s, "\n"); + return; + } + + default: + case CMD_REQUEST_USAGE: + { + LOG_INFO("Usage:^3 ", GetProgramCommandPrefix(), " notice message"); + LOG_INFO(" Where 'message' is the message to append."); + return; + } + } +} diff --git a/qcsrc/menu/modules/chat/commands.qh b/qcsrc/menu/modules/chat/commands.qh new file mode 100644 index 000000000..dd585830a --- /dev/null +++ b/qcsrc/menu/modules/chat/commands.qh @@ -0,0 +1,7 @@ +#pragma once + +enum { + NOTICE_CHAT = BIT(0), + NOTICE_SILENT = BIT(1), + NOTICE_PRIVATE = BIT(2), +}; diff --git a/qcsrc/menu/modules/chat/interface.qh b/qcsrc/menu/modules/chat/interface.qh new file mode 100644 index 000000000..1760a2ef3 --- /dev/null +++ b/qcsrc/menu/modules/chat/interface.qh @@ -0,0 +1,5 @@ +#pragma once + +#include "commands.qh" + +string autocvar__cl_hook_print;