hlmod.hu

Magyar Half-Life Mód közösség!
Pontos idő: 2024.04.24. 18:33



Jelenlévő felhasználók

Jelenleg 155 felhasználó van jelen :: 1 regisztrált, 0 rejtett és 154 vendég

A legtöbb felhasználó (1565 fő) 2020.11.21. 11:26-kor tartózkodott itt.

Regisztrált felhasználók: Majestic-12 [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  [ 3 hozzászólás ] 
Szerző Üzenet
HozzászólásElküldve: 2018.06.27. 15:24 
Offline
Tag

Csatlakozott: 2018.01.31. 14:33
Hozzászólások: 47
Üdv. Olyan kérdésem lenne hogy felraktam a banlistát weboldalra. De hiába jár le valakinek a ban vagy unbannolom. A phpmyadminból nem tűnik el. Ettől függetlenül fel tud már menni a szerverre, visszont a hiba az hogy ha mapot váltok akkor is feltud menni a szervere még ha bannolva van akkor is. De a ott benne marad. Mintha ki nem olvasná a dolgokat csak küldené. Mi lehet a hiba?

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


Hozzászólás jelentése
Vissza a tetejére
   
HozzászólásElküldve: 2018.11.25. 04:30 
Offline
Tud valamit
Avatar

Csatlakozott: 2018.11.02. 12:23
Hozzászólások: 148
Megköszönt másnak: 2 alkalommal
Megköszönték neki: 19 alkalommal
Hali. Próbáld meg fájlba menteni, ha úgy is csinálja, akkor valami gáz van. Ha nem, akkor SQL-el lesz a gond.


forcecraft írta:
Üdv. Olyan kérdésem lenne hogy felraktam a banlistát weboldalra. De hiába jár le valakinek a ban vagy unbannolom. A phpmyadminból nem tűnik el. Ettől függetlenül fel tud már menni a szerverre, visszont a hiba az hogy ha mapot váltok akkor is feltud menni a szervere még ha bannolva van akkor is. De a ott benne marad. Mintha ki nem olvasná a dolgokat csak küldené. Mi lehet a hiba?

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

_________________
****


Hozzászólás jelentése
Vissza a tetejére
   
HozzászólásElküldve: 2018.11.25. 09:32 
Offline
Beavatott
Avatar

Csatlakozott: 2008.09.15. 16:41
Hozzászólások: 76
Megköszönték neki: 6 alkalommal
Esetleg hibaüzenet nincs a log fileban?

_________________
Kép


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  [ 3 hozzászólás ] 


Ki van itt

Jelenlévő fórumozók: Majestic-12 [Bot] valamint 19 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