hlmod.hu

Magyar Half-Life Mód közösség!
Pontos idő: 2025.06.22. 10:42



Jelenlévő felhasználók

Jelenleg 358 felhasználó van jelen :: 1 regisztrált, 0 rejtett és 357 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]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  [4 hozzászólás ] 
Szerző Üzenet
 Hozzászólás témája: fejlet ban
HozzászólásElküldve:2013.10.20. 08:07 
Offline
Senior Tag

Csatlakozott:2009.12.28. 10:01
Hozzászólások:204
Megköszönt másnak: 4 alkalommal
Megköszönték neki: 3 alkalommal
ÜDv valaki meg tudja nekem csinálni hogy mikor ki banolják akkor van olyan hogy unbanért látogass el ide:https://www.facebook.com/groups/FunSzerverHungay/ hogy ezt írja ki előre is köszönöm


Hozzászólás jelentése
Vissza a tetejére
   
 Hozzászólás témája: Re: fejlet ban
HozzászólásElküldve:2013.10.20. 08:52 
Offline
Felfüggesztve

Csatlakozott:2013.08.09. 22:37
Hozzászólások:571
Megköszönt másnak: 10 alkalommal
Megköszönték neki: 85 alkalommal
Beállítod a Data/lang mappában a advanced_bans.txt ben.


Hozzászólás jelentése
Vissza a tetejére
   
 Hozzászólás témája: Re: fejlet ban
HozzászólásElküldve:2013.10.20. 10:08 
Offline
Senior Tag

Csatlakozott:2009.12.28. 10:01
Hozzászólások:204
Megköszönt másnak: 4 alkalommal
Megköszönték neki: 3 alkalommal
itt nem lehet?
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. }


Hozzászólás jelentése
Vissza a tetejére
   
 Hozzászólás témája: Re: fejlet ban
HozzászólásElküldve:2013.10.20. 11:09 
Offline
Felfüggesztve
Avatar

Csatlakozott:2013.06.09. 18:47
Hozzászólások:2004
Megköszönt másnak: 1 alkalommal
Megköszönték neki: 220 alkalommal
Legközelebb
SMA Forráskód: [ Mindet kijelol ]
  1.  
-ba rakd a kódot, mert elromlik a görgőm.

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

_________________
Ha elnyerte valamelyik témában a hozzászólásom a tetszésedet melyet olvastál, akkor egy egyszerű gombnyomással kifejezheted, hogy tetszett.


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  [4 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