· 8 years ago · Dec 23, 2017, 06:48 PM
1/* AMX Mod X script
2* ______ __ __ __ ________
3* / ____ \ \ \ / / / | |______ |
4* / / \ \ \ \ / / / | __ | |
5* | / \ | \ \ / / / /| | |__| | |
6* | | | | ______ _ __ \ \ / / _ / / | | ______ | |
7* _ _____ _____ | | | | / ____ \ | | / / \ \ / / |_| / / | | / ____ \ | |
8* | | / __ | / __ | | | | | | / \_\ | | / / \ \ / / _ / / | | /_/ \ \ | |
9* | |/ / | |/ / | | | | | | | \_____ | |/ / \ \ / / | | / /____| |__ ______| | | |
10* | | / | | / | | | | | | \_____ \ | | / \ \ / / | | /_______ |__| / _____ | | |
11* | |/ | |/ | | | | | | \ | | |/\ \ \ / / | | | | / / | | __ | |
12* | | | | | | | \ / | __ | | | |\ \ \ \/ / | | | | | | /| | | | | |
13* | | | | | | \ \____/ / \ \____/ | | | \ \ \ / | | | | \ \___/ /\ \ / / _____| |
14* |_| |_| |_| \______/ \______/ |_| \_\ \/ |_| |_| \_____/ \_\ /_/ |_______|
15*
16*
17*
18*** Copyright 2011 - 2013, m0skVi4a ;]
19*** Plugin created in Rousse, Bulgaria
20*
21*
22*** Plugin thread 1:
23* https://forums.alliedmods.net/showthread.php?t=171460
24*
25*** Plugin thread 2:
26* http://amxmodxbg.org/forum/viewtopic.php?t=37116
27*
28*
29*** Description:
30*
31* This is Register System. You can put a password to your name and if someone connect to the server with the same name he will be kicked if
32
33he does not login.
34*
35*
36*** Commands:
37*
38* say /reg
39* say_team /reg
40* Open the register system menu
41*
42*
43*** CVARS:
44*
45* "rs_on" - Is the plugin on(1) or off(0). Default: 1
46* "rs_save_type" - Where to seve the information: to file(0) or to MySQL(1). Default: 0
47* "rs_remember" - How to remember the players (Registrations, Punishments): by Name(0), by IP(1) or by SteamID(2).
48
49Default: 0
50* "rs_host" - The host for the database. Default: 127.0.0.1
51* "rs_user" - The username for the database login. Default: root
52* "rs_pass" - The password for the database login. Default:
53* "rs_db" - The database name. Default: registersystem
54* "rs_password_prefix" - The prefix of the setinfo for the Auto Login function. Default: _rspass
55* "rs_register_time" - How much time has the client to register. If is set to 0 registration is not mandatory. Default: 0
56* "rs_login_time" - How much time has the client to login if is registered. Default: 60.0
57* "rs_password_len" - What is minimum length of the password. Default: 6
58* "rs_attempts" - How much attempts has the client to login if he type wrong password. Default: 3
59* "rs_chngpass_times" - How much times can the client change his password per map. Default: 3
60* "rs_register_log" - Is it allowed the plugin to log in file when the client is registered. Default: 1
61* "rs_chngpass_log" - Is it allowed the plugin to log in file when the client has change his password. Default: 1
62* "rs_autologin_log" - Is it allowed the plugin to log in file when the client has change his Auto Login function. Default: 1
63* "rs_blind" - Whether clients who have not Logged or who must Register be blinded. Default: 1
64* "rs_commands" - Whether clients who have not Logged or who must Register commands' be blocked: Dissabled(0), Enabled for
65
66all commands(1), Enabled by File or SQL table(2). Default: 1
67* "rs_logout" - What to do when client Logout - kick him from the server(0) or wait to Login during the Login time(1).
68
69Default: 0
70* "rs_count" - Is the countig when you have to register or you have to login on(1) or off(0). Default: 1
71* "rs_advert" - Is the advertisement for not registered players on(1) or off(0). Default: 1
72* "rs_advert_int" - What is the interval between two advertisements in seconds. Default: 60
73* "rs_ajc_team" - Is the Auto Join On Connect option on(1, 2, 5, 6) or off(0). 1 is Terrorists, 2 is Counter-Terrorsits, 6
74
75Spectators, 5 Auto Assign. Default: 0
76* "rs_ajc_class_t" - Which class the Terrorists will be (AJC must be on) - 1 is Terror, 2 is Leet, 3 is Artic, 4 is Guerilla, 5
77
78is Auto Sellect, if it is set to 0 playes can choose which class they wiil be. Default: 5
79* "rs_ajc_class_ct" - Which class the Counter-Terrorists will be (AJC must be on) - 1 is Urban, 2 is GSG-9, 3 is SAS, 4 is GIGN,
80
815 is Auto Sellect, if it is set to 0 playes can choose which class they wiil be. Default: 5
82* "rs_ajc_admin" - Is it allowed players with defined flag (Default: ADMIN_IMMUNITY) can choose in which team will they be
83
84(AJC must be on). Default: 1
85* "rs_ajc_change" - Is it allowed players to change their team(0) or not(1). Default: 0
86* "rs_remember_punish_by" - How to remember the punished players: by Nmae(0), by IP(1) or by SteamID(2). Default: 0
87* "rs_cant_login_time" - How much time in seconds players can't login after typing wrong passwrods. Default: 300
88* "rs_cant_change_pass_time"- How much time in seconds players can't change their paswords after changing it before that. Default: 300
89* "rs_whitelsit" - Whether clients, whose Names are in File or SQL table, must Register(1) or not(0). Default: 1
90*
91* All CVARS are without quotes!
92*
93*
94*** Credits:
95*
96* m0skVi4a ;] - for the idea of the plugin and its creation
97* ConnorMcLeod - for his help to block the name change for logged clients
98* Sylwester - for the idea for the encrypt
99* dark_style - for ideas in the plugin
100* Vasilii-Zaicev - for testing the plugin
101*
102*
103*** Changelog:
104*
105* November 6, 2011 - V1.0 BETA:
106* - First Release
107*
108* November 20, 2011 - V1.1 FINAL
109* - Fixed some bugs
110* - Added change Password function
111* - Added Info/Help
112* - Added cvars to show when the client is registered and change his password
113* - Password are now encrypted for more safety
114*
115* November 23, 2011 - V1.1 FINAL FIX 1
116* - Fixed bug if the client type more than CVAR setted attempts passwords
117*
118* November 28, 2011 - V1.1 FINAL FIX 2
119* - Fixed bug if that the menu does not pop up when user connect
120*
121* December 26, 2011 - V2.0
122* - Fixed bug if player change his name and the system does not check the new name
123* - Added block chooseteam if the client is registered but not logged
124* - Added MySQL support
125* - Added .cfg file to manually set the settings of the system
126* - Added CVAR for setting which clients can change their names
127* - Added auto login on changelevel or client retry
128*
129* December 27, 2011 - V2.0 FIX 1
130* - Fixed bug with the kick function
131*
132* January 3, 2012 - V2.0 FIX 2
133* - Fixed bug with the auto login function that does not work on Steam clients
134*
135* January 24, 2012 - V3.0
136* - Fixed bug with the MYSQL Connection
137* - Added new style of the Change Password function
138* - Removed some CVARs and added new
139* - Now in the Register System file or into MYSQL table is not saving the date and time for registering or for changing password
140
141for the client. They are saving in special log file with name register_system_log.txt
142*
143* February 17, 2012 - V4.0
144* - Fixed some little bugs
145* - Added new style of the main menu
146* - Removed the possibility of SQL Injection
147* - The whole name change function is rewritten
148* - Added option for the not registered and not logged clients to be blinded
149* - Added option for the not registered and not logged clients chat's to be blocked
150* - Added showing information in the consoles of the clients about why they are kicked
151*
152* February 19, 2012 - V4.0 FIX 1
153* - Fixed bug with the join in the Spectator team
154* - Added the Auto Assign option in the main menu
155* - Small rewrite of the Auto Login function
156*
157* March 7, 2012 - V5.0
158* - Fixed bug with % that replace the space in the name of the client
159* - Fixed the bug with the menu that stands when client choose team
160* - Fixed some little bugs
161* - Added new style of the main menu
162*
163* August 4, 2012 - V6.0
164* - Fixed bug which the plugin changes player names sometimes
165* - Fixed bug when the main menu sometimes appears on new round and it can't be choosen an option
166* - Added live counter to count how many seconds does the player has to Login or Register
167* - Added Auto Join On Connect (AJC) options.
168* - Added plugin natives for API plugins
169* - Added Advertisement for players which are not registered
170* - Now the plugin doesn't use the team menu and it can be used in other mods like Zombie Plague
171* - Some functions are rewritten for better work of the plugin
172* - The Optiosn Menu is removed and its options are in the new style Main Menu
173*
174* September 21, 2012 - V7.0
175* - Fixed bug with passwords conflicts
176* - Fixed bug with the Auto Login function
177* - Fixed bug with the Auto join function
178* - Fixed bug with the Name Change function
179* - Added file with listed commands which players can not use until they login
180* - Added reconnect Support for the Login functions
181* - Added reconnect Support for the Change Password function
182* - Added some features for the Auto Join function
183* - Added more stylish way for executing the configuration files
184*
185* October 14, 2012 - V7.0 FIX 1
186* - Fxied bug when player change his name to admin name and hi can register it before hi is kicked
187*
188* January 4, 2013 - V7.0 FIX 2
189* - Fixed bug with the MYSQL part
190* - Fixed bug with the automatic name chage
191* - Small changes of the code
192*
193* June 9, 2013 - V8.0
194* - Fixed bug when HLTV connects and registration is mandatory and the HLTV is kicked
195* - Fixed bug with the configuration file which doesn't set properly some CVARS
196* - Small changes of the code for better work of the plugin
197*
198* November 24, 2013 - V9.0
199* - Added White list for names
200* - Added global advertisements for Registering and Logging
201* - Added option for choosing by what to save the registrations - Name, IP, SteamID
202* - Added CVAR for managing restricted commands to ALL instead of writing them one by one
203*
204*
205*** Contact me on:
206* E-MAIL: pvldimitrov@gmail.com
207* SKYPE: pa7ohin
208*/
209
210#include <amxmodx>
211#include <celltrie>
212#include <cstrike>
213#include <fakemeta>
214#include <hamsandwich>
215#include <sqlx>
216
217
218#define VERSION "9.0"
219#define TASK_MESS 1000
220#define TASK_KICK 2000
221#define TASK_MENU 3000
222#define TASK_TIMER 4000
223#define TASK_ADVERT 5000
224#define TASK_AJC 6000
225#define MENU_TASK_TIME 0.5
226#define AJC_TASK_TIME 0.1
227#define AJC_ADMIN_FLAG ADMIN_IMMUNITY
228#define SALT "8c4f4370c53e0c1e1ae9acd577dddbed"
229#define MAX_NAMES 64
230
231//Start of CVAR pointers
232new g_on;
233new g_save;
234new g_host;
235new g_user;
236new g_pass;
237new g_db;
238new g_setinfo_pr;
239new g_regtime;
240new g_logtime;
241new g_pass_length;
242new g_attempts;
243new g_chp_time;
244new g_reg_log;
245new g_chp_log;
246new g_aulog_log;
247new g_blind;
248new g_comm;
249new g_logout;
250new g_count;
251new g_announce;
252new g_advert;
253new g_advert_int;
254new g_ajc_team;
255new g_ajc_admin;
256new g_ajc_class[2];
257new g_ajc_change;
258new g_member;
259new g_time;
260new g_time_pass;
261new g_whitelist;
262//End of CVAR pointers
263
264//Start of Arrays
265new configs_dir[64]
266new cfg_file[256];
267new reg_file[256];
268new commands_file[256];
269new whitelist_file[256];
270new part_names[MAX_NAMES][32];
271new starting_names[MAX_NAMES][32];
272new ending_names[MAX_NAMES][32];
273new count;
274new sz_time[9];
275new line = 0;
276new text[512];
277new params[2];
278new check_name[32];
279new check_client_data[35];
280new check_pass[34];
281new check_status[11];
282new query[512];
283new Handle:g_sqltuple;
284new password[33][34];
285new typedpass[32];
286new new_pass[33][32];
287new hash[34];
288new pass_prefix[32];
289new attempts[33];
290new times[33];
291new g_player_time[33];
292new g_client_data[33][35];
293new value;
294new menu[512];
295new keys;
296new length;
297new g_maxplayers;
298new g_saytxt
299new g_screenfade
300new g_sync_hud
301new temp1[2];
302new temp2[2];
303new temp_count;
304new type;
305new col_command;
306new col_name;
307new input[32];
308new temp_name[32];
309//End fo Arrays
310
311//Start of Booleans
312new bool:error = false
313new bool:data_ready = false;
314new bool:is_logged[33];
315new bool:is_registered[33];
316new bool:is_autolog[33];
317new bool:cant_change_pass[33];
318new bool:changing_name[33];
319new bool:name_checked[33];
320new bool:is_true = false
321//End of Booleans
322
323//Start of Trie handles
324new Trie:g_commands;
325new Trie:g_login_times;
326new Trie:g_cant_login_time;
327new Trie:g_pass_change_times;
328new Trie:g_cant_change_pass_time;
329new Trie:g_full_nmaes;
330//End of Trie handles
331
332//Start of Constants
333new const separator_1[] = "==============================================================================="
334new const separator_2[] = "-------------------------------------------------------------------------------"
335new const prefix[] = "[REGISTER SYSTEM]";
336new const log_file[] = "register_system_log.txt";
337//new const JOIN_TEAM_MENU_FIRST[] = "#Team_Select";
338//new const JOIN_TEAM_MENU_FIRST_SPEC[] = "#Team_Select_Spect";
339//new const JOIN_TEAM_MENU_INGAME[] = "#IG_Team_Select";
340//new const JOIN_TEAM_MENU_INGAME_SPEC[] = "#IG_Team_Select_Spect";
341new const JOIN_TEAM_VGUI_MENU = 2;
342
343//Start of CVARs
344new const g_cvars[][][] =
345{
346 {"rs_on", "1"},
347 {"rs_save_type", "0"},
348 {"rs_remember", "0"},
349 {"rs_host", "127.0.0.1"},
350 {"rs_user", "root"},
351 {"rs_pass", "123456"},
352 {"rs_db", "registersystem"},
353 {"rs_password_prefix", "_rspass"},
354 {"rs_register_time", "0"},
355 {"rs_login_time", "60.0"},
356 {"rs_password_len", "6"},
357 {"rs_attempts", "3"},
358 {"rs_chngpass_times", "3"},
359 {"rs_register_log", "1"},
360 {"rs_chngpass_log", "1"},
361 {"rs_autologin_log", "1"},
362 {"rs_blind", "1"},
363 {"rs_commands", "1"},
364 {"rs_logout", "0"},
365 {"rs_count", "1"},
366 {"rs_announce", "1"},
367 {"rs_advert", "1"},
368 {"rs_advert_int", "60.0"},
369 {"rs_ajc_team", "0"},
370 {"rs_ajc_class_t", "5"},
371 {"rs_ajc_class_ct", "5"},
372 {"rs_ajc_admin", "1"},
373 {"rs_ajc_change", "0"},
374 {"rs_cant_login_time", "300"},
375 {"rs_cant_change_pass_time", "300"},
376 {"rs_whitelist", "1"}
377};//End of CVARs
378//End of Constants
379
380/*==============================================================================
381 Start of Plugin Init
382================================================================================*/
383public plugin_init()
384{
385 register_plugin("Register System", VERSION, "m0skVi4a ;]")
386
387 g_on = register_cvar(g_cvars[0][0], g_cvars[0][1])
388 g_save = register_cvar(g_cvars[1][0], g_cvars[1][1])
389 g_member = register_cvar(g_cvars[2][0], g_cvars[2][1])
390 g_host = register_cvar(g_cvars[3][0], g_cvars[3][1])
391 g_user = register_cvar(g_cvars[4][0], g_cvars[4][1])
392 g_pass = register_cvar(g_cvars[5][0], g_cvars[5][1])
393 g_db = register_cvar(g_cvars[6][0], g_cvars[6][1])
394 g_setinfo_pr = register_cvar(g_cvars[7][0], g_cvars[7][1])
395 g_regtime = register_cvar(g_cvars[8][0], g_cvars[8][1])
396 g_logtime = register_cvar(g_cvars[9][0], g_cvars[9][1])
397 g_pass_length = register_cvar(g_cvars[10][0], g_cvars[10][1])
398 g_attempts = register_cvar(g_cvars[11][0], g_cvars[11][1])
399 g_chp_time = register_cvar(g_cvars[12][0], g_cvars[12][1])
400 g_reg_log = register_cvar(g_cvars[13][0], g_cvars[13][1])
401 g_chp_log = register_cvar(g_cvars[14][0], g_cvars[14][1])
402 g_aulog_log = register_cvar(g_cvars[15][0], g_cvars[15][1])
403 g_blind = register_cvar(g_cvars[16][0], g_cvars[16][1])
404 g_comm = register_cvar(g_cvars[17][0], g_cvars[17][1])
405 g_logout = register_cvar(g_cvars[18][0], g_cvars[18][1])
406 g_count = register_cvar(g_cvars[19][0], g_cvars[19][1])
407 g_announce = register_cvar(g_cvars[20][0], g_cvars[20][1])
408 g_advert = register_cvar(g_cvars[21][0], g_cvars[21][1])
409 g_advert_int = register_cvar(g_cvars[22][0], g_cvars[22][1])
410 g_ajc_team = register_cvar(g_cvars[23][0], g_cvars[23][1])
411 g_ajc_class[0] = register_cvar(g_cvars[24][0], g_cvars[24][1])
412 g_ajc_class[1] = register_cvar(g_cvars[25][0], g_cvars[25][1])
413 g_ajc_admin = register_cvar(g_cvars[26][0], g_cvars[26][1])
414 g_ajc_change = register_cvar(g_cvars[27][0], g_cvars[27][1])
415 g_time = register_cvar(g_cvars[28][0], g_cvars[28][1])
416 g_time_pass = register_cvar(g_cvars[29][0], g_cvars[29][1])
417 g_whitelist = register_cvar(g_cvars[30][0], g_cvars[30][1])
418
419 get_localinfo("amxx_configsdir", configs_dir, charsmax(configs_dir))
420 formatex(cfg_file, charsmax(cfg_file), "%s/registersystem.cfg", configs_dir)
421 formatex(reg_file, charsmax(reg_file), "%s/regusers.ini", configs_dir)
422 formatex(commands_file, charsmax(commands_file), "%s/registersystem_commands.ini", configs_dir)
423 formatex(whitelist_file, charsmax(whitelist_file), "%s/registersystem_whitelist.ini", configs_dir)
424
425 register_message(get_user_msgid("ShowMenu"), "TextMenu")
426 register_message(get_user_msgid("VGUIMenu"), "VGUIMenu")
427 register_menucmd(register_menuid("Register System Main Menu"), 1023, "HandlerMainMenu")
428 register_menucmd(register_menuid("Password Menu"), 1023, "HandlerConfirmPasswordMenu")
429 register_clcmd("jointeam", "HookTeamCommands")
430 register_clcmd("chooseteam", "HookTeamCommands")
431 register_clcmd("LOGIN_PASS", "Login")
432 register_clcmd("REGISTER_PASS", "Register")
433 register_clcmd("CHANGE_PASS_NEW", "ChangePasswordNew")
434 register_clcmd("CHANGE_PASS_OLD", "ChangePasswordOld")
435 register_clcmd("AUTO_LOGIN_PASS", "AutoLoginPassword")
436 RegisterHam(Ham_Spawn, "player", "HookPlayerSpawn", 1)
437 register_forward(FM_PlayerPreThink, "PlayerPreThink")
438 register_forward(FM_ClientUserInfoChanged, "ClientInfoChanged")
439
440 register_dictionary("register_system.txt")
441 g_maxplayers = get_maxplayers()
442 g_saytxt = get_user_msgid("SayText")
443 g_screenfade = get_user_msgid("ScreenFade")
444 g_sync_hud = CreateHudSyncObj()
445 g_commands = TrieCreate()
446 g_login_times = TrieCreate()
447 g_cant_login_time = TrieCreate()
448 g_pass_change_times = TrieCreate()
449 g_cant_change_pass_time = TrieCreate()
450 g_full_nmaes = TrieCreate()
451}
452/*==============================================================================
453 End of Plugin Init
454================================================================================*/
455
456/*==============================================================================
457 Start of Plugin Natives
458================================================================================*/
459public plugin_natives()
460{
461 register_library("register_system")
462 register_native("is_registered", "_is_registered")
463 register_native("is_logged", "_is_logged")
464 register_native("is_autologged", "_is_autologged")
465 register_native("get_cant_login_time", "_get_cant_login_time")
466 register_native("get_cant_change_pass_time", "_get_cant_change_pass_time")
467}
468
469public _is_registered(plugin, parameters)
470{
471 if(parameters != 1)
472 return false
473
474 new id = get_param(1)
475
476 if(!id)
477 return false
478
479 if(is_registered[id])
480 {
481 return true
482 }
483
484 return false
485}
486
487public _is_logged(plugin, parameters)
488{
489 if(parameters != 1)
490 return false
491
492 new id = get_param(1)
493
494 if(!id)
495 return false
496
497 if(is_logged[id])
498 {
499 return true
500 }
501
502 return false
503}
504
505public _is_autologged(plugin, parameters)
506{
507 if(parameters != 1)
508 return -1
509
510 new id = get_param(1)
511
512 if(!id)
513 return -1
514
515 if(is_autolog[id])
516 {
517 return true
518 }
519
520 return false
521}
522
523public _get_cant_login_time(plugin, parameters)
524{
525 if(parameters != 1)
526 return -1
527
528 new id = get_param(1)
529
530 if(!id)
531 return -1
532
533 new data[35];
534
535 switch(get_pcvar_num(g_member))
536 {
537 case 0:
538 {
539 get_user_name(id, data, charsmax(data))
540 }
541 case 1:
542 {
543 get_user_ip(id, data, charsmax(data))
544 }
545 case 2:
546 {
547 get_user_authid(id, data, charsmax(data))
548 }
549 default:
550 {
551 get_user_name(id, data, charsmax(data))
552 }
553 }
554
555 if(TrieGetCell(g_cant_login_time, data, value))
556 {
557 new cal_time = get_pcvar_num(g_time) - (time() - value)
558 return cal_time
559 }
560
561 return -1
562}
563
564public _get_cant_change_pass_time(plugin, parameters)
565{
566 if(parameters != 1)
567 return -1
568
569 new id = get_param(1)
570
571 if(!id)
572 return -1
573
574 new data[35];
575
576 switch(get_pcvar_num(g_member))
577 {
578 case 0:
579 {
580 get_user_name(id, data, charsmax(data))
581 }
582 case 1:
583 {
584 get_user_ip(id, data, charsmax(data))
585 }
586 case 2:
587 {
588 get_user_authid(id, data, charsmax(data))
589 }
590 default:
591 {
592 get_user_name(id, data, charsmax(data))
593 }
594 }
595
596 if(TrieGetCell(g_cant_change_pass_time, data, value))
597 {
598 new cal_time = get_pcvar_num(g_time_pass) - (time() - value)
599 return cal_time
600 }
601
602 return -1
603}
604/*==============================================================================
605 End of Plugin Natives
606================================================================================*/
607
608/*==============================================================================
609 Start of Executing plugin's config and choose the save mode
610================================================================================*/
611public plugin_cfg()
612{
613 if(!get_pcvar_num(g_on))
614 return PLUGIN_HANDLED
615
616 server_print(" ")
617 server_print(separator_1)
618 server_print("Title : Register System")
619 server_print("Version : %s", VERSION)
620 server_print("Author : m0skVi4a ;]")
621 server_print("Site : https://forums.alliedmods.net/showthread.php?t=171460")
622 server_print(separator_2)
623
624 get_time("%H:%M:%S", sz_time, charsmax(sz_time))
625
626 if(!file_exists(cfg_file))
627 {
628 server_print("[%s] [ERROR] > File registersystem.cfg not found!", sz_time)
629 error = true
630 }
631 else
632 {
633 server_print("[%s] > Loading settings from registersystem.cfg", sz_time)
634
635 line = 0, length = 0, count = 0, error = false;
636
637 while(read_file(cfg_file, line++ , text, charsmax(text), length))
638 {
639 if(!text[0] || text[0] == '^n' || text[0] == ';' || (text[0] == '/' && text[1] == '/'))
640 continue
641
642 new cvar[32], param[32], bool:error_1 = true, bool:error_2 = true
643
644 trim(text)
645 parse(text, cvar, charsmax(cvar), param, charsmax(param))
646
647 for(new i = 0; i <= charsmax(g_cvars); i++)
648 {
649 if(equal(cvar, g_cvars[i][0]))
650 {
651 error_1 = false
652 }
653 }
654
655 if(param[0] && !(equali(param, " ")))
656 {
657 error_2 = false
658 }
659
660 if(error_1)
661 {
662 server_print("[%s] [ERROR] > Unknown CVAR ^"%s^"", sz_time, cvar)
663 error = true
664 }
665 else
666 {
667 if(error_2)
668 {
669 server_print("[%s] [ERROR] > Bad value for ^"%s^"", sz_time, cvar)
670 error = true
671 }
672 else
673 {
674 server_print("[%s] [OK] > Read cvar ^"%s^" ^"%s^"", sz_time, cvar, param)
675 server_cmd("%s %s", cvar, param)
676 count++
677 }
678 }
679 }
680
681 if(!count)
682 {
683 server_print("[%s] [ERROR] > There were no CVARs in registersystem.cfg", sz_time)
684 error = true
685 }
686 }
687
688 server_print(separator_2)
689
690 if(error)
691 {
692 server_print("[%s] [WARNING] > Reading some data from configuration file failed!", sz_time)
693 server_print("> Please check [ERROR] messages above for solving this problem!")
694 }
695 else
696 {
697 server_print("[%s] [OK] > All settings loaded successfully!", sz_time)
698 }
699
700 server_print(separator_1)
701 server_print(" ")
702
703 set_task(1.0, "LoadData")
704
705 return PLUGIN_CONTINUE
706}
707
708public LoadData()
709{
710 if(get_pcvar_num(g_save))
711 {
712 Init_MYSQL()
713 return
714 }
715 else
716 {
717 if(!file_exists(reg_file))
718 {
719 write_file(reg_file,";Register System file^n;Modifying may cause the clients to can not Login!^n^n")
720 server_print("%s Could not find Register System file - %s Creating new...", prefix, reg_file)
721 }
722 }
723
724 if(get_pcvar_num(g_comm) == 1)
725 {
726 line = 0, length = 0, count = 0, error = false;
727 get_time("%H:%M:%S", sz_time, charsmax(sz_time))
728
729 server_print(" ")
730 server_print(separator_1)
731 server_print(prefix)
732 server_print(separator_2)
733
734 if(!file_exists(commands_file))
735 {
736 server_print("[%s] [ERROR] > File registersystem_commands.ini not found!", sz_time)
737 error = true
738 }
739 else
740 {
741 server_print("[%s] > Loading settings from registersystem_commands.ini", sz_time)
742
743 line = 0, length = 0, count = 0;
744
745 while(read_file(commands_file, line++ , text, charsmax(text), length))
746 {
747 if(!text[0] || text[0] == '^n' || text[0] == ';' || (text[0] == '/' && text[1] == '/'))
748 continue
749
750 trim(text)
751 parse(text, text, charsmax(text))
752
753 TrieSetCell(g_commands, text, 1)
754 count++
755 }
756
757 if(count)
758 {
759 server_print("[%s] [OK] > %d command%s loaded!", sz_time, count, count > 1 ? "s" : "")
760 }
761 else
762 {
763 server_print("[%s] [ERROR] > There were no commands in registersystem_commands.ini", sz_time)
764 error = true
765 }
766 }
767
768 server_print(separator_2)
769
770 if(error)
771 {
772 server_print("[%s] [WARNING] > Reading some data from commands file failed!", sz_time)
773 server_print("> Please check [ERROR] messages above for solving this problem!")
774 }
775 else
776 {
777 server_print("[%s] [OK] > Commands file loaded successfully!", sz_time)
778 }
779
780 server_print(separator_1)
781 server_print(" ")
782 }
783
784 if(get_pcvar_num(g_whitelist))
785 {
786 line = 0, length = 0, count = 0, error = false;
787 get_time("%H:%M:%S", sz_time, charsmax(sz_time))
788
789 server_print(" ")
790 server_print(separator_1)
791 server_print(prefix)
792 server_print(separator_2)
793
794 if(!file_exists(whitelist_file))
795 {
796 server_print("[%s] [ERROR] > File registersystem_whitelist.ini not found!", sz_time)
797 error = true
798 }
799 else
800 {
801 server_print("[%s] > Loading settings from registersystem_whitelist.ini", sz_time)
802
803 line = 0, length = 0, count = 0, error = false;
804 new t_text[32];
805 new count1 = 0, count2 = 0, count3 = 0, count4 = 0
806
807 while(read_file(whitelist_file, line++ , t_text, charsmax(t_text), length))
808 {
809 if(!t_text[0] || t_text[0] == '^n' || t_text[0] == ';' || (t_text[0] == '/' && t_text[1] == '/'))
810 continue
811
812 trim(t_text)
813 parse(t_text, t_text, charsmax(t_text))
814
815 if(t_text[0] == '%')
816 {
817 if(t_text[strlen(t_text) - 1] == '%') //Part name
818 {
819 if(count1 >= MAX_NAMES)
820 continue
821
822 replace_all(t_text, charsmax(t_text), "%", "")
823 part_names[count1++] = t_text
824 }
825 else //Ending name
826 {
827 if(count2 >= MAX_NAMES)
828 continue
829
830 replace_all(t_text, charsmax(t_text), "%", "")
831 ending_names[count2++] = t_text
832 }
833 }
834 else // Starting name
835 {
836 if(t_text[strlen(t_text) - 1] == '%')
837 {
838 if(count3 >= MAX_NAMES)
839 continue
840
841 replace_all(t_text, charsmax(t_text), "%", "")
842 starting_names[count3++] = t_text
843 }
844 else //Full name
845 {
846 if(++count4 >= MAX_NAMES)
847 continue
848
849 replace_all(t_text, charsmax(t_text), "%", "")
850 TrieSetCell(g_full_nmaes, t_text, 1)
851 }
852 }
853
854 count++
855 }
856
857 if(count)
858 {
859 server_print("[%s] [OK] > %d name%s loaded!", sz_time, count, count > 1 ? "s" : "")
860 }
861 else
862 {
863 server_print("[%s] [ERROR] > There were no names in registersystem_whitelist.ini", sz_time)
864 error = true
865 }
866 }
867
868 if(error)
869 {
870 server_print("[%s] [WARNING] > Reading some data from whitelist file failed!", sz_time)
871 server_print("> Please check [ERROR] messages above for solving this problem!")
872 }
873 else
874 {
875 server_print("[%s] [OK] > Whitelist file loaded successfully!", sz_time)
876 }
877
878 server_print(separator_1)
879 server_print(" ")
880 }
881
882 data_ready = true
883
884 for(new i = 1 ; i <= g_maxplayers ; i++)
885 {
886 if(!is_user_connecting(i) && !is_user_connected(i))
887 continue
888
889 if(get_pcvar_num(g_whitelist))
890 {
891 CheckName(i)
892 }
893 else
894 {
895 CheckClient(i)
896 }
897 }
898}
899
900public Init_MYSQL()
901{
902 new host[64], user[32], pass[32], db[128];
903
904 get_pcvar_string(g_host, host, charsmax(host))
905 get_pcvar_string(g_user, user, charsmax(user))
906 get_pcvar_string(g_pass, pass, charsmax(pass))
907 get_pcvar_string(g_db, db, charsmax(db))
908
909 g_sqltuple = SQL_MakeDbTuple(host, user, pass, db)
910 formatex(query, charsmax(query), "CREATE TABLE IF NOT EXISTS registersystem (Name VARCHAR(35), Password VARCHAR(34), Status VARCHAR(10)) ;
911
912CREATE TABLE IF NOT EXISTS rs_commands (Command VARCHAR(64)) ; CREATE TABLE IF NOT EXISTS rs_names (Names VARCHAR(64))")
913 SQL_ThreadQuery(g_sqltuple, "QueryCreateTable", query)
914}
915
916public QueryCreateTable(failstate, Handle:query1, error[], errcode, data[], datasize, Float:queuetime)
917{
918 if(failstate == TQUERY_CONNECT_FAILED)
919 {
920 set_fail_state("[REGISTER SYSTEM] Could not connect to database!")
921 }
922 else if(failstate == TQUERY_QUERY_FAILED)
923 {
924 set_fail_state("[REGISTER SYSTEM] Query failed!")
925 }
926 else if(errcode)
927 {
928 server_print("%s Error on query: %s", prefix, error)
929 }
930 else
931 {
932 server_print("%s MYSQL connection succesful!", prefix)
933
934 new data[1];
935
936 if(get_pcvar_num(g_comm) == 1)
937 {
938 data[0] = 0
939 formatex(query, charsmax(query), "SELECT * FROM `rs_commands`;")
940 SQL_ThreadQuery(g_sqltuple, "QueryCollectData", query, data, 1)
941 }
942
943 if(get_pcvar_num(g_whitelist))
944 {
945 data[0] = 1
946 formatex(query, charsmax(query), "SELECT * FROM `rs_names`;")
947 SQL_ThreadQuery(g_sqltuple, "QueryCollectData", query, data, 1)
948 }
949 else
950 {
951 data_ready = true
952
953 for(new i = 1 ; i <= g_maxplayers ; i++)
954 {
955 if(!is_user_connecting(i) && !is_user_connected(i))
956 continue
957
958 if(get_pcvar_num(g_whitelist))
959 {
960 CheckName(i)
961 }
962 else
963 {
964 CheckClient(i)
965 }
966 }
967 }
968 }
969}
970
971public QueryCollectData(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
972{
973 if(failstate == TQUERY_CONNECT_FAILED || failstate == TQUERY_QUERY_FAILED)
974 {
975 log_amx("%s", error)
976 return
977 }
978 else
979 {
980 type = data[0]
981 get_time("%H:%M:%S", sz_time, charsmax(sz_time))
982
983 if(!type)
984 {
985 count = 0
986 col_command = SQL_FieldNameToNum(query, "Command")
987
988 server_print(" ")
989 server_print(separator_1)
990 server_print(prefix)
991 server_print(separator_2)
992 server_print("[%s] > Loading SQL table ^"rs_commands^"", sz_time)
993
994 while(SQL_MoreResults(query))
995 {
996 SQL_ReadResult(query, col_command, input, charsmax(input))
997 TrieSetCell(g_commands, input, 1)
998 count++
999 SQL_NextRow(query)
1000 }
1001
1002 if(count)
1003 {
1004 server_print("[%s] [OK] > %d command%s loaded!", sz_time, count, count > 1 ? "s" : "")
1005 server_print("[%s] [OK] > SQL table ^"rs_commands^" loaded successfully!", sz_time)
1006 }
1007 else
1008 {
1009 server_print("[%s] [ERROR] > There were no commands in SQL table ^"rs_commands^"", sz_time)
1010 server_print("[%s] [WARNING] > Reading some data from the table failed!", sz_time)
1011 server_print("> Please check [ERROR] messages above for solving this problem!")
1012 }
1013
1014 server_print(separator_1)
1015 server_print(" ")
1016 }
1017 else
1018 {
1019 new count1 = 0, count2 = 0, count3 = 0, count4 = 0
1020 count = 0
1021 col_name = SQL_FieldNameToNum(query, "Names")
1022
1023 server_print(" ")
1024 server_print(separator_1)
1025 server_print(prefix)
1026 server_print(separator_2)
1027 server_print("[%s] > Loading SQL table ^"rs_names^"", sz_time)
1028
1029 while(SQL_MoreResults(query))
1030 {
1031 SQL_ReadResult(query, col_name, input, charsmax(input))
1032
1033 if(input[0] == '%')
1034 {
1035 if(input[strlen(input) - 1] == '%') //Part name
1036 {
1037 if(count1 >= MAX_NAMES)
1038 continue
1039
1040 replace_all(input, charsmax(input), "%", "")
1041 part_names[count1++] = input
1042 }
1043 else // Starting name
1044 {
1045 if(count2 >= MAX_NAMES)
1046 continue
1047
1048 replace_all(input, charsmax(input), "%", "")
1049 ending_names[count2++] = input
1050 }
1051 }
1052 else
1053 {
1054 if(input[strlen(input) - 1] == '%') //Ending name
1055 {
1056 if(count3 >= MAX_NAMES)
1057 continue
1058
1059 replace_all(input, charsmax(input), "%", "")
1060 starting_names[count3++] = input
1061 }
1062 else //Full name
1063 {
1064 if(++count4 >= MAX_NAMES)
1065 continue
1066
1067 replace_all(input, charsmax(input), "%", "")
1068 TrieSetCell(g_full_nmaes, input, 1)
1069 }
1070 }
1071
1072 count++
1073 SQL_NextRow(query)
1074 }
1075
1076
1077 if(count)
1078 {
1079 server_print("[%s] [OK] > %d name%s loaded!", sz_time, count, count > 1 ? "s" : "")
1080 server_print("[%s] [OK] > SQL table ^"rs_names^" loaded successfully!", sz_time)
1081 }
1082 else
1083 {
1084 server_print("[%s] [ERROR] > There were no names in SQL table ^"rs_names^"", sz_time)
1085 server_print("[%s] [WARNING] > Reading some data from the table failed!", sz_time)
1086 server_print("> Please check [ERROR] messages above for solving this problem!")
1087 }
1088
1089 server_print(separator_1)
1090 server_print(" ")
1091
1092 data_ready = true
1093
1094 for(new i = 1 ; i <= g_maxplayers ; i++)
1095 {
1096 if(!is_user_connecting(i) && !is_user_connected(i))
1097 continue
1098
1099 if(get_pcvar_num(g_whitelist))
1100 {
1101 CheckName(i)
1102 }
1103 else
1104 {
1105 CheckClient(i)
1106 }
1107 }
1108 }
1109 }
1110}
1111/*==============================================================================
1112 End of Executing plugin's config and choose the save mode
1113================================================================================*/
1114
1115/*==============================================================================
1116 Start of plugin's end function
1117================================================================================*/
1118public plugin_end()
1119{
1120 TrieDestroy(g_commands)
1121 TrieDestroy(g_login_times)
1122 TrieDestroy(g_cant_login_time)
1123 TrieDestroy(g_pass_change_times)
1124 TrieDestroy(g_cant_change_pass_time)
1125}
1126/*==============================================================================
1127 End of plugin's end function
1128================================================================================*/
1129
1130/*==============================================================================
1131 Start of Client's connect and disconenct functions
1132================================================================================*/
1133public client_authorized(id)
1134{
1135 clear_user(id)
1136 remove_tasks(id)
1137
1138 switch(get_pcvar_num(g_member))
1139 {
1140 case 0:
1141 {
1142 get_user_name(id, g_client_data[id], charsmax(g_client_data))
1143 }
1144 case 1:
1145 {
1146 get_user_ip(id, g_client_data[id], charsmax(g_client_data), 1)
1147 }
1148 case 2:
1149 {
1150 get_user_authid(id, g_client_data[id], charsmax(g_client_data))
1151 }
1152 default:
1153 {
1154 get_user_name(id, g_client_data[id], charsmax(g_client_data))
1155 }
1156 }
1157
1158 if(TrieGetCell(g_login_times, g_client_data[id], value))
1159 {
1160 attempts[id] = value
1161
1162 if(attempts[id] >= get_pcvar_num(g_attempts))
1163 {
1164 params[0] = id
1165 params[1] = 3
1166 set_task(1.0, "KickPlayer", id+TASK_KICK, params, sizeof params)
1167 }
1168 }
1169
1170 if(TrieGetCell(g_pass_change_times, g_client_data[id], value))
1171 {
1172 times[id] = value
1173
1174 if(times[id] >= get_pcvar_num(g_chp_time))
1175 {
1176 cant_change_pass[id] = true
1177 }
1178 }
1179
1180 if(data_ready)
1181 {
1182 if(get_pcvar_num(g_whitelist))
1183 {
1184 CheckName(id)
1185 }
1186 else
1187 {
1188 CheckClient(id)
1189 }
1190 }
1191}
1192
1193public client_putinserver(id)
1194{
1195 if(data_ready && name_checked[id])
1196 {
1197 ShowMsg(id)
1198
1199 if(get_pcvar_num(g_advert) && get_pcvar_num(g_advert_int))
1200 {
1201 set_task(get_pcvar_float(g_advert_int), "ShowAdvert", id+TASK_ADVERT)
1202 }
1203 }
1204}
1205
1206public client_disconnect(id)
1207{
1208 clear_user(id)
1209 remove_tasks(id)
1210}
1211/*==============================================================================
1212 End of Client's connect and disconenct functions
1213================================================================================*/
1214
1215/*==============================================================================
1216 Start of Check Client functions
1217================================================================================*/
1218public CheckName(id)
1219{
1220 if(!get_pcvar_num(g_on) || is_user_bot(id) || is_user_hltv(id) || !data_ready)
1221 return PLUGIN_HANDLED
1222
1223 get_user_name(id, check_name, charsmax(check_name))
1224
1225 if(TrieGetCell(g_full_nmaes, check_name, value))
1226 {
1227 name_checked[id] = false
1228 return PLUGIN_CONTINUE
1229 }
1230
1231 for(new i = 0 ; i <= charsmax(part_names) ;i++)
1232 {
1233 if(containi(check_name, part_names[i]) != -1)
1234 {
1235 name_checked[id] = false
1236 return PLUGIN_CONTINUE
1237 }
1238 }
1239
1240 for(new i = 0 ; i <= charsmax(starting_names) ; i++)
1241 {
1242 is_true = false
1243
1244 for(new j = 0 ; j <= strlen(starting_names[i]) - 1 ; j++)
1245 {
1246 formatex(temp1, charsmax(temp1), "%c", starting_names[i][j])
1247 formatex(temp2, charsmax(temp2), "%c", check_name[j])
1248
1249 if(equali(temp1, temp2))
1250 {
1251 is_true = true
1252 }
1253 else
1254 {
1255 is_true = false
1256 break
1257 }
1258 }
1259
1260 if(is_true)
1261 {
1262 name_checked[id] = false
1263 return PLUGIN_CONTINUE
1264 }
1265 }
1266
1267 for(new i = 0 ; i <= charsmax(ending_names) ; i++)
1268 {
1269 is_true = false
1270
1271 if(!(strlen(check_name) >= strlen(ending_names[i])))
1272 continue
1273
1274 temp_count = strlen(check_name) - strlen(ending_names[i])
1275
1276 for(new j = strlen(ending_names[i]) - 1 ; j >= 0 ; j--)
1277 {
1278 formatex(temp1, charsmax(temp1), "%c", ending_names[i][j])
1279 formatex(temp2, charsmax(temp2), "%c", check_name[j + temp_count])
1280
1281 if(equali(temp1, temp2))
1282 {
1283 is_true = true
1284 }
1285 else
1286 {
1287 is_true = false
1288 break
1289 }
1290 }
1291
1292 if(is_true)
1293 {
1294 name_checked[id] = false
1295 return PLUGIN_CONTINUE
1296 }
1297 }
1298
1299 name_checked[id] = true
1300 CheckClient(id)
1301 return PLUGIN_CONTINUE
1302}
1303
1304public CheckClient(id)
1305{
1306 if(!get_pcvar_num(g_on) || is_user_bot(id) || is_user_hltv(id) || !data_ready || !name_checked[id])
1307 return PLUGIN_HANDLED
1308
1309 remove_tasks(id)
1310 is_registered[id] = false
1311 is_logged[id] = false
1312 is_autolog[id] = false
1313
1314 switch(get_pcvar_num(g_member))
1315 {
1316 case 0:
1317 {
1318 get_user_name(id, g_client_data[id], charsmax(g_client_data))
1319 }
1320 case 1:
1321 {
1322 get_user_ip(id, g_client_data[id], charsmax(g_client_data), 1)
1323 }
1324 case 2:
1325 {
1326 get_user_authid(id, g_client_data[id], charsmax(g_client_data))
1327 }
1328 default:
1329 {
1330 get_user_name(id, g_client_data[id], charsmax(g_client_data))
1331 }
1332 }
1333
1334 if(get_pcvar_num(g_save))
1335 {
1336 new data[1]
1337 data[0] = id
1338
1339 formatex(query, charsmax(query), "SELECT `Password`, `Status` FROM `registersystem` WHERE Name = ^"%s^";", g_client_data[id])
1340
1341 SQL_ThreadQuery(g_sqltuple, "QuerySelectData", query, data, 1)
1342 }
1343 else
1344 {
1345 line = 0, length = 0;
1346
1347 while(read_file(reg_file, line++ , text, charsmax(text), length))
1348 {
1349 if(!text[0] || text[0] == '^n' || text[0] == ';' || (text[0] == '/' && text[1] == '/'))
1350 continue
1351
1352 parse(text, check_client_data, charsmax(check_client_data), check_pass, charsmax(check_pass), check_status, charsmax
1353
1354(check_status))
1355
1356 if(!(equal(check_client_data, g_client_data[id])))
1357 continue
1358
1359 is_registered[id] = true
1360 password[id] = check_pass
1361
1362 if(equal(check_status, "LOGGED_IN"))
1363 {
1364 is_autolog[id] = true
1365 CheckAutoLogin(id)
1366 }
1367
1368 if(is_user_connected(id))
1369 {
1370 user_silentkill(id)
1371 cs_set_user_team(id, CS_TEAM_UNASSIGNED)
1372 ShowMsg(id)
1373
1374 if(get_pcvar_num(g_advert) && get_pcvar_num(g_advert_int))
1375 {
1376 set_task(get_pcvar_float(g_advert_int), "ShowAdvert", id+TASK_ADVERT)
1377 }
1378 }
1379
1380 break
1381 }
1382 }
1383 return PLUGIN_CONTINUE
1384}
1385
1386public QuerySelectData(FailState, Handle:Query, error[], errorcode, data[], datasize, Float:fQueueTime)
1387{
1388 if(FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED)
1389 {
1390 log_amx("%s", error)
1391 return
1392 }
1393 else
1394 {
1395 new id = data[0];
1396 new col_pass = SQL_FieldNameToNum(Query, "Password")
1397 new col_status = SQL_FieldNameToNum(Query, "Status")
1398
1399 while(SQL_MoreResults(Query))
1400 {
1401 SQL_ReadResult(Query, col_pass, check_pass, charsmax(check_pass))
1402 SQL_ReadResult(Query, col_status, check_status, charsmax(check_status))
1403 is_registered[id] = true
1404 password[id] = check_pass
1405
1406 if(equal(check_status, "LOGGED_IN"))
1407 {
1408 is_autolog[id] = true
1409 CheckAutoLogin(id)
1410 }
1411
1412 if(is_user_connected(id))
1413 {
1414 user_silentkill(id)
1415 cs_set_user_team(id, CS_TEAM_UNASSIGNED)
1416 ShowMsg(id)
1417
1418 if(get_pcvar_num(g_advert) && get_pcvar_num(g_advert_int))
1419 {
1420 set_task(get_pcvar_float(g_advert_int), "ShowAdvert", id+TASK_ADVERT)
1421 }
1422 }
1423
1424 SQL_NextRow(Query)
1425 }
1426 }
1427}
1428
1429public CheckAutoLogin(id)
1430{
1431 new client_password[32];
1432
1433 get_pcvar_string(g_setinfo_pr, pass_prefix, charsmax(pass_prefix))
1434 get_user_info(id, pass_prefix, client_password, charsmax(client_password))
1435 hash = convert_password(client_password)
1436
1437 if(equal(hash, password[id]))
1438 {
1439 is_logged[id] = true
1440 }
1441 else
1442 {
1443 is_autolog[id] = false
1444 }
1445}
1446/*==============================================================================
1447 End of Check Client functions
1448================================================================================*/
1449
1450/*==============================================================================
1451 Start of Show Client's informative messages
1452================================================================================*/
1453public ShowMsg(id)
1454{
1455 if(!get_pcvar_num(g_on))
1456 return PLUGIN_HANDLED
1457
1458 remove_tasks(id)
1459
1460 set_task(5.0, "Messages", id+TASK_MESS)
1461
1462 params[0] = id
1463
1464 if(!is_registered[id])
1465 {
1466 if(get_pcvar_float(g_regtime) != 0)
1467 {
1468 if(!changing_name[id])
1469 {
1470 CreateMainMenuTask(id+TASK_MENU)
1471
1472 if(get_pcvar_num(g_count))
1473 {
1474 g_player_time[id] = get_pcvar_num(g_regtime)
1475 ShowTimer(id+TASK_TIMER)
1476 }
1477 params[1] = 1
1478 set_task(get_pcvar_float(g_regtime) + 3, "KickPlayer", id+TASK_KICK, params, sizeof params)
1479 return PLUGIN_HANDLED
1480 }
1481 else
1482 {
1483 g_player_time[id] = -1
1484 set_task(1.0, "ShowTimer", id+TASK_TIMER)
1485 }
1486 }
1487 }
1488 else if(!is_logged[id])
1489 {
1490 if(!changing_name[id])
1491 {
1492 CreateMainMenuTask(id+TASK_MENU)
1493
1494 if(get_pcvar_num(g_count))
1495 {
1496 g_player_time[id] = get_pcvar_num(g_logtime)
1497 ShowTimer(id+TASK_TIMER)
1498 }
1499 params[1] = 2
1500 set_task(get_pcvar_float(g_logtime) + 3, "KickPlayer", id+TASK_KICK, params, sizeof params)
1501 return PLUGIN_HANDLED
1502 }
1503 else
1504 {
1505 g_player_time[id] = -1
1506 set_task(1.0, "ShowTimer", id+TASK_TIMER)
1507 }
1508 }
1509 return PLUGIN_CONTINUE
1510}
1511
1512public ShowTimer(id)
1513{
1514 id -= TASK_TIMER
1515
1516 if(!is_user_connected(id))
1517 return PLUGIN_HANDLED
1518
1519 switch(g_player_time[id])
1520 {
1521 case 10..19:
1522 {
1523 set_hudmessage(255, 255, 0, -1.0, -1.0, 0, 0.02, 1.0,_,_, -1)
1524 }
1525 case 0..9:
1526 {
1527 set_hudmessage(255, 0, 0, -1.0, -1.0, 1, 0.02, 1.0,_,_, -1)
1528 }
1529 case -1:
1530 {
1531 set_hudmessage(255, 255, 255, -1.0, -1.0, 1, 0.02, 1.0,_,_, -1)
1532 }
1533 default:
1534 {
1535 set_hudmessage(0, 255, 0, -1.0, -1.0, 0, 0.02, 1.0,_,_, -1)
1536 }
1537 }
1538
1539 if(g_player_time[id] == 0)
1540 {
1541 ShowSyncHudMsg(id, g_sync_hud, "%L", LANG_SERVER, "KICK_HUD")
1542 return PLUGIN_CONTINUE
1543 }
1544 else if(!is_registered[id] && get_pcvar_float(g_regtime))
1545 {
1546 if(g_player_time[id] == -1)
1547 {
1548 ShowSyncHudMsg(id, g_sync_hud, "%L", LANG_SERVER, "REGISTER_AFTER")
1549 set_task(1.0, "ShowTimer", id+TASK_TIMER)
1550 return PLUGIN_HANDLED
1551 }
1552
1553 ShowSyncHudMsg(id, g_sync_hud, "%L", LANG_SERVER, g_player_time[id] > 1 ? "REGISTER_HUD" : "REGISTER_HUD_SEC", g_player_time[id])
1554 }
1555 else if(is_registered[id] && !is_logged[id])
1556 {
1557 if(g_player_time[id] == -1)
1558 {
1559 ShowSyncHudMsg(id, g_sync_hud, "%L", LANG_SERVER, "LOGIN_AFTER")
1560 set_task(1.0, "ShowTimer", id+TASK_TIMER)
1561 return PLUGIN_HANDLED
1562 }
1563
1564 ShowSyncHudMsg(id, g_sync_hud, "%L ", LANG_SERVER, g_player_time[id] > 1 ? "LOGIN_HUD" : "LOGIN_HUD_SEC", g_player_time[id])
1565 }
1566 else return PLUGIN_HANDLED
1567
1568 g_player_time[id]--
1569
1570 set_task(1.0, "ShowTimer", id+TASK_TIMER)
1571
1572 return PLUGIN_CONTINUE
1573}
1574
1575public Messages(id)
1576{
1577 id -= TASK_MESS
1578
1579 if(!is_registered[id])
1580 {
1581 if(get_pcvar_float(g_regtime) != 0)
1582 {
1583 client_printcolor(id, "%L", LANG_SERVER, "REGISTER_CHAT", prefix, get_pcvar_num(g_regtime))
1584 }
1585 else
1586 {
1587 client_printcolor(id, "%L", LANG_SERVER, "YOUCANREG_CHAT", prefix)
1588 }
1589 }
1590 else if(!is_logged[id])
1591 {
1592 client_printcolor(id, "%L", LANG_SERVER, "LOGIN_CHAT", prefix, get_pcvar_num(g_logtime))
1593 }
1594 else if(is_autolog[id])
1595 {
1596 if(get_pcvar_num(g_announce))
1597 {
1598 get_user_name(id, temp_name, charsmax(temp_name))
1599 client_printcolor(0, "%L", LANG_SERVER, "LOG_LOGING_G", prefix, temp_name)
1600 }
1601 else
1602 {
1603 client_printcolor(id, "%L", LANG_SERVER, "AUTO_LOGIN_CHAT", prefix)
1604 }
1605 }
1606}
1607/*==============================================================================
1608 End of Show Client's informative messages
1609================================================================================*/
1610
1611/*==============================================================================
1612 Start of Client's Auto Login Changer function
1613================================================================================*/
1614public AutoLoginPassword(id)
1615{
1616 if(!get_pcvar_num(g_on))
1617 return PLUGIN_HANDLED
1618
1619 read_args(typedpass, charsmax(typedpass))
1620 remove_quotes(typedpass)
1621
1622 hash = convert_password(typedpass)
1623
1624 if(!equal(hash, password[id]))
1625 {
1626 TrieSetCell(g_login_times, g_client_data[id], ++attempts[id])
1627 client_printcolor(id, "%L", LANG_SERVER, "LOG_PASS_INVALID", prefix, attempts[id], get_pcvar_num(g_attempts))
1628
1629 if(attempts[id] >= get_pcvar_num(g_attempts))
1630 {
1631 if(get_pcvar_num(g_count))
1632 {
1633 g_player_time[id] = 0
1634 ShowTimer(id+TASK_TIMER)
1635 }
1636
1637 if(get_pcvar_num(g_time))
1638 {
1639 TrieSetCell(g_cant_login_time, g_client_data[id], time())
1640 }
1641 else
1642 {
1643 TrieSetCell(g_cant_login_time, g_client_data[id], 0)
1644 }
1645 params[0] = id
1646 params[1] = 3
1647 set_task(2.0, "KickPlayer", id+TASK_KICK, params, sizeof params)
1648
1649 if(get_pcvar_num(g_time))
1650 {
1651 set_task(get_pcvar_float(g_time), "RemoveCantLogin", 0, g_client_data[id], sizeof g_client_data)
1652 }
1653 return PLUGIN_HANDLED
1654 }
1655 else
1656 {
1657 client_cmd(id, "messagemode AUTO_LOGIN_PASS")
1658 }
1659
1660 return PLUGIN_HANDLED
1661 }
1662 else
1663 {
1664 get_pcvar_string(g_setinfo_pr, pass_prefix, charsmax(pass_prefix))
1665 client_cmd(id, "setinfo %s %s", pass_prefix, typedpass)
1666 AutoLogin(id, true)
1667 MainMenu(id)
1668 }
1669 return PLUGIN_CONTINUE
1670}
1671
1672AutoLogin(id, bool:enabled = true)
1673{
1674 if(!is_registered[id] || !is_logged[id])
1675 return PLUGIN_HANDLED
1676
1677 switch(get_pcvar_num(g_member))
1678 {
1679 case 0:
1680 {
1681 get_user_name(id, g_client_data[id], charsmax(g_client_data))
1682 }
1683 case 1:
1684 {
1685 get_user_ip(id, g_client_data[id], charsmax(g_client_data), 1)
1686 }
1687 case 2:
1688 {
1689 get_user_authid(id, g_client_data[id], charsmax(g_client_data))
1690 }
1691 default:
1692 {
1693 get_user_name(id, g_client_data[id], charsmax(g_client_data))
1694 }
1695 }
1696
1697 if(get_pcvar_num(g_save))
1698 {
1699 formatex(query, charsmax(query), "UPDATE registersystem SET Status = ^"%s^" WHERE Name = ^"%s^";", enabled ? "LOGGED_IN" :
1700
1701"LOGGED_OUT", g_client_data[id])
1702 SQL_ThreadQuery(g_sqltuple, "QuerySetData", query)
1703 }
1704 else
1705 {
1706 line = 0, length = 0;
1707
1708 while(read_file(reg_file, line++ , text, charsmax(text), length))
1709 {
1710 parse(text, text, charsmax(text))
1711
1712 if(!(equal(text, g_client_data[id])))
1713 continue
1714
1715 formatex(text, charsmax(text), "^"%s^" ^"%s^" ^"%s^"", g_client_data[id], password[id], enabled ? "LOGGED_IN" :
1716
1717"LOGGED_OUT")
1718 write_file(reg_file, text, line - 1)
1719
1720 break
1721 }
1722 }
1723
1724 if(enabled)
1725 {
1726 is_autolog[id] = true
1727 client_printcolor(id, "%L", LANG_SERVER, "AUTO_LOGIN_ON", prefix)
1728
1729 if(get_pcvar_num(g_aulog_log))
1730 {
1731 log_to_file(log_file, "%L", LANG_SERVER, "LOGFILE_AUTO_ON", g_client_data[id])
1732 }
1733 }
1734 else
1735 {
1736 is_autolog[id] = false
1737 client_printcolor(id, "%L", LANG_SERVER, "AUTO_LOGIN_OFF", prefix)
1738 get_pcvar_string(g_setinfo_pr, pass_prefix, charsmax(pass_prefix))
1739 client_cmd(id, "setinfo %s ^"^"", pass_prefix)
1740
1741 if(get_pcvar_num(g_aulog_log))
1742 {
1743 log_to_file(log_file, "%L", LANG_SERVER, "LOGFILE_AUTO_OFF", g_client_data[id])
1744 }
1745 }
1746
1747 return PLUGIN_CONTINUE
1748}
1749/*==============================================================================
1750 End of Client's Auto Login Changer function
1751================================================================================*/
1752
1753/*==============================================================================
1754 Start of the Main Menu function
1755================================================================================*/
1756public CreateMainMenuTask(id)
1757{
1758 id -= TASK_MENU
1759
1760 if((!is_registered[id] && get_pcvar_float(g_regtime)) || (is_registered[id] && !is_logged[id]))
1761 {
1762 MainMenu(id)
1763 set_task(MENU_TASK_TIME, "CreateMainMenuTask", id+TASK_MENU)
1764 }
1765}
1766
1767public MainMenu(id)
1768{
1769 if(!get_pcvar_num(g_on) || !is_user_connected(id) || !data_ready || !name_checked[id])
1770 return PLUGIN_HANDLED
1771
1772 length = 0
1773
1774 if(is_registered[id])
1775 {
1776 if(is_logged[id])
1777 {
1778 length += formatex(menu[length], charsmax(menu) - length, "%L", LANG_SERVER, "MAIN_MENU_LOG", LANG_SERVER, is_autolog[id]
1779
1780? "AUTO_LOG_DIS" : "AUTO_LOG_EN")
1781 keys = MENU_KEY_1|MENU_KEY_4|MENU_KEY_5|MENU_KEY_9|MENU_KEY_0
1782 }
1783 else
1784 {
1785 length += formatex(menu[length], charsmax(menu) - length, "%L", LANG_SERVER, "MAIN_MENU_REG")
1786 keys = MENU_KEY_1|MENU_KEY_9
1787 }
1788 }
1789 else
1790 {
1791 if(get_pcvar_float(g_regtime) == 0)
1792 {
1793 length += formatex(menu[length], charsmax(menu) - length, "%L", LANG_SERVER, "MAIN_MENU_NOTREG")
1794 keys = MENU_KEY_2|MENU_KEY_9|MENU_KEY_0
1795 }
1796 else
1797 {
1798 length += formatex(menu[length], charsmax(menu) - length, "%L", LANG_SERVER, "MAIN_MENU_NOTREG_FORCE")
1799 keys = MENU_KEY_2|MENU_KEY_9
1800 }
1801 }
1802 show_menu(id, keys, menu, -1, "Register System Main Menu")
1803
1804 return PLUGIN_CONTINUE
1805}
1806
1807public HandlerMainMenu(id, key)
1808{
1809 switch(key)
1810 {
1811 case 0:
1812 {
1813 if(!is_logged[id])
1814 {
1815 client_cmd(id, "messagemode LOGIN_PASS")
1816 }
1817 else
1818 {
1819 AutoLogin(id, false)
1820
1821 if(get_pcvar_num(g_logout))
1822 {
1823 CheckClient(id)
1824 CreateMainMenuTask(id+TASK_MENU)
1825 }
1826 else
1827 {
1828 if(get_pcvar_num(g_count))
1829 {
1830 g_player_time[id] = 0
1831 ShowTimer(id+TASK_TIMER)
1832 }
1833
1834 params[0] = id
1835 params[1] = 4
1836 set_task(2.0, "KickPlayer", id+TASK_KICK, params, sizeof params)
1837 }
1838
1839 client_printcolor(id, "%L", LANG_SERVER, "LOG_OUT", prefix)
1840 is_logged[id] = false
1841 }
1842 }
1843 case 1:
1844 {
1845 client_cmd(id, "messagemode REGISTER_PASS")
1846 }
1847 case 3:
1848 {
1849 if(!is_logged[id])
1850 return PLUGIN_HANDLED
1851
1852 if(cant_change_pass[id])
1853 {
1854 client_printcolor(id, "%L", LANG_SERVER, "CHANGE_TIMES", prefix, get_pcvar_num(g_chp_time))
1855 MainMenu(id)
1856 return PLUGIN_HANDLED
1857 }
1858 else
1859 {
1860 client_cmd(id, "messagemode CHANGE_PASS_NEW")
1861 MainMenu(id)
1862 }
1863 }
1864 case 4:
1865 {
1866 if(!is_logged[id])
1867 {
1868 MainMenu(id)
1869 return PLUGIN_HANDLED
1870 }
1871
1872 if(is_autolog[id])
1873 {
1874 AutoLogin(id, false)
1875 }
1876 else
1877 {
1878 client_cmd(id, "messagemode AUTO_LOGIN_PASS")
1879 }
1880 MainMenu(id)
1881 }
1882 case 8:
1883 {
1884 Info(id)
1885 MainMenu(id)
1886 }
1887 case 9:
1888 {
1889 return PLUGIN_HANDLED
1890 }
1891 }
1892 return PLUGIN_HANDLED
1893}
1894/*==============================================================================
1895 End of the Main Menu function
1896================================================================================*/
1897
1898/*==============================================================================
1899 Start of Login function
1900================================================================================*/
1901public Login(id)
1902{
1903 if(!get_pcvar_num(g_on) || !data_ready || !name_checked[id])
1904 return PLUGIN_HANDLED
1905
1906 if(changing_name[id])
1907 {
1908 client_printcolor(id, "%L", LANG_SERVER, "LOGIN_AFTER")
1909 return PLUGIN_HANDLED
1910 }
1911
1912 if(!is_registered[id])
1913 {
1914 client_printcolor(id, "%L", LANG_SERVER, "LOG_NOTREG", prefix)
1915 return PLUGIN_HANDLED
1916 }
1917
1918 if(is_logged[id])
1919 {
1920 client_printcolor(id, "%L", LANG_SERVER, "LOG_LOGGED", prefix);
1921 return PLUGIN_HANDLED
1922 }
1923
1924 read_args(typedpass, charsmax(typedpass))
1925 remove_quotes(typedpass)
1926
1927 if(equal(typedpass, ""))
1928 return PLUGIN_HANDLED
1929
1930 hash = convert_password(typedpass)
1931
1932 if(!equal(hash, password[id]))
1933 {
1934 TrieSetCell(g_login_times, g_client_data[id], ++attempts[id])
1935 client_printcolor(id, "%L", LANG_SERVER, "LOG_PASS_INVALID", prefix, attempts[id], get_pcvar_num(g_attempts))
1936
1937 if(attempts[id] >= get_pcvar_num(g_attempts))
1938 {
1939 if(get_pcvar_num(g_count))
1940 {
1941 g_player_time[id] = 0
1942 ShowTimer(id+TASK_TIMER)
1943 }
1944
1945 if(get_pcvar_num(g_time))
1946 {
1947 TrieSetCell(g_cant_login_time, g_client_data[id], time())
1948 }
1949 else
1950 {
1951 TrieSetCell(g_cant_login_time, g_client_data[id], 0)
1952 }
1953
1954 params[0] = id
1955 params[1] = 3
1956 set_task(2.0, "KickPlayer", id+TASK_KICK, params, sizeof params)
1957
1958 if(get_pcvar_num(g_time))
1959 {
1960 set_task(get_pcvar_float(g_time), "RemoveCantLogin", 0, g_client_data[id], sizeof g_client_data)
1961 }
1962 return PLUGIN_HANDLED
1963 }
1964 else
1965 {
1966 client_cmd(id, "messagemode LOGIN_PASS")
1967 }
1968 return PLUGIN_HANDLED
1969 }
1970 else
1971 {
1972 is_logged[id] = true
1973 attempts[id] = 0
1974 remove_task(id+TASK_KICK)
1975
1976 if(get_pcvar_num(g_announce))
1977 {
1978 get_user_name(id, temp_name, charsmax(temp_name))
1979 client_printcolor(0, "%L", LANG_SERVER, "LOG_LOGING_G", prefix, temp_name)
1980 }
1981 else
1982 {
1983 client_printcolor(id, "%L", LANG_SERVER, "LOG_LOGING", prefix)
1984 }
1985
1986 MainMenu(id)
1987 client_cmd(id, "jointeam")
1988 }
1989 return PLUGIN_CONTINUE
1990}
1991/*==============================================================================
1992 End of Login function
1993================================================================================*/
1994
1995/*==============================================================================
1996 Start of Register function
1997================================================================================*/
1998public Register(id)
1999{
2000 if(!get_pcvar_num(g_on) || !data_ready || !name_checked[id])
2001 return PLUGIN_HANDLED
2002
2003 if(changing_name[id])
2004 {
2005 client_printcolor(id, "%L", LANG_SERVER, "REGISTER_AFTER")
2006 return PLUGIN_HANDLED
2007 }
2008
2009 read_args(typedpass, charsmax(typedpass))
2010 remove_quotes(typedpass)
2011
2012 new passlength = strlen(typedpass)
2013
2014 if(equal(typedpass, ""))
2015 return PLUGIN_HANDLED
2016
2017 if(is_registered[id])
2018 {
2019 client_printcolor(id, "%L", LANG_SERVER, "REG_EXISTS", prefix)
2020 return PLUGIN_HANDLED
2021 }
2022
2023 if(passlength < get_pcvar_num(g_pass_length))
2024 {
2025 client_printcolor(id, "%L", LANG_SERVER, "REG_LEN", prefix, get_pcvar_num(g_pass_length))
2026 client_cmd(id, "messagemode REGISTER_PASS")
2027 return PLUGIN_HANDLED
2028 }
2029
2030 new_pass[id] = typedpass
2031 remove_task(id+TASK_MENU)
2032 ConfirmPassword(id)
2033 return PLUGIN_CONTINUE
2034}
2035/*==============================================================================
2036 End of Register function
2037================================================================================*/
2038
2039/*==============================================================================
2040 Start of Change Password function
2041================================================================================*/
2042public ChangePasswordNew(id)
2043{
2044 if(!get_pcvar_num(g_on) || !is_registered[id] || !is_logged[id] || changing_name[id] || !data_ready || !name_checked[id])
2045 return PLUGIN_HANDLED
2046
2047 if(cant_change_pass[id])
2048 {
2049 client_printcolor(id, "%L", LANG_SERVER, "CHANGE_TIMES", prefix, get_pcvar_num(g_chp_time))
2050 return PLUGIN_HANDLED
2051 }
2052
2053 read_args(typedpass, charsmax(typedpass))
2054 remove_quotes(typedpass)
2055
2056 new passlenght = strlen(typedpass)
2057
2058 if(equal(typedpass, ""))
2059 return PLUGIN_HANDLED
2060
2061 if(passlenght < get_pcvar_num(g_pass_length))
2062 {
2063 client_printcolor(id, "%L", LANG_SERVER, "REG_LEN", prefix, get_pcvar_num(g_pass_length))
2064 client_cmd(id, "messagemode CHANGE_PASS_NEW")
2065 return PLUGIN_HANDLED
2066 }
2067
2068 new_pass[id] = typedpass
2069 client_cmd(id, "messagemode CHANGE_PASS_OLD")
2070 return PLUGIN_CONTINUE
2071}
2072
2073public ChangePasswordOld(id)
2074{
2075 if(!get_pcvar_num(g_on) || !is_registered[id] || !is_logged[id] || changing_name[id] || !data_ready || !name_checked[id])
2076 return PLUGIN_HANDLED
2077
2078 if(cant_change_pass[id])
2079 {
2080 client_printcolor(id, "%L", LANG_SERVER, "CHANGE_TIMES", prefix, get_pcvar_num(g_chp_time))
2081 return PLUGIN_HANDLED
2082 }
2083
2084 read_args(typedpass, charsmax(typedpass))
2085 remove_quotes(typedpass)
2086
2087 if(equal(typedpass, "") || equal(new_pass[id], ""))
2088 return PLUGIN_HANDLED
2089
2090 hash = convert_password(typedpass)
2091
2092 if(!equali(hash, password[id]))
2093 {
2094 TrieSetCell(g_login_times, g_client_data[id], ++attempts[id])
2095 client_printcolor(id, "%L", LANG_SERVER, "LOG_PASS_INVALID", prefix, attempts[id], get_pcvar_num(g_attempts))
2096
2097 if(attempts[id] >= get_pcvar_num(g_attempts))
2098 {
2099 if(get_pcvar_num(g_count))
2100 {
2101 g_player_time[id] = 0
2102 ShowTimer(id+TASK_TIMER)
2103 }
2104
2105 if(get_pcvar_num(g_time))
2106 {
2107 TrieSetCell(g_cant_login_time, g_client_data[id], time())
2108 }
2109 else
2110 {
2111 TrieSetCell(g_cant_login_time, g_client_data[id], 0)
2112 }
2113 params[0] = id
2114 params[1] = 3
2115 set_task(2.0, "KickPlayer", id+TASK_KICK, params, sizeof params)
2116
2117 if(get_pcvar_num(g_time))
2118 {
2119 set_task(get_pcvar_float(g_time), "RemoveCantLogin", 0, g_client_data[id], sizeof g_client_data)
2120 }
2121 return PLUGIN_HANDLED
2122 }
2123 else
2124 {
2125 client_cmd(id, "messagemode CHANGE_PASS_OLD")
2126 }
2127 return PLUGIN_HANDLED
2128 }
2129
2130 ConfirmPassword(id)
2131 return PLUGIN_CONTINUE
2132}
2133/*==============================================================================
2134 End of Change Password function
2135================================================================================*/
2136
2137/*==============================================================================
2138 Start of Confirming Register's or Change Password's password function
2139================================================================================*/
2140public ConfirmPassword(id)
2141{
2142 if(!get_pcvar_num(g_on) || !is_user_connected(id))
2143 return PLUGIN_HANDLED
2144
2145 length = 0
2146
2147 formatex(menu, charsmax(menu) - length, "%L", LANG_SERVER, "MENU_PASS", new_pass[id])
2148 keys = MENU_KEY_1|MENU_KEY_2|MENU_KEY_0
2149
2150 show_menu(id, keys, menu, -1, "Password Menu")
2151 return PLUGIN_CONTINUE
2152}
2153
2154public HandlerConfirmPasswordMenu(id, key)
2155{
2156 switch(key)
2157 {
2158 case 0:
2159 {
2160 switch(get_pcvar_num(g_member))
2161 {
2162 case 0:
2163 {
2164 get_user_name(id, g_client_data[id], charsmax(g_client_data))
2165 }
2166 case 1:
2167 {
2168 get_user_ip(id, g_client_data[id], charsmax(g_client_data), 1)
2169 }
2170 case 2:
2171 {
2172 get_user_authid(id, g_client_data[id], charsmax(g_client_data))
2173 }
2174 default:
2175 {
2176 get_user_name(id, g_client_data[id], charsmax(g_client_data))
2177 }
2178 }
2179
2180 hash = convert_password(new_pass[id])
2181
2182 if(is_registered[id])
2183 {
2184 if(get_pcvar_num(g_save))
2185 {
2186 formatex(query, charsmax(query), "UPDATE `registersystem` SET Password = ^"%s^", Status = ^"%s^" WHERE
2187
2188Name = ^"%s^";", hash, is_autolog[id] == true ? "LOGGED_IN" : "LOGGED_OUT", g_client_data[id])
2189 SQL_ThreadQuery(g_sqltuple, "QuerySetData", query)
2190 }
2191 else
2192 {
2193 line = 0, length = 0;
2194
2195 while(read_file(reg_file, line++ , text, charsmax(text), length))
2196 {
2197 parse(text, text, charsmax(text))
2198
2199 if(!(equal(text, g_client_data[id])))
2200 continue
2201
2202 formatex(text, charsmax(text), "^"%s^" ^"%s^" ^"%s^"", g_client_data[id], hash, is_autolog[id] ==
2203
2204true ? "LOGGED_IN" : "LOGGED_OUT")
2205 write_file(reg_file, text, line - 1)
2206
2207 break
2208 }
2209 }
2210
2211 password[id] = hash
2212 TrieSetCell(g_pass_change_times, g_client_data[id], ++times[id])
2213 client_printcolor(id, "%L", LANG_SERVER, "CHANGE_NEW", prefix, new_pass[id])
2214
2215 if(is_autolog[id])
2216 {
2217 get_pcvar_string(g_setinfo_pr, pass_prefix, charsmax(pass_prefix))
2218 client_cmd(id, "setinfo %s %s", pass_prefix, new_pass[id])
2219 }
2220
2221 if(times[id] >= get_pcvar_num(g_chp_time))
2222 {
2223 cant_change_pass[id] = true
2224
2225 if(get_pcvar_num(g_time_pass))
2226 {
2227 TrieSetCell(g_cant_change_pass_time, g_client_data[id], time())
2228 }
2229 else
2230 {
2231 TrieSetCell(g_cant_change_pass_time, g_client_data[id], 0)
2232 }
2233
2234 if(get_pcvar_num(g_time_pass))
2235 {
2236 set_task(get_pcvar_float(g_time), "RemoveCantChangePass", 0, g_client_data[id], sizeof
2237
2238g_client_data)
2239 }
2240 }
2241
2242 if(get_pcvar_num(g_chp_log))
2243 {
2244 log_to_file(log_file, "%L", LANG_SERVER, "LOGFILE_CHNG_PASS", g_client_data[id])
2245 }
2246
2247 MainMenu(id)
2248 }
2249 else
2250 {
2251 if(get_pcvar_num(g_save))
2252 {
2253 formatex(query, charsmax(query), "INSERT INTO `registersystem` (`Name`, `Password`, `Status`) VALUES
2254
2255(^"%s^", ^"%s^", ^"LOGGED_OUT^");", g_client_data[id], hash)
2256 SQL_ThreadQuery(g_sqltuple, "QuerySetData", query)
2257 }
2258 else
2259 {
2260 new file_pointer = fopen(reg_file, "a")
2261 format(text, charsmax(text), "^n^"%s^" ^"%s^" ^"^"", g_client_data[id], hash)
2262 fprintf(file_pointer, text)
2263 fclose(file_pointer)
2264 }
2265
2266 is_registered[id] = true
2267 password[id] = hash
2268 new_pass[id] = ""
2269
2270 if(get_pcvar_num(g_announce))
2271 {
2272 client_printcolor(0, "%L", LANG_SERVER, "REG_REGIS_G", prefix, temp_name)
2273 }
2274 else
2275 {
2276 client_printcolor(id, "%L", LANG_SERVER, "REG_REGIS", prefix, get_pcvar_num(g_logtime))
2277 }
2278
2279 if(get_pcvar_num(g_reg_log))
2280 {
2281 log_to_file(log_file, "%L", LANG_SERVER, "LOGFILE_REG", g_client_data[id])
2282 }
2283
2284 if(is_user_connected(id))
2285 {
2286 user_silentkill(id)
2287 cs_set_user_team(id, CS_TEAM_UNASSIGNED)
2288 ShowMsg(id)
2289 }
2290 }
2291 }
2292 case 1:
2293 {
2294 if(is_registered[id])
2295 {
2296 client_cmd(id, "messagemode CHANGE_PASS_NEW")
2297 }
2298 else
2299 {
2300 client_cmd(id, "messagemode REGISTER_PASS")
2301 CreateMainMenuTask(id+TASK_MENU)
2302 }
2303 }
2304 case 9:
2305 {
2306 MainMenu(id)
2307 CreateMainMenuTask(id+TASK_MENU)
2308 return PLUGIN_HANDLED
2309 }
2310 }
2311 return PLUGIN_HANDLED
2312}
2313
2314public QuerySetData(FailState, Handle:Query, error[],errcode, data[], datasize)
2315{
2316 if(FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED)
2317 {
2318 log_amx("%s", error)
2319 return
2320 }
2321}
2322/*==============================================================================
2323 End of Confirming Register's or Change Password's password function
2324================================================================================*/
2325
2326/*==============================================================================
2327 Start of Jointeam menus and commands functions
2328================================================================================*/
2329public HookTeamCommands(id)
2330{
2331 if(!get_pcvar_num(g_on) || !is_user_connected(id))
2332 return PLUGIN_CONTINUE
2333
2334 if(!data_ready)
2335 return PLUGIN_HANDLED
2336
2337 if(!name_checked[id])
2338 return PLUGIN_CONTINUE
2339
2340 if((!is_registered[id] && get_pcvar_float(g_regtime)) || (is_registered[id] && !is_logged[id]))
2341 {
2342 MainMenu(id)
2343 return PLUGIN_HANDLED
2344 }
2345 else if(get_pcvar_num(g_ajc_change) && cs_get_user_team(id) != CS_TEAM_UNASSIGNED && (!get_pcvar_num(g_ajc_admin) || !(get_user_flags(id)
2346
2347& AJC_ADMIN_FLAG)))
2348 {
2349 return PLUGIN_HANDLED
2350 }
2351 return PLUGIN_CONTINUE
2352}
2353
2354public TextMenu(msgid, dest, id)
2355{
2356 if(!get_pcvar_num(g_on) || !is_user_connected(id))
2357 return PLUGIN_CONTINUE
2358
2359 if(!data_ready)
2360 return PLUGIN_HANDLED
2361
2362 if(!name_checked[id])
2363 return PLUGIN_CONTINUE
2364
2365 static menu_text[64];
2366
2367 get_msg_arg_string(4, menu_text, charsmax(menu_text))
2368
2369// if(equal(menu_text, JOIN_TEAM_MENU_FIRST) || equal(menu_text, JOIN_TEAM_MENU_FIRST_SPEC))
2370 {
2371 if((!is_registered[id] && get_pcvar_float(g_regtime)) || (is_registered[id] && !is_logged[id]))
2372 {
2373 MainMenu(id)
2374 return PLUGIN_HANDLED
2375 }
2376 else if((get_pcvar_num(g_ajc_team) && cs_get_user_team(id) == CS_TEAM_UNASSIGNED) && !task_exists(TASK_AJC) && (!get_pcvar_num
2377
2378(g_ajc_admin) || !(get_user_flags(id) & AJC_ADMIN_FLAG)))
2379 {
2380 SetAutoJoinTask(id, msgid)
2381 return PLUGIN_HANDLED
2382 }
2383 }
2384// else if(equal(menu_text, JOIN_TEAM_MENU_INGAME) || equal(menu_text, JOIN_TEAM_MENU_INGAME_SPEC))
2385 {
2386 if((!is_registered[id] && get_pcvar_float(g_regtime)) || (is_registered[id] && !is_logged[id]))
2387 {
2388 MainMenu(id)
2389 return PLUGIN_HANDLED
2390 }
2391 else if(get_pcvar_num(g_ajc_change) && (!get_pcvar_num(g_ajc_admin) || !(get_user_flags(id) & AJC_ADMIN_FLAG)))
2392 {
2393 return PLUGIN_HANDLED
2394 }
2395 }
2396 return PLUGIN_CONTINUE
2397}
2398
2399public VGUIMenu(msgid, dest, id)
2400{
2401 if(!get_pcvar_num(g_on) || get_msg_arg_int(1) != JOIN_TEAM_VGUI_MENU || !is_user_connected(id))
2402 return PLUGIN_CONTINUE
2403
2404 if(!data_ready)
2405 return PLUGIN_HANDLED
2406
2407 if(!name_checked[id])
2408 return PLUGIN_CONTINUE
2409
2410 if((!is_registered[id] && get_pcvar_float(g_regtime)) || (is_registered[id] && !is_logged[id]))
2411 {
2412 MainMenu(id)
2413 return PLUGIN_HANDLED
2414 }
2415 else if(get_pcvar_num(g_ajc_team))
2416 {
2417 if((!get_pcvar_num(g_ajc_admin) || !(get_user_flags(id) & AJC_ADMIN_FLAG)))
2418 {
2419 if(cs_get_user_team(id) == CS_TEAM_UNASSIGNED && !task_exists(TASK_AJC))
2420 {
2421 SetAutoJoinTask(id, msgid)
2422 return PLUGIN_HANDLED
2423 }
2424 else if(get_pcvar_num(g_ajc_change))
2425 {
2426 return PLUGIN_HANDLED
2427 }
2428 }
2429 }
2430 else if(get_pcvar_num(g_ajc_change) && (!get_pcvar_num(g_ajc_admin) || !(get_user_flags(id) & AJC_ADMIN_FLAG)))
2431 {
2432 return PLUGIN_HANDLED
2433 }
2434 return PLUGIN_CONTINUE
2435}
2436/*==============================================================================
2437 End of Jointeam menus and commands functions
2438================================================================================*/
2439
2440/*==============================================================================
2441 Start of Auto Join function
2442================================================================================*/
2443public AutoJoin(parameters[])
2444{
2445 new id = parameters[0]
2446
2447 if(!is_user_connected(id))
2448 return PLUGIN_HANDLED
2449
2450 if(cs_get_user_team(id) != CS_TEAM_UNASSIGNED)
2451 return PLUGIN_HANDLED
2452
2453 new g_team[2], g_team_num = get_pcvar_num(g_ajc_team)
2454
2455 if(g_team_num == 6)
2456 {
2457 num_to_str(g_team_num, g_team, charsmax(g_team))
2458 engclient_cmd(id, "jointeam", g_team)
2459 return PLUGIN_CONTINUE
2460 }
2461
2462 if(g_team_num == 5)
2463 {
2464 g_team_num = random_num(1, 2)
2465 }
2466 else if(g_team_num != 1 && g_team_num != 2)
2467 return PLUGIN_HANDLED
2468
2469 new g_class_num = get_pcvar_num(g_ajc_class[g_team_num - 1])
2470 num_to_str(g_team_num, g_team, charsmax(g_team))
2471
2472 if(g_class_num == 5)
2473 {
2474 g_class_num = random_num(1, 4)
2475 }
2476
2477 if(g_class_num == 0 || (g_class_num != 1 && g_class_num != 2 && g_class_num != 3 && g_class_num != 4))
2478 {
2479 engclient_cmd(id, "jointeam", g_team)
2480 return PLUGIN_CONTINUE
2481 }
2482
2483 new g_class[2], msg_block = get_msg_block(parameters[1])
2484
2485 num_to_str(g_class_num, g_class, charsmax(g_class))
2486
2487 set_msg_block(parameters[1], BLOCK_SET)
2488 engclient_cmd(id, "jointeam", g_team)
2489 engclient_cmd(id, "joinclass", g_class)
2490 set_msg_block(parameters[1], msg_block)
2491
2492 return PLUGIN_CONTINUE
2493}
2494/*==============================================================================
2495 End of Auto Join functions
2496================================================================================*/
2497
2498/*==============================================================================
2499 Start of Hook Client's commands
2500================================================================================*/
2501public client_command(id)
2502{
2503 if(!get_pcvar_num(g_on) || !data_ready)
2504 return PLUGIN_HANDLED
2505
2506 new command[64], arg[16];
2507
2508 read_argv(0, command, charsmax(command))
2509 read_argv(1, arg, charsmax(arg))
2510
2511 if((equali(command, "say") || equali(command, "say_team")) && equali(arg, "/reg"))
2512 {
2513 if(!name_checked[id])
2514 {
2515 client_printcolor(id, "%L", LANG_SERVER, "WHITE_LIST", prefix)
2516 }
2517 else
2518 {
2519 MainMenu(id)
2520 }
2521
2522 return PLUGIN_CONTINUE
2523 }
2524
2525 if(get_pcvar_num(g_comm) == 1)
2526 {
2527 if(TrieKeyExists(g_commands, command))
2528 {
2529 if(!is_registered[id] && get_pcvar_float(g_regtime))
2530 {
2531 console_print(id, "%s %L", prefix, LANG_SERVER, "COMMAND_REG")
2532 client_printcolor(id, "!g%s!t %L", prefix, LANG_SERVER, "COMMAND_REG")
2533 return PLUGIN_HANDLED
2534 }
2535 else if(is_registered[id] && !is_logged[id])
2536 {
2537 console_print(id, "%s %L", prefix, LANG_SERVER, "COMMAND_LOG")
2538 client_printcolor(id, "!g%s!t %L", prefix, LANG_SERVER, "COMMAND_LOG")
2539 return PLUGIN_HANDLED
2540 }
2541 }
2542 }
2543 else if(get_pcvar_num(g_comm) == 2)
2544 {
2545 return PLUGIN_HANDLED
2546 }
2547
2548 return PLUGIN_CONTINUE
2549}
2550
2551/*==============================================================================
2552 End of Hook Client's commands
2553================================================================================*/
2554
2555/*==============================================================================
2556 Start of Info/Help MOTD function
2557================================================================================*/
2558public Info(id)
2559{
2560 show_motd(id, "rshelpmotd.txt", "Register System Help")
2561}
2562/*==============================================================================
2563 End of Info/Help MOTD function
2564================================================================================*/
2565
2566/*==============================================================================
2567 Start of Advret function
2568================================================================================*/
2569public ShowAdvert(id)
2570{
2571 id -= TASK_ADVERT
2572
2573 if(!get_pcvar_num(g_on) || !get_pcvar_num(g_advert) || !is_user_connected(id) || is_registered[id])
2574 return PLUGIN_HANDLED
2575
2576 client_printcolor(id, "%L", LANG_SERVER, "YOUCANREG_CHAT", prefix)
2577 set_task(get_pcvar_float(g_advert_int), "ShowAdvert", id+TASK_ADVERT)
2578
2579 return PLUGIN_CONTINUE
2580}
2581/*==============================================================================
2582 End of Advret function
2583================================================================================*/
2584
2585/*==============================================================================
2586 Start of Player Spawn function
2587================================================================================*/
2588public HookPlayerSpawn(id)
2589{
2590 if(get_pcvar_num(g_on) && is_user_connected(id))
2591 {
2592 show_menu(id, 0, "^n", 1)
2593 }
2594}
2595/*==============================================================================
2596 End of Player Spawn function
2597================================================================================*/
2598
2599/*==============================================================================
2600 Start of Player PreThink function for the blind function
2601================================================================================*/
2602public PlayerPreThink(id)
2603{
2604 if(!get_pcvar_num(g_on) || !get_pcvar_num(g_blind) || !is_user_connected(id) || changing_name[id])
2605 return PLUGIN_HANDLED
2606
2607 if((!is_registered[id] && get_pcvar_float(g_regtime)) || (is_registered[id] && !is_logged[id]))
2608 {
2609 message_begin(MSG_ONE_UNRELIABLE, g_screenfade, {0,0,0}, id)
2610 write_short(1<<12)
2611 write_short(1<<12)
2612 write_short(0x0000)
2613 write_byte(0)
2614 write_byte(0)
2615 write_byte(0)
2616 write_byte(255)
2617 message_end()
2618 }
2619
2620 return PLUGIN_CONTINUE
2621}
2622/*==============================================================================
2623 End of Player PreThink function for the blind function
2624================================================================================*/
2625
2626/*==============================================================================
2627 Start of Client Info Change function for hooking name change of clients
2628================================================================================*/
2629public ClientInfoChanged(id)
2630{
2631 if(!get_pcvar_num(g_on) || !is_user_connected(id))
2632 return FMRES_IGNORED
2633
2634 new oldname[32], newname[32];
2635
2636 get_user_name(id, oldname, charsmax(oldname))
2637 get_user_info(id, "name", newname, charsmax(newname))
2638
2639 if(!equal(oldname, newname))
2640 {
2641 replace_all(newname, charsmax(newname), "%", " ")
2642
2643 changing_name[id] = false
2644
2645 if(!is_user_alive(id))
2646 {
2647 changing_name[id] = true
2648 }
2649 else
2650 {
2651 if(is_logged[id])
2652 {
2653 set_user_info(id, "name", oldname)
2654 client_printcolor(id, "%L", LANG_SERVER, "NAME_CHANGE_LOG", prefix)
2655 return FMRES_HANDLED
2656 }
2657
2658 if(get_pcvar_num(g_whitelist))
2659 {
2660 set_task(1.0, "CheckName", id)
2661 }
2662 else
2663 {
2664 set_task(1.0, "CheckClient", id)
2665 }
2666 }
2667 }
2668 return FMRES_IGNORED
2669}
2670/*==============================================================================
2671 End of Client Info Change function for hooking name change of clients
2672================================================================================*/
2673
2674/*==============================================================================
2675 Start of Kick Player function
2676================================================================================*/
2677public KickPlayer(parameters[])
2678{
2679 new id = parameters[0]
2680 new reason = parameters[1]
2681
2682 if(!is_user_connecting(id) && !is_user_connected(id))
2683 return PLUGIN_HANDLED
2684
2685 new userid = get_user_userid(id)
2686
2687 switch(reason)
2688 {
2689 case 1:
2690 {
2691 if(is_registered[id])
2692 return PLUGIN_HANDLED
2693
2694 console_print(id, "%L", LANG_SERVER, "KICK_INFO")
2695 server_cmd("kick #%i ^"%L^"", userid, LANG_PLAYER, "KICK_REG")
2696 }
2697 case 2:
2698 {
2699 if(is_logged[id])
2700 return PLUGIN_HANDLED
2701
2702 console_print(id, "%L", LANG_SERVER, "KICK_INFO")
2703 server_cmd("kick #%i ^"%L^"", userid, LANG_PLAYER, "KICK_LOGIN")
2704 }
2705 case 3:
2706 {
2707 if(TrieGetCell(g_cant_login_time, g_client_data[id], value))
2708 {
2709 console_print(id, "%L", LANG_SERVER, "KICK_INFO")
2710
2711 if(!value)
2712 {
2713 server_cmd("kick #%i ^"%s^"", userid, LANG_PLAYER, "KICK_ATMP_MAP", get_pcvar_num(g_attempts))
2714 }
2715 else
2716 {
2717 new cal_time = get_pcvar_num(g_time) - (time() - value)
2718 server_cmd("kick #%i ^"%s^"", userid, LANG_PLAYER, "KICK_ATMP_TIME", get_pcvar_num(g_attempts), cal_time)
2719 }
2720 }
2721 }
2722 case 4:
2723 {
2724 console_print(id, "%L", LANG_SERVER, "KICK_INFO")
2725 server_cmd("kick #%i ^"%L^"", userid, LANG_SERVER, "KICK_LOGOUT")
2726 }
2727 }
2728 return PLUGIN_CONTINUE
2729}
2730/*==============================================================================
2731 End of Kick Player function
2732================================================================================*/
2733
2734/*==============================================================================
2735 Start of Removing Punishes function
2736================================================================================*/
2737public RemoveCantLogin(data[])
2738{
2739 TrieDeleteKey(g_login_times, data)
2740 TrieDeleteKey(g_cant_login_time, data)
2741}
2742
2743public RemoveCantChangePass(data[])
2744{
2745 TrieDeleteKey(g_cant_change_pass_time, data)
2746 TrieDeleteKey(g_pass_change_times, data)
2747
2748 new target;
2749
2750 switch(get_pcvar_num(g_member))
2751 {
2752 case 0:
2753 {
2754 target = find_player("a", data)
2755 }
2756 case 1:
2757 {
2758 target = find_player("d", data)
2759 }
2760 case 2:
2761 {
2762 target = find_player("c", data)
2763 }
2764 default:
2765 {
2766 target = find_player("a", data)
2767 }
2768 }
2769
2770 if(!target)
2771 return PLUGIN_HANDLED
2772
2773 cant_change_pass[target] = false
2774 client_printcolor(target, "%L", LANG_SERVER, "CHANGE_CAN", prefix)
2775 return PLUGIN_CONTINUE
2776}
2777/*==============================================================================
2778 End of Removing Punish function
2779================================================================================*/
2780
2781/*==============================================================================
2782 Start of Plugin's stocks
2783================================================================================*/
2784stock client_printcolor(const id, const message[], any:...)
2785{
2786 new g_message[191];
2787 new i = 1, players[32];
2788
2789 vformat(g_message, charsmax(g_message), message, 3)
2790
2791 replace_all(g_message, charsmax(g_message), "!g", "^4")
2792 replace_all(g_message, charsmax(g_message), "!n", "^1")
2793 replace_all(g_message, charsmax(g_message), "!t", "^3")
2794
2795 if(id)
2796 {
2797 players[0] = id
2798 }
2799 else
2800 {
2801 get_players(players, i, "ch")
2802 }
2803
2804 for(new j = 0; j < i; j++)
2805 {
2806 if(is_user_connected(players[j]))
2807 {
2808 message_begin(MSG_ONE_UNRELIABLE, g_saytxt,_, players[j])
2809 write_byte(players[j])
2810 write_string(g_message)
2811 message_end()
2812 }
2813 }
2814}
2815
2816stock convert_password(const password[])
2817{
2818 new pass_salt[64], converted_password[34];
2819
2820 formatex(pass_salt, charsmax(pass_salt), "%s%s", password, SALT)
2821 md5(pass_salt, converted_password)
2822
2823 return converted_password
2824}
2825
2826stock SetAutoJoinTask(id, menu_msgid)
2827{
2828 params[0] = id
2829 params[1] = menu_msgid
2830
2831 set_task(AJC_TASK_TIME, "AutoJoin", id+TASK_AJC, params, sizeof params)
2832}
2833
2834stock clear_user(const id)
2835{
2836 is_logged[id] = false
2837 is_registered[id] = false
2838 is_autolog[id] = false
2839 cant_change_pass[id] = false
2840 changing_name[id] = false
2841 name_checked[id] = true
2842 attempts[id] = 0
2843 times[id] = 0
2844}
2845
2846stock remove_tasks(const id)
2847{
2848 remove_task(id+TASK_MESS)
2849 remove_task(id+TASK_KICK)
2850 remove_task(id+TASK_MENU)
2851 remove_task(id+TASK_TIMER)
2852 remove_task(id+TASK_ADVERT)
2853 remove_task(id+TASK_AJC)
2854 remove_task(id)
2855}
2856/*==============================================================================
2857 End of Plugin's stocks
2858================================================================================*/