Advertisement
mforce

Advanced Bans BUGFIXED

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