Skip to content

Commit dab96be

Browse files
authored
CA Addon: Request UnGAG (/sorry) (#233)
* ca_remove_user_gag(): Add admin arg * add Ungag plugin * Add lang * refactoring * Add description * refactoring №2 * fix: native ca_remove_user_gag() admin param usage * fix: message receiver for `/sorry` cmd * cmd rename: `/unmute` -> `/ungag` * Rework `RequestUngag.sma` * Use `CA_Client_Say*()` & add `CmdRouter()` * Add `say /ungag #` cmd handling * Add config * remove extra CVar `ca_requestungag_admin_flag` * increase default timeout * lil fixes * Ignore /sorry sender for chat info * change default timings * fix checks priority * add //todo
1 parent 7bfcc51 commit dab96be

File tree

6 files changed

+190
-34
lines changed

6 files changed

+190
-34
lines changed

cstrike/addons/amxmodx/configs/plugins-ChatAdditions.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ CA_Storage_SQLite.amxx debug ; SQLite storage provider
1010
; Extensions
1111
CA_Mute.amxx debug ; Players can choose who they can hear.
1212
CA_Addon_DeathMute.amxx debug ; Alive players don't hear dead players after 5 secs
13-
CA_Addon_RankRestrictions.amxx debug ; Restrict chat until you reach the rank of a statistic
13+
CA_Addon_RankRestrictions.amxx debug ; Restrict chat until you reach the rank of a statistic.
1414
CA_Addon_VoteGag.amxx debug ; Ability for players to vote for gag.
15-
CA_Gag.amxx debug ; Manage player chats for the admin
15+
CA_Addon_RequestUnGag.amxx debug ; A player can apologize to the administration.
16+
CA_Gag.amxx debug ; Manage player chats for the admin.
1617

1718
; IMPORTANT: Place you chat manager below (Chat RBS plugins, Lite Translit, Colored Translit etc..)
1819
; Most chat managers are not written using the correct chat handling,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This file was auto-generated by AMX Mod X (v1.9.0.5271)
2+
// Cvars for plugin "CA Addon: Request UnGAG" by "steelzzz" (CA_Addon_Request_UnGag.amxx, v6ce18b0)
3+
4+
5+
// Request ungag command
6+
// -
7+
// Default: "/sorry"
8+
ca_requestungag_cmd "/sorry"
9+
10+
// delay time request ungag
11+
// -
12+
// Default: "40.0"
13+
// Minimum: "1.000000"
14+
ca_requestungag_delay "40.0"
15+
16+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[ru]
2+
RequestUnGag_NoAccess = ^4* ^1У вас не заблокирован чат.
3+
RequestUnGag_TimeOut = ^4* ^1Попробуйте через %i сек.
4+
RequestUnGag_Requested = ^4* ^1Игрок ^4%n ^1просит снять гаг. Чтобы снять гаг, напишите: ^4/ungag %d^1
5+
RequestUnGag_YouRequested = ^4* ^1Вы попросили снять гаг.
6+
7+
[en]
8+
RequestUnGag_NoAccess = ^4* ^1You don't have a chat block.
9+
RequestUnGag_TimeOut = ^4* ^1Try it in %i seconds.
10+
RequestUnGag_Requested = ^4* ^1The player ^4%n ^1asks to remove the gag. To remove it write: ^4/ungag %i^1
11+
RequestUnGag_YouRequested = ^4* ^1You asked to take off the gag.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#include <amxmodx>
2+
#include <amxmisc>
3+
4+
#include <ChatAdditions>
5+
#include <CA_GAG_API>
6+
7+
#pragma ctrlchar '\'
8+
#pragma tabsize 2
9+
10+
static Float: g_userNextRequestTime[MAX_PLAYERS + 1]
11+
12+
static ca_requestungag_cmd[32],
13+
Float: ca_requestungag_delay
14+
15+
static ca_gag_access_flags_high[32], ca_gag_access_flags[32]
16+
17+
public stock const PluginName[] = "CA Addon: Request UnGAG"
18+
public stock const PluginVersion[] = CA_VERSION
19+
public stock const PluginAuthor[] = "steelzzz"
20+
public stock const PluginURL[] = "github.com/ChatAdditions/ChatsAdditions_AMXX"
21+
public stock const PluginDescription[] = "A player can apologize to the administration"
22+
23+
public plugin_init() {
24+
register_plugin(PluginName, PluginVersion, PluginAuthor)
25+
register_dictionary("CA_Addon_RequestUngag.txt")
26+
27+
Register_CVars()
28+
AutoExecConfig(true, "CA_Addon_RequestUnGag", "ChatAdditions")
29+
}
30+
31+
public Register_CVars() {
32+
bind_pcvar_string(create_cvar("ca_requestungag_cmd", "/sorry",
33+
.description = "Request ungag command"),
34+
ca_requestungag_cmd, charsmax(ca_requestungag_cmd)
35+
)
36+
37+
bind_pcvar_float(create_cvar("ca_requestungag_delay", "40.0",
38+
.description = "delay time request ungag",
39+
.has_min = true, .min_val = 1.0),
40+
ca_requestungag_delay
41+
)
42+
43+
bind_pcvar_string(get_cvar_pointer("ca_gag_access_flags_high"),
44+
ca_gag_access_flags_high, charsmax(ca_gag_access_flags_high)
45+
)
46+
47+
bind_pcvar_string(get_cvar_pointer("ca_gag_access_flags"),
48+
ca_gag_access_flags, charsmax(ca_gag_access_flags)
49+
)
50+
}
51+
52+
// TODO: Create `_PRE` hook forward instead this.
53+
public CA_Client_Say(player, const message[]) {
54+
if(strcmp(message, ca_requestungag_cmd) != 0)
55+
return PLUGIN_CONTINUE
56+
57+
if(!ca_has_user_gag(player)) {
58+
client_print_color(player, print_team_default, "%L", player, "RequestUnGag_NoAccess")
59+
60+
return PLUGIN_HANDLED
61+
}
62+
63+
new Float: gametime = get_gametime()
64+
if(g_userNextRequestTime[player] > gametime) {
65+
new timeLeft = floatround(g_userNextRequestTime[player] - gametime, floatround_ceil)
66+
client_print_color(player, print_team_default, "%L", player, "RequestUnGag_TimeOut", timeLeft)
67+
68+
return PLUGIN_HANDLED
69+
}
70+
71+
new userID = get_user_userid(player)
72+
73+
new players[MAX_PLAYERS], count
74+
get_players_ex(players, count, (GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV))
75+
76+
new accessFlagsHigh = read_flags(ca_gag_access_flags_high)
77+
new accessFlags = read_flags(ca_gag_access_flags)
78+
79+
for(new i; i < count; i++) {
80+
new receiver = players[i]
81+
82+
if(receiver == player)
83+
continue
84+
85+
if(!(get_user_flags(receiver) & (accessFlags | accessFlagsHigh)))
86+
continue
87+
88+
client_print_color(receiver, print_team_default, "%L",
89+
receiver, "RequestUnGag_Requested",
90+
player, userID
91+
)
92+
}
93+
94+
g_userNextRequestTime[player] = gametime + ca_requestungag_delay
95+
96+
client_print_color(player, print_team_default, "%L", player, "RequestUnGag_YouRequested")
97+
return PLUGIN_HANDLED
98+
}

cstrike/addons/amxmodx/scripting/CA_Gag.sma

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ new const g_adminChatCmds[][] = {
5353
"amx_tsay2"
5454
}
5555

56+
new const g_gagCmd[] = "gag"
57+
new const g_unGagCmd[] = "ungag"
58+
5659
public stock const PluginName[] = "CA: Gag"
5760
public stock const PluginVersion[] = CA_VERSION
5861
public stock const PluginAuthor[] = "Sergey Shorokhov"
@@ -106,7 +109,6 @@ public plugin_init() {
106109
}
107110

108111
register_clcmd("amx_gagmenu", "ClCmd_Gag", (accessFlags | accessFlagsHigh), .FlagManager = false)
109-
register_clcmd("say", "ClCmd_Say", (accessFlags | accessFlagsHigh), .FlagManager = false)
110112

111113
for(new i; i < sizeof g_adminChatCmds; i++)
112114
register_clcmd(g_adminChatCmds[i], "ClCmd_adminSay", ADMIN_CHAT);
@@ -1062,28 +1064,6 @@ public ClCmd_Gag(const id, const level, const cid) {
10621064
return PLUGIN_HANDLED
10631065
}
10641066

1065-
public ClCmd_Say(const id, const level, const cid) {
1066-
new args[128]; read_args(args, charsmax(args))
1067-
trim(args); remove_quotes(args)
1068-
1069-
new const strFind[] = "gag"
1070-
1071-
if(strncmp(args[1], strFind, charsmax(strFind)) != 0) {
1072-
return PLUGIN_CONTINUE
1073-
}
1074-
1075-
if(!cmd_access(id, level, cid, 1)) {
1076-
return PLUGIN_CONTINUE
1077-
}
1078-
1079-
new nickname[32]
1080-
copy(nickname, charsmax(nickname), args[5])
1081-
1082-
MenuShow_PlayersList(id, nickname)
1083-
1084-
return PLUGIN_HANDLED
1085-
}
1086-
10871067
public ClCmd_EnterGagReason(const id, const level, const cid) {
10881068
if(!cmd_access(id, level, cid, 1)) {
10891069
return PLUGIN_HANDLED
@@ -1315,7 +1295,10 @@ public CA_Client_Voice(const listener, const sender) {
13151295
return CA_SUPERCEDE
13161296
}
13171297

1318-
public CA_Client_SayTeam(id) {
1298+
public CA_Client_SayTeam(id, const message[]) {
1299+
if(CmdRouter(id, message))
1300+
return PLUGIN_CONTINUE
1301+
13191302
new bool: hasBlock = (g_currentGags[id][gd_reason][r_flags] & gagFlag_SayTeam)
13201303

13211304
if(!hasBlock) {
@@ -1328,7 +1311,10 @@ public CA_Client_SayTeam(id) {
13281311
return CA_SUPERCEDE
13291312
}
13301313

1331-
public CA_Client_Say(id) {
1314+
public CA_Client_Say(id, const message[]) {
1315+
if(CmdRouter(id, message))
1316+
return PLUGIN_CONTINUE
1317+
13321318
new bool: hasBlock = (g_currentGags[id][gd_reason][r_flags] & gagFlag_Say)
13331319

13341320
if(!hasBlock) {
@@ -1659,6 +1645,48 @@ static Gag_Expired(const id) {
16591645
client_print_color(0, print_team_default, "%L %L", LANG_PLAYER, "Gag_prefix", LANG_PLAYER, "Gag_PlayerExpiredGag", id)
16601646
}
16611647

1648+
static bool: CmdRouter(const player, const message[]) {
1649+
if(!(get_user_flags(player) & (read_flags(ca_gag_access_flags) | read_flags(ca_gag_access_flags_high))))
1650+
return false
1651+
1652+
new cmd[32], token[32]
1653+
strtok2(message[1], cmd, charsmax(cmd), token, charsmax(token), .trim = true)
1654+
1655+
if(strncmp(cmd, g_gagCmd, charsmax(g_gagCmd), true) == 0) {
1656+
MenuShow_PlayersList(player, token)
1657+
return true
1658+
}
1659+
1660+
if(strncmp(cmd, g_unGagCmd, charsmax(g_unGagCmd), true) == 0) {
1661+
new targetUserID = strtol(token)
1662+
if(targetUserID == 0)
1663+
return false
1664+
1665+
UnGag_ByUserID(player, targetUserID)
1666+
return true
1667+
}
1668+
1669+
return false
1670+
}
1671+
1672+
static UnGag_ByUserID(const admin, const targetUserID) {
1673+
new target = find_player_ex(FindPlayer_MatchUserId | FindPlayer_ExcludeBots, targetUserID)
1674+
if(!is_user_connected(target)) {
1675+
client_print_color(admin, print_team_red, "%L %L", admin, "Gag_prefix", admin, "Gag_PlayerNotConnected")
1676+
return
1677+
}
1678+
1679+
new bool: hasBlock = g_currentGags[target][gd_reason][r_flags] != gagFlag_Removed
1680+
if(!hasBlock) {
1681+
client_print_color(admin, print_team_red, "%L %L", admin, "Gag_prefix", admin, "Gag_PlayerExpiredGag", target)
1682+
return
1683+
}
1684+
1685+
GagData_Copy(g_adminTempData[admin], g_currentGags[target])
1686+
g_adminTempData[admin][gd_target] = target
1687+
1688+
Gag_Remove(admin, target)
1689+
}
16621690

16631691
Register_Forwards() {
16641692
g_fwd_gag_setted = CreateMultiForward("CA_gag_setted", ET_STOP,
@@ -1722,17 +1750,18 @@ public bool: native_ca_has_user_gag(const plugin_id, const argc) {
17221750
}
17231751

17241752
public bool: native_ca_remove_user_gag(const plugin_id, const argc) {
1725-
enum { arg_index = 1 }
1753+
enum { arg_target = 1, arg_admin }
17261754

1727-
new target = get_param(arg_index)
1755+
new target = get_param(arg_target)
17281756
new gag_flags_s: flags = g_currentGags[target][gd_reason][r_flags]
17291757

17301758
if(flags == gagFlag_Removed) {
17311759
return false
17321760
}
17331761

1734-
GagData_Copy(g_adminTempData[0], g_currentGags[target])
1735-
g_adminTempData[0][gd_target] = target
1762+
new admin = get_param(arg_admin)
1763+
GagData_Copy(g_adminTempData[admin], g_currentGags[target])
1764+
g_adminTempData[admin][gd_target] = target
17361765

1737-
return Gag_Remove(0, target)
1766+
return Gag_Remove(admin, target)
17381767
}

cstrike/addons/amxmodx/scripting/include/CA_GAG_API.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,15 @@ native bool: ca_has_user_gag(const index);
174174
/**
175175
* Remove client's gag data..
176176
*
177-
* @param index Client index
177+
* @param target Target Index
178+
* @param admin Admin Index (0 - server)
178179
*
179180
* @return True if gag has been removed.
180181
* @error If the client index is not within the range of 1 to
181182
* MaxClients, or the client is not connected, an error
182183
* will be thrown.
183184
*/
184-
native bool: ca_remove_user_gag(const index);
185+
native bool: ca_remove_user_gag(const target, admin = 0);
185186

186187
/**
187188
* Called on Gag save.

0 commit comments

Comments
 (0)