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