hlmod.hu

Magyar Half-Life Mód közösség!
Pontos idő: 2025.06.16. 20:30



Jelenlévő felhasználók

Jelenleg 367 felhasználó van jelen :: 2 regisztrált, 0 rejtett és 365 vendég

A legtöbb felhasználó (2761 fő) 2025.01.09. 20:06-kor tartózkodott itt.

Regisztrált felhasználók: Bing [Bot], Google [Bot]az elmúlt 5 percben aktív felhasználók alapján

Utoljára aktív
Ahhoz hogy lásd ki volt utoljára aktív, be kell jelentkezned.



Az oldal teljeskörű
használatához regisztrálj.

Regisztráció

Kereső


Új téma nyitása Hozzászólás a témához  [2 hozzászólás ] 
Szerző Üzenet
 Hozzászólás témája: advanced bans
HozzászólásElküldve:2012.12.26. 19:25 
Helo!

Azt szeretném kérni, hogy ezt a plugint úgy írnátok át nekem, hogy amikor banolnak egy embert arról screensht készüljön.

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


Hozzászólás jelentése
Vissza a tetejére
   
 Hozzászólás témája: Re: advanced bans
HozzászólásElküldve:2013.05.05. 04:33 
Offline
Tud valamit

Csatlakozott:2013.01.21. 10:10
Hozzászólások:138
Megköszönt másnak: 20 alkalommal
Megköszönték neki: 6 alkalommal
TESSÉK:

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

_________________
See you next time! :)

Ha hasznosnak találtad a hozzászólásomat, köszönd meg a Kép lenyomásával..!! :)


Hozzászólás jelentése
Vissza a tetejére
   
Hozzászólások megjelenítése: Rendezés 
Új téma nyitása Hozzászólás a témához  [2 hozzászólás ] 


Ki van itt

Jelenlévő fórumozók: nincs regisztrált felhasználó valamint 5 vendég


Nyithatsz új témákat ebben a fórumban.
Válaszolhatsz egy témára ebben a fórumban.
Nem szerkesztheted a hozzászólásaidat ebben a fórumban.
Nem törölheted a hozzászólásaidat ebben a fórumban.
Nem küldhetsz csatolmányokat ebben a fórumban.

Keresés:
Ugrás:  
Powered by phpBB® Forum Software © phpBB Limited
Magyar fordítás © Magyar phpBB Közösség
Portal: Kiss Portal Extension © Michael O'Toole