Advertisement
Guest User

Untitled

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