· 5 years ago · Jul 20, 2020, 03:54 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 formatex( createinto, sizeof createinto - 1, "INSERT INTO `%s` VALUES('%s','%s','%s','%f','%s','%s','%s'%s)", style == PRO_TOP ? "kz_pro15" : "kz_nub15", map, steam, name, ftime, dia, g_weaponsnames[str_to_num(x2)], style == PRO_TOP ? "" : gochecks)
247 SQL_ThreadQuery(g_SqlTuple, "QueryHandle", createinto)
248 GetNewRank(id, style)
249 }
250 else
251 {
252 new Float:qtime, minutos, Float:segundos, Float:mejorar
253 SQL_ReadResult(hQuery, 0, qtime)
254
255 if(ftime < qtime)
256 {
257 mejorar = qtime - ftime
258 minutos = floatround(mejorar, floatround_floor)/60
259 segundos = mejorar - (60*minutos)
260 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")
261 #if defined USE_KZ_IRC
262 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")
263 #endif
264 formatex(gochecks, 31, ", gocheck='%d'", str_to_num(x3))
265 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)
266 SQL_ThreadQuery(g_SqlTuple, "QueryHandle", createinto)
267 GetNewRank(id, style)
268
269 }
270 else
271 {
272 mejorar = ftime - qtime
273 minutos = floatround(mejorar, floatround_floor)/60
274 segundos = mejorar - (60*minutos)
275 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")
276 #if defined USE_KZ_IRC
277 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")
278 #endif
279 }
280 }
281
282 return PLUGIN_CONTINUE
283}
284/*================================================================================================*/
285/************************************** [New Rank Funccion] ***************************************/
286/*=============================================================================R=E=Y=M=O=N==A=R=G=*/
287
288stock GetNewRank(id, type)
289{
290 new createinto[1001], mapname[64]
291 get_mapname(mapname, 63)
292
293 new cData[2]
294 cData[0] = id
295 cData[1] = type
296
297 formatex(createinto, 1000, "SELECT authid FROM `%s` WHERE mapname='%s' ORDER BY time LIMIT 15", type == PRO_TOP ? "kz_pro15" : "kz_nub15", mapname)
298 SQL_ThreadQuery(g_SqlTuple, "GetNewRank_QueryHandler", createinto, cData, 2)
299}
300
301/*================================================================================================*/
302
303public GetNewRank_QueryHandler(iFailState, Handle:hQuery, szError[], iErrnum, cData[], iSize, Float:fQueueTime)
304{
305 new id = cData[0]
306 if( iFailState != TQUERY_SUCCESS )
307 {
308 return log_amx("TOP15 SQL: SQL Error #%d - %s", iErrnum, szError)
309 }
310
311 new steam[32], authid[32], name[32], i = 0
312 get_user_authid(id, steam, 31)
313 get_user_name(id, name, 31)
314
315 while( SQL_MoreResults(hQuery) )
316 {
317 i++
318 SQL_ReadResult(hQuery, 0, authid, 31)
319
320 if( equal(authid, steam) )
321 {
322 kz_colorchat(0, "!t%s!g new rank in!t %s!g [!t%d!g]", name, cData[1] == PRO_TOP ? "Pro15" : "Nub15", i)
323 #if defined USE_KZ_IRC
324 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)
325 #endif
326 break;
327 }
328
329 SQL_NextRow(hQuery)
330 }
331
332 return PLUGIN_CONTINUE
333}
334
335/*================================================================================================*/
336/*************************************** [Name Funccions] *****************************************/
337/*=============================================================================R=E=Y=M=O=N==A=R=G=*/
338
339public client_infochanged(id)
340{
341 if( !is_user_connected(id) && g_pluginload)
342 {
343 return PLUGIN_CONTINUE
344 }
345
346 new newname[32], oldname[32]
347
348 get_user_name(id, oldname, 31)
349 get_user_info(id, "name", newname, 31)
350
351 if(!equal(newname, oldname))
352 {
353 kz_update_plrname(id, newname, true)
354 }
355
356 return PLUGIN_CONTINUE
357}
358
359stock kz_update_plrname(id, const newname[32] = "", bool:shownew = false)
360{
361 new createinto[1001], steam[32], name[32]
362 get_user_authid(id, steam, 31)
363
364 if( equal(newname, "") )
365 get_user_name(id, name, 31)
366 else
367 name = newname
368
369 replace_all(name, 31, "\", "")
370 replace_all(name, 31, "`", "\`")
371 replace_all(name, 31, "'", "\'")
372
373 formatex(createinto, 1000, "UPDATE `kz_pro15` SET name='%s' WHERE authid='%s'", name, steam)
374 SQL_ThreadQuery(g_SqlTuple, "QueryHandle", createinto)
375 formatex(createinto, 1000, "UPDATE `kz_nub15` SET name='%s' WHERE authid='%s'", name, steam)
376 SQL_ThreadQuery(g_SqlTuple, "QueryHandle", createinto)
377
378 if( shownew )
379 kz_colorchat(id, "!tTOP15 SQL:!g Your new name for Top is: !t%s", name)
380
381 return 1
382}
383
384/*================================================================================================*/
385/*************************************** [Chats Funccions] ****************************************/
386/*=============================================================================R=E=Y=M=O=N==A=R=G=*/
387
388public kz_hookchat(id)
389{
390 new args[128]
391 read_args(args, 127)
392 remove_quotes(args)
393
394 // Is the message we are looking for
395 if( args[0] != '.' && args[0] != '/' )
396 return PLUGIN_CONTINUE
397
398 new command[12], cmdmap[64], mapname[64]
399 parse(args, command, 11, cmdmap, 63)
400
401 replace_all(command, 11, ".", "")
402 replace_all(command, 11, "/", "")
403
404 if( equal(command, "pro15") )
405 {
406 if( is_map_valid(cmdmap) )
407 {
408 kz_showhtml_motd(id, PRO_TOP, cmdmap)
409 }
410 else if( !is_map_valid(cmdmap) && !equal(cmdmap, "") )
411 {
412 kz_colorchat(id, "!tKZTOP: !gInvalid writing or not on our server")
413 }
414 else
415 {
416 get_mapname(mapname, 63)
417 kz_showhtml_motd(id, PRO_TOP, mapname)
418 }
419
420 return PLUGIN_HANDLED
421 }
422 else if( equal(command, "nub15") )
423 {
424 if( is_map_valid(cmdmap) )
425 {
426 kz_showhtml_motd(id, NUB_TOP, cmdmap)
427 }
428 else if( !is_map_valid(cmdmap) && !equal(cmdmap, "") )
429 {
430 kz_colorchat(id, "!tKZTOP: !gInvalid writing or not on our server")
431 }
432 else
433 {
434 get_mapname(mapname, 63)
435 kz_showhtml_motd(id, NUB_TOP, mapname)
436 }
437
438 return PLUGIN_HANDLED
439 }
440 else if( equal(command, "top15") )
441 {
442 kz_topsmenu(id)
443 return PLUGIN_HANDLED
444 }
445 else if( equal(command, "prorecords") || equal(command, "prorecs") )
446 {
447 new createinto[1001], authid[32], cData[2]
448 get_user_authid(id, authid, 31)
449 cData[0] = id
450 cData[1] = 0
451
452 formatex(createinto, 1000, "SELECT `mapname` FROM kz_pro15 WHERE authid='%s' ORDER BY mapname", authid)
453 SQL_ThreadQuery(g_SqlTuple, "GetProRecords_QueryHandler", createinto, cData, 2)
454 }
455
456 return PLUGIN_CONTINUE
457}
458
459/*================================================================================================*/
460
461stock kz_topsmenu(id, page = 0)
462{
463 new menu = menu_create("\r[Kz-Arg] \yTop15", "menufunc")
464
465 menu_additem(menu, "Pro15", "1")
466 menu_additem(menu, "Nub15", "2")
467 menu_additem(menu, "Last Pro15", "3")
468
469 menu_display(id, menu, page)
470}
471
472public menufunc(id, menu, item)
473{
474 if(item == MENU_EXIT)
475 {
476 return PLUGIN_HANDLED;
477 }
478
479 new data[6], iName[64], iaccess, callback, mapname[64]
480 menu_item_getinfo(menu, item, iaccess, data, 5, iName, 63, callback)
481 get_mapname(mapname, 63)
482
483 kz_showhtml_motd(id, str_to_num(data), mapname)
484
485 return PLUGIN_HANDLED
486}
487
488/*================================================================================================*/
489
490stock kz_showhtml_motd(id, type, const otherinfo[])
491{
492 new buffer[1001], namebuffer[64], filepath[96], completetype[64]
493
494 formatex(completetype, 63, "&map=%s", otherinfo)
495
496 switch( type )
497 {
498 case PRO_TOP:
499 {
500 formatex(namebuffer, 63, "[Kz-Arg] Pro15 of %s", equal(otherinfo, "") ? "All Maps" : otherinfo)
501 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))
502 }
503 case NUB_TOP:
504 {
505 formatex(namebuffer, 63, "[Kz-Arg] Nub15 of %s", equal(otherinfo, "") ? "All Maps" : otherinfo)
506 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))
507 }
508 case 3:
509 {
510 formatex(namebuffer, 63, "[Kz-Arg] Last %s Pro15", "10")
511 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))
512 }
513 }
514
515 show_motd(id, buffer, namebuffer)
516}
517
518/*================================================================================================*/
519/*================================================================================================*/
520/*================================================================================================*/
521/*================================================================================================*/
522/*================================================================================================*/
523#if defined USE_KZ_IRC
524
525public kzirc_recivemsg(const Channel[], const Msg[], const Name[], const Host[], id, access)
526{
527 //server_print("Channel: %s Msg: %s Name: %s Host: %s ID: %d Access: %d", Channel, Msg, Name, Host, id, access)
528
529 if( equal(Channel, Kz_Irc_Channel) )
530 {
531 if( equal(Msg, "!help") )
532 {
533 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)
534 return
535 }
536 else if( equal(Msg, "!lastpro") )
537 {
538 GetLastRank()
539 return
540 }
541
542 new command[12], cmdmap[64]
543 parse(Msg, command, 11, cmdmap, 63)
544
545 replace_all(command, 11, "!", "")
546 replace_all(command, 11, "?", "")
547
548 if( equal(command, "pro15") )
549 {
550 if( is_map_valid(cmdmap) )
551 {
552 irc_sendpro15(PRO_TOP, cmdmap)
553 }
554 else if( !is_map_valid(cmdmap) && !equal(cmdmap, "") )
555 {
556 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)
557 }
558 else
559 {
560 irc_sendpro15(PRO_TOP)
561 }
562
563 return
564 }
565 else if( equal(command, "nub15") )
566 {
567 if( is_map_valid(cmdmap) )
568 {
569 irc_sendpro15(NUB_TOP, cmdmap)
570 }
571 else if( !is_map_valid(cmdmap) && !equal(cmdmap, "") )
572 {
573 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)
574 }
575 else
576 {
577 irc_sendpro15(NUB_TOP)
578 }
579
580 return
581 }
582
583 }
584}
585
586/*================================================================================================*/
587/*================================================================================================*/
588/*================================================================================================*/
589
590stock GetLastRank()
591{
592 new createinto[1001]
593
594 formatex(createinto, 1000, "SELECT `authid`, `mapname` FROM kz_pro15 ORDER BY date desc")
595 SQL_ThreadQuery(g_SqlTuple, "GetLastRank_QueryHandler", createinto)
596}
597
598/*================================================================================================*/
599
600public GetLastRank_QueryHandler(iFailState, Handle:hQuery, szError[], iErrnum, cData[], iSize, Float:fQueueTime)
601{
602 if( iFailState != TQUERY_SUCCESS )
603 {
604 return log_amx("TOP15 SQL: SQL Error #%d - %s", iErrnum, szError)
605 }
606
607 new authid[32], mapname[64], i, contadorlast, Handle:pepepin
608 new b_authid[32], b_name[32], b_mapname[64], Float:b_tiempo, b_eldia[64], Float:b_iSec, b_iMin
609
610 while( SQL_MoreResults(hQuery) )
611 {
612 if( contadorlast >= 5 )
613 break
614
615 SQL_ReadResult(hQuery, 0, authid, 31)
616 SQL_ReadResult(hQuery, 1, mapname, 63)
617
618 pepepin = SQL_PrepareQuery(SqlConnection, "SELECT * FROM `kz_pro15` WHERE mapname='%s' ORDER BY time LIMIT 15", mapname)
619
620 if( SQL_Execute(pepepin) )
621 {
622 i = 0
623 while( SQL_MoreResults(pepepin) )
624 {
625 i++
626 SQL_ReadResult(pepepin, 2, b_authid, 31)
627
628 if( equal(authid, b_authid) )
629 {
630 contadorlast++
631 SQL_ReadResult(pepepin, 0, b_mapname, 63)
632 SQL_ReadResult(pepepin, 3, b_name, 31)
633 SQL_ReadResult(pepepin, 4, b_tiempo)
634 SQL_ReadResult(pepepin, 5, b_eldia, 63)
635 new dia[32]
636 format_time(dia, 31, "%m.%d.%y", parse_time(b_eldia, "%Y-%m-%d %H:%M:%S") )
637 b_iMin = floatround(b_tiempo, floatround_floor)/60
638 b_iSec = b_tiempo - (60*b_iMin)
639
640
641 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)
642 break;
643 }
644
645 SQL_NextRow(pepepin)
646 }
647
648 }
649
650 SQL_FreeHandle(pepepin)
651 SQL_NextRow(hQuery)
652 }
653
654 return PLUGIN_CONTINUE
655}
656
657/*================================================================================================*/
658/*================================================================================================*/
659/*================================================================================================*/
660
661stock irc_sendpro15(type, const map[64] = "")
662{
663 new mapname[64], cData[65], createinto[1001]
664 if( equal(map, "") )
665 {
666 get_mapname(mapname, 63)
667 }
668 else
669 {
670 mapname = map
671 }
672
673 cData[0] = type
674 copy(cData[1], 63, mapname)
675
676 formatex(createinto, 1000, "SELECT * FROM `%s` WHERE mapname='%s' ORDER BY time LIMIT 15", type == PRO_TOP ? "kz_pro15" : "kz_nub15", mapname)
677 SQL_ThreadQuery(g_SqlTuple, "IRC_Ranks_QueryHandler", createinto, cData, 65)
678
679}
680
681public IRC_Ranks_QueryHandler(iFailState, Handle:hQuery, szError[], iErrnum, cData[], iSize, Float:fQueueTime)
682{
683 if( iFailState != TQUERY_SUCCESS )
684 {
685 return log_amx("TOP15 SQL: SQL Error #%d - %s", iErrnum, szError)
686 }
687
688 new type = cData[0], i
689
690 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])
691
692 new name[32], Float:tiempo, eldia[64], dia[32], server[32], ifnum15[32], weapon[32]
693
694 while( SQL_MoreResults(hQuery) )
695 {
696 i++
697 SQL_ReadResult(hQuery, 3, name, 31)
698 SQL_ReadResult(hQuery, 4, tiempo)
699 SQL_ReadResult(hQuery, 5, eldia, 31)
700 SQL_ReadResult(hQuery, 6, weapon, 31)
701
702
703 new iMin, Float:iSec
704 format_time(dia, 31, "%m.%d.%y", parse_time(eldia, "%Y-%m-%d %H:%M:%S") )
705 iMin = floatround(tiempo, floatround_floor)/60
706 iSec = tiempo - (60*iMin)
707
708 if( type == NUB_TOP )
709 {
710 formatex(ifnum15, 31, "0,1 %d 0,7 >> ", SQL_ReadResult(hQuery, 8) )
711 }
712
713 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)
714
715 SQL_NextRow(hQuery)
716 }
717
718 return PLUGIN_CONTINUE
719}
720
721#endif
722
723/*================================================================================================*/
724/*================================================================================================*/
725/*================================================================================================*/
726
727public client_putinserver(id)
728{
729 if( is_user_hltv(id) || is_user_bot(id) )
730 {
731 return
732 }
733
734 new createinto[1001], authid[32], cData[2]
735 get_user_authid(id, authid, 31)
736 cData[0] = id
737 cData[1] = 1
738
739 formatex(createinto, 1000, "SELECT `mapname` FROM kz_pro15 WHERE authid='%s' ORDER BY mapname", authid)
740 SQL_ThreadQuery(g_SqlTuple, "GetProRecords_QueryHandler", createinto, cData, 2)
741
742}
743
744public GetProRecords_QueryHandler(iFailState, Handle:hQuery, szError[], iErrnum, cData[], iSize, Float:fQueueTime)
745{
746 if( iFailState != TQUERY_SUCCESS )
747 {
748 return log_amx("TOP15 SQL: SQL Error #%d - %s", iErrnum, szError)
749 }
750
751 new id = cData[0]
752 new mapname[64], Handle:pepepin, steam[32]
753 new contadorpro = 0
754 get_user_authid(id, steam, 31)
755
756 while( SQL_MoreResults(hQuery) )
757 {
758 // Proximo mapa en la tabla...
759 SQL_ReadResult(hQuery, 0, mapname, 63)
760
761 // Tambien podemos hacer llamadas sin tener que redirigir todo a otra funcion....
762 // Aca usamos la Variable de la conexion y no la variable de la estructura de datos.
763 // Esta opcion esta buena cuando nos conectamos y desconectamos. Digamos, solo una consulta.
764 pepepin = SQL_PrepareQuery(SqlConnection, "SELECT authid FROM `kz_pro15` WHERE mapname='%s' ORDER BY time LIMIT 15", mapname)
765
766 // Si podemos ejecutar la informacion seguimos.
767 if( SQL_Execute(pepepin) )
768 {
769 // Mas Resultados en pepepin...
770 while( SQL_MoreResults(pepepin) )
771 {
772 // Esta ese jugador dentro de los 15 mejores del mapa?
773 new authid[32]
774 SQL_ReadResult(pepepin, 0, authid, 31)
775
776 // Si son iguales seguimos, contandooo..
777 if( equal(authid, steam) )
778 {
779 contadorpro++
780 break;
781 }
782
783 SQL_NextRow(pepepin) // Proxima columna...
784 }
785
786 }
787
788 SQL_FreeHandle(pepepin) // Limpiamos.
789
790 SQL_NextRow(hQuery) // Proxima columna de los mapa que tiene el player.
791 }
792
793 if( cData[1] == 1 )
794 {
795 new name[32], country[46], ip[32]
796 get_user_name(id, name, 31)
797 get_user_ip(id, ip, 31, 1)
798 kz_colorchat(0, "!t%s!g connected from (!t%s!g) with!t %d!g ProRecords", name, country, contadorpro)
799 #if defined USE_KZ_IRC
800 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)
801 #endif
802 }
803 else
804 {
805 kz_colorchat(id, "You have!t %d!g ProRecords", contadorpro)
806 }
807
808 return PLUGIN_CONTINUE
809
810}
811/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
812*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang11274\\ f0\\ fs16 \n\\ par }
813*/