· 5 years ago · Jul 20, 2020, 04:38 AM
1//#define USE_KZ_IRC
2#include <amxmodx>
3#include <geoip>
4#include <kzarg>
5
6// Necesitamos Incluir esta libreria y sacarle el ; en modules.ini
7#include <sqlx>
8
9#if defined USE_KZ_IRC
10#include <kzarg_irc>
11#endif
12
13/*================================================================================================*/
14/************************************* [Some Stuffs] **********************************************/
15/*=============================================================================R=E=Y=M=O=N==A=R=G=*/
16new const g_weaponsnames[][] =
17{
18 "", // NULL
19 "p228", "shield", "scout", "hegrenade", "xm1014", "c4",
20 "mac10", "aug", "smokegrenade", "elite", "fiveseven",
21 "ump45", "sg550", "galil", "famas", "usp", "glock18",
22 "awp", "mp5navy", "m249", "m3", "m4a1", "tmp", "g3sg1",
23 "flashbang", "deagle", "sg552", "ak47", "knife", "p90"
24}
25
26enum
27{
28 TOP_NULL,
29 PRO_TOP,
30 NUB_TOP,
31 ALL_PRO_TOP,
32 ALL_NUB_TOP
33}
34
35/*================================================================================================*/
36
37new const SQL_PLUGIN_VERSION[] = "1.0 Beta"
38new query[4096];
39#define DATABASE "KZ"
40new g_sql_error[512],g_top_menu,g_block_top_menu;
41
42/*================================================================================================*/
43
44// Necesitamos un par de variables para almacenar los apuntadores...
45new Handle:g_SqlTuple
46new Handle:SqlConnection
47
48#if defined USE_KZ_IRC
49new Kz_Irc_Channel[64]
50#endif
51
52new bool:g_pluginload
53new g_mainmenuitem
54
55/*================================================================================================*/
56/************************************* [Plugin Inits] *********************************************/
57/*=============================================================================R=E=Y=M=O=N==A=R=G=*/
58// Esto es como el plugin_init pero lo creee asi para que se cargue luego que todo el kz fue arrancado.
59public kz_pluginload()
60{
61 new version[64]
62 kz_get_plugin_version(version, 63)
63
64 #if defined USE_KZ_IRC
65 kzirc_getchannel(Kz_Irc_Channel, 63)
66 #endif
67
68 register_plugin("SQL Top15", SQL_PLUGIN_VERSION, "ReymonARG")
69
70 g_mainmenuitem = kz_mainmenu_item_register("Top15", "")
71
72 register_clcmd("say", "kz_hookchat")
73 register_clcmd("say_team", "kz_hookchat")
74
75 // Do no Edit.
76 server_print("[Kz-Arg] TOP15 SQL: Load SQL Top15 with Kz-Arg Mod: %s", version)
77
78 // Es mejor no conectarnos de una a la SQL.
79 // Si tu sql esta en tu misma maquina es mejor que siempre quede conectada.
80 set_task(0.2, "Init_MYSQL")
81 set_task(0.4, "sqlLoadTop");
82
83}
84
85/*================================================================================================*/
86
87public kz_itemmainmenu(id, item)
88{
89 if( item == g_mainmenuitem )
90 {
91 kz_topsmenu(id)
92 }
93}
94
95/*================================================================================================*/
96/*************************************** [Sqlx Inits] *********************************************/
97/*=============================================================================R=E=Y=M=O=N==A=R=G=*/
98public Init_MYSQL()
99{
100 new get_type[ 12 ];
101
102
103 SQL_SetAffinity( "sqlite" );
104
105 SQL_GetAffinity( get_type, sizeof get_type );
106
107 if( !equali( get_type, "sqlite" ) )
108 {
109 log_to_file( "SQLITE_ERROR.txt", "Error de conexion" );
110 return pause( "a" );
111 }
112
113 static iLen; iLen = 0;
114
115 iLen += formatex(query[iLen], charsmax(query) - iLen, "CREATE TABLE IF NOT EXISTS `kz_pro15` (`mapname` VARCHAR NOT NULL , \
116 `authid` VARCHAR, `name` VARCHAR, `time` VARCHAR, `dia` VARCHAR, `weapon` VARCHAR);CREATE TABLE IF NOT EXISTS `kz_nub15` (`mapname` VARCHAR NOT NULL , \
117 `authid` VARCHAR, `name` VARCHAR, `time` VARCHAR, `dia` VARCHAR, `weapon` VARCHAR, `GoCheck` INTEGER);")
118
119 g_SqlTuple = SQL_MakeDbTuple("", "", "", DATABASE)
120 SQL_ThreadQuery(g_SqlTuple, "QueryCreateTable", query)
121
122 return PLUGIN_CONTINUE
123}
124public QueryCreateTable(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
125{
126 if(failstate == TQUERY_CONNECT_FAILED)
127 {
128 set_fail_state("[CONEXION SQL] No se pudo conectar a la database!")
129 }
130 else if(failstate == TQUERY_QUERY_FAILED)
131 {
132 set_fail_state("[CONEXION SQL] Query Fallo!")
133 }
134 else if(errcode)
135 {
136 server_print("Error en la query: %s", error)
137 }
138 else
139 {
140 server_print("[CONEXION SQL] SISTEMA DE GUARDADO CARGADO.!")
141 }
142}
143/*================================================================================================*/
144/********************************** [Default Put for Sql] *****************************************/
145/*=============================================================================R=E=Y=M=O=N==A=R=G=*/
146
147public QueryHandle(iFailState, Handle:hQuery, szError[], iErrnum, cData[], iSize, Float:fQueueTime)
148{
149 // Siempre tenemos que chekear errores.
150 if( iFailState != TQUERY_SUCCESS )
151 {
152 log_amx("[Kz-Arg] TOP15 SQL: SQL Error #%d - %s", iErrnum, szError)
153 return kz_colorchat(0, "!tTOP15 SQL: !gWarring the Tops can not be Saved")
154 }
155
156 // Debug
157 server_print("[Kz-Arg] Server Sending Info to SQL Server")
158
159 return PLUGIN_CONTINUE
160}
161
162/*================================================================================================*/
163/****************************** [Free Sql When Plugin Finish] *************************************/
164/*=============================================================================R=E=Y=M=O=N==A=R=G=*/
165
166public plugin_end()
167{
168 // Como termina el plugin... Se cambia de mapa o cayo el server
169 // Tenemos que cerrar la conexion...
170 SQL_FreeHandle(g_SqlTuple)
171}
172
173/*================================================================================================*/
174/********************************* [Forward from Kz-Arg Mod] **************************************/
175/*=============================================================================R=E=Y=M=O=N==A=R=G=*/
176
177public kz_finishclimb(id, Float:tiempo, check, gocheck, weapon)
178{
179 new map[64], steam[32]
180 get_mapname(map, sizeof map - 1 )
181 get_user_authid(id, steam, sizeof steam - 1 )
182
183 new createinto[1001]
184
185 // Como solo podemos pasar un solo array a la proxima funcion.
186 // Creamos una nueva y le hacemos una mini estructura....
187 new cData[192]
188 cData[0] = id
189 formatex(cData[2], charsmax(cData)-2, "^"%f^" ^"%d^" ^"%d^"", tiempo, weapon, gocheck)
190
191 if( gocheck == 0 && (weapon == CSW_USP || weapon == CSW_KNIFE) )
192 {
193 cData[1] = PRO_TOP
194 formatex(createinto, sizeof createinto - 1, "SELECT time FROM `kz_pro15` WHERE mapname='%s' AND authid='%s'", map, steam)
195 SQL_ThreadQuery(g_SqlTuple, "Set_QueryHandler", createinto, cData, strlen(cData[2])+1)
196 }
197 else if( weapon == CSW_USP || weapon == CSW_KNIFE || weapon == CSW_SCOUT )
198 {
199 cData[1] = NUB_TOP
200 formatex(createinto, sizeof createinto - 1, "SELECT time FROM `kz_nub15` WHERE mapname='%s' AND authid='%s'", map, steam)
201 SQL_ThreadQuery(g_SqlTuple, "Set_QueryHandler", createinto, cData, strlen(cData[2])+1)
202 }
203
204}
205
206/*================================================================================================*/
207/************************ [Call for Pro15 From Forward from Kz-Arg Mod] ***************************/
208/*=============================================================================R=E=Y=M=O=N==A=R=G=*/
209
210public Set_QueryHandler(iFailState, Handle:hQuery, szError[], iErrnum, cData[], iSize, Float:fQueueTime)
211{
212 new id = cData[0]
213 new style = cData[1]
214 if( iFailState != TQUERY_SUCCESS )
215 {
216 log_amx("[Kz-Arg] TOP15 SQL: SQL Error #%d - %s", iErrnum, szError)
217 return kz_colorchat(0, "!tTOP15 SQL:!gWarring the Tops can not be Saved")
218 }
219
220 server_print("[Kz-Arg] Server Geting Info of SQL Server")
221 kz_update_plrname(id) // Update here when not is doing anything.
222
223 new createinto[1001]
224 new x1[16], x2[4], x3[5]
225 parse(cData[2], x1, 15, x2, 3, x3, 4)
226
227 new Float:ftime = str_to_float(x1)
228 new dia[64], map[64], steam[32], name[32], ip[15], country[3], gochecks[32]
229 get_time("%Y%m%d%H%M%S", dia, sizeof dia - 1) // I use this with datatime
230 get_mapname(map, sizeof map - 1)
231 get_user_authid(id, steam, sizeof steam - 1)
232 get_user_name(id, name, sizeof name - 1)
233 get_user_ip (id, ip, sizeof ip - 1, 1)
234 strtolower(country) // Yes. Converts all characters to lower.
235
236 // First Remove the \ because then I put if there is others problems.
237 replace_all(name, 31, "\", "")
238 replace_all(name, 31, "`", "\`")
239 replace_all(name, 31, "'", "\'")
240
241 if( SQL_NumResults(hQuery) == 0 )
242 {
243 formatex(gochecks, 31, ", '%d'", str_to_num(x3))
244 kz_colorchat(0, "!t%s !gis the first time that complete!t %s", name, map)
245 #if defined USE_KZ_IRC
246 kzirc_setmsg("PRIVMSG %s :00,7 >> 0,1 %s 0,7 >> 0,1 is the first time that complete 0,7 >> 0,1 %s 0,7 >> ^n", Kz_Irc_Channel, name, map)
247 #endif
248 if(style == PRO_TOP)
249 formatex( createinto, sizeof createinto - 1, "INSERT INTO `kz_pro15` VALUES('%s','%s','%s','%f','%s','%s')", map, steam, name, ftime, dia, g_weaponsnames[str_to_num(x2)])
250 else if(style != PRO_TOP)
251 formatex( createinto, sizeof createinto - 1, "INSERT INTO `kz_nub15` VALUES('%s','%s','%s','%f','%s','%s','%s')", map, steam, name, ftime, dia, g_weaponsnames[str_to_num(x2)], gochecks)
252
253 SQL_ThreadQuery(g_SqlTuple, "QueryHandle", createinto)
254 GetNewRank(id, style)
255 }
256 else
257 {
258 new Float:qtime, minutos, Float:segundos, Float:mejorar
259 SQL_ReadResult(hQuery, 0, qtime)
260
261 if(ftime < qtime)
262 {
263 mejorar = qtime - ftime
264 minutos = floatround(mejorar, floatround_floor)/60
265 segundos = mejorar - (60*minutos)
266 kz_colorchat(0, "!t%s !gimproved his time !t%02d:%s%.6f !gin !t%s", name, minutos, segundos < 10 ? "0" : "", segundos, style == PRO_TOP ? "Pro15" : "Nub15")
267 #if defined USE_KZ_IRC
268 kzirc_setmsg("PRIVMSG %s :00,7 >> 0,1 %s 0,7 >> 0,1 improved his time 0,7 >> 0,1 %02d:%s%.6f 0,7 >> 0,1 %s 0,7 >> ^n", Kz_Irc_Channel, name, minutos, segundos < 10 ? "0" : "", segundos, style == PRO_TOP ? "Pro15" : "Nub15")
269 #endif
270 formatex(gochecks, 31, ", gocheck='%d'", str_to_num(x3))
271 formatex(createinto, sizeof createinto - 1, "UPDATE `%s` SET time='%f', weapon='%s', date='%s',%s WHERE authid='%s' AND mapname='%s'", style == PRO_TOP ? "kz_pro15" : "kz_nub15", ftime, g_weaponsnames[str_to_num(x2)], dia, style == PRO_TOP ? "" : gochecks, steam, map)
272 SQL_ThreadQuery(g_SqlTuple, "QueryHandle", createinto)
273 GetNewRank(id, style)
274
275 }
276 else
277 {
278 mejorar = ftime - qtime
279 minutos = floatround(mejorar, floatround_floor)/60
280 segundos = mejorar - (60*minutos)
281 kz_colorchat(0, "!t%s !gfail his better time by !t%02d:%s%.6f !gin !t%s", name, minutos, segundos < 10 ? "0" : "", segundos, style == PRO_TOP ? "Pro15" : "Nub15")
282 #if defined USE_KZ_IRC
283 kzirc_setmsg("PRIVMSG %s :00,7 >> 0,1 %s 0,7 >> 0,1 fail his better time by 0,7 >> 0,1 %02d:%s%.6f 0,7 >> 0,1 %s 0,7 >> ^n", Kz_Irc_Channel, name, minutos, segundos < 10 ? "0" : "", segundos, style == PRO_TOP ? "Pro15" : "Nub15")
284 #endif
285 }
286 }
287 set_task(0.4, "sqlLoadTop");
288
289 return PLUGIN_CONTINUE
290}
291/*================================================================================================*/
292/************************************** [New Rank Funccion] ***************************************/
293/*=============================================================================R=E=Y=M=O=N==A=R=G=*/
294
295stock GetNewRank(id, type)
296{
297 new createinto[1001], mapname[64]
298 get_mapname(mapname, 63)
299
300 new cData[2]
301 cData[0] = id
302 cData[1] = type
303
304 formatex(createinto, 1000, "SELECT authid FROM `%s` WHERE mapname='%s' ORDER BY time LIMIT 15", type == PRO_TOP ? "kz_pro15" : "kz_nub15", mapname)
305 SQL_ThreadQuery(g_SqlTuple, "GetNewRank_QueryHandler", createinto, cData, 2)
306}
307
308/*================================================================================================*/
309
310public GetNewRank_QueryHandler(iFailState, Handle:hQuery, szError[], iErrnum, cData[], iSize, Float:fQueueTime)
311{
312 new id = cData[0]
313 if( iFailState != TQUERY_SUCCESS )
314 {
315 return log_amx("TOP15 SQL: SQL Error #%d - %s", iErrnum, szError)
316 }
317
318 new steam[32], authid[32], name[32], i = 0
319 get_user_authid(id, steam, 31)
320 get_user_name(id, name, 31)
321
322 while( SQL_MoreResults(hQuery) )
323 {
324 i++
325 SQL_ReadResult(hQuery, 0, authid, 31)
326
327 if( equal(authid, steam) )
328 {
329 kz_colorchat(0, "!t%s!g new rank in!t %s!g [!t%d!g]", name, cData[1] == PRO_TOP ? "Pro15" : "Nub15", i)
330 #if defined USE_KZ_IRC
331 kzirc_setmsg("PRIVMSG %s :00,7 >> 0,1 %s 0,7 >> 0,1 new rank in 0,7 >> 0,1 %s 0,7 >> 0,1 %d 0,7 >> ^n", Kz_Irc_Channel, name, cData[1] == PRO_TOP ? "Pro15" : "Nub15", i)
332 #endif
333 break;
334 }
335
336 SQL_NextRow(hQuery)
337 }
338
339 return PLUGIN_CONTINUE
340}
341
342/*================================================================================================*/
343/*************************************** [Name Funccions] *****************************************/
344/*=============================================================================R=E=Y=M=O=N==A=R=G=*/
345
346public client_infochanged(id)
347{
348 if( !is_user_connected(id) && g_pluginload)
349 {
350 return PLUGIN_CONTINUE
351 }
352
353 new newname[32], oldname[32]
354
355 get_user_name(id, oldname, 31)
356 get_user_info(id, "name", newname, 31)
357
358 if(!equal(newname, oldname))
359 {
360 kz_update_plrname(id, newname, true)
361 }
362
363 return PLUGIN_CONTINUE
364}
365
366stock kz_update_plrname(id, const newname[32] = "", bool:shownew = false)
367{
368 new createinto[1001], steam[32], name[32]
369 get_user_authid(id, steam, 31)
370
371 if( equal(newname, "") )
372 get_user_name(id, name, 31)
373 else
374 name = newname
375
376 replace_all(name, 31, "\", "")
377 replace_all(name, 31, "`", "\`")
378 replace_all(name, 31, "'", "\'")
379
380 formatex(createinto, 1000, "UPDATE `kz_pro15` SET name='%s' WHERE authid='%s'", name, steam)
381 SQL_ThreadQuery(g_SqlTuple, "QueryHandle", createinto)
382 formatex(createinto, 1000, "UPDATE `kz_nub15` SET name='%s' WHERE authid='%s'", name, steam)
383 SQL_ThreadQuery(g_SqlTuple, "QueryHandle", createinto)
384
385 if( shownew )
386 kz_colorchat(id, "!tTOP15 SQL:!g Your new name for Top is: !t%s", name)
387
388 return 1
389}
390
391/*================================================================================================*/
392/*************************************** [Chats Funccions] ****************************************/
393/*=============================================================================R=E=Y=M=O=N==A=R=G=*/
394
395public kz_hookchat(id)
396{
397 new args[128]
398 read_args(args, 127)
399 remove_quotes(args)
400
401 // Is the message we are looking for
402 if( args[0] != '.' && args[0] != '/' )
403 return PLUGIN_CONTINUE
404
405 new command[12], cmdmap[64], mapname[64]
406 parse(args, command, 11, cmdmap, 63)
407
408 replace_all(command, 11, ".", "")
409 replace_all(command, 11, "/", "")
410
411 if( equal(command, "pro15") )
412 {
413 if( is_map_valid(cmdmap) )
414 {
415 kz_showhtml_motd(id, PRO_TOP, cmdmap)
416 }
417 else if( !is_map_valid(cmdmap) && !equal(cmdmap, "") )
418 {
419 kz_colorchat(id, "!tKZTOP: !gInvalid writing or not on our server")
420 }
421 else
422 {
423 get_mapname(mapname, 63)
424 kz_showhtml_motd(id, PRO_TOP, mapname)
425 }
426
427 return PLUGIN_HANDLED
428 }
429 else if( equal(command, "nub15") )
430 {
431 if( is_map_valid(cmdmap) )
432 {
433 kz_showhtml_motd(id, NUB_TOP, cmdmap)
434 }
435 else if( !is_map_valid(cmdmap) && !equal(cmdmap, "") )
436 {
437 kz_colorchat(id, "!tKZTOP: !gInvalid writing or not on our server")
438 }
439 else
440 {
441 get_mapname(mapname, 63)
442 kz_showhtml_motd(id, NUB_TOP, mapname)
443 }
444
445 return PLUGIN_HANDLED
446 }
447 else if( equal(command, "top15") )
448 {
449 kz_topsmenu(id)
450 return PLUGIN_HANDLED
451 }
452 else if( equal(command, "prorecords") || equal(command, "prorecs") )
453 {
454 new createinto[1001], authid[32], cData[2]
455 get_user_authid(id, authid, 31)
456 cData[0] = id
457 cData[1] = 0
458
459 formatex(createinto, 1000, "SELECT `mapname` FROM kz_pro15 WHERE authid='%s' ORDER BY mapname", authid)
460 SQL_ThreadQuery(g_SqlTuple, "GetProRecords_QueryHandler", createinto, cData, 2)
461 }
462
463 return PLUGIN_CONTINUE
464}
465
466/*================================================================================================*/
467
468stock kz_topsmenu(id, page = 0)
469{
470 new menu = menu_create("\r[Kz-Arg] \yTop15", "menufunc")
471
472 menu_additem(menu, "Pro15", "1")
473 menu_additem(menu, "Nub15", "2")
474 menu_additem(menu, "Last Pro15", "3")
475
476 menu_display(id, menu, page)
477}
478
479public menufunc(id, menu, item)
480{
481 if(item == MENU_EXIT)
482 {
483 return PLUGIN_HANDLED;
484 }
485
486 new data[6], iName[64], iaccess, callback, mapname[64]
487 menu_item_getinfo(menu, item, iaccess, data, 5, iName, 63, callback)
488 get_mapname(mapname, 63)
489
490 kz_showhtml_motd(id, str_to_num(data), mapname)
491
492 return PLUGIN_HANDLED
493}
494
495/*================================================================================================*/
496
497stock kz_showhtml_motd(id, type, const otherinfo[])
498{
499 new buffer[1001], namebuffer[64], filepath[96], completetype[64]
500
501 formatex(completetype, 63, "&map=%s", otherinfo)
502
503 switch( type )
504 {
505 case PRO_TOP:
506 {
507 formatex(namebuffer, 63, "[Kz-Arg] Pro15 of %s", equal(otherinfo, "") ? "All Maps" : otherinfo)
508 formatex(buffer, 1000, "<html><head><meta http-equiv=^"Refresh^" content=^"0;url=http://%s/top15.php?mode=pro15%s&rand=%d^"></head><body><p>LOADING...</p></body></html>", filepath, equal(otherinfo, "") ? "" : completetype, random_num(0, 1000))
509 }
510 case NUB_TOP:
511 {
512 formatex(namebuffer, 63, "[Kz-Arg] Nub15 of %s", equal(otherinfo, "") ? "All Maps" : otherinfo)
513 formatex(buffer, 1000, "<html><head><meta http-equiv=^"Refresh^" content=^"0;url=http://%s/top15.php?mode=nub15%s&rand=%d^"></head><body><p>LOADING...</p></body></html>", filepath, equal(otherinfo, "") ? "" : completetype, random_num(0, 1000))
514 }
515 case 3:
516 {
517 formatex(namebuffer, 63, "[Kz-Arg] Last %s Pro15", "10")
518 formatex(buffer, 1000, "<html><head><meta http-equiv=^"Refresh^" content=^"0;url=http://%s/kz_lastpro.php?maxs=%s&rand=%d^"></head><body><p>LOADING...</p></body></html>", filepath, "10", random_num(0, 1000))
519 }
520 }
521
522 show_motd(id, buffer, namebuffer)
523}
524
525/*================================================================================================*/
526/*================================================================================================*/
527/*================================================================================================*/
528/*================================================================================================*/
529/*================================================================================================*/
530#if defined USE_KZ_IRC
531
532public kzirc_recivemsg(const Channel[], const Msg[], const Name[], const Host[], id, access)
533{
534 //server_print("Channel: %s Msg: %s Name: %s Host: %s ID: %d Access: %d", Channel, Msg, Name, Host, id, access)
535
536 if( equal(Channel, Kz_Irc_Channel) )
537 {
538 if( equal(Msg, "!help") )
539 {
540 kzirc_setmsg("PRIVMSG %s :00,7 >> 0,1 Commands: 0,7 >> 0,1 !pro15 <mapname> 0,7 ! 0,1 !num15 <mapname> 0,7 ! 0,1 !status 0,7 ! 0,1 !info 0,7 ! 0,1 And More 0,7 >> ^n", Kz_Irc_Channel)
541 return
542 }
543 else if( equal(Msg, "!lastpro") )
544 {
545 GetLastRank()
546 return
547 }
548
549 new command[12], cmdmap[64]
550 parse(Msg, command, 11, cmdmap, 63)
551
552 replace_all(command, 11, "!", "")
553 replace_all(command, 11, "?", "")
554
555 if( equal(command, "pro15") )
556 {
557 if( is_map_valid(cmdmap) )
558 {
559 irc_sendpro15(PRO_TOP, cmdmap)
560 }
561 else if( !is_map_valid(cmdmap) && !equal(cmdmap, "") )
562 {
563 kzirc_setmsg("PRIVMSG %s :00,7 >> 0,1 KZTOP 0,7 >> 0,1 Invalid writing or not on our server 0,7 >> ^n", Kz_Irc_Channel)
564 }
565 else
566 {
567 irc_sendpro15(PRO_TOP)
568 }
569
570 return
571 }
572 else if( equal(command, "nub15") )
573 {
574 if( is_map_valid(cmdmap) )
575 {
576 irc_sendpro15(NUB_TOP, cmdmap)
577 }
578 else if( !is_map_valid(cmdmap) && !equal(cmdmap, "") )
579 {
580 kzirc_setmsg("PRIVMSG %s :00,7 >> 0,1 KZTOP 0,7 >> 0,1 Invalid writing or not on our server 0,7 >> ^n", Kz_Irc_Channel)
581 }
582 else
583 {
584 irc_sendpro15(NUB_TOP)
585 }
586
587 return
588 }
589
590 }
591}
592
593/*================================================================================================*/
594/*================================================================================================*/
595/*================================================================================================*/
596
597stock GetLastRank()
598{
599 new createinto[1001]
600
601 formatex(createinto, 1000, "SELECT `authid`, `mapname` FROM kz_pro15 ORDER BY date desc")
602 SQL_ThreadQuery(g_SqlTuple, "GetLastRank_QueryHandler", createinto)
603}
604
605/*================================================================================================*/
606
607public GetLastRank_QueryHandler(iFailState, Handle:hQuery, szError[], iErrnum, cData[], iSize, Float:fQueueTime)
608{
609 if( iFailState != TQUERY_SUCCESS )
610 {
611 return log_amx("TOP15 SQL: SQL Error #%d - %s", iErrnum, szError)
612 }
613
614 new authid[32], mapname[64], i, contadorlast, Handle:pepepin
615 new b_authid[32], b_name[32], b_mapname[64], Float:b_tiempo, b_eldia[64], Float:b_iSec, b_iMin
616
617 while( SQL_MoreResults(hQuery) )
618 {
619 if( contadorlast >= 5 )
620 break
621
622 SQL_ReadResult(hQuery, 0, authid, 31)
623 SQL_ReadResult(hQuery, 1, mapname, 63)
624
625 pepepin = SQL_PrepareQuery(SqlConnection, "SELECT * FROM `kz_pro15` WHERE mapname='%s' ORDER BY time LIMIT 15", mapname)
626
627 if( SQL_Execute(pepepin) )
628 {
629 i = 0
630 while( SQL_MoreResults(pepepin) )
631 {
632 i++
633 SQL_ReadResult(pepepin, 2, b_authid, 31)
634
635 if( equal(authid, b_authid) )
636 {
637 contadorlast++
638 SQL_ReadResult(pepepin, 0, b_mapname, 63)
639 SQL_ReadResult(pepepin, 3, b_name, 31)
640 SQL_ReadResult(pepepin, 4, b_tiempo)
641 SQL_ReadResult(pepepin, 5, b_eldia, 63)
642 new dia[32]
643 format_time(dia, 31, "%m.%d.%y", parse_time(b_eldia, "%Y-%m-%d %H:%M:%S") )
644 b_iMin = floatround(b_tiempo, floatround_floor)/60
645 b_iSec = b_tiempo - (60*b_iMin)
646
647
648 kzirc_setmsg("PRIVMSG %s :00,7 >> 9,1 #%d 0,1 %s 0,7 >> 0,1 %s 0,7 >> 0,1 %02d:%s%.6f 0,7 >> 0,1 %s 0,7 >> 0,7 >> ^n", Kz_Irc_Channel, i, b_name, b_mapname, b_iMin, b_iSec < 10 ? "0" : "", b_iSec, dia)
649 break;
650 }
651
652 SQL_NextRow(pepepin)
653 }
654
655 }
656
657 SQL_FreeHandle(pepepin)
658 SQL_NextRow(hQuery)
659 }
660
661 return PLUGIN_CONTINUE
662}
663
664/*================================================================================================*/
665/*================================================================================================*/
666/*================================================================================================*/
667
668stock irc_sendpro15(type, const map[64] = "")
669{
670 new mapname[64], cData[65], createinto[1001]
671 if( equal(map, "") )
672 {
673 get_mapname(mapname, 63)
674 }
675 else
676 {
677 mapname = map
678 }
679
680 cData[0] = type
681 copy(cData[1], 63, mapname)
682
683 formatex(createinto, 1000, "SELECT * FROM `%s` WHERE mapname='%s' ORDER BY time LIMIT 15", type == PRO_TOP ? "kz_pro15" : "kz_nub15", mapname)
684 SQL_ThreadQuery(g_SqlTuple, "IRC_Ranks_QueryHandler", createinto, cData, 65)
685
686}
687
688public IRC_Ranks_QueryHandler(iFailState, Handle:hQuery, szError[], iErrnum, cData[], iSize, Float:fQueueTime)
689{
690 if( iFailState != TQUERY_SUCCESS )
691 {
692 return log_amx("TOP15 SQL: SQL Error #%d - %s", iErrnum, szError)
693 }
694
695 new type = cData[0], i
696
697 kzirc_setmsg("PRIVMSG %s :00,7 >> 0,1 Listing %s of %s 0,7 >> ^n", Kz_Irc_Channel, type == PRO_TOP ? "Pro15" : "Nub15", cData[1])
698
699 new name[32], Float:tiempo, eldia[64], dia[32], server[32], ifnum15[32], weapon[32]
700
701 while( SQL_MoreResults(hQuery) )
702 {
703 i++
704 SQL_ReadResult(hQuery, 3, name, 31)
705 SQL_ReadResult(hQuery, 4, tiempo)
706 SQL_ReadResult(hQuery, 5, eldia, 31)
707 SQL_ReadResult(hQuery, 6, weapon, 31)
708
709
710 new iMin, Float:iSec
711 format_time(dia, 31, "%m.%d.%y", parse_time(eldia, "%Y-%m-%d %H:%M:%S") )
712 iMin = floatround(tiempo, floatround_floor)/60
713 iSec = tiempo - (60*iMin)
714
715 if( type == NUB_TOP )
716 {
717 formatex(ifnum15, 31, "0,1 %d 0,7 >> ", SQL_ReadResult(hQuery, 8) )
718 }
719
720 kzirc_setmsg("PRIVMSG %s :00,7 >> 9,1 #%d 0,1 %s 0,7 >> 0,1 %02d:%s%.6f 0,7 >> 0,1 %s 0,7 >> 0,1 %s 0,7 >> %s0,7 >> ^n", Kz_Irc_Channel, i, name, iMin, iSec < 10 ? "0" : "", iSec, dia, weapon, type == PRO_TOP ? "" : ifnum15)
721
722 SQL_NextRow(hQuery)
723 }
724
725 return PLUGIN_CONTINUE
726}
727
728#endif
729
730/*================================================================================================*/
731/*================================================================================================*/
732/*================================================================================================*/
733
734public client_putinserver(id)
735{
736 if( is_user_hltv(id) || is_user_bot(id) )
737 {
738 return
739 }
740
741 new createinto[1001], authid[32], cData[2]
742 get_user_authid(id, authid, 31)
743 cData[0] = id
744 cData[1] = 1
745
746 formatex(createinto, 1000, "SELECT `mapname` FROM kz_pro15 WHERE authid='%s' ORDER BY mapname", authid)
747 SQL_ThreadQuery(g_SqlTuple, "GetProRecords_QueryHandler", createinto, cData, 2)
748
749}
750
751public GetProRecords_QueryHandler(iFailState, Handle:hQuery, szError[], iErrnum, cData[], iSize, Float:fQueueTime)
752{
753 if( iFailState != TQUERY_SUCCESS )
754 {
755 return log_amx("TOP15 SQL: SQL Error #%d - %s", iErrnum, szError)
756 }
757
758 new id = cData[0]
759 new mapname[64], Handle:pepepin, steam[32]
760 new contadorpro = 0
761 get_user_authid(id, steam, 31)
762
763 while( SQL_MoreResults(hQuery) )
764 {
765 // Proximo mapa en la tabla...
766 SQL_ReadResult(hQuery, 0, mapname, 63)
767
768 // Tambien podemos hacer llamadas sin tener que redirigir todo a otra funcion....
769 // Aca usamos la Variable de la conexion y no la variable de la estructura de datos.
770 // Esta opcion esta buena cuando nos conectamos y desconectamos. Digamos, solo una consulta.
771 pepepin = SQL_PrepareQuery(SqlConnection, "SELECT authid FROM `kz_pro15` WHERE mapname='%s' ORDER BY time LIMIT 15", mapname)
772
773 // Si podemos ejecutar la informacion seguimos.
774 if( SQL_Execute(pepepin) )
775 {
776 // Mas Resultados en pepepin...
777 while( SQL_MoreResults(pepepin) )
778 {
779 // Esta ese jugador dentro de los 15 mejores del mapa?
780 new authid[32]
781 SQL_ReadResult(pepepin, 0, authid, 31)
782
783 // Si son iguales seguimos, contandooo..
784 if( equal(authid, steam) )
785 {
786 contadorpro++
787 break;
788 }
789
790 SQL_NextRow(pepepin) // Proxima columna...
791 }
792
793 }
794
795 SQL_FreeHandle(pepepin) // Limpiamos.
796
797 SQL_NextRow(hQuery) // Proxima columna de los mapa que tiene el player.
798 }
799
800 if( cData[1] == 1 )
801 {
802 new name[32], country[46], ip[32]
803 get_user_name(id, name, 31)
804 get_user_ip(id, ip, 31, 1)
805 kz_colorchat(0, "!t%s!g connected from (!t%s!g) with!t %d!g ProRecords", name, country, contadorpro)
806 #if defined USE_KZ_IRC
807 kzirc_setmsg("PRIVMSG %s :00,7 >> 0,1 %s (%s) 0,7 >> 0,1 Connect With 0,7 >> 0,1 %d ProRecords 0,7 >> ^n", Kz_Irc_Channel, name, steam, contadorpro)
808 #endif
809 }
810 else
811 {
812 kz_colorchat(id, "You have!t %d!g ProRecords", contadorpro)
813 }
814
815 return PLUGIN_CONTINUE
816
817}
818public sqlLoadTop()
819{
820 new Handle:sqlQuery
821 new Handle:Query,Handle:Tuple
822 static Error,szError[300]
823 new mapa[64]
824 get_mapname(mapa, sizeof mapa - 1 )
825 Query = SQL_MakeDbTuple("", "", "", DATABASE)
826 Tuple = SQL_Connect(Query,Error,szError,300)
827
828 sqlQuery = SQL_PrepareQuery(Tuple, "SELECT * FROM kz_pro15 WHERE mapname='%s' ORDER BY time DESC LIMIT 15;",mapa);
829
830 if(!SQL_Execute(sqlQuery)) // Si no se ejecuta la consulta...
831 checkError(sqlQuery, 1);
832
833 else if(SQL_NumResults(sqlQuery)) // Si la consulta arroja resultados...
834 {
835 g_top_menu = menu_create("\yTOP 15 - PROS^n\yPagina:\r", "menu_Nothing");
836
837 g_block_top_menu = 0;
838
839 new sData[128];
840 new sName[32];
841 new sPosition[5];
842
843 new iLevel;
844 new iPosition;
845
846 while(SQL_MoreResults(sqlQuery))
847 {
848 ++iPosition;
849
850 SQL_ReadResult(sqlQuery, 2, sName, charsmax(sName));
851 iLevel = SQL_ReadResult( sqlQuery, SQL_FieldNameToNum( sqlQuery, "time" ) );
852
853 num_to_str(iPosition, sPosition, charsmax(sPosition));
854
855 formatex(sData, charsmax(sData), "\r#%s \y- \w%s \y- \wTiempo \r%s",sPosition, sName, iLevel);
856 menu_addtext2( g_top_menu, sData);
857
858 SQL_NextRow(sqlQuery);
859 }
860
861 menu_setprop(g_top_menu, MPROP_NEXTNAME, "Siguiente");
862 menu_setprop(g_top_menu, MPROP_BACKNAME, "Atrás");
863 menu_setprop(g_top_menu, MPROP_EXITNAME, "Salir");
864
865 SQL_FreeHandle(sqlQuery);
866 }
867 else
868 {
869 g_block_top_menu = 1;
870 SQL_FreeHandle(sqlQuery); // Cerramos la consulta
871 }
872}
873public checkError(const Handle:sqlQuery, const query_num)
874{
875 SQL_QueryError(sqlQuery, g_sql_error, charsmax(g_sql_error)); // Guardamos el error en la variable g_sql_error
876
877 log_to_file("error_sql.log", "- CONSULTA: %d - ERROR: %s", query_num, g_sql_error); // Logeamos en un archivo el error y desde que consulta vino
878
879 SQL_FreeHandle(sqlQuery); // Cerramos la consulta
880}
881
882public clcmd_Top15(id)
883{
884 if(!is_user_connected(id))
885 return PLUGIN_HANDLED;
886
887 if(g_block_top_menu)
888 {
889 client_print(id, print_chat, "* El TOP15 está vacío!");
890 return PLUGIN_HANDLED;
891 }
892
893 menu_display(id, g_top_menu);
894
895 return PLUGIN_HANDLED;
896}
897
898public menu_Nothing(id, menuid, item)
899{
900 if(!is_user_connected(id) || item == MENU_EXIT)
901 return PLUGIN_HANDLED;
902
903 clcmd_Top15(id);
904 return PLUGIN_HANDLED;
905}