· 8 years ago · Jun 03, 2018, 02:36 PM
1#pragma semicolon 1
2
3#define DEBUG
4
5#define PLUGIN_AUTHOR "jenz"
6#define PLUGIN_VERSION "1.00"
7#define ZONE_PREFIX_RACE "ZONE_PREFIX_RACE"
8#define ZONE_PREFIX_SURF_S1 "ZONE_PREFIX_SURF_S1"
9#define ZONE_PREFIX_SURF_E1 "ZONE_PREFIX_SURF_E1"
10#define ZONE_PREFIX_SURF_S2 "ZONE_PREFIX_SURF_S2"
11#define ZONE_PREFIX_SURF_E2 "ZONE_PREFIX_SURF_E2"
12#define ZONE_PREFIX_SURF_S3 "ZONE_PREFIX_SURF_S3"
13#define ZONE_PREFIX_SURF_E3 "ZONE_PREFIX_SURF_E3"
14#define ZONE_PREFIX_SURF_S4 "ZONE_PREFIX_SURF_S4"
15#define ZONE_PREFIX_SURF_E4 "ZONE_PREFIX_SURF_E4"
16#define ZONE_PREFIX_SURF_S5 "ZONE_PREFIX_SURF_S5"
17#define ZONE_PREFIX_SURF_E5 "ZONE_PREFIX_SURF_E5"
18
19#include <sourcemod>
20#include <sdktools>
21#include <sdkhooks>
22#include <devzones>
23#include <colorvariables>
24
25
26//Global variables
27bool b_message[MAXPLAYERS];
28bool b_roundend;
29float playertimes[MAXPLAYERS];
30float engineRoundtime;
31float engineSeconds;
32int engine_minutes;
33char mapname[512];
34
35//surf stages i guess
36float engineRoundtimeS1[MAXPLAYERS];
37float engineSecondsS1[MAXPLAYERS];
38int engine_minutesS1[MAXPLAYERS];
39
40//stage verification autism
41int b_currentS1[MAXPLAYERS];
42int b_currentS2[MAXPLAYERS];
43int b_currentS3[MAXPLAYERS];
44int b_currentS4[MAXPLAYERS];
45int b_currentS5[MAXPLAYERS];
46bool b_Smap;
47bool b_Rmap;
48
49public Plugin myinfo =
50{
51 name = "Unloze Map Timer",
52 author = PLUGIN_AUTHOR,
53 description = "Timers for Race Maps",
54 version = PLUGIN_VERSION,
55 url = ""
56};
57
58public void OnPluginStart()
59{
60 SQL_StartConnection();
61 RegConsoleCmd("sm_toptime", cmd_timerCheck, "checking");
62 RegConsoleCmd("sm_time", cmd_timerCheckself, "checking own");
63
64 RegConsoleCmd("sm_s1", cmd_timerCheckS1, "checking");
65 RegConsoleCmd("sm_s2", cmd_timerCheckS2, "checking 2");
66 RegConsoleCmd("sm_s2", cmd_timerCheckselfS2self, "checking own 2");
67 RegConsoleCmd("sm_s3", cmd_timerCheckS3, "checking 3");
68 RegConsoleCmd("sm_s3", cmd_timerCheckselfS3self, "checking own 3");
69 RegConsoleCmd("sm_s4", cmd_timerCheckS4, "checking 4");
70 RegConsoleCmd("sm_s4", cmd_timerCheckselfS4self, "checking own 4");
71 RegConsoleCmd("sm_s5", cmd_timerCheckS5, "checking 5");
72 RegConsoleCmd("sm_s5", cmd_timerCheckselfS5self, "checking own 5");
73 HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
74 HookEvent("round_end", Event_RoundEnd);
75}
76
77public void OnMapStart()
78{
79 GetCurrentMap(mapname, sizeof(mapname));
80 b_Smap = false;
81 b_Rmap = false;
82}
83
84public void SQL_SelectTop_Callback(Database db, DBResultSet results, const char[] error, any data)
85{
86 Menu menu = new Menu(MenuHandler1);
87 menu.SetTitle("Maptimer: %s", mapname);
88
89 if (results == null)
90 {
91 LogError("[SS] Selecting players error. Reason: %s", error);
92 return;
93 }
94
95 int client = GetClientFromSerial(data);
96 if (client == 0)
97 {
98 LogError("[SS] Client is not valid. Reason: %s", error);
99 return;
100 }
101
102 int iS_Count = 0;
103 char gS_MenuContent[524];
104
105 while (results.FetchRow())
106 {
107 float oldTime = 0.0;
108 int engine_cMin = 0;
109 float engine_cSec = 0.0;
110 iS_Count++;
111
112 //Player Name
113 char[] gS_PlayerName = new char[MAX_NAME_LENGTH];
114 results.FetchString(0, gS_PlayerName, MAX_NAME_LENGTH);
115 oldTime = results.FetchFloat(1);
116 engine_cMin = RoundToFloor(oldTime / 60);
117 engine_cSec = oldTime - (engine_cMin * 60);
118
119 Format(gS_MenuContent, sizeof(gS_MenuContent), "%i:%f - %s", engine_cMin, engine_cSec, gS_PlayerName);
120
121 menu.AddItem("-1", gS_MenuContent, ITEMDRAW_DISABLED);
122 }
123
124 if (!iS_Count)
125 {
126 menu.AddItem("-1", "No results.", ITEMDRAW_DISABLED);
127 }
128
129 //menu.AddItem("no", "No", ITEMDRAW_DISABLED);
130 menu.ExitButton = true;
131 menu.Display(client, 20);
132
133}
134
135public Action cmd_timerCheck(int client, int args)
136{
137 if (b_Rmap == false)
138 {
139 CPrintToChat(client, "Not race map");
140 return Plugin_Handled;
141 }
142 Database db;
143 char sQuery[512];
144 char error[255];
145
146 if (SQL_CheckConfig("zetimer"))
147 {
148 db = SQL_Connect("zetimer", true, error, sizeof(error));
149 }
150 if (db == null)
151 {
152 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
153 delete db;
154 }
155
156 Format(sQuery, sizeof(sQuery), "SELECT name, %s FROM `zetimer_table` WHERE %s > 0.000 ORDER BY %s ASC LIMIT 10", mapname, mapname, mapname);
157 db.Query(SQL_SelectTop_Callback, sQuery, GetClientSerial(client), DBPrio_Normal);
158
159 delete db;
160 return Plugin_Handled;
161}
162
163
164public Action cmd_timerCheckself(int client, int args)
165{
166 if (b_Rmap == false)
167 {
168 CPrintToChat(client, "Not race map");
169 return Plugin_Handled;
170 }
171 Database db;
172 char sQuery[512];
173 char error[255];
174
175 if (SQL_CheckConfig("zetimer"))
176 {
177 db = SQL_Connect("zetimer", true, error, sizeof(error));
178 }
179 if (db == null)
180 {
181 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
182 delete db;
183 return Plugin_Handled;
184 }
185
186 char sSID[64];
187 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
188
189 Format(sQuery, sizeof(sQuery), "SELECT name, %s FROM `zetimer_table` WHERE steam_auth = '%s'", mapname, sSID);
190 DBResultSet rs;
191
192 if ((rs = SQL_Query(db, sQuery)) == null)
193 {
194 delete db;
195 delete rs;
196 return Plugin_Handled;
197 }
198
199 char gS_MessageContent[524];
200 if (rs.FetchRow())
201 {
202 float oldTime = 0.0;
203 int engine_cMin = 0;
204 float engine_cSec = 0.0;
205
206 //Player Name
207 char[] gS_PlayerName = new char[MAX_NAME_LENGTH];
208 rs.FetchString(0, gS_PlayerName, MAX_NAME_LENGTH);
209 oldTime = rs.FetchFloat(1);
210 engine_cMin = RoundToFloor(oldTime / 60);
211 engine_cSec = oldTime - (engine_cMin * 60);
212
213 Format(gS_MessageContent, sizeof(gS_MessageContent), "%i:%f - %s", engine_cMin, engine_cSec, gS_PlayerName);
214 CPrintToChat(client, "Your best time: %s", gS_MessageContent);
215 }
216
217 delete db;
218 delete rs;
219 return Plugin_Handled;
220}
221
222
223public Action cmd_timerCheckS1(int client, int args)
224{
225 if (b_Smap == false)
226 {
227 CPrintToChat(client, "Not surf map");
228 return Plugin_Handled;
229 }
230
231 Database db;
232 char sQuery[512];
233 char error[255];
234
235 if (SQL_CheckConfig("zetimer"))
236 {
237 db = SQL_Connect("zetimer", true, error, sizeof(error));
238 }
239 if (db == null)
240 {
241 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
242 delete db;
243 }
244
245 Format(sQuery, sizeof(sQuery), "SELECT name, `%sS1` FROM `zetimer_tableSurf` WHERE `%sS1` > 0.000 ORDER BY `%sS1` ASC LIMIT 10", mapname, mapname, mapname);
246 db.Query(SQL_SelectTop_Callback, sQuery, GetClientSerial(client), DBPrio_Normal);
247 CPrintToChatAll("!S1 sQuery: %s",sQuery);
248
249 char sSID[64];
250 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
251 Format(sQuery, sizeof(sQuery), "SELECT name, `%sS1` FROM `zetimer_tableSurf` WHERE steam_auth = '%s'", mapname, sSID);
252 DBResultSet rs;
253 CPrintToChatAll("!S1 sQuery name: %s",sQuery);
254
255 if ((rs = SQL_Query(db, sQuery)) == null)
256 {
257 delete db;
258 delete rs;
259 return Plugin_Handled;
260 }
261
262 char gS_MessageContent[524];
263 if (rs.FetchRow())
264 {
265 float oldTime = 0.0;
266 int engine_cMin = 0;
267 float engine_cSec = 0.0;
268
269 //Player Name
270 char[] gS_PlayerName = new char[MAX_NAME_LENGTH];
271 rs.FetchString(0, gS_PlayerName, MAX_NAME_LENGTH);
272 oldTime = rs.FetchFloat(1);
273 engine_cMin = RoundToFloor(oldTime / 60);
274 engine_cSec = oldTime - (engine_cMin * 60);
275
276 Format(gS_MessageContent, sizeof(gS_MessageContent), "%i:%f - %s", engine_cMin, engine_cSec, gS_PlayerName);
277 CPrintToChat(client, "Your best time: %s", gS_MessageContent);
278 }
279 delete db;
280 delete rs;
281 return Plugin_Handled;
282}
283
284public Action cmd_timerCheckS2(int client, int args)
285{
286 Database db;
287 char sQuery[512];
288 char error[255];
289
290 if (SQL_CheckConfig("zetimer"))
291 {
292 db = SQL_Connect("zetimer", true, error, sizeof(error));
293 }
294 if (db == null)
295 {
296 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
297 delete db;
298 }
299
300 Format(sQuery, sizeof(sQuery), "SELECT name, `%sS2` FROM `zetimer_tableSurf` WHERE `%sS2` > 0.000 ORDER BY `%sS2` ASC LIMIT 10", mapname, mapname, mapname);
301 db.Query(SQL_SelectTop_Callback, sQuery, GetClientSerial(client), DBPrio_Normal);
302 delete db;
303 return Plugin_Handled;
304}
305
306public Action cmd_timerCheckS3(int client, int args)
307{
308 Database db;
309 char sQuery[512];
310 char error[255];
311
312 if (SQL_CheckConfig("zetimer"))
313 {
314 db = SQL_Connect("zetimer", true, error, sizeof(error));
315 }
316 if (db == null)
317 {
318 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
319 delete db;
320 }
321
322 Format(sQuery, sizeof(sQuery), "SELECT name, `%sS3` FROM `zetimer_tableSurf` WHERE `%sS3` > 0.000 ORDER BY `%sS3` ASC LIMIT 10", mapname, mapname, mapname);
323 db.Query(SQL_SelectTop_Callback, sQuery, GetClientSerial(client), DBPrio_Normal);
324 delete db;
325 return Plugin_Handled;
326}
327
328public Action cmd_timerCheckS4(int client, int args)
329{
330 Database db;
331 char sQuery[512];
332 char error[255];
333
334 if (SQL_CheckConfig("zetimer"))
335 {
336 db = SQL_Connect("zetimer", true, error, sizeof(error));
337 }
338 if (db == null)
339 {
340 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
341 delete db;
342 }
343
344 Format(sQuery, sizeof(sQuery), "SELECT name, `%sS4` FROM `zetimer_tableSurf` WHERE `%sS4` > 0.000 ORDER BY `%sS4` ASC LIMIT 10", mapname, mapname, mapname);
345 db.Query(SQL_SelectTop_Callback, sQuery, GetClientSerial(client), DBPrio_Normal);
346 delete db;
347 return Plugin_Handled;
348}
349
350
351public Action cmd_timerCheckS5(int client, int args)
352{
353 Database db;
354 char sQuery[512];
355 char error[255];
356
357 if (SQL_CheckConfig("zetimer"))
358 {
359 db = SQL_Connect("zetimer", true, error, sizeof(error));
360 }
361 if (db == null)
362 {
363 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
364 delete db;
365 }
366
367 Format(sQuery, sizeof(sQuery), "SELECT name, `%sS5` FROM `zetimer_tableSurf` WHERE `%sS5` > 0.000 ORDER BY `%sS5` ASC LIMIT 10", mapname, mapname, mapname);
368 db.Query(SQL_SelectTop_Callback, sQuery, GetClientSerial(client), DBPrio_Normal);
369 delete db;
370 return Plugin_Handled;
371}
372
373public Action cmd_timerCheckselfS2self(int client, int args)
374{
375 Database db;
376 char sQuery[512];
377 char error[255];
378
379 if (SQL_CheckConfig("zetimer"))
380 {
381 db = SQL_Connect("zetimer", true, error, sizeof(error));
382 }
383 if (db == null)
384 {
385 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
386 delete db;
387 return Plugin_Handled;
388 }
389
390 char sSID[64];
391 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
392 Format(sQuery, sizeof(sQuery), "SELECT name, `%sS2` FROM `zetimer_tableSurf` WHERE steam_auth = '%s'", mapname, sSID);
393 DBResultSet rs;
394
395 if ((rs = SQL_Query(db, sQuery)) == null)
396 {
397 delete db;
398 delete rs;
399 return Plugin_Handled;
400 }
401
402 char gS_MessageContent[524];
403 if (rs.FetchRow())
404 {
405 float oldTime = 0.0;
406 int engine_cMin = 0;
407 float engine_cSec = 0.0;
408
409 //Player Name
410 char[] gS_PlayerName = new char[MAX_NAME_LENGTH];
411 rs.FetchString(0, gS_PlayerName, MAX_NAME_LENGTH);
412 oldTime = rs.FetchFloat(1);
413 engine_cMin = RoundToFloor(oldTime / 60);
414 engine_cSec = oldTime - (engine_cMin * 60);
415
416 Format(gS_MessageContent, sizeof(gS_MessageContent), "%i:%f - %s", engine_cMin, engine_cSec, gS_PlayerName);
417 CPrintToChat(client, "Your best time: %s", gS_MessageContent);
418 }
419
420 delete db;
421 delete rs;
422 return Plugin_Handled;
423}
424
425
426public Action cmd_timerCheckselfS3self(int client, int args)
427{
428 Database db;
429 char sQuery[512];
430 char error[255];
431
432 if (SQL_CheckConfig("zetimer"))
433 {
434 db = SQL_Connect("zetimer", true, error, sizeof(error));
435 }
436 if (db == null)
437 {
438 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
439 delete db;
440 return Plugin_Handled;
441 }
442
443 char sSID[64];
444 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
445 Format(sQuery, sizeof(sQuery), "SELECT name, `%sS3` FROM `zetimer_tableSurf` WHERE steam_auth = '%s'", mapname, sSID);
446 DBResultSet rs;
447
448 if ((rs = SQL_Query(db, sQuery)) == null)
449 {
450 delete db;
451 delete rs;
452 return Plugin_Handled;
453 }
454
455 char gS_MessageContent[524];
456 if (rs.FetchRow())
457 {
458 float oldTime = 0.0;
459 int engine_cMin = 0;
460 float engine_cSec = 0.0;
461
462 //Player Name
463 char[] gS_PlayerName = new char[MAX_NAME_LENGTH];
464 rs.FetchString(0, gS_PlayerName, MAX_NAME_LENGTH);
465 oldTime = rs.FetchFloat(1);
466 engine_cMin = RoundToFloor(oldTime / 60);
467 engine_cSec = oldTime - (engine_cMin * 60);
468
469 Format(gS_MessageContent, sizeof(gS_MessageContent), "%i:%f - %s", engine_cMin, engine_cSec, gS_PlayerName);
470 CPrintToChat(client, "Your best time: %s", gS_MessageContent);
471 }
472
473 delete db;
474 delete rs;
475 return Plugin_Handled;
476}
477
478
479public Action cmd_timerCheckselfS4self(int client, int args)
480{
481 Database db;
482 char sQuery[512];
483 char error[255];
484
485 if (SQL_CheckConfig("zetimer"))
486 {
487 db = SQL_Connect("zetimer", true, error, sizeof(error));
488 }
489 if (db == null)
490 {
491 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
492 delete db;
493 return Plugin_Handled;
494 }
495
496 char sSID[64];
497 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
498 Format(sQuery, sizeof(sQuery), "SELECT name, `%sS4` FROM `zetimer_tableSurf` WHERE steam_auth = '%s'", mapname, sSID);
499 DBResultSet rs;
500
501 if ((rs = SQL_Query(db, sQuery)) == null)
502 {
503 delete db;
504 delete rs;
505 return Plugin_Handled;
506 }
507
508 char gS_MessageContent[524];
509 if (rs.FetchRow())
510 {
511 float oldTime = 0.0;
512 int engine_cMin = 0;
513 float engine_cSec = 0.0;
514
515 //Player Name
516 char[] gS_PlayerName = new char[MAX_NAME_LENGTH];
517 rs.FetchString(0, gS_PlayerName, MAX_NAME_LENGTH);
518 oldTime = rs.FetchFloat(1);
519 engine_cMin = RoundToFloor(oldTime / 60);
520 engine_cSec = oldTime - (engine_cMin * 60);
521
522 Format(gS_MessageContent, sizeof(gS_MessageContent), "%i:%f - %s", engine_cMin, engine_cSec, gS_PlayerName);
523 CPrintToChat(client, "Your best time: %s", gS_MessageContent);
524 }
525
526 delete db;
527 delete rs;
528 return Plugin_Handled;
529}
530
531
532public Action cmd_timerCheckselfS5self(int client, int args)
533{
534 Database db;
535 char sQuery[512];
536 char error[255];
537
538 if (SQL_CheckConfig("zetimer"))
539 {
540 db = SQL_Connect("zetimer", true, error, sizeof(error));
541 }
542 if (db == null)
543 {
544 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
545 delete db;
546 return Plugin_Handled;
547 }
548
549 char sSID[64];
550 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
551 Format(sQuery, sizeof(sQuery), "SELECT name, `%sS5` FROM `zetimer_tableSurf` WHERE steam_auth = '%s'", mapname, sSID);
552 DBResultSet rs;
553
554 if ((rs = SQL_Query(db, sQuery)) == null)
555 {
556 delete db;
557 delete rs;
558 return Plugin_Handled;
559 }
560
561 char gS_MessageContent[524];
562 if (rs.FetchRow())
563 {
564 float oldTime = 0.0;
565 int engine_cMin = 0;
566 float engine_cSec = 0.0;
567
568 //Player Name
569 char[] gS_PlayerName = new char[MAX_NAME_LENGTH];
570 rs.FetchString(0, gS_PlayerName, MAX_NAME_LENGTH);
571 oldTime = rs.FetchFloat(1);
572 engine_cMin = RoundToFloor(oldTime / 60);
573 engine_cSec = oldTime - (engine_cMin * 60);
574
575 Format(gS_MessageContent, sizeof(gS_MessageContent), "%i:%f - %s", engine_cMin, engine_cSec, gS_PlayerName);
576 CPrintToChat(client, "Your best time: %s", gS_MessageContent);
577 }
578
579 delete db;
580 delete rs;
581 return Plugin_Handled;
582}
583
584public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2)
585{
586
587 /* If the menu was cancelled, print a message to the server about it. */
588 if (action == MenuAction_Cancel)
589 {
590 PrintToServer("Client %d's menu was cancelled. Reason: %d", param1, param2);
591 }
592 /* If the menu has ended, destroy it */
593 else if (action == MenuAction_End)
594 {
595 delete menu;
596 }
597}
598
599//hooked roundstart
600public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
601{
602 for (int i = 1; i < MaxClients; i++)
603 {
604 if(IsValidClient(i))
605 {
606 playertimes[i] = 0.0;
607 b_message[i] = false;
608 engineRoundtimeS1[i] = 0.0;
609 engineSecondsS1[i] = 0.0;
610 engine_minutesS1[i] = 0;
611
612 b_currentS1[i] = -1;
613 b_currentS2[i] = -1;
614 b_currentS3[i] = -1;
615 b_currentS4[i] = -1;
616 b_currentS5[i] = -1;
617 }
618 }
619
620 engineRoundtime = 0.0;
621 engine_minutes = 0;
622 engineSeconds = 0.0;
623 CreateTimer(0.1, Timer_Countdown, _, TIMER_REPEAT);
624 //TIMER_FLAG_NO_MAPCHANGE
625 b_roundend = false;
626}
627
628public void Event_RoundEnd(Handle event, const char[] name, bool dontBroadcast)
629{
630 b_roundend = true;
631}
632
633//Callback for timer
634public Action Timer_Countdown(Handle timer, any data)
635{
636 if (b_roundend)
637 {
638 return Plugin_Stop;
639 }
640 engineRoundtime += 0.1;
641 engineSeconds += 0.1;
642 if (engineSeconds >= 60.0)
643 {
644 engine_minutes += 1;
645 engineSeconds = 0.0;
646 }
647
648
649 return Plugin_Changed;
650}
651
652//devzones stock
653public Zone_OnClientLeave(client, const char [] zone)
654{
655 if (client < 1 || client > MaxClients || !IsClientInGame(client) ||!IsPlayerAlive(client))
656 {
657 return;
658 }
659
660 if (GetClientTeam(client) != 3)
661 {
662 return;
663 }
664
665 engineRoundtimeS1[client] = 0.0;
666 engineSecondsS1[client] = 0.0;
667 engine_minutesS1[client] = 0;
668
669
670 if((StrContains(zone, ZONE_PREFIX_SURF_S1, false)== 0) && GetClientTeam(client) == 3)
671 {
672 b_currentS1[client] = 0;
673 b_currentS2[client] = 0;
674 b_currentS3[client] = 0;
675 b_currentS4[client] = 0;
676 b_currentS5[client] = 0;
677 CreateTimer(0.1, Timer_CountdownS1, client, TIMER_REPEAT);
678 }
679
680 if((StrContains(zone, ZONE_PREFIX_SURF_S2, false)== 0) && GetClientTeam(client) == 3)
681 {
682 b_currentS1[client] = 0;
683 b_currentS2[client] = 0;
684 b_currentS3[client] = 0;
685 b_currentS4[client] = 0;
686 b_currentS5[client] = 0;
687 CreateTimer(0.1, Timer_CountdownS1, client, TIMER_REPEAT);
688 }
689
690 if((StrContains(zone, ZONE_PREFIX_SURF_S3, false)== 0) && GetClientTeam(client) == 3)
691 {
692 b_currentS1[client] = 0;
693 b_currentS2[client] = 0;
694 b_currentS3[client] = 0;
695 b_currentS4[client] = 0;
696 b_currentS5[client] = 0;
697 CreateTimer(0.1, Timer_CountdownS1, client, TIMER_REPEAT);
698 }
699
700 if((StrContains(zone, ZONE_PREFIX_SURF_S4, false)== 0) && GetClientTeam(client) == 3)
701 {
702 b_currentS1[client] = 0;
703 b_currentS2[client] = 0;
704 b_currentS3[client] = 0;
705 b_currentS4[client] = 0;
706 b_currentS5[client] = 0;
707 CreateTimer(0.1, Timer_CountdownS1, client, TIMER_REPEAT);
708 }
709 if((StrContains(zone, ZONE_PREFIX_SURF_S5, false)== 0) && GetClientTeam(client) == 3)
710 {
711 b_currentS1[client] = 0;
712 b_currentS2[client] = 0;
713 b_currentS3[client] = 0;
714 b_currentS4[client] = 0;
715 b_currentS5[client] = 0;
716 CreateTimer(0.1, Timer_CountdownS1, client, TIMER_REPEAT);
717 }
718}
719public Zone_OnClientEntry(int client, const char[] zone)
720{
721 float oldTime[MAXPLAYERS];
722 if (client < 1 || client > MaxClients || !IsClientInGame(client) ||!IsPlayerAlive(client))
723 {
724 return;
725 }
726 if (GetClientTeam(client) != 3)
727 {
728 return;
729 }
730
731 if ((StrContains(zone, ZONE_PREFIX_SURF_S1, false) == 0) && GetClientTeam(client) == 3)
732 {
733 b_Smap = true;
734 b_currentS1[client] = -1;
735 }
736 if ((StrContains(zone, ZONE_PREFIX_SURF_S2, false) == 0) && GetClientTeam(client) == 3)
737 {
738 b_Smap = true;
739 b_currentS2[client] = -1;
740 }
741 if ((StrContains(zone, ZONE_PREFIX_SURF_S3, false) == 0) && GetClientTeam(client) == 3)
742 {
743 b_Smap = true;
744 b_currentS3[client] = -1;
745 }
746 if ((StrContains(zone, ZONE_PREFIX_SURF_S4, false) == 0) && GetClientTeam(client) == 3)
747 {
748 b_Smap = true;
749 b_currentS4[client] = -1;
750 }
751 if ((StrContains(zone, ZONE_PREFIX_SURF_S5, false) == 0) && GetClientTeam(client) == 3)
752 {
753 b_Smap = true;
754 b_currentS5[client] = -1;
755 }
756
757 if (b_currentS1[client] == -1 || b_currentS2[client] == -1 || b_currentS3[client] == -1 || b_currentS4[client] == -1 || b_currentS5[client] == -1)
758 {
759 return;
760 }
761
762 if((StrContains(zone, ZONE_PREFIX_SURF_E1, false) == 0) && GetClientTeam(client) == 3)
763 {
764 b_Smap = true;
765 b_currentS1[client] = -1;
766 playertimes[client] = engineRoundtimeS1[client];
767 oldTime[client] = receiveMYSQLSurf(client, playertimes[client]);
768
769 //CPrintToChatAll("zone is ZONE_PREFIX_SURF_E1");
770 CPrintToChat(client, "{green}[Unloze] Client: %N \nTime: %i:%f", client, engine_minutesS1[client], engineSecondsS1[client]);
771 int engine_cMinS1 = 0;
772 float engine_cSecS1 = 0.0;
773 engine_cMinS1 = RoundToFloor(oldTime[client] / 60);
774 engine_cSecS1 = oldTime[client] - (engine_cMinS1 * 60);
775 CPrintToChat(client, "Your record Stage 1: 0%i:%f", engine_cMinS1, engine_cSecS1);
776
777
778 if (playertimes[client] < oldTime[client] || oldTime[client] == -1.000000 || oldTime[client] == 0.000000)
779 {
780 sendMYSQLSurf(client, playertimes[client]);
781 CPrintToChat(client, "Updated timer");
782 }
783
784 return;
785 }
786
787 if((StrContains(zone, ZONE_PREFIX_SURF_E2, false)== 0) && GetClientTeam(client) == 3)
788 {
789 b_Smap = true;
790 b_currentS2[client] = -1;
791 playertimes[client] = engineRoundtimeS1[client];
792 oldTime[client] = receiveMYSQLSurfS2(client, playertimes[client]);
793
794 //CPrintToChatAll("zone is ZONE_PREFIX_SURF_E2");
795 CPrintToChat(client, "{green}[Unloze] Client: %N \nTime: %i:%f", client, engine_minutesS1[client], engineSecondsS1[client]);
796 int engine_cMinS1 = 0;
797 float engine_cSecS1 = 0.0;
798 engine_cMinS1 = RoundToFloor(oldTime[client] / 60);
799 engine_cSecS1 = oldTime[client] - (engine_cMinS1 * 60);
800 CPrintToChat(client, "Your record Stage 2: 0%i:%f", engine_cMinS1, engine_cSecS1);
801
802
803 if (playertimes[client] < oldTime[client] || oldTime[client] == -1.000000 || oldTime[client] == 0.000000)
804 {
805 sendMYSQLSurfS2(client, playertimes[client]);
806 CPrintToChat(client, "Updated timer");
807 }
808
809 return;
810 }
811
812 if((StrContains(zone, ZONE_PREFIX_SURF_E3, false) == 0) && GetClientTeam(client) == 3)
813 {
814 b_Smap = true;
815 b_currentS3[client] = -1;
816 playertimes[client] = engineRoundtimeS1[client];
817 oldTime[client] = receiveMYSQLSurfS3(client, playertimes[client]);
818
819 //CPrintToChatAll("zone is ZONE_PREFIX_SURF_E3");
820 CPrintToChat(client, "{green}[Unloze] Client: %N \nTime: %i:%f", client, engine_minutesS1[client], engineSecondsS1[client]);
821 int engine_cMinS1 = 0;
822 float engine_cSecS1 = 0.0;
823 engine_cMinS1 = RoundToFloor(oldTime[client] / 60);
824 engine_cSecS1 = oldTime[client] - (engine_cMinS1 * 60);
825 CPrintToChat(client, "Your record Stage 3: 0%i:%f", engine_cMinS1, engine_cSecS1);
826
827
828 if (playertimes[client] < oldTime[client] || oldTime[client] == -1.000000 || oldTime[client] == 0.000000)
829 {
830 sendMYSQLSurfS3(client, playertimes[client]);
831 CPrintToChat(client, "Updated timer");
832 }
833
834 return;
835 }
836
837 if((StrContains(zone, ZONE_PREFIX_SURF_E4, false) == 0) || GetClientTeam(client) != 3)
838 {
839 b_Smap = true;
840 b_currentS4[client] = -1;
841 playertimes[client] = engineRoundtimeS1[client];
842 oldTime[client] = receiveMYSQLSurfS4(client, playertimes[client]);
843
844 //CPrintToChatAll("zone is ZONE_PREFIX_SURF_E4");
845 CPrintToChat(client, "{green}[Unloze] Client: %N \nTime: %i:%f", client, engine_minutesS1[client], engineSecondsS1[client]);
846 int engine_cMinS1 = 0;
847 float engine_cSecS1 = 0.0;
848 engine_cMinS1 = RoundToFloor(oldTime[client] / 60);
849 engine_cSecS1 = oldTime[client] - (engine_cMinS1 * 60);
850 CPrintToChat(client, "Your record Stage 4: 0%i:%f", engine_cMinS1, engine_cSecS1);
851
852
853 if (playertimes[client] < oldTime[client] || oldTime[client] == -1.000000 || oldTime[client] == 0.000000)
854 {
855 sendMYSQLSurfS4(client, playertimes[client]);
856 CPrintToChat(client, "Updated timer");
857 }
858
859 return;
860 }
861
862 if((StrContains(zone, ZONE_PREFIX_SURF_E5, false) == 0) || GetClientTeam(client) != 3)
863 {
864 b_Smap = true;
865 b_currentS5[client] = -1;
866 playertimes[client] = engineRoundtimeS1[client];
867 oldTime[client] = receiveMYSQLSurfS5(client, playertimes[client]);
868
869 //CPrintToChatAll("zone is ZONE_PREFIX_SURF_E5");
870 CPrintToChat(client, "{green}[Unloze] Client: %N \nTime: %i:%f", client, engine_minutesS1[client], engineSecondsS1[client]);
871 int engine_cMinS1 = 0;
872 float engine_cSecS1 = 0.0;
873 engine_cMinS1 = RoundToFloor(oldTime[client] / 60);
874 engine_cSecS1 = oldTime[client] - (engine_cMinS1 * 60);
875 CPrintToChat(client, "Your record Stage 5: 0%i:%f", engine_cMinS1, engine_cSecS1);
876
877
878 if (playertimes[client] < oldTime[client] || oldTime[client] == -1.000000 || oldTime[client] == 0.000000)
879 {
880 sendMYSQLSurfS5(client, playertimes[client]);
881 CPrintToChat(client, "Updated timer");
882 }
883
884 return;
885 }
886
887
888
889
890 //everything below here is only for ZONE_PREFIX_RACE
891
892 if(!(StrContains(zone, ZONE_PREFIX_RACE, false)== 0) || GetClientTeam(client) != 3)
893 {
894 return;
895 }
896
897 b_Rmap = true;
898
899 playertimes[client] = engineRoundtime;
900
901 if (b_message[client] == true)
902 {
903 return;
904 }
905
906 CPrintToChat(client, "{green}[Unloze] Client: %N \nTime: %i:%f", client, engine_minutes, engineSeconds);
907
908
909 oldTime[client] = receiveMYSQL(client, playertimes[client]);
910
911 if(oldTime[client] != -1.000000 && oldTime[client] != 0.000000)
912 {
913 int engine_cMin = 0;
914 float engine_cSec = 0.0;
915 engine_cMin = RoundToFloor(oldTime[client] / 60);
916 engine_cSec = oldTime[client] - (engine_cMin * 60);
917 CPrintToChat(client, "Your record: 0%i:%f", engine_cMin, engine_cSec);
918 }
919
920 if (playertimes[client] < oldTime[client] || oldTime[client] == -1.000000 || oldTime[client] == 0.000000)
921 {
922 sendMYSQL(client, playertimes[client]);
923 CPrintToChat(client, "Updated timer");
924 }
925
926 b_message[client] = true;
927}
928
929public Action Timer_CountdownS1(Handle timer, int client)
930{
931 if (b_currentS1[client] == -1 || b_currentS2[client] == -1 || b_currentS3[client] == -1|| b_currentS4[client] == -1 || b_currentS5[client] == -1)
932 {
933 return Plugin_Stop;
934 }
935
936 engineRoundtimeS1[client] += 0.1;
937 engineSecondsS1[client] += 0.1;
938 if (engineSecondsS1[client] >= 60.0)
939 {
940 engine_minutesS1[client] += 1;
941 engineSecondsS1[client] = 0.0;
942 }
943
944 return Plugin_Changed;
945}
946
947
948public float receiveMYSQLSurf(int client, float f_playerTime)
949{
950 //variables
951 float iCollected;
952 char sQuery[255];
953 char sSID[64];
954 char error[255];
955 DBResultSet rs;
956 Database db;
957
958 if (SQL_CheckConfig("zetimer"))
959 {
960 db = SQL_Connect("zetimer", true, error, sizeof(error));
961 }
962 if (db == null)
963 {
964 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
965 delete db;
966 }
967 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
968 Format(sQuery, sizeof(sQuery), "SELECT `%sS1` FROM `zetimer_tableSurf` WHERE steam_auth = '%s'", mapname, sSID);
969
970 if ((rs = SQL_Query(db, sQuery)) == null)
971 {
972 delete db;
973 delete rs;
974 return -1.0;
975 }
976
977 if(SQL_FetchRow(rs))
978 {
979 iCollected = SQL_FetchFloat(rs, 0);
980 }
981
982 delete rs;
983 delete db;
984 return iCollected;
985}
986
987
988public float receiveMYSQLSurfS2(int client, float f_playerTime)
989{
990 //variables
991 float iCollected;
992 char sQuery[255];
993 char sSID[64];
994 char error[255];
995 DBResultSet rs;
996 Database db;
997
998 if (SQL_CheckConfig("zetimer"))
999 {
1000 db = SQL_Connect("zetimer", true, error, sizeof(error));
1001 }
1002 if (db == null)
1003 {
1004 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
1005 delete db;
1006 }
1007 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
1008 Format(sQuery, sizeof(sQuery), "SELECT `%sS2` FROM `zetimer_tableSurf` WHERE steam_auth = '%s'", mapname, sSID);
1009
1010 if ((rs = SQL_Query(db, sQuery)) == null)
1011 {
1012 delete db;
1013 delete rs;
1014 return -1.0;
1015 }
1016
1017 if(SQL_FetchRow(rs))
1018 {
1019 iCollected = SQL_FetchFloat(rs, 0);
1020 }
1021
1022 delete rs;
1023 delete db;
1024 return iCollected;
1025}
1026
1027
1028public float receiveMYSQLSurfS3(int client, float f_playerTime)
1029{
1030 //variables
1031 float iCollected;
1032 char sQuery[255];
1033 char sSID[64];
1034 char error[255];
1035 DBResultSet rs;
1036 Database db;
1037
1038 if (SQL_CheckConfig("zetimer"))
1039 {
1040 db = SQL_Connect("zetimer", true, error, sizeof(error));
1041 }
1042 if (db == null)
1043 {
1044 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
1045 delete db;
1046 }
1047 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
1048 Format(sQuery, sizeof(sQuery), "SELECT `%sS3` FROM `zetimer_tableSurf` WHERE steam_auth = '%s'", mapname, sSID);
1049
1050 if ((rs = SQL_Query(db, sQuery)) == null)
1051 {
1052 delete db;
1053 delete rs;
1054 return -1.0;
1055 }
1056
1057 if(SQL_FetchRow(rs))
1058 {
1059 iCollected = SQL_FetchFloat(rs, 0);
1060 }
1061
1062 delete rs;
1063 delete db;
1064 return iCollected;
1065}
1066
1067
1068
1069public float receiveMYSQLSurfS4(int client, float f_playerTime)
1070{
1071 //variables
1072 float iCollected;
1073 char sQuery[255];
1074 char sSID[64];
1075 char error[255];
1076 DBResultSet rs;
1077 Database db;
1078
1079 if (SQL_CheckConfig("zetimer"))
1080 {
1081 db = SQL_Connect("zetimer", true, error, sizeof(error));
1082 }
1083 if (db == null)
1084 {
1085 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
1086 delete db;
1087 }
1088 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
1089 Format(sQuery, sizeof(sQuery), "SELECT `%sS4` FROM `zetimer_tableSurf` WHERE steam_auth = '%s'", mapname, sSID);
1090
1091 if ((rs = SQL_Query(db, sQuery)) == null)
1092 {
1093 delete db;
1094 delete rs;
1095 return -1.0;
1096 }
1097
1098 if(SQL_FetchRow(rs))
1099 {
1100 iCollected = SQL_FetchFloat(rs, 0);
1101 }
1102
1103 delete rs;
1104 delete db;
1105 return iCollected;
1106}
1107
1108
1109public float receiveMYSQLSurfS5(int client, float f_playerTime)
1110{
1111 //variables
1112 float iCollected;
1113 char sQuery[255];
1114 char sSID[64];
1115 char error[255];
1116 DBResultSet rs;
1117 Database db;
1118
1119 if (SQL_CheckConfig("zetimer"))
1120 {
1121 db = SQL_Connect("zetimer", true, error, sizeof(error));
1122 }
1123 if (db == null)
1124 {
1125 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
1126 delete db;
1127 }
1128 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
1129 Format(sQuery, sizeof(sQuery), "SELECT `%sS5` FROM `zetimer_tableSurf` WHERE steam_auth = '%s'", mapname, sSID);
1130
1131 if ((rs = SQL_Query(db, sQuery)) == null)
1132 {
1133 delete db;
1134 delete rs;
1135 return -1.0;
1136 }
1137
1138 if(SQL_FetchRow(rs))
1139 {
1140 iCollected = SQL_FetchFloat(rs, 0);
1141 }
1142
1143 delete rs;
1144 delete db;
1145 return iCollected;
1146}
1147
1148public float receiveMYSQL(int client, float f_playerTime)
1149{
1150 //variables
1151 float iCollected;
1152 char sQuery[255];
1153 char sSID[64];
1154 char error[255];
1155 DBResultSet rs;
1156 Database db;
1157
1158 if (SQL_CheckConfig("zetimer"))
1159 {
1160 db = SQL_Connect("zetimer", true, error, sizeof(error));
1161 }
1162 if (db == null)
1163 {
1164 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
1165 delete db;
1166 }
1167 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
1168 Format(sQuery, sizeof(sQuery), "SELECT `%s` FROM `zetimer_table` WHERE steam_auth = '%s'", mapname, sSID);
1169
1170 if ((rs = SQL_Query(db, sQuery)) == null)
1171 {
1172 delete db;
1173 delete rs;
1174 return -1.0;
1175 }
1176
1177 if(SQL_FetchRow(rs))
1178 {
1179 iCollected = SQL_FetchFloat(rs, 0);
1180 }
1181
1182 delete rs;
1183 delete db;
1184 return iCollected;
1185}
1186
1187public void sendMYSQLSurf(int client, float f_playerTime)
1188{
1189 char error[255];
1190 Database db;
1191 if (SQL_CheckConfig("zetimer"))
1192 {
1193 db = SQL_Connect("zetimer", true, error, sizeof(error));
1194 }
1195 if (db == null)
1196 {
1197 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
1198 delete db;
1199 }
1200
1201 char sSID[64];
1202 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
1203 char sQuery[255];
1204 Format(sQuery, sizeof(sQuery), "SELECT `%sS1` FROM `zetimer_tableSurf` LIMIT 10", mapname);
1205
1206 DBResultSet rs;
1207 if ((rs = SQL_Query(db, sQuery)) == null)
1208 {
1209 delete db;
1210 delete rs;
1211 }
1212 if (rs.FetchRow())
1213 {
1214 Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_tableSurf` (`steam_auth`, `name`, `%sS1`) VALUES ('%s', '%N', '%f') ON DUPLICATE KEY UPDATE `name` = '%N', `%sS1` = '%f'", mapname, sSID, client, f_playerTime, client, mapname, f_playerTime);
1215 SQL_TQuery(db, DummyCallbackSimple, sQuery);
1216 }
1217 else
1218 {
1219 Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_tableSurf` ADD COLUMN `%sS1` DECIMAL(13,3) NOT NULL", mapname);
1220 SQL_TQuery(db, DummyCallbackSimple, sQuery);
1221 }
1222 delete db;
1223 delete rs;
1224 //CPrintToChatAll("reaching end, query is: %s", sQuery);
1225}
1226
1227public void sendMYSQLSurfS2(int client, float f_playerTime)
1228{
1229 char error[255];
1230 Database db;
1231 if (SQL_CheckConfig("zetimer"))
1232 {
1233 db = SQL_Connect("zetimer", true, error, sizeof(error));
1234 }
1235 if (db == null)
1236 {
1237 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
1238 delete db;
1239 }
1240
1241 char sSID[64];
1242 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
1243 char sQuery[255];
1244 Format(sQuery, sizeof(sQuery), "SELECT `%sS2` FROM `zetimer_tableSurf` LIMIT 10", mapname);
1245
1246 DBResultSet rs;
1247 if ((rs = SQL_Query(db, sQuery)) == null)
1248 {
1249 delete db;
1250 delete rs;
1251 }
1252 if (rs.FetchRow())
1253 {
1254 Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_tableSurf` (`steam_auth`, `name`, `%sS2`) VALUES ('%s', '%N', '%f') ON DUPLICATE KEY UPDATE `name` = '%N', `%sS2` = '%f'", mapname, sSID, client, f_playerTime, client, mapname, f_playerTime);
1255 SQL_TQuery(db, DummyCallbackSimple, sQuery);
1256 }
1257 else
1258 {
1259 Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_tableSurf` ADD COLUMN `%sS2` DECIMAL(13,3) NOT NULL", mapname);
1260 SQL_TQuery(db, DummyCallbackSimple, sQuery);
1261 }
1262 delete db;
1263 delete rs;
1264 //CPrintToChatAll("reaching end, query is: %s", sQuery);
1265}
1266
1267public void sendMYSQLSurfS3(int client, float f_playerTime)
1268{
1269 char error[255];
1270 Database db;
1271 if (SQL_CheckConfig("zetimer"))
1272 {
1273 db = SQL_Connect("zetimer", true, error, sizeof(error));
1274 }
1275 if (db == null)
1276 {
1277 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
1278 delete db;
1279 }
1280
1281 char sSID[64];
1282 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
1283 char sQuery[255];
1284 Format(sQuery, sizeof(sQuery), "SELECT `%sS3` FROM `zetimer_tableSurf` LIMIT 10", mapname);
1285
1286 DBResultSet rs;
1287 if ((rs = SQL_Query(db, sQuery)) == null)
1288 {
1289 delete db;
1290 delete rs;
1291 }
1292 if (rs.FetchRow())
1293 {
1294 Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_tableSurf` (`steam_auth`, `name`, `%sS3`) VALUES ('%s', '%N', '%f') ON DUPLICATE KEY UPDATE `name` = '%N', `%sS3` = '%f'", mapname, sSID, client, f_playerTime, client, mapname, f_playerTime);
1295 SQL_TQuery(db, DummyCallbackSimple, sQuery);
1296 }
1297 else
1298 {
1299 Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_tableSurf` ADD COLUMN `%sS3` DECIMAL(13,3) NOT NULL", mapname);
1300 SQL_TQuery(db, DummyCallbackSimple, sQuery);
1301 }
1302 delete db;
1303 delete rs;
1304 //CPrintToChatAll("reaching end, query is: %s", sQuery);
1305}
1306
1307
1308public void sendMYSQLSurfS4(int client, float f_playerTime)
1309{
1310 char error[255];
1311 Database db;
1312 if (SQL_CheckConfig("zetimer"))
1313 {
1314 db = SQL_Connect("zetimer", true, error, sizeof(error));
1315 }
1316 if (db == null)
1317 {
1318 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
1319 delete db;
1320 }
1321
1322 char sSID[64];
1323 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
1324 char sQuery[255];
1325 Format(sQuery, sizeof(sQuery), "SELECT `%sS4` FROM `zetimer_tableSurf` LIMIT 10", mapname);
1326
1327 DBResultSet rs;
1328 if ((rs = SQL_Query(db, sQuery)) == null)
1329 {
1330 delete db;
1331 delete rs;
1332 }
1333 if (rs.FetchRow())
1334 {
1335 Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_tableSurf` (`steam_auth`, `name`, `%sS4`) VALUES ('%s', '%N', '%f') ON DUPLICATE KEY UPDATE `name` = '%N', `%sS4` = '%f'", mapname, sSID, client, f_playerTime, client, mapname, f_playerTime);
1336 SQL_TQuery(db, DummyCallbackSimple, sQuery);
1337 }
1338 else
1339 {
1340 Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_tableSurf` ADD COLUMN `%sS4` DECIMAL(13,3) NOT NULL", mapname);
1341 SQL_TQuery(db, DummyCallbackSimple, sQuery);
1342 }
1343 delete db;
1344 delete rs;
1345 //CPrintToChatAll("reaching end, query is: %s", sQuery);
1346}
1347
1348public void sendMYSQLSurfS5(int client, float f_playerTime)
1349{
1350 char error[255];
1351 Database db;
1352 if (SQL_CheckConfig("zetimer"))
1353 {
1354 db = SQL_Connect("zetimer", true, error, sizeof(error));
1355 }
1356 if (db == null)
1357 {
1358 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
1359 delete db;
1360 }
1361
1362 char sSID[64];
1363 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
1364 char sQuery[255];
1365 Format(sQuery, sizeof(sQuery), "SELECT `%sS5` FROM `zetimer_tableSurf` LIMIT 10", mapname);
1366
1367 DBResultSet rs;
1368 if ((rs = SQL_Query(db, sQuery)) == null)
1369 {
1370 delete db;
1371 delete rs;
1372 }
1373 if (rs.FetchRow())
1374 {
1375 Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_tableSurf` (`steam_auth`, `name`, `%sS5`) VALUES ('%s', '%N', '%f') ON DUPLICATE KEY UPDATE `name` = '%N', `%sS5` = '%f'", mapname, sSID, client, f_playerTime, client, mapname, f_playerTime);
1376 SQL_TQuery(db, DummyCallbackSimple, sQuery);
1377 }
1378 else
1379 {
1380 Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_tableSurf` ADD COLUMN `%sS5` DECIMAL(13,3) NOT NULL", mapname);
1381 SQL_TQuery(db, DummyCallbackSimple, sQuery);
1382 }
1383 delete db;
1384 delete rs;
1385 //CPrintToChatAll("reaching end, query is: %s", sQuery);
1386}
1387
1388public void sendMYSQL(int client, float f_playerTime)
1389{
1390 char error[255];
1391 Database db;
1392 if (SQL_CheckConfig("zetimer"))
1393 {
1394 db = SQL_Connect("zetimer", true, error, sizeof(error));
1395 }
1396 if (db == null)
1397 {
1398 CPrintToChatAll("{green}[Unloze] Error! Could not connect to MYSQL-DB!");
1399 delete db;
1400 }
1401
1402 char sSID[64];
1403 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
1404 char sQuery[255];
1405 Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table` ADD COLUMN `%s` DECIMAL(13,3) NOT NULL", mapname);
1406 SQL_TQuery(db, DummyCallbackSimple, sQuery);
1407 Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_table` (`steam_auth`, `name`, `%s`) VALUES ('%s', '%N', '%f') ON DUPLICATE KEY UPDATE `name` = '%N', `%s` = '%f'", mapname, sSID, client, f_playerTime, client, mapname, f_playerTime);
1408 SQL_TQuery(db, DummyCallbackSimple, sQuery);
1409 delete db;
1410 //CPrintToChatAll("reaching end, query is: %s", sQuery);
1411}
1412
1413
1414
1415public void SQL_StartConnection()
1416{
1417 char error[255];
1418 Database db;
1419 if (SQL_CheckConfig("zetimer"))
1420 {
1421 db = SQL_Connect("zetimer", true, error, sizeof(error));
1422 }
1423 if (db == null)
1424 {
1425 CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
1426 delete db;
1427 }
1428
1429 //create tables
1430 char sQuery[255];
1431 Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `zetimer_table` (`steam_auth` VARCHAR(254) NOT NULL, `name` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_auth`))");
1432 SQL_TQuery(db, DummyCallbackSimple, sQuery);
1433 Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `zetimer_tableSurf` (`steam_auth` VARCHAR(254) NOT NULL, `name` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_auth`))");
1434 SQL_TQuery(db, DummyCallbackSimple, sQuery);
1435 delete db;
1436}
1437
1438
1439
1440//stocks and verification stuff
1441
1442
1443stock bool IsValidClient(int client, bool alive = false, bool bots = false)
1444{
1445 if (client > 0 && client <= MaxClients && IsClientInGame(client) && (alive == false || IsPlayerAlive(client)) && (bots == false && !IsFakeClient(client)))
1446 {
1447 return true;
1448 }
1449 return false;
1450}
1451
1452
1453public void OnClientPostAdminCheck(int client)
1454{
1455 char error[255];
1456 char sQuery[255];
1457 char sSID[64];
1458 Database db;
1459 DBResultSet rs;
1460
1461 if (SQL_CheckConfig("zetimer"))
1462 {
1463 db = SQL_Connect("zetimer", true, error, sizeof(error));
1464 }
1465 if (db == null)
1466 {
1467 CPrintToChatAll("{green}[Unloze] {white}Error! Could not connect to MYSQL-DB!");
1468 delete db;
1469 }
1470 GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
1471 Format(sQuery, sizeof(sQuery), "UPDATE `zetimer_table` SET `name`= '%N' WHERE `steam_auth` = '%s'", client, sSID);
1472 SQL_TQuery(db, DummyCallbackSimple, sQuery);
1473 Format(sQuery, sizeof(sQuery), "UPDATE `zetimer_tableSurf` SET `name`= '%N' WHERE `steam_auth` = '%s'", client, sSID);
1474 SQL_TQuery(db, DummyCallbackSimple, sQuery);
1475 delete rs;
1476 delete db;
1477}
1478
1479public void DummyCallbackSimple(Handle hOwner, Handle hChild, const char[] err, DataPack pack1)
1480{
1481 if (hOwner == null || hChild == null)
1482 {
1483 LogError("Query error. (%s)", err);
1484 }
1485}