· 9 years ago · Feb 01, 2017, 07:32 AM
1/* *********************************************************************
2
3Thanks for people that help me:
4- dalto (http://forums.alliedmods.net/member.php?u=29575)
5
6
7Updates:
8 * Display FIX
9 * Query FIXES
10 * New: OLD STATS deleting
11 * Update TABLE on UTF8 and Setting NAMES to UTF8 on DatabaseConnect
12 * Changes in Database Connect
13 * New: Added "/headhunters"
14 * New: played_time, we will creat most active players TOP
15 * New: last_active ON this we will base is this player stats not to old.. (we dont want have BIG MySQL DataBase)
16 in future, maybe i will creat archive table, that there we will be have those player's, and they will be come back from archive when they will connect.
17 * Anti Flood Protection (new userFlood[64];)
18 * New announce message on: onClientPutInServer(client)
19 * WWW sie Cvar ("sm_lrcss_www",)
20 * PHP site nick protection:
21 [ ReplaceString(name, sizeof(name), "'", "");
22 ReplaceString(name, sizeof(name), "<", "");
23 ReplaceString(name, sizeof(name), "\"", "");
24]
25* Changed SQL_Query on SQL_TQuery Functions, Helper: - dalto
26* Added Debug Mode for MySQL Queries: new DEBUG = 0;
27* Added: char steamIdSave[64][255]; for Player Disconnect useage in: SQL_TQuery
28* Added: if(hndl == INVALID_HANDLE) function check in all: SQL_TQuery
29
30MySQL Query:
31
32CREATE TABLE `tf2ware_rank`(
33`rank_id` int(64) NOT NULL auto_increment,
34`steamId` varchar(32) NOT NULL default '',
35`nick` varchar(128) NOT NULL default '',
36`mg_won` int(12) NOT NULL default '0,
37`mg_lose` int(12) NOT NULL default '0,
38`bossstagewon` int(12) NOT NULL default '0,
39`totalwins` int(12) NOT NULL default '0,
40`last_active` int(12) NOT NULL default '0,
41`played_time` int(12) NOT NULL default '0,
42PRIMARY KEY (`rank_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;
43
44database.cfg
45
46 "tf2ware_rank"
47 {
48 "driver" "default"
49 "host" "127.0.0.1"
50 "database" "database_name"
51 "user" "database_user"
52 "pass" "PASSWORD"
53 //"timeout" "0"
54 "port" "3306"
55 }
56
57*************************************************************************** */
58
59// KOLOROWE KREDKI
60#define YELLOW 0x01
61#define GREEN 0x04
62
63// DEBUG MODE (1 = ON, 0 = OFF)
64bool DEBUG;
65int g_reconnectCounter = 0;
66Handle g_hSQL;
67// SOME DEFINES
68#define MAX_LINE_WIDTH 60
69
70// STATS TIME (SET DAYS AFTER STATS ARE DELETE OF NONACTIVE PLAYERS)
71#define PLAYER_STATSOLD 30
72int mg_id;
73char output3[255];
74// STATS DEFINATION FOR PLAYERS
75int MinigameWon[MAXPLAYERS+1];
76int MinigameLose[MAXPLAYERS+1];
77int BossStageWon[MAXPLAYERS+1];
78int TotalRoundWon[MAXPLAYERS+1];
79int userInit[MAXPLAYERS+1];
80int userFlood[MAXPLAYERS+1];
81int userPtime[MAXPLAYERS+1];
82int Mg_Query[MAXPLAYERS+1];
83char steamIdSave[MAXPLAYERS+1][255];
84
85// HANDLE OF DATABASE
86
87int ConnectSQL()
88{
89 if (g_hSQL != INVALID_HANDLE)
90 CloseHandle(g_hSQL);
91
92 g_hSQL = INVALID_HANDLE;
93
94 if (SQL_CheckConfig("tf2ware_rank"))
95 {
96 SQL_TConnect(ConnectSQLCallback, "tf2ware_rank");
97 //SQL_TConnect(ConnectSQLCallback, "tf2wareminigames");
98 }
99 else
100 {
101 SetFailState("PLUGIN STOPPED - Reason: no config entry found for 'tf2ware_rank' in databases.cfg - PLUGIN STOPPED");
102 }
103}
104
105public int ConnectSQLCallback(Handle owner, Handle hndl, const char[] error, any data)
106{
107 if (g_reconnectCounter >= 5)
108 {
109 SetFailState("PLUGIN STOPPED - Reason: reconnect counter reached max - PLUGIN STOPPED");
110 return;
111 }
112
113 if (hndl == INVALID_HANDLE)
114 {
115 LogError("[tf2ware_rank.smx] Connection to SQL database has failed, Try #%d, Reason: %s", g_reconnectCounter, error);
116 g_reconnectCounter++;
117 ConnectSQL();
118
119 return;
120 }
121
122 char driver[16];
123 SQL_GetDriverIdent(owner, driver, sizeof(driver));
124
125 g_hSQL = CloneHandle(hndl);
126
127 if (StrEqual(driver, "mysql", false))
128 {
129 PrintToChatAll("MERDA!");
130
131 SQL_TQuery(g_hSQL, CreateSQLTableCallback, "CREATE TABLE IF NOT EXISTS `tf2ware_rank` (`rank_id` INTEGER PRIMARY KEY, `steamid` varchar(32) NOT NULL, `nick` varchar(128) NOT NULL, `mg_won` INTEGER NOT NULL, `mg_lose` INTEGER NOT NULL, `bossstagewon` INTEGER NOT NULL, `totalwins` INTEGER NOT NULL, `last_active` INTEGER NOT NULL, `played_time` INTEGER NOT NULL);");
132 char output[128];
133 char Query[255];
134 for (int i=0; i<sizeof(g_name); i++)
135 {
136 if (StrEqual(g_name[i], ""))
137 {
138 continue;
139 }
140 Format(output, sizeof(output), "%2d_%s", GetMinigameConfNum(g_name[i], "id"), g_name[i]);
141 Format(Query, sizeof(Query), "ALTER TABLE `tf2ware_rank` ADD `%s` INTEGER NOT NULL;", output);
142 SQL_TQuery(g_hSQL, CreateSQLTableCallback, Query);
143 }
144 }
145 g_reconnectCounter = 1;
146}
147
148public int CreateSQLTableCallback(Handle owner, Handle hndl, const char[] error, any data)
149{
150 if (owner == INVALID_HANDLE)
151 {
152 g_reconnectCounter++;
153 ConnectSQL();
154
155 return;
156 }
157
158 if (hndl == INVALID_HANDLE)
159 {
160 return;
161 }
162}
163
164public int InitializeClient( int client )
165{
166 if (!IsFakeClient(client))
167 {
168 MinigameWon[client]=0;
169 MinigameLose[client]=0;
170 BossStageWon[client]=0;
171 TotalRoundWon[client]=0;
172 userFlood[client]=0;
173 userPtime[client]=GetTime();
174 char steamId[64];
175 GetClientAuthId(client, AuthId_Steam2, steamId, sizeof(steamId));
176 steamIdSave[client] = steamId;
177 PrintToChatAll("client %s", steamId);
178 Mg_Query[client] = 0;
179 CreateTimer(1.0, initPlayerBase, client);
180 }
181}
182
183public Action initPlayerBase(Handle timer, any client){
184 if (g_hSQL != INVALID_HANDLE)
185 {
186 char buffer[200];
187 Format(buffer, sizeof(buffer), "SELECT * FROM tf2ware_rank WHERE steamId = '%s'", steamIdSave[client]);
188 PrintToChatAll("DEBUG: Action:initPlayerBase (%s)", buffer);
189 SQL_TQuery(g_hSQL, SQLUserLoad, buffer, client);
190 }
191}
192public int saveUser(int client){
193 if ( !IsFakeClient(client) && userInit[client] == 1)
194 {
195 if (g_hSQL != INVALID_HANDLE)
196 {
197 char buffer[200];
198 Format(buffer, sizeof(buffer), "SELECT * FROM tf2ware_rank WHERE steamId = '%s'", steamIdSave[client]);
199 PrintToChatAll("DEBUG: saveUser (%s)", buffer);
200
201 SQL_TQuery(g_hSQL, SQLUserSave, buffer, client);
202 }
203 }
204}
205
206public Action Command_Say(int client, int args){
207
208 char text[192]; char command[64];
209
210 int startidx = 0;
211
212 GetCmdArgString(text, sizeof(text));
213
214 if (text[strlen(text)-1] == '"')
215 {
216 text[strlen(text)-1] = '\0';
217 startidx = 1;
218 }
219 if (strcmp(command, "say2", false) == 0)
220
221 startidx += 4;
222
223 if (strcmp(text[startidx], "/rank", false) == 0) {
224 if(userFlood[client] != 1){
225 saveUser(client);
226 GetMyRank(client);
227 userFlood[client]=1;
228 CreateTimer(10.0, removeFlood, client);
229 } else {
230 PrintToChat(client,"%cDo not flood the server!", GREEN);
231 }
232 } else if (strcmp(text[startidx], "/top10", false) == 0)
233 {
234 if(userFlood[client] != 1){
235 saveUser(client);
236 showTOP(client);
237 userFlood[client]=1;
238 CreateTimer(10.0, removeFlood, client);
239 } else {
240 PrintToChat(client,"%cDo not flood the server!", GREEN);
241 }
242 } else if (strcmp(text[startidx], "/topboss", false) == 0)
243 {
244 if(userFlood[client] != 1){
245 saveUser(client);
246 showTOPHeadHunter(client);
247 userFlood[client]=1;
248 CreateTimer(10.0, removeFlood, client);
249 } else {
250 PrintToChat(client,"%cDo not flood the server!", GREEN);
251 }
252 }
253 else if (strcmp(text[startidx], "/wlr", false) == 0)
254 {
255 if(userFlood[client] != 1){
256 saveUser(client);
257 GetMyWLR(client);
258 userFlood[client]=1;
259 CreateTimer(10.0, removeFlood, client);
260 } else {
261 PrintToChat(client,"%cDo not flood the server!", GREEN);
262 }
263 }
264 return Plugin_Continue;
265}
266
267public Action removeFlood(Handle timer, any client){
268 userFlood[client]=0;
269}
270public int GetMyWLR(int client){
271 if (g_hSQL != INVALID_HANDLE)
272 {
273 if(userInit[client] == 1){
274
275 char buffer[200];
276 Format(buffer, sizeof(buffer), "SELECT `mg_won`, `mg_lose`, `bossstagewon` FROM `tf2ware_rank` WHERE `steamId` = '%s' LIMIT 1", steamIdSave[client]);
277 PrintToChatAll("DEBUG: GetMyWLR (%s)", buffer);
278 SQL_TQuery(g_hSQL, SQLGetMyWLR, buffer, client);
279
280 } else {
281
282 PrintToChat(client,"%cWait for system load you from database", GREEN);
283
284 }
285 } else {
286 PrintToChat(client, "%cWLR System is now not avilable", GREEN);
287 }
288}
289public int GetMyRank(int client){
290 if (g_hSQL != INVALID_HANDLE)
291 {
292 if(userInit[client] == 1){
293
294 char buffer[200];
295 Format(buffer, sizeof(buffer), "SELECT `mg_won`, `mg_lose`, `bossstagewon`, `totalwins` FROM `tf2ware_rank` WHERE `steamId` = '%s' LIMIT 1", steamIdSave[client]);
296 PrintToChatAll("DEBUG: GetMyRank (%s)", buffer);
297 SQL_TQuery(g_hSQL, SQLGetMyRank, buffer, client);
298
299 } else {
300
301 PrintToChat(client,"%cWait for system load you from database", GREEN);
302
303 }
304 } else {
305 PrintToChat(client, "%cRank System is now not avilable", GREEN);
306 }
307}
308public int GetMyGameList(int client){
309 if (g_hSQL != INVALID_HANDLE)
310 {
311 if(userInit[client] == 1){
312
313 char buffer[200];
314 Format(buffer, sizeof(buffer), "SELECT `mg_won`, `mg_lose`, `bossstagewon`, `totalwins` FROM `tf2ware_rank` WHERE `steamId` = '%s' LIMIT 1", steamIdSave[client]);
315 PrintToChatAll("DEBUG: GetMyRank (%s)", buffer);
316 SQL_TQuery(g_hSQL, SQLGetMyRank, buffer, client);
317
318 } else {
319
320 PrintToChat(client,"%cWait for system load you from database", GREEN);
321
322 }
323 } else {
324 PrintToChat(client, "%cRank System is now not avilable", GREEN);
325 }
326}
327
328public int showTOP(int client){
329
330 if (g_hSQL != INVALID_HANDLE)
331 {
332 char buffer[200];
333 //Format(buffer, sizeof(buffer), "SELECT *, (`mg_lose`/`mg_won`) / `played_time` AS rankn FROM `tf2ware_rank` WHERE `mg_won` > 0 AND `mg_lose` > 0 ORDER BY rankn ASC LIMIT 10");
334 Format(buffer, sizeof(buffer), "SELECT * FROM tf2ware_rank ORDER BY totalwins DESC LIMIT 10");
335 PrintToChatAll("DEBUG: showTOP (%s)", buffer);
336 SQL_TQuery(g_hSQL, SQLTopShow, buffer, client);
337 } else {
338 PrintToChat(client, "%cRank System is now not avilable", GREEN);
339 }
340}
341
342public int showTOPHeadHunter(int client){
343
344 if (g_hSQL != INVALID_HANDLE)
345 {
346 char buffer[200];
347 char output[255];
348 for (int i=0; i<sizeof(g_name); i++)
349 {
350 if (StrEqual(g_name[i], ""))
351 {
352 continue;
353 }
354 Format(output3, sizeof(output3), "%s", g_name[i]);
355 Format(output, sizeof(output), "%2d_%s", GetMinigameConfNum(g_name[i], "id"), g_name[i]);
356 Format(buffer, sizeof(buffer), "SELECT `%s` FROM `tf2ware_rank` WHERE `steamId` = '%s' LIMIT 1", output, steamIdSave[client]);
357 PrintToChatAll("DEBUG: showTOPHeadHunter (%s)", buffer);
358 mg_id = GetMinigameConfNum(g_name[i], "id");
359 SQL_TQuery(g_hSQL, SQLTopShowHS, buffer, client);
360 //PrintToChatAll("%s", buffer);
361 }
362 //SQL_TQuery(g_hSQL, SQLTopShowHS, buffer, client);
363 } else {
364 PrintToChat(client, "%cRank System is now not avilable", GREEN);
365 }
366}
367
368public int TopMenu(Menu menu, MenuAction action, int param1, int param2)
369{
370}
371
372// ================================================================================
373
374public int SQLErrorCheckCallback(Handle owner, Handle hndl, const char[] error, any data)
375{
376 if(!StrEqual("", error))
377 {
378 PrintToChatAll("Last Connect SQL Error: %s", error);
379 }
380}
381
382
383public int SQLUserLoad(Handle owner, Handle hndl, const char[] error, any client){
384 if (!IsClientInGame(client)) return;
385 if(SQL_FetchRow(hndl))
386 {
387 char name[MAX_LINE_WIDTH];
388 GetClientName( client, name, sizeof(name) );
389
390 ReplaceString(name, sizeof(name), "'", "");
391 ReplaceString(name, sizeof(name), "<", "");
392 ReplaceString(name, sizeof(name), "\"", "");
393
394 char buffer[512];
395 Format(buffer, sizeof(buffer), "UPDATE tf2ware_rank SET nick = '%s', last_active = '%i' WHERE steamId = '%s'", name, GetTime(), steamIdSave[client]);
396 PrintToChatAll("DEBUG: SQLUserLoad (%s)", buffer);
397 SQL_TQuery(g_hSQL, SQLErrorCheckCallback, buffer);
398
399 userInit[client] = 1;
400 } else {
401
402 char name[MAX_LINE_WIDTH];
403 char buffer[200];
404
405 GetClientName( client, name, sizeof(name) );
406
407 ReplaceString(name, sizeof(name), "'", "");
408 ReplaceString(name, sizeof(name), "<", "");
409 ReplaceString(name, sizeof(name), "\"", "");
410
411 Format(buffer, sizeof(buffer), "INSERT INTO tf2ware_rank (steamId, nick, last_active) VALUES('%s','%s', '%i')", steamIdSave[client], name, GetTime());
412 PrintToChatAll("DEBUG: SQLUserLoad (%s)", buffer);
413 SQL_TQuery(g_hSQL, SQLErrorCheckCallback, buffer);
414
415 userInit[client] = 1;
416 }
417}
418
419public int SQLUserSave(Handle owner, Handle hndl, const char[] error, any client){
420 if(hndl == INVALID_HANDLE)
421 {
422 LogError(error);
423 PrintToChatAll("Last Connect SQL Error: %s", error);
424 return;
425 }
426
427 int QueryReadRow_MGWON;
428 int QueryReadRow_MGLOSE;
429 int QueryReadRow_BOSSWON;
430 int QueryReadRow_TOTALROUNDS;
431 int QueryReadRow_PTIME;
432 int QueryReadRow_MGQUERY;
433
434 if(SQL_FetchRow(hndl))
435 {
436 QueryReadRow_MGWON=SQL_FetchInt(hndl,3) + MinigameWon[client];
437 QueryReadRow_MGLOSE=SQL_FetchInt(hndl,4) + MinigameLose[client];
438 QueryReadRow_BOSSWON=SQL_FetchInt(hndl,5) + BossStageWon[client];
439 QueryReadRow_TOTALROUNDS=SQL_FetchInt(hndl,6) + TotalRoundWon[client];
440 QueryReadRow_PTIME=SQL_FetchInt(hndl,8) + GetTime() - userPtime[client];
441 QueryReadRow_MGQUERY=SQL_FetchInt(hndl,iMinigame +9) + MinigameLose[client];
442 MinigameWon[client] = 0;
443 MinigameLose[client] = 0;
444 BossStageWon[client] = 0;
445 TotalRoundWon[client] = 0;
446 Mg_Query[client] = 0;
447 userPtime[client] = GetTime();
448 char buffer[512];
449 PrintToChatAll("MINIGIOCO %s", output2);
450 Format(buffer, sizeof(buffer), "UPDATE tf2ware_rank SET mg_won = '%i', mg_lose = '%i', bossstagewon = '%i', totalwins = '%i', played_time = '%i', %s = '%i' WHERE steamId = '%s'", QueryReadRow_MGWON, QueryReadRow_MGLOSE, QueryReadRow_BOSSWON, QueryReadRow_TOTALROUNDS, QueryReadRow_PTIME, output2, QueryReadRow_MGQUERY, steamIdSave[client]);
451
452
453 PrintToChatAll("DEBUG: SQLUserSave (%s)", buffer);
454 SQL_TQuery(g_hSQL, SQLErrorCheckCallback, buffer);
455 }
456
457}
458
459public int SQLGetMyWLR(Handle owner, Handle hndl, const char[] error, any client){
460 if(hndl == INVALID_HANDLE)
461 {
462 LogError(error);
463 PrintToChatAll("Last Connect SQL Error: %s", error);
464 return;
465 }
466
467 int RAmgwon;
468 int RAmglose;
469 int RABossWon;
470
471 if(SQL_FetchRow(hndl))
472 {
473 RAmgwon=SQL_FetchInt(hndl, 0);
474 RAmglose=SQL_FetchInt(hndl, 1);
475 RABossWon=SQL_FetchInt(hndl, 2);
476 //RATotalwins=SQL_FetchInt(hndl, 3);
477 char buffer[512];
478 //test
479 // 0.00027144
480 //STEAM_0:1:13462423
481 //Format(buffer, sizeof(buffer), "SELECT ((`mg_lose`/`mg_won`)/`played_time`) AS rankn FROM `tf2ware_rank` WHERE (`mg_won` > 0 AND `mg_lose` > 0) AND ((`mg_lose`/`mg_won`)/`played_time`) < (SELECT ((`mg_lose`/`mg_won`)/`played_time`) FROM `tf2ware_rank` WHERE steamId = '%s' LIMIT 1) AND `steamId` != '%s' ORDER BY rankn ASC", steamIdSave[client], steamIdSave[client]);
482 float fmg_won = float(RAmgwon + RABossWon);
483 float fmg_lose = float(RAmglose);
484 float kpd = 0.0;
485 if (fmg_won <= 0 && fmg_lose <= 0)
486 {
487 return;
488 }
489 else if (fmg_won > 0 && fmg_lose <= 0)
490 {
491 kpd = fmg_won - fmg_lose;
492 }
493 else if (fmg_won > 0 && fmg_lose > 0)
494 {
495 kpd = fmg_won / fmg_lose;
496 }
497 Format(buffer, sizeof(buffer), "WinLoseRatio: %.2f , minigames won: %i, minigames losed: %i, Boss Stages Wons: %i", kpd, RAmgwon, RAmglose , RABossWon);
498 PrintToChatAll("DEBUG: SQLGetMyWLR (%s)", buffer);
499 //SQL_TQuery(g_hSQL, SQLShowWLRHandle, buffer, client);
500 //SQL_TQuery(g_hSQL, SQLShowWLR, buffer, client);
501 PrintToChat(client,"%cWin/Lose Rate (%s)", GREEN, buffer);
502 //PrintToChat(client,"%cMinigame Won: %i | Minigame Failed: %i | Boss Stage Won: %i | Total TF2Ware Rounds Wins: %i", GREEN, RAmgwon, RAmglose, RABossWon, RATotalwins);
503 } else {
504 PrintToChat(client, "%cYour kpd is not avlilable!", GREEN);
505 }
506}
507public int SQLGetMyRank(Handle owner, Handle hndl, const char[] error, any client){
508 if(hndl == INVALID_HANDLE)
509 {
510 LogError(error);
511 PrintToChatAll("Last Connect SQL Error: %s", error);
512 return;
513 }
514
515 int RAmgwon;
516 int RAmglose;
517 int RABossWon;
518 int RATotalwins;
519
520 if(SQL_FetchRow(hndl))
521 {
522 RAmgwon=SQL_FetchInt(hndl, 0);
523 RAmglose=SQL_FetchInt(hndl, 1);
524 RABossWon=SQL_FetchInt(hndl, 2);
525 RATotalwins=SQL_FetchInt(hndl, 3);
526 char buffer[512];
527 //test
528 // 0.00027144
529 //STEAM_0:1:13462423
530 Format(buffer, sizeof(buffer), "SELECT ((`mg_lose`/`mg_won`)/`played_time`) AS rankn FROM `tf2ware_rank` WHERE (`mg_won` > 0 AND `mg_lose` > 0) AND ((`mg_lose`/`mg_won`)/`played_time`) < (SELECT ((`mg_lose`/`mg_won`)/`played_time`) FROM `tf2ware_rank` WHERE steamId = '%s' LIMIT 1) AND `steamId` != '%s' ORDER BY rankn ASC", steamIdSave[client], steamIdSave[client]);
531
532 PrintToChatAll("DEBUG: SQLGetMyRank (%s)", buffer);
533 SQL_TQuery(g_hSQL, SQLShowRank, buffer, client);
534 PrintToChat(client,"%cMinigame Won: %i | Minigame Failed: %i | Boss Stage Won: %i | Total TF2Ware Rounds Wins: %i", GREEN, RAmgwon, RAmglose, RABossWon, RATotalwins);
535 } else {
536 PrintToChat(client, "%cYour kpd is not avlilable!", GREEN);
537 }
538}
539public int SQLShowRank(Handle owner, Handle hndl, const char[] error, any client){
540 if (SQL_HasResultSet(hndl))
541 {
542 int rows = SQL_GetRowCount(hndl);
543 PrintToChat(client,"%cYour rank is: %i.", GREEN, rows);
544 }
545}
546public int SQLShowWLR(Handle owner, Handle hndl, const char[] error, any client){
547 if (SQL_HasResultSet(hndl))
548 {
549 int rows = SQL_GetRowCount(hndl);
550 PrintToChat(client,"%cYour rank is: %i.", GREEN, rows);
551 }
552}
553
554public int SQLTopShow(Handle owner, Handle hndl, const char[] error, any client){
555
556 if(hndl == INVALID_HANDLE)
557 {
558 LogError(error);
559 PrintToChatAll("Last Connect SQL Error: %s", error);
560 return;
561 }
562
563 //Handle Panel = CreatePanel(GetMenuStyleHandle(MenuStyle_Valve));
564 Panel panel = CreatePanel(GetMenuStyleHandle(MenuStyle_Radio));
565 char text[128];
566 Format(text,127,"TF2ware Rounds Top 10 Players");
567 SetPanelTitle(panel,text);
568
569 int row;
570 char name[64];
571 //int mgwin;
572 //int mglose;
573 int totalwins;
574 if (SQL_HasResultSet(hndl))
575 {
576 while (SQL_FetchRow(hndl))
577 {
578 row++;
579 SQL_FetchString(hndl, 2, name, sizeof(name));
580 //mgwin=SQL_FetchInt(hndl,3);
581 //mglose=SQL_FetchInt(hndl,4);
582 totalwins=SQL_FetchInt(hndl,6);
583 Format(text,127,"%d) %s Won %i times!", row, name, totalwins);
584 DrawPanelText(panel, text);
585 //Format(text,127,"Minigame Won: %i - Minigame Failed: %i", mgwin, mglose);
586/* Format(text,127,"Won %i times!", totalwins);
587 DrawPanelText(panel, text); */
588
589 }
590 } else {
591 Format(text,127,"TF2ware Rounds TOP 10 is empty!");
592 DrawPanelText(panel, text);
593 }
594
595 DrawPanelItem(panel, " ", ITEMDRAW_SPACER|ITEMDRAW_RAWLINE);
596
597 Format(text,59,"Exit");
598 DrawPanelItem(panel, text);
599
600 SendPanelToClient(panel, client, TopMenu, 20);
601 //panel.Send(client, TopMenu, 20);
602
603 //delete panel
604
605 CloseHandle(panel);
606
607}
608public int SQLTopShowHS(Handle owner, Handle hndl, const char[] error, any client){
609
610 if(hndl == INVALID_HANDLE)
611 {
612 LogError(error);
613 PrintToChatAll("Last Connect SQL Error: %s", error);
614 return;
615 }
616
617 Panel panel = CreatePanel(GetMenuStyleHandle(MenuStyle_Radio));
618 char text[128];
619 Format(text,127,"Minigames win details");
620 SetPanelTitle(panel,text);
621
622 int row;
623 char name[64];
624 int mg_Query;
625 int ptimed;
626 char textime[64];
627
628 if (SQL_HasResultSet(hndl))
629 {
630 while (SQL_FetchRow(hndl))
631 { row++;
632 //SQL_FetchString(hndl, 2, name, sizeof(name));
633 mg_Query=SQL_FetchInt(hndl, mg_id + 9);
634 Format(text,127,"%d: %s : %i", row, output3, mg_Query);
635 DrawPanelText(panel, text);
636 }
637 } else {
638 Format(text,127,"TOP BossStageWon is empty!");
639 DrawPanelText(panel, text);
640 }
641
642 DrawPanelItem(panel, " ", ITEMDRAW_SPACER|ITEMDRAW_RAWLINE);
643
644 Format(text,59,"Exit");
645 DrawPanelItem(panel, text);
646
647 SendPanelToClient(panel, client, TopMenu, 20);
648
649 CloseHandle(panel);
650
651}
652
653/* public int SQLTopShowHS(Handle owner, Handle hndl, const char[] error, any client){
654
655 if(hndl == INVALID_HANDLE)
656 {
657 LogError(error);
658 PrintToChatAll("Last Connect SQL Error: %s", error);
659 return;
660 }
661
662 Panel panel = CreatePanel(GetMenuStyleHandle(MenuStyle_Radio));
663 char text[128];
664 Format(text,127,"Top 10 BossStage");
665 SetPanelTitle(panel,text);
666
667 int row;
668 char name[64];
669 int mg_Query;
670 int ptimed;
671 char textime[64];
672
673 if (SQL_HasResultSet(hndl))
674 {
675 while (SQL_FetchRow(hndl))
676 {
677 row++;
678 SQL_FetchString(hndl, 2, name, sizeof(name));
679 mg_Query=SQL_FetchInt(hndl,mg_id + 10);
680 ptimed=SQL_FetchInt(hndl,8);
681
682 if(ptimed <= 3600){
683 Format(textime,63,"%i m.", ptimed / 60);
684 } else if(ptimed <= 43200){
685 Format(textime,63,"%i h.", ptimed / 60 / 60);
686 } else if(ptimed <= 1339200){
687 Format(textime,63,"%i d.", ptimed / 60 / 60 / 12);
688 } else {
689 Format(textime,63,"%i mo.", ptimed / 60 / 60 / 12 / 31);
690 }
691
692 Format(text,127,"%d: %s", row, name);
693 DrawPanelText(panel, text);
694 Format(text,127,"HS: %i - In Time: %s", shoths, textime);
695 DrawPanelText(panel, text);
696
697 }
698 } else {
699 Format(text,127,"TOP BossStageWon is empty!");
700 DrawPanelText(panel, text);
701 }
702
703 DrawPanelItem(panel, " ", ITEMDRAW_SPACER|ITEMDRAW_RAWLINE);
704
705 Format(text,59,"Exit");
706 DrawPanelItem(panel, text);
707
708 SendPanelToClient(panel, client, TopMenu, 20);
709
710 CloseHandle(panel);
711
712} */
713
714/* int PrintQueryData(Handle query)
715{
716 if (!SQL_HasResultSet(query))
717 {
718 PrintToChatAll("Query Handle %x has no results", query)
719 return
720 }
721
722 int rows = SQL_GetRowCount(query)
723 int fields = SQL_GetFieldCount(query)
724
725 char fieldNames[fields][32]
726 PrintToChatAll("Fields: %d", fields)
727 for (int i=0; i<fields; i++)
728 {
729 SQL_FieldNumToName(query, i, fieldNames[i], 32)
730 PrintToChatAll("-> Field %d: \"%s\"", i, fieldNames[i])
731 }
732
733 PrintToChatAll("Rows: %d", rows)
734 char result[255]
735 int row
736 while (SQL_FetchRow(query))
737 {
738 row++
739 PrintToChatAll("Row %d:", row)
740 for (int i=0; i<fields; i++)
741 {
742 SQL_FetchString(query, i, result, sizeof(result))
743 PrintToChatAll(" [%s] %s", fieldNames[i], result)
744 }
745 }
746} */
747public int SQL_ErrorCheckCallBack(Handle owner, Handle hndl, const char[] error, any data)
748{
749 // This is just an errorcallback for function who normally don't return any data
750 if(hndl == INVALID_HANDLE)
751 {
752 SetFailState("Query failed! %s", error);
753 LogError("Didint connect to a detabase2!");
754 }
755}