· 6 years ago · Jan 05, 2020, 04:04 AM
1/* CS:GO Weapons&Knives SourceMod Plugin
2 *
3 * Copyright (C) 2017 Kağan 'kgns' Üstüngel
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation, either version 3 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see http://www.gnu.org/licenses/.
16 */
17
18void GetPlayerData(int client)
19{
20 char steamid[32];
21 GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid), true);
22 char query[255];
23 FormatEx(query, sizeof(query), "SELECT * FROM %sweapons WHERE steamid = '%s'", g_TablePrefix, steamid);
24 db.Query(T_GetPlayerDataCallback, query, GetClientUserId(client));
25}
26
27public void T_GetPlayerDataCallback(Database database, DBResultSet results, const char[] error, int userid)
28{
29 int clientIndex = GetClientOfUserId(userid);
30 if(IsValidClient(clientIndex))
31 {
32 if (results == null)
33 {
34 LogError("Query failed! %s", error);
35 }
36 else if (results.RowCount == 0)
37 {
38 char steamid[32];
39 GetClientAuthId(clientIndex, AuthId_Steam2, steamid, sizeof(steamid), true);
40 char query[255];
41 FormatEx(query, sizeof(query), "INSERT INTO %sweapons (steamid) VALUES ('%s')", g_TablePrefix, steamid);
42 DataPack pack = new DataPack();
43 pack.WriteString(steamid);
44 pack.WriteString(query);
45 db.Query(T_InsertCallback, query, pack);
46 for(int i = 0; i < sizeof(g_WeaponClasses); i++)
47 {
48 g_iSkins[clientIndex][i] = 0;
49 g_iStatTrak[clientIndex][i] = 0;
50 g_iStatTrakCount[clientIndex][i] = 0;
51 g_NameTag[clientIndex][i] = "";
52 g_fFloatValue[clientIndex][i] = 0.0;
53 g_iWeaponSeed[clientIndex][i] = -1;
54 }
55 g_iKnife[clientIndex] = 0;
56 }
57 else
58 {
59 if(results.FetchRow())
60 {
61 for(int i = 2, j = 0; j < sizeof(g_WeaponClasses); i += 6, j++)
62 {
63 g_iSkins[clientIndex][j] = results.FetchInt(i);
64 g_fFloatValue[clientIndex][j] = results.FetchFloat(i + 1);
65 g_iStatTrak[clientIndex][j] = results.FetchInt(i + 2);
66 g_iStatTrakCount[clientIndex][j] = results.FetchInt(i + 3);
67 results.FetchString(i + 4, g_NameTag[clientIndex][j], 128);
68 g_iWeaponSeed[clientIndex][j] = results.FetchInt(i + 5);
69 }
70 g_iKnife[clientIndex] = results.FetchInt(1);
71 }
72 char steamid[32];
73 GetClientAuthId(clientIndex, AuthId_Steam2, steamid, sizeof(steamid), true);
74 char query[255];
75 FormatEx(query, sizeof(query), "REPLACE INTO %sweapons_timestamps (steamid, last_seen) VALUES ('%s', %d)", g_TablePrefix, steamid, GetTime());
76 DataPack pack = new DataPack();
77 pack.WriteString(query);
78 db.Query(T_TimestampCallback, query, pack);
79 }
80 }
81}
82
83public void T_InsertCallback(Database database, DBResultSet results, const char[] error, DataPack pack)
84{
85 pack.Reset();
86 char steamid[32];
87 pack.ReadString(steamid, 32);
88 if (results == null)
89 {
90 char buffer[1024];
91 pack.ReadString(buffer, 1024);
92 LogError("Insert Query failed! query: \"%s\" error: \"%s\"", buffer, error);
93 }
94 else
95 {
96 char query[255];
97 FormatEx(query, sizeof(query), "REPLACE INTO %sweapons_timestamps (steamid, last_seen) VALUES ('%s', %d)", g_TablePrefix, steamid, GetTime());
98 DataPack newPack = new DataPack();
99 newPack.WriteString(query);
100 db.Query(T_TimestampCallback, query, newPack);
101 }
102 CloseHandle(pack);
103}
104
105public void T_TimestampCallback(Database database, DBResultSet results, const char[] error, DataPack pack)
106{
107 if (results == null)
108 {
109 pack.Reset();
110 char buffer[1024];
111 pack.ReadString(buffer, 1024);
112 LogError("Timestamp Query failed! query: \"%s\" error: \"%s\"", buffer, error);
113 }
114 CloseHandle(pack);
115}
116
117void UpdatePlayerData(int client, char[] updateFields)
118{
119 char steamid[32];
120 GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid), true);
121 char query[1024];
122 FormatEx(query, sizeof(query), "UPDATE %sweapons SET %s WHERE steamid = '%s'", g_TablePrefix, updateFields, steamid);
123 DataPack pack = new DataPack();
124 pack.WriteString(query);
125 db.Query(T_UpdatePlayerDataCallback, query, pack);
126}
127
128public void T_UpdatePlayerDataCallback(Database database, DBResultSet results, const char[] error, DataPack pack)
129{
130 if (results == null)
131 {
132 pack.Reset();
133 char buffer[1024];
134 pack.ReadString(buffer, 1024);
135 LogError("Update Player failed! query: \"%s\" error: \"%s\"", buffer, error);
136 }
137 CloseHandle(pack);
138}
139
140public void SQLConnectCallback(Database database, const char[] error, any data)
141{
142 if (database == null)
143 {
144 LogError("Database failure: %s", error);
145 }
146 else
147 {
148 db = database;
149 char dbIdentifier[10];
150
151 db.Driver.GetIdentifier(dbIdentifier, sizeof(dbIdentifier));
152 bool mysql = StrEqual(dbIdentifier, "mysql");
153
154 CreateMainTable(mysql);
155 }
156}
157
158void CreateMainTable(bool mysql, bool recreate = false)
159{
160 char createQuery[20480];
161
162 int index = 0;
163
164 index += FormatEx(createQuery[index], sizeof(createQuery) - index, " \
165 CREATE TABLE IF NOT EXISTS %sweapons ( \
166 steamid varchar(32) NOT NULL PRIMARY KEY, \
167 knife int(4) NOT NULL DEFAULT '0', \
168 awp int(4) NOT NULL DEFAULT '0', \
169 awp_float decimal(3,2) NOT NULL DEFAULT '0.0', \
170 awp_trak int(1) NOT NULL DEFAULT '0', \
171 awp_trak_count int(10) NOT NULL DEFAULT '0', \
172 awp_tag varchar(256) NOT NULL DEFAULT '', \
173 awp_seed int(10) NOT NULL DEFAULT '-1', \
174 ak47 int(4) NOT NULL DEFAULT '0', \
175 ak47_float decimal(3,2) NOT NULL DEFAULT '0.0', \
176 ak47_trak int(1) NOT NULL DEFAULT '0', \
177 ak47_trak_count int(10) NOT NULL DEFAULT '0', \
178 ak47_tag varchar(256) NOT NULL DEFAULT '', \
179 ak47_seed int(10) NOT NULL DEFAULT '-1', \
180 m4a1 int(4) NOT NULL DEFAULT '0', \
181 m4a1_float decimal(3,2) NOT NULL DEFAULT '0.0', \
182 m4a1_trak int(1) NOT NULL DEFAULT '0', \
183 m4a1_trak_count int(10) NOT NULL DEFAULT '0', \
184 m4a1_tag varchar(256) NOT NULL DEFAULT '', \
185 m4a1_seed int(10) NOT NULL DEFAULT '-1', ", g_TablePrefix);
186 index += FormatEx(createQuery[index], sizeof(createQuery) - index, " \
187 m4a1_silencer int(4) NOT NULL DEFAULT '0', \
188 m4a1_silencer_float decimal(3,2) NOT NULL DEFAULT '0.0', \
189 m4a1_silencer_trak int(1) NOT NULL DEFAULT '0', \
190 m4a1_silencer_trak_count int(10) NOT NULL DEFAULT '0', \
191 m4a1_silencer_tag varchar(256) NOT NULL DEFAULT '', \
192 m4a1_silencer_seed int(10) NOT NULL DEFAULT '-1', \
193 deagle int(4) NOT NULL DEFAULT '0', \
194 deagle_float decimal(3,2) NOT NULL DEFAULT '0.0', \
195 deagle_trak int(1) NOT NULL DEFAULT '0', \
196 deagle_trak_count int(10) NOT NULL DEFAULT '0', \
197 deagle_tag varchar(256) NOT NULL DEFAULT '', \
198 deagle_seed int(10) NOT NULL DEFAULT '-1', \
199 usp_silencer int(4) NOT NULL DEFAULT '0', \
200 usp_silencer_float decimal(3,2) NOT NULL DEFAULT '0.0', \
201 usp_silencer_trak int(1) NOT NULL DEFAULT '0', \
202 usp_silencer_trak_count int(10) NOT NULL DEFAULT '0', \
203 usp_silencer_tag varchar(256) NOT NULL DEFAULT '', \
204 usp_silencer_seed int(10) NOT NULL DEFAULT '-1', \
205 hkp2000 int(4) NOT NULL DEFAULT '0', \
206 hkp2000_float decimal(3,2) NOT NULL DEFAULT '0.0', \
207 hkp2000_trak int(1) NOT NULL DEFAULT '0', ");
208 index += FormatEx(createQuery[index], sizeof(createQuery) - index, " \
209 hkp2000_trak_count int(10) NOT NULL DEFAULT '0', \
210 hkp2000_tag varchar(256) NOT NULL DEFAULT '', \
211 hkp2000_seed int(10) NOT NULL DEFAULT '-1', \
212 glock int(4) NOT NULL DEFAULT '0', \
213 glock_float decimal(3,2) NOT NULL DEFAULT '0.0', \
214 glock_trak int(1) NOT NULL DEFAULT '0', \
215 glock_trak_count int(10) NOT NULL DEFAULT '0', \
216 glock_tag varchar(256) NOT NULL DEFAULT '', \
217 glock_seed int(10) NOT NULL DEFAULT '-1', \
218 elite int(4) NOT NULL DEFAULT '0', \
219 elite_float decimal(3,2) NOT NULL DEFAULT '0.0', \
220 elite_trak int(1) NOT NULL DEFAULT '0', \
221 elite_trak_count int(10) NOT NULL DEFAULT '0', \
222 elite_tag varchar(256) NOT NULL DEFAULT '', \
223 elite_seed int(10) NOT NULL DEFAULT '-1', \
224 p250 int(4) NOT NULL DEFAULT '0', \
225 p250_float decimal(3,2) NOT NULL DEFAULT '0.0', \
226 p250_trak int(1) NOT NULL DEFAULT '0', \
227 p250_trak_count int(10) NOT NULL DEFAULT '0', \
228 p250_tag varchar(256) NOT NULL DEFAULT '', \
229 p250_seed int(10) NOT NULL DEFAULT '-1', \
230 cz75a int(4) NOT NULL DEFAULT '0', ");
231 index += FormatEx(createQuery[index], sizeof(createQuery) - index, " \
232 cz75a_float decimal(3,2) NOT NULL DEFAULT '0.0', \
233 cz75a_trak int(1) NOT NULL DEFAULT '0', \
234 cz75a_trak_count int(10) NOT NULL DEFAULT '0', \
235 cz75a_tag varchar(256) NOT NULL DEFAULT '', \
236 cz75a_seed int(10) NOT NULL DEFAULT '-1', \
237 fiveseven int(4) NOT NULL DEFAULT '0', \
238 fiveseven_float decimal(3,2) NOT NULL DEFAULT '0.0', \
239 fiveseven_trak int(1) NOT NULL DEFAULT '0', \
240 fiveseven_trak_count int(10) NOT NULL DEFAULT '0', \
241 fiveseven_tag varchar(256) NOT NULL DEFAULT '', \
242 fiveseven_seed int(10) NOT NULL DEFAULT '-1', \
243 tec9 int(4) NOT NULL DEFAULT '0', \
244 tec9_float decimal(3,2) NOT NULL DEFAULT '0.0', \
245 tec9_trak int(1) NOT NULL DEFAULT '0', \
246 tec9_trak_count int(10) NOT NULL DEFAULT '0', \
247 tec9_tag varchar(256) NOT NULL DEFAULT '', \
248 tec9_seed int(10) NOT NULL DEFAULT '-1', \
249 revolver int(4) NOT NULL DEFAULT '0', \
250 revolver_float decimal(3,2) NOT NULL DEFAULT '0.0', \
251 revolver_trak int(1) NOT NULL DEFAULT '0', \
252 revolver_trak_count int(10) NOT NULL DEFAULT '0', ");
253 index += FormatEx(createQuery[index], sizeof(createQuery) - index, " \
254 revolver_tag varchar(256) NOT NULL DEFAULT '', \
255 revolver_seed int(10) NOT NULL DEFAULT '-1', \
256 nova int(4) NOT NULL DEFAULT '0', \
257 nova_float decimal(3,2) NOT NULL DEFAULT '0.0', \
258 nova_trak int(1) NOT NULL DEFAULT '0', \
259 nova_trak_count int(10) NOT NULL DEFAULT '0', \
260 nova_tag varchar(256) NOT NULL DEFAULT '', \
261 nova_seed int(10) NOT NULL DEFAULT '-1', \
262 xm1014 int(4) NOT NULL DEFAULT '0', \
263 xm1014_float decimal(3,2) NOT NULL DEFAULT '0.0', \
264 xm1014_trak int(1) NOT NULL DEFAULT '0', \
265 xm1014_trak_count int(10) NOT NULL DEFAULT '0', \
266 xm1014_tag varchar(256) NOT NULL DEFAULT '', \
267 xm1014_seed int(10) NOT NULL DEFAULT '-1', \
268 mag7 int(4) NOT NULL DEFAULT '0', \
269 mag7_float decimal(3,2) NOT NULL DEFAULT '0.0', \
270 mag7_trak int(1) NOT NULL DEFAULT '0', \
271 mag7_trak_count int(10) NOT NULL DEFAULT '0', \
272 mag7_tag varchar(256) NOT NULL DEFAULT '', \
273 mag7_seed int(10) NOT NULL DEFAULT '-1', \
274 sawedoff int(4) NOT NULL DEFAULT '0', \
275 sawedoff_float decimal(3,2) NOT NULL DEFAULT '0.0', ");
276 index += FormatEx(createQuery[index], sizeof(createQuery) - index, " \
277 sawedoff_trak int(1) NOT NULL DEFAULT '0', \
278 sawedoff_trak_count int(10) NOT NULL DEFAULT '0', \
279 sawedoff_tag varchar(256) NOT NULL DEFAULT '', \
280 sawedoff_seed int(10) NOT NULL DEFAULT '-1', \
281 m249 int(4) NOT NULL DEFAULT '0', \
282 m249_float decimal(3,2) NOT NULL DEFAULT '0.0', \
283 m249_trak int(1) NOT NULL DEFAULT '0', \
284 m249_trak_count int(10) NOT NULL DEFAULT '0', \
285 m249_tag varchar(256) NOT NULL DEFAULT '', \
286 m249_seed int(10) NOT NULL DEFAULT '-1', \
287 negev int(4) NOT NULL DEFAULT '0', \
288 negev_float decimal(3,2) NOT NULL DEFAULT '0.0', \
289 negev_trak int(1) NOT NULL DEFAULT '0', \
290 negev_trak_count int(10) NOT NULL DEFAULT '0', \
291 negev_tag varchar(256) NOT NULL DEFAULT '', \
292 negev_seed int(10) NOT NULL DEFAULT '-1', \
293 mp9 int(4) NOT NULL DEFAULT '0', \
294 mp9_float decimal(3,2) NOT NULL DEFAULT '0.0', \
295 mp9_trak int(1) NOT NULL DEFAULT '0', \
296 mp9_trak_count int(10) NOT NULL DEFAULT '0', \
297 mp9_tag varchar(256) NOT NULL DEFAULT '', \
298 mp9_seed int(10) NOT NULL DEFAULT '-1', ");
299 index += FormatEx(createQuery[index], sizeof(createQuery) - index, " \
300 mac10 int(4) NOT NULL DEFAULT '0', \
301 mac10_float decimal(3,2) NOT NULL DEFAULT '0.0', \
302 mac10_trak int(1) NOT NULL DEFAULT '0', \
303 mac10_trak_count int(10) NOT NULL DEFAULT '0', \
304 mac10_tag varchar(256) NOT NULL DEFAULT '', \
305 mac10_seed int(10) NOT NULL DEFAULT '-1', \
306 mp7 int(4) NOT NULL DEFAULT '0', \
307 mp7_float decimal(3,2) NOT NULL DEFAULT '0.0', \
308 mp7_trak int(1) NOT NULL DEFAULT '0', \
309 mp7_trak_count int(10) NOT NULL DEFAULT '0', \
310 mp7_tag varchar(256) NOT NULL DEFAULT '', \
311 mp7_seed int(10) NOT NULL DEFAULT '-1', \
312 ump45 int(4) NOT NULL DEFAULT '0', \
313 ump45_float decimal(3,2) NOT NULL DEFAULT '0.0', \
314 ump45_trak int(1) NOT NULL DEFAULT '0', \
315 ump45_trak_count int(10) NOT NULL DEFAULT '0', \
316 ump45_tag varchar(256) NOT NULL DEFAULT '', \
317 ump45_seed int(10) NOT NULL DEFAULT '-1', \
318 p90 int(4) NOT NULL DEFAULT '0', \
319 p90_float decimal(3,2) NOT NULL DEFAULT '0.0', \
320 p90_trak int(1) NOT NULL DEFAULT '0', ");
321 index += FormatEx(createQuery[index], sizeof(createQuery) - index, " \
322 p90_trak_count int(10) NOT NULL DEFAULT '0', \
323 p90_tag varchar(256) NOT NULL DEFAULT '', \
324 p90_seed int(10) NOT NULL DEFAULT '-1', \
325 bizon int(4) NOT NULL DEFAULT '0', \
326 bizon_float decimal(3,2) NOT NULL DEFAULT '0.0', \
327 bizon_trak int(1) NOT NULL DEFAULT '0', \
328 bizon_trak_count int(10) NOT NULL DEFAULT '0', \
329 bizon_tag varchar(256) NOT NULL DEFAULT '', \
330 bizon_seed int(10) NOT NULL DEFAULT '-1', \
331 famas int(4) NOT NULL DEFAULT '0', \
332 famas_float decimal(3,2) NOT NULL DEFAULT '0.0', \
333 famas_trak int(1) NOT NULL DEFAULT '0', \
334 famas_trak_count int(10) NOT NULL DEFAULT '0', \
335 famas_tag varchar(256) NOT NULL DEFAULT '', \
336 famas_seed int(10) NOT NULL DEFAULT '-1', \
337 galilar int(4) NOT NULL DEFAULT '0', \
338 galilar_float decimal(3,2) NOT NULL DEFAULT '0.0', \
339 galilar_trak int(1) NOT NULL DEFAULT '0', \
340 galilar_trak_count int(10) NOT NULL DEFAULT '0', \
341 galilar_tag varchar(256) NOT NULL DEFAULT '', \
342 galilar_seed int(10) NOT NULL DEFAULT '-1', \
343 ssg08 int(4) NOT NULL DEFAULT '0', ");
344 index += FormatEx(createQuery[index], sizeof(createQuery) - index, " \
345 ssg08_float decimal(3,2) NOT NULL DEFAULT '0.0', \
346 ssg08_trak int(1) NOT NULL DEFAULT '0', \
347 ssg08_trak_count int(10) NOT NULL DEFAULT '0', \
348 ssg08_tag varchar(256) NOT NULL DEFAULT '', \
349 ssg08_seed int(10) NOT NULL DEFAULT '-1', \
350 aug int(4) NOT NULL DEFAULT '0', \
351 aug_float decimal(3,2) NOT NULL DEFAULT '0.0', \
352 aug_trak int(1) NOT NULL DEFAULT '0', \
353 aug_trak_count int(10) NOT NULL DEFAULT '0', \
354 aug_tag varchar(256) NOT NULL DEFAULT '', \
355 aug_seed int(10) NOT NULL DEFAULT '-1', \
356 sg556 int(4) NOT NULL DEFAULT '0', \
357 sg556_float decimal(3,2) NOT NULL DEFAULT '0.0', \
358 sg556_trak int(1) NOT NULL DEFAULT '0', \
359 sg556_trak_count int(10) NOT NULL DEFAULT '0', \
360 sg556_tag varchar(256) NOT NULL DEFAULT '', \
361 sg556_seed int(10) NOT NULL DEFAULT '-1', \
362 scar20 int(4) NOT NULL DEFAULT '0', \
363 scar20_float decimal(3,2) NOT NULL DEFAULT '0.0', \
364 scar20_trak int(1) NOT NULL DEFAULT '0', \
365 scar20_trak_count int(10) NOT NULL DEFAULT '0', ");
366 index += FormatEx(createQuery[index], sizeof(createQuery) - index, " \
367 scar20_tag varchar(256) NOT NULL DEFAULT '', \
368 scar20_seed int(10) NOT NULL DEFAULT '-1', \
369 g3sg1 int(4) NOT NULL DEFAULT '0', \
370 g3sg1_float decimal(3,2) NOT NULL DEFAULT '0.0', \
371 g3sg1_trak int(1) NOT NULL DEFAULT '0', \
372 g3sg1_trak_count int(10) NOT NULL DEFAULT '0', \
373 g3sg1_tag varchar(256) NOT NULL DEFAULT '', \
374 g3sg1_seed int(10) NOT NULL DEFAULT '-1', \
375 knife_karambit int(4) NOT NULL DEFAULT '0', \
376 knife_karambit_float decimal(3,2) NOT NULL DEFAULT '0.0', \
377 knife_karambit_trak int(1) NOT NULL DEFAULT '0', \
378 knife_karambit_trak_count int(10) NOT NULL DEFAULT '0', \
379 knife_karambit_tag varchar(256) NOT NULL DEFAULT '', \
380 knife_karambit_seed int(10) NOT NULL DEFAULT '-1', \
381 knife_m9_bayonet int(4) NOT NULL DEFAULT '0', \
382 knife_m9_bayonet_float decimal(3,2) NOT NULL DEFAULT '0.0', \
383 knife_m9_bayonet_trak int(1) NOT NULL DEFAULT '0', \
384 knife_m9_bayonet_trak_count int(10) NOT NULL DEFAULT '0', \
385 knife_m9_bayonet_tag varchar(256) NOT NULL DEFAULT '', \
386 knife_m9_bayonet_seed int(10) NOT NULL DEFAULT '-1', \
387 bayonet int(4) NOT NULL DEFAULT '0', \
388 bayonet_float decimal(3,2) NOT NULL DEFAULT '0.0', ");
389 index += FormatEx(createQuery[index], sizeof(createQuery) - index, " \
390 bayonet_trak int(1) NOT NULL DEFAULT '0', \
391 bayonet_trak_count int(10) NOT NULL DEFAULT '0', \
392 bayonet_tag varchar(256) NOT NULL DEFAULT '', \
393 bayonet_seed int(10) NOT NULL DEFAULT '-1', \
394 knife_survival_bowie int(4) NOT NULL DEFAULT '0', \
395 knife_survival_bowie_float decimal(3,2) NOT NULL DEFAULT '0.0', \
396 knife_survival_bowie_trak int(1) NOT NULL DEFAULT '0', \
397 knife_survival_bowie_trak_count int(10) NOT NULL DEFAULT '0', \
398 knife_survival_bowie_tag varchar(256) NOT NULL DEFAULT '', \
399 knife_survival_bowie_seed int(10) NOT NULL DEFAULT '-1', \
400 knife_butterfly int(4) NOT NULL DEFAULT '0', \
401 knife_butterfly_float decimal(3,2) NOT NULL DEFAULT '0.0', \
402 knife_butterfly_trak int(1) NOT NULL DEFAULT '0', \
403 knife_butterfly_trak_count int(10) NOT NULL DEFAULT '0', \
404 knife_butterfly_tag varchar(256) NOT NULL DEFAULT '', \
405 knife_butterfly_seed int(10) NOT NULL DEFAULT '-1', \
406 knife_flip int(4) NOT NULL DEFAULT '0', \
407 knife_flip_float decimal(3,2) NOT NULL DEFAULT '0.0', \
408 knife_flip_trak int(1) NOT NULL DEFAULT '0', \
409 knife_flip_trak_count int(10) NOT NULL DEFAULT '0', \
410 knife_flip_tag varchar(256) NOT NULL DEFAULT '', \
411 knife_flip_seed int(10) NOT NULL DEFAULT '-1', ");
412 index += FormatEx(createQuery[index], sizeof(createQuery) - index, " \
413 knife_push int(4) NOT NULL DEFAULT '0', \
414 knife_push_float decimal(3,2) NOT NULL DEFAULT '0.0', \
415 knife_push_trak int(1) NOT NULL DEFAULT '0', \
416 knife_push_trak_count int(10) NOT NULL DEFAULT '0', \
417 knife_push_tag varchar(256) NOT NULL DEFAULT '', \
418 knife_push_seed int(10) NOT NULL DEFAULT '-1', \
419 knife_tactical int(4) NOT NULL DEFAULT '0', \
420 knife_tactical_float decimal(3,2) NOT NULL DEFAULT '0.0', \
421 knife_tactical_trak int(1) NOT NULL DEFAULT '0', \
422 knife_tactical_trak_count int(10) NOT NULL DEFAULT '0', \
423 knife_tactical_tag varchar(256) NOT NULL DEFAULT '', \
424 knife_tactical_seed int(10) NOT NULL DEFAULT '-1', \
425 knife_falchion int(4) NOT NULL DEFAULT '0', \
426 knife_falchion_float decimal(3,2) NOT NULL DEFAULT '0.0', \
427 knife_falchion_trak int(1) NOT NULL DEFAULT '0', \
428 knife_falchion_trak_count int(10) NOT NULL DEFAULT '0', \
429 knife_falchion_tag varchar(256) NOT NULL DEFAULT '', \
430 knife_falchion_seed int(10) NOT NULL DEFAULT '-1', \
431 knife_gut int(4) NOT NULL DEFAULT '0', \
432 knife_gut_float decimal(3,2) NOT NULL DEFAULT '0.0', \
433 knife_gut_trak int(1) NOT NULL DEFAULT '0', ");
434 index += FormatEx(createQuery[index], sizeof(createQuery) - index, " \
435 knife_gut_trak_count int(10) NOT NULL DEFAULT '0', \
436 knife_gut_tag varchar(256) NOT NULL DEFAULT '', \
437 knife_gut_seed int(10) NOT NULL DEFAULT '-1', \
438 knife_ursus int(4) NOT NULL DEFAULT '0', \
439 knife_ursus_float decimal(3,2) NOT NULL DEFAULT '0.0', \
440 knife_ursus_trak int(1) NOT NULL DEFAULT '0', \
441 knife_ursus_trak_count int(10) NOT NULL DEFAULT '0', \
442 knife_ursus_tag varchar(256) NOT NULL DEFAULT '', \
443 knife_ursus_seed int(10) NOT NULL DEFAULT '-1', \
444 knife_gypsy_jackknife int(4) NOT NULL DEFAULT '0', \
445 knife_gypsy_jackknife_float decimal(3,2) NOT NULL DEFAULT '0.0',\
446 knife_gypsy_jackknife_trak int(1) NOT NULL DEFAULT '0', \
447 knife_gypsy_jackknife_trak_count int(10) NOT NULL DEFAULT '0', \
448 knife_gypsy_jackknife_tag varchar(256) NOT NULL DEFAULT '', \
449 knife_gypsy_jackknife_seed int(10) NOT NULL DEFAULT '-1', \
450 knife_stiletto int(4) NOT NULL DEFAULT '0', \
451 knife_stiletto_float decimal(3,2) NOT NULL DEFAULT '0.0', \
452 knife_stiletto_trak int(1) NOT NULL DEFAULT '0', \
453 knife_stiletto_trak_count int(10) NOT NULL DEFAULT '0', \
454 knife_stiletto_tag varchar(256) NOT NULL DEFAULT '', \
455 knife_stiletto_seed int(10) NOT NULL DEFAULT '-1', \
456 knife_widowmaker int(4) NOT NULL DEFAULT '0', ");
457 index += FormatEx(createQuery[index], sizeof(createQuery) - index, " \
458 knife_widowmaker_float decimal(3,2) NOT NULL DEFAULT '0.0', \
459 knife_widowmaker_trak int(1) NOT NULL DEFAULT '0', \
460 knife_widowmaker_trak_count int(10) NOT NULL DEFAULT '0', \
461 knife_widowmaker_tag varchar(256) NOT NULL DEFAULT '', \
462 knife_widowmaker_seed int(10) NOT NULL DEFAULT '-1', \
463 mp5sd int(4) NOT NULL DEFAULT '0', \
464 mp5sd_float decimal(3,2) NOT NULL DEFAULT '0.0', \
465 mp5sd_trak int(1) NOT NULL DEFAULT '0', \
466 mp5sd_trak_count int(10) NOT NULL DEFAULT '0', \
467 mp5sd_tag varchar(256) NOT NULL DEFAULT '', \
468 mp5sd_seed int(10) NOT NULL DEFAULT '-1', \
469 knife_css int(4) NOT NULL DEFAULT '0', \
470 knife_css_float decimal(3,2) NOT NULL DEFAULT '0.0', \
471 knife_css_trak int(1) NOT NULL DEFAULT '0', \
472 knife_css_trak_count int(10) NOT NULL DEFAULT '0', \
473 knife_css_tag varchar(256) NOT NULL DEFAULT '', \
474 knife_css_seed int(10) NOT NULL DEFAULT '-1', \
475 knife_cord int(4) NOT NULL DEFAULT '0', \
476 knife_cord_float decimal(3,2) NOT NULL DEFAULT '0.0', \
477 knife_cord_trak int(1) NOT NULL DEFAULT '0', \
478 knife_cord_trak_count int(10) NOT NULL DEFAULT '0', \
479 knife_cord_tag varchar(256) NOT NULL DEFAULT '', ");
480 index += FormatEx(createQuery[index], sizeof(createQuery) - index, " \
481 knife_cord_seed int(10) NOT NULL DEFAULT '-1', \
482 knife_canis int(4) NOT NULL DEFAULT '0', \
483 knife_canis_float decimal(3,2) NOT NULL DEFAULT '0.0', \
484 knife_canis_trak int(1) NOT NULL DEFAULT '0', \
485 knife_canis_trak_count int(10) NOT NULL DEFAULT '0', \
486 knife_canis_tag varchar(256) NOT NULL DEFAULT '', \
487 knife_canis_seed int(10) NOT NULL DEFAULT '-1', \
488 knife_outdoor int(4) NOT NULL DEFAULT '0', \
489 knife_outdoor_float decimal(3,2) NOT NULL DEFAULT '0.0', \
490 knife_outdoor_trak int(1) NOT NULL DEFAULT '0', \
491 knife_outdoor_trak_count int(10) NOT NULL DEFAULT '0', \
492 knife_outdoor_tag varchar(256) NOT NULL DEFAULT '', \
493 knife_outdoor_seed int(10) NOT NULL DEFAULT '-1', \
494 knife_skeleton int(4) NOT NULL DEFAULT '0', \
495 knife_skeleton_float decimal(3,2) NOT NULL DEFAULT '0.0', \
496 knife_skeleton_trak int(1) NOT NULL DEFAULT '0', \
497 knife_skeleton_trak_count int(10) NOT NULL DEFAULT '0', \
498 knife_skeleton_tag varchar(256) NOT NULL DEFAULT '', \
499 knife_skeleton_seed int(10) NOT NULL DEFAULT '-1')");
500
501 if (mysql)
502 {
503 index += FormatEx(createQuery[index], sizeof(createQuery) - index, " ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;");
504 }
505
506 if (recreate)
507 {
508 db.Query(T_ReCreateMainTableCallback, createQuery, mysql, DBPrio_High);
509 }
510 else
511 {
512 db.Query(T_CreateMainTableCallback, createQuery, mysql, DBPrio_High);
513 }
514}
515
516public void T_ReCreateMainTableCallback(Database database, DBResultSet results, const char[] error, bool mysql)
517{
518 if (results == null)
519 {
520 LogError("%s Recreating the main table has failed! %s", (mysql ? "MySQL" : "SQLite"), error);
521 }
522 else
523 {
524 int index = 0;
525
526 char migrateQuery[8192];
527
528 index += FormatEx(migrateQuery[index], sizeof(migrateQuery) - index, " \
529 INSERT INTO %sweapons (steamid, knife, awp, awp_float, awp_trak, awp_trak_count, awp_tag, ak47, ak47_float, \
530 ak47_trak, ak47_trak_count, ak47_tag, m4a1, m4a1_float, m4a1_trak, m4a1_trak_count, m4a1_tag, m4a1_silencer, \
531 m4a1_silencer_float, m4a1_silencer_trak, m4a1_silencer_trak_count, m4a1_silencer_tag, deagle, deagle_float, \
532 deagle_trak, deagle_trak_count, deagle_tag, usp_silencer, usp_silencer_float, usp_silencer_trak, \
533 usp_silencer_trak_count, usp_silencer_tag, hkp2000, hkp2000_float, hkp2000_trak, hkp2000_trak_count, \
534 hkp2000_tag, glock, glock_float, glock_trak, glock_trak_count, glock_tag, elite, elite_float, elite_trak, ", g_TablePrefix);
535 index += FormatEx(migrateQuery[index], sizeof(migrateQuery) - index, " \
536 elite_trak_count, elite_tag, p250, p250_float, p250_trak, p250_trak_count, p250_tag, cz75a, cz75a_float, \
537 cz75a_trak, cz75a_trak_count, cz75a_tag, fiveseven, fiveseven_float, fiveseven_trak, fiveseven_trak_count, \
538 fiveseven_tag, tec9, tec9_float, tec9_trak, tec9_trak_count, tec9_tag, revolver, revolver_float, revolver_trak, \
539 revolver_trak_count, revolver_tag, nova, nova_float, nova_trak, nova_trak_count, nova_tag, xm1014, xm1014_float, \
540 xm1014_trak, xm1014_trak_count, xm1014_tag, mag7, mag7_float, mag7_trak, mag7_trak_count, mag7_tag, sawedoff, \
541 sawedoff_float, sawedoff_trak, sawedoff_trak_count, sawedoff_tag, m249, m249_float, m249_trak, m249_trak_count, \
542 m249_tag, negev, negev_float, negev_trak, negev_trak_count, negev_tag, mp9, mp9_float, mp9_trak, mp9_trak_count, ");
543 index += FormatEx(migrateQuery[index], sizeof(migrateQuery) - index, " \
544 mp9_tag, mac10, mac10_float, mac10_trak, mac10_trak_count, mac10_tag, mp7, mp7_float, mp7_trak, mp7_trak_count, \
545 mp7_tag, ump45, ump45_float, ump45_trak, ump45_trak_count, ump45_tag, p90, p90_float, p90_trak, p90_trak_count, \
546 p90_tag, bizon, bizon_float, bizon_trak, bizon_trak_count, bizon_tag, famas, famas_float, famas_trak, \
547 famas_trak_count, famas_tag, galilar, galilar_float, galilar_trak, galilar_trak_count, galilar_tag, ssg08, \
548 ssg08_float, ssg08_trak, ssg08_trak_count, ssg08_tag, aug, aug_float, aug_trak, aug_trak_count, aug_tag, sg556, \
549 sg556_float, sg556_trak, sg556_trak_count, sg556_tag, scar20, scar20_float, scar20_trak, scar20_trak_count, \
550 scar20_tag, g3sg1, g3sg1_float, g3sg1_trak, g3sg1_trak_count, g3sg1_tag, knife_karambit, knife_karambit_float, \
551 knife_karambit_trak, knife_karambit_trak_count, knife_karambit_tag, knife_m9_bayonet, knife_m9_bayonet_float, ");
552 index += FormatEx(migrateQuery[index], sizeof(migrateQuery) - index, " \
553 knife_m9_bayonet_trak, knife_m9_bayonet_trak_count, knife_m9_bayonet_tag, bayonet, bayonet_float, bayonet_trak, \
554 bayonet_trak_count, bayonet_tag, knife_survival_bowie, knife_survival_bowie_float, knife_survival_bowie_trak, \
555 knife_survival_bowie_trak_count, knife_survival_bowie_tag, knife_butterfly, knife_butterfly_float, knife_butterfly_trak, \
556 knife_butterfly_trak_count, knife_butterfly_tag, knife_flip, knife_flip_float, knife_flip_trak, knife_flip_trak_count, \
557 knife_flip_tag, knife_push, knife_push_float, knife_push_trak, knife_push_trak_count, knife_push_tag, knife_tactical, \
558 knife_tactical_float, knife_tactical_trak, knife_tactical_trak_count, knife_tactical_tag, knife_falchion, \
559 knife_falchion_float, knife_falchion_trak, knife_falchion_trak_count, knife_falchion_tag, knife_gut, knife_gut_float, ");
560 index += FormatEx(migrateQuery[index], sizeof(migrateQuery) - index, " \
561 knife_gut_trak, knife_gut_trak_count, knife_gut_tag, knife_ursus, knife_ursus_float, knife_ursus_trak, \
562 knife_ursus_trak_count, knife_ursus_tag, knife_gypsy_jackknife, knife_gypsy_jackknife_float, knife_gypsy_jackknife_trak, \
563 knife_gypsy_jackknife_trak_count, knife_gypsy_jackknife_tag, knife_stiletto, knife_stiletto_float, knife_stiletto_trak, \
564 knife_stiletto_trak_count, knife_stiletto_tag, knife_widowmaker, knife_widowmaker_float, knife_widowmaker_trak, \
565 knife_widowmaker_trak_count, knife_widowmaker_tag, mp5sd, mp5sd_float, mp5sd_trak, mp5sd_trak_count, mp5sd_tag, knife_css, \
566 knife_css_float, knife_css_trak, knife_css_trak_count, knife_css_tag, knife_css_seed) \
567 SELECT * FROM %sweapons_tmp", g_TablePrefix);
568
569 db.Query(T_MigrateOldDataCallback, migrateQuery, mysql, DBPrio_High);
570 }
571}
572
573public void T_MigrateOldDataCallback(Database database, DBResultSet results, const char[] error, bool mysql)
574{
575 if (results == null)
576 {
577 LogError("%s Migrating old data has failed! %s", (mysql ? "MySQL" : "SQLite"), error);
578 }
579 else
580 {
581 LogMessage("%s Old data has been migrated successfully", (mysql ? "MySQL" : "SQLite"));
582
583 char dropTableQuery[512];
584 Format(dropTableQuery, sizeof(dropTableQuery), "DROP TABLE %sweapons_tmp", g_TablePrefix);
585 db.Query(T_DropOldTableCallback, dropTableQuery, mysql, DBPrio_High);
586 }
587}
588
589public void T_DropOldTableCallback(Database database, DBResultSet results, const char[] error, bool mysql)
590{
591 if (results == null)
592 {
593 LogError("%s Dropping old table has failed! %s", (mysql ? "MySQL" : "SQLite"), error);
594 }
595 else
596 {
597 LogMessage("%s Old table has been dropped successfully", (mysql ? "MySQL" : "SQLite"));
598 if(++g_iDatabaseState > 1)
599 {
600 LogMessage("%s DB connection successful", (mysql ? "MySQL" : "SQLite"));
601 for(int i = 1; i <= MaxClients; i++)
602 {
603 if(IsClientInGame(i) && IsClientAuthorized(i))
604 {
605 OnClientPostAdminCheck(i);
606 }
607 }
608 DeleteInactivePlayerData();
609 }
610 }
611}
612
613public void T_CreateMainTableCallback(Database database, DBResultSet results, const char[] error, bool mysql)
614{
615 if (results == null)
616 {
617 LogError("%s Creating the main table has failed! %s", (mysql ? "MySQL" : "SQLite"), error);
618 }
619 else
620 {
621 g_iMigrationStep = 0;
622 AddWeaponColumns(mysql, "knife_ursus", false);
623
624 char createQuery[512];
625 Format(createQuery, sizeof(createQuery), " \
626 CREATE TABLE %sweapons_timestamps ( \
627 steamid varchar(32) NOT NULL PRIMARY KEY, \
628 last_seen int(11) NOT NULL)", g_TablePrefix);
629
630 if (mysql)
631 {
632 Format(createQuery, sizeof(createQuery), "%s ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;", createQuery);
633 }
634
635 db.Query(T_CreateTimestampTableCallback, createQuery, mysql, DBPrio_High);
636 }
637}
638
639void addSeedColumns(bool mysql)
640{
641 char seedCheckQuery[128];
642 FormatEx(seedCheckQuery, sizeof(seedCheckQuery), "SELECT awp_seed FROM %sweapons", g_TablePrefix);
643
644 db.Query(T_SeedColumnCallback, seedCheckQuery, mysql, DBPrio_High);
645}
646
647public void T_SeedColumnCallback(Database database, DBResultSet results, const char[] error, bool mysql)
648{
649 if (results == null)
650 {
651 LogMessage("%s Attempting to create seed columns", (mysql ? "MySQL" : "SQLite"));
652
653 char seedColumnsQuery[8192];
654
655 int index = 0;
656
657 if (mysql)
658 {
659 index += FormatEx(seedColumnsQuery[index], sizeof(seedColumnsQuery) - index, " \
660 ALTER TABLE %sweapons \
661 ADD COLUMN awp_seed int(10) NOT NULL DEFAULT '-1' AFTER awp_tag, \
662 ADD COLUMN ak47_seed int(10) NOT NULL DEFAULT '-1' AFTER ak47_tag, \
663 ADD COLUMN m4a1_seed int(10) NOT NULL DEFAULT '-1' AFTER m4a1_tag, \
664 ADD COLUMN m4a1_silencer_seed int(10) NOT NULL DEFAULT '-1' AFTER m4a1_silencer_tag, \
665 ADD COLUMN deagle_seed int(10) NOT NULL DEFAULT '-1' AFTER deagle_tag, \
666 ADD COLUMN usp_silencer_seed int(10) NOT NULL DEFAULT '-1' AFTER usp_silencer_tag, \
667 ADD COLUMN hkp2000_seed int(10) NOT NULL DEFAULT '-1' AFTER hkp2000_tag, \
668 ADD COLUMN glock_seed int(10) NOT NULL DEFAULT '-1' AFTER glock_tag, \
669 ADD COLUMN elite_seed int(10) NOT NULL DEFAULT '-1' AFTER elite_tag, \
670 ADD COLUMN p250_seed int(10) NOT NULL DEFAULT '-1' AFTER p250_tag, \
671 ADD COLUMN cz75a_seed int(10) NOT NULL DEFAULT '-1' AFTER cz75a_tag, \
672 ADD COLUMN fiveseven_seed int(10) NOT NULL DEFAULT '-1' AFTER fiveseven_tag, \
673 ADD COLUMN tec9_seed int(10) NOT NULL DEFAULT '-1' AFTER tec9_tag, \
674 ADD COLUMN revolver_seed int(10) NOT NULL DEFAULT '-1' AFTER revolver_tag, \
675 ADD COLUMN nova_seed int(10) NOT NULL DEFAULT '-1' AFTER nova_tag, \
676 ADD COLUMN xm1014_seed int(10) NOT NULL DEFAULT '-1' AFTER xm1014_tag, \
677 ADD COLUMN mag7_seed int(10) NOT NULL DEFAULT '-1' AFTER mag7_tag, \
678 ADD COLUMN sawedoff_seed int(10) NOT NULL DEFAULT '-1' AFTER sawedoff_tag, \
679 ADD COLUMN m249_seed int(10) NOT NULL DEFAULT '-1' AFTER m249_tag, \
680 ADD COLUMN negev_seed int(10) NOT NULL DEFAULT '-1' AFTER negev_tag, \
681 ADD COLUMN mp9_seed int(10) NOT NULL DEFAULT '-1' AFTER mp9_tag, ", g_TablePrefix);
682 index += FormatEx(seedColumnsQuery[index], sizeof(seedColumnsQuery) - index, " \
683 ADD COLUMN mac10_seed int(10) NOT NULL DEFAULT '-1' AFTER mac10_tag, \
684 ADD COLUMN mp7_seed int(10) NOT NULL DEFAULT '-1' AFTER mp7_tag, \
685 ADD COLUMN ump45_seed int(10) NOT NULL DEFAULT '-1' AFTER ump45_tag, \
686 ADD COLUMN p90_seed int(10) NOT NULL DEFAULT '-1' AFTER p90_tag, \
687 ADD COLUMN bizon_seed int(10) NOT NULL DEFAULT '-1' AFTER bizon_tag, \
688 ADD COLUMN famas_seed int(10) NOT NULL DEFAULT '-1' AFTER famas_tag, \
689 ADD COLUMN galilar_seed int(10) NOT NULL DEFAULT '-1' AFTER galilar_tag, \
690 ADD COLUMN ssg08_seed int(10) NOT NULL DEFAULT '-1' AFTER ssg08_tag, \
691 ADD COLUMN aug_seed int(10) NOT NULL DEFAULT '-1' AFTER aug_tag, \
692 ADD COLUMN sg556_seed int(10) NOT NULL DEFAULT '-1' AFTER sg556_tag, \
693 ADD COLUMN scar20_seed int(10) NOT NULL DEFAULT '-1' AFTER scar20_tag, \
694 ADD COLUMN g3sg1_seed int(10) NOT NULL DEFAULT '-1' AFTER g3sg1_tag, \
695 ADD COLUMN knife_karambit_seed int(10) NOT NULL DEFAULT '-1' AFTER knife_karambit_tag, \
696 ADD COLUMN knife_m9_bayonet_seed int(10) NOT NULL DEFAULT '-1' AFTER knife_m9_bayonet_tag, \
697 ADD COLUMN bayonet_seed int(10) NOT NULL DEFAULT '-1' AFTER bayonet_tag, \
698 ADD COLUMN knife_survival_bowie_seed int(10) NOT NULL DEFAULT '-1' AFTER knife_survival_bowie_tag, \
699 ADD COLUMN knife_butterfly_seed int(10) NOT NULL DEFAULT '-1' AFTER knife_butterfly_tag, \
700 ADD COLUMN knife_flip_seed int(10) NOT NULL DEFAULT '-1' AFTER knife_flip_tag, \
701 ADD COLUMN knife_push_seed int(10) NOT NULL DEFAULT '-1' AFTER knife_push_tag, \
702 ADD COLUMN knife_tactical_seed int(10) NOT NULL DEFAULT '-1' AFTER knife_tactical_tag, \
703 ADD COLUMN knife_falchion_seed int(10) NOT NULL DEFAULT '-1' AFTER knife_falchion_tag, \
704 ADD COLUMN knife_gut_seed int(10) NOT NULL DEFAULT '-1' AFTER knife_gut_tag, \
705 ADD COLUMN knife_ursus_seed int(10) NOT NULL DEFAULT '-1' AFTER knife_ursus_tag, \
706 ADD COLUMN knife_gypsy_jackknife_seed int(10) NOT NULL DEFAULT '-1' AFTER knife_gypsy_jackknife_tag, \
707 ADD COLUMN knife_stiletto_seed int(10) NOT NULL DEFAULT '-1' AFTER knife_stiletto_tag, \
708 ADD COLUMN knife_widowmaker_seed int(10) NOT NULL DEFAULT '-1' AFTER knife_widowmaker_tag, \
709 ADD COLUMN mp5sd_seed int(10) NOT NULL DEFAULT '-1' AFTER mp5sd_tag");
710
711 db.Query(T_SeedConfirmationCallback, seedColumnsQuery, mysql, DBPrio_High);
712 }
713 else
714 {
715 char renameQuery[512];
716 Format(renameQuery, sizeof(renameQuery), "ALTER TABLE %sweapons RENAME TO %sweapons_tmp", g_TablePrefix, g_TablePrefix);
717 db.Query(T_RenameCallback, renameQuery, mysql, DBPrio_High);
718 }
719 }
720 else
721 {
722 if(++g_iDatabaseState > 1)
723 {
724 LogMessage("%s DB connection successful", (mysql ? "MySQL" : "SQLite"));
725 for(int i = 1; i <= MaxClients; i++)
726 {
727 if(IsClientInGame(i) && IsClientAuthorized(i))
728 {
729 OnClientPostAdminCheck(i);
730 }
731 }
732 DeleteInactivePlayerData();
733 }
734 }
735}
736
737public void T_RenameCallback(Database database, DBResultSet results, const char[] error, bool mysql)
738{
739 if (results == null)
740 {
741 LogError("%s Renaming old table has failed! %s", (mysql ? "MySQL" : "SQLite"), error);
742 }
743 else
744 {
745 CreateMainTable(mysql, true);
746 }
747}
748
749public void T_SeedConfirmationCallback(Database database, DBResultSet results, const char[] error, bool mysql)
750{
751 if (results == null)
752 {
753 LogError("%s Seed column creation failed! %s", (mysql ? "MySQL" : "SQLite"), error);
754 }
755 else
756 {
757 LogMessage("Successfully created seed columns");
758 if(++g_iDatabaseState > 1)
759 {
760 LogMessage("%s DB connection successful", (mysql ? "MySQL" : "SQLite"));
761 for(int i = 1; i <= MaxClients; i++)
762 {
763 if(IsClientInGame(i) && IsClientAuthorized(i))
764 {
765 OnClientPostAdminCheck(i);
766 }
767 }
768 DeleteInactivePlayerData();
769 }
770 }
771}
772
773void AddWeaponColumns(bool mysql, const char[] weapon, bool seedColumn = true)
774{
775 Transaction txn = new Transaction();
776 char query[512];
777 Format(query, sizeof(query), "ALTER TABLE %sweapons ADD %s int(4) NOT NULL DEFAULT '0'", g_TablePrefix, weapon);
778 txn.AddQuery(query);
779 Format(query, sizeof(query), "ALTER TABLE %sweapons ADD %s_float decimal(3,2) NOT NULL DEFAULT '0.0'", g_TablePrefix, weapon);
780 txn.AddQuery(query);
781 Format(query, sizeof(query), "ALTER TABLE %sweapons ADD %s_trak int(1) NOT NULL DEFAULT '0'", g_TablePrefix, weapon);
782 txn.AddQuery(query);
783 Format(query, sizeof(query), "ALTER TABLE %sweapons ADD %s_trak_count int(10) NOT NULL DEFAULT '0'", g_TablePrefix, weapon);
784 txn.AddQuery(query);
785 Format(query, sizeof(query), "ALTER TABLE %sweapons ADD %s_tag varchar(256) NOT NULL DEFAULT ''", g_TablePrefix, weapon);
786 txn.AddQuery(query);
787 if (seedColumn)
788 {
789 Format(query, sizeof(query), "ALTER TABLE %sweapons ADD %s_seed int(10) NOT NULL DEFAULT '-1'", g_TablePrefix, weapon);
790 txn.AddQuery(query);
791 }
792 db.Execute(txn, Txn_OnSucess, Txn_OnFail, mysql);
793}
794
795public void Txn_OnSucess(Database database, bool mysql, int numQueries, DBResultSet[] results, any[] queryData)
796{
797 if(++g_iMigrationStep >= sizeof(g_MigrationWeapons))
798 {
799 addSeedColumns(mysql);
800 }
801 else
802 {
803 AddWeaponColumns(mysql, g_MigrationWeapons[g_iMigrationStep], g_iMigrationStep > 4);
804 }
805}
806
807public void Txn_OnFail(Database database, bool mysql, int numQueries, const char[] error, int failIndex, any[] queryData)
808{
809 if(++g_iMigrationStep >= sizeof(g_MigrationWeapons))
810 {
811 addSeedColumns(mysql);
812 }
813 else
814 {
815 AddWeaponColumns(mysql, g_MigrationWeapons[g_iMigrationStep], g_iMigrationStep > 4);
816 }
817}
818
819public void T_CreateTimestampTableCallback(Database database, DBResultSet results, const char[] error, bool mysql)
820{
821 if (results == null)
822 {
823 if(++g_iDatabaseState > 1)
824 {
825 LogMessage("%s DB connection successful", (mysql ? "MySQL" : "SQLite"));
826 for(int i = 1; i <= MaxClients; i++)
827 {
828 if(IsClientInGame(i) && IsClientAuthorized(i))
829 {
830 OnClientPostAdminCheck(i);
831 }
832 }
833 DeleteInactivePlayerData();
834 }
835 }
836 else
837 {
838 char insertQuery[512];
839 Format(insertQuery, sizeof(insertQuery), " \
840 INSERT INTO %sweapons_timestamps \
841 SELECT steamid, %d FROM %sweapons", g_TablePrefix, GetTime(), g_TablePrefix);
842
843 db.Query(T_InsertTimestampsCallback, insertQuery, mysql, DBPrio_High);
844 }
845}
846
847public void T_InsertTimestampsCallback(Database database, DBResultSet results, const char[] error, bool mysql)
848{
849 if (results == null)
850 {
851 LogError("%s Insert timestamps failed! %s", (mysql ? "MySQL" : "SQLite"), error);
852 }
853 else
854 {
855 if(++g_iDatabaseState > 1)
856 {
857 LogMessage("%s DB connection successful", (mysql ? "MySQL" : "SQLite"));
858 for(int i = 1; i <= MaxClients; i++)
859 {
860 if(IsClientInGame(i) && IsClientAuthorized(i))
861 {
862 OnClientPostAdminCheck(i);
863 }
864 }
865 DeleteInactivePlayerData();
866 }
867 }
868}
869
870void DeleteInactivePlayerData()
871{
872 if(g_iGraceInactiveDays > 0)
873 {
874 char query[255];
875 int now = GetTime();
876 FormatEx(query, sizeof(query), "DELETE FROM %sweapons WHERE steamid in (SELECT steamid FROM %sweapons_timestamps WHERE last_seen < %d - (%d * 86400))", g_TablePrefix, g_TablePrefix, now, g_iGraceInactiveDays);
877 DataPack pack = new DataPack();
878 pack.WriteCell(now);
879 pack.WriteString(query);
880 db.Query(T_DeleteInactivePlayerDataCallback, query, pack);
881 }
882}
883
884public void T_DeleteInactivePlayerDataCallback(Database database, DBResultSet results, const char[] error, DataPack pack)
885{
886 pack.Reset();
887 int now = pack.ReadCell();
888 if (results == null)
889 {
890 char buffer[1024];
891 pack.ReadString(buffer, 1024);
892 LogError("Delete Inactive Player Data failed! query: \"%s\" error: \"%s\"", buffer, error);
893 }
894 else
895 {
896 if(now > 0)
897 {
898 char query[255];
899 FormatEx(query, sizeof(query), "DELETE FROM %sweapons_timestamps WHERE last_seen < %d - (%d * 86400)", g_TablePrefix, now, g_iGraceInactiveDays);
900 DataPack newPack = new DataPack();
901 newPack.WriteCell(0);
902 newPack.WriteString(query);
903 db.Query(T_DeleteInactivePlayerDataCallback, query, newPack);
904 }
905 else
906 {
907 LogMessage("Inactive players' data has been deleted");
908 }
909 }
910 CloseHandle(pack);
911}