Advertisement
Guest User

Untitled

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