@@ -23,7 +23,8 @@ const MAX_REASON_LENGTH = 256;
2323new g_query[QUERY_LENGTH]
2424
2525new Handle: g_tuple = Empty_Handle
26- new Queue: g_queueLoad = Invalid_Queue
26+ new Queue: g_queueLoad = Invalid_Queue,
27+ Queue: g_queueSave = Invalid_Queue
2728
2829new g_serverID = - 1
2930
@@ -49,6 +50,7 @@ public plugin_init() {
4950 AutoExecConfig (true , " CA_Storage_GameCMS" , " ChatAdditions" )
5051
5152 g_queueLoad = QueueCreate (MAX_AUTHID_LENGTH)
53+ g_queueSave = QueueCreate (gagData_s)
5254}
5355public OnConfigsExecuted () {
5456 g_tuple = SQL_MakeDbTuple (ca_storage_host, ca_storage_user, ca_storage_pass, ca_storage_dbname)
@@ -62,6 +64,7 @@ public plugin_end() {
6264 }
6365
6466 QueueDestroy (g_queueLoad)
67+ QueueDestroy (g_queueSave)
6568}
6669public plugin_natives () {
6770 RegisterNatives ()
@@ -135,6 +138,27 @@ Storage_Save(const name[], const authID[], const IP[],
135138 const reason[], const adminName[], const adminAuthID[],
136139 const adminIP[], const expireAt, const flags) {
137140
141+ if (! g_storageInitialized) {
142+ new gagData[gagData_s]; {
143+ copy (gagData[gd_name], charsmax (gagData[gd_name]), name)
144+ copy (gagData[gd_authID], charsmax (gagData[gd_authID]), authID)
145+ copy (gagData[gd_IP], charsmax (gagData[gd_IP]), IP)
146+
147+ copy (gagData[gd_adminName], charsmax (gagData[gd_adminName]), adminName)
148+ copy (gagData[gd_adminAuthID], charsmax (gagData[gd_adminAuthID]), adminAuthID)
149+ copy (gagData[gd_adminIP], charsmax (gagData[gd_adminIP]), adminIP)
150+
151+ copy (gagData[gd_reason][r_name], charsmax (gagData[r_name]), reason)
152+ gagData[gd_reason][r_flags] = gag_flags_s: flags
153+
154+ gagData[gd_expireAt] = expireAt
155+ }
156+
157+ QueuePushArray (g_queueSave, gagData)
158+
159+ return
160+ }
161+
138162 #pragma unused adminIP, adminAuthID, IP
139163 new name_safe[MAX_NAME_LENGTH * 2 ];
140164 SQL_QuoteString (Empty_Handle, name_safe, charsmax (name_safe), name);
@@ -282,6 +306,14 @@ public handle_Loaded(failstate, Handle: query, error[], errnum, data[], size, Fl
282306}
283307
284308Storage_Remove (const authID[]) {
309+ if (g_storageInitialized || g_tuple == Empty_Handle) {
310+ CA_Log (logLevel_Warning, " Storage_Remove(): Storage connection not initialized. Query not executed. (g_storageInitialized=%i , g_tuple=%i )" ,
311+ g_storageInitialized, g_tuple
312+ )
313+
314+ return
315+ }
316+
285317 formatex (g_query, charsmax (g_query), " DELETE FROM %s " , SQL_TBL_GAGS); {
286318 strcat (g_query, fmt (" WHERE (authid = '%s ')" , authID), charsmax (g_query))
287319 }
@@ -332,9 +364,35 @@ public handle_GetServerID(failstate, Handle: query, error[], errnum, data[], siz
332364 g_storageInitialized = true
333365 ExecuteForward (g_fwd_StorageInitialized, g_ret)
334366
367+ // Load prepared data from storage
368+ new queueCounter
335369 for (new i, len = QueueSize (g_queueLoad); i < len; i++ ) {
336370 new authID[MAX_AUTHID_LENGTH]; QueuePopString (g_queueLoad, authID, charsmax (authID))
337371 Storage_Load (authID)
372+
373+ ++ queueCounter
374+ }
375+
376+ if (queueCounter) {
377+ CA_Log (logLevel_Info, " Loaded %i queue gags from DB (slow DB connection issue)" , queueCounter)
378+ queueCounter = 0
379+ }
380+
381+ // Save prepared data to storage
382+ for (new i, len = QueueSize (g_queueSave); i < len; i++ ) {
383+ new gagData[gagData_s]; QueuePopArray (g_queueSave, gagData, sizeof (gagData))
384+
385+ Storage_Save (gagData[gd_name], gagData[gd_authID], gagData[gd_IP],
386+ gagData[gd_reason][r_name], gagData[gd_adminName], gagData[gd_adminAuthID],
387+ gagData[gd_adminIP], gagData[gd_expireAt], gagData[gd_reason][r_flags]
388+ )
389+
390+ ++ queueCounter
391+ }
392+
393+ if (queueCounter) {
394+ CA_Log (logLevel_Info, " Saved %i queue gags to DB (slow DB connection issue)" , queueCounter)
395+ queueCounter = 0
338396 }
339397}
340398
0 commit comments