Advertisement
Guest User

Untitled

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