Skip to content

Commit dbc71a5

Browse files
authored
FIX: CA_Mute SQLite storage work (#312)
* - FIX: sqlite mute saves to SQLite; - Feature: Global mute also will save for players to SQLite storage. * query fix * comeback table declaration and usage
1 parent 09f2399 commit dbc71a5

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

cstrike/addons/amxmodx/scripting/CA_Mute.sma

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public MenuHandler_PlayersList(const id, const menu, const item) {
175175

176176
if(userID == ITEM_MUTE_ALL) {
177177
g_globalMute[id] ^= true
178+
Storage_Update(id, ITEM_MUTE_ALL)
178179

179180
client_print_color(0, print_team_default, "%L \3%n\1 %L ", id, "Mute_prefix",
180181
id, LANG_PLAYER, g_globalMute[id] ? "Mute_PlayerNowMutedAll" : "Mute_PlayerNowUnmutedAll"
@@ -219,7 +220,6 @@ public client_disconnected(id) {
219220
if (!g_playersMute[i][id])
220221
continue
221222

222-
// Storage_Update(i, id)
223223
g_playersMute[i][id] = false
224224
}
225225
}
@@ -253,8 +253,8 @@ Storage_Init() {
253253
Storage_Create() {
254254
new query[QUERY_LENGTH / 2]
255255

256-
formatex(query, charsmax(query), "CREATE TABLE IF NOT EXISTS %s ", g_mute_table); {
257-
strcat(query, "( id INTEGER PRIMARY KEY AUTOINCREMENT,", charsmax(query))
256+
formatex(query, charsmax(query), "CREATE TABLE IF NOT EXISTS %s", g_mute_table); {
257+
strcat(query, " ( id INTEGER PRIMARY KEY AUTOINCREMENT,", charsmax(query))
258258
strcat(query, "authid VARCHAR NOT NULL,", charsmax(query))
259259
strcat(query, "authid_target VARCHAR NOT NULL); ", charsmax(query))
260260
strcat(query, fmt("CREATE UNIQUE INDEX IF NOT EXISTS authid_target_idx1 ON %s (authid, authid_target)", g_mute_table), charsmax(query))
@@ -276,21 +276,33 @@ public client_putinserver(player) {
276276
}
277277

278278
Storage_Update(const player, const target) {
279-
if(!is_user_connected(target))
280-
return
279+
new query[QUERY_LENGTH / 2]
281280

282-
new authId[MAX_AUTHID_LENGTH], authId_target[MAX_AUTHID_LENGTH]
281+
new authId[MAX_AUTHID_LENGTH]
283282
get_user_authid(player, authId, charsmax(authId))
284-
get_user_authid(target, authId_target, charsmax(authId_target))
285283

286-
new query[QUERY_LENGTH / 2]
284+
if(target == ITEM_MUTE_ALL) {
285+
if(g_globalMute[player]) {
286+
formatex(query, charsmax(query), "INSERT INTO %s (authid, authid_target)", g_mute_table)
287+
strcat(query, fmt(" VALUES ('%s', '%s') ON CONFLICT DO NOTHING", authId, "GLOBAL"), charsmax(query))
288+
} else {
289+
formatex(query, charsmax(query), "DELETE FROM %s", g_mute_table)
290+
strcat(query, fmt(" WHERE authid='%s' AND authid_target = '%s'", authId, "GLOBAL"), charsmax(query))
291+
}
292+
293+
SQL_ThreadQuery(g_tuple, "handle_Saved", query)
294+
return
295+
}
296+
297+
new authId_target[MAX_AUTHID_LENGTH]
298+
get_user_authid(target, authId_target, charsmax(authId_target))
287299

288300
if(g_playersMute[player][target]) {
289301
formatex(query, charsmax(query), "INSERT INTO %s (authid, authid_target)", g_mute_table)
290-
strcat(query, fmt("VALUES ('%s', '%s') ON CONFLICT IGNORE", authId, authId_target), charsmax(query))
302+
strcat(query, fmt(" VALUES ('%s', '%s') ON CONFLICT DO NOTHING", authId, authId_target), charsmax(query))
291303
} else {
292-
formatex(query, charsmax(query), "DELETE FROM %s ", g_mute_table)
293-
strcat(query, fmt("WHERE authid='%s' AND authid_target = '%s'", authId, authId_target), charsmax(query))
304+
formatex(query, charsmax(query), "DELETE FROM %s", g_mute_table)
305+
strcat(query, fmt(" WHERE authid ='%s' AND authid_target = '%s'", authId, authId_target), charsmax(query))
294306
}
295307

296308
SQL_ThreadQuery(g_tuple, "handle_Saved", query)
@@ -307,8 +319,8 @@ Storage_Load(const player) {
307319
get_user_authid(player, authId, charsmax(authId))
308320

309321
new query[QUERY_LENGTH / 2]
310-
formatex(query, charsmax(query), "SELECT authid, authid_target FROM %s ", g_mute_table)
311-
strcat(query, fmt("WHERE authid='%s' OR authid_target = '%s'", authId, authId), charsmax(query))
322+
formatex(query, charsmax(query), "SELECT authid, authid_target FROM %s", g_mute_table)
323+
strcat(query, fmt(" WHERE authid ='%s' OR authid_target = '%s'", authId, authId), charsmax(query))
312324

313325
SQL_ThreadQuery(g_tuple, "handle_LoadedMute", query)
314326
}
@@ -327,7 +339,12 @@ public handle_LoadedMute(failstate, Handle: query, error[], errnum, data[], size
327339
SQL_ReadResult(query, 1, authId_target, charsmax(authId_target))
328340

329341
new player = find_player_ex(FindPlayer_MatchAuthId, authId)
330-
if (player == 0) {
342+
if(player == 0) {
343+
goto next
344+
}
345+
346+
if(strcmp(authId_target, "GLOBAL") == 0) {
347+
g_globalMute[player] = true
331348
goto next
332349
}
333350

0 commit comments

Comments
 (0)