diff --git a/addons/chat/$PBOPREFIX$ b/addons/chat/$PBOPREFIX$ new file mode 100644 index 0000000..7b62a9b --- /dev/null +++ b/addons/chat/$PBOPREFIX$ @@ -0,0 +1 @@ +z\afm\addons\chat diff --git a/addons/chat/CfgEventHandlers.hpp b/addons/chat/CfgEventHandlers.hpp new file mode 100644 index 0000000..2a3f71f --- /dev/null +++ b/addons/chat/CfgEventHandlers.hpp @@ -0,0 +1,15 @@ +class Extended_PreStart_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_SCRIPT(XEH_preStart)); + }; +}; +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_SCRIPT(XEH_preInit)); + }; +}; +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_SCRIPT(XEH_postInit)); + }; +}; diff --git a/addons/chat/README.md b/addons/chat/README.md new file mode 100644 index 0000000..2fc42c1 --- /dev/null +++ b/addons/chat/README.md @@ -0,0 +1,11 @@ +## Chat + +Game chat related features. + +### Chat lock + +This components adds an option to block global (system and side) chats, making them visible only to sender and logged in admins and zeuses. + +## Authors + +- [veteran29](https://github.com/veteran29) diff --git a/addons/chat/XEH_PREP.hpp b/addons/chat/XEH_PREP.hpp new file mode 100644 index 0000000..7ce8fcb --- /dev/null +++ b/addons/chat/XEH_PREP.hpp @@ -0,0 +1 @@ +PREP(handleChatMessage); diff --git a/addons/chat/XEH_postInit.sqf b/addons/chat/XEH_postInit.sqf new file mode 100644 index 0000000..f5ea42c --- /dev/null +++ b/addons/chat/XEH_postInit.sqf @@ -0,0 +1,7 @@ +#include "script_component.hpp" + +if (hasInterface) then { + addMissionEventHandler ["HandleChatMessage", { + call FUNC(handleChatMessage); + }]; +}; diff --git a/addons/chat/XEH_preInit.sqf b/addons/chat/XEH_preInit.sqf new file mode 100644 index 0000000..6706cf8 --- /dev/null +++ b/addons/chat/XEH_preInit.sqf @@ -0,0 +1,10 @@ +#include "script_component.hpp" +ADDON = false; + +PREP_RECOMPILE_START; +#include "XEH_PREP.hpp" +PREP_RECOMPILE_END; + +#include "initSettings.inc.sqf" + +ADDON = true; diff --git a/addons/chat/XEH_preStart.sqf b/addons/chat/XEH_preStart.sqf new file mode 100644 index 0000000..a51262a --- /dev/null +++ b/addons/chat/XEH_preStart.sqf @@ -0,0 +1,2 @@ +#include "script_component.hpp" +#include "XEH_PREP.hpp" diff --git a/addons/chat/config.cpp b/addons/chat/config.cpp new file mode 100644 index 0000000..e8dc203 --- /dev/null +++ b/addons/chat/config.cpp @@ -0,0 +1,18 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + name = COMPONENT_NAME; + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = { + "afm_common" + }; + author = "ArmaForces"; + authors[] = {"veteran29"}; + VERSION_CONFIG; + }; +}; + +#include "CfgEventHandlers.hpp" diff --git a/addons/chat/functions/fnc_handleChatMessage.sqf b/addons/chat/functions/fnc_handleChatMessage.sqf new file mode 100644 index 0000000..ea28959 --- /dev/null +++ b/addons/chat/functions/fnc_handleChatMessage.sqf @@ -0,0 +1,43 @@ +#include "script_component.hpp" +/* + * Author: veteran29 + * Handle chat message. + * + * Arguments: + * 0: Channel + * 1: N/A + * 2: N/A + * 3: Sent text + * 4: Person sending the message + * + * Return Value: + * Should message be blocked + * + * Example: + * call afm_chat_fnc_handleChatMessage + * + * Public: No + */ + +params [["_channel", -1], "", ["_from", ""], ["_text", ""], ["_sender", objNull]]; +if (_text == "") exitWith {false}; + +if (GVAR(allowGlobalChat) || {!(_channel in RESTRICTED_CHANNELS)}) exitWith {false}; + +if (_sender getVariable [QEGVAR(common,isAdmin), false]) exitWith { + [format ["(ADMIN) %1", _from], _text] +}; + +if (!isNull getAssignedCuratorLogic _sender) exitWith { + [format ["(ZEUS) %1", _from], _text] +}; + +if (_sender isEqualTo player) exitWith { + systemChat LLSTRING(AllowGlobalChat_Warning); + playSound "3DEN_notificationWarning"; + + false // return, player always sees his own message +}; + +isNull getAssignedCuratorLogic player // show all messages to zeus +&& !(player getVariable [QEGVAR(common,isAdmin), false]) // show all messages to admin diff --git a/addons/chat/functions/script_component.hpp b/addons/chat/functions/script_component.hpp new file mode 100644 index 0000000..fcf9da9 --- /dev/null +++ b/addons/chat/functions/script_component.hpp @@ -0,0 +1 @@ +#include "..\script_component.hpp" diff --git a/addons/chat/initSettings.inc.sqf b/addons/chat/initSettings.inc.sqf new file mode 100644 index 0000000..54cea14 --- /dev/null +++ b/addons/chat/initSettings.inc.sqf @@ -0,0 +1,9 @@ + +[ + QGVAR(allowGlobalChat), + "CHECKBOX", + [LSTRING(AllowGlobalChat), LSTRING(AllowGlobalChat_Description)], + LSTRING(DisplayName), + true, + 1 +] call CBA_fnc_addSetting; diff --git a/addons/chat/script_component.hpp b/addons/chat/script_component.hpp new file mode 100644 index 0000000..0e57729 --- /dev/null +++ b/addons/chat/script_component.hpp @@ -0,0 +1,18 @@ +#define COMPONENT chat +#include "\z\afm\addons\main\script_mod.hpp" + +// #define DEBUG_MODE_FULL +// #define DISABLE_COMPILE_CACHE + +#ifdef DEBUG_ENABLED_CHAT + #define DEBUG_MODE_FULL +#endif + #ifdef DEBUG_SETTINGS_CHAT + #define DEBUG_SETTINGS DEBUG_SETTINGS_CHAT +#endif + +#include "\z\afm\addons\main\script_macros.hpp" + +#define CHAT_CHANNEL_GLOBAL 0 +#define CHAT_CHANNEL_SIDE 1 +#define RESTRICTED_CHANNELS [CHAT_CHANNEL_GLOBAL, CHAT_CHANNEL_SIDE] diff --git a/addons/chat/stringtable.xml b/addons/chat/stringtable.xml new file mode 100644 index 0000000..a4b81ab --- /dev/null +++ b/addons/chat/stringtable.xml @@ -0,0 +1,21 @@ + + + + + ArmaForces - Chat + ArmaForces - Czat + + + Allow global/side chat + Zezwól na czat globalny/strony + + + Should players be allowed to chat on global and their side chat. If disabled chat messages from these channels will only be visible to admins and zeus players. + Czy gracze mają mieć możliwość pisania na czacie globalnym i czacie swojej strony. Jeżeli wyłączone to wiadomości z tych kanałów będą widoczne tylko dla administratorów i zeusów. + + + Global and side chat is disabled, your message is visible only to administrators and zeuses! + Czat globalny i strony jest wyłączony, twoja wiadomość jest widoczna tylko dla administratorów i zeusów! + + + diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 84f2529..0a95bfe 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -1 +1,27 @@ -#include "script_component.hpp" \ No newline at end of file +#include "script_component.hpp" + +if (hasInterface) then { + ["login", { + [{IS_ADMIN}, { + player setVariable [QGVAR(isAdmin), true, true]; + }, nil, 5] call CBA_fnc_waitUntilAndExecute; + }, "all"] call CBA_fnc_registerChatCommand; + + ["logout", { + if (player getVariable [QGVAR(isAdmin), false]) then { + player setVariable [QGVAR(isAdmin), false, true]; + }; + }, "all"] call CBA_fnc_registerChatCommand; + + ["unit", { + params ["_newPlayer", "_oldPlayer"]; + + if (IS_ADMIN) then { + _newPlayer setVariable [QGVAR(isAdmin), true, true]; + }; + + if (_oldPlayer getVariable [QGVAR(isAdmin), false]) then { + _oldPlayer setVariable [QGVAR(isAdmin), false, true]; + }; + }, true] call CBA_fnc_addPlayerEventHandler; +};