HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. // A plugint magyarosította *tOrNaDo
  2. #include <amxmodx>
  3. #include <amxmisc>
  4. #include <engine>
  5. #include <regex>
  6.  
  7. #define PLUGIN_NAME "Advanced Bans"
  8. #define PLUGIN_VERSION "0.8.1"
  9. #define PLUGIN_AUTHOR "Exolent"
  10.  
  11. #pragma semicolon 1
  12.  
  13.  
  14.  
  15. // ===============================================
  16. // CUSTOMIZATION STARTS HERE
  17. // ===============================================
  18.  
  19.  
  20. // uncomment the line below if you want this plugin to
  21. // load old bans from the banned.cfg and listip.cfg files
  22. //#define KEEP_DEFAULT_BANS
  23.  
  24.  
  25. // uncomment the line below if you want the history to be in one file
  26. //#define HISTORY_ONE_FILE
  27.  
  28.  
  29. // if you must have a maximum amount of bans to be compatible with AMXX versions before 1.8.0
  30. // change this number to your maximum amount
  31. // if you would rather have unlimited (requires AMXX 1.8.0 or higher) then set it to 0
  32. #define MAX_BANS 0
  33.  
  34.  
  35. // if you want to use SQL for your server, then uncomment the line below
  36. //#define USING_SQL
  37.  
  38.  
  39. // ===============================================
  40. // CUSTOMIZATION ENDS HERE
  41. // ===============================================
  42.  
  43.  
  44.  
  45. #if defined USING_SQL
  46. #include <sqlx>
  47.  
  48. #define TABLE_NAME "advanced_bans"
  49. #define KEY_NAME "name"
  50. #define KEY_STEAMID "steamid"
  51. #define KEY_BANLENGTH "banlength"
  52. #define KEY_UNBANTIME "unbantime"
  53. #define KEY_REASON "reason"
  54. #define KEY_ADMIN_NAME "admin_name"
  55. #define KEY_ADMIN_STEAMID "admin_steamid"
  56.  
  57. #define RELOAD_BANS_INTERVAL 60.0
  58. #endif
  59.  
  60. #define REGEX_IP_PATTERN "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
  61. #define REGEX_STEAMID_PATTERN "^^STEAM_0:(0|1):\d+$"
  62.  
  63. new Regex:g_IP_pattern;
  64. new Regex:g_SteamID_pattern;
  65. new g_regex_return;
  66.  
  67. /*bool:IsValidIP(const ip[])
  68.   {
  69.   return regex_match_c(ip, g_IP_pattern, g_regex_return) > 0;
  70.   }*/
  71.  
  72. #define IsValidIP(%1) (regex_match_c(%1, g_IP_pattern, g_regex_return) > 0)
  73.  
  74. /*bool:IsValidAuthid(const authid[])
  75.   {
  76.   return regex_match_c(authid, g_SteamID_pattern, g_regex_return) > 0;
  77.   }*/
  78.  
  79. #define IsValidAuthid(%1) (regex_match_c(%1, g_SteamID_pattern, g_regex_return) > 0)
  80.  
  81.  
  82. enum // for name displaying
  83. {
  84. ACTIVITY_NONE, // nothing is shown
  85. ACTIVITY_HIDE, // admin name is hidden
  86. ACTIVITY_SHOW // admin name is shown
  87. };
  88. new const g_admin_activity[] =
  89. {
  90. ACTIVITY_NONE, // amx_show_activity 0 = show nothing to everyone
  91. ACTIVITY_HIDE, // amx_show_activity 1 = hide admin name from everyone
  92. ACTIVITY_SHOW, // amx_show_activity 2 = show admin name to everyone
  93. ACTIVITY_SHOW, // amx_show_activity 3 = show name to admins but hide it from normal users
  94. ACTIVITY_SHOW, // amx_show_activity 4 = show name to admins but show nothing to normal users
  95. ACTIVITY_HIDE // amx_show_activity 5 = hide name from admins but show nothing to normal users
  96. };
  97. new const g_normal_activity[] =
  98. {
  99. ACTIVITY_NONE, // amx_show_activity 0 = show nothing to everyone
  100. ACTIVITY_HIDE, // amx_show_activity 1 = hide admin name from everyone
  101. ACTIVITY_SHOW, // amx_show_activity 2 = show admin name to everyone
  102. ACTIVITY_HIDE, // amx_show_activity 3 = show name to admins but hide it from normal users
  103. ACTIVITY_NONE, // amx_show_activity 4 = show name to admins but show nothing to normal users
  104. ACTIVITY_NONE // amx_show_activity 5 = hide name from admins but show nothing to normal users
  105. };
  106.  
  107.  
  108. #if MAX_BANS <= 0
  109. enum _:BannedData
  110. {
  111. bd_name[32],
  112. bd_steamid[35],
  113. bd_banlength,
  114. bd_unbantime[32],
  115. bd_reason[128],
  116. bd_admin_name[64],
  117. bd_admin_steamid[35]
  118. };
  119.  
  120. new Trie:g_trie;
  121. new Array:g_array;
  122. #else
  123. new g_names[MAX_BANS][32];
  124. new g_steamids[MAX_BANS][35];
  125. new g_banlengths[MAX_BANS];
  126. new g_unbantimes[MAX_BANS][32];
  127. new g_reasons[MAX_BANS][128];
  128. new g_admin_names[MAX_BANS][64];
  129. new g_admin_steamids[MAX_BANS][35];
  130. #endif
  131. new g_total_bans;
  132.  
  133. #if !defined USING_SQL
  134. new g_ban_file[64];
  135. #else
  136. new Handle:g_sql_tuple;
  137. new bool:g_loading_bans = true;
  138. #endif
  139.  
  140. new ab_website;
  141. new ab_immunity;
  142. new ab_bandelay;
  143. new ab_unbancheck;
  144.  
  145. new amx_show_activity;
  146.  
  147. #if MAX_BANS <= 0
  148. new Array:g_maxban_times;
  149. new Array:g_maxban_flags;
  150. #else
  151. #define MAX_BANLIMITS 30
  152. new g_maxban_times[MAX_BANLIMITS];
  153. new g_maxban_flags[MAX_BANLIMITS];
  154. #endif
  155. new g_total_maxban_times;
  156.  
  157. new g_unban_entity;
  158.  
  159. new g_max_clients;
  160.  
  161. new g_msgid_SayText;
  162.  
  163. public plugin_init()
  164. {
  165. register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
  166. register_cvar("advanced_bans", PLUGIN_VERSION, FCVAR_SPONLY);
  167.  
  168. register_dictionary("advanced_bans.txt");
  169.  
  170. register_concmd("amx_ban", "CmdBan", ADMIN_BAN, "<nick, #userid, authid> <time in minutes> <reason>");
  171. register_concmd("amx_banip", "CmdBanIp", ADMIN_BAN, "<nick, #userid, authid> <time in minutes> <reason>");
  172. register_concmd("amx_addban", "CmdAddBan", ADMIN_BAN, "<name> <authid or ip> <time in minutes> <reason>");
  173. register_concmd("amx_unban", "CmdUnban", ADMIN_BAN, "<authid or ip>");
  174. register_concmd("amx_banlist", "CmdBanList", ADMIN_BAN, "[start] -- shows everyone who is banned");
  175. register_srvcmd("amx_addbanlimit", "CmdAddBanLimit", -1, "<flag> <time in minutes>");
  176.  
  177. ab_website = register_cvar("ab_website", "Weboldalad linkje");
  178. ab_immunity = register_cvar("ab_immunity", "1");
  179. ab_bandelay = register_cvar("ab_bandelay", "1.0");
  180. ab_unbancheck = register_cvar("ab_unbancheck", "5.0");
  181.  
  182. amx_show_activity = register_cvar("amx_show_activity", "2");
  183.  
  184. #if MAX_BANS <= 0
  185. g_trie = TrieCreate();
  186. g_array = ArrayCreate(BannedData);
  187. #endif
  188.  
  189. #if !defined MAX_BANLIMITS
  190. g_maxban_times = ArrayCreate(1);
  191. g_maxban_flags = ArrayCreate(1);
  192. #endif
  193.  
  194. #if !defined USING_SQL
  195. get_datadir(g_ban_file, sizeof(g_ban_file) - 1);
  196. add(g_ban_file, sizeof(g_ban_file) - 1, "/cs16t3am_banok.txt");
  197.  
  198. LoadBans();
  199. #else
  200. g_sql_tuple = SQL_MakeStdTuple();
  201. PrepareTable();
  202. #endif
  203.  
  204. new error[2];
  205. g_IP_pattern = regex_compile(REGEX_IP_PATTERN, g_regex_return, error, sizeof(error) - 1);
  206. g_SteamID_pattern = regex_compile(REGEX_STEAMID_PATTERN, g_regex_return, error, sizeof(error) - 1);
  207.  
  208. g_max_clients = get_maxplayers();
  209.  
  210. g_msgid_SayText = get_user_msgid("SayText");
  211. }
  212.  
  213. #if defined USING_SQL
  214. PrepareTable()
  215. {
  216. new query[128];
  217. formatex(query, sizeof(query) - 1,\
  218. "CREATE TABLE IF NOT EXISTS `%s` (`%s` varchar(32) NOT NULL, `%s` varchar(35) NOT NULL, `%s` int(10) NOT NULL, `%s` varchar(32) NOT NULL, `%s` varchar(128) NOT NULL, `%s` varchar(64) NOT NULL, `%s` varchar(35) NOT NULL);",\
  219. TABLE_NAME, KEY_NAME, KEY_STEAMID, KEY_BANLENGTH, KEY_UNBANTIME, KEY_REASON, KEY_ADMIN_NAME, KEY_ADMIN_STEAMID
  220. );
  221.  
  222. SQL_ThreadQuery(g_sql_tuple, "QueryCreateTable", query);
  223. }
  224.  
  225. public QueryCreateTable(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
  226. {
  227. if( failstate == TQUERY_CONNECT_FAILED )
  228. {
  229. set_fail_state("Could not connect to database.");
  230. }
  231. else if( failstate == TQUERY_QUERY_FAILED )
  232. {
  233. set_fail_state("Query failed.");
  234. }
  235. else if( errcode )
  236. {
  237. log_amx("Error on query: %s", error);
  238. }
  239. else
  240. {
  241. LoadBans();
  242. }
  243. }
  244. #endif
  245.  
  246. public plugin_cfg()
  247. {
  248. CreateUnbanEntity();
  249. }
  250.  
  251. public CreateUnbanEntity()
  252. {
  253. static failtimes;
  254.  
  255. g_unban_entity = create_entity("info_target");
  256.  
  257. if( !is_valid_ent(g_unban_entity) )
  258. {
  259. ++failtimes;
  260.  
  261. log_amx("[ERROR] Failed to create unban entity (%i/10)", failtimes);
  262.  
  263. if( failtimes < 10 )
  264. {
  265. set_task(1.0, "CreateUnbanEntity");
  266. }
  267. else
  268. {
  269. log_amx("[ERROR] Could not create unban entity!");
  270. }
  271.  
  272. return;
  273. }
  274.  
  275. entity_set_string(g_unban_entity, EV_SZ_classname, "unban_entity");
  276. entity_set_float(g_unban_entity, EV_FL_nextthink, get_gametime() + 1.0);
  277.  
  278. register_think("unban_entity", "FwdThink");
  279. }
  280.  
  281. public client_authorized(client)
  282. {
  283. static authid[35];
  284. get_user_authid(client, authid, sizeof(authid) - 1);
  285.  
  286. static ip[35];
  287. get_user_ip(client, ip, sizeof(ip) - 1, 1);
  288.  
  289. #if MAX_BANS > 0
  290. static banned_authid[35], bool:is_ip;
  291. for( new i = 0; i < g_total_bans; i++ )
  292. {
  293. copy(banned_authid, sizeof(banned_authid) - 1, g_steamids[i]);
  294.  
  295. is_ip = bool:(containi(banned_authid, ".") != -1);
  296.  
  297. if( is_ip && equal(ip, banned_authid) || !is_ip && equal(authid, banned_authid) )
  298. {
  299. static name[32], reason[128], unbantime[32], admin_name[32], admin_steamid[64];
  300. copy(name, sizeof(name) - 1, g_names[i]);
  301. copy(reason, sizeof(reason) - 1, g_reasons[i]);
  302. new banlength = g_banlengths[i];
  303. copy(unbantime, sizeof(unbantime) - 1, g_unbantimes[i]);
  304. copy(admin_name, sizeof(admin_name) - 1, g_admin_names[i]);
  305. copy(admin_steamid, sizeof(admin_steamid) - 1, g_admin_steamids[i]);
  306.  
  307. PrintBanInformation(client, name, banned_authid, reason, banlength, unbantime, admin_name, admin_steamid, true, true);
  308.  
  309. set_task(get_pcvar_float(ab_bandelay), "TaskDisconnectPlayer", client);
  310. break;
  311. }
  312. }
  313. #else
  314. static array_pos;
  315.  
  316. if( TrieGetCell(g_trie, authid, array_pos) || TrieGetCell(g_trie, ip, array_pos) )
  317. {
  318. static data[BannedData];
  319. ArrayGetArray(g_array, array_pos, data);
  320.  
  321. PrintBanInformation(client, data[bd_name], data[bd_steamid], data[bd_reason], data[bd_banlength], data[bd_unbantime], data[bd_admin_name], data[bd_admin_steamid], true, true);
  322.  
  323. set_task(get_pcvar_float(ab_bandelay), "TaskDisconnectPlayer", client);
  324. }
  325. #endif
  326. }
  327.  
  328. public CmdBan(client, level, cid)
  329. {
  330. if( !cmd_access(client, level, cid, 4) ) return PLUGIN_HANDLED;
  331.  
  332. static arg[128];
  333. read_argv(1, arg, sizeof(arg) - 1);
  334.  
  335. new target = cmd_target(client, arg, GetTargetFlags(client));
  336. if( !target ) return PLUGIN_HANDLED;
  337.  
  338. static target_authid[35];
  339. get_user_authid(target, target_authid, sizeof(target_authid) - 1);
  340.  
  341. if( !IsValidAuthid(target_authid) )
  342. {
  343. console_print(client, "[AdvancedBan] %L", client, "AB_NOT_AUTHORIZED");
  344. return PLUGIN_HANDLED;
  345. }
  346.  
  347. #if MAX_BANS <= 0
  348. if( TrieKeyExists(g_trie, target_authid) )
  349. {
  350. console_print(client, "[AdvancedBan] %L", client, "AB_ALREADY_BANNED_STEAMID");
  351. return PLUGIN_HANDLED;
  352. }
  353. #else
  354. for( new i = 0; i < g_total_bans; i++ )
  355. {
  356. if( !strcmp(target_authid, g_steamids[i], 1) )
  357. {
  358. console_print(client, "[AdvancedBan] %L", client, "AB_ALREADY_BANNED_STEAMID");
  359. return PLUGIN_HANDLED;
  360. }
  361. }
  362. #endif
  363.  
  364. read_argv(2, arg, sizeof(arg) - 1);
  365.  
  366. new length = str_to_num(arg);
  367. new maxlength = GetMaxBanTime(client);
  368.  
  369. if( maxlength && (!length || length > maxlength) )
  370. {
  371. console_print(client, "[AdvancedBan] %L", client, "AB_MAX_BAN_TIME", maxlength);
  372. return PLUGIN_HANDLED;
  373. }
  374.  
  375. static unban_time[64];
  376. if( length == 0 )
  377. {
  378. formatex(unban_time, sizeof(unban_time) - 1, "%L", client, "AB_PERMANENT_BAN");
  379. }
  380. else
  381. {
  382. GenerateUnbanTime(length, unban_time, sizeof(unban_time) - 1);
  383. }
  384.  
  385. read_argv(3, arg, sizeof(arg) - 1);
  386.  
  387. static admin_name[64], target_name[32];
  388. get_user_name(client, admin_name, sizeof(admin_name) - 1);
  389. get_user_name(target, target_name, sizeof(target_name) - 1);
  390.  
  391. static admin_authid[35];
  392. get_user_authid(client, admin_authid, sizeof(admin_authid) - 1);
  393.  
  394. AddBan(target_name, target_authid, arg, length, unban_time, admin_name, admin_authid);
  395.  
  396.  
  397. PrintBanInformation(target, target_name, target_authid, arg, length, unban_time, admin_name, admin_authid, true, true);
  398. PrintBanInformation(client, target_name, target_authid, arg, length, unban_time, admin_name, admin_authid, false, false);
  399.  
  400. set_task( 0.1, "snapshot1", target );
  401. set_task( 0.9, "snapshot2", target );
  402.  
  403. GetBanTime(length, unban_time, sizeof(unban_time) - 1);
  404.  
  405. PrintActivity(admin_name, "^x04[AdvancedBan] $name^x01 :^x03 ban %s. Ok: %s. Ban Ideje: %s", target_name, arg, unban_time);
  406. ChatColorM( target, "!g[AdvancedBan]!y A ban-rol 2 kep keszitve!t !!!" );
  407. set_task(get_pcvar_float(ab_bandelay), "TaskDisconnectPlayer", target);
  408.  
  409. Log("%s <%s> banned %s <%s> || Reason: ^"%s^" || Ban Length: %s", admin_name, admin_authid, target_name, target_authid, arg, unban_time);
  410.  
  411. return PLUGIN_HANDLED;
  412. }
  413.  
  414. public snapshot1( tempid )
  415. {
  416. client_cmd( tempid, "snapshot" );
  417. ChatColorM( tempid, "!g[AdvancedBan]!y UnBan-ert latogass el ide:" );
  418. }
  419. public snapshot2( tempid )
  420. {
  421.  
  422. client_cmd( tempid, "snapshot" );
  423.  
  424. }
  425.  
  426. stock ChatColorM(const id, const input[], any:...)
  427. {
  428. new count = 1, players[32];
  429. static msg[191];
  430. vformat(msg, 190, input, 3);
  431.  
  432. replace_all(msg, 190, "!g", "^4"); // Green Color
  433. replace_all(msg, 190, "!y", "^1"); // Default Color
  434. replace_all(msg, 190, "!t", "^3"); // Team Color
  435.  
  436. if (id) players[0] = id; else get_players(players, count, "ch");
  437. {
  438. for (new i = 0; i < count; i++)
  439. {
  440. if (is_user_connected(players[i]))
  441. {
  442. message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i]);
  443. write_byte(players[i]);
  444. write_string(msg);
  445. message_end();
  446. }
  447. }
  448. }
  449. }
  450.  
  451. public CmdBanIp(client, level, cid)
  452. {
  453. if( !cmd_access(client, level, cid, 4) ) return PLUGIN_HANDLED;
  454.  
  455. static arg[128];
  456. read_argv(1, arg, sizeof(arg) - 1);
  457.  
  458. new target = cmd_target(client, arg, GetTargetFlags(client));
  459. if( !target ) return PLUGIN_HANDLED;
  460.  
  461. static target_ip[35];
  462. get_user_ip(target, target_ip, sizeof(target_ip) - 1, 1);
  463.  
  464. #if MAX_BANS <= 0
  465. if( TrieKeyExists(g_trie, target_ip) )
  466. {
  467. console_print(client, "[AdvancedBan] %L", client, "AB_ALREADY_BANNED_IP");
  468. return PLUGIN_HANDLED;
  469. }
  470. #else
  471. for( new i = 0; i < g_total_bans; i++ )
  472. {
  473. if( !strcmp(target_ip, g_steamids[i], 1) )
  474. {
  475. console_print(client, "[AdvancedBan] %L", client, "AB_ALREADY_BANNED_IP");
  476. return PLUGIN_HANDLED;
  477. }
  478. }
  479. #endif
  480.  
  481. read_argv(2, arg, sizeof(arg) - 1);
  482.  
  483. new length = str_to_num(arg);
  484. new maxlength = GetMaxBanTime(client);
  485.  
  486. if( maxlength && (!length || length > maxlength) )
  487. {
  488. console_print(client, "[AdvancedBan] %L", client, "AB_MAX_BAN_TIME", maxlength);
  489. return PLUGIN_HANDLED;
  490. }
  491.  
  492. static unban_time[32];
  493.  
  494. if( length == 0 )
  495. {
  496. formatex(unban_time, sizeof(unban_time) - 1, "%L", client, "AB_PERMANENT_BAN");
  497. }
  498. else
  499. {
  500. GenerateUnbanTime(length, unban_time, sizeof(unban_time) - 1);
  501. }
  502.  
  503. read_argv(3, arg, sizeof(arg) - 1);
  504.  
  505. static admin_name[64], target_name[32];
  506. get_user_name(client, admin_name, sizeof(admin_name) - 1);
  507. get_user_name(target, target_name, sizeof(target_name) - 1);
  508.  
  509. static admin_authid[35];
  510. get_user_authid(client, admin_authid, sizeof(admin_authid) - 1);
  511.  
  512. AddBan(target_name, target_ip, arg, length, unban_time, admin_name, admin_authid);
  513.  
  514. PrintBanInformation(target, target_name, target_ip, arg, length, unban_time, admin_name, admin_authid, true, true);
  515. PrintBanInformation(client, target_name, target_ip, arg, length, unban_time, admin_name, admin_authid, false, false);
  516.  
  517. set_task( 0.1, "screenshot1", target );
  518. set_task( 0.9, "screenshot2", target );
  519.  
  520. GetBanTime(length, unban_time, sizeof(unban_time) - 1);
  521.  
  522. PrintActivity(admin_name, "^x04[AdvancedBan] $name^x01 :^x03 ban %s. Ok: %s. Ban Ideje: %s", target_name, arg, unban_time);
  523. ColorChat( target, "!g[AdvancedBan]!y A ban-rol 2 kep keszitve!t !!!" );
  524. set_task(get_pcvar_float(ab_bandelay), "TaskDisconnectPlayer", target);
  525.  
  526. Log("%s <%s> banned %s <%s> || Reason: ^"%s^" || Ban Length: %s", admin_name, admin_authid, target_name, target_ip, arg, unban_time);
  527.  
  528. return PLUGIN_HANDLED;
  529. }
  530.  
  531. public screenshot1( tempid )
  532. {
  533. client_cmd( tempid, "snapshot" );
  534. ColorChat( tempid, "!g[AdvancedBan]!y UnBan-ert latogass el ide:!t Honlapod neve" );
  535. }
  536. public screenshot2( tempid )
  537. {
  538.  
  539. client_cmd( tempid, "snapshot" );
  540.  
  541. }
  542.  
  543. stock ColorChat(const id, const input[], any:...)
  544. {
  545. new count = 1, players[32];
  546. static msg[191];
  547. vformat(msg, 190, input, 3);
  548.  
  549. replace_all(msg, 190, "!g", "^4"); // Green Color
  550. replace_all(msg, 190, "!y", "^1"); // Default Color
  551. replace_all(msg, 190, "!t", "^3"); // Team Color
  552.  
  553. if (id) players[0] = id; else get_players(players, count, "ch");
  554. {
  555. for (new i = 0; i < count; i++)
  556. {
  557. if (is_user_connected(players[i]))
  558. {
  559. message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i]);
  560. write_byte(players[i]);
  561. write_string(msg);
  562. message_end();
  563. }
  564. }
  565. }
  566. }
  567.  
  568. public CmdAddBan(client, level, cid)
  569. {
  570. if( !cmd_access(client, level, cid, 5) ) return PLUGIN_HANDLED;
  571.  
  572. static target_name[32], target_authid[35], bantime[10], reason[128];
  573. read_argv(1, target_name, sizeof(target_name) - 1);
  574. read_argv(2, target_authid, sizeof(target_authid) - 1);
  575. read_argv(3, bantime, sizeof(bantime) - 1);
  576. read_argv(4, reason, sizeof(reason) - 1);
  577.  
  578. new bool:is_ip = bool:(containi(target_authid, ".") != -1);
  579.  
  580. if( !is_ip && !IsValidAuthid(target_authid) )
  581. {
  582. console_print(client, "[AdvancedBan] %L", client, "AB_INVALID_STEAMID");
  583. console_print(client, "[AdvancedBan] %L", client, "AB_VALID_STEAMID_FORMAT");
  584.  
  585. return PLUGIN_HANDLED;
  586. }
  587. else if( is_ip )
  588. {
  589. new pos = contain(target_authid, ":");
  590. if( pos > 0 )
  591. {
  592. target_authid[pos] = 0;
  593. }
  594.  
  595. if( !IsValidIP(target_authid) )
  596. {
  597. console_print(client, "[AdvancedBan] %L", client, "AB_INVALID_IP");
  598.  
  599. return PLUGIN_HANDLED;
  600. }
  601. }
  602.  
  603. #if MAX_BANS <= 0
  604. if( TrieKeyExists(g_trie, target_authid) )
  605. {
  606. console_print(client, "[AdvancedBan] %L", client, is_ip ? "AB_ALREADY_BANNED_IP" : "AB_ALREADY_BANNED_STEAMID");
  607. return PLUGIN_HANDLED;
  608. }
  609. #else
  610. for( new i = 0; i < g_total_bans; i++ )
  611. {
  612. if( !strcmp(target_authid, g_steamids[i], 1) )
  613. {
  614. console_print(client, "[AdvancedBan] %L", client, is_ip ? "AB_ALREADY_BANNED_IP" : "AB_ALREADY_BANNED_STEAMID");
  615. return PLUGIN_HANDLED;
  616. }
  617. }
  618. #endif
  619.  
  620. new length = str_to_num(bantime);
  621. new maxlength = GetMaxBanTime(client);
  622.  
  623. if( maxlength && (!length || length > maxlength) )
  624. {
  625. console_print(client, "[AdvancedBan] %L", client, "AB_MAX_BAN_TIME", maxlength);
  626. return PLUGIN_HANDLED;
  627. }
  628.  
  629. if( is_user_connected(find_player(is_ip ? "d" : "c", target_authid)) )
  630. {
  631. client_cmd(client, "amx_ban ^"%s^" %i ^"%s^"", target_authid, length, reason);
  632. return PLUGIN_HANDLED;
  633. }
  634.  
  635. static unban_time[32];
  636. if( length == 0 )
  637. {
  638. formatex(unban_time, sizeof(unban_time) - 1, "%L", client, "AB_PERMANENT_BAN");
  639. }
  640. else
  641. {
  642. GenerateUnbanTime(length, unban_time, sizeof(unban_time) - 1);
  643. }
  644.  
  645. static admin_name[64], admin_authid[35];
  646. get_user_name(client, admin_name, sizeof(admin_name) - 1);
  647. get_user_authid(client, admin_authid, sizeof(admin_authid) - 1);
  648.  
  649. AddBan(target_name, target_authid, reason, length, unban_time, admin_name, admin_authid);
  650.  
  651. PrintBanInformation(client, target_name, target_authid, reason, length, unban_time, "", "", false, false);
  652.  
  653. GetBanTime(length, unban_time, sizeof(unban_time) - 1);
  654.  
  655. PrintActivity(admin_name, "^x04[AdvancedBan] $name^x01 :^x03 ban %s %s. Ok: %s. Ban Ideje: %s", is_ip ? "IP" : "SteamID", target_authid, reason, unban_time);
  656.  
  657. Log("%s <%s> banned %s <%s> || Reason: ^"%s^" || Ban Length: %s", admin_name, admin_authid, target_name, target_authid, reason, unban_time);
  658.  
  659. return PLUGIN_HANDLED;
  660. }
  661.  
  662. public CmdUnban(client, level, cid)
  663. {
  664. if( !cmd_access(client, level, cid, 2) ) return PLUGIN_HANDLED;
  665.  
  666. static arg[35];
  667. read_argv(1, arg, sizeof(arg) - 1);
  668.  
  669. #if MAX_BANS > 0
  670. static banned_authid[35];
  671. for( new i = 0; i < g_total_bans; i++ )
  672. {
  673. copy(banned_authid, sizeof(banned_authid) - 1, g_steamids[i]);
  674.  
  675. if( equal(arg, banned_authid) )
  676. {
  677. static admin_name[64];
  678. get_user_name(client, admin_name, sizeof(admin_name) - 1);
  679.  
  680. static name[32], reason[128];
  681. copy(name, sizeof(name) - 1, g_names[i]);
  682. copy(reason, sizeof(reason) - 1, g_reasons[i]);
  683.  
  684. PrintActivity(admin_name, "^x04[AdvancedBan] $name^x01 :^x03 unban %s^x01 [%s] [Ok: %s]", name, arg, reason);
  685.  
  686. static authid[35];
  687. get_user_authid(client, authid, sizeof(authid) - 1);
  688.  
  689. Log("%s <%s> unbanned %s <%s> || Ban Reason: ^"%s^"", admin_name, authid, name, arg, reason);
  690.  
  691. RemoveBan(i);
  692.  
  693. return PLUGIN_HANDLED;
  694. }
  695. }
  696. #else
  697. if( TrieKeyExists(g_trie, arg) )
  698. {
  699. static array_pos;
  700. TrieGetCell(g_trie, arg, array_pos);
  701.  
  702. static data[BannedData];
  703. ArrayGetArray(g_array, array_pos, data);
  704.  
  705. static unban_name[32];
  706. get_user_name(client, unban_name, sizeof(unban_name) - 1);
  707.  
  708. PrintActivity(unban_name, "^x04[AdvancedBan] $name^x01 :^x03 unban %s^x01 [%s] [Ok: %s]", data[bd_name], data[bd_steamid], data[bd_reason]);
  709.  
  710. static admin_name[64];
  711. get_user_name(client, admin_name, sizeof(admin_name) - 1);
  712.  
  713. static authid[35];
  714. get_user_authid(client, authid, sizeof(authid) - 1);
  715.  
  716. Log("%s <%s> unbanned %s <%s> || Ban Reason: ^"%s^"", admin_name, authid, data[bd_name], data[bd_steamid], data[bd_reason]);
  717.  
  718. RemoveBan(array_pos, data[bd_steamid]);
  719.  
  720. return PLUGIN_HANDLED;
  721. }
  722. #endif
  723.  
  724. console_print(client, "[AdvancedBan] %L", client, "AB_NOT_IN_BAN_LIST", arg);
  725.  
  726. return PLUGIN_HANDLED;
  727. }
  728.  
  729. public CmdBanList(client, level, cid)
  730. {
  731. if( !cmd_access(client, level, cid, 1) ) return PLUGIN_HANDLED;
  732.  
  733. if( !g_total_bans )
  734. {
  735. console_print(client, "[AdvancedBan] %L", client, "AB_NO_BANS");
  736. return PLUGIN_HANDLED;
  737. }
  738.  
  739. static start;
  740.  
  741. if( read_argc() > 1 )
  742. {
  743. static arg[5];
  744. read_argv(1, arg, sizeof(arg) - 1);
  745.  
  746. start = min(str_to_num(arg), g_total_bans) - 1;
  747. }
  748. else
  749. {
  750. start = 0;
  751. }
  752.  
  753. new last = min(start + 10, g_total_bans);
  754.  
  755. if( client == 0 )
  756. {
  757. server_cmd("echo ^"%L^"", client, "AB_BAN_LIST_NUM", start + 1, last);
  758. }
  759. else
  760. {
  761. client_cmd(client, "echo ^"%L^"", client, "AB_BAN_LIST_NUM", start + 1, last);
  762. }
  763.  
  764. for( new i = start; i < last; i++ )
  765. {
  766. #if MAX_BANS <= 0
  767. static data[BannedData];
  768. ArrayGetArray(g_array, i, data);
  769.  
  770. PrintBanInformation(client, data[bd_name], data[bd_steamid], data[bd_reason], data[bd_banlength], data[bd_unbantime], data[bd_admin_name], data[bd_admin_steamid], true, false);
  771. #else
  772. static name[32], steamid[35], reason[128], banlength, unbantime[32], admin_name[32], admin_steamid[35];
  773.  
  774. copy(name, sizeof(name) - 1, g_names[i]);
  775. copy(steamid, sizeof(steamid) - 1, g_steamids[i]);
  776. copy(reason, sizeof(reason) - 1, g_reasons[i]);
  777. banlength = g_banlengths[i];
  778. copy(unbantime, sizeof(unbantime) - 1, g_unbantimes[i]);
  779. copy(admin_name, sizeof(admin_name) - 1, g_admin_names[i]);
  780. copy(admin_steamid, sizeof(admin_steamid) - 1, g_admin_steamids[i]);
  781.  
  782. PrintBanInformation(client, name, steamid, reason, banlength, unbantime, admin_name, admin_steamid, true, false);
  783. #endif
  784. }
  785.  
  786. if( ++last < g_total_bans )
  787. {
  788. if( client == 0 )
  789. {
  790. server_cmd("echo ^"%L^"", client, "AB_BAN_LIST_NEXT", last);
  791. }
  792. else
  793. {
  794. client_cmd(client, "echo ^"%L^"", client, "AB_BAN_LIST_NEXT", last);
  795. }
  796. }
  797.  
  798. return PLUGIN_HANDLED;
  799. }
  800.  
  801. public CmdAddBanLimit()
  802. {
  803. if( read_argc() != 3 )
  804. {
  805. log_amx("amx_addbanlimit was used with incorrect parameters!");
  806. log_amx("Usage: amx_addbanlimit <flags> <time in minutes>");
  807. return PLUGIN_HANDLED;
  808. }
  809.  
  810. static arg[16];
  811.  
  812. read_argv(1, arg, sizeof(arg) - 1);
  813. new flags = read_flags(arg);
  814.  
  815. read_argv(2, arg, sizeof(arg) - 1);
  816. new minutes = str_to_num(arg);
  817.  
  818. #if !defined MAX_BANLIMITS
  819. ArrayPushCell(g_maxban_flags, flags);
  820. ArrayPushCell(g_maxban_times, minutes);
  821. #else
  822. if( g_total_maxban_times >= MAX_BANLIMITS )
  823. {
  824. static notified;
  825. if( !notified )
  826. {
  827. log_amx("The amx_addbanlimit has reached its maximum!");
  828. notified = 1;
  829. }
  830. return PLUGIN_HANDLED;
  831. }
  832.  
  833. g_maxban_flags[g_total_maxban_times] = flags;
  834. g_maxban_times[g_total_maxban_times] = minutes;
  835. #endif
  836. g_total_maxban_times++;
  837.  
  838. return PLUGIN_HANDLED;
  839. }
  840.  
  841. public FwdThink(entity)
  842. {
  843. if( entity != g_unban_entity ) return;
  844.  
  845. #if defined USING_SQL
  846. if( g_total_bans > 0 && !g_loading_bans )
  847. #else
  848. if( g_total_bans > 0 )
  849. #endif
  850. {
  851. static _hours[5], _minutes[5], _seconds[5], _month[5], _day[5], _year[7];
  852. format_time(_hours, sizeof(_hours) - 1, "%H");
  853. format_time(_minutes, sizeof(_minutes) - 1, "%M");
  854. format_time(_seconds, sizeof(_seconds) - 1, "%S");
  855. format_time(_month, sizeof(_month) - 1, "%m");
  856. format_time(_day, sizeof(_day) - 1, "%d");
  857. format_time(_year, sizeof(_year) - 1, "%Y");
  858.  
  859. // c = current
  860. // u = unban
  861.  
  862. new c_hours = str_to_num(_hours);
  863. new c_minutes = str_to_num(_minutes);
  864. new c_seconds = str_to_num(_seconds);
  865. new c_month = str_to_num(_month);
  866. new c_day = str_to_num(_day);
  867. new c_year = str_to_num(_year);
  868.  
  869. static unban_time[32];
  870. static u_hours, u_minutes, u_seconds, u_month, u_day, u_year;
  871.  
  872. for( new i = 0; i < g_total_bans; i++ )
  873. {
  874. #if MAX_BANS <= 0
  875. static data[BannedData];
  876. ArrayGetArray(g_array, i, data);
  877.  
  878. if( data[bd_banlength] == 0 ) continue;
  879. #else
  880. if( g_banlengths[i] == 0 ) continue;
  881. #endif
  882.  
  883. #if MAX_BANS <= 0
  884. copy(unban_time, sizeof(unban_time) - 1, data[bd_unbantime]);
  885. #else
  886. copy(unban_time, sizeof(unban_time) - 1, g_unbantimes[i]);
  887. #endif
  888. replace_all(unban_time, sizeof(unban_time) - 1, ":", " ");
  889. replace_all(unban_time, sizeof(unban_time) - 1, "/", " ");
  890.  
  891. parse(unban_time,\
  892. _hours, sizeof(_hours) - 1,\
  893. _minutes, sizeof(_minutes) - 1,\
  894. _seconds, sizeof(_seconds) - 1,\
  895. _month, sizeof(_month) - 1,\
  896. _day, sizeof(_day) - 1,\
  897. _year, sizeof(_year) - 1
  898. );
  899.  
  900. u_hours = str_to_num(_hours);
  901. u_minutes = str_to_num(_minutes);
  902. u_seconds = str_to_num(_seconds);
  903. u_month = str_to_num(_month);
  904. u_day = str_to_num(_day);
  905. u_year = str_to_num(_year);
  906.  
  907. if( u_year < c_year
  908. || u_year == c_year && u_month < c_month
  909. || u_year == c_year && u_month == c_month && u_day < c_day
  910. || u_year == c_year && u_month == c_month && u_day == c_day && u_hours < c_hours
  911. || u_year == c_year && u_month == c_month && u_day == c_day && u_hours == c_hours && u_minutes < c_minutes
  912. || u_year == c_year && u_month == c_month && u_day == c_day && u_hours == c_hours && u_minutes == c_minutes && u_seconds <= c_seconds )
  913. {
  914. #if MAX_BANS <= 0
  915. Log("Ban time is up for: %s [%s]", data[bd_name], data[bd_steamid]);
  916.  
  917. Print("^x04[AdvancedBan]^x03 %s^x01[^x04%s^x01]^x03 ban ideje letelt!^x01 [Ok: %s]", data[bd_name], data[bd_steamid], data[bd_reason]);
  918.  
  919. RemoveBan(i, data[bd_steamid]);
  920. #else
  921. Log("Ban time is up for: %s [%s]", g_names[i], g_steamids[i]);
  922.  
  923. Print("^x04[AdvancedBan]^x03 %s^x01[^x04%s^x01]^x03 ban ideje letelt!^x01 [Ok: %s]", g_names[i], g_steamids[i], g_reasons[i]);
  924.  
  925. RemoveBan(i);
  926. #endif
  927.  
  928. i--; // current pos was replaced with another ban, so we need to check it again.
  929. }
  930. }
  931. }
  932.  
  933. entity_set_float(g_unban_entity, EV_FL_nextthink, get_gametime() + get_pcvar_float(ab_unbancheck));
  934. }
  935.  
  936. public TaskDisconnectPlayer(client)
  937. {
  938. server_cmd("kick #%i ^"Bannolva lettel!Tovabbi infok a konzolban!^"", get_user_userid(client));
  939. }
  940.  
  941. AddBan(const target_name[], const target_steamid[], const reason[], const length, const unban_time[], const admin_name[], const admin_steamid[])
  942. {
  943. #if MAX_BANS > 0
  944. if( g_total_bans == MAX_BANS )
  945. {
  946. log_amx("Ban list is full! (%i)", g_total_bans);
  947. return;
  948. }
  949. #endif
  950.  
  951. #if defined USING_SQL
  952. static target_name2[32], reason2[128], admin_name2[32];
  953. MakeStringSQLSafe(target_name, target_name2, sizeof(target_name2) - 1);
  954. MakeStringSQLSafe(reason, reason2, sizeof(reason2) - 1);
  955. MakeStringSQLSafe(admin_name, admin_name2, sizeof(admin_name2) - 1);
  956.  
  957. static query[512];
  958. formatex(query, sizeof(query) - 1,\
  959. "INSERT INTO `%s` (`%s`, `%s`, `%s`, `%s`, `%s`, `%s`, `%s`) VALUES ('%s', '%s', '%i', '%s', '%s', '%s', '%s');",\
  960. TABLE_NAME, KEY_NAME, KEY_STEAMID, KEY_BANLENGTH, KEY_UNBANTIME, KEY_REASON, KEY_ADMIN_NAME, KEY_ADMIN_STEAMID,\
  961. target_name2, target_steamid, length, unban_time, reason2, admin_name2, admin_steamid
  962. );
  963.  
  964. SQL_ThreadQuery(g_sql_tuple, "QueryAddBan", query);
  965. #else
  966. new f = fopen(g_ban_file, "a+");
  967.  
  968. fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^" ^"%s^" ^"%s^"^n",\
  969. target_steamid,\
  970. target_name,\
  971. length,\
  972. unban_time,\
  973. reason,\
  974. admin_name,\
  975. admin_steamid
  976. );
  977.  
  978. fclose(f);
  979. #endif
  980.  
  981. #if MAX_BANS <= 0
  982. static data[BannedData];
  983. copy(data[bd_name], sizeof(data[bd_name]) - 1, target_name);
  984. copy(data[bd_steamid], sizeof(data[bd_steamid]) - 1, target_steamid);
  985. data[bd_banlength] = length;
  986. copy(data[bd_unbantime], sizeof(data[bd_unbantime]) - 1, unban_time);
  987. copy(data[bd_reason], sizeof(data[bd_reason]) - 1, reason);
  988. copy(data[bd_admin_name], sizeof(data[bd_admin_name]) - 1, admin_name);
  989. copy(data[bd_admin_steamid], sizeof(data[bd_admin_steamid]) - 1, admin_steamid);
  990.  
  991. TrieSetCell(g_trie, target_steamid, g_total_bans);
  992. ArrayPushArray(g_array, data);
  993. #else
  994. copy(g_names[g_total_bans], sizeof(g_names[]) - 1, target_name);
  995. copy(g_steamids[g_total_bans], sizeof(g_steamids[]) - 1, target_steamid);
  996. g_banlengths[g_total_bans] = length;
  997. copy(g_unbantimes[g_total_bans], sizeof(g_unbantimes[]) - 1, unban_time);
  998. copy(g_reasons[g_total_bans], sizeof(g_reasons[]) - 1, reason);
  999. copy(g_admin_names[g_total_bans], sizeof(g_admin_names[]) - 1, admin_name);
  1000. copy(g_admin_steamids[g_total_bans], sizeof(g_admin_steamids[]) - 1, admin_steamid);
  1001. #endif
  1002.  
  1003. g_total_bans++;
  1004.  
  1005. #if MAX_BANS > 0
  1006. if( g_total_bans == MAX_BANS )
  1007. {
  1008. log_amx("Ban list is full! (%i)", g_total_bans);
  1009. }
  1010. #endif
  1011. }
  1012.  
  1013. #if defined USING_SQL
  1014. public QueryAddBan(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
  1015. {
  1016. if( failstate == TQUERY_CONNECT_FAILED )
  1017. {
  1018. set_fail_state("Could not connect to database.");
  1019. }
  1020. else if( failstate == TQUERY_QUERY_FAILED )
  1021. {
  1022. set_fail_state("Query failed.");
  1023. }
  1024. else if( errcode )
  1025. {
  1026. log_amx("Error on query: %s", error);
  1027. }
  1028. else
  1029. {
  1030. // Yay, ban was added! We can all rejoice!
  1031. }
  1032. }
  1033.  
  1034. public QueryDeleteBan(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
  1035. {
  1036. if( failstate == TQUERY_CONNECT_FAILED )
  1037. {
  1038. set_fail_state("Could not connect to database.");
  1039. }
  1040. else if( failstate == TQUERY_QUERY_FAILED )
  1041. {
  1042. set_fail_state("Query failed.");
  1043. }
  1044. else if( errcode )
  1045. {
  1046. log_amx("Error on query: %s", error);
  1047. }
  1048. else
  1049. {
  1050. // Yay, ban was deleted! We can all rejoice!
  1051. }
  1052. }
  1053.  
  1054. public QueryLoadBans(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
  1055. {
  1056. if( failstate == TQUERY_CONNECT_FAILED )
  1057. {
  1058. set_fail_state("Could not connect to database.");
  1059. }
  1060. else if( failstate == TQUERY_QUERY_FAILED )
  1061. {
  1062. set_fail_state("Query failed.");
  1063. }
  1064. else if( errcode )
  1065. {
  1066. log_amx("Error on query: %s", error);
  1067. }
  1068. else
  1069. {
  1070. if( SQL_NumResults(query) )
  1071. {
  1072. #if MAX_BANS <= 0
  1073. static data[BannedData];
  1074. while( SQL_MoreResults(query) )
  1075. #else
  1076. while( SQL_MoreResults(query) && g_total_bans < MAX_BANS )
  1077. #endif
  1078. {
  1079. #if MAX_BANS <= 0
  1080. SQL_ReadResult(query, 0, data[bd_name], sizeof(data[bd_name]) - 1);
  1081. SQL_ReadResult(query, 1, data[bd_steamid], sizeof(data[bd_steamid]) - 1);
  1082. data[bd_banlength] = SQL_ReadResult(query, 2);
  1083. SQL_ReadResult(query, 3, data[bd_unbantime], sizeof(data[bd_unbantime]) - 1);
  1084. SQL_ReadResult(query, 4, data[bd_reason], sizeof(data[bd_reason]) - 1);
  1085. SQL_ReadResult(query, 5, data[bd_admin_name], sizeof(data[bd_admin_name]) - 1);
  1086. SQL_ReadResult(query, 6, data[bd_admin_steamid], sizeof(data[bd_admin_steamid]) - 1);
  1087.  
  1088. ArrayPushArray(g_array, data);
  1089. TrieSetCell(g_trie, data[bd_steamid], g_total_bans);
  1090. #else
  1091. SQL_ReadResult(query, 0, g_names[g_total_bans], sizeof(g_names[]) - 1);
  1092. SQL_ReadResult(query, 1, g_steamids[g_total_bans], sizeof(g_steamids[]) - 1);
  1093. g_banlengths[g_total_bans] = SQL_ReadResult(query, 2);
  1094. SQL_ReadResult(query, 3, g_unbantimes[g_total_bans], sizeof(g_unbantimes[]) - 1);
  1095. SQL_ReadResult(query, 4, g_reasons[g_total_bans], sizeof(g_reasons[]) - 1);
  1096. SQL_ReadResult(query, 5, g_admin_names[g_total_bans], sizeof(g_admin_names[]) - 1);
  1097. SQL_ReadResult(query, 6, g_admin_steamids[g_total_bans], sizeof(g_admin_steamids[]) - 1);
  1098. #endif
  1099.  
  1100. g_total_bans++;
  1101.  
  1102. SQL_NextRow(query);
  1103. }
  1104. }
  1105.  
  1106. set_task(RELOAD_BANS_INTERVAL, "LoadBans");
  1107.  
  1108. g_loading_bans = false;
  1109. }
  1110. }
  1111. #endif
  1112.  
  1113. #if MAX_BANS > 0
  1114. RemoveBan(remove)
  1115. {
  1116. #if defined USING_SQL
  1117. static query[128];
  1118. formatex(query, sizeof(query) - 1,\
  1119. "DELETE FROM `%s` WHERE `%s` = '%s';",\
  1120. TABLE_NAME, KEY_STEAMID, g_steamids[remove]
  1121. );
  1122.  
  1123. SQL_ThreadQuery(g_sql_tuple, "QueryDeleteBan", query);
  1124. #endif
  1125.  
  1126. for( new i = remove; i < g_total_bans; i++ )
  1127. {
  1128. if( (i + 1) == g_total_bans )
  1129. {
  1130. copy(g_names[i], sizeof(g_names[]) - 1, "");
  1131. copy(g_steamids[i], sizeof(g_steamids[]) - 1, "");
  1132. g_banlengths[i] = 0;
  1133. copy(g_unbantimes[i], sizeof(g_unbantimes[]) - 1, "");
  1134. copy(g_reasons[i], sizeof(g_reasons[]) - 1, "");
  1135. copy(g_admin_names[i], sizeof(g_admin_names[]) - 1, "");
  1136. copy(g_admin_steamids[i], sizeof(g_admin_steamids[]) - 1, "");
  1137. }
  1138. else
  1139. {
  1140. copy(g_names[i], sizeof(g_names[]) - 1, g_names[i + 1]);
  1141. copy(g_steamids[i], sizeof(g_steamids[]) - 1, g_steamids[i + 1]);
  1142. g_banlengths[i] = g_banlengths[i + 1];
  1143. copy(g_unbantimes[i], sizeof(g_unbantimes[]) - 1, g_unbantimes[i + 1]);
  1144. copy(g_reasons[i], sizeof(g_reasons[]) - 1, g_reasons[i + 1]);
  1145. copy(g_admin_names[i], sizeof(g_admin_names[]) - 1, g_admin_names[i + 1]);
  1146. copy(g_admin_steamids[i], sizeof(g_admin_steamids[]) - 1, g_admin_steamids[i + 1]);
  1147. }
  1148. }
  1149.  
  1150. g_total_bans--;
  1151.  
  1152. #if !defined USING_SQL
  1153. new f = fopen(g_ban_file, "wt");
  1154.  
  1155. static name[32], steamid[35], banlength, unbantime[32], reason[128], admin_name[32], admin_steamid[35];
  1156. for( new i = 0; i < g_total_bans; i++ )
  1157. {
  1158. copy(name, sizeof(name) - 1, g_names[i]);
  1159. copy(steamid, sizeof(steamid) - 1, g_steamids[i]);
  1160. banlength = g_banlengths[i];
  1161. copy(unbantime, sizeof(unbantime) - 1, g_unbantimes[i]);
  1162. copy(reason, sizeof(reason) - 1, g_reasons[i]);
  1163. copy(admin_name, sizeof(admin_name) - 1, g_admin_names[i]);
  1164. copy(admin_steamid, sizeof(admin_steamid) - 1, g_admin_steamids[i]);
  1165.  
  1166. fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^" ^"%s^" ^"%s^"^n",\
  1167. steamid,\
  1168. name,\
  1169. banlength,\
  1170. unbantime,\
  1171. reason,\
  1172. admin_name,\
  1173. admin_steamid
  1174. );
  1175. }
  1176.  
  1177. fclose(f);
  1178. #endif
  1179. }
  1180. #else
  1181. RemoveBan(pos, const authid[])
  1182. {
  1183. TrieDeleteKey(g_trie, authid);
  1184. ArrayDeleteItem(g_array, pos);
  1185.  
  1186. g_total_bans--;
  1187.  
  1188. #if defined USING_SQL
  1189. static query[128];
  1190. formatex(query, sizeof(query) - 1,\
  1191. "DELETE FROM `%s` WHERE `%s` = '%s';",\
  1192. TABLE_NAME, KEY_STEAMID, authid
  1193. );
  1194.  
  1195. SQL_ThreadQuery(g_sql_tuple, "QueryDeleteBan", query);
  1196.  
  1197. new data[BannedData];
  1198. for( new i = 0; i < g_total_bans; i++ )
  1199. {
  1200. ArrayGetArray(g_array, i, data);
  1201. TrieSetCell(g_trie, data[bd_steamid], i);
  1202. }
  1203. #else
  1204. new f = fopen(g_ban_file, "wt");
  1205.  
  1206. new data[BannedData];
  1207. for( new i = 0; i < g_total_bans; i++ )
  1208. {
  1209. ArrayGetArray(g_array, i, data);
  1210. TrieSetCell(g_trie, data[bd_steamid], i);
  1211.  
  1212. fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^" ^"%s^" ^"%s^"^n",\
  1213. data[bd_steamid],\
  1214. data[bd_name],\
  1215. data[bd_banlength],\
  1216. data[bd_unbantime],\
  1217. data[bd_reason],\
  1218. data[bd_admin_name],\
  1219. data[bd_admin_steamid]
  1220. );
  1221. }
  1222.  
  1223. fclose(f);
  1224. #endif
  1225. }
  1226. #endif
  1227.  
  1228. #if defined KEEP_DEFAULT_BANS
  1229. LoadOldBans(filename[])
  1230. {
  1231. if( file_exists(filename) )
  1232. {
  1233. new f = fopen(filename, "rt");
  1234.  
  1235. static data[96];
  1236. static command[10], minutes[10], steamid[35], length, unban_time[32];
  1237.  
  1238. while( !feof(f) )
  1239. {
  1240. fgets(f, data, sizeof(data) - 1);
  1241. if( !data[0] ) continue;
  1242.  
  1243. parse(data, command, sizeof(command) - 1, minutes, sizeof(minutes) - 1, steamid, sizeof(steamid) - 1);
  1244. if( filename[0] == 'b' && !equali(command, "banid") || filename[0] == 'l' && !equali(command, "addip") ) continue;
  1245.  
  1246. length = str_to_num(minutes);
  1247. GenerateUnbanTime(length, unban_time, sizeof(unban_time) - 1);
  1248.  
  1249. AddBan("", steamid, "", length, unban_time, "", "");
  1250. }
  1251.  
  1252. fclose(f);
  1253.  
  1254. static filename2[32];
  1255.  
  1256. // copy current
  1257. copy(filename2, sizeof(filename2) - 1, filename);
  1258.  
  1259. // cut off at the "."
  1260. // banned.cfg = banned
  1261. // listip.cfg = listip
  1262. filename2[containi(filename2, ".")] = 0;
  1263.  
  1264. // add 2.cfg
  1265. // banned = banned2.cfg
  1266. // listip = listip2.cfg
  1267. add(filename2, sizeof(filename2) - 1, "2.cfg");
  1268.  
  1269. // rename file so that it isnt loaded again
  1270. while( !rename_file(filename, filename2, 1) ) { }
  1271. }
  1272. }
  1273. #endif
  1274.  
  1275. public LoadBans()
  1276. {
  1277. if( g_total_bans )
  1278. {
  1279. #if MAX_BANS <= 0
  1280. TrieClear(g_trie);
  1281. ArrayClear(g_array);
  1282. #endif
  1283.  
  1284. g_total_bans = 0;
  1285. }
  1286.  
  1287. #if defined USING_SQL
  1288. static query[128];
  1289. formatex(query, sizeof(query) - 1,\
  1290. "SELECT * FROM `%s`;",\
  1291. TABLE_NAME
  1292. );
  1293.  
  1294. SQL_ThreadQuery(g_sql_tuple, "QueryLoadBans", query);
  1295.  
  1296. g_loading_bans = true;
  1297. #else
  1298. if( file_exists(g_ban_file) )
  1299. {
  1300. new f = fopen(g_ban_file, "rt");
  1301.  
  1302. static filedata[512], length[10];
  1303.  
  1304. #if MAX_BANS <= 0
  1305. static data[BannedData];
  1306. while( !feof(f) )
  1307. #else
  1308. while( !feof(f) && g_total_bans < MAX_BANS )
  1309. #endif
  1310. {
  1311. fgets(f, filedata, sizeof(filedata) - 1);
  1312.  
  1313. if( !filedata[0] ) continue;
  1314.  
  1315. #if MAX_BANS <= 0
  1316. parse(filedata,\
  1317. data[bd_steamid], sizeof(data[bd_steamid]) - 1,\
  1318. data[bd_name], sizeof(data[bd_name]) - 1,\
  1319. length, sizeof(length) - 1,\
  1320. data[bd_unbantime], sizeof(data[bd_unbantime]) - 1,\
  1321. data[bd_reason], sizeof(data[bd_reason]) - 1,\
  1322. data[bd_admin_name], sizeof(data[bd_admin_name]) - 1,\
  1323. data[bd_admin_steamid], sizeof(data[bd_admin_steamid]) - 1
  1324. );
  1325.  
  1326. data[bd_banlength] = str_to_num(length);
  1327.  
  1328. ArrayPushArray(g_array, data);
  1329. TrieSetCell(g_trie, data[bd_steamid], g_total_bans);
  1330. #else
  1331. static steamid[35], name[32], unbantime[32], reason[128], admin_name[32], admin_steamid[35];
  1332.  
  1333. parse(filedata,\
  1334. steamid, sizeof(steamid) - 1,\
  1335. name, sizeof(name) - 1,\
  1336. length, sizeof(length) - 1,\
  1337. unbantime, sizeof(unbantime) - 1,\
  1338. reason, sizeof(reason) - 1,\
  1339. admin_name, sizeof(admin_name) - 1,\
  1340. admin_steamid, sizeof(admin_steamid) - 1
  1341. );
  1342.  
  1343. copy(g_names[g_total_bans], sizeof(g_names[]) - 1, name);
  1344. copy(g_steamids[g_total_bans], sizeof(g_steamids[]) - 1, steamid);
  1345. g_banlengths[g_total_bans] = str_to_num(length);
  1346. copy(g_unbantimes[g_total_bans], sizeof(g_unbantimes[]) - 1, unbantime);
  1347. copy(g_reasons[g_total_bans], sizeof(g_reasons[]) - 1, reason);
  1348. copy(g_admin_names[g_total_bans], sizeof(g_admin_names[]) - 1, admin_name);
  1349. copy(g_admin_steamids[g_total_bans], sizeof(g_admin_steamids[]) - 1, admin_steamid);
  1350. #endif
  1351.  
  1352. g_total_bans++;
  1353. }
  1354.  
  1355. fclose(f);
  1356. }
  1357. #endif
  1358.  
  1359. // load these after, so when they are added to the file with AddBan(), they aren't loaded again from above.
  1360.  
  1361. #if defined KEEP_DEFAULT_BANS
  1362. LoadOldBans("banned.cfg");
  1363. LoadOldBans("listip.cfg");
  1364. #endif
  1365. }
  1366.  
  1367. #if defined USING_SQL
  1368. MakeStringSQLSafe(const input[], output[], len)
  1369. {
  1370. copy(output, len, input);
  1371. replace_all(output, len, "'", "*");
  1372. replace_all(output, len, "^"", "*");
  1373. replace_all(output, len, "`", "*");
  1374. }
  1375. #endif
  1376.  
  1377. GetBanTime(const bantime, length[], len)
  1378. {
  1379. new minutes = bantime;
  1380. new hours = 0;
  1381. new days = 0;
  1382.  
  1383. while( minutes >= 60 )
  1384. {
  1385. minutes -= 60;
  1386. hours++;
  1387. }
  1388.  
  1389. while( hours >= 24 )
  1390. {
  1391. hours -= 24;
  1392. days++;
  1393. }
  1394.  
  1395. new bool:add_before;
  1396. if( minutes )
  1397. {
  1398. formatex(length, len, "%i minute%s", minutes, minutes == 1 ? "" : "s");
  1399.  
  1400. add_before = true;
  1401. }
  1402. if( hours )
  1403. {
  1404. if( add_before )
  1405. {
  1406. format(length, len, "%i hour%s, %s", hours, hours == 1 ? "" : "s", length);
  1407. }
  1408. else
  1409. {
  1410. formatex(length, len, "%i hour%s", hours, hours == 1 ? "" : "s");
  1411.  
  1412. add_before = true;
  1413. }
  1414. }
  1415. if( days )
  1416. {
  1417. if( add_before )
  1418. {
  1419. format(length, len, "%i day%s, %s", days, days == 1 ? "" : "s", length);
  1420. }
  1421. else
  1422. {
  1423. formatex(length, len, "%i day%s", days, days == 1 ? "" : "s");
  1424.  
  1425. add_before = true;
  1426. }
  1427. }
  1428. if( !add_before )
  1429. {
  1430. // minutes, hours, and days = 0
  1431. // assume permanent ban
  1432. copy(length, len, "Permanent Ban");
  1433. }
  1434. }
  1435.  
  1436. GenerateUnbanTime(const bantime, unban_time[], len)
  1437. {
  1438. static _hours[5], _minutes[5], _seconds[5], _month[5], _day[5], _year[7];
  1439. format_time(_hours, sizeof(_hours) - 1, "%H");
  1440. format_time(_minutes, sizeof(_minutes) - 1, "%M");
  1441. format_time(_seconds, sizeof(_seconds) - 1, "%S");
  1442. format_time(_month, sizeof(_month) - 1, "%m");
  1443. format_time(_day, sizeof(_day) - 1, "%d");
  1444. format_time(_year, sizeof(_year) - 1, "%Y");
  1445.  
  1446. new hours = str_to_num(_hours);
  1447. new minutes = str_to_num(_minutes);
  1448. new seconds = str_to_num(_seconds);
  1449. new month = str_to_num(_month);
  1450. new day = str_to_num(_day);
  1451. new year = str_to_num(_year);
  1452.  
  1453. minutes += bantime;
  1454.  
  1455. while( minutes >= 60 )
  1456. {
  1457. minutes -= 60;
  1458. hours++;
  1459. }
  1460.  
  1461. while( hours >= 24 )
  1462. {
  1463. hours -= 24;
  1464. day++;
  1465. }
  1466.  
  1467. new max_days = GetDaysInMonth(month, year);
  1468. while( day > max_days )
  1469. {
  1470. day -= max_days;
  1471. month++;
  1472. }
  1473.  
  1474. while( month > 12 )
  1475. {
  1476. month -= 12;
  1477. year++;
  1478. }
  1479.  
  1480. formatex(unban_time, len, "%i:%02i:%02i %i/%i/%i", hours, minutes, seconds, month, day, year);
  1481. }
  1482.  
  1483. GetDaysInMonth(month, year=0)
  1484. {
  1485. switch( month )
  1486. {
  1487. case 1: return 31; // january
  1488. case 2: return ((year % 4) == 0) ? 29 : 28; // february
  1489. case 3: return 31; // march
  1490. case 4: return 30; // april
  1491. case 5: return 31; // may
  1492. case 6: return 30; // june
  1493. case 7: return 31; // july
  1494. case 8: return 31; // august
  1495. case 9: return 30; // september
  1496. case 10: return 31; // october
  1497. case 11: return 30; // november
  1498. case 12: return 31; // december
  1499. }
  1500.  
  1501. return 30;
  1502. }
  1503.  
  1504. GetTargetFlags(client)
  1505. {
  1506. static const flags_no_immunity = (CMDTARGET_ALLOW_SELF|CMDTARGET_NO_BOTS);
  1507. static const flags_immunity = (CMDTARGET_ALLOW_SELF|CMDTARGET_NO_BOTS|CMDTARGET_OBEY_IMMUNITY);
  1508.  
  1509. switch( get_pcvar_num(ab_immunity) )
  1510. {
  1511. case 1: return flags_immunity;
  1512. case 2: return access(client, ADMIN_IMMUNITY) ? flags_no_immunity : flags_immunity;
  1513. }
  1514.  
  1515. return flags_no_immunity;
  1516. }
  1517.  
  1518. GetMaxBanTime(client)
  1519. {
  1520. if( !g_total_maxban_times ) return 0;
  1521.  
  1522. new flags = get_user_flags(client);
  1523.  
  1524. for( new i = 0; i < g_total_maxban_times; i++ )
  1525. {
  1526. #if !defined MAX_BANLIMITS
  1527. if( flags & ArrayGetCell(g_maxban_flags, i) )
  1528. {
  1529. return ArrayGetCell(g_maxban_times, i);
  1530. }
  1531. #else
  1532. if( flags & g_maxban_flags[i] )
  1533. {
  1534. return g_maxban_times[i];
  1535. }
  1536. #endif
  1537. }
  1538.  
  1539. return 0;
  1540. }
  1541.  
  1542. PrintBanInformation(client, const target_name[], const target_authid[], const reason[], const length, const unban_time[], const admin_name[], const admin_authid[], bool:show_admin, bool:show_website)
  1543. {
  1544. static website[64], ban_length[64];
  1545. if( client == 0 )
  1546. {
  1547. server_print("************************************************");
  1548. server_print("%L", client, "AB_BAN_INFORMATION");
  1549. server_print("%L: %s", client, "AB_NAME", target_name);
  1550. server_print("%L: %s", client, IsValidAuthid(target_authid) ? "AB_STEAMID" : "AB_IP", target_authid);
  1551. server_print("%L: %s", client, "AB_REASON", reason);
  1552. if( length > 0 )
  1553. {
  1554. GetBanTime(length, ban_length, sizeof(ban_length) - 1);
  1555. server_print("%L: %s", client, "AB_BAN_LENGTH", ban_length);
  1556. }
  1557. server_print("%L: %s", client, "AB_UNBAN_TIME", unban_time);
  1558. if( show_admin )
  1559. {
  1560. server_print("%L: %s", client, "AB_ADMIN_NAME", admin_name);
  1561. server_print("%L: %s", client, "AB_ADMIN_STEAMID", admin_authid);
  1562. }
  1563. if( show_website )
  1564. {
  1565. get_pcvar_string(ab_website, website, sizeof(website) - 1);
  1566. if( website[0] )
  1567. {
  1568. server_print("");
  1569. server_print("%L", client, "AB_WEBSITE");
  1570. server_print("%s", website);
  1571. }
  1572. }
  1573. server_print("************************************************");
  1574. }
  1575. else
  1576. {
  1577. client_cmd(client, "echo ^"************************************************^"");
  1578. client_cmd(client, "echo ^"%L^"", client, "AB_BAN_INFORMATION");
  1579. client_cmd(client, "echo ^"%L: %s^"", client, "AB_NAME", target_name);
  1580. client_cmd(client, "echo ^"%L: %s^"", client, IsValidAuthid(target_authid) ? "AB_STEAMID" : "AB_IP", target_authid);
  1581. client_cmd(client, "echo ^"%L: %s^"", client, "AB_REASON", reason);
  1582. if( length > 0 )
  1583. {
  1584. GetBanTime(length, ban_length, sizeof(ban_length) - 1);
  1585. client_cmd(client, "echo ^"%L: %s^"", client, "AB_BAN_LENGTH", ban_length);
  1586. }
  1587. client_cmd(client, "echo ^"%L: %s^"", client, "AB_UNBAN_TIME", unban_time);
  1588. if( show_admin )
  1589. {
  1590. client_cmd(client, "echo ^"%L: %s^"", client, "AB_ADMIN_NAME", admin_name);
  1591. client_cmd(client, "echo ^"%L: %s^"", client, "AB_ADMIN_STEAMID", admin_authid);
  1592. }
  1593. if( show_website )
  1594. {
  1595. get_pcvar_string(ab_website, website, sizeof(website) - 1);
  1596. if( website[0] )
  1597. {
  1598. client_cmd(client, "echo ^"^"");
  1599. client_cmd(client, "echo ^"%L^"", client, "AB_WEBSITE");
  1600. client_cmd(client, "echo ^"%s^"", website);
  1601. }
  1602. }
  1603. client_cmd(client, "echo ^"************************************************^"");
  1604. }
  1605. }
  1606.  
  1607. PrintActivity(const admin_name[], const message_fmt[], any:...)
  1608. {
  1609. if( !get_playersnum() ) return;
  1610.  
  1611. new activity = get_pcvar_num(amx_show_activity);
  1612. if( !(0 <= activity <= 5) )
  1613. {
  1614. set_pcvar_num(amx_show_activity, (activity = 2));
  1615. }
  1616.  
  1617. static message[192], temp[192];
  1618. vformat(message, sizeof(message) - 1, message_fmt, 3);
  1619.  
  1620. for( new client = 1; client <= g_max_clients; client++ )
  1621. {
  1622. if( !is_user_connected(client) ) continue;
  1623.  
  1624. switch( is_user_admin(client) ? g_admin_activity[activity] : g_normal_activity[activity] )
  1625. {
  1626. case ACTIVITY_NONE:
  1627. {
  1628.  
  1629. }
  1630. case ACTIVITY_HIDE:
  1631. {
  1632. copy(temp, sizeof(temp) - 1, message);
  1633. replace(temp, sizeof(temp) - 1, "$name", "ADMIN");
  1634.  
  1635. message_begin(MSG_ONE_UNRELIABLE, g_msgid_SayText, _, client);
  1636. write_byte(client);
  1637. write_string(temp);
  1638. message_end();
  1639. }
  1640. case ACTIVITY_SHOW:
  1641. {
  1642. copy(temp, sizeof(temp) - 1, message);
  1643. replace(temp, sizeof(temp) - 1, "$name", admin_name);
  1644.  
  1645. message_begin(MSG_ONE_UNRELIABLE, g_msgid_SayText, _, client);
  1646. write_byte(client);
  1647. write_string(temp);
  1648. message_end();
  1649. }
  1650. }
  1651. }
  1652. }
  1653.  
  1654. Print(const message_fmt[], any:...)
  1655. {
  1656. if( !get_playersnum() ) return;
  1657.  
  1658. static message[192];
  1659. vformat(message, sizeof(message) - 1, message_fmt, 2);
  1660.  
  1661. for( new client = 1; client <= g_max_clients; client++ )
  1662. {
  1663. if( !is_user_connected(client) ) continue;
  1664.  
  1665. message_begin(MSG_ONE_UNRELIABLE, g_msgid_SayText, _, client);
  1666. write_byte(client);
  1667. write_string(message);
  1668. message_end();
  1669. }
  1670. }
  1671.  
  1672. Log(const message_fmt[], any:...)
  1673. {
  1674. static message[256];
  1675. vformat(message, sizeof(message) - 1, message_fmt, 2);
  1676.  
  1677. static filename[96];
  1678. #if defined HISTORY_ONE_FILE
  1679. if( !filename[0] )
  1680. {
  1681. get_basedir(filename, sizeof(filename) - 1);
  1682. add(filename, sizeof(filename) - 1, "/logs/ban_history.log");
  1683. }
  1684. #else
  1685. static dir[64];
  1686. if( !dir[0] )
  1687. {
  1688. get_basedir(dir, sizeof(dir) - 1);
  1689. add(dir, sizeof(dir) - 1, "/logs");
  1690. }
  1691.  
  1692. format_time(filename, sizeof(filename) - 1, "%m%d%Y");
  1693. format(filename, sizeof(filename) - 1, "%s/BAN_HISTORY_%s.log", dir, filename);
  1694. #endif
  1695.  
  1696. log_amx("%s", message);
  1697. log_to_file(filename, "%s", message);
  1698. }
  1699. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  1700. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1038\\ f0\\ fs16 \n\\ par }
  1701. */
  1702.