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

FIX: CA_Mute SQLite storage work #312

Merged
merged 3 commits into from
Dec 10, 2023
Merged
Changes from all 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
45 changes: 31 additions & 14 deletions cstrike/addons/amxmodx/scripting/CA_Mute.sma
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public MenuHandler_PlayersList(const id, const menu, const item) {

if(userID == ITEM_MUTE_ALL) {
g_globalMute[id] ^= true
Storage_Update(id, ITEM_MUTE_ALL)

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

// Storage_Update(i, id)
g_playersMute[i][id] = false
}
}
Expand Down Expand Up @@ -253,8 +253,8 @@ Storage_Init() {
Storage_Create() {
new query[QUERY_LENGTH / 2]

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

Storage_Update(const player, const target) {
if(!is_user_connected(target))
return
new query[QUERY_LENGTH / 2]

new authId[MAX_AUTHID_LENGTH], authId_target[MAX_AUTHID_LENGTH]
new authId[MAX_AUTHID_LENGTH]
get_user_authid(player, authId, charsmax(authId))
get_user_authid(target, authId_target, charsmax(authId_target))

new query[QUERY_LENGTH / 2]
if(target == ITEM_MUTE_ALL) {
if(g_globalMute[player]) {
formatex(query, charsmax(query), "INSERT INTO %s (authid, authid_target)", g_mute_table)
strcat(query, fmt(" VALUES ('%s', '%s') ON CONFLICT DO NOTHING", authId, "GLOBAL"), charsmax(query))
} else {
formatex(query, charsmax(query), "DELETE FROM %s", g_mute_table)
strcat(query, fmt(" WHERE authid='%s' AND authid_target = '%s'", authId, "GLOBAL"), charsmax(query))
}

SQL_ThreadQuery(g_tuple, "handle_Saved", query)
return
}

new authId_target[MAX_AUTHID_LENGTH]
get_user_authid(target, authId_target, charsmax(authId_target))

if(g_playersMute[player][target]) {
formatex(query, charsmax(query), "INSERT INTO %s (authid, authid_target)", g_mute_table)
strcat(query, fmt("VALUES ('%s', '%s') ON CONFLICT IGNORE", authId, authId_target), charsmax(query))
strcat(query, fmt(" VALUES ('%s', '%s') ON CONFLICT DO NOTHING", authId, authId_target), charsmax(query))
} else {
formatex(query, charsmax(query), "DELETE FROM %s ", g_mute_table)
strcat(query, fmt("WHERE authid='%s' AND authid_target = '%s'", authId, authId_target), charsmax(query))
formatex(query, charsmax(query), "DELETE FROM %s", g_mute_table)
strcat(query, fmt(" WHERE authid ='%s' AND authid_target = '%s'", authId, authId_target), charsmax(query))
}

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

new query[QUERY_LENGTH / 2]
formatex(query, charsmax(query), "SELECT authid, authid_target FROM %s ", g_mute_table)
strcat(query, fmt("WHERE authid='%s' OR authid_target = '%s'", authId, authId), charsmax(query))
formatex(query, charsmax(query), "SELECT authid, authid_target FROM %s", g_mute_table)
strcat(query, fmt(" WHERE authid ='%s' OR authid_target = '%s'", authId, authId), charsmax(query))

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

new player = find_player_ex(FindPlayer_MatchAuthId, authId)
if (player == 0) {
if(player == 0) {
goto next
}

if(strcmp(authId_target, "GLOBAL") == 0) {
g_globalMute[player] = true
goto next
}

Expand Down