Skip to content

Commit

Permalink
Chat - Add component (#219)
Browse files Browse the repository at this point in the history
* Add chat component

* Implement chat restriction setting

* Common - Add network synced admin state gvar

* Add isAdmin handlers only on clients

* Fix translation

* Fix admin/zeus prefix not added on remote clients

* Update addons/chat/stringtable.xml

Co-authored-by: 3Mydlo3 <mydlo333@interia.pl>

* Update addons/chat/stringtable.xml

Co-authored-by: 3Mydlo3 <mydlo333@interia.pl>

* Move chat channels ids to defines

---------

Co-authored-by: 3Mydlo3 <mydlo333@interia.pl>
  • Loading branch information
veteran29 and 3Mydlo3 authored Aug 14, 2024
1 parent 293e784 commit f04d7c1
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 1 deletion.
1 change: 1 addition & 0 deletions addons/chat/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z\afm\addons\chat
15 changes: 15 additions & 0 deletions addons/chat/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -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));
};
};
11 changes: 11 additions & 0 deletions addons/chat/README.md
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions addons/chat/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PREP(handleChatMessage);
7 changes: 7 additions & 0 deletions addons/chat/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "script_component.hpp"

if (hasInterface) then {
addMissionEventHandler ["HandleChatMessage", {
call FUNC(handleChatMessage);
}];
};
10 changes: 10 additions & 0 deletions addons/chat/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions addons/chat/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "script_component.hpp"
#include "XEH_PREP.hpp"
18 changes: 18 additions & 0 deletions addons/chat/config.cpp
Original file line number Diff line number Diff line change
@@ -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"
43 changes: 43 additions & 0 deletions addons/chat/functions/fnc_handleChatMessage.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "script_component.hpp"
/*
* Author: veteran29
* Handle chat message.
*
* Arguments:
* 0: Channel <NUMBER>
* 1: N/A
* 2: N/A
* 3: Sent text <STRING>
* 4: Person sending the message <OBJECT>
*
* Return Value:
* Should message be blocked <BOOL>
*
* 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
1 change: 1 addition & 0 deletions addons/chat/functions/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "..\script_component.hpp"
9 changes: 9 additions & 0 deletions addons/chat/initSettings.inc.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

[
QGVAR(allowGlobalChat),
"CHECKBOX",
[LSTRING(AllowGlobalChat), LSTRING(AllowGlobalChat_Description)],
LSTRING(DisplayName),
true,
1
] call CBA_fnc_addSetting;
18 changes: 18 additions & 0 deletions addons/chat/script_component.hpp
Original file line number Diff line number Diff line change
@@ -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]
21 changes: 21 additions & 0 deletions addons/chat/stringtable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project name="AFM">
<Package name="Chat">
<Key ID="STR_AFM_Chat_DisplayName">
<English>ArmaForces - Chat</English>
<Polish>ArmaForces - Czat</Polish>
</Key>
<Key ID="STR_AFM_Chat_AllowGlobalChat">
<English>Allow global/side chat</English>
<Polish>Zezwól na czat globalny/strony</Polish>
</Key>
<Key ID="STR_AFM_Chat_AllowGlobalChat_Description">
<English>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.</English>
<Polish>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.</Polish>
</Key>
<Key ID="STR_AFM_Chat_AllowGlobalChat_Warning">
<English>Global and side chat is disabled, your message is visible only to administrators and zeuses!</English>
<Polish>Czat globalny i strony jest wyłączony, twoja wiadomość jest widoczna tylko dla administratorów i zeusów!</Polish>
</Key>
</Package>
</Project>
28 changes: 27 additions & 1 deletion addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
#include "script_component.hpp"
#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;
};

0 comments on commit f04d7c1

Please sign in to comment.