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