· 8 years ago · Feb 12, 2018, 09:28 PM
1/*
2Notice:
3---------------
4- Requires Simple Chat Processor (Redux)
5- Get It Here: https://forums.alliedmods.net/showthread.php?p=1820365
6
7Pending:
8---------------
9- Add minimum players. V
10- Track maps that players complete, total % of maps completed, etc. V
11- Connect message showing rank. V
12
13Revision 1.0.5c
14---------------
15- Fixed an issue where steam universe was allowed to be CS:GO+ if a client failed initial auth and required secondary checks added in 1.0.5b.
16- Added Impact123's AutoExecConfig (Link within Source) so future revisions automatically update the plugin's configuration file.
17- Renamed plugin from timer-ranks to timer-rankings, also renamed plugin configuration file from timer-ranks to timer-rankings.
18- Added ConVar timer_ranks_enabled, which globally enables/disables plugin.
19- Implemented debug mode, activated on timer_ranks_enabled 2, which logs information to logs/timer-rankings.debug.log.
20- Cached/Optimized usage of all convars for the plugin.
21- Cleaned up the phrasing of defined convars.
22- Changed default configuration file from /configs/timer/ranks.configs.cfg to /configs/timer/rankings.cfg
23--- Cleaned up the default information found within rankings.cfg to be a bit more user friendly.
24- Added support for new configuration file /configs/timer/rankings.maps.cfg
25--- Any maps defined within will use the specified default worth instead of using timer_ranks_default_worth.
26
27Revision 1.0.5d (OCD CHANGES!!! OH NOES!)
28---------------
29- ServerCommand timer_printranks renamed to timer_rankingsdump; corresponding debug file renamed to /logs/timer-rankings.dump.log.
30- Plugin translation file renamed from timer-ranks.phrases.txt to timer-rankings.phrases.txt
31- Plugin registers itself as timer-rankings instead of timer-ranks.
32- Depreciated ConVar timer_ranks_client_default.
33- Expanded functionality of ConVar timer_ranks_display_method:
34--- Controls what features are enabled; any feature that's left off the plugin will ignore.
35--- Positive values force those features upon clients and they cannot be disabled.
36--- Negative values control what features clients can enable/disable, as well as their defaults.
37--- Example: timer_ranks_display_method 15 - ScoreTag, ScoreStars, ChatTag, ChatColor are all forced.
38--- Example: timer_ranks_display_method -7 - ScoreTag, ChatTag, and ChatColor can be enabled/disabled. ScoreStars are hidden.
39- Implemented several new elements of code that had been developed during [SM] TIme Tracker.
40--- OnChatMessage now correctly obeys features being enabled / disabled.
41--- Colors are now properly formated on usage, removing redundant code on load.
42--- {teamcolor} is now properly formated for teams on both CS:S and CS:GO.
43--- Global rank messages now have a cooldown of 60 seconds vs original 5 seconds, optimized segment.
44--- Client display choices, from timer_ranks_display_method < 0, are now saved rather than resetting on connect.
45- Fixed a bug where the Show Rank command was off by one value. 1st place would show rank 0 of x.
46- Removed confirmation phrases that appeared when toggling client display features.
47- Added support for Scoreboard Stars (MVP) to the Cookie Menu and View Positions menu.
48- Fixed numerous bugs within the Cookie Menu concerning translation usage.
49- Removed the ability to disable all features within the Cookie Menu at once (redundant).
50- The player's name now appears within the View Positions menu if a Chat Tag is available, showing any colors available.
51- Updating timer_ranks_display_method from positive to negative takes effect instantly.
52- Cleaned up failing logic and messages for all administrator commands; also changed printing functionality
53--- Excluding the list* commands, remaining admin commands print messages to all in-game admins and prints to sourcemod logs.
54--- timer_changerankpoints now correctly updates a client's points vs overwriting it.
55- Added support for displaying a # within Menu_Top_Option/Menu_Next_Option translations. Ex: (#1) Name, Points
56- All menus disappear after 30 seconds of no selection vs infinite prior.
57
58Revision 1.0.5e
59---------------
60- Added convar timer_ranks_limit_top_page, which controls how many entries per page appear for Top Players and Next Players
61- Added convar timer_ranks_settings_menu, which controls whether or not !settings receives an entry for the plugin.
62- Added Settings support for [Timer] Rankings, which has the same features as the chat commands in menu form.
63- 8 New Translations (Bottom of timer-rankings.phrases.txt, marked v1.0.5e
64- Implemented code to ignore all bots, if for whatever reason they're available (or replay/sourcetv).
65
66Revision 1.0.6
67--------------
68- Added convar timer_ranks_finishprec, which controls how much precent you get from finish the map and the stages
69- Added difficulty support
70- Added stage support
71- Added geo rank
72- Removed Multiple Completions
73- Changed from morecolors/colors to timer-colors that combine both
74- UpdateClientTag moved to timer-hud
75
76IMPORTANT CHANGES
77--- CONFIGURATION: NOW CALLED rankings.cfg
78--- TRANSLATIONS: NOW CALLED timer-rankings.phrases.txt
79--- PLUGIN: NOW CALLED timer-rankings
80*/
81
82#pragma semicolon 1
83#define PLUGIN_VERSION "1.0.406"
84
85#include <sourcemod>
86#include <sdktools>
87#include <sdkhooks>
88#include <cstrike>
89#include <timer>
90#include <timer-worldrecord>
91#include <timer-logging>
92#include <clientprefs>
93#include <geoip>
94#include <autoexecconfig> //https://github.com/Impact123/AutoExecConfig
95#include <scp>
96
97#undef REQUIRE_PLUGIN
98#include <timer-mapzones>
99#include <timer-physics>
100
101
102//* * * * * * * * * * * * * * * * * * * * * * * * * *
103//Defines
104//* * * * * * * * * * * * * * * * * * * * * * * * * *
105#define MAX_TAG_LENGTH 256
106//- States for plugin commands.
107#define cChatCookie 0
108#define cChatTop 1
109#define cChatRank 2
110#define cChatView 3
111#define cChatWorth 4
112#define cChatNext 5
113#define cChatTopCountry 6
114#define cChatRankCountry 7
115//- States for displaying data.
116#define cDisplayNone 0
117#define cDisplayChatTag 1
118#define cDisplayChatColor 2
119#define cDisplayScoreTag 4
120#define cDisplayScoreStars 8
121//- Cooldown for global messages.
122#define cGlobalCooldown 60
123//- States for debugging mode.
124#define cPrintRanks 1
125#define cPrintMaps 2
126#define cPrintPlayers 4
127//* * * * * * * * * * * * * * * * * * * * * * * * * *
128//Handles
129//* * * * * * * * * * * * * * * * * * * * * * * * * *
130new Handle:g_hEnabled = INVALID_HANDLE;
131new Handle:g_hDatabase = INVALID_HANDLE;
132new Handle:g_hDisplayMethod = INVALID_HANDLE;
133new Handle:g_hRequiredPoints = INVALID_HANDLE;
134new Handle:g_hGlobalMessage = INVALID_HANDLE;
135new Handle:g_hPositionMethod = INVALID_HANDLE;
136new Handle:g_hLimitTopPlayers = INVALID_HANDLE;
137new Handle:g_hDefaultWorth = INVALID_HANDLE;
138new Handle:g_hAdvertisement = INVALID_HANDLE;
139new Handle:g_hDisplayCookie = INVALID_HANDLE;
140new Handle:g_hTrie_CfgCommands = INVALID_HANDLE;
141new Handle:g_hTrie_CfgMaps = INVALID_HANDLE;
142new Handle:g_hTrie_CfgWorth = INVALID_HANDLE;
143new Handle:g_hTrie_CfgTier = INVALID_HANDLE;
144new Handle:g_hArray_InitalizeCleanup = INVALID_HANDLE;
145new Handle:g_hCfgArray_DisplayTag = INVALID_HANDLE;
146new Handle:g_hCfgArray_DisplayInfo = INVALID_HANDLE;
147new Handle:g_hCfgArray_DisplayStars = INVALID_HANDLE;
148new Handle:g_hCfgArray_DisplayChat = INVALID_HANDLE;
149new Handle:g_hCfgArray_DisplayColor = INVALID_HANDLE;
150new Handle:g_hArray_CfgPoints = INVALID_HANDLE;
151new Handle:g_hArray_CfgRanks = INVALID_HANDLE;
152new Handle:g_hArray_Positions = INVALID_HANDLE;
153new Handle:g_hSettingsMenu = INVALID_HANDLE;
154new Handle:g_hLimitTopPerPage = INVALID_HANDLE;
155new Handle:g_hFinishPercentage = INVALID_HANDLE;
156new Handle:g_hPointFarmingFactor = INVALID_HANDLE;
157//* * * * * * * * * * * * * * * * * * * * * * * * * *
158//Variables
159//* * * * * * * * * * * * * * * * * * * * * * * * * *
160new bool:g_bLateLoad;
161new bool:g_bTimerPhysics;
162new bool:g_bTimerMapZones;
163new bool:g_bLateQuery;
164new bool:g_bSql;
165new bool:g_bInitalizing;
166new bool:g_bGlobalMessage;
167new bool:g_bSettingsMenu;
168new g_iEnabled;
169new g_iTotalDiff;
170new g_iCurrentMapWorth;
171new g_iCurrentMapTier;
172new g_iTotalRanks;
173new g_iTotalPlayers;
174new g_iDiffPoints[32];
175new g_iInitalizeQueries;
176new g_iHighestRank;
177new g_iDisplayMethod;
178new g_iRequiredPoints;
179new g_iPositionMethod;
180new g_iLimitTopPlayers;
181new g_iDefaultMapWorth;
182new g_iDebugIndex = 1;
183new g_iCurrentDebug = -1;
184new g_iLimitTopPerPage;
185new Float:g_fAdvertisement;
186new Float:g_fDiffFactor[32];
187new Float:g_fFinishPrec;
188new Float:g_fPointFarmingFactor;
189new String:g_sLoadingScoreTag[64];
190new String:g_sLoadingChatTag[64];
191new String:g_sLoadingChatColor[64];
192new String:g_sCurrentMap[PLATFORM_MAX_PATH];
193new String:g_sPluginLog[PLATFORM_MAX_PATH];
194new String:g_sDumpLog[PLATFORM_MAX_PATH];
195//* * * * * * * * * * * * * * * * * * * * * * * * * *
196//Client Data
197//* * * * * * * * * * * * * * * * * * * * * * * * * *
198new bool:g_bComplete[MAXPLAYERS + 1][32];
199new bool:g_bStageComplete[MAXPLAYERS+1][64][32];
200new g_iStageCompletionsProgress[MAXPLAYERS+1];
201new g_iDifficultyCompletionsProgress[MAXPLAYERS+1];
202new g_iCurrentPoints[MAXPLAYERS + 1];
203new g_iNextIndex[MAXPLAYERS + 1] = { -1, ... };
204new g_iCurrentIndex[MAXPLAYERS + 1] = { -1, ... };
205new g_iLastGlobalMessage[MAXPLAYERS + 1];
206new String:g_sAuth[MAXPLAYERS + 1][24];
207new String:g_sMapChoosed[MAXPLAYERS + 1][64];
208new String:g_sChoosedName[MAXPLAYERS+1][64];
209new String:g_sChoosedCountry[MAXPLAYERS+1][64];
210new String:g_sCountry[MAXPLAYERS+1][64];
211new g_iChoosedPoints[MAXPLAYERS+1];
212new g_iChoosedTopMenuRank[MAXPLAYERS+1];
213new bool:g_bLoadedSQL[MAXPLAYERS + 1];
214new bool:g_bAuthed[MAXPLAYERS + 1];
215new g_iClientDisplay[MAXPLAYERS + 1];
216new bool:g_bLoadedCookies[MAXPLAYERS + 1];
217new g_iRank[MAXPLAYERS+1] = {-1, ...};
218new g_iCountryRank[MAXPLAYERS+1];
219new g_iTotalRanksCountry[MAXPLAYERS+1];
220new bool:g_bConnected[MAXPLAYERS+1] = {false, ...};
221new bool:g_bVip[MAXPLAYERS+1] = {false, ...};
222new bool:g_bForcedVip[MAXPLAYERS+1] = {false, ...};
223new String:g_sVipString[MAXPLAYERS+1][MAX_TAG_LENGTH];
224new String:g_sVipTextString[MAXPLAYERS+1][MAX_TAG_LENGTH];
225new String:g_sSetVipAuth[MAXPLAYERS+1][64];
226new bool:g_bSemiVip[MAXPLAYERS+1];
227
228public Plugin:myinfo =
229{
230 name = "[Timer] Rankings",
231 author = "Panduh (AlliedMods: thetwistedpanda) | Ofir",
232 description = "An advanced ranking component designed for servers running alongub's [Timer] plugin, providing competitive ranking",
233 version = PLUGIN_VERSION,
234 url = "http://forums.alliedmods.com/"
235};
236
237public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
238{
239 g_bLateLoad = g_bLateQuery = late;
240 CreateNative("Timer_GetClientPoints", Native_GetClientPoints);
241 CreateNative("Timer_GetClientRank", Native_GetClientRank);
242 CreateNative("Timer_GetClientTag", Native_GetClientTag);
243 CreateNative("Timer_GetClientChatTag", Native_GetClientChatTag);
244 CreateNative("Timer_GetTotalRankedPlayers", Native_GetTotalRankedPlayers);
245 CreateNative("Timer_GetTotalRankedPlayersCountry", Native_GetTotalRankedPlayersCountry);
246 CreateNative("Timer_GetClientCountryRank", Native_GetClientCountryRank);
247 RegPluginLibrary("timer-rankings");
248
249 if(late)
250 {
251 for(new i = 1; i <= MaxClients; i++)
252 {
253 if(i >= 1 && i <= MaxClients && IsClientInGame(i))
254 {
255 OnClientPostAdminCheck(i);
256 }
257 }
258 }
259
260 return APLRes_Success;
261}
262
263public OnLibraryAdded(const String:name[])
264{
265 if (StrEqual(name, "timer-physics"))
266 {
267 g_bTimerPhysics = true;
268 }
269 else if(StrEqual(name, "timer-mapzones"))
270 {
271 g_bTimerMapZones = true;
272 }
273}
274
275public OnLibraryRemoved(const String:name[])
276{
277 if (StrEqual(name, "timer-physics"))
278 {
279 g_bTimerPhysics = false;
280 }
281 else if(StrEqual(name, "timer-mapzones"))
282 {
283 g_bTimerMapZones = false;
284 }
285}
286
287public OnPluginStart()
288{
289 AutoExecConfig_SetFile("timer-rankings");
290
291 LoadTranslations("common.phrases");
292 LoadTranslations("timer-rankings.phrases");
293 g_bTimerPhysics = LibraryExists("timer-physics");
294 g_bTimerMapZones = LibraryExists("timer-mapzones");
295 AutoExecConfig_CreateConVar("timer_ranks_version", PLUGIN_VERSION, "[Timer] Rankings: Version", FCVAR_PLUGIN|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
296
297 g_hEnabled = AutoExecConfig_CreateConVar("timer_ranks_enabled", "1", "Determines operating mode of the plugin. (0 = Disabled, 1 = Enabled, 2 = Debug)", FCVAR_NONE, true, 0.0, true, 2.0);
298 HookConVarChange(g_hEnabled, OnCVarChange);
299 g_iEnabled = GetConVarInt(g_hEnabled);
300
301 g_hDisplayMethod = AutoExecConfig_CreateConVar("timer_ranks_display_method", "3", "Determines what information is displayed by clients. Negative / Positives cannot be combined. Positives will force the feature, negatives will allow clients to toggle it on/off. Values that are left off will be ignored by the plugin. (-1/1 = Chat Tag, -2/2 = Text Color, -4/4 = Scoreboard Tag, -8/8 = Scoreboard Stars)", FCVAR_NONE, true, -15.0, true, 15.0);
302 HookConVarChange(g_hDisplayMethod, OnCVarChange);
303 g_iDisplayMethod = GetConVarInt(g_hDisplayMethod);
304
305 g_hRequiredPoints = AutoExecConfig_CreateConVar("timer_ranks_minimum_points", "20", "Optional requirement that determines the minimum number of points a client must possess to be in any rankings.", FCVAR_NONE, true, 0.0);
306 HookConVarChange(g_hRequiredPoints, OnCVarChange);
307 g_iRequiredPoints = GetConVarInt(g_hRequiredPoints);
308
309 g_hGlobalMessage = AutoExecConfig_CreateConVar("timer_ranks_global_messages", "0", "If enabled, a message will be sent to all players when a client checks their rank, otherwise only the issuing client will receive the message.", FCVAR_NONE, true, 0.0, true, 1.0);
310 HookConVarChange(g_hGlobalMessage, OnCVarChange);
311 g_bGlobalMessage = GetConVarBool(g_hGlobalMessage);
312
313 g_hPositionMethod = AutoExecConfig_CreateConVar("timer_ranks_position_method", "1", "Determines what method will be used to determine rank positions in-game. (0 = Based on clients' total number of points, 1 = Based on the clients' current rank within the server)", FCVAR_NONE, true, 0.0, true, 1.0);
314 HookConVarChange(g_hPositionMethod, OnCVarChange);
315 g_iPositionMethod = GetConVarInt(g_hPositionMethod);
316
317 g_hLimitTopPlayers = AutoExecConfig_CreateConVar("timer_ranks_limit_top_players", "100", "The maximum number of players to be pulled for the Top Players command.", FCVAR_NONE, true, 0.0);
318 HookConVarChange(g_hLimitTopPlayers, OnCVarChange);
319 g_iLimitTopPlayers = GetConVarInt(g_hLimitTopPlayers);
320
321 g_hDefaultWorth = AutoExecConfig_CreateConVar("timer_ranks_default_worth", "10", "The default number of points map completions are worth before modification, unless a default worth is already defined within configs/timer/rankings.maps.cfg.", FCVAR_NONE, true, 0.0);
322 HookConVarChange(g_hDefaultWorth, OnCVarChange);
323 g_iDefaultMapWorth = GetConVarInt(g_hDefaultWorth);
324
325 g_hAdvertisement = AutoExecConfig_CreateConVar("timer_ranks_adverts", "0.0", "Optional feature that prints the translation phrase `Advertisement` every x.x seconds. (0.0 = Disabled)", FCVAR_NONE, true, 0.0);
326 HookConVarChange(g_hAdvertisement, OnCVarChange);
327 g_fAdvertisement = GetConVarFloat(g_hAdvertisement);
328
329 g_hLimitTopPerPage = AutoExecConfig_CreateConVar("timer_ranks_limit_top_page", "0", "The maximum number of entries to show per page for the Top Players command. (0 = Default)", FCVAR_NONE, true, 0.0);
330 HookConVarChange(g_hLimitTopPerPage, OnCVarChange);
331 g_iLimitTopPerPage = GetConVarInt(g_hLimitTopPerPage);
332
333 g_hSettingsMenu = AutoExecConfig_CreateConVar("timer_ranks_settings_menu", "1", "If enabled, the plugin will receive it's own entry in the !settings with shortcuts to all commands. Restart required to disable.", FCVAR_NONE, true, 0.0, true, 1.0);
334 HookConVarChange(g_hSettingsMenu, OnCVarChange);
335 g_bSettingsMenu = GetConVarBool(g_hSettingsMenu);
336
337 g_hFinishPercentage = AutoExecConfig_CreateConVar("timer_ranks_finishprec", "0.5", "Percentage bonus when you finish the whole map", FCVAR_NONE, true, 0.0);
338 HookConVarChange(g_hFinishPercentage, OnCVarChange);
339 g_fFinishPrec = GetConVarFloat(g_hFinishPercentage);
340
341 g_hPointFarmingFactor = AutoExecConfig_CreateConVar("timer_ranks_pointfactor", "0", "How much percentage of the points player gets when they finish after the first time, 0 - To disable, 0.5 - to half", FCVAR_NONE, true, 0.0);
342 HookConVarChange(g_hPointFarmingFactor, OnCVarChange);
343 g_fPointFarmingFactor = GetConVarFloat(g_hPointFarmingFactor);
344
345 AutoExecConfig_ExecuteFile();
346 AutoExecConfig_CleanFile();
347
348 if(!SQL_CheckConfig("timer"))
349 {
350 SetFailState("[Timer] Ranking Stopped - There is no 'timer' entry within databases.cfg!");
351 }
352
353 AddCommandListener(Command_Say, "say");
354 AddCommandListener(Command_Say, "say_team");
355 RegConsoleCmd("sm_chatranks", Command_ChatRanks, "Show Chat Ranks in Chat");
356 RegAdminCmd("sm_setmapworth", Command_SetMapPoints, ADMFLAG_KICK, "Usage: timer_setmapworth <amount> <map> | An amount of -1 will remove it from the database.");
357 RegAdminCmd("sm_setpoints", Command_SetMapPoints, ADMFLAG_KICK, "Usage: timer_setmapworth <amount> <map> | An amount of -1 will remove it from the database.");
358 RegAdminCmd("sm_settier", Command_SetMapTier, ADMFLAG_KICK, "Usage: timer_settier <tier> <map> | An amount of -1 will remove it from the database.");
359 RegAdminCmd("timer_setrankpoints", Command_SetRankPoints, ADMFLAG_CHEATS, "Usage: timer_setrankpoints <steam> <amount> | <steam> must exist otherwise the operation fails.");
360 RegAdminCmd("timer_changerankpoints", Command_ChangeRankPoints, ADMFLAG_CHEATS, "Usage: timer_changerankpoints <steam> <amount> | <steam> must exist otherwise the operation fails. | Positive to add, Negative to subtract.");
361 RegAdminCmd("timer_initalizeranks", Command_InitalizeRanks, ADMFLAG_ROOT, "Erases existing ranking information and re-creates it based on newest information from core databases.");
362 RegAdminCmd("timer_initalizemaps", Command_InitalizeRanksMaps, ADMFLAG_ROOT, "Ensures all maps currently found within `ranks` are added to the map database with timer_ranks_default_worth points.");
363 RegAdminCmd("timer_listranks", Command_ListRanks, ADMFLAG_KICK, "Queries the database for all ranking information and displays it to server console or issuing admin.");
364 RegAdminCmd("timer_listmaps", Command_ListMaps, ADMFLAG_KICK, "Queries the database for all map configurations and displays it to server console or issuing admin.");
365 RegAdminCmd("sm_addvip", Command_AddVip, ADMFLAG_KICK);
366 RegAdminCmd("sm_deletevip", Command_RemoveVip, ADMFLAG_KICK);
367 RegAdminCmd("sm_removevip", Command_RemoveVip, ADMFLAG_KICK);
368 RegConsoleCmd("sm_settag", Command_SetTag);
369 RegConsoleCmd("sm_addtotag", Command_AddToTag);
370 RegConsoleCmd("sm_settext", Command_SetText);
371 RegConsoleCmd("sm_viphelp", Command_VipHelp);
372 RegConsoleCmd("sm_printtag", Command_PrintTag);
373 RegConsoleCmd("sm_printtext", Command_PrintTag);
374 RegConsoleCmd("sm_vip", Command_VipHelp);
375
376 RegAdminCmd("sm_setforcedtag", Command_SetForcedTag, ADMFLAG_ROOT);
377
378 HookEvent("player_spawn", Event_OnPlayerSpawn);
379 HookEvent("player_team", Event_OnPlayerTeam);
380 HookEvent("player_connect", Event_OnPlayerConnect, EventHookMode_Pre);
381 HookEvent("player_disconnect", Event_OnPlayerDisconnect, EventHookMode_Pre);
382
383 if(g_iDisplayMethod < 0)
384 {
385 g_hDisplayCookie = RegClientCookie("Timer-Ranks-Display", "Determines the display method for [Timer] Ranks.", CookieAccess_Private);
386 }
387
388 if(g_bSettingsMenu)
389 {
390 decl String:sFormat[64];
391 Format(sFormat, sizeof(sFormat), "%T", "Menu_Core_Title", LANG_SERVER);
392 SetCookieMenuItem(Menu_Settings, 0, sFormat);
393 }
394
395 BuildPath(Path_SM, g_sPluginLog, sizeof(g_sPluginLog), "logs/timer-rankings.debug.log");
396 BuildPath(Path_SM, g_sDumpLog, sizeof(g_sDumpLog), "logs/timer-rankings.dump.log");
397 RegServerCmd("timer_rankingsdump", Command_PrintRanks, "Generates a dump file in /logs/ that contains all definitions and rankings.");
398}
399
400public Menu_Settings(client, CookieMenuAction:action, any:info, String:buffer[], maxlen)
401{
402 switch(action)
403 {
404 case CookieMenuAction_DisplayOption:
405 Format(buffer, maxlen, "%t", "Menu_Core_Title", client);
406 case CookieMenuAction_SelectOption:
407 CreateSettingsMenu(client);
408 }
409}
410
411public OnCVarChange(Handle:cvar, const String:oldvalue[], const String:newvalue[])
412{
413 if(cvar == g_hEnabled)
414 {
415 g_iEnabled = StringToInt(newvalue);
416 }
417 else if(cvar == g_hDisplayMethod)
418 {
419 g_iDisplayMethod = StringToInt(newvalue);
420
421 if(g_iDisplayMethod < 0 && g_hDisplayCookie == INVALID_HANDLE)
422 {
423 g_hDisplayCookie = RegClientCookie("Timer-Ranks-Display", "Determines the display method for [Timer] Ranks.", CookieAccess_Private);
424 for(new i = 1; i <= MaxClients; i++)
425 {
426 if(IsClientInGame(i) && g_bAuthed[i] && !g_bLoadedCookies[i] && AreClientCookiesCached(i))
427 {
428 LoadClientData(i);
429 }
430 }
431 }
432 }
433 else if(cvar == g_hRequiredPoints)
434 {
435 g_iRequiredPoints = StringToInt(newvalue);
436 }
437 else if(cvar == g_hGlobalMessage)
438 {
439 g_bGlobalMessage = bool:StringToInt(newvalue);
440 }
441 else if(cvar == g_hPositionMethod)
442 {
443 g_iPositionMethod = StringToInt(newvalue);
444 }
445 else if(cvar == g_hLimitTopPlayers)
446 {
447 g_iLimitTopPlayers = StringToInt(newvalue);
448 }
449 else if(cvar == g_hDefaultWorth)
450 {
451 g_iDefaultMapWorth = StringToInt(newvalue);
452 }
453 else if(cvar == g_hAdvertisement)
454 {
455 g_fAdvertisement = StringToFloat(newvalue);
456 }
457 else if(cvar == g_hLimitTopPerPage)
458 {
459 g_iLimitTopPerPage = StringToInt(newvalue);
460 }
461 else if(cvar == g_hSettingsMenu)
462 {
463 g_bSettingsMenu = bool:StringToInt(newvalue);
464 }
465 else if(cvar == g_hFinishPercentage)
466 {
467 g_fFinishPrec = StringToFloat(newvalue);
468 }
469 else if(cvar == g_hPointFarmingFactor)
470 {
471 g_fPointFarmingFactor = StringToFloat(newvalue);
472 }
473}
474
475
476public OnConfigsExecuted()
477{
478 if(!g_iEnabled)
479 return;
480
481 Parse_Difficulties();
482 Parse_DefaultWorth();
483 Parse_DefualtTier();
484 Parse_Points();
485
486 if(g_bLateLoad)
487 {
488 for(new i = 1; i <= MaxClients; i++)
489 {
490 if(IsClientInGame(i) && !IsFakeClient(i))
491 {
492 g_bAuthed[i] = GetClientAuthId(i, AuthId_Steam2, g_sAuth[i], sizeof(g_sAuth[]));
493 if(!g_bAuthed[i])
494 CreateTimer(2.0, Timer_AuthClient, GetClientUserId(i), TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
495 else
496 {
497 if(!g_bLoadedCookies[i] && AreClientCookiesCached(i))
498 LoadClientData(i);
499 }
500 }
501 }
502
503 GetCurrentMap(g_sCurrentMap, sizeof(g_sCurrentMap));
504 g_bLateLoad = false;
505 }
506
507 if(g_bTimerMapZones)
508 {
509 if(g_hDatabase == INVALID_HANDLE)
510 SQL_TConnect(SQL_Connect_Database, "timer");
511 else
512 GetMapWorth();
513 }
514}
515
516public OnMapZonesLoaded()
517{
518 if(g_hDatabase == INVALID_HANDLE)
519 SQL_TConnect(SQL_Connect_Database, "timer");
520 else
521 GetMapWorth();
522}
523
524public OnMapStart()
525{
526 if(!g_iEnabled)
527 return;
528
529 GetCurrentMap(g_sCurrentMap, sizeof(g_sCurrentMap));
530 StringToLower(g_sCurrentMap);
531
532 if(g_fAdvertisement > 0.0)
533 CreateTimer(g_fAdvertisement, Timer_Advertisement, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
534}
535
536public OnMapEnd()
537{
538 if(!g_iEnabled)
539 return;
540
541 g_sCurrentMap[0] = '\0';
542}
543
544public Action:Command_AddVip(client, args)
545{
546 if(args > 0)
547 {
548 new String:arg1[MAX_TARGET_LENGTH];
549 GetCmdArg(1, arg1, MAX_TARGET_LENGTH);
550
551 if(StrContains(arg1, "STEAM_", true) != -1)
552 {
553 GetCmdArgString(g_sSetVipAuth[client], 64);
554 }
555 else
556 {
557 new target = FindTarget(client, arg1, false, false);
558 if(target == -1)
559 {
560 ReplyToCommand(client, "[SM] '%s' not found", arg1);
561 return Plugin_Handled;
562 }
563 GetClientAuthId(target, AuthId_Steam2, g_sSetVipAuth[client], 64);
564 }
565
566 new Handle:menu = CreateMenu(MenuHandler_AddVip, MENU_ACTIONS_ALL);
567 SetMenuTitle(menu, "Select for how much time:");
568 AddMenuItem(menu, "604800", "1 Week");
569 AddMenuItem(menu, "1209600", "2 Weeks");
570 AddMenuItem(menu, "2629743", "1 Month");
571 AddMenuItem(menu, "7889231", "3 Month");
572 AddMenuItem(menu, "15778463", "6 Month");
573 AddMenuItem(menu, "31556926", "1 Year");
574 AddMenuItem(menu, "-1", "Permanent");
575 AddMenuItem(menu, "-2", "Semi Permanent(Cant set his own Tag)");
576 DisplayMenu(menu, client, MENU_TIME_FOREVER);
577 }
578 else
579 {
580 ReplyToCommand(client, "[SM] sm_addvip <name|STEAM_ID>");
581 }
582
583 return Plugin_Handled;
584}
585
586public MenuHandler_AddVip(Handle:menu, MenuAction:action, param1, param2)
587{
588 switch(action)
589 {
590 case MenuAction_End:
591 CloseHandle(menu);
592 case MenuAction_Select:
593 {
594 decl String:sInfo[75];
595 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
596 g_bSemiVip[param1] = false;
597 new vipTime = StringToInt(sInfo);
598 if(vipTime > 0)
599 {
600 vipTime += GetTime();
601 }
602 if(vipTime == -2)
603 {
604 g_bSemiVip[param1] = true;
605 }
606 decl String:sQuery[192];
607 Format(sQuery, sizeof(sQuery), "UPDATE `ranks` SET `vipendtime` = %d WHERE `auth` = '%s'", vipTime, g_sSetVipAuth[param1]);
608 SQL_TQuery(g_hDatabase, CallBack_SetClientVip, sQuery, GetClientUserId(param1));
609 }
610 }
611}
612
613public Action:Command_RemoveVip(client, args)
614{
615 if(args > 0)
616 {
617 new String:arg1[MAX_TARGET_LENGTH];
618 GetCmdArg(1, arg1, MAX_TARGET_LENGTH);
619
620 if(StrContains(arg1, "STEAM_", true) != -1)
621 {
622 GetCmdArgString(g_sSetVipAuth[client], 64);
623 }
624 else
625 {
626 new target = FindTarget(client, arg1, false, false);
627 if(target == -1)
628 {
629 ReplyToCommand(client, "[SM] '%s' not found", arg1);
630 return Plugin_Handled;
631 }
632 GetClientAuthId(target, AuthId_Steam2, g_sSetVipAuth[client], 64);
633 }
634
635 decl String:sQuery[192];
636 Format(sQuery, sizeof(sQuery), "UPDATE `ranks` SET `vipendtime` = 0 WHERE `auth` = '%s'", g_sSetVipAuth[client]);
637 SQL_TQuery(g_hDatabase, CallBack_RemoveClientVip, sQuery, GetClientUserId(client));
638 }
639 else
640 {
641 ReplyToCommand(client, "[SM] sm_removevip <name|STEAM_ID>");
642 }
643
644 return Plugin_Handled;
645}
646
647public CallBack_SetClientVip(Handle:owner, Handle:hndl, const String:error[], any:userid)
648{
649 if(hndl == INVALID_HANDLE)
650 {
651 Timer_LogError("SQL Error on CallBack_SetClientVip: %s", error);
652 return;
653 }
654
655 new client = GetClientOfUserId(userid);
656 if(!client || !IsClientInGame(client))
657 return;
658
659 CPrintToChat(client, "%t%t", "Prefix_Chat", "Vip_Setted_Admin", g_sSetVipAuth[client]);
660
661 new String:sAuth[64];
662 for (new i = 1; i <= MaxClients; i++)
663 {
664 if(IsClientInGame(i))
665 {
666 GetClientAuthId(i, AuthId_Steam2, sAuth, 64);
667 if(StrEqual(g_sSetVipAuth[client], sAuth))
668 {
669 CPrintToChat(i, "%t%t", "Prefix_Chat", "Vip_Setted_Client");
670 if(g_bSemiVip[client])
671 g_bForcedVip[i] = true;
672 else
673 g_bVip[i] = true;
674 break;
675 }
676 }
677 }
678}
679
680public CallBack_RemoveClientVip(Handle:owner, Handle:hndl, const String:error[], any:userid)
681{
682 if(hndl == INVALID_HANDLE)
683 {
684 Timer_LogError("SQL Error on CallBack_RemoveClientVip: %s", error);
685 return;
686 }
687
688 new client = GetClientOfUserId(userid);
689 if(!client || !IsClientInGame(client))
690 return;
691
692 CPrintToChat(client, "%tYou have removed %s Vip", "Prefix_Chat", g_sSetVipAuth[client]);
693
694 new String:sAuth[64];
695 for (new i = 1; i <= MaxClients; i++)
696 {
697 if(IsClientInGame(i))
698 {
699 GetClientAuthId(i, AuthId_Steam2, sAuth, 64);
700 if(StrEqual(g_sSetVipAuth[client], sAuth))
701 {
702 CPrintToChat(i, "%tYour Vip has been removed", "Prefix_Chat");
703 g_bVip[i] = false;
704 g_bForcedVip[i] = false;
705 break;
706 }
707 }
708 }
709}
710
711public Action:Command_SetTag(client, args)
712{
713 if(g_bVip[client])
714 {
715 GetCmdArgString(g_sVipString[client], MAX_TAG_LENGTH);
716 CPrintToChat(client, "%t%t", "Prefix_Chat", "Vip_Tag_Setted");
717 //SetClientCookie(client, g_hCoockieVipTagString, g_sVipString[client]);
718 new String:sAuth[64];
719 GetClientAuthId(client, AuthId_Steam2, sAuth, 64);
720 decl String:sQuery[192+MAX_TAG_LENGTH];
721 Format(sQuery, sizeof(sQuery), "UPDATE `ranks` SET `customtag` = '%s' WHERE `auth` = '%s'", g_sVipString[client], sAuth);
722 SQL_TQuery(g_hDatabase, CallBack_UpdateClientVip, sQuery, _);
723 }
724 else
725 {
726 CPrintToChat(client, "%t%t", "Prefix_Chat", "Vip_Denied");
727 }
728 return Plugin_Handled;
729}
730
731public Action:Command_AddToTag(client, args)
732{
733 if(g_bVip[client])
734 {
735 new String:sArg[MAX_TAG_LENGTH];
736 GetCmdArgString(sArg, MAX_TAG_LENGTH);
737 Format(g_sVipString[client], MAX_TAG_LENGTH, "%s%s", g_sVipString[client], sArg);
738 CPrintToChat(client, "%t%t", "Prefix_Chat", "Vip_Tag_Setted");
739 new String:sAuth[64];
740 GetClientAuthId(client, AuthId_Steam2, sAuth, 64);
741 decl String:sQuery[192+MAX_TAG_LENGTH];
742 Format(sQuery, sizeof(sQuery), "UPDATE `ranks` SET `customtag` = '%s' WHERE `auth` = '%s'", g_sVipString[client], sAuth);
743 SQL_TQuery(g_hDatabase, CallBack_UpdateClientVip, sQuery, _);
744 }
745 else
746 {
747 CPrintToChat(client, "%t%t", "Prefix_Chat", "Vip_Denied");
748 }
749 return Plugin_Handled;
750}
751
752public Action:Command_SetText(client, args)
753{
754 if(g_bVip[client])
755 {
756 GetCmdArgString(g_sVipTextString[client], MAX_TAG_LENGTH);
757 //SetClientCookie(client, g_hCoockieVipTextString, g_sVipTextString[client]);
758 CPrintToChat(client, "%t%t", "Prefix_Chat", "Vip_Text_Setted");
759 new String:sAuth[64];
760 GetClientAuthId(client, AuthId_Steam2, sAuth, 64);
761 decl String:sQuery[192+MAX_TAG_LENGTH];
762 Format(sQuery, sizeof(sQuery), "UPDATE `ranks` SET `customchat` = '%s' WHERE `auth` = '%s'", g_sVipTextString[client], sAuth);
763 SQL_TQuery(g_hDatabase, CallBack_UpdateClientVip, sQuery, _);
764 }
765 else
766 {
767 CPrintToChat(client, "%t%t", "Prefix_Chat", "Vip_Denied");
768 }
769 return Plugin_Handled;
770}
771
772public Action:Command_SetForcedTag(client, args)
773{
774 new String:sAuth[64];
775 new String:sBuffer[128];
776
777 new iBreak;
778 decl String:sText[192];
779 GetCmdArgString(sText, sizeof(sText));
780
781 iBreak = BreakString(sText, sAuth, sizeof(sAuth));
782 if(iBreak == -1)
783 {
784 return Plugin_Handled;
785 }
786 strcopy(sBuffer, sizeof(sBuffer), sText[iBreak]);
787
788 decl String:sQuery[192+MAX_TAG_LENGTH];
789 Format(sQuery, sizeof(sQuery), "UPDATE `ranks` SET `customtag` = '%s' WHERE `auth` = '%s'", sBuffer, sAuth);
790 SQL_TQuery(g_hDatabase, CallBack_UpdateClientVip, sQuery, _);
791 return Plugin_Handled;
792}
793
794public CallBack_UpdateClientVip(Handle:owner, Handle:hndl, const String:error[], any:userid)
795{
796 if(hndl == INVALID_HANDLE)
797 {
798 Timer_LogError("SQL Error on CallBack_SetClientVip: %s", error);
799 return;
800 }
801}
802
803
804public Action:Command_VipHelp(client, args)
805{
806 CPrintToChat(client, "%tCheck console for output", "Prefix_Chat");
807 new String:sBuffer[1024];
808 StrCat(sBuffer, sizeof(sBuffer), "\n================VIP===============\n");
809 StrCat(sBuffer, sizeof(sBuffer), "==============Commands==============");
810 StrCat(sBuffer, sizeof(sBuffer), "\nsm_settag <tag> - Set name Tag by the format below. Example: sm_settag {green}Of{blue}ir");
811 StrCat(sBuffer, sizeof(sBuffer), "\nsm_addtotag <addtotag> - Add more text to tag if its too long");
812 StrCat(sBuffer, sizeof(sBuffer), "\nsm_settext <text> - Set text color by the format below. Example: sm_settext {random}");
813 StrCat(sBuffer, sizeof(sBuffer), "\nsm_printtag - Print current tag + text color to console.");
814 StrCat(sBuffer, sizeof(sBuffer), "\n==============Format==============\n");
815 StrCat(sBuffer, sizeof(sBuffer), "==============Colors==============");
816 if(!isCSS())
817 StrCat(sBuffer, sizeof(sBuffer), "\n{default}\n{darkred}\n{green}\n{lightgreen}\n{orange}\n{blue}\n{olive}\n{lime}\n{red}\n{purple}\n{grey}\n{yellow}\n{lightblue}\n{steelblue}\n{darkblue}\n{pink}\n{lightred}");
818 else
819 {
820 StrCat(sBuffer, sizeof(sBuffer), "\nAll morecolors.inc Colors - https://www.doctormckay.com/download/scripting/include/morecolors.inc");
821 StrCat(sBuffer, sizeof(sBuffer), "\nAll Customize Hex Color. Example:{color: 9EC34F} - http://www.color-hex.com/");
822 }
823
824 StrCat(sBuffer, sizeof(sBuffer), "\n==============Random==============");
825 StrCat(sBuffer, sizeof(sBuffer), "\n{random} - Random Color");
826 StrCat(sBuffer, sizeof(sBuffer), "\n{random: {green}{blue}} - Random Between Colors (green and blue unlimted)");
827
828 StrCat(sBuffer, sizeof(sBuffer), "\n==============Name==============");
829 StrCat(sBuffer, sizeof(sBuffer), "\n{name} - Will replaced by your steam name");
830
831 StrCat(sBuffer, sizeof(sBuffer), "\n================VIP===============");
832 PrintToConsole(client, "%s", sBuffer);
833 return Plugin_Handled;
834}
835
836public Action:Command_PrintTag(client, args)
837{
838 CPrintToChat(client, "%tCheck console for output", "Prefix_Chat");
839 new String:sBuffer[1024];
840 StrCat(sBuffer, sizeof(sBuffer), "\n================TAG===============\n");
841 StrCat(sBuffer, sizeof(sBuffer), g_sVipString[client]);
842 StrCat(sBuffer, sizeof(sBuffer), "\n================TEXT===============\n");
843 StrCat(sBuffer, sizeof(sBuffer), g_sVipTextString[client]);
844 PrintToConsole(client, "%s", sBuffer);
845 return Plugin_Handled;
846}
847
848public Action:Timer_Advertisement(Handle:timer)
849{
850 if(!g_iEnabled)
851 return Plugin_Continue;
852
853 CPrintToChatAll("%t%t", "Prefix_Chat", "Advertisement");
854
855 return Plugin_Continue;
856}
857
858public OnClientPostAdminCheck(client)
859{
860 if(!g_iEnabled || IsFakeClient(client))
861 return;
862
863 g_bAuthed[client] = GetClientAuthId(client, AuthId_Steam2, g_sAuth[client], sizeof(g_sAuth[]));
864 if(!g_bAuthed[client])
865 CreateTimer(2.0, Timer_AuthClient, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
866 else if(g_hDatabase != INVALID_HANDLE && !g_bInitalizing)
867 {
868 if(!g_bLoadedSQL[client])
869 {
870 decl String:sQuery[192];
871 Format(sQuery, sizeof(sQuery), "SELECT `points`,`vipendtime`,`customtag`,`customchat` FROM `ranks` WHERE `auth` = '%s'", g_sAuth[client]);
872 if(g_iEnabled == 2)
873 PrintToDebug("OnClientPostAdminCheck(%N): Issuing Query `%s`", client, sQuery);
874 SQL_TQuery(g_hDatabase, CallBack_ClientConnect, sQuery, GetClientUserId(client), DBPrio_High);
875 }
876
877 if(!g_bLoadedCookies[client] && AreClientCookiesCached(client))
878 LoadClientData(client);
879 }
880}
881
882public OnClientCookiesCached(client)
883{
884 if(!g_iEnabled || IsFakeClient(client))
885 return;
886
887 if(!g_bLoadedCookies[client])
888 LoadClientData(client);
889}
890
891LoadClientData(client)
892{
893 if(g_hDisplayCookie == INVALID_HANDLE)
894 return;
895
896 new String:sCookie[3] = "";
897 GetClientCookie(client, g_hDisplayCookie, sCookie, sizeof(sCookie));
898
899 if(StrEqual(sCookie, "", false))
900 {
901 new iDisplayMethod = (g_iDisplayMethod * -1);
902 decl String:sBuffer[3];
903 IntToString(iDisplayMethod, sBuffer, sizeof(sBuffer));
904 SetClientCookie(client, g_hDisplayCookie, sBuffer);
905
906 g_iClientDisplay[client] = iDisplayMethod;
907 }
908 else
909 {
910 g_iClientDisplay[client] = StringToInt(sCookie);
911 }
912
913 g_bLoadedCookies[client] = true;
914}
915
916public OnClientDisconnect(client)
917{
918 if(!g_iEnabled)
919 return;
920
921 g_sAuth[client][0] = '\0';
922
923 g_bAuthed[client] = false;
924 g_bLoadedSQL[client] = false;
925 g_bLoadedCookies[client] = false;
926 g_bConnected[client] = false;
927 g_bVip[client] = false;
928
929 g_iNextIndex[client] = -1;
930 g_iCurrentIndex[client] = -1;
931 g_iCurrentPoints[client] = 0;
932 g_iLastGlobalMessage[client] = 0;
933 g_iClientDisplay[client] = 0;
934 for (new i = 0; i < 32; i++)
935 {
936 g_bComplete[client][i] = false;
937 for (new j = 0; j < 64; j++)
938 {
939 g_bStageComplete[client][j][i] = false;
940 }
941 }
942}
943
944// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
945
946public Action:Command_Say(client, const String:command[], argc)
947{
948 if(!g_iEnabled || !client || g_bInitalizing)
949 return Plugin_Continue;
950
951 decl String:sText[192], String:sBuffer[24];
952 GetCmdArgString(sText, sizeof(sText));
953 new String:message[256];
954 strcopy(message, sizeof(message), sText);
955 StripQuotes(message);
956 if(strlen(message) == 0)
957 {
958 return Plugin_Handled;
959 }
960
961 //new bool:HideCmd = message[0] == '/';
962 //new bool:HideCmd = true;
963 new iIndex, iStart;
964 if(sText[strlen(sText) - 1] == '"')
965 {
966 sText[strlen(sText) - 1] = '\0';
967 iStart = 1;
968 }
969 new String:args[2][64];
970 ExplodeString(sText, " ", args, 2, 64);
971 BreakString(sText[iStart], sBuffer, sizeof(sBuffer));
972 if(GetTrieValue(g_hTrie_CfgCommands, sBuffer, iIndex))
973 {
974 switch(iIndex)
975 {
976 case cChatCookie:
977 {
978 if(g_iDisplayMethod >= 0 || g_hDisplayCookie == INVALID_HANDLE || g_iCurrentIndex[client] == -1)
979 return Plugin_Continue;
980
981 if(!g_bLoadedSQL[client] || !g_bLoadedCookies[client])
982 {
983 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase.Loading");
984 return Plugin_Handled;
985 }
986
987 CreateCookieMenu(client);
988 return Plugin_Handled;
989 }
990 case cChatTop:
991 {
992 g_iChoosedTopMenuRank[client] = 0;
993 if(!StrEqual(args[1], ""))
994 {
995 g_iChoosedTopMenuRank[client] = StringToInt(args[1]);
996 if(g_iChoosedTopMenuRank[client] > g_iTotalPlayers)
997 g_iChoosedTopMenuRank[client] = g_iTotalPlayers;
998 g_iChoosedTopMenuRank[client]++;
999 }
1000 Format(sText, sizeof(sText), "SELECT `lastname`,`points`,`auth` FROM `ranks` WHERE `points` >= %d ORDER BY `points` DESC LIMIT 0, %d", g_iRequiredPoints, g_iLimitTopPlayers);
1001 if(g_iEnabled == 2)
1002 PrintToDebug("Command_Say(%N): Issuing Query `%s`", client, sText);
1003 SQL_TQuery(g_hDatabase, CallBack_Top, sText, GetClientUserId(client), DBPrio_High);
1004 return Plugin_Handled;
1005 }
1006 case cChatRank:
1007 {
1008 if(!StrEqual(args[1], ""))
1009 {
1010 if(args[1][0] != '@')
1011 {
1012 Format(sText, sizeof(sText), "SELECT `lastname`,`points` FROM `ranks` WHERE `lastname` LIKE '%%%s%%' LIMIT 1", args[1]);
1013 SQL_TQuery(g_hDatabase, CallBack_RankByName, sText, GetClientUserId(client), DBPrio_High);
1014 return Plugin_Handled;
1015 }
1016 else
1017 {
1018 new position;
1019 BreakString(args[1][1], args[1], 64);
1020 position = StringToInt(args[1]);
1021 Format(sText, sizeof(sText), "SELECT `lastname`,`points` FROM `ranks` ORDER BY `points` DESC LIMIT 0,%d", position+1);
1022 new Handle:pack = CreateDataPack();
1023 WritePackCell(pack, GetClientUserId(client));
1024 WritePackCell(pack, position);
1025 SQL_TQuery(g_hDatabase, CallBack_RankByPlace, sText, pack, DBPrio_High);
1026 return Plugin_Handled;
1027 }
1028 }
1029
1030 if(!g_bLoadedSQL[client])
1031 {
1032 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Loading");
1033 return Plugin_Handled;
1034 }
1035
1036 if(g_iCurrentPoints[client] < g_iRequiredPoints)
1037 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Rank_Not_Enough", g_iRequiredPoints, g_iCurrentPoints[client]);
1038 else
1039 {
1040 Format(sText, sizeof(sText), "SELECT COUNT(*) FROM `ranks` WHERE `points` > %d ORDER BY `points` DESC", g_iCurrentPoints[client]);
1041 if(g_iEnabled == 2)
1042 PrintToDebug("Command_Say(%N): Issuing Query `%s`", client, sText);
1043 SQL_TQuery(g_hDatabase, CallBack_Rank, sText, GetClientUserId(client), DBPrio_High);
1044 }
1045 return Plugin_Handled;
1046 }
1047 case cChatView:
1048 {
1049 if(g_iDisplayMethod != 0)
1050 CreateInfoMenu(client);
1051 else
1052 return Plugin_Handled;
1053 }
1054 case cChatWorth:
1055 {
1056 if(!StrEqual(args[1], "") && !StrEqual(args[1], g_sCurrentMap))
1057 {
1058 Format(sText, sizeof(sText), "SELECT `map`, `points`, `tier` FROM `maps` WHERE `map` LIKE '%%%s%%'", args[1]);
1059 strcopy(g_sMapChoosed[client], 64, args[1]);
1060 SQL_TQuery(g_hDatabase, CallBack_MapInfo, sText, GetClientUserId(client), DBPrio_High);
1061 }
1062
1063 if(g_bTimerMapZones && g_fFinishPrec != 1.0 && Timer_GetStageCount() > 1)
1064 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Points_Per_Map_Stages", g_iCurrentMapWorth, RoundToFloor((float(g_iCurrentMapWorth) * (1.0 - g_fFinishPrec)) / Timer_GetStageCount()), RoundToFloor(float(g_iCurrentMapWorth) - (RoundToFloor((float(g_iCurrentMapWorth) * (1.0 - g_fFinishPrec)) / Timer_GetStageCount()) * Timer_GetStageCount())), g_iCurrentMapTier);
1065 else
1066 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Points_Per_Map", g_iCurrentMapWorth, g_iCurrentMapTier);
1067 return Plugin_Handled;
1068 }
1069 case cChatNext:
1070 {
1071 if(!StrEqual(args[1], ""))
1072 {
1073 Format(sText, sizeof(sText), "SELECT `auth`,`points` FROM `ranks` WHERE `lastname` LIKE '%%%s%%' LIMIT 1", args[1]);
1074 SQL_TQuery(g_hDatabase, CallBack_NextByName, sText, GetClientUserId(client), DBPrio_High);
1075 return Plugin_Handled;
1076 }
1077
1078 if(!g_bLoadedSQL[client])
1079 {
1080 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Loading");
1081 return Plugin_Handled;
1082 }
1083
1084 Format(sText, sizeof(sText), "SELECT `lastname`,`points`,`auth` FROM `ranks` WHERE `points` > %d AND `points` >= %d AND `auth` != '%s' ORDER BY `points` ASC LIMIT %d", g_iCurrentPoints[client], g_iRequiredPoints, g_sAuth[client], g_iLimitTopPlayers);
1085 if(g_iEnabled == 2)
1086 PrintToDebug("Command_Say(%N): Issuing Query `%s`", client, sText);
1087 g_iChoosedPoints[client] = g_iCurrentPoints[client];
1088 SQL_TQuery(g_hDatabase, CallBack_Next, sText, GetClientUserId(client), DBPrio_High);
1089 return Plugin_Handled;
1090 }
1091 case cChatTopCountry:
1092 {
1093 if(!StrEqual(args[1], ""))
1094 {
1095 if(args[1][0] != '@')
1096 {
1097 Format(sText, sizeof(sText), "SELECT `lastcountry` FROM `ranks` WHERE `lastcountry` LIKE '%%%s%%' ORDER BY `points` DESC", args[1]);
1098 SQL_TQuery(g_hDatabase, CallBack_TopCountryByName, sText, GetClientUserId(client), DBPrio_High);
1099 return Plugin_Handled;
1100 }
1101 else
1102 {
1103
1104 new position;
1105 BreakString(args[1][1], args[1], 64);
1106 position = StringToInt(args[1]);
1107
1108 new Handle:pack = CreateDataPack();
1109 WritePackCell(pack, GetClientUserId(client));
1110 WritePackCell(pack, position);
1111
1112 Format(sText, sizeof(sText), "SELECT `lastcountry` FROM `ranks` ORDER BY `points` DESC LIMIT 0,%d", position+1);
1113 SQL_TQuery(g_hDatabase, CallBack_TopCountryByPlace, sText, pack, DBPrio_High);
1114 return Plugin_Handled;
1115 }
1116 }
1117 else
1118 {
1119 Format(sText, sizeof(sText), "SELECT DISTINCT `lastcountry`, SUM(`points`), COUNT(*) FROM `ranks` WHERE `points` >= %d GROUP BY `lastcountry` ORDER BY SUM(`points`) DESC", g_iRequiredPoints);
1120 if(g_iEnabled == 2)
1121 PrintToDebug("Command_Say(%N): Issuing Query `%s`", client, sText);
1122 SQL_TQuery(g_hDatabase, CallBack_TopCountry, sText, GetClientUserId(client), DBPrio_High);
1123 }
1124 return Plugin_Handled;
1125 }
1126 case cChatRankCountry:
1127 {
1128 if(!StrEqual(args[1], ""))
1129 {
1130 if(args[1][0] != '@')
1131 {
1132 Format(sText, sizeof(sText), "SELECT `lastname`,`points`,`lastcountry` FROM `ranks` WHERE `lastname` LIKE '%%%s%%' LIMIT 1", args[1]);
1133 SQL_TQuery(g_hDatabase, CallBack_CountryRankByName, sText, GetClientUserId(client), DBPrio_High);
1134 return Plugin_Handled;
1135 }
1136 else
1137 {
1138 new position;
1139 BreakString(args[1][1], args[1], 64);
1140 position = StringToInt(args[1]);
1141 Format(sText, sizeof(sText), "SELECT `lastname`,`points` FROM `ranks` WHERE `lastcountry` = '%s' ORDER BY `points` DESC LIMIT 0,%d", g_sCountry[client], position+1);
1142 new Handle:pack = CreateDataPack();
1143 WritePackCell(pack, GetClientUserId(client));
1144 WritePackCell(pack, position);
1145 SQL_TQuery(g_hDatabase, CallBack_CountryRankByPlace, sText, pack, DBPrio_High);
1146 return Plugin_Handled;
1147 }
1148 }
1149
1150 if(!g_bLoadedSQL[client])
1151 {
1152 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Loading");
1153 return Plugin_Handled;
1154 }
1155
1156 if(g_iCurrentPoints[client] < g_iRequiredPoints)
1157 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Rank_Not_Enough", g_iRequiredPoints, g_iCurrentPoints[client]);
1158 else
1159 {
1160 Format(sText, sizeof(sText), "SELECT COUNT(*) FROM `ranks` WHERE `points` > %d AND `lastcountry` = '%s' ORDER BY `points` DESC", g_iCurrentPoints[client], g_sCountry[client]);
1161 if(g_iEnabled == 2)
1162 PrintToDebug("Command_Say(%N): Issuing Query `%s`", client, sText);
1163 SQL_TQuery(g_hDatabase, CallBack_CountryRank, sText, GetClientUserId(client), DBPrio_High);
1164 }
1165 return Plugin_Handled;
1166 }
1167 }
1168 return Plugin_Handled;
1169 }
1170 return Plugin_Continue;
1171}
1172
1173CreateCookieMenu(client)
1174{
1175 decl String:sBuffer[128];
1176 new Handle:hMenu = CreateMenu(MenuHandler_CookieMenu);
1177
1178 Format(sBuffer, sizeof(sBuffer), "%T", "Menu_Title_Cookie", client);
1179 SetMenuTitle(hMenu, sBuffer);
1180
1181 decl String:sSelected[8], String:sUnselected[8];
1182 Format(sSelected, sizeof(sSelected), "%T", "Menu_Option_Selected", client);
1183 Format(sSelected, sizeof(sSelected), "%T", "Menu_Option_Empty", client);
1184
1185 new iDisplayMethod = (g_iDisplayMethod * -1);
1186 if(iDisplayMethod & cDisplayScoreTag)
1187 {
1188 GetArrayString(g_hCfgArray_DisplayTag, g_iCurrentIndex[client], sBuffer, sizeof(sBuffer));
1189 if(!StrEqual(sBuffer, ""))
1190 Format(sBuffer, sizeof(sBuffer), "%s%T", (g_iClientDisplay[client] & cDisplayScoreTag) ? sSelected : sUnselected, "Menu_Cookie_Option_Tag", client);
1191 else
1192 Format(sBuffer, sizeof(sBuffer), "%s%T", (g_iClientDisplay[client] & cDisplayScoreTag) ? sSelected : sUnselected, "Menu_Cookie_Option_Tag_Default", client);
1193 AddMenuItem(hMenu, "1", sBuffer);
1194 }
1195
1196 if(iDisplayMethod & cDisplayChatTag)
1197 {
1198 GetArrayString(g_hCfgArray_DisplayChat, g_iCurrentIndex[client], sBuffer, sizeof(sBuffer));
1199 if(!StrEqual(sBuffer, ""))
1200 Format(sBuffer, sizeof(sBuffer), "%s%T", (g_iClientDisplay[client] & cDisplayChatTag) ? sSelected : sUnselected, "Menu_Cookie_Option_Chat", client);
1201 else
1202 Format(sBuffer, sizeof(sBuffer), "%s%T", (g_iClientDisplay[client] & cDisplayChatTag) ? sSelected : sUnselected, "Menu_Cookie_Option_Chat_Default", client);
1203 AddMenuItem(hMenu, "2", sBuffer);
1204 }
1205
1206 if(iDisplayMethod & cDisplayChatColor)
1207 {
1208 GetArrayString(g_hCfgArray_DisplayColor, g_iCurrentIndex[client], sBuffer, sizeof(sBuffer));
1209 if(!StrEqual(sBuffer, ""))
1210 Format(sBuffer, sizeof(sBuffer), "%s%T", (g_iClientDisplay[client] & cDisplayChatColor) ? sSelected : sUnselected, "Menu_Cookie_Option_Text", client);
1211 else
1212 Format(sBuffer, sizeof(sBuffer), "%s%T", (g_iClientDisplay[client] & cDisplayChatColor) ? sSelected : sUnselected, "Menu_Cookie_Option_Text_Default", client);
1213 AddMenuItem(hMenu, "4", sBuffer);
1214 }
1215
1216 if(iDisplayMethod & cDisplayScoreStars)
1217 {
1218 if(GetArrayCell(g_hCfgArray_DisplayStars, g_iCurrentIndex[client]))
1219 Format(sBuffer, sizeof(sBuffer), "%s%T", (g_iClientDisplay[client] & cDisplayScoreStars) ? sSelected : sUnselected, "Menu_Cookie_Option_Stars", client);
1220 else
1221 Format(sBuffer, sizeof(sBuffer), "%s%T", (g_iClientDisplay[client] & cDisplayScoreStars) ? sSelected : sUnselected, "Menu_Cookie_Option_Stars_Default", client);
1222 AddMenuItem(hMenu, "8", sBuffer);
1223 }
1224
1225 DisplayMenu(hMenu, client, 30);
1226}
1227
1228public MenuHandler_CookieMenu(Handle:menu, MenuAction:action, param1, param2)
1229{
1230 switch(action)
1231 {
1232 case MenuAction_End:
1233 CloseHandle(menu);
1234 case MenuAction_Select:
1235 {
1236 decl String:sOption[4];
1237 GetMenuItem(menu, param2, sOption, 4);
1238
1239 switch(StringToInt(sOption))
1240 {
1241 case cDisplayScoreTag:
1242 {
1243 decl String:sBuffer[20], String:sTemp[20];
1244 GetArrayString(g_hCfgArray_DisplayTag, g_iCurrentIndex[param1], sBuffer, sizeof(sBuffer));
1245
1246 if(g_iClientDisplay[param1] & cDisplayScoreTag)
1247 {
1248 g_iClientDisplay[param1] &= ~cDisplayScoreTag;
1249
1250 CS_GetClientClanTag(param1, sTemp, sizeof(sTemp));
1251 if(StrEqual(sTemp, sBuffer))
1252 CS_SetClientClanTag(param1, "");
1253 }
1254 else
1255 {
1256 g_iClientDisplay[param1] |= cDisplayScoreTag;
1257
1258 CS_GetClientClanTag(param1, sTemp, sizeof(sTemp));
1259 if(!StrEqual(sTemp, sBuffer))
1260 CS_SetClientClanTag(param1, sBuffer);
1261 }
1262 }
1263 case cDisplayChatTag:
1264 {
1265 if(g_iClientDisplay[param1] & cDisplayChatTag)
1266 {
1267 g_iClientDisplay[param1] &= ~cDisplayChatTag;
1268 }
1269 else
1270 {
1271 g_iClientDisplay[param1] |= cDisplayChatTag;
1272 }
1273 }
1274 case cDisplayChatColor:
1275 {
1276 if(g_iClientDisplay[param1] & cDisplayChatColor)
1277 {
1278 g_iClientDisplay[param1] &= ~cDisplayChatColor;
1279 }
1280 else
1281 {
1282 g_iClientDisplay[param1] |= cDisplayChatColor;
1283 }
1284 }
1285 case cDisplayScoreStars:
1286 {
1287 if(g_iClientDisplay[param1] & cDisplayScoreStars)
1288 {
1289 g_iClientDisplay[param1] &= ~cDisplayScoreStars;
1290 }
1291 else
1292 {
1293 g_iClientDisplay[param1] |= cDisplayScoreStars;
1294 }
1295 }
1296 }
1297
1298 decl String:sBuffer[3];
1299 IntToString(g_iClientDisplay[param1], sBuffer, sizeof(sBuffer));
1300 SetClientCookie(param1, g_hDisplayCookie, sBuffer);
1301
1302 CreateCookieMenu(param1);
1303 }
1304 }
1305}
1306
1307CreateInfoMenu(client, item = 0)
1308{
1309 if(g_iTotalRanks < 0)
1310 return;
1311
1312 decl String:sBuffer[128], String:sTemp[4];
1313 Format(sBuffer, sizeof(sBuffer), "%T", "Menu_Title_Info", client);
1314
1315 new Handle:hMenu = CreateMenu(MenuHandler_InfoMenu);
1316 SetMenuTitle(hMenu, sBuffer);
1317 SetMenuExitButton(hMenu, true);
1318 SetMenuExitBackButton(hMenu, false);
1319
1320 new iHideNegative;
1321 if(g_iPositionMethod)
1322 iHideNegative = FindValueInArray(g_hArray_Positions, -1);
1323 else
1324 iHideNegative = FindValueInArray(g_hArray_CfgPoints, -1);
1325
1326 for(new i = 2; i <= g_iTotalRanks; i++)
1327 {
1328 if(i == iHideNegative)
1329 continue;
1330
1331 GetArrayString(g_hCfgArray_DisplayInfo, i, sBuffer, sizeof(sBuffer));
1332 IntToString(i, sTemp, sizeof(sTemp));
1333 AddMenuItem(hMenu, sTemp, sBuffer);
1334 }
1335
1336 DisplayMenuAtItem(hMenu, client, item, 30);
1337}
1338
1339public MenuHandler_InfoMenu(Handle:menu, MenuAction:action, param1, param2)
1340{
1341 switch(action)
1342 {
1343 case MenuAction_End:
1344 CloseHandle(menu);
1345 case MenuAction_Select:
1346 {
1347 decl String:sOption[4], String:sInfo[64];
1348 GetMenuItem(menu, param2, sOption, 4);
1349 new iIndex = StringToInt(sOption);
1350
1351 GetArrayString(g_hCfgArray_DisplayInfo, iIndex, sInfo, sizeof(sInfo));
1352
1353 new iEnd, iStart, iPoints;
1354 if(g_iPositionMethod)
1355 {
1356 new iPreviousIndex = (iIndex - 1);
1357 if(iPreviousIndex < 0)
1358 iStart = 1;
1359 else
1360 {
1361 iStart = GetArrayCell(g_hArray_CfgRanks, iPreviousIndex);
1362 if(iStart == -1)
1363 iStart = 1;
1364 else
1365 iStart++;
1366 }
1367
1368 iEnd = GetArrayCell(g_hArray_CfgRanks, iIndex);
1369 CPrintToChat(param1, "%t%t", "Prefix_Chat", "Phrase_Info_Rank_Rank", iStart, iEnd, sInfo);
1370 }
1371 else
1372 {
1373 iPoints = GetArrayCell(g_hArray_CfgPoints, iIndex);
1374 CPrintToChat(param1, "%t%t", "Prefix_Chat", "Phrase_Info_Rank_Points", iPoints, sInfo);
1375 }
1376
1377 if(g_iDisplayMethod > 0)
1378 {
1379 decl String:sTag[64], String:sChat[MAX_TAG_LENGTH], String:sText[MAX_TAG_LENGTH];
1380 GetArrayString(g_hCfgArray_DisplayTag, iIndex, sTag, sizeof(sTag));
1381 GetArrayString(g_hCfgArray_DisplayChat, iIndex, sChat, sizeof(sChat));
1382 FormatCustomColor(sChat, sChat, sizeof(sChat), param1);
1383 GetArrayString(g_hCfgArray_DisplayColor, iIndex, sText, sizeof(sText));
1384 FormatCustomColor(sText, sText, sizeof(sText), param1);
1385
1386 if(g_iDisplayMethod & cDisplayScoreTag && !StrEqual(sTag, ""))
1387 CPrintToChat(param1, "%t%t", "Prefix_Chat", "Phrase_Info_Rank_Display_Tag", sTag);
1388 if(g_iDisplayMethod & cDisplayChatTag && !StrEqual(sChat, ""))
1389 CPrintToChat(param1, "%t%t", "Prefix_Chat", "Phrase_Info_Rank_Display_Chat", sChat, param1);
1390 if(g_iDisplayMethod & cDisplayChatColor && !StrEqual(sText, ""))
1391 CPrintToChat(param1, "%t%t", "Prefix_Chat", "Phrase_Info_Rank_Display_Text", sText);
1392 if(g_iDisplayMethod & cDisplayScoreStars)
1393 {
1394 new iStars = GetArrayCell(g_hCfgArray_DisplayStars, iIndex);
1395 if(iStars)
1396 {
1397 CPrintToChat(param1, "%t%t", "Prefix_Chat", "Phrase_Info_Rank_Display_Stars", iStars);
1398 }
1399 }
1400 }
1401 else if(g_iDisplayMethod < 0)
1402 {
1403 new iDisplayMethod = g_iDisplayMethod * -1;
1404
1405 decl String:sTag[64], String:sChat[MAX_TAG_LENGTH], String:sText[MAX_TAG_LENGTH];
1406 GetArrayString(g_hCfgArray_DisplayTag, iIndex, sTag, sizeof(sTag));
1407 GetArrayString(g_hCfgArray_DisplayChat, iIndex, sChat, sizeof(sChat));
1408 FormatCustomColor(sChat, sChat, sizeof(sChat), param1);
1409 GetArrayString(g_hCfgArray_DisplayColor, iIndex, sText, sizeof(sText));
1410 FormatCustomColor(sText, sText, sizeof(sText), param1);
1411
1412 if(iDisplayMethod & cDisplayScoreTag && !StrEqual(sTag, ""))
1413 CPrintToChat(param1, "%t%t", "Prefix_Chat", "Phrase_Info_Rank_Display_Tag", sTag);
1414 if(iDisplayMethod & cDisplayChatTag && !StrEqual(sChat, ""))
1415 CPrintToChat(param1, "%t%t", "Prefix_Chat", "Phrase_Info_Rank_Display_Chat", sChat, param1);
1416 if(iDisplayMethod & cDisplayChatColor && !StrEqual(sText, ""))
1417 CPrintToChat(param1, "%t%t", "Prefix_Chat", "Phrase_Info_Rank_Display_Text", sText);
1418 if(iDisplayMethod & cDisplayScoreStars)
1419 {
1420 new iStars = GetArrayCell(g_hCfgArray_DisplayStars, iIndex);
1421 if(iStars)
1422 {
1423 CPrintToChat(param1, "%t%t", "Prefix_Chat", "Phrase_Info_Rank_Display_Stars", iStars);
1424 }
1425 }
1426 }
1427
1428 if(!g_iPositionMethod && g_iCurrentPoints[param1] < iPoints)
1429 {
1430 iPoints -= g_iCurrentPoints[param1];
1431 CPrintToChat(param1, "%t%t", "Prefix_Chat", "Phrase_Info_Rank_Remaining", iPoints);
1432 }
1433
1434 CreateInfoMenu(param1, GetMenuSelectionPosition());
1435 }
1436 }
1437}
1438
1439// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1440
1441public OnFinishRound(client, const String:map[], jumps, flashbangs, physicsDifficulty, fpsmax, const String:timeString[], const String:timeDiffString[], totalrank, bool:overwrite, strafes, bool:firstTime, Float:fTime, trikzpartner)
1442{
1443 if(!g_iEnabled || IsFakeClient(client))
1444 return;
1445
1446 //This shouldn't be done... Cache & Reward after?
1447 if(!g_bLoadedSQL[client] || !g_bAuthed[client] || g_hDatabase == INVALID_HANDLE || !g_iCurrentMapWorth || g_bInitalizing)
1448 return;
1449
1450 new iBuffer;
1451 if(g_bTimerMapZones && g_fFinishPrec != 1.0)
1452 iBuffer = RoundToFloor(float(g_iCurrentMapWorth) - (RoundToFloor((float(g_iCurrentMapWorth) * (1.0 - g_fFinishPrec)) / Timer_GetStageCount()) * Timer_GetStageCount()));
1453 else
1454 iBuffer = g_iCurrentMapWorth;
1455 if(g_bTimerPhysics && g_iTotalDiff && physicsDifficulty > 0)
1456 {
1457 if(g_bTimerMapZones)
1458 iBuffer = RoundToFloor(float(iBuffer) * g_fDiffFactor[physicsDifficulty]);
1459 else if(physicsDifficulty)
1460 iBuffer = RoundToFloor(float(iBuffer) * 1.5); //Pro Record
1461 }
1462
1463
1464 if(!g_bComplete[client][physicsDifficulty])
1465 {
1466 if(g_bTimerMapZones && Timer_GetStageCount() > 1)
1467 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Complete_Round_Points", iBuffer, g_sCurrentMap);
1468 else
1469 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Complete_Round_Points", RoundToFloor(float(g_iCurrentMapWorth) * g_fDiffFactor[physicsDifficulty]), g_sCurrentMap);
1470 }
1471 else if(g_bComplete[client][physicsDifficulty] && g_fPointFarmingFactor > 0.0)
1472 {
1473 iBuffer = RoundToNearest(iBuffer * g_fPointFarmingFactor);
1474 if(g_bTimerMapZones && Timer_GetStageCount() > 1)
1475 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Complete_Round_Points", iBuffer, g_sCurrentMap);
1476 else
1477 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Complete_Round_Points", RoundToFloor(float(g_iCurrentMapWorth) * g_fDiffFactor[physicsDifficulty] * g_fPointFarmingFactor), g_sCurrentMap);
1478 }
1479 else
1480 {
1481 return;
1482 }
1483 g_bComplete[client][physicsDifficulty] = true;
1484
1485 g_iCurrentPoints[client] += iBuffer;
1486
1487 decl String:sQuery[192];
1488 Format(sQuery, sizeof(sQuery), "UPDATE `ranks` SET `points` = %d WHERE `auth` = '%s'", g_iCurrentPoints[client], g_sAuth[client]);
1489 if(g_iEnabled == 2)
1490 PrintToDebug("OnFinishRound(%N): Issuing Query `%s`", client, sQuery);
1491 SQL_TQuery(g_hDatabase, CallBack_UpdateClient, sQuery, GetClientUserId(client), DBPrio_Low);
1492
1493 if(g_iPositionMethod)
1494 {
1495 Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM `ranks` WHERE `points` > %d ORDER BY `points` DESC", g_iCurrentPoints[client]);
1496 if(g_iEnabled == 2)
1497 PrintToDebug("OnFinishRound(%N): Issuing Query `%s`", client, sQuery);
1498 SQL_TQuery(g_hDatabase, CallBack_LoadRank, sQuery, GetClientUserId(client), DBPrio_Low);
1499 }
1500 if(!g_iPositionMethod)
1501 {
1502 if(g_iNextIndex[client] == -1)
1503 return;
1504
1505 if(g_iCurrentPoints[client] >= g_iNextIndex[client])
1506 {
1507 g_iCurrentIndex[client]++;
1508 if(g_iCurrentIndex[client] == g_iTotalRanks)
1509 g_iNextIndex[client] = -1;
1510 else
1511 g_iNextIndex[client] = GetArrayCell(g_hArray_CfgPoints, g_iCurrentIndex[client] + 1);
1512
1513 UpdateClientRank(client);
1514
1515 }
1516 }
1517}
1518
1519public OnTimerDeleteRecord(const String:auth[], part, difficulty)
1520{
1521 if(part == 3)
1522 return;
1523 new iBuffer;
1524
1525 if(g_bTimerMapZones && g_fFinishPrec != 1.0)
1526 {
1527 if (part == 1)
1528 iBuffer = RoundToFloor(float(g_iCurrentMapWorth) - (RoundToFloor((float(g_iCurrentMapWorth) * (1.0 - g_fFinishPrec)) / Timer_GetStageCount()) * Timer_GetStageCount()));
1529 if(part == 2)
1530 iBuffer = RoundToFloor((float(g_iCurrentMapWorth) * (1.0 - g_fFinishPrec)) / Timer_GetStageCount());
1531 }
1532 else
1533 {
1534 iBuffer = g_iCurrentMapWorth;
1535 }
1536
1537 if(g_bTimerPhysics && g_iTotalDiff && difficulty > 0)
1538 iBuffer = RoundToFloor(float(iBuffer) * g_fDiffFactor[difficulty]);
1539
1540 new Handle:pack = CreateDataPack();
1541 WritePackCell(pack, iBuffer);
1542 WritePackString(pack, auth);
1543
1544 decl String:sQuery[192];
1545 Format(sQuery, sizeof(sQuery), "SELECT points FROM `ranks` WHERE auth = '%s'", auth);
1546 SQL_TQuery(g_hDatabase, CallBack_DeleteRecord, sQuery, pack, DBPrio_Low);
1547}
1548
1549public CallBack_DeleteRecord(Handle:owner, Handle:hndl, const String:error[], any:pack)
1550{
1551 new String:auth[MAX_AUTHID_LENGTH];
1552 ResetPack(pack);
1553 new iBuffer = ReadPackCell(pack);
1554 ReadPackString(pack, auth, MAX_AUTHID_LENGTH);
1555 CloseHandle(pack);
1556 if(SQL_FetchRow(hndl))
1557 {
1558 new i_currentpoints = SQL_FetchInt(hndl, 0);
1559 decl String:sQuery[192];
1560 i_currentpoints -= iBuffer;
1561 Format(sQuery, sizeof(sQuery), "UPDATE `ranks` SET `points` = %d WHERE `auth` = '%s'", i_currentpoints, auth);
1562 SQL_TQuery(g_hDatabase, CallBack_UpdateClient, sQuery, _, DBPrio_Low);
1563 }
1564}
1565
1566public OnFinishStage(client, const String:map[], jumps, flashbangs, physicsDifficulty, fpsmax, const String:timeString[], const String:timeDiffString[], totalrank, bool:overwrite, stagenum, strafes, bool:firstTime, Float:fTime)
1567{
1568 if(!g_iEnabled || IsFakeClient(client))
1569 return;
1570
1571 //This shouldn't be done... Cache & Reward after?
1572 if(!g_bLoadedSQL[client] || !g_bAuthed[client] || g_hDatabase == INVALID_HANDLE || !g_iCurrentMapWorth || g_bInitalizing || g_fFinishPrec == 1.0)
1573 return;
1574
1575 new iBuffer = RoundToFloor((float(g_iCurrentMapWorth) * (1.0 - g_fFinishPrec)) / Timer_GetStageCount());
1576
1577 if(g_bTimerPhysics && g_iTotalDiff && physicsDifficulty > 0)
1578 iBuffer = RoundToFloor(float(iBuffer) * g_fDiffFactor[physicsDifficulty]);
1579
1580 if(!g_bStageComplete[client][stagenum][physicsDifficulty])
1581 {
1582 if(Timer_GetStageCount() > 1)
1583 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Complete_Stage_Points", iBuffer, stagenum);
1584 }
1585 else if(g_bStageComplete[client][stagenum][physicsDifficulty] && g_fPointFarmingFactor > 0.0)
1586 {
1587 iBuffer = RoundToNearest(iBuffer * g_fPointFarmingFactor);
1588 if(Timer_GetStageCount() > 1)
1589 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Complete_Stage_Points", iBuffer, stagenum);
1590 }
1591 else
1592 {
1593 return;
1594 }
1595 g_bStageComplete[client][stagenum][physicsDifficulty] = true;
1596
1597 g_iCurrentPoints[client] += iBuffer;
1598
1599 decl String:sQuery[192];
1600 Format(sQuery, sizeof(sQuery), "UPDATE `ranks` SET `points` = %d WHERE `auth` = '%s'", g_iCurrentPoints[client], g_sAuth[client]);
1601 if(g_iEnabled == 2)
1602 PrintToDebug("OnFinishRound(%N): Issuing Query `%s`", client, sQuery);
1603 SQL_TQuery(g_hDatabase, CallBack_UpdateClient, sQuery, GetClientUserId(client), DBPrio_Low);
1604
1605 if(g_iPositionMethod)
1606 {
1607 Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM `ranks` WHERE `points` > %d ORDER BY `points` DESC", g_iCurrentPoints[client]);
1608 if(g_iEnabled == 2)
1609 PrintToDebug("OnFinishRound(%N): Issuing Query `%s`", client, sQuery);
1610 SQL_TQuery(g_hDatabase, CallBack_LoadRank, sQuery, GetClientUserId(client), DBPrio_Low);
1611 }
1612 else
1613 {
1614 if(g_iNextIndex[client] == -1)
1615 return;
1616
1617 if(g_iCurrentPoints[client] >= g_iNextIndex[client])
1618 {
1619 g_iCurrentIndex[client]++;
1620 if(g_iCurrentIndex[client] == g_iTotalRanks)
1621 g_iNextIndex[client] = -1;
1622 else
1623 g_iNextIndex[client] = GetArrayCell(g_hArray_CfgPoints, g_iCurrentIndex[client] + 1);
1624
1625 UpdateClientRank(client);
1626
1627 }
1628 }
1629
1630}
1631
1632
1633public Action:OnChatMessage(&author, Handle:recipients, String:name[], String:message[])
1634{
1635 if(!g_iEnabled || g_hDatabase == INVALID_HANDLE || !g_bAuthed[author] || !g_iDisplayMethod)
1636 return Plugin_Continue;
1637 if(g_iDisplayMethod < 0)
1638 {
1639 new iDisplay = (g_iDisplayMethod * -1);
1640
1641 if((g_hDisplayCookie != INVALID_HANDLE && !g_bLoadedCookies[author]) || !g_bLoadedSQL[author])
1642 {
1643 if(iDisplay & cDisplayChatTag)
1644 {
1645 Format(name, 64, "%s%s", g_sLoadingChatTag, name);
1646 CReplaceColorCodes(name, 64, author, false);
1647 }
1648
1649 if(iDisplay & cDisplayChatColor)
1650 {
1651 Format(message, 256, "%s%s", g_sLoadingChatColor, message);
1652 CReplaceColorCodes(message, 256, author, false);
1653 }
1654
1655 return Plugin_Changed;
1656 }
1657 else if(g_iCurrentIndex[author] != -1)
1658 {
1659 new String:sNameBuffer[MAX_TAG_LENGTH];
1660 if(iDisplay & cDisplayChatTag && g_iClientDisplay[author] & cDisplayChatTag)
1661 {
1662 if((g_bVip[author] || g_bForcedVip[author]) && !StrEqual(g_sVipString[author], ""))
1663 {
1664 FormatCustomColor(g_sVipString[author], sNameBuffer, MAX_TAG_LENGTH, author);
1665 }
1666 else
1667 {
1668 GetArrayString(g_hCfgArray_DisplayChat, g_iCurrentIndex[author], sNameBuffer, sizeof(sNameBuffer));
1669 FormatCustomColor(sNameBuffer, sNameBuffer, MAX_TAG_LENGTH, author);
1670 Format(sNameBuffer, MAX_TAG_LENGTH, "%s%s", sNameBuffer, name);
1671 }
1672 CReplaceColorCodes(sNameBuffer, MAX_TAG_LENGTH, author, false);
1673
1674 strcopy(name, sizeof(sNameBuffer), sNameBuffer);
1675 }
1676
1677 if(iDisplay & cDisplayChatColor && g_iClientDisplay[author] & cDisplayChatColor)
1678 {
1679 new String:sTextPrefix[MAX_TAG_LENGTH];
1680 if((g_bVip[author] || g_bForcedVip[author]) && !StrEqual(g_sVipTextString[author], ""))
1681 {
1682 FormatCustomColor(g_sVipTextString[author], sTextPrefix, 256, author);
1683 }
1684 else
1685 {
1686 GetArrayString(g_hCfgArray_DisplayColor, g_iCurrentIndex[author], sTextPrefix, sizeof(sTextPrefix));
1687 FormatCustomColor(sTextPrefix, sTextPrefix, 256, author);
1688 }
1689 CReplaceColorCodes(sTextPrefix, MAX_TAG_LENGTH, author, false);
1690 stripCustomColors(message, 256);
1691 Format(sTextPrefix, 256, "%s%s", sTextPrefix, message);
1692
1693 strcopy(message, sizeof(sTextPrefix), sTextPrefix);
1694 }
1695 return Plugin_Changed;
1696 }
1697 }
1698 else
1699 {
1700 if(!g_bLoadedSQL[author])
1701 {
1702 if(g_iDisplayMethod & cDisplayChatTag)
1703 {
1704 Format(name, 64, "%s%s", g_sLoadingChatTag, name);
1705 CReplaceColorCodes(name, 64, author, false);
1706 }
1707
1708 if(g_iDisplayMethod & cDisplayChatColor)
1709 {
1710 Format(message, 256, "%s%s", g_sLoadingChatColor, message);
1711 CReplaceColorCodes(message, 256, author, false);
1712 }
1713
1714 return Plugin_Changed;
1715 }
1716 else if(g_iCurrentIndex[author] != -1)
1717 {
1718 new String:sNameBuffer[MAX_TAG_LENGTH];
1719 if(g_iDisplayMethod & cDisplayChatTag)
1720 {
1721 if((g_bVip[author] || g_bForcedVip[author]) && !StrEqual(g_sVipString[author], ""))
1722 {
1723 FormatCustomColor(g_sVipString[author], sNameBuffer, MAX_TAG_LENGTH, author);
1724 }
1725 else
1726 {
1727 GetArrayString(g_hCfgArray_DisplayChat, g_iCurrentIndex[author], sNameBuffer, sizeof(sNameBuffer));
1728 FormatCustomColor(sNameBuffer, sNameBuffer, MAX_TAG_LENGTH, author);
1729 Format(sNameBuffer, MAX_TAG_LENGTH, "%s%s", sNameBuffer, name);
1730 }
1731 CReplaceColorCodes(sNameBuffer, MAX_TAG_LENGTH, author, false);
1732
1733 strcopy(name, sizeof(sNameBuffer), sNameBuffer);
1734 }
1735
1736 if(g_iDisplayMethod & cDisplayChatColor)
1737 {
1738 new String:sTextPrefix[MAX_TAG_LENGTH];
1739 if((g_bVip[author] || g_bForcedVip[author]) && !StrEqual(g_sVipTextString[author], ""))
1740 {
1741 FormatCustomColor(g_sVipTextString[author], sTextPrefix, 64, author);
1742 FormatCustomColor(sTextPrefix, sTextPrefix, 256, author);
1743 }
1744 else
1745 {
1746 GetArrayString(g_hCfgArray_DisplayColor, g_iCurrentIndex[author], sTextPrefix, sizeof(sTextPrefix));
1747 }
1748 CReplaceColorCodes(sTextPrefix, 256, author, false);
1749 stripCustomColors(message, 256);
1750 Format(sTextPrefix, 256, "%s%s", sTextPrefix, message);
1751
1752 strcopy(message, sizeof(sTextPrefix), sTextPrefix);
1753 }
1754
1755 return Plugin_Changed;
1756 }
1757 }
1758
1759 return Plugin_Continue;
1760}
1761
1762
1763stock FormatCustomColor(const String:input[], String:output[], maxlength, client)
1764{
1765 //{custom:9EC34F}
1766 new String:sBuffer[512];
1767 strcopy(sBuffer, sizeof(sBuffer), input);
1768 new String:sName[128];
1769 GetClientName(client, sName, 128);
1770 ReplaceString(sBuffer, maxlength, "{name}", sName, false);
1771 new count = SubStringCount(sBuffer, "{random");
1772 if(count != 0)
1773 {
1774 count++;
1775 new String:sParts[count][128];
1776 new String:sRandom[128];
1777 ExplodeString(sBuffer, "{rando", sParts, count, 128);
1778 for (new i = 1; i < count; i++)
1779 {
1780 if(StrContains(sParts[i], "m}", false) != -1)
1781 {
1782 GetRandomColor(sRandom);
1783 ReplaceString(sParts[i], 128, "m}", sRandom, false);
1784 }
1785 else
1786 {
1787 ReplaceString(sParts[i], 128, "m: ", "", false);
1788 new colorCount = SubStringCount(sParts[i], "{") + 2;
1789 decl String:sColorsParts[colorCount][128];
1790 ReplaceString(sParts[i], 128, "{", "");
1791 ExplodeString(sParts[i], "}", sColorsParts, colorCount, 128);
1792 for (new k = 0; k < colorCount-2; k++)
1793 {
1794 Format(sColorsParts[k], 128, "{%s}", sColorsParts[k]);
1795 }
1796
1797 new randomInt = GetRandomInt(0, colorCount-3);
1798 FormatEx(sParts[i], 128, "%s%s", sColorsParts[randomInt], sColorsParts[colorCount-1]);
1799 }
1800 }
1801 FormatEx(sBuffer, maxlength, "");
1802 for (new i = 1; i < count; i++)
1803 {
1804 FormatEx(sBuffer, maxlength, "%s%s", sBuffer, sParts[i]);
1805 }
1806 }
1807 count = SubStringCount(sBuffer, "{color:");
1808 if(count != 0)
1809 {
1810 count++;
1811 new String:sParts[count][128];
1812 ExplodeString(sBuffer, "{color: ", sParts, count, 128);
1813 for (new i = 1; i < count; i++)
1814 {
1815 ReplaceString(sParts[i], 128, "}", "");
1816 }
1817 FormatEx(sBuffer, maxlength, "");
1818 for (new i = 1; i < count; i++)
1819 {
1820 FormatEx(sBuffer, maxlength, "%s\x07%s", sBuffer, sParts[i]);
1821 }
1822 }
1823 strcopy(output, maxlength, sBuffer);
1824}
1825
1826stock SubStringCount(const String:input[], const String:substring[])
1827{
1828 new count = 0;
1829 new index = 0;
1830 new start = 0;
1831 for (new i = 0; i < 1000; i++)
1832 {
1833 start = StrContains(input[index], substring, false);
1834 if(start == -1)
1835 break;
1836 index = start + index + 1;
1837 count++;
1838 }
1839 return count;
1840}
1841
1842public Action:Event_OnPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
1843{
1844 if(!g_iEnabled)
1845 return Plugin_Continue;
1846
1847 new client = GetClientOfUserId(GetEventInt(event, "userid"));
1848 if(!client || !IsClientInGame(client) || GetClientTeam(client) <= CS_TEAM_SPECTATOR || IsFakeClient(client))
1849 return Plugin_Continue;
1850
1851 //UpdateClientRank(client);
1852 return Plugin_Continue;
1853}
1854
1855public Action:Event_OnPlayerTeam(Handle:event, const String:name[], bool:dontBroadcast)
1856{
1857 if(!g_iEnabled)
1858 return Plugin_Continue;
1859
1860 new client = GetClientOfUserId(GetEventInt(event, "userid"));
1861 if(!client || !IsClientInGame(client) || IsFakeClient(client))
1862 return Plugin_Continue;
1863
1864 //UpdateClientRank(client);
1865 return Plugin_Continue;
1866}
1867
1868public Action:Event_OnPlayerConnect(Handle:event, const String:name[], bool:dontBroadcast)
1869{
1870 dontBroadcast = true;
1871 return Plugin_Continue;
1872}
1873
1874public Action:Event_OnPlayerDisconnect(Handle:event, const String:name[], bool:dontBroadcast)
1875{
1876 dontBroadcast = true;
1877 new client = GetClientOfUserId(GetEventInt(event, "userid"));
1878
1879 if(client > 0 && IsClientInGame(client) && !IsFakeClient(client))
1880 {
1881 if(g_bConnected[client])
1882 {
1883 decl String:sName[64];
1884 GetClientName(client, sName, 64);
1885 if(g_iCurrentPoints[client] >= g_iRequiredPoints)
1886 CPrintToChatAll("%t%t", "Prefix_Chat", "Phrase_Player_Disconnect", sName, g_iCurrentPoints[client], g_iRank[client], g_sAuth[client]);
1887 else
1888 CPrintToChatAll("%t%t", "Prefix_Chat", "Phrase_Player_DisconnectUnRanked", sName, g_sAuth[client]);
1889 }
1890
1891 }
1892 return Plugin_Continue;
1893}
1894
1895UpdateClientRank(client)
1896{
1897 if(g_hDatabase != INVALID_HANDLE)
1898 {
1899 decl String:sQuery[192];
1900 Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM `ranks` WHERE `points` > %d ORDER BY `points` DESC", g_iCurrentPoints[client]);
1901 SQL_TQuery(g_hDatabase, CallBack_UpdateRank, sQuery, GetClientUserId(client), DBPrio_High);
1902 }
1903}
1904
1905public CallBack_UpdateRank(Handle:owner, Handle:hndl, const String:error[], any:userid)
1906{
1907 if(hndl == INVALID_HANDLE)
1908 {
1909 Timer_LogError("SQL Error on CallBack_UpdateRank: %s", error);
1910 return;
1911 }
1912 new client = GetClientOfUserId(userid);
1913 if(!client || !IsClientInGame(client))
1914 return;
1915
1916 if(SQL_FetchRow(hndl))
1917 {
1918 new iCount = SQL_FetchInt(hndl, 0)+1;
1919 g_iRank[client] = iCount;
1920 UpdateClientCountryRank(client);
1921 }
1922}
1923
1924UpdateClientCountryRank(client)
1925{
1926 decl String:sQuery[192];
1927 Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM `ranks` WHERE `points` > %d AND `lastcountry` = '%s' ORDER BY `points` DESC", g_iCurrentPoints[client], g_sCountry[client]);
1928 SQL_TQuery(g_hDatabase, CallBack_UpdateCountryRank, sQuery, GetClientUserId(client));
1929}
1930
1931public CallBack_UpdateCountryRank(Handle:owner, Handle:hndl, const String:error[], any:userid)
1932{
1933 if(hndl == INVALID_HANDLE)
1934 {
1935 Timer_LogError("SQL Error on CallBack_UpdateCountryRank: %s", error);
1936 return;
1937 }
1938 new client = GetClientOfUserId(userid);
1939 if(!client || !IsClientInGame(client))
1940 return;
1941
1942 if(SQL_FetchRow(hndl))
1943 {
1944 new iCount = SQL_FetchInt(hndl, 0)+1;
1945 g_iCountryRank[client] = iCount;
1946 UpdateTotalRankByCountry(client, g_sCountry[client]);
1947 }
1948}
1949
1950// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1951
1952public SQL_Connect_Database(Handle:owner, Handle:hndl, const String:error[], any:data)
1953{
1954 if(hndl == INVALID_HANDLE)
1955 {
1956 Timer_LogError("SQL Error on SQL_Connect_Database.Handle: %s", error);
1957 return;
1958 }
1959
1960 g_hDatabase = hndl;
1961 decl String:sDriver[16];
1962 SQL_GetDriverIdent(owner, sDriver, sizeof(sDriver));
1963
1964 g_bSql = StrEqual(sDriver, "mysql", false);
1965 if(g_bSql)
1966 {
1967 SQL_TQuery(g_hDatabase, CallBack_Names, "SET NAMES 'utf8'", _, DBPrio_High);
1968
1969 SQL_TQuery(g_hDatabase, CallBack_Creation, "CREATE TABLE IF NOT EXISTS `ranks` (`auth` varchar(24) NOT NULL PRIMARY KEY, `points` int(11) NOT NULL default 0, `lastname` varchar(65) NOT NULL default '', `lastplay` int(11) NOT NULL default 0, `lastcountry` varchar(64) NOT NULL, `vipendtime` int(11) NOT NULL default 0, `customtag` varchar(512), `customchat` varchar(64));");
1970
1971 SQL_TQuery(g_hDatabase, CallBack_Maps, "CREATE TABLE IF NOT EXISTS `maps` (`map` varchar(256) NOT NULL PRIMARY KEY, `points` int(11) NOT NULL default 0, `played` int(11) NOT NULL default 0, `setuptime` int(32) NOT NULL default 0, `tier` int(11) NOT NULL default 1);");
1972 }
1973 else
1974 {
1975 SQL_TQuery(g_hDatabase, CallBack_Creation, "CREATE TABLE IF NOT EXISTS `ranks` (`auth` varchar(24) NOT NULL PRIMARY KEY, `points` INTEGER NOT NULL default 0, `lastname` varchar(65) NOT NULL default '', `lastplay` INTEGER NOT NULL default 0, `lastcountry` varchar(64) NOT NULL, `vipendtime` INTEGER NOT NULL default 0, `customtag` varchar(512), `customchat` varchar(64));");
1976
1977 SQL_TQuery(g_hDatabase, CallBack_Maps, "CREATE TABLE IF NOT EXISTS `maps` (`map` varchar(256) NOT NULL PRIMARY KEY, `points` INTEGER NOT NULL default 0, `played` INTEGER NOT NULL default 0, `setuptime` INTEGER NOT NULL default 0, `tier` INTEGER NOT NULL default 1);");
1978 }
1979
1980 decl String:sQuery[128];
1981 Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM `ranks` WHERE `points` >= %d", g_iRequiredPoints);
1982
1983 SQL_TQuery(g_hDatabase, CallBack_Total, sQuery, _, DBPrio_Low);
1984}
1985
1986public CallBack_Total(Handle:owner, Handle:hndl, const String:error[], any:ref)
1987{
1988 if(hndl == INVALID_HANDLE)
1989 {
1990 Timer_LogError("SQL Error on CallBack_Total: %s", error);
1991 return;
1992 }
1993
1994 if(SQL_FetchRow(hndl))
1995 {
1996 g_iTotalPlayers = SQL_FetchInt(hndl, 0);
1997 }
1998}
1999
2000UpdateTotalRankByCountry(client, const String:sCountry[])
2001{
2002 decl String:sQuery[128];
2003 FormatEx(sQuery, 128, "SELECT COUNT(*) FROM `ranks` WHERE lastcountry = '%s' AND `points` >= %d", sCountry, g_iRequiredPoints);
2004 SQL_TQuery(g_hDatabase, CallBack_TotalCountry, sQuery, client, DBPrio_Normal);
2005}
2006
2007public CallBack_TotalCountry(Handle:owner, Handle:hndl, const String:error[], any:data)
2008{
2009 if(hndl == INVALID_HANDLE)
2010 {
2011 Timer_LogError("SQL Error on CallBack_TotalCountry: %s", error);
2012 return;
2013 }
2014
2015 if(SQL_FetchRow(hndl))
2016 {
2017 g_iTotalRanksCountry[data] = SQL_FetchInt(hndl, 0);
2018 }
2019}
2020
2021public CallBack_Names(Handle:owner, Handle:hndl, const String:error[], any:data)
2022{
2023 if(hndl == INVALID_HANDLE)
2024 {
2025 Timer_LogError("SQL Error on CallBack_Names: %s", error);
2026 return;
2027 }
2028}
2029
2030public CallBack_Creation(Handle:owner, Handle:hndl, const String:error[], any:data)
2031{
2032 if(hndl == INVALID_HANDLE)
2033 {
2034 Timer_LogError("SQL Error on CallBack_Creation: %s", error);
2035 return;
2036 }
2037
2038 if(g_bLateQuery)
2039 {
2040 decl String:sQuery[192];
2041 for (new i = 1; i <= MaxClients; i++)
2042 {
2043 if(IsClientInGame(i) && !g_bLoadedSQL[i] && g_bAuthed[i] && !IsFakeClient(i))
2044 {
2045 Format(sQuery, sizeof(sQuery), "SELECT `points`,`vipendtime`,`customtag`,`customchat` FROM `ranks` WHERE `auth` = '%s'", g_sAuth[i]);
2046 if(g_iEnabled == 2)
2047 PrintToDebug("CallBack_Creation(%N): Issuing Query `%s`", i, sQuery);
2048 SQL_TQuery(g_hDatabase, CallBack_ClientConnect, sQuery, GetClientUserId(i), DBPrio_High);
2049 }
2050 }
2051
2052 g_bLateQuery = false;
2053 }
2054}
2055
2056GetMapWorth()
2057{
2058 if(g_bInitalizing)
2059 return;
2060
2061 decl String:sQuery[384];
2062 Format(sQuery, sizeof(sQuery), "SELECT `points`, `tier` FROM `maps` WHERE `map` = '%s'", g_sCurrentMap);
2063 if(g_iEnabled == 2)
2064 PrintToDebug("GetMapWorth: Issuing Query `%s`", sQuery);
2065 SQL_TQuery(g_hDatabase, CallBack_MapConnect, sQuery);
2066}
2067
2068public CallBack_Maps(Handle:owner, Handle:hndl, const String:error[], any:data)
2069{
2070 if(hndl == INVALID_HANDLE)
2071 {
2072 Timer_LogError("SQL Error on CallBack_Maps: %s", error);
2073 return;
2074 }
2075
2076 GetMapWorth();
2077}
2078
2079public CallBack_MapConnect(Handle:owner, Handle:hndl, const String:error[], any:data)
2080{
2081 if(hndl == INVALID_HANDLE)
2082 {
2083 Timer_LogError("SQL Error on CallBack_MapConnect: %s", error);
2084 return;
2085 }
2086
2087 decl String:sQuery[384];
2088 if(!SQL_GetRowCount(hndl))
2089 {
2090 if(!GetTrieValue(g_hTrie_CfgWorth, g_sCurrentMap, g_iCurrentMapWorth))
2091 g_iCurrentMapWorth = g_iDefaultMapWorth;
2092
2093 if(!GetTrieValue(g_hTrie_CfgTier, g_sCurrentMap, g_iCurrentMapTier))
2094 g_iCurrentMapTier = 1;
2095
2096 Format(sQuery, sizeof(sQuery), "INSERT INTO `maps` (`map`,`points`,`played`, `setuptime`, `tier`) VALUES ('%s', %d, 0, %d, %d)", g_sCurrentMap, g_iCurrentMapWorth, GetTime(), g_iCurrentMapTier);
2097 if(g_iEnabled == 2)
2098 PrintToDebug("CallBack_MapConnect(): Issuing Query `%s`", sQuery);
2099 SQL_TQuery(g_hDatabase, CallBack_MapInsert, sQuery);
2100 }
2101 else if(SQL_FetchRow(hndl))
2102 {
2103 g_iCurrentMapWorth = SQL_FetchInt(hndl, 0);
2104 g_iCurrentMapTier = SQL_FetchInt(hndl, 1);
2105
2106 Format(sQuery, sizeof(sQuery), "UPDATE `maps` SET `played` = `played` + 1 WHERE map = '%s'", g_sCurrentMap);
2107 if(g_iEnabled == 2)
2108 PrintToDebug("CallBack_MapConnect(): Issuing Query `%s`", sQuery);
2109 SQL_TQuery(g_hDatabase, CallBack_MapUpdate, sQuery);
2110 }
2111}
2112
2113public CallBack_MapInsert(Handle:owner, Handle:hndl, const String:error[], any:data)
2114{
2115 if(hndl == INVALID_HANDLE)
2116 {
2117 Timer_LogError("SQL Error on CallBack_MapInsert: %s", error);
2118 return;
2119 }
2120}
2121
2122public CallBack_MapUpdate(Handle:owner, Handle:hndl, const String:error[], any:data)
2123{
2124 if(hndl == INVALID_HANDLE)
2125 {
2126 Timer_LogError("SQL Error on CallBack_MapUpdate: %s", error);
2127 return;
2128 }
2129}
2130
2131public CallBack_MapInfo(Handle:owner, Handle:hndl, const String:error[], any:data)
2132{
2133 if(hndl == INVALID_HANDLE)
2134 {
2135 Timer_LogError("SQL Error on CallBack_MapInfo: %s", error);
2136 return;
2137 }
2138
2139 new client = GetClientOfUserId(data);
2140 if(!client || !IsClientInGame(client))
2141 return;
2142
2143 if(!SQL_GetRowCount(hndl))
2144 {
2145 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Points_Not_Found", g_sMapChoosed[client]);
2146 }
2147 else if(SQL_FetchRow(hndl))
2148 {
2149 new String:sMapName[MAX_MAPNAME_LENGTH];
2150 SQL_FetchString(hndl, 0, sMapName, sizeof(sMapName));
2151 new points = SQL_FetchInt(hndl, 1);
2152 new tier = SQL_FetchInt(hndl, 2);
2153 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Points_Per_Map_Name", sMapName, points, tier);
2154 }
2155}
2156
2157public CallBack_CreateClient(Handle:owner, Handle:hndl, const String:error[], any:userid)
2158{
2159 if(hndl == INVALID_HANDLE)
2160 {
2161 Timer_LogError("SQL Error on CallBack_CreateClient: %s", error);
2162 return;
2163 }
2164
2165 new client = GetClientOfUserId(userid);
2166 if(!client || !IsClientInGame(client))
2167 return;
2168
2169 g_iCurrentIndex[client] = -1;
2170 if(g_iPositionMethod)
2171 {
2172 decl String:sQuery[192];
2173 Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM `ranks` WHERE `points` > %d ORDER BY `points` DESC", g_iCurrentPoints[client]);
2174 if(g_iEnabled == 2)
2175 PrintToDebug("CallBack_CreateClient(%N): Issuing Query `%s`", client, sQuery);
2176 SQL_TQuery(g_hDatabase, CallBack_LoadRank, sQuery, userid);
2177 }
2178 else
2179 {
2180 for(new i = 0; i <= g_iTotalRanks; i++)
2181 {
2182 new iPoints = GetArrayCell(g_hArray_CfgPoints, i);
2183 if(iPoints == -1)
2184 continue;
2185
2186 if(g_iCurrentPoints[client] >= GetArrayCell(g_hArray_CfgPoints, i))
2187 g_iCurrentIndex[client] = i;
2188 else
2189 break;
2190 }
2191
2192 if(g_iCurrentIndex[client] == -1)
2193 {
2194 g_iCurrentIndex[client] = FindValueInArray(g_hArray_CfgPoints, -1);
2195 g_iNextIndex[client] = GetArrayCell(g_hArray_CfgPoints, g_iTotalRanks);
2196 }
2197 else
2198 {
2199 if(g_iCurrentIndex[client] == g_iTotalRanks)
2200 g_iNextIndex[client] = -1;
2201 else
2202 g_iNextIndex[client] = GetArrayCell(g_hArray_CfgPoints, g_iCurrentIndex[client] + 1);
2203 }
2204
2205 g_bLoadedSQL[client] = true;
2206
2207 UpdateClientRank(client);
2208
2209 }
2210}
2211
2212public CallBack_UpdateClient(Handle:owner, Handle:hndl, const String:error[], any:data)
2213{
2214 if(hndl == INVALID_HANDLE)
2215 {
2216 Timer_LogError("SQL Error on CallBack_UpdateClient: %s", error);
2217 return;
2218 }
2219}
2220
2221public CallBack_ClientConnect(Handle:owner, Handle:hndl, const String:error[], any:userid)
2222{
2223 if(hndl == INVALID_HANDLE)
2224 {
2225 Timer_LogError("SQL Error on CallBack_ClientConnect: %s", error);
2226 return;
2227 }
2228
2229 new client = GetClientOfUserId(userid);
2230 if(!client || !IsClientInGame(client) || client == 0)
2231 return;
2232
2233 new String:sName[MAX_NAME_LENGTH];
2234 new String:sSafeName[((MAX_NAME_LENGTH * 2) + 1)];
2235 new String:ip[32];
2236
2237 GetClientName(client, sName, sizeof(sName));
2238 SQL_EscapeString(g_hDatabase, sName, sSafeName, sizeof(sSafeName));
2239
2240 if(!(GetClientIP(client,ip,sizeof(ip)) && GeoipCountry(ip,g_sCountry[client], 64)))
2241 FormatEx(g_sCountry[client], 64, "Unknown Country");
2242 UpdateTotalRankByCountry(client, g_sCountry[client]);
2243 decl String:sQuery[256];
2244 if(!SQL_GetRowCount(hndl))
2245 {
2246 g_iCurrentPoints[client] = 0;
2247 g_bVip[client] = false;
2248 g_bForcedVip[client] = false;
2249 Format(sQuery, sizeof(sQuery), "INSERT INTO `ranks` (auth, points, lastname, lastplay, lastcountry, vipendtime) VALUES ('%s', 0, '%s', %d, '%s', 0)", g_sAuth[client], sSafeName, GetTime(), g_sCountry[client]);
2250 if(g_iEnabled == 2)
2251 PrintToDebug("CallBack_ClientConnect(%N): Issuing Query `%s`", client, sQuery);
2252 SQL_TQuery(g_hDatabase, CallBack_CreateClient, sQuery, userid, DBPrio_High);
2253
2254 g_iTotalPlayers++;
2255 }
2256 else if(SQL_FetchRow(hndl))
2257 {
2258 Format(sQuery, sizeof(sQuery), "UPDATE `ranks` SET lastname = '%s', lastplay = %d, lastcountry = '%s' WHERE auth = '%s'", sSafeName, GetTime(), g_sCountry[client], g_sAuth[client]);
2259 if(g_iEnabled == 2)
2260 PrintToDebug("CallBack_ClientConnect(%N): Issuing Query `%s`", client, sQuery);
2261 SQL_TQuery(g_hDatabase, CallBack_UpdateClient, sQuery, _, DBPrio_High);
2262
2263 g_iCurrentPoints[client] = SQL_FetchInt(hndl, 0);
2264 new vipTime = SQL_FetchInt(hndl, 1);
2265 if(GetTime() < vipTime || vipTime == -1)
2266 {
2267 g_bVip[client] = true;
2268 }
2269 else if(vipTime == -2)
2270 {
2271 g_bForcedVip[client] = true;
2272 }
2273 else
2274 {
2275 g_bVip[client] = false;
2276 g_bForcedVip[client] = false;
2277 }
2278 SQL_FetchString(hndl, 2, g_sVipString[client], MAX_TAG_LENGTH);
2279 SQL_FetchString(hndl, 3, g_sVipTextString[client], MAX_TAG_LENGTH);
2280
2281 if(g_iPositionMethod)
2282 {
2283 Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM `ranks` WHERE `points` > %d ORDER BY `points` DESC", g_iCurrentPoints[client]);
2284 if(g_iEnabled == 2)
2285 PrintToDebug("CallBack_LoadRank(%N): Issuing Query `%s`", client, sQuery);
2286 SQL_TQuery(g_hDatabase, CallBack_LoadRank, sQuery, userid, DBPrio_High);
2287 }
2288 else
2289 {
2290 g_iCurrentIndex[client] = -1;
2291 for(new i = 0; i <= g_iTotalRanks; i++)
2292 {
2293 new iPoints = GetArrayCell(g_hArray_CfgPoints, i);
2294 if(iPoints == -1)
2295 continue;
2296
2297 if(g_iCurrentPoints[client] >= GetArrayCell(g_hArray_CfgPoints, i))
2298 g_iCurrentIndex[client] = i;
2299 else
2300 break;
2301 }
2302
2303 if(g_iCurrentIndex[client] == -1)
2304 {
2305 g_iCurrentIndex[client] = FindValueInArray(g_hArray_CfgPoints, -1);
2306 g_iNextIndex[client] = GetArrayCell(g_hArray_CfgPoints, g_iTotalRanks);
2307 }
2308 else
2309 {
2310 if(g_iCurrentIndex[client] == g_iTotalRanks)
2311 g_iNextIndex[client] = -1;
2312 else
2313 g_iNextIndex[client] = GetArrayCell(g_hArray_CfgPoints, g_iCurrentIndex[client] + 1);
2314 }
2315
2316 g_bLoadedSQL[client] = true;
2317
2318 UpdateClientRank(client);
2319 if(!g_bConnected[client])
2320 {
2321 /*
2322 GetClientName(client, sName, 64);
2323 new String:sCountry[64];
2324 if(!(GetClientIP(client,ip,sizeof(ip)) && GeoipCountry(ip,sCountry[client], 64)))
2325 FormatEx(sCountry[client], 64, "Unknown Country");
2326
2327 if(g_iCurrentPoints[client] >= g_iRequiredPoints)
2328 CPrintToChatAll("%t%t", "Prefix_Chat", "Phrase_Player_Connect", sName, g_iCurrentPoints[client], g_iRank[client], g_sAuth[client], sCountry[client]);
2329 else
2330 CPrintToChatAll("%t%t", "Prefix_Chat", "Phrase_Player_ConnectUnRanked", sName, g_sAuth[client], sCountry[client]);
2331 g_bConnected[client] = true;
2332 */
2333 CreateTimer(3.0, Timer_ConnectMessage, client, TIMER_FLAG_NO_MAPCHANGE);
2334 }
2335 }
2336 }
2337
2338
2339 g_iDifficultyCompletionsProgress[client] = 1;
2340 Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM `round` WHERE `map` = '%s' AND `auth` = '%s' AND `part` = 'full' AND `physicsdifficulty` = '%d' GROUP BY 'map' ", g_sCurrentMap, g_sAuth[client], g_iDifficultyCompletionsProgress[client]);
2341 if(g_iEnabled == 2)
2342 PrintToDebug("CallBack_ClientConnect(%N): Issuing Query `%s`", client, sQuery);
2343 SQL_TQuery(g_hDatabase, CallBack_LoadCompletions, sQuery, userid);
2344}
2345
2346public Action Timer_ConnectMessage(Handle timer, any client)
2347{
2348 if(!g_bConnected[client])
2349 {
2350 new String:sName[64];
2351 GetClientName(client, sName, 64);
2352 new String:sCountry[64];
2353 new String:ip[32];
2354 if(!(GetClientIP(client,ip,sizeof(ip)) && GeoipCountry(ip,sCountry[client], 64)))
2355 FormatEx(sCountry[client], 64, "Unknown Country");
2356
2357 if(g_iCurrentPoints[client] >= g_iRequiredPoints)
2358 CPrintToChatAll("%t%t", "Prefix_Chat", "Phrase_Player_Connect", sName, g_iCurrentPoints[client], g_iRank[client], g_sAuth[client], sCountry[client]);
2359 else
2360 CPrintToChatAll("%t%t", "Prefix_Chat", "Phrase_Player_ConnectUnRanked", sName, g_sAuth[client], sCountry[client]);
2361 g_bConnected[client] = true;
2362 }
2363}
2364
2365public CallBack_LoadStageCompletions(Handle:owner, Handle:hndl, const String:error[], any:userid)
2366{
2367 if(hndl == INVALID_HANDLE)
2368 {
2369 Timer_LogError("SQL Error on CallBack_LoadCompletions: %s", error);
2370 return;
2371 }
2372 new client = GetClientOfUserId(userid);
2373 if(!client || !IsClientInGame(client))
2374 return;
2375
2376 if(SQL_FetchRow(hndl))
2377 g_bStageComplete[client][g_iStageCompletionsProgress[client]][g_iDifficultyCompletionsProgress[client]] = true;
2378 else
2379 g_bStageComplete[client][g_iStageCompletionsProgress[client]][g_iDifficultyCompletionsProgress[client]] = false;
2380
2381 decl String:sQuery[256];
2382 if(g_iStageCompletionsProgress[client] <= Timer_GetStageCount())
2383 {
2384 g_iDifficultyCompletionsProgress[client] = 1;
2385 Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM `round` WHERE `map` = '%s' AND `auth` = '%s' AND `part` = 'stage%d' AND `physicsdifficulty` = '%d' GROUP BY 'map' ", g_sCurrentMap, g_sAuth[client], g_iStageCompletionsProgress[client], g_iDifficultyCompletionsProgress[client]);
2386 SQL_TQuery(g_hDatabase, CallBack_LoadDifficultyStageCompletions, sQuery, userid);
2387 }
2388}
2389
2390public CallBack_LoadDifficultyStageCompletions(Handle:owner, Handle:hndl, const String:error[], any:userid)
2391{
2392 if(hndl == INVALID_HANDLE)
2393 {
2394 Timer_LogError("SQL Error on CallBack_LoadCompletions: %s", error);
2395 return;
2396 }
2397 new client = GetClientOfUserId(userid);
2398 if(!client || !IsClientInGame(client))
2399 return;
2400
2401 if(SQL_FetchRow(hndl))
2402 g_bStageComplete[client][g_iStageCompletionsProgress[client]][g_iDifficultyCompletionsProgress[client]] = true;
2403 else
2404 g_bStageComplete[client][g_iStageCompletionsProgress[client]][g_iDifficultyCompletionsProgress[client]] = false;
2405
2406 decl String:sQuery[256];
2407 if(g_iDifficultyCompletionsProgress[client] < g_iTotalDiff)
2408 {
2409 g_iDifficultyCompletionsProgress[client]++;
2410 Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM `round` WHERE `map` = '%s' AND `auth` = '%s' AND `part` = 'stage%d' AND `physicsdifficulty` = '%d' GROUP BY 'map' ", g_sCurrentMap, g_sAuth[client], g_iStageCompletionsProgress[client], g_iDifficultyCompletionsProgress[client]);
2411 SQL_TQuery(g_hDatabase, CallBack_LoadDifficultyStageCompletions, sQuery, userid);
2412 }
2413 else if(g_bTimerMapZones)
2414 {
2415 g_iDifficultyCompletionsProgress[client] = 1;
2416 g_iStageCompletionsProgress[client]++;
2417 Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM `round` WHERE `map` = '%s' AND `auth` = '%s' AND `part` = 'stage%d' AND `physicsdifficulty` = '%d' GROUP BY 'map' ", g_sCurrentMap, g_sAuth[client], g_iStageCompletionsProgress[client], g_iDifficultyCompletionsProgress[client]);
2418 SQL_TQuery(g_hDatabase, CallBack_LoadStageCompletions, sQuery, userid);
2419 }
2420}
2421
2422public CallBack_LoadCompletions(Handle:owner, Handle:hndl, const String:error[], any:userid)
2423{
2424 if(hndl == INVALID_HANDLE)
2425 {
2426 Timer_LogError("SQL Error on CallBack_LoadStageCompletions: %s", error);
2427 return;
2428 }
2429 new client = GetClientOfUserId(userid);
2430 if(!client || !IsClientInGame(client))
2431 return;
2432
2433 if(SQL_FetchRow(hndl))
2434 g_bComplete[client][g_iDifficultyCompletionsProgress[client]] = true;
2435 else
2436 g_bComplete[client][g_iDifficultyCompletionsProgress[client]] = false;
2437
2438 decl String:sQuery[256];
2439 if(g_iDifficultyCompletionsProgress[client] < g_iTotalDiff)
2440 {
2441 g_iDifficultyCompletionsProgress[client]++;
2442 Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM `round` WHERE `map` = '%s' AND `auth` = '%s' AND `part` = 'full' AND `physicsdifficulty` = '%d' GROUP BY 'map' ", g_sCurrentMap, g_sAuth[client], g_iDifficultyCompletionsProgress[client]);
2443 SQL_TQuery(g_hDatabase, CallBack_LoadCompletions, sQuery, userid);
2444 }
2445 else if(g_bTimerMapZones)
2446 {
2447 g_iDifficultyCompletionsProgress[client] = 1;
2448 g_iStageCompletionsProgress[client] = 1;
2449 Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM `round` WHERE `map` = '%s' AND `auth` = '%s' AND `part` = 'stage%d' AND `physicsdifficulty` = '%d' GROUP BY 'map' ", g_sCurrentMap, g_sAuth[client], g_iStageCompletionsProgress[client], g_iDifficultyCompletionsProgress[client]);
2450 SQL_TQuery(g_hDatabase, CallBack_LoadStageCompletions, sQuery, userid);
2451 }
2452}
2453
2454public CallBack_LoadRank(Handle:owner, Handle:hndl, const String:error[], any:userid)
2455{
2456 if(hndl == INVALID_HANDLE)
2457 {
2458 Timer_LogError("SQL Error on CallBack_LoadRank: %s", error);
2459 return;
2460 }
2461 new client = GetClientOfUserId(userid);
2462 if(!client || !IsClientInGame(client) || !g_iPositionMethod)
2463 return;
2464
2465 new iOutside = FindValueInArray(g_hArray_Positions, -1);
2466 if(SQL_FetchRow(hndl))
2467 {
2468 g_iRank[client] = SQL_FetchInt(hndl, 0)+1;
2469 if(g_iRank[client] > g_iHighestRank)
2470 {
2471 g_iCurrentIndex[client] = iOutside;
2472 }
2473 else
2474 {
2475 for(new i = g_iTotalRanks-1; i != 0; i--)
2476 {
2477 if(GetArrayCell(g_hArray_CfgRanks, i) < g_iRank[client] && g_iRank[client] <= GetArrayCell(g_hArray_CfgRanks, i+1))
2478 {
2479 g_iCurrentIndex[client] = i+1;
2480 break;
2481 }
2482
2483 }
2484 }
2485 }
2486 else
2487 {
2488 g_iCurrentIndex[client] = iOutside;
2489 }
2490
2491 if(g_iCurrentPoints[client] < g_iRequiredPoints)
2492 {
2493 g_iCurrentIndex[client] = iOutside;
2494 }
2495 g_bLoadedSQL[client] = true;
2496
2497 UpdateClientRank(client);
2498 if(!g_bConnected[client])
2499 {
2500 /*
2501 decl String:sName[64];
2502 GetClientName(client, sName, 64);
2503 new String:sCountry[64];
2504 decl String:ip[32];
2505 if(!(GetClientIP(client,ip,sizeof(ip)) && GeoipCountry(ip,sCountry[client], 64)))
2506 FormatEx(sCountry[client], 64, "Unknown Country");
2507
2508 if(g_iCurrentPoints[client] >= g_iRequiredPoints)
2509 CPrintToChatAll("%t%t", "Prefix_Chat", "Phrase_Player_Connect", sName, g_iCurrentPoints[client], g_iRank[client], g_sAuth[client], sCountry[client]);
2510 else
2511 CPrintToChatAll("%t%t", "Prefix_Chat", "Phrase_Player_ConnectUnRanked", sName, g_sAuth[client], sCountry[client]);
2512 g_bConnected[client] = true;
2513 */
2514 CreateTimer(3.0, Timer_ConnectMessage, client, TIMER_FLAG_NO_MAPCHANGE);
2515 }
2516}
2517
2518public CallBack_TopCountry(Handle:owner, Handle:hndl, const String:error[], any:userid)
2519{
2520 if(hndl == INVALID_HANDLE)
2521 {
2522 Timer_LogError("SQL Error on CallBack_TopCountry: %s", error);
2523 return;
2524 }
2525 new client = GetClientOfUserId(userid);
2526 if(!client || !IsClientInGame(client))
2527 return;
2528
2529 decl String:sCountry[75];
2530 decl String:sDisplay[128];
2531 new Handle:menu = CreateMenu(MenuHandler_TopCountry);
2532 SetMenuTitle(menu, "%T", "Menu_Title_Top_Country", client);
2533 SetMenuExitButton(menu, true);
2534 SetMenuExitBackButton(menu, false);
2535 new i = 0;
2536 if(SQL_GetRowCount(hndl))
2537 {
2538 while(SQL_FetchRow(hndl))
2539 {
2540 SQL_FetchString(hndl, 0, sCountry, sizeof(sCountry));
2541 FormatEx(sDisplay, 128, "%T", "Menu_Top_Option_Country", client, sCountry, SQL_FetchInt(hndl, 1), i + 1, SQL_FetchInt(hndl, 2));
2542 AddMenuItem(menu, sCountry, sDisplay);
2543 i++;
2544 }
2545 }
2546 DisplayMenu(menu, client, MENU_TIME_FOREVER);
2547}
2548
2549public MenuHandler_TopCountry(Handle:menu, MenuAction:action, param1, param2)
2550{
2551 switch(action)
2552 {
2553 case MenuAction_End:
2554 CloseHandle(menu);
2555 case MenuAction_Select:
2556 {
2557 decl String:sInfo[75];
2558 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2559
2560 new Handle:pack = CreateDataPack();
2561 WritePackCell(pack, GetClientUserId(param1));
2562 WritePackString(pack, sInfo);
2563
2564 decl String:sQuery[192];
2565 Format(sQuery, sizeof(sQuery), "SELECT `lastname`,`points`,`auth` FROM `ranks` WHERE `lastcountry` = '%s' AND `points` >= %d ORDER BY `points` DESC LIMIT %d", sInfo, g_iRequiredPoints, g_iLimitTopPlayers);
2566 SQL_TQuery(g_hDatabase, CallBack_TopInCountry, sQuery, pack);
2567 }
2568 }
2569}
2570
2571public CallBack_TopInCountry(Handle:owner, Handle:hndl, const String:error[], any:pack)
2572{
2573 if(hndl == INVALID_HANDLE)
2574 {
2575 Timer_LogError("SQL Error on CallBack_Top: %s", error);
2576 return;
2577 }
2578 ResetPack(pack);
2579 new client = GetClientOfUserId(ReadPackCell(pack));
2580 if(!client || !IsClientInGame(client))
2581 return;
2582
2583 decl String:sCountry[75];
2584 ReadPackString(pack, sCountry, 75);
2585 new Handle:menu = CreateMenu(MenuHandler_MenuTopPlayers);
2586 SetMenuTitle(menu, "%T", "Menu_Title_Top_InCountry", client, sCountry);
2587 SetMenuExitButton(menu, true);
2588 SetMenuExitBackButton(menu, false);
2589
2590 new iIndex, iPoints;
2591 decl String:sName[32];
2592 decl String:sAuth[64];
2593 decl String:sDisplay[64];
2594 if(SQL_GetRowCount(hndl))
2595 {
2596 new Handle:hPack = CreateDataPack();
2597 WritePackCell(hPack, iIndex);
2598 while(SQL_FetchRow(hndl))
2599 {
2600 SQL_FetchString(hndl, 0, sName, sizeof(sName));
2601 iPoints = SQL_FetchInt(hndl, 1);
2602 SQL_FetchString(hndl, 2, sAuth, sizeof(sAuth));
2603
2604 Format(sDisplay, sizeof(sDisplay), "%T", "Menu_Top_Option", client, sName, iPoints, iIndex + 1);
2605 AddMenuItem(menu, sAuth, sDisplay, ITEMDRAW_DEFAULT);
2606
2607 iIndex++;
2608 }
2609 DisplayMenu(menu, client, MENU_TIME_FOREVER);
2610 }
2611}
2612
2613public CallBack_TopCountryByName(Handle:owner, Handle:hndl, const String:error[], any:data)
2614{
2615 if(hndl == INVALID_HANDLE)
2616 {
2617 Timer_LogError("SQL Error on CallBack_TopCountryByName: %s", error);
2618 return;
2619 }
2620 new client = GetClientOfUserId(data);
2621 if(!client || !IsClientInGame(client))
2622 return;
2623
2624 if(SQL_FetchRow(hndl))
2625 {
2626 new String:sCountry[64];
2627 SQL_FetchString(hndl, 0, sCountry, 64);
2628
2629 new Handle:hPack = CreateDataPack();
2630 WritePackCell(hPack, GetClientUserId(client));
2631 WritePackString(hPack, sCountry);
2632
2633 decl String:sQuery[192];
2634 Format(sQuery, sizeof(sQuery), "SELECT `lastname`,`points`,`auth` FROM `ranks` WHERE `lastcountry` = '%s' AND `points` >= %d ORDER BY `points` DESC LIMIT %d", sCountry, g_iRequiredPoints, g_iLimitTopPlayers);
2635 SQL_TQuery(g_hDatabase, CallBack_TopInCountry, sQuery, hPack);
2636 }
2637}
2638
2639public CallBack_TopCountryByPlace(Handle:owner, Handle:hndl, const String:error[], any:data)
2640{
2641 ResetPack(data);
2642 new client = GetClientOfUserId(ReadPackCell(data));
2643 if(!client || !IsClientInGame(client))
2644 return;
2645 new rank = ReadPackCell(data);
2646 new counter = 0;
2647 while(SQL_FetchRow(hndl))
2648 {
2649 if(rank == counter)
2650 {
2651 new String:sCountry[64];
2652 SQL_FetchString(hndl, 0, sCountry, 64);
2653
2654 new Handle:hPack = CreateDataPack();
2655 WritePackCell(hPack, GetClientUserId(client));
2656 WritePackString(hPack, sCountry);
2657
2658 decl String:sQuery[192];
2659 Format(sQuery, sizeof(sQuery), "SELECT `lastname`,`points`,`auth` FROM `ranks` WHERE `lastcountry` = '%s' AND `points` >= %d ORDER BY `points` DESC LIMIT %d", sCountry, g_iRequiredPoints, g_iLimitTopPlayers);
2660 SQL_TQuery(g_hDatabase, CallBack_TopInCountry, sQuery, hPack);
2661 }
2662 counter++;
2663 }
2664}
2665public CallBack_Top(Handle:owner, Handle:hndl, const String:error[], any:userid)
2666{
2667 if(hndl == INVALID_HANDLE)
2668 {
2669 Timer_LogError("SQL Error on CallBack_Top: %s", error);
2670 return;
2671 }
2672 new client = GetClientOfUserId(userid);
2673 if(!client || !IsClientInGame(client))
2674 return;
2675
2676 new iIndex, iPoints;
2677 decl String:sName[32];
2678 decl String:sAuth[64];
2679 if(SQL_GetRowCount(hndl))
2680 {
2681 new Handle:hPack = CreateDataPack();
2682 WritePackCell(hPack, iIndex);
2683 while(SQL_FetchRow(hndl))
2684 {
2685 SQL_FetchString(hndl, 0, sName, sizeof(sName));
2686 iPoints = SQL_FetchInt(hndl, 1);
2687 SQL_FetchString(hndl, 2, sAuth, sizeof(sAuth));
2688
2689 WritePackString(hPack, sName);
2690 WritePackCell(hPack, iPoints);
2691 WritePackString(hPack, sAuth);
2692
2693 iIndex++;
2694 }
2695
2696 SetPackPosition(hPack, 0);
2697 WritePackCell(hPack, iIndex);
2698 CreateTopMenu(client, hPack);
2699 }
2700 else
2701 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Rank_None");
2702}
2703
2704CreateTopMenu(client, Handle:pack)
2705{
2706 decl String:sBuffer[128], String:sName[32], String:sAuth[64];
2707 new Handle:hMenu = CreateMenu(MenuHandler_MenuTopPlayers);
2708
2709 Format(sBuffer, sizeof(sBuffer), "%T", "Menu_Title_Top", client, g_iLimitTopPlayers);
2710 SetMenuTitle(hMenu, sBuffer);
2711 if(g_iLimitTopPerPage)
2712 SetMenuPagination(hMenu, g_iLimitTopPerPage);
2713 SetMenuExitButton(hMenu, true);
2714 SetMenuExitBackButton(hMenu, false);
2715
2716 ResetPack(pack);
2717 new iCount = ReadPackCell(pack);
2718 for(new i = 0; i < iCount; i++)
2719 {
2720 ReadPackString(pack, sName, sizeof(sName));
2721 new iPoints = ReadPackCell(pack);
2722 ReadPackString(pack, sAuth, sizeof(sAuth));
2723
2724 Format(sBuffer, sizeof(sBuffer), "%T", "Menu_Top_Option", client, sName, iPoints, i + 1);
2725 AddMenuItem(hMenu, sAuth, sBuffer, ITEMDRAW_DEFAULT);
2726 }
2727 CloseHandle(pack);
2728 Format(sBuffer, sizeof(sBuffer), "%T", "Menu_Title_Top", client, iCount);
2729 DisplayMenuAtItem(hMenu, client, g_iChoosedTopMenuRank[client], 30);
2730}
2731
2732public MenuHandler_MenuTopPlayers(Handle:menu, MenuAction:action, param1, param2)
2733{
2734 switch(action)
2735 {
2736 case MenuAction_End:
2737 CloseHandle(menu);
2738 case MenuAction_Select:
2739 {
2740 decl String:sInfo[32];
2741 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2742 //Timer_CreatePlayerStatsMenu(param1, sInfo);
2743 }
2744 }
2745}
2746
2747public CallBack_Next(Handle:owner, Handle:hndl, const String:error[], any:userid)
2748{
2749 if(hndl == INVALID_HANDLE)
2750 {
2751 Timer_LogError("SQL Error on CallBack_Next: %s", error);
2752 return;
2753 }
2754 new client = GetClientOfUserId(userid);
2755 if(!client || !IsClientInGame(client))
2756 return;
2757
2758 new iIndex, iPoints;
2759 decl String:sName[32], String:sAuth[64];
2760 if(SQL_GetRowCount(hndl))
2761 {
2762 new Handle:hPack = CreateDataPack();
2763 WritePackCell(hPack, iIndex);
2764 while(SQL_FetchRow(hndl))
2765 {
2766 SQL_FetchString(hndl, 0, sName, sizeof(sName));
2767 iPoints = SQL_FetchInt(hndl, 1);
2768 SQL_FetchString(hndl, 2, sAuth, sizeof(sAuth));
2769
2770 WritePackString(hPack, sName);
2771 WritePackCell(hPack, iPoints);
2772 WritePackString(hPack, sAuth);
2773
2774 iIndex++;
2775 }
2776
2777 SetPackPosition(hPack, 0);
2778 WritePackCell(hPack, iIndex);
2779 CreateNextMenu(client, hPack);
2780 }
2781 else
2782 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Next_None");
2783}
2784
2785CreateNextMenu(client, Handle:pack)
2786{
2787 decl String:sBuffer[128], String:sName[32], String:sAuth[64];
2788 new Handle:hMenu = CreateMenu(MenuHandler_MenuNextPlayers);
2789
2790 SetMenuTitle(hMenu, sBuffer);
2791 if(g_iLimitTopPerPage)
2792 SetMenuPagination(hMenu, g_iLimitTopPerPage);
2793 SetMenuExitButton(hMenu, true);
2794 SetMenuExitBackButton(hMenu, false);
2795
2796 ResetPack(pack);
2797 new iCount = ReadPackCell(pack);
2798 Format(sBuffer, sizeof(sBuffer), "%T", "Menu_Title_Next", client, iCount);
2799 for(new i = 0; i < iCount; i++)
2800 {
2801 ReadPackString(pack, sName, sizeof(sName));
2802 new iPoints = ReadPackCell(pack);
2803 ReadPackString(pack, sAuth, sizeof(sAuth));
2804
2805 Format(sBuffer, sizeof(sBuffer), "%T", "Menu_Next_Option", client, sName, iPoints, iCount - i, iPoints - g_iChoosedPoints[client]);
2806
2807 if(i == 0)
2808 AddMenuItem(hMenu, sAuth, sBuffer);
2809 else
2810 InsertMenuItem(hMenu, 0, sAuth, sBuffer);
2811 }
2812 CloseHandle(pack);
2813 DisplayMenu(hMenu, client, 30);
2814}
2815
2816CreateSettingsMenu(client)
2817{
2818 decl String:sBuffer[128];
2819 new Handle:hMenu = CreateMenu(MenuHandler_SettingsMenu);
2820
2821 Format(sBuffer, sizeof(sBuffer), "%T", "Menu_Settings_Title", client);
2822 SetMenuTitle(hMenu, sBuffer);
2823
2824 if(g_iDisplayMethod < 0 && g_hDisplayCookie != INVALID_HANDLE && g_iCurrentIndex[client] != -1)
2825 {
2826 Format(sBuffer, sizeof(sBuffer), "%T", "Menu_Settings_Option_Cookie", client);
2827 AddMenuItem(hMenu, "1", sBuffer);
2828 }
2829
2830 Format(sBuffer, sizeof(sBuffer), "%T", "Menu_Settings_Option_Top", client);
2831 AddMenuItem(hMenu, "2", sBuffer);
2832
2833 Format(sBuffer, sizeof(sBuffer), "%T", "Menu_Settings_Option_Rank", client);
2834 AddMenuItem(hMenu, "3", sBuffer);
2835
2836 Format(sBuffer, sizeof(sBuffer), "%T", "Menu_Settings_Option_Worth", client);
2837 AddMenuItem(hMenu, "4", sBuffer);
2838
2839 Format(sBuffer, sizeof(sBuffer), "%T", "Menu_Settings_Option_Next", client);
2840 AddMenuItem(hMenu, "5", sBuffer);
2841
2842 if(g_iDisplayMethod != 0)
2843 {
2844 Format(sBuffer, sizeof(sBuffer), "%T", "Menu_Settings_Option_Positions", client);
2845 AddMenuItem(hMenu, "6", sBuffer);
2846 }
2847
2848 DisplayMenu(hMenu, client, 30);
2849}
2850
2851public MenuHandler_SettingsMenu(Handle:menu, MenuAction:action, param1, param2)
2852{
2853 switch(action)
2854 {
2855 case MenuAction_End:
2856 CloseHandle(menu);
2857 case MenuAction_Select:
2858 {
2859 if(g_iCurrentIndex[param1] == -1)
2860 return;
2861
2862 decl String:sOption[4];
2863 GetMenuItem(menu, param2, sOption, 4);
2864 switch(StringToInt(sOption))
2865 {
2866 case 1:
2867 {
2868 if(!g_bLoadedSQL[param1] || !g_bLoadedCookies[param1])
2869 {
2870 CPrintToChat(param1, "%t%t", "Prefix_Chat", "Phrase.Loading");
2871 return;
2872 }
2873
2874 CreateCookieMenu(param1);
2875 }
2876 case 2:
2877 {
2878 decl String:sQuery[192];
2879 Format(sQuery, sizeof(sQuery), "SELECT `lastname`,`points`,`auth` FROM `ranks` WHERE `points` > %d ORDER BY `points` DESC LIMIT %d", g_iRequiredPoints, g_iLimitTopPlayers);
2880 if(g_iEnabled == 2)
2881 PrintToDebug("Command_Say(%N): Issuing Query `%s`", param1, sQuery);
2882 SQL_TQuery(g_hDatabase, CallBack_Top, sQuery, GetClientUserId(param1));
2883 }
2884 case 3:
2885 {
2886 if(!g_bLoadedSQL[param1])
2887 {
2888 CPrintToChat(param1, "%t%t", "Prefix_Chat", "Phrase_Loading");
2889 return;
2890 }
2891
2892 if(g_iCurrentPoints[param1] < g_iRequiredPoints)
2893 CPrintToChat(param1, "%t%t", "Prefix_Chat", "Phrase_Rank_Not_Enough", g_iRequiredPoints, g_iCurrentPoints[param1]);
2894 else
2895 {
2896 decl String:sQuery[192];
2897 Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM `ranks` WHERE `points` > %d ORDER BY `points` DESC", g_iCurrentPoints[param1]);
2898 if(g_iEnabled == 2)
2899 PrintToDebug("Command_Say(%N): Issuing Query `%s`", param1, sQuery);
2900 SQL_TQuery(g_hDatabase, CallBack_Rank, sQuery, GetClientUserId(param1));
2901 }
2902
2903 CreateSettingsMenu(param1);
2904 }
2905 case 4:
2906 {
2907 CPrintToChat(param1, "%t%t", "Prefix_Chat", "Phrase_Points_Per_Map", g_iCurrentMapWorth, g_iCurrentMapTier);
2908
2909 CreateSettingsMenu(param1);
2910 }
2911 case 5:
2912 {
2913 if(!g_bLoadedSQL[param1])
2914 {
2915 CPrintToChat(param1, "%t%t", "Prefix_Chat", "Phrase_Loading");
2916 return;
2917 }
2918
2919 decl String:sQuery[192];
2920 Format(sQuery, sizeof(sQuery), "SELECT `lastname`,`points` FROM `ranks` WHERE `points` > %d AND `auth` != '%s' ORDER BY `points` ASC LIMIT %d", g_iCurrentPoints[param1], g_sAuth[param1], g_iLimitTopPlayers);
2921 if(g_iEnabled == 2)
2922 PrintToDebug("Command_Say(%N): Issuing Query `%s`", param1, sQuery);
2923 SQL_TQuery(g_hDatabase, CallBack_Next, sQuery, GetClientUserId(param1));
2924 }
2925 case 6:
2926 {
2927 CreateInfoMenu(param1);
2928 }
2929 }
2930 }
2931 }
2932}
2933
2934public MenuHandler_MenuNextPlayers(Handle:menu, MenuAction:action, param1, param2)
2935{
2936 switch(action)
2937 {
2938 case MenuAction_End:
2939 CloseHandle(menu);
2940 case MenuAction_Select:
2941 {
2942 decl String:sInfo[32];
2943 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2944 //Timer_CreatePlayerStatsMenu(param1, sInfo);
2945 }
2946 }
2947}
2948
2949public CallBack_Rank(Handle:owner, Handle:hndl, const String:error[], any:userid)
2950{
2951 if(hndl == INVALID_HANDLE)
2952 {
2953 Timer_LogError("SQL Error on CallBack_Rank: %s", error);
2954 return;
2955 }
2956 new client = GetClientOfUserId(userid);
2957 if(!client || !IsClientInGame(client))
2958 return;
2959
2960 if(SQL_FetchRow(hndl))
2961 {
2962 new iTime = GetTime();
2963 g_iRank[client] = SQL_FetchInt(hndl, 0)+1;
2964
2965 if(g_bGlobalMessage)
2966 {
2967 if(iTime > g_iLastGlobalMessage[client] + cGlobalCooldown)
2968 {
2969 g_iLastGlobalMessage[client] = iTime;
2970 new String:sName[64];
2971 GetClientName(client, sName, 64);
2972 CPrintToChatAll("%t%t", "Prefix_Chat", "Phrase_Rank_Global", sName, g_iRank[client], g_iTotalPlayers, g_iCurrentPoints[client]);
2973 return;
2974 }
2975 }
2976
2977 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Rank_Player", g_iRank[client], g_iTotalPlayers, g_iCurrentPoints[client]);
2978 }
2979}
2980
2981public CallBack_CountryRank(Handle:owner, Handle:hndl, const String:error[], any:userid)
2982{
2983 if(hndl == INVALID_HANDLE)
2984 {
2985 Timer_LogError("SQL Error on CallBack_CountryRank: %s", error);
2986 return;
2987 }
2988 new client = GetClientOfUserId(userid);
2989 if(!client || !IsClientInGame(client))
2990 return;
2991
2992 if(SQL_FetchRow(hndl))
2993 {
2994 new iTime = GetTime();
2995 UpdateTotalRankByCountry(client, g_sCountry[client]);
2996
2997 g_iCountryRank[client] = SQL_FetchInt(hndl, 0)+1;
2998 if(g_bGlobalMessage)
2999 {
3000 if(iTime > g_iLastGlobalMessage[client] + cGlobalCooldown)
3001 {
3002 g_iLastGlobalMessage[client] = iTime;
3003 CPrintToChatAll("%t%t", "Prefix_Chat", "Phrase_CountryRank_Global", client, g_iCountryRank[client], g_iTotalRanksCountry[client], g_iCurrentPoints[client], g_sCountry[client]);
3004 return;
3005 }
3006 }
3007
3008 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_CountryRank_Player", g_iCountryRank[client], g_iTotalRanksCountry[client], g_iCurrentPoints[client], g_sCountry[client]);
3009 }
3010}
3011
3012public CallBack_RankGlobal(Handle:owner, Handle:hndl, const String:error[], any:userid)
3013{
3014 if(hndl == INVALID_HANDLE)
3015 {
3016 Timer_LogError("SQL Error on CallBack_Rank: %s", error);
3017 return;
3018 }
3019 new String:sName[MAX_NAME_LENGTH];
3020 new client = GetClientOfUserId(userid);
3021 if(!client || !IsClientInGame(client))
3022 return;
3023 GetClientName(client, sName, MAX_NAME_LENGTH);
3024
3025 if(SQL_FetchRow(hndl))
3026 {
3027 new iCount = SQL_FetchInt(hndl, 0);
3028
3029 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Rank_Global", sName,iCount, g_iTotalPlayers, g_iCurrentPoints[client]);
3030 }
3031}
3032
3033public CallBack_CountryRankByName(Handle:owner, Handle:hndl, const String:error[], any:userid)
3034{
3035 if(hndl == INVALID_HANDLE)
3036 {
3037 Timer_LogError("SQL Error on CallBack_CountryRankByName: %s", error);
3038 return;
3039 }
3040 new client = GetClientOfUserId(userid);
3041 if(!client || !IsClientInGame(client))
3042 return;
3043
3044 if(SQL_FetchRow(hndl))
3045 {
3046 SQL_FetchString(hndl, 0, g_sChoosedName[client], 64);
3047 g_iChoosedPoints[client] = SQL_FetchInt(hndl, 1);
3048 SQL_FetchString(hndl, 2, g_sChoosedCountry[client], 64);
3049 decl String:sQuery[384];
3050 Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM `ranks` WHERE `points` > %d AND `lastcountry` = '%s' ORDER BY `points` DESC", g_iChoosedPoints[client], g_sChoosedCountry[client]);
3051 SQL_TQuery(g_hDatabase, CallBack_CountryRankOther, sQuery, GetClientUserId(client));
3052 }
3053}
3054
3055public CallBack_CountryRankOther(Handle:owner, Handle:hndl, const String:error[], any:userid)
3056{
3057 if(hndl == INVALID_HANDLE)
3058 {
3059 Timer_LogError("SQL Error on CallBack_RankOther: %s", error);
3060 return;
3061 }
3062 new client = GetClientOfUserId(userid);
3063 if(!client || !IsClientInGame(client))
3064 return;
3065
3066 if(SQL_FetchRow(hndl))
3067 {
3068 new iRank = SQL_FetchInt(hndl, 0)+1;
3069 UpdateTotalRankByCountry(client, g_sCountry[client]);
3070 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_CountryRank_Global", g_sChoosedName[client], iRank, g_iTotalRanksCountry[client], g_iChoosedPoints[client], g_sChoosedCountry[client]);
3071 }
3072}
3073
3074public CallBack_RankByName(Handle:owner, Handle:hndl, const String:error[], any:userid)
3075{
3076 if(hndl == INVALID_HANDLE)
3077 {
3078 Timer_LogError("SQL Error on CallBack_RankByName: %s", error);
3079 return;
3080 }
3081 new client = GetClientOfUserId(userid);
3082 if(!client || !IsClientInGame(client))
3083 return;
3084
3085 if(SQL_FetchRow(hndl))
3086 {
3087 SQL_FetchString(hndl, 0, g_sChoosedName[client], 64);
3088 g_iChoosedPoints[client] = SQL_FetchInt(hndl, 1);
3089 decl String:sQuery[384];
3090 Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) FROM `ranks` WHERE `points` > %d ORDER BY `points` DESC", g_iChoosedPoints[client]);
3091 SQL_TQuery(g_hDatabase, CallBack_RankOther, sQuery, GetClientUserId(client));
3092 }
3093}
3094
3095public CallBack_RankByPlace(Handle:owner, Handle:hndl, const String:error[], any:data)
3096{
3097 if(hndl == INVALID_HANDLE)
3098 {
3099 Timer_LogError("SQL Error on CallBack_RankByPlace: %s", error);
3100 return;
3101 }
3102 ResetPack(data);
3103 new client = GetClientOfUserId(ReadPackCell(data));
3104 new rank = ReadPackCell(data);
3105 CloseHandle(data);
3106 if(!client || !IsClientInGame(client))
3107 return;
3108
3109 new counter = 1;
3110 while(SQL_FetchRow(hndl))
3111 {
3112 if(rank == counter)
3113 {
3114 new String:name[64];
3115 SQL_FetchString(hndl, 0, name, 64);
3116 new points = SQL_FetchInt(hndl, 1);
3117 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Rank_Global", name, rank, g_iTotalPlayers, points);
3118 }
3119 counter++;
3120 }
3121}
3122
3123public CallBack_CountryRankByPlace(Handle:owner, Handle:hndl, const String:error[], any:data)
3124{
3125 if(hndl == INVALID_HANDLE)
3126 {
3127 Timer_LogError("SQL Error on CallBack_CountryRankByPlace: %s", error);
3128 return;
3129 }
3130 ResetPack(data);
3131 new client = GetClientOfUserId(ReadPackCell(data));
3132 new rank = ReadPackCell(data);
3133 CloseHandle(data);
3134 if(!client || !IsClientInGame(client))
3135 return;
3136
3137 new counter = 1;
3138 while(SQL_FetchRow(hndl))
3139 {
3140 if(rank == counter)
3141 {
3142 new String:name[64];
3143 SQL_FetchString(hndl, 0, name, 64);
3144 new points = SQL_FetchInt(hndl, 1);
3145 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_CountryRank_Global", name, rank, g_iTotalRanksCountry[client], points, g_sCountry[client]);
3146 }
3147 counter++;
3148 }
3149}
3150
3151public CallBack_NextByName(Handle:owner, Handle:hndl, const String:error[], any:userid)
3152{
3153 if(hndl == INVALID_HANDLE)
3154 {
3155 Timer_LogError("SQL Error on CallBack_NextByName: %s", error);
3156 return;
3157 }
3158 new client = GetClientOfUserId(userid);
3159 if(!client || !IsClientInGame(client))
3160 return;
3161
3162 if(SQL_FetchRow(hndl))
3163 {
3164 SQL_FetchString(hndl, 0, g_sChoosedName[client], 64);
3165 g_iChoosedPoints[client] = SQL_FetchInt(hndl, 1);
3166 decl String:sQuery[384];
3167 Format(sQuery, sizeof(sQuery), "SELECT `lastname`,`points`,`auth` FROM `ranks` WHERE `points` > %d AND `auth` != '%s' ORDER BY `points` ASC LIMIT %d", g_iChoosedPoints[client], g_sChoosedName[client], g_iLimitTopPlayers);
3168 SQL_TQuery(g_hDatabase, CallBack_Next, sQuery, GetClientUserId(client));
3169 }
3170}
3171
3172public CallBack_RankOther(Handle:owner, Handle:hndl, const String:error[], any:userid)
3173{
3174 if(hndl == INVALID_HANDLE)
3175 {
3176 Timer_LogError("SQL Error on CallBack_RankOther: %s", error);
3177 return;
3178 }
3179 new client = GetClientOfUserId(userid);
3180 if(!client || !IsClientInGame(client))
3181 return;
3182
3183 if(SQL_FetchRow(hndl))
3184 {
3185 new iRank = SQL_FetchInt(hndl, 0)+1;
3186 CPrintToChat(client, "%t%t", "Prefix_Chat", "Phrase_Rank_Global", g_sChoosedName[client], iRank, g_iTotalPlayers, g_iChoosedPoints[client]);
3187 }
3188}
3189
3190public PanelHandler_RankMenu(Handle:menu, MenuAction:action, param1, param2)
3191{
3192 switch(action)
3193 {
3194 case MenuAction_End:
3195 CloseHandle(menu);
3196 }
3197}
3198
3199public Action:Command_ChatRanks(client, args)
3200{
3201 decl String:sName[MAX_NAME_LENGTH];
3202 new String:sTag[MAX_TAG_LENGTH];
3203 new String:sChatColor[MAX_TAG_LENGTH];
3204 GetClientName(client, sName, MAX_NAME_LENGTH);
3205 for(new i = 2; i <= g_iTotalRanks; i++)
3206 {
3207 GetArrayString(g_hCfgArray_DisplayChat, i, sTag, sizeof(sTag));
3208 FormatCustomColor(sTag, sTag, sizeof(sTag), client);
3209 GetArrayString(g_hCfgArray_DisplayColor, i, sChatColor, sizeof(sChatColor));
3210 FormatCustomColor(sChatColor, sChatColor, sizeof(sChatColor), client);
3211 if(g_iPositionMethod == 1)
3212 {
3213 new num1, num2;
3214 num1 = GetArrayCell(g_hArray_CfgRanks, i);
3215 num2 = GetArrayCell(g_hArray_CfgRanks, i-1)+1;
3216 if(num1 != num2)
3217 CPrintToChat(client, "%d-%d. %s%s: %s TEST", num2, num1, sTag, sName, sChatColor);
3218 else
3219 CPrintToChat(client, "%d. %s%s: %s TEST", num1, sTag, sName, sChatColor);
3220 }
3221 else
3222 {
3223 new num1, num2;
3224 num1 = GetArrayCell(g_hArray_CfgPoints, i);
3225 num2 = GetArrayCell(g_hArray_CfgPoints, i+1)-1;
3226 if(num1 != num2)
3227 CPrintToChat(client, "%d-%d. %s%s: %s TEST", num1-1, num2+1, sTag, sName, sChatColor);
3228 else
3229 CPrintToChat(client, "%d. %s%s: %s TEST", num1, sTag, sName, sChatColor);
3230 }
3231 }
3232 return Plugin_Handled;
3233}
3234
3235public Action:Command_SetMapPoints(client, args)
3236{
3237 if(!g_iEnabled)
3238 return Plugin_Handled;
3239
3240 if(g_hDatabase != INVALID_HANDLE && !g_bInitalizing)
3241 {
3242 if(args < 1)
3243 {
3244 ReplyToCommand(client, "Usage: sm_setpoints <amount> <map>.");
3245 return Plugin_Handled;
3246 }
3247
3248 decl String:sText[192];
3249 decl String:arg1[32], String:arg2[32];
3250 new iPoints;
3251 new Handle:hPack = CreateDataPack();
3252 GetCmdArg(1, arg1, 32);
3253 GetCmdArg(2, arg2, 32);
3254 if(args < 2)
3255 {
3256 strcopy(arg2, 32, g_sCurrentMap);
3257 }
3258 iPoints = StringToInt(arg1);
3259 WritePackString(hPack, arg2);
3260 WritePackCell(hPack, iPoints);
3261
3262 Format(sText, sizeof(sText), "SELECT `points` FROM `maps` WHERE `map` = '%s'", arg2);
3263 if(g_iEnabled == 2)
3264 PrintToDebug("Command_SetMapPoints(%N): Issuing Query `set points`", client);
3265 SQL_TQuery(g_hDatabase, CallBack_CommandSetMapPoints, sText, hPack);
3266 }
3267 else
3268 ReplyToCommand(client, "[SM] Database offline; cannot complete action!");
3269
3270 return Plugin_Handled;
3271}
3272
3273public Action:Command_SetMapTier(client, args)
3274{
3275 if(!g_iEnabled)
3276 return Plugin_Handled;
3277
3278 if(g_hDatabase != INVALID_HANDLE && !g_bInitalizing)
3279 {
3280 if(args < 1)
3281 {
3282 ReplyToCommand(client, "Usage: sm_settier <tier> <map>.");
3283 return Plugin_Handled;
3284 }
3285
3286 decl String:sText[192];
3287 decl String:arg1[32], String:arg2[32];
3288 new iTier;
3289 new Handle:hPack = CreateDataPack();
3290 GetCmdArg(1, arg1, 32);
3291 GetCmdArg(2, arg2, 32);
3292 if(args < 2)
3293 {
3294 strcopy(arg2, 32, g_sCurrentMap);
3295 }
3296 iTier = StringToInt(arg1);
3297 WritePackString(hPack, arg2);
3298 WritePackCell(hPack, iTier);
3299
3300 Format(sText, sizeof(sText), "SELECT `tier` FROM `maps` WHERE `map` = '%s'", arg2);
3301 if(g_iEnabled == 2)
3302 PrintToDebug("Command_SetMapPoints(%N): Issuing Query `set points`", client);
3303 SQL_TQuery(g_hDatabase, CallBack_CommandSetMapTier, sText, hPack);
3304 }
3305 else
3306 ReplyToCommand(client, "[SM] Database offline; cannot complete action!");
3307
3308 return Plugin_Handled;
3309}
3310
3311public CallBack_CommandDeleteMapPoints(Handle:owner, Handle:hndl, const String:error[], any:pack)
3312{
3313 if(hndl == INVALID_HANDLE)
3314 {
3315 Timer_LogError("SQL Error on CallBack_CommandDeleteMapPoints: %s", error);
3316 return;
3317 }
3318
3319 ResetPack(pack);
3320 decl String:sMap[128];
3321 ReadPackString(pack, sMap, sizeof(sMap));
3322 CloseHandle(pack);
3323
3324 if(StrEqual(g_sCurrentMap, sMap))
3325 if(!GetTrieValue(g_hTrie_CfgWorth, g_sCurrentMap, g_iCurrentMapWorth))
3326 g_iCurrentMapWorth = g_iDefaultMapWorth;
3327
3328 PrintToAdmins("(Notice) Map `%s` has been removed from the map database.", sMap);
3329}
3330
3331public CallBack_CommandSetMapPoints(Handle:owner, Handle:hndl, const String:error[], any:pack)
3332{
3333 if(hndl == INVALID_HANDLE)
3334 {
3335 Timer_LogError("SQL Error on CallBack_CommandSetMapPoints: %s", error);
3336 return;
3337 }
3338
3339 ResetPack(pack);
3340 decl String:sMap[128];
3341 ReadPackString(pack, sMap, sizeof(sMap));
3342 new iPoints = ReadPackCell(pack);
3343
3344 decl String:sQuery[192];
3345 if(!SQL_GetRowCount(hndl))
3346 {
3347 PrintToAdmins("(Notice) Map `%s` has been added from the map database.", sMap);
3348
3349 Format(sQuery, sizeof(sQuery), "INSERT INTO `maps` (`map`,`points`,`played`, `setuptime`, `tier`) VALUES ('%s', %d, 0, %d, 1)", sMap, iPoints, GetTime());
3350 if(g_iEnabled == 2)
3351 PrintToDebug("CallBack_CommandSetMapPoints(): Issuing Query `%s`", sQuery);
3352 SQL_TQuery(g_hDatabase, CallBack_CommandSetMapPointsResult, sQuery, pack);
3353 }
3354 else if(SQL_FetchRow(hndl))
3355 {
3356 PrintToAdmins("(Notice) Map `%s` has been modified in the map database.", sMap);
3357
3358 Format(sQuery, sizeof(sQuery), "UPDATE `maps` SET `points` = %d, `setuptime` = %d WHERE map = '%s'", iPoints, GetTime(), sMap);
3359 if(g_iEnabled == 2)
3360 PrintToDebug("CallBack_CommandSetMapPoints(): Issuing Query `%s`", sQuery);
3361 SQL_TQuery(g_hDatabase, CallBack_CommandSetMapPointsResult, sQuery, pack);
3362 }
3363
3364 if(StrEqual(g_sCurrentMap, sMap))
3365 g_iCurrentMapWorth = iPoints;
3366}
3367
3368public CallBack_CommandSetMapPointsResult(Handle:owner, Handle:hndl, const String:error[], any:pack)
3369{
3370 if(hndl == INVALID_HANDLE)
3371 {
3372 Timer_LogError("SQL Error on CallBack_CommandSetMapPointsResult: %s", error);
3373 return;
3374 }
3375
3376 ResetPack(pack);
3377 decl String:sMap[128];
3378 ReadPackString(pack, sMap, sizeof(sMap));
3379 new iPoints = ReadPackCell(pack);
3380 CloseHandle(pack);
3381
3382 PrintToAdmins("(Notice) Map `%s` will reward %d points for completion.", sMap, iPoints);
3383}
3384
3385public CallBack_CommandSetMapTier(Handle:owner, Handle:hndl, const String:error[], any:pack)
3386{
3387 if(hndl == INVALID_HANDLE)
3388 {
3389 Timer_LogError("SQL Error on CallBack_CommandSetMapTier: %s", error);
3390 return;
3391 }
3392
3393 ResetPack(pack);
3394 decl String:sMap[128];
3395 ReadPackString(pack, sMap, sizeof(sMap));
3396 new iTier = ReadPackCell(pack);
3397
3398 decl String:sQuery[192];
3399 if(!SQL_GetRowCount(hndl))
3400 {
3401 new iPoints;
3402 if(!GetTrieValue(g_hTrie_CfgWorth, g_sCurrentMap, iPoints))
3403 iPoints = g_iDefaultMapWorth;
3404
3405 PrintToAdmins("(Notice) Map `%s` has been added from the map database.", sMap);
3406
3407 Format(sQuery, sizeof(sQuery), "INSERT INTO `maps` (`map`,`points`,`played`, `setuptime`) VALUES ('%s', %d, 0, %d, %d)", sMap, iPoints, GetTime(), iTier);
3408 if(g_iEnabled == 2)
3409 PrintToDebug("CallBack_CommandSetMapTier(): Issuing Query `%s`", sQuery);
3410 SQL_TQuery(g_hDatabase, CallBack_CommandSetMapTierResult, sQuery, pack);
3411 }
3412 else if(SQL_FetchRow(hndl))
3413 {
3414 PrintToAdmins("(Notice) Map `%s` has been modified in the map database.", sMap);
3415
3416 Format(sQuery, sizeof(sQuery), "UPDATE `maps` SET `tier` = %d, `setuptime` = %d WHERE map = '%s'", iTier, GetTime(), sMap);
3417 if(g_iEnabled == 2)
3418 PrintToDebug("CallBack_CommandSetMapTier(): Issuing Query `%s`", sQuery);
3419 SQL_TQuery(g_hDatabase, CallBack_CommandSetMapTierResult, sQuery, pack);
3420 }
3421
3422 if(StrEqual(g_sCurrentMap, sMap))
3423 g_iCurrentMapTier = iTier;
3424}
3425
3426public CallBack_CommandSetMapTierResult(Handle:owner, Handle:hndl, const String:error[], any:pack)
3427{
3428 if(hndl == INVALID_HANDLE)
3429 {
3430 Timer_LogError("SQL Error on CallBack_CommandSetMapTierResult: %s", error);
3431 return;
3432 }
3433
3434 ResetPack(pack);
3435 decl String:sMap[128];
3436 ReadPackString(pack, sMap, sizeof(sMap));
3437 new iTier = ReadPackCell(pack);
3438 CloseHandle(pack);
3439
3440 PrintToAdmins("(Notice) Map `%s` set to tier %d", sMap, iTier);
3441}
3442
3443public Action:Command_SetRankPoints(client, args)
3444{
3445 if(!g_iEnabled)
3446 return Plugin_Handled;
3447
3448 if(g_hDatabase != INVALID_HANDLE && !g_bInitalizing)
3449 {
3450 if(args < 2)
3451 {
3452 ReplyToCommand(client, "Usage: timer_setrankpoints <steam> <amount> | <steam> must exist otherwise the operation fails.");
3453 return Plugin_Handled;
3454 }
3455
3456 new iBreak, iPoints;
3457 new Handle:hPack = CreateDataPack();
3458 decl String:sText[192], String:sAuth[24];
3459 GetCmdArgString(sText, sizeof(sText));
3460
3461 iBreak = BreakString(sText, sAuth, sizeof(sAuth));
3462 if(iBreak == -1)
3463 {
3464 CloseHandle(hPack);
3465
3466 ReplyToCommand(client, "Usage: timer_setrankpoints <steam> <amount> | <steam> must exist otherwise the operation fails.");
3467 return Plugin_Handled;
3468 }
3469 iPoints = StringToInt(sText[iBreak]);
3470
3471 WritePackString(hPack, sAuth);
3472 WritePackCell(hPack, iPoints);
3473
3474 Format(sText, sizeof(sText), "SELECT `points` FROM `ranks` WHERE `auth` = '%s'", sAuth);
3475 if(g_iEnabled == 2)
3476 PrintToDebug("Command_SetRankPoints(%N): Issuing Query `%s`", client, sText);
3477 SQL_TQuery(g_hDatabase, CallBack_CommandSetRankPoints, sText, hPack);
3478 }
3479 else
3480 ReplyToCommand(client, "[SM] Database offline; cannot complete action!");
3481
3482 return Plugin_Handled;
3483}
3484
3485public CallBack_CommandSetRankPoints(Handle:owner, Handle:hndl, const String:error[], any:pack)
3486{
3487 if(hndl == INVALID_HANDLE)
3488 {
3489 Timer_LogError("SQL Error on CallBack_CommandSetRankPoints: %s", error);
3490 return;
3491 }
3492
3493 ResetPack(pack);
3494 decl String:sAuth[24];
3495 ReadPackString(pack, sAuth, sizeof(sAuth));
3496 new iPoints = ReadPackCell(pack);
3497 CloseHandle(pack);
3498
3499 if(!SQL_GetRowCount(hndl))
3500 PrintToAdmins("(Notice) Auth '%s' does not exist within the database; please check your input!", sAuth);
3501 else
3502 {
3503 PrintToAdmins("(Notice) Auth '%s' now has a total of %d points.", sAuth, iPoints);
3504
3505 decl String:sQuery[192];
3506 Format(sQuery, sizeof(sQuery), "UPDATE `ranks` SET `points` = %d WHERE `auth` = '%s'", iPoints, sAuth);
3507 if(g_iEnabled == 2)
3508 PrintToDebug("CallBack_CommandSetRankPoints(): Issuing Query `%s`", sQuery);
3509 SQL_TQuery(g_hDatabase, CallBack_UpdateClient, sQuery, _);
3510
3511 for(new i = 1; i <= MaxClients; i++)
3512 {
3513 if(IsClientInGame(i) && StrEqual(sAuth, g_sAuth[i], false))
3514 {
3515 g_iCurrentPoints[i] = iPoints;
3516 break;
3517 }
3518 }
3519 }
3520}
3521
3522public Action:Command_ChangeRankPoints(client, args)
3523{
3524 if(!g_iEnabled)
3525 return Plugin_Handled;
3526
3527 if(g_hDatabase != INVALID_HANDLE && !g_bInitalizing)
3528 {
3529 if(args < 2)
3530 {
3531 ReplyToCommand(client, "Usage: timer_changerankpoints <steam> <amount> | <steam> must exist otherwise the operation fails. | Positive = Add, Negative = Subtract");
3532 return Plugin_Handled;
3533 }
3534
3535 new iBreak, iPoints;
3536 new Handle:hPack = CreateDataPack();
3537 decl String:sText[192], String:sAuth[24];
3538 GetCmdArgString(sText, sizeof(sText));
3539
3540 iBreak = BreakString(sText, sAuth, sizeof(sAuth));
3541 if(iBreak == -1)
3542 {
3543 CloseHandle(hPack);
3544
3545 ReplyToCommand(client, "Usage: timer_changerankpoints <steam> <amount> | <steam> must exist otherwise the operation fails. | Positive = Add, Negative = Subtract");
3546 return Plugin_Handled;
3547 }
3548 iPoints = StringToInt(sText[iBreak]);
3549
3550 WritePackString(hPack, sAuth);
3551 WritePackCell(hPack, iPoints);
3552
3553 Format(sText, sizeof(sText), "SELECT `points` FROM `ranks` WHERE `auth` = '%s'", sAuth);
3554 if(g_iEnabled == 2)
3555 PrintToDebug("Command_ChangeRankPoints(): Issuing Query `%s`", sText);
3556 SQL_TQuery(g_hDatabase, CallBack_CommandChangeRankPoints, sText, hPack);
3557 }
3558 else
3559 ReplyToCommand(client, "[SM] Database offline; cannot complete action!");
3560
3561 return Plugin_Handled;
3562}
3563
3564public CallBack_CommandChangeRankPoints(Handle:owner, Handle:hndl, const String:error[], any:pack)
3565{
3566 if(hndl == INVALID_HANDLE)
3567 {
3568 Timer_LogError("SQL Error on CallBack_CommandChangeRankPoints: %s", error);
3569 return;
3570 }
3571
3572 ResetPack(pack);
3573 decl String:sAuth[24];
3574 ReadPackString(pack, sAuth, sizeof(sAuth));
3575 new iPoints = ReadPackCell(pack);
3576 CloseHandle(pack);
3577
3578 if(!SQL_GetRowCount(hndl))
3579 PrintToAdmins("(Notice) Auth '%s' does not exist within the database; please check your input!", sAuth);
3580 else if(SQL_FetchRow(hndl))
3581 {
3582 new iCurrent = SQL_FetchInt(hndl, 0);
3583 PrintToAdmins("(Notice) Auth '%s' has been assigned %d points.", sAuth, iPoints);
3584
3585 decl String:sQuery[192];
3586 Format(sQuery, sizeof(sQuery), "UPDATE `ranks` SET `points` = %d WHERE `auth` = '%s'", (iCurrent + iPoints), sAuth);
3587 if(g_iEnabled == 2)
3588 PrintToDebug("CallBack_CommandChangeRankPoints(): Issuing Query `%s`", sQuery);
3589 SQL_TQuery(g_hDatabase, CallBack_UpdateClient, sQuery, _);
3590
3591 for(new i = 1; i <= MaxClients; i++)
3592 {
3593 if(IsClientInGame(i) && StrEqual(sAuth, g_sAuth[i], false))
3594 {
3595 g_iCurrentPoints[i] = (iCurrent + iPoints);
3596 break;
3597 }
3598 }
3599 }
3600}
3601
3602public Action:Command_ListMaps(client, args)
3603{
3604 if(!g_iEnabled)
3605 return Plugin_Handled;
3606
3607 if(g_hDatabase != INVALID_HANDLE && !g_bInitalizing)
3608 {
3609 decl String:sQuery[128];
3610 Format(sQuery, sizeof(sQuery), "SELECT `map`,`points` FROM `maps` ORDER BY `map` ASC");
3611 if(g_iEnabled == 2)
3612 PrintToDebug("Command_ListMaps(%N): Issuing Query `%s`", client, sQuery);
3613 SQL_TQuery(g_hDatabase, CallBack_CommandListMaps, sQuery, client ? GetClientUserId(client) : 0);
3614 }
3615
3616 return Plugin_Handled;
3617}
3618
3619public CallBack_CommandListMaps(Handle:owner, Handle:hndl, const String:error[], any:userid)
3620{
3621 if(hndl == INVALID_HANDLE)
3622 {
3623 Timer_LogError("SQL Error on CallBack_CommandListMaps: %s", error);
3624 return;
3625 }
3626
3627 new iClient;
3628 decl String:sBuffer[128];
3629 new Handle:hMenu = INVALID_HANDLE;
3630 if(userid)
3631 {
3632 iClient = GetClientOfUserId(userid);
3633 if(!IsClientInGame(iClient))
3634 return;
3635
3636 hMenu = CreateMenu(MenuHandler_ListMapMenu);
3637 SetMenuTitle(hMenu, "[Timer] Ranking\n- Map List");
3638 }
3639
3640 new iIndex;
3641 decl iWorth, String:sMap[128];
3642 while(SQL_FetchRow(hndl))
3643 {
3644 iIndex++;
3645
3646 SQL_FetchString(hndl, 0, sMap, sizeof(sMap));
3647 iWorth = SQL_FetchInt(hndl, 1);
3648
3649 if(!userid)
3650 ReplyToCommand(iClient, "%s, %d Points", sMap, iWorth);
3651 else
3652 {
3653 Format(sBuffer, sizeof(sBuffer), "%s, %d Points", sMap, iWorth);
3654 AddMenuItem(hMenu, "", sBuffer, ITEMDRAW_DISABLED);
3655 }
3656 }
3657
3658 if(hMenu != INVALID_HANDLE)
3659 DisplayMenu(hMenu, iClient, 30);
3660}
3661
3662public MenuHandler_ListMapMenu(Handle:menu, MenuAction:action, param1, param2)
3663{
3664 switch(action)
3665 {
3666 case MenuAction_End:
3667 CloseHandle(menu);
3668 }
3669}
3670
3671public Action:Command_ListRanks(client, args)
3672{
3673 if(!g_iEnabled)
3674 return Plugin_Handled;
3675
3676 if(g_hDatabase != INVALID_HANDLE && !g_bInitalizing)
3677 {
3678 decl String:sQuery[128];
3679 Format(sQuery, sizeof(sQuery), "SELECT `lastname`,`points` FROM `ranks` ORDER BY `points` DESC");
3680 if(g_iEnabled == 2)
3681 PrintToDebug("Command_ListRanks(%N): Issuing Query `%s`", client, sQuery);
3682 SQL_TQuery(g_hDatabase, CallBack_CommandListRanks, sQuery, client ? GetClientUserId(client) : 0);
3683 }
3684
3685 return Plugin_Handled;
3686}
3687
3688public CallBack_CommandListRanks(Handle:owner, Handle:hndl, const String:error[], any:userid)
3689{
3690 if(hndl == INVALID_HANDLE)
3691 {
3692 Timer_LogError("SQL Error on CallBack_CommandListRanks: %s", error);
3693 return;
3694 }
3695
3696 new iClient;
3697 decl String:sBuffer[128];
3698 new Handle:hMenu = INVALID_HANDLE;
3699 if(userid)
3700 {
3701 iClient = GetClientOfUserId(userid);
3702 if(!IsClientInGame(iClient))
3703 return;
3704
3705 hMenu = CreateMenu(MenuHandler_ListRankMenu);
3706 SetMenuTitle(hMenu, "[Timer] Ranking\n- Player List");
3707 }
3708
3709 new iIndex;
3710 decl iPoints, String:sName[64];
3711 while(SQL_FetchRow(hndl))
3712 {
3713 iIndex++;
3714
3715 SQL_FetchString(hndl, 0, sName, sizeof(sName));
3716 iPoints = SQL_FetchInt(hndl, 1);
3717
3718 if(!userid)
3719 ReplyToCommand(iClient, "(#%d) %s, %d Points", iIndex, sName, iPoints);
3720 else
3721 {
3722 Format(sBuffer, sizeof(sBuffer), "(#%d) %s, %d Points", iIndex, sName, iPoints);
3723 AddMenuItem(hMenu, "", sBuffer, ITEMDRAW_DISABLED);
3724 }
3725 }
3726
3727 if(hMenu != INVALID_HANDLE)
3728 DisplayMenu(hMenu, iClient, 30);
3729}
3730
3731public MenuHandler_ListRankMenu(Handle:menu, MenuAction:action, param1, param2)
3732{
3733 switch(action)
3734 {
3735 case MenuAction_End:
3736 CloseHandle(menu);
3737 }
3738}
3739
3740public Action:Command_InitalizeRanksMaps(client, args)
3741{
3742 CPrintToChatAll("%t1) [Timer] Rankings: Map Initalization", "Prefix_Chat");
3743 CPrintToChatAll("%t2) The database will now add any missing maps from `round`", "Prefix_Chat");
3744 CPrintToChatAll("%t3) All features of this plugin are disabled during the process.", "Prefix_Chat");
3745 CPrintToChatAll("%t4) Please wait for the process to complete before playing.", "Prefix_Chat");
3746 CPrintToChatAll("%t5) The proces is complete when the final 4/4 appears.", "Prefix_Chat");
3747
3748 PrintToServer("%t1) [Timer] Rankings: Map Initalization", "Prefix_Hint");
3749 PrintToServer("%t2) The database will now add any missing maps from `round`", "Prefix_Hint");
3750 PrintToServer("%t3) All features of this plugin are disabled during the process.", "Prefix_Hint");
3751 PrintToServer("%t4) Please wait for the process to complete before playing.", "Prefix_Hint");
3752 PrintToServer("%t5) The proces is complete when the final 4/4 appears.", "Prefix_Hint");
3753
3754 CreateTimer(5.0, Timer_InitalizeMaps);
3755 return Plugin_Handled;
3756}
3757
3758public Action:Timer_InitalizeMaps(Handle:timer)
3759{
3760 PrintToServer("%t- Intalizing - Step 1/4", "Prefix_Hint");
3761 CPrintToChatAll("%t- Intalizing - Step 1/4", "Prefix_Chat");
3762
3763 decl String:sQuery[192];
3764 Format(sQuery, sizeof(sQuery), "SELECT DISTINCT `map` FROM `round`");
3765 SQL_TQuery(g_hDatabase, InitalizeMapStep1, sQuery, _);
3766}
3767
3768public InitalizeMapStep1(Handle:owner, Handle:hndl, const String:error[], any:pack)
3769{
3770 PrintToServer("%t- Intalizing - Step 2/4", "Prefix_Hint");
3771 CPrintToChatAll("%t- Intalizing - Step 2/4", "Prefix_Chat");
3772 if(hndl == INVALID_HANDLE)
3773 {
3774 Timer_LogError("SQL Error on InitalizeMapStep1: %s", error);
3775 return;
3776 }
3777
3778 decl String:sQuery[192], String:sMap[128];
3779 while(SQL_FetchRow(hndl))
3780 {
3781 SQL_FetchString(hndl, 0, sMap, sizeof(sMap));
3782 new Handle:hPack = CreateDataPack();
3783 WritePackString(hPack, sMap);
3784
3785 g_iInitalizeQueries++;
3786 Format(sQuery, sizeof(sQuery), "SELECT * FROM `maps` WHERE `map` = '%s'", sMap);
3787 SQL_TQuery(g_hDatabase, InitalizeMapsStep2, sQuery, hPack);
3788 }
3789}
3790
3791public InitalizeMapsStep2(Handle:owner, Handle:hndl, const String:error[], any:pack)
3792{
3793 g_iInitalizeQueries--;
3794
3795 if(hndl == INVALID_HANDLE)
3796 {
3797 Timer_LogError("SQL Error on InitalizeMapsStep2: %s", error);
3798 return;
3799 }
3800
3801 decl String:sQuery[384], String:sMap[128];
3802 ResetPack(pack);
3803 ReadPackString(pack, sMap, sizeof(sMap));
3804 CloseHandle(pack);
3805
3806 if(!SQL_GetRowCount(hndl))
3807 {
3808 new iWorth;
3809 if(!GetTrieValue(g_hTrie_CfgMaps, sMap, iWorth))
3810 if(!GetTrieValue(g_hTrie_CfgWorth, g_sCurrentMap, g_iCurrentMapWorth))
3811 iWorth = g_iDefaultMapWorth;
3812
3813 g_iInitalizeQueries++;
3814 Format(sQuery, sizeof(sQuery), "INSERT INTO `maps` (`map`,`points`,`played`) VALUES ('%s', %d, 0)", sMap, iWorth);
3815 SQL_TQuery(g_hDatabase, InitalizeMapsStep3, sQuery);
3816 }
3817 else
3818 {
3819 g_iInitalizeQueries++;
3820 Format(sQuery, sizeof(sQuery), "SELECT * FROM `maps` WHERE `map` = '%s'", sMap);
3821 SQL_TQuery(g_hDatabase, InitalizeMapsStep3, sQuery);
3822 }
3823}
3824
3825public InitalizeMapsStep3(Handle:owner, Handle:hndl, const String:error[], any:pack)
3826{
3827 if(hndl == INVALID_HANDLE)
3828 {
3829 Timer_LogError("SQL Error on InitalizeMapsStep3: %s", error);
3830 return;
3831 }
3832
3833 g_iInitalizeQueries--;
3834 if(g_iInitalizeQueries <= 0)
3835 {
3836 PrintToServer("%t- Intalizing Maps - Step 4/4, Process Completed", "Prefix_Hint");
3837 CPrintToChatAll("%t- Intalizing Maps - Step 4/4 Process Completed", "Prefix_Chat");
3838 }
3839 else if(!GetRandomInt(0, 5))
3840 {
3841 PrintToServer("%t- Intalizing Maps - Step 3/4, Queries Remaining = %d", "Prefix_Hint", g_iInitalizeQueries);
3842 CPrintToChatAll("%t- Intalizing Maps - Step 3/4, Queries Remaining = %d", "Prefix_Chat", g_iInitalizeQueries);
3843 }
3844}
3845
3846public Action:Command_InitalizeRanks(client, args)
3847{
3848 if(!g_iEnabled)
3849 return Plugin_Handled;
3850
3851 CPrintToChatAll("%t1) [Timer] Rankings: Rank Initalization", "Prefix_Chat");
3852 CPrintToChatAll("%t2) The database will be repopulated with current information.", "Prefix_Chat");
3853 CPrintToChatAll("%t3) All features of this plugin are disabled during the process.", "Prefix_Chat");
3854 CPrintToChatAll("%t4) Please wait for the process to complete before playing.", "Prefix_Chat");
3855 CPrintToChatAll("%t5) The proces is complete when the final 8/8 appears.", "Prefix_Chat");
3856
3857 PrintToServer("%t1) [Timer] Rankings: Rank Initalization", "Prefix_Hint");
3858 PrintToServer("%t2) The database will be repopulated with current information.", "Prefix_Hint");
3859 PrintToServer("%t3) All features of this plugin are disabled during the process.", "Prefix_Hint");
3860 PrintToServer("%t4) Please wait for the process to complete before playing.", "Prefix_Hint");
3861 PrintToServer("%t5) The proces is complete when the final 8/8 appears.", "Prefix_Hint");
3862
3863 if(g_hArray_InitalizeCleanup == INVALID_HANDLE)
3864 g_hArray_InitalizeCleanup = CreateArray();
3865 else
3866 ClearArray(g_hArray_InitalizeCleanup);
3867
3868 CreateTimer(5.0, Timer_InitalizeRanks);
3869
3870 return Plugin_Handled;
3871}
3872
3873public Action:Timer_InitalizeRanks(Handle:timer)
3874{
3875 PrintToServer("%t- Intalizing - Step 1/8", "Prefix_Hint");
3876 CPrintToChatAll("%t- Intalizing - Step 1/8", "Prefix_Chat");
3877
3878 g_bInitalizing = true;
3879 decl String:sQuery[64];
3880 Format(sQuery, sizeof(sQuery), "SELECT `map`,`points` FROM `maps`");
3881 SQL_TQuery(g_hDatabase, InitalizeStep2, sQuery);
3882}
3883
3884public InitalizeStep2(Handle:owner, Handle:hndl, const String:error[], any:data)
3885{
3886 if(hndl == INVALID_HANDLE)
3887 {
3888 Timer_LogError("SQL Error on InitalizeStep2: %s", error);
3889 return;
3890 }
3891
3892 if(g_hTrie_CfgMaps == INVALID_HANDLE)
3893 g_hTrie_CfgMaps = CreateTrie();
3894 else
3895 ClearTrie(g_hTrie_CfgMaps);
3896
3897 decl String:sQuery[192], String:sMap[128], iPoints;
3898 if(!SQL_GetRowCount(hndl))
3899 {
3900 PrintToServer("%t- Intalizing - Step 2/8", "Prefix_Hint");
3901 CPrintToChatAll("%t- Intalizing - Step 2/8", "Prefix_Chat");
3902 }
3903 else
3904 {
3905 while(SQL_FetchRow(hndl))
3906 {
3907 SQL_FetchString(hndl, 0, sMap, sizeof(sMap));
3908 iPoints = SQL_FetchInt(hndl, 1);
3909
3910 PrintToServer("%t- Intalizing - Step 2/8 - Map %s = %d Points", "Prefix_Hint", sMap, iPoints);
3911 CPrintToChatAll("%t- Intalizing - Step 2/8 - Map %s = %d Points", "Prefix_Chat", sMap, iPoints);
3912
3913 if(iPoints >= 0)
3914 SetTrieValue(g_hTrie_CfgMaps, sMap, iPoints);
3915 }
3916 }
3917
3918 Format(sQuery, sizeof(sQuery), "DROP TABLE `ranks`");
3919 SQL_TQuery(g_hDatabase, InitalizeStep3, sQuery);
3920}
3921
3922public InitalizeStep3(Handle:owner, Handle:hndl, const String:error[], any:data)
3923{
3924 if(hndl == INVALID_HANDLE)
3925 {
3926 Timer_LogError("SQL Error on InitalizeStep3: %s", error);
3927 return;
3928 }
3929 PrintToServer("%t- Intalizing - Step 3/8", "Prefix_Hint");
3930 CPrintToChatAll("%t- Intalizing - Step 3/8", "Prefix_Chat");
3931
3932 if(g_hDatabase != INVALID_HANDLE && CloseHandle(g_hDatabase))
3933 g_hDatabase = INVALID_HANDLE;
3934
3935 SQL_TConnect(InitalizeStep4, "timer");
3936}
3937
3938public InitalizeStep4(Handle:owner, Handle:hndl, const String:error[], any:data)
3939{
3940 if(hndl == INVALID_HANDLE)
3941 {
3942 Timer_LogError("SQL Error on InitalizeStep4.Handle: %s", error);
3943 return;
3944 }
3945
3946 PrintToServer("%t- Intalizing - Step 4/8", "Prefix_Hint");
3947 CPrintToChatAll("%t- Intalizing - Step 4/8", "Prefix_Chat");
3948
3949 g_hDatabase = hndl;
3950 if(g_bSql)
3951 {
3952 SQL_TQuery(g_hDatabase, CallBack_Names, "SET NAMES 'utf8'", _, DBPrio_High);
3953 SQL_TQuery(g_hDatabase, InitalizeStep5, "CREATE TABLE IF NOT EXISTS `ranks` (`auth` varchar(32) NOT NULL PRIMARY KEY, `points` int(11) NOT NULL, `lastname` varchar(64) NOT NULL, `lastplay` int(11) NOT NULL, `lastcountry` varchar(64) NOT NULL);");
3954 }
3955 else
3956 SQL_TQuery(g_hDatabase, InitalizeStep5, "CREATE TABLE IF NOT EXISTS `ranks` (`auth` varchar(32) NOT NULL PRIMARY KEY, `points` INTEGER NOT NULL, `lastname` varchar(64) NOT NULL, `lastplay` INTEGER NOT NULL, `lastcountry` varchar(64) NOT NULL);");
3957}
3958
3959public InitalizeStep5(Handle:owner, Handle:hndl, const String:error[], any:data)
3960{
3961 if(hndl == INVALID_HANDLE)
3962 {
3963 Timer_LogError("SQL Error on InitalizeStep5: %s", error);
3964 return;
3965 }
3966 PrintToServer("%t- Intalizing - Step 5/8", "Prefix_Hint");
3967 CPrintToChatAll("%t- Intalizing - Step 5/8", "Prefix_Chat");
3968
3969 decl String:sQuery[192];
3970 Format(sQuery, sizeof(sQuery), "SELECT DISTINCT `auth`,`name` FROM `round` GROUP BY `auth`");
3971 SQL_TQuery(g_hDatabase, InitalizeStep6, sQuery);
3972}
3973
3974public InitalizeStep6(Handle:owner, Handle:hndl, const String:error[], any:data)
3975{
3976 if(hndl == INVALID_HANDLE)
3977 {
3978 Timer_LogError("SQL Error on InitalizeStep6: %s", error);
3979 return;
3980 }
3981
3982 g_iInitalizeQueries = 0;
3983 decl String:sQuery[192], String:sAuth[24], String:sOriginal[24], String:sName[64];
3984 if(!SQL_GetRowCount(hndl))
3985 {
3986 g_bInitalizing = false;
3987 PrintToServer("%t- Intalizing - Step 6/8, Terminating Process, Not Enough Data", "Prefix_Hint", g_iInitalizeQueries);
3988 CPrintToChatAll("%t- Intalizing - Step 6/8, Terminating Process, Not Enough Data", "Prefix_Chat", g_iInitalizeQueries);
3989 }
3990 else
3991 {
3992 while(SQL_FetchRow(hndl))
3993 {
3994 SQL_FetchString(hndl, 0, sOriginal, sizeof(sOriginal));
3995 SQL_FetchString(hndl, 1, sName, sizeof(sName));
3996 decl String:sSafeName[(2 * strlen(sName) + 1)];
3997 SQL_EscapeString(g_hDatabase, sName, sSafeName, (2 * strlen(sName) + 1));
3998 strcopy(sAuth, sizeof(sAuth), sOriginal);
3999
4000 new Handle:hPack = CreateDataPack();
4001 WritePackString(hPack, sOriginal);
4002 WritePackString(hPack, sAuth);
4003 PushArrayCell(g_hArray_InitalizeCleanup, hPack);
4004
4005 g_iInitalizeQueries++;
4006 Format(sQuery, sizeof(sQuery), "INSERT INTO `ranks` (`auth`,`points`, `lastname`, `lastplay`) VALUES ('%s', 0, '%s', 0)", sAuth, sSafeName);
4007 SQL_TQuery(g_hDatabase, InitalizeStep7, sQuery, hPack);
4008 }
4009
4010 if(g_iInitalizeQueries)
4011 {
4012 PrintToServer("%t- Intalizing - Step 6/8, %d Unique Steam IDs", "Prefix_Hint", g_iInitalizeQueries);
4013 CPrintToChatAll("%t- Intalizing - Step 6/8, %d Unique Steam IDs", "Prefix_Chat", g_iInitalizeQueries);
4014 }
4015 }
4016}
4017
4018public InitalizeStep7(Handle:owner, Handle:hndl, const String:error[], any:pack)
4019{
4020 if(hndl == INVALID_HANDLE)
4021 {
4022 Timer_LogError("SQL Error on InitalizeStep7: %s", error);
4023 return;
4024 }
4025
4026 ResetPack(pack);
4027 decl String:sAuth[24], String:sOriginal[24];
4028 ReadPackString(pack, sOriginal, sizeof(sOriginal));
4029 ReadPackString(pack, sAuth, sizeof(sAuth));
4030
4031 decl String:sQuery[192];
4032 Format(sQuery, sizeof(sQuery), "SELECT `map`,`physicsdifficulty` FROM `round` WHERE `auth` = '%s'", sOriginal);
4033 SQL_TQuery(g_hDatabase, InitalizeStep8, sQuery, pack);
4034}
4035
4036public InitalizeStep8(Handle:owner, Handle:hndl, const String:error[], any:pack)
4037{
4038 if(hndl == INVALID_HANDLE)
4039 {
4040 Timer_LogError("SQL Error on InitalizeStep8: %s", error);
4041 return;
4042 }
4043
4044 ResetPack(pack);
4045 decl String:sAuth[24], String:sOriginal[24];
4046 ReadPackString(pack, sOriginal, sizeof(sOriginal));
4047 ReadPackString(pack, sAuth, sizeof(sAuth));
4048
4049 new iQueries, iChance = (g_iInitalizeQueries / 4);
4050 g_iInitalizeQueries--;
4051 decl String:sMap[128], String:sQuery[192], iPhysics, iWorth;
4052
4053 if(!SQL_GetRowCount(hndl))
4054 {
4055 g_iInitalizeQueries++;
4056 Format(sQuery, sizeof(sQuery), "UPDATE `ranks` SET `points` = `points` + %d WHERE `auth` = '%s'", iWorth, sAuth);
4057 SQL_TQuery(g_hDatabase, InitalizeStep9, sQuery);
4058 }
4059 else
4060 {
4061 new Handle:hTemp = CreateTrie();
4062 while(SQL_FetchRow(hndl))
4063 {
4064 iQueries++;
4065
4066 SQL_FetchString(hndl, 0, sMap, sizeof(sMap));
4067 iPhysics = SQL_FetchInt(hndl, 1);
4068
4069 iWorth = 0;
4070 if(GetTrieValue(g_hTrie_CfgMaps, sMap, iWorth))
4071 if(g_bTimerPhysics && g_iTotalDiff && iPhysics > 0)
4072 iWorth = RoundToFloor(float(iWorth) * g_fDiffFactor[iPhysics]);
4073
4074 if(!GetRandomInt(0, iChance))
4075 {
4076 PrintToServer("%t- Intalizing - Step 7/8, Processing...", "Prefix_Hint");
4077 CPrintToChatAll("%t- Intalizing - Step 7/8, Processing...", "Prefix_Chat");
4078 }
4079
4080 g_iInitalizeQueries++;
4081 Format(sQuery, sizeof(sQuery), "UPDATE `ranks` SET `points` = `points` + %d WHERE `auth` = '%s'", iWorth, sAuth);
4082 SQL_TQuery(g_hDatabase, InitalizeStep9, sQuery);
4083 }
4084
4085 CloseHandle(hTemp);
4086 }
4087}
4088
4089public InitalizeStep9(Handle:owner, Handle:hndl, const String:error[], any:pack)
4090{
4091 if(hndl == INVALID_HANDLE)
4092 {
4093 Timer_LogError("SQL Error on InitalizeStep9: %s", error);
4094 return;
4095 }
4096
4097 g_iInitalizeQueries--;
4098 new iChance = g_iInitalizeQueries / 4;
4099 if(g_iInitalizeQueries <= 0)
4100 {
4101 PrintToServer("%t- Intalizing - Step 8/8, Process Completed", "Prefix_Hint");
4102 CPrintToChatAll("%t- Intalizing - Step 8/8, Process Completed", "Prefix_Chat");
4103
4104 g_bInitalizing = false;
4105 for(new i = 0; i < GetArraySize(g_hArray_InitalizeCleanup); i++)
4106 {
4107 new Handle:hTemp2 = Handle:GetArrayCell(g_hArray_InitalizeCleanup, 0);
4108 CloseHandle(hTemp2);
4109 RemoveFromArray(g_hArray_InitalizeCleanup, 0);
4110 }
4111 }
4112 else if(!GetRandomInt(0, iChance))
4113 {
4114 PrintToServer("%t- Intalizing - Step 7/8, Queries Remaining = %d", "Prefix_Hint", g_iInitalizeQueries);
4115 CPrintToChatAll("%t- Intalizing - Step 7/8, Queries Remaining = %d", "Prefix_Chat", g_iInitalizeQueries);
4116 }
4117}
4118
4119// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4120
4121Parse_DefaultWorth()
4122{
4123 if(g_hTrie_CfgWorth == INVALID_HANDLE)
4124 g_hTrie_CfgWorth = CreateTrie();
4125 else
4126 ClearTrie(g_hTrie_CfgWorth);
4127
4128 decl String:sPath[PLATFORM_MAX_PATH];
4129 BuildPath(Path_SM, sPath, sizeof(sPath), "configs/timer/rankings.maps.cfg");
4130 new Handle:hKeyValues = CreateKeyValues("Timer.Rankings.Maps");
4131 new points;
4132 if(FileToKeyValues(hKeyValues, sPath))
4133 {
4134 if(KvGotoFirstSubKey(hKeyValues, false))
4135 {
4136 do
4137 {
4138 KvGetSectionName(hKeyValues, sPath, sizeof(sPath));
4139 points = KvGetNum(hKeyValues, NULL_STRING, g_iDefaultMapWorth);
4140 SetTrieValue(g_hTrie_CfgWorth, sPath, points);
4141 }
4142 while (KvGotoNextKey(hKeyValues, false));
4143 KvGoBack(hKeyValues);
4144 }
4145 }
4146
4147 CloseHandle(hKeyValues);
4148
4149 if(!GetTrieValue(g_hTrie_CfgWorth, g_sCurrentMap, g_iCurrentMapWorth))
4150 g_iCurrentMapWorth = g_iDefaultMapWorth;
4151}
4152
4153Parse_DefualtTier()
4154{
4155 if(g_hTrie_CfgTier == INVALID_HANDLE)
4156 g_hTrie_CfgTier = CreateTrie();
4157 else
4158 ClearTrie(g_hTrie_CfgTier);
4159
4160 decl String:sPath[PLATFORM_MAX_PATH];
4161 BuildPath(Path_SM, sPath, sizeof(sPath), "configs/timer/rankings.maps.cfg");
4162 new Handle:hKeyValues = CreateKeyValues("Timer.Rankings.Tier");
4163 new tier;
4164 if(FileToKeyValues(hKeyValues, sPath))
4165 {
4166 KvGotoNextKey(hKeyValues);
4167 if(KvGotoFirstSubKey(hKeyValues, false))
4168 {
4169 do
4170 {
4171 KvGetSectionName(hKeyValues, sPath, sizeof(sPath));
4172 tier = KvGetNum(hKeyValues, NULL_STRING, 1);
4173 SetTrieValue(g_hTrie_CfgTier, sPath, tier);
4174 }
4175 while (KvGotoNextKey(hKeyValues, false));
4176 KvGoBack(hKeyValues);
4177 }
4178 }
4179
4180 CloseHandle(hKeyValues);
4181
4182 if(!GetTrieValue(g_hTrie_CfgTier, g_sCurrentMap, g_iCurrentMapTier))
4183 g_iCurrentMapTier = 1;
4184}
4185
4186Parse_Points()
4187{
4188 if(g_hArray_CfgPoints == INVALID_HANDLE)
4189 g_hArray_CfgPoints = CreateArray();
4190 else
4191 ClearArray(g_hArray_CfgPoints);
4192
4193 if(g_hArray_CfgRanks == INVALID_HANDLE)
4194 g_hArray_CfgRanks = CreateArray();
4195 else
4196 ClearArray(g_hArray_CfgRanks);
4197
4198 if(g_hCfgArray_DisplayTag == INVALID_HANDLE)
4199 g_hCfgArray_DisplayTag = CreateArray(16);
4200 else
4201 ClearArray(g_hCfgArray_DisplayTag);
4202
4203 if(g_hCfgArray_DisplayChat == INVALID_HANDLE)
4204 g_hCfgArray_DisplayChat = CreateArray(MAX_TAG_LENGTH);
4205 else
4206 ClearArray(g_hCfgArray_DisplayChat);
4207
4208 if(g_hTrie_CfgCommands == INVALID_HANDLE)
4209 g_hTrie_CfgCommands = CreateTrie();
4210 else
4211 ClearTrie(g_hTrie_CfgCommands);
4212
4213 if(g_hCfgArray_DisplayInfo == INVALID_HANDLE)
4214 g_hCfgArray_DisplayInfo = CreateArray(16);
4215 else
4216 ClearArray(g_hCfgArray_DisplayInfo);
4217
4218 if(g_hCfgArray_DisplayStars == INVALID_HANDLE)
4219 g_hCfgArray_DisplayStars = CreateArray();
4220 else
4221 ClearArray(g_hCfgArray_DisplayStars);
4222
4223 if(g_hCfgArray_DisplayColor == INVALID_HANDLE)
4224 g_hCfgArray_DisplayColor = CreateArray(MAX_TAG_LENGTH);
4225 else
4226 ClearArray(g_hCfgArray_DisplayColor);
4227
4228 if(g_hArray_Positions == INVALID_HANDLE)
4229 g_hArray_Positions = CreateArray();
4230 else
4231 ClearArray(g_hArray_Positions);
4232
4233 new Handle:hTemp[8] = { INVALID_HANDLE, ... };
4234 hTemp[0] = CreateArray();
4235 hTemp[1] = CreateArray();
4236 hTemp[2] = CreateArray(MAX_TAG_LENGTH);
4237 hTemp[3] = CreateArray(MAX_TAG_LENGTH);
4238 hTemp[4] = CreateArray(MAX_TAG_LENGTH);
4239 hTemp[5] = CreateArray(MAX_TAG_LENGTH);
4240 hTemp[6] = CreateArray();
4241 hTemp[7] = CreateArray();
4242
4243 g_iTotalRanks = 0;
4244 decl iBuffer, String:sPath[PLATFORM_MAX_PATH], String:sBuffer[MAX_TAG_LENGTH];
4245 BuildPath(Path_SM, sPath, sizeof(sPath), "configs/timer/rankings.cfg");
4246
4247 new Handle:hKeyValues = CreateKeyValues("Timer.Rankings.Configs");
4248 if(FileToKeyValues(hKeyValues, sPath) && KvGotoFirstSubKey(hKeyValues))
4249 {
4250 do
4251 {
4252 KvGetSectionName(hKeyValues, sPath, sizeof(sPath));
4253 if(StrEqual(sPath, "Commands", false))
4254 {
4255 KvGotoFirstSubKey(hKeyValues, false);
4256 do
4257 {
4258 KvGetSectionName(hKeyValues, sBuffer, sizeof(sBuffer));
4259 iBuffer = KvGetNum(hKeyValues, NULL_STRING, 0);
4260
4261 if(!StrContains(sBuffer, "sm_"))
4262 {
4263 strcopy(sPath, sizeof(sPath), sBuffer);
4264 ReplaceString(sPath, sizeof(sPath), "sm_", "!", false);
4265 SetTrieValue(g_hTrie_CfgCommands, sPath, iBuffer);
4266
4267 strcopy(sPath, sizeof(sPath), sBuffer);
4268 ReplaceString(sPath, sizeof(sPath), "sm_", "/", false);
4269 SetTrieValue(g_hTrie_CfgCommands, sPath, iBuffer);
4270 }
4271 else
4272 SetTrieValue(g_hTrie_CfgCommands, sBuffer, iBuffer);
4273 }
4274 while (KvGotoNextKey(hKeyValues, false));
4275
4276 KvGoBack(hKeyValues);
4277 }
4278 else if(StrEqual(sPath, "Loading", false))
4279 {
4280 KvGetString(hKeyValues, "tag", g_sLoadingScoreTag, sizeof(g_sLoadingScoreTag));
4281 KvGetString(hKeyValues, "chat", g_sLoadingChatTag, sizeof(g_sLoadingChatTag));
4282 KvGetString(hKeyValues, "text", g_sLoadingChatColor, sizeof(g_sLoadingChatColor));
4283
4284 ReplaceString(g_sLoadingChatTag, sizeof(g_sLoadingChatTag), "#", "\x07");
4285 ReplaceString(g_sLoadingChatColor, sizeof(g_sLoadingChatColor), "#", "\x07");
4286 }
4287 else
4288 {
4289 PushArrayCell(hTemp[0], KvGetNum(hKeyValues, "points", 0));
4290
4291 PushArrayCell(hTemp[1], KvGetNum(hKeyValues, "ranks", 0));
4292
4293 KvGetString(hKeyValues, "tag", sPath, sizeof(sPath));
4294 PushArrayString(hTemp[2], sPath);
4295
4296 KvGetString(hKeyValues, "chat", sBuffer, sizeof(sBuffer));
4297 ReplaceString(sBuffer, sizeof(sBuffer), "#", "\x07");
4298 PushArrayString(hTemp[3], sBuffer);
4299
4300 KvGetString(hKeyValues, "text", sBuffer, sizeof(sBuffer));
4301 ReplaceString(sBuffer, sizeof(sBuffer), "#", "\x07");
4302 PushArrayString(hTemp[4], sBuffer);
4303
4304 KvGetString(hKeyValues, "info", sPath, sizeof(sPath));
4305 PushArrayString(hTemp[5], sPath);
4306
4307 PushArrayCell(hTemp[6], KvGetNum(hKeyValues, "stars", 0));
4308 PushArrayCell(hTemp[7], KvGetNum(hKeyValues, "csgorank", 0));
4309 g_iTotalRanks++;
4310 }
4311 }
4312 while (KvGotoNextKey(hKeyValues));
4313
4314 g_iTotalRanks--;
4315 for(new i = g_iTotalRanks; i >= 0; i--)
4316 {
4317 new iIndex;
4318 new iCurrent;
4319 new iLowest = 2147483647;
4320
4321 if(g_iPositionMethod)
4322 {
4323 new iSize = GetArraySize(hTemp[1]);
4324 for(new j = 0; j < iSize; j++)
4325 {
4326 if((iCurrent = GetArrayCell(hTemp[1], j)) <= iLowest)
4327 {
4328 iIndex = j;
4329 iLowest = iCurrent;
4330 }
4331 }
4332 }
4333 else
4334 {
4335 new iSize = GetArraySize(hTemp[0]);
4336 for(new j = 0; j < iSize; j++)
4337 {
4338 if((iCurrent = GetArrayCell(hTemp[0], j)) <= iLowest)
4339 {
4340 iIndex = j;
4341 iLowest = iCurrent;
4342 }
4343 }
4344 }
4345
4346 new String:scfgBuffer[MAX_TAG_LENGTH];
4347 PushArrayCell(g_hArray_CfgPoints, GetArrayCell(hTemp[0], iIndex));
4348 PushArrayCell(g_hArray_CfgRanks, GetArrayCell(hTemp[1], iIndex));
4349 GetArrayString(hTemp[2], iIndex, scfgBuffer, sizeof(scfgBuffer));
4350 PushArrayString(g_hCfgArray_DisplayTag, scfgBuffer);
4351 GetArrayString(hTemp[3], iIndex, scfgBuffer, sizeof(scfgBuffer));
4352 PushArrayString(g_hCfgArray_DisplayChat, scfgBuffer);
4353 GetArrayString(hTemp[4], iIndex, scfgBuffer, sizeof(scfgBuffer));
4354 PushArrayString(g_hCfgArray_DisplayColor, scfgBuffer);
4355 GetArrayString(hTemp[5], iIndex, scfgBuffer, sizeof(scfgBuffer));
4356 PushArrayString(g_hCfgArray_DisplayInfo, scfgBuffer);
4357 PushArrayCell(g_hCfgArray_DisplayStars, GetArrayCell(hTemp[6], iIndex));
4358
4359
4360 for(new j = 0; j <= 6; j++)
4361 RemoveFromArray(hTemp[j], iIndex);
4362 }
4363
4364 if(g_iPositionMethod)
4365 {
4366 new iSize = GetArraySize(g_hArray_CfgRanks);
4367 for(new i = 0; i < iSize; i++)
4368 {
4369 g_iHighestRank = GetArrayCell(g_hArray_CfgRanks, i);
4370
4371 if(FindValueInArray(g_hArray_Positions, g_iHighestRank) == -1)
4372 PushArrayCell(g_hArray_Positions, g_iHighestRank);
4373 }
4374 }
4375 }
4376
4377 CloseHandle(hKeyValues);
4378 for(new i = 0; i <= 6; i++)
4379 CloseHandle(hTemp[i]);
4380}
4381
4382Parse_Difficulties()
4383{
4384 g_iTotalDiff = 0;
4385 decl String:sPath[PLATFORM_MAX_PATH];
4386 BuildPath(Path_SM, sPath, sizeof(sPath), "configs/timer/difficulties.cfg");
4387
4388 new Handle:hKeyValues = CreateKeyValues("timer.difficulties");
4389 if (!FileToKeyValues(hKeyValues, sPath) || !KvGotoFirstSubKey(hKeyValues))
4390 CloseHandle(hKeyValues);
4391 else
4392 {
4393 do
4394 {
4395 KvGetSectionName(hKeyValues, sPath, sizeof(sPath));
4396 new iIndex = StringToInt(sPath);
4397 g_iDiffPoints[iIndex] = KvGetNum(hKeyValues, "points", 0);
4398 g_fDiffFactor[iIndex] = KvGetFloat(hKeyValues, "map_factor", 1.0);
4399
4400 g_iTotalDiff++;
4401 }
4402 while (KvGotoNextKey(hKeyValues));
4403
4404 CloseHandle(hKeyValues);
4405 }
4406}
4407
4408public Action:Command_PrintRanks(args)
4409{
4410 decl String:sArgument[4];
4411 GetCmdArg(1, sArgument, sizeof(sArgument));
4412 new iArgument = StringToInt(sArgument);
4413
4414 if(iArgument & cPrintRanks)
4415 {
4416 decl String:sTemp[256];
4417 LogToFile(g_sDumpLog, "%d currently defined ranks.", g_iTotalRanks);
4418 LogToFile(g_sDumpLog, "===Rank Definitions===");
4419 for(new i = 0; i <= g_iTotalRanks; i++)
4420 {
4421 LogToFile(g_sDumpLog, "Minimum Points: %d", GetArrayCell(g_hArray_CfgPoints, i));
4422 LogToFile(g_sDumpLog, "Minimum Rank: %d", GetArrayCell(g_hArray_CfgRanks, i));
4423 GetArrayString(g_hCfgArray_DisplayTag, i, sTemp, sizeof(sTemp));
4424 LogToFile(g_sDumpLog, "Tag: %s", sTemp);
4425 GetArrayString(g_hCfgArray_DisplayChat, i, sTemp, sizeof(sTemp));
4426 LogToFile(g_sDumpLog, "Chat: %s", sTemp);
4427 GetArrayString(g_hCfgArray_DisplayColor, i, sTemp, sizeof(sTemp));
4428 LogToFile(g_sDumpLog, "Text: %s", sTemp);
4429 GetArrayString(g_hCfgArray_DisplayInfo, i, sTemp, sizeof(sTemp));
4430 LogToFile(g_sDumpLog, "Info: %s", sTemp);
4431 LogToFile(g_sDumpLog, "Stars: %d", GetArrayCell(g_hCfgArray_DisplayStars, i));
4432 if(i < g_iTotalRanks)
4433 LogToFile(g_sDumpLog, "---");
4434 else
4435 LogToFile(g_sDumpLog, "");
4436 }
4437
4438 PrintToChatAll("[Timer] Rankings: Finished printing Rank configuration to log!");
4439 }
4440
4441 if(iArgument & cPrintMaps)
4442 {
4443 decl String:sMapQuery[256];
4444 Format(sMapQuery, sizeof(sMapQuery), "SELECT * FROM `maps` ORDER BY `maps` ASC");
4445 SQL_TQuery(g_hDatabase, CallBack_DebugPrintMaps, sMapQuery);
4446 }
4447
4448 if(iArgument & cPrintPlayers)
4449 {
4450 if(g_iCurrentDebug != -1)
4451 return Plugin_Handled;
4452
4453 g_iCurrentDebug = (g_iTotalPlayers > 500) ? 500 : g_iTotalPlayers;
4454 decl String:sPlayerQuery[256];
4455 Format(sPlayerQuery, sizeof(sPlayerQuery), "SELECT `lastname`,`auth`,`points` FROM `ranks` ORDER BY `points` DESC LIMIT %d,%d", 0, g_iCurrentDebug);
4456 SQL_TQuery(g_hDatabase, CallBack_DebugPrintPlayers, sPlayerQuery, 0);
4457 }
4458
4459 return Plugin_Handled;
4460}
4461
4462public CallBack_DebugPrintMaps(Handle:owner, Handle:hndl, const String:error[], any:data)
4463{
4464 if(hndl == INVALID_HANDLE || !SQL_GetRowCount(hndl))
4465 {
4466 LogToFile(g_sDumpLog, "No Maps Found");
4467 LogToFile(g_sDumpLog, "");
4468
4469 PrintToChatAll("[Timer] Rankings: Finished printing Map Worth to log!");
4470 return;
4471 }
4472
4473 new iIndex;
4474 decl iPoints, iPlayed, String:sMap[256];
4475 while(SQL_FetchRow(hndl))
4476 {
4477 SQL_FetchString(hndl, 0, sMap, sizeof(sMap));
4478 iPoints = SQL_FetchInt(hndl, 1);
4479 iPlayed = SQL_FetchInt(hndl, 2);
4480
4481 ++iIndex;
4482 LogToFile(g_sDumpLog, "[%d] `%d` == %d Points, Played %dx", sMap, iPoints, iPlayed);
4483 }
4484
4485 LogToFile(g_sDumpLog, "");
4486 PrintToChatAll("[Timer] Rankings: Finished printing Map Worth to log!");
4487}
4488
4489public CallBack_DebugPrintPlayers(Handle:owner, Handle:hndl, const String:error[], any:data)
4490{
4491 if(hndl == INVALID_HANDLE || !SQL_GetRowCount(hndl))
4492 {
4493 LogToFile(g_sDumpLog, "No Players Found");
4494 LogToFile(g_sDumpLog, "");
4495
4496 PrintToChatAll("[Timer] Rankings: Finished printing Player Ranks to log!");
4497 return;
4498 }
4499
4500 LogToFile(g_sDumpLog, "---Entries %d - %d---", data, g_iCurrentDebug);
4501
4502 new iSize = GetArraySize(g_hArray_Positions);
4503 new iOutside = FindValueInArray(g_hArray_Positions, -1);
4504 decl iPoints, String:sName[65], String:sAuth[24], String:sPosition[256];
4505 while(SQL_FetchRow(hndl))
4506 {
4507 SQL_FetchString(hndl, 0, sName, sizeof(sName));
4508 SQL_FetchString(hndl, 1, sAuth, sizeof(sAuth));
4509 iPoints = SQL_FetchInt(hndl, 2);
4510
4511 new iPosition = -1;
4512 if(g_iDebugIndex > g_iHighestRank)
4513 iPosition = iOutside;
4514 else
4515 {
4516 for(new i = 0; i < iSize; i++)
4517 {
4518 if(g_iDebugIndex <= GetArrayCell(g_hArray_Positions, i))
4519 {
4520 iPosition = i;
4521 break;
4522 }
4523 }
4524 }
4525
4526 if(iPosition != -1)
4527 GetArrayString(g_hCfgArray_DisplayInfo, iPosition, sPosition, sizeof(sPosition));
4528 else
4529 strcopy(sPosition, sizeof(sPosition), "");
4530
4531 LogToFile(g_sDumpLog, "[%s] `%s` == %d Points, %d/%d Position (`%s`)", sAuth, sName, iPoints, iPosition, g_iHighestRank, sPosition);
4532 g_iDebugIndex++;
4533 }
4534
4535 if(data == g_iTotalPlayers)
4536 {
4537 PrintToChatAll("[Timer] Rankings: Finished printing Player Ranks to log!");
4538 g_iDebugIndex = 1;
4539 g_iCurrentDebug = -1;
4540 return;
4541 }
4542
4543 new iStart = g_iCurrentDebug + 1;
4544 g_iCurrentDebug += 500;
4545 if(g_iCurrentDebug > g_iTotalPlayers)
4546 g_iCurrentDebug = g_iTotalPlayers;
4547
4548 decl String:sPlayerQuery[256];
4549 Format(sPlayerQuery, sizeof(sPlayerQuery), "SELECT `lastname`,`auth`,`points` FROM `ranks` ORDER BY `points` DESC LIMIT %d,%d", iStart, g_iCurrentDebug);
4550 SQL_TQuery(g_hDatabase, CallBack_DebugPrintPlayers, sPlayerQuery, iStart);
4551}
4552
4553public Action:Timer_AuthClient(Handle:timer, any:userid)
4554{
4555 new client = GetClientOfUserId(userid);
4556 if(IsClientInGame(client) && !IsFakeClient(client))
4557 {
4558 g_bAuthed[client] = GetClientAuthId(client, AuthId_Steam2, g_sAuth[client], sizeof(g_sAuth[]));
4559 if(!g_bAuthed[client])
4560 return Plugin_Continue;
4561 else
4562 {
4563 if(g_hDatabase != INVALID_HANDLE && !g_bInitalizing)
4564 return Plugin_Continue;
4565
4566 if(!g_bLoadedSQL[client])
4567 {
4568 decl String:sQuery[192];
4569 Format(sQuery, sizeof(sQuery), "SELECT `points`,`vipendtime`,`customtag`,`customchat` FROM `ranks` WHERE `auth` = '%s'", g_sAuth[client]);
4570 SQL_TQuery(g_hDatabase, CallBack_ClientConnect, sQuery, GetClientUserId(client));
4571 }
4572
4573 if(!g_bLoadedCookies[client] && AreClientCookiesCached(client))
4574 LoadClientData(client);
4575 }
4576 }
4577
4578 return Plugin_Stop;
4579}
4580
4581/*ErrorCheck(Handle:owner, const String:error[], const String:callback[] = "")
4582{
4583 if(owner == INVALID_HANDLE)
4584 {
4585 LogError("[Timer] Rankings: Fatal error occured in `%s`", callback);
4586 LogError("> `%s`", error);
4587 if(g_iEnabled == 2)
4588 {
4589 PrintToDebug("[Timer] Rankings: Fatal error occured in `%s`", callback);
4590 PrintToDebug("> `%s`", error);
4591 }
4592
4593 //SetFailState("FATAL SQL ERROR in `%s`; View logs!", callback);
4594 }
4595 else if(!StrEqual(error, ""))
4596 {
4597 LogError("[Timer] Rankings: Error occured in `%s`", callback);
4598 LogError("> `%s`", error);
4599 if(g_iEnabled == 2)
4600 {
4601 PrintToDebug("[Timer] Rankings: Error occured in `%s`", callback);
4602 PrintToDebug("> `%s`", error);
4603 }
4604 }
4605}*/
4606
4607stock PrintToDebug(const String:format[], any:...)
4608{
4609 decl String:sBuffer[1024];
4610 VFormat(sBuffer, sizeof(sBuffer), format, 2);
4611
4612 LogToFile(g_sPluginLog, sBuffer);
4613}
4614
4615stock PrintToAdmins(const String:format[], any:...)
4616{
4617 decl String:sBuffer[512];
4618 VFormat(sBuffer, sizeof(sBuffer), format, 2);
4619
4620 LogMessage("%s", sBuffer);
4621 for(new i = 1; i <= MaxClients; i++)
4622 {
4623 if(!IsClientInGame(i) || !CheckCommandAccess(i, "Timer_Rankings_Admin", ADMFLAG_GENERIC))
4624 continue;
4625
4626 CPrintToChat(i, "%t%s", "Prefix_Chat", sBuffer);
4627 }
4628
4629 if(g_iEnabled == 2)
4630 LogToFile(g_sPluginLog, sBuffer);
4631}
4632
4633public Native_GetClientPoints(Handle:plugin, numParams)
4634{
4635 return g_iCurrentPoints[GetNativeCell(1)];
4636}
4637
4638public Native_GetClientRank(Handle:plugin, numParams)
4639{
4640 if(g_iCurrentPoints[GetNativeCell(1)] < g_iRequiredPoints)
4641 return 0;
4642
4643 return g_iRank[GetNativeCell(1)];
4644}
4645
4646public Native_GetClientTag(Handle:plugin, numParams)
4647{
4648 decl String:sBuffer[20];
4649 new client = GetNativeCell(1);
4650 if(!IsFakeClient(client) && client > 0 && g_iCurrentPoints[client] < g_iRequiredPoints)
4651 GetArrayString(g_hCfgArray_DisplayTag, 0, sBuffer, sizeof(sBuffer));
4652 else if(!IsFakeClient(client) && client > 0 && g_iCurrentIndex[client] > 0)
4653 GetArrayString(g_hCfgArray_DisplayTag, g_iCurrentIndex[client], sBuffer, sizeof(sBuffer));
4654
4655 SetNativeString(2, sBuffer, GetNativeCell(3));
4656 return true;
4657}
4658
4659public Native_GetClientChatTag(Handle:plugin, numParams)
4660{
4661 decl String:sBuffer[20];
4662 new client = GetNativeCell(1);
4663 if(!IsFakeClient(client) && client > 0 && g_iCurrentPoints[client] < g_iRequiredPoints)
4664 GetArrayString(g_hCfgArray_DisplayTag, 0, sBuffer, sizeof(sBuffer));
4665 if(!IsFakeClient(client))
4666 GetArrayString(g_hCfgArray_DisplayChat, g_iCurrentIndex[client], sBuffer, sizeof(sBuffer));
4667
4668 SetNativeString(2, sBuffer, GetNativeCell(3));
4669 return true;
4670}
4671
4672public Native_GetTotalRankedPlayers(Handle:plugin, numParams)
4673{
4674 return g_iTotalPlayers;
4675}
4676
4677
4678public Native_GetTotalRankedPlayersCountry(Handle:plugin, numParams)
4679{
4680 new client = GetNativeCell(1);
4681 return g_iTotalRanksCountry[client];
4682}
4683
4684public Native_GetClientCountryRank(Handle:plugin, numParams)
4685{
4686 new client = GetNativeCell(1);
4687 return g_iCountryRank[client];
4688}