Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat - Add component #219

Merged
merged 9 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 [0, 1])}) exitWith {false};
veteran29 marked this conversation as resolved.
Show resolved Hide resolved

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;
14 changes: 14 additions & 0 deletions addons/chat/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#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"
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 chat globalny/strony</Polish>
veteran29 marked this conversation as resolved.
Show resolved Hide resolved
</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łaczony, twoja wiadomość jest widoczna tylko dla administratorów i zeusów!</Polish>
veteran29 marked this conversation as resolved.
Show resolved Hide resolved
</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;
};
Loading