HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <engine>
  4.  
  5. #define PLUGIN "ADMIN Gag"
  6. #define VERSION "1.0"
  7. #define AUTHOR "RaZzoR"
  8.  
  9. #define GAG_FLAG ADMIN_BAN
  10. #define GAG_IMMUNITY ADMIN_IMMUNITY
  11.  
  12. #define DICTIONARY "admin_gag.txt"
  13. #define USE_COLOR_CHAT
  14.  
  15. #if defined USE_COLOR_CHAT
  16. #include <colorchat>
  17. #endif
  18.  
  19. new const gag_file_name[] = "gagged_users.txt"
  20.  
  21. enum _:GagData {
  22. gag_name[32],
  23. gag_steamid[35],
  24. gag_length,
  25. ungag_time[32],
  26. gag_reason[128]
  27. }
  28.  
  29. new Trie:g_trie
  30. new Array:g_array
  31. new total_gags, g_ungag_entity
  32. new gag_file[64], Float:get_gag_time[33], tempid[33]
  33.  
  34. new gag_immunity, gag_ungagcheck
  35.  
  36. public plugin_init() {
  37. register_plugin(PLUGIN, VERSION, AUTHOR)
  38.  
  39. #if defined USE_COLOR_CHAT
  40. register_dictionary_colored(DICTIONARY)
  41. #else
  42. register_dictionary(DICTIONARY)
  43. #endif
  44.  
  45. gag_immunity = register_cvar("gag_immunity", "1")
  46. gag_ungagcheck = register_cvar("gag_ungagcheck", "1.0")
  47.  
  48. register_clcmd("say /gag_menu", "gag_menu")
  49. register_clcmd("say /ungag_menu", "ungag_menu")
  50.  
  51. register_clcmd("say", "gag_say")
  52. register_clcmd("say_team", "gag_say")
  53.  
  54. register_clcmd("GAG_TIME", "clcmd_time")
  55. register_clcmd("GAG_REASON", "clcmd_reason")
  56.  
  57. register_concmd("gag_authid", "concmd_gag_authid", GAG_FLAG, "<nev, #userid, authid> <ido percben> <ok>")
  58. register_concmd("gag_ip", "concmd_gag_ip", GAG_FLAG, "<nev, #userid, authid> <ido percben> <ok>")
  59. register_concmd("gag_add", "concmd_gag_add", GAG_FLAG, "<nev> <authid vagy ip> <ido percben> <ok>")
  60. register_concmd("gag_list", "concmd_gag_list", GAG_FLAG, "[start] -- megmutat minden nemitast")
  61. register_concmd("ungag", "concmd_ungag", GAG_FLAG, "<authid vagy ip>")
  62.  
  63. get_datadir(gag_file, sizeof(gag_file) - 1)
  64. format(gag_file, sizeof(gag_file) - 1, "%s/%s", gag_file, gag_file_name)
  65.  
  66. g_trie = TrieCreate()
  67. g_array = ArrayCreate(GagData)
  68.  
  69. LoadGags()
  70. }
  71.  
  72. public plugin_cfg() create_ungag_entity()
  73.  
  74. public client_PostThink(id) {
  75. static authid[35]
  76. get_user_authid(id, authid, sizeof(authid) - 1)
  77.  
  78. static ip[35]
  79. get_user_ip(id, ip, sizeof(ip) - 1, 1)
  80.  
  81. static array_pos
  82. if(TrieGetCell(g_trie, authid, array_pos) || TrieGetCell(g_trie, ip, array_pos)) set_speak(id, SPEAK_MUTED)
  83. else set_speak(id, SPEAK_LISTENALL)
  84. }
  85.  
  86. public create_ungag_entity() {
  87. static failtimes
  88.  
  89. g_ungag_entity = create_entity("info_target")
  90.  
  91. if(!is_valid_ent(g_ungag_entity)) {
  92. ++failtimes
  93.  
  94. log_amx("%L", LANG_SERVER, "FAILED_TO_CREATE_UNGAG_ENTITY", failtimes)
  95.  
  96. if(failtimes < 10) set_task(1.0, "create_ungag_entity")
  97. else log_amx("%L", LANG_SERVER, "COULD_NOT_CREATE_UNGAG_ENTITY")
  98.  
  99. return
  100. }
  101.  
  102. entity_set_string(g_ungag_entity, EV_SZ_classname, "ungag_entity")
  103. entity_set_float(g_ungag_entity, EV_FL_nextthink, get_gametime() + 1.0)
  104.  
  105. register_think("ungag_entity", "UnGag_Check")
  106. }
  107.  
  108. public UnGag_Check(entity)
  109. {
  110. if(entity != g_ungag_entity) return
  111.  
  112. if(total_gags > 0)
  113. {
  114. static _hours[5], _minutes[5], _seconds[5], _month[5], _day[5], _year[7]
  115. format_time(_hours, sizeof(_hours) - 1, "%H")
  116. format_time(_minutes, sizeof(_minutes) - 1, "%M")
  117. format_time(_seconds, sizeof(_seconds) - 1, "%S")
  118. format_time(_month, sizeof(_month) - 1, "%m")
  119. format_time(_day, sizeof(_day) - 1, "%d")
  120. format_time(_year, sizeof(_year) - 1, "%Y")
  121.  
  122.  
  123. new c_hours = str_to_num(_hours)
  124. new c_minutes = str_to_num(_minutes)
  125. new c_seconds = str_to_num(_seconds)
  126. new c_month = str_to_num(_month)
  127. new c_day = str_to_num(_day)
  128. new c_year = str_to_num(_year)
  129.  
  130. static load_ungag_time[32]
  131. static u_hours, u_minutes, u_seconds, u_month, u_day, u_year
  132.  
  133. for(new i = 0; i < total_gags; i++) {
  134. static data[GagData]
  135. ArrayGetArray(g_array, i, data)
  136.  
  137. if(data[gag_length] == 0) continue
  138.  
  139. copy(load_ungag_time, sizeof(load_ungag_time) - 1, data[ungag_time])
  140.  
  141. replace_all(load_ungag_time, sizeof(load_ungag_time) - 1, ":", " ")
  142. replace_all(load_ungag_time, sizeof(load_ungag_time) - 1, "/", " ")
  143.  
  144. parse(load_ungag_time,\
  145. _hours, sizeof(_hours) - 1,\
  146. _minutes, sizeof(_minutes) - 1,\
  147. _seconds, sizeof(_seconds) - 1,\
  148. _month, sizeof(_month) - 1,\
  149. _day, sizeof(_day) - 1,\
  150. _year, sizeof(_year) - 1
  151. )
  152.  
  153. u_hours = str_to_num(_hours)
  154. u_minutes = str_to_num(_minutes)
  155. u_seconds = str_to_num(_seconds)
  156. u_month = str_to_num(_month)
  157. u_day = str_to_num(_day)
  158. u_year = str_to_num(_year)
  159.  
  160. if( u_year < c_year
  161. || u_year == c_year && u_month < c_month
  162. || u_year == c_year && u_month == c_month && u_day < c_day
  163. || u_year == c_year && u_month == c_month && u_day == c_day && u_hours < c_hours
  164. || u_year == c_year && u_month == c_month && u_day == c_day && u_hours == c_hours && u_minutes < c_minutes
  165. || u_year == c_year && u_month == c_month && u_day == c_day && u_hours == c_hours && u_minutes == c_minutes && u_seconds <= c_seconds ) {
  166. #if defined USE_COLOR_CHAT
  167. ColorChat(0, RED, "%L", LANG_PLAYER, "GAG_EXPIRED", data[gag_name], data[gag_steamid], data[gag_reason])
  168. #else
  169. NoColorChat(0, "%L", LANG_PLAYER, "GAG_EXPIRED", data[gag_name], data[gag_steamid], data[gag_reason])
  170. #endif
  171.  
  172. RemoveGag(i, data[gag_steamid])
  173.  
  174. i--
  175. }
  176. }
  177. }
  178.  
  179. entity_set_float(g_ungag_entity, EV_FL_nextthink, get_gametime() + get_pcvar_float(gag_ungagcheck))
  180. }
  181.  
  182. public concmd_gag_authid(id, level, cid) {
  183. if(!cmd_access(id, level, cid, 4)) return PLUGIN_HANDLED
  184.  
  185. static arg[128]
  186. read_argv(1, arg, sizeof(arg) - 1)
  187.  
  188. new target = cmd_target(id, arg, GetTargetFlags(id))
  189. if(!target) return PLUGIN_HANDLED
  190.  
  191. static target_authid[35]
  192. get_user_authid(target, target_authid, sizeof(target_authid) - 1)
  193.  
  194. if(TrieKeyExists(g_trie, target_authid)) {
  195. console_print(id, "%L", id, "ALREADY_GAGGED_STEAMID", target_authid)
  196. return PLUGIN_HANDLED
  197. }
  198.  
  199. read_argv(2, arg, sizeof(arg) - 1)
  200. new Float:length = str_to_float(arg)
  201.  
  202. static ungag_time2[64], gag_time2[64]
  203.  
  204. if(length == 0.0) formatex(ungag_time2, sizeof(ungag_time2) - 1, "%L", id, "PERMANENT_GAG")
  205. else GenerateUnGagTime(length, ungag_time2, sizeof(ungag_time2) - 1)
  206.  
  207. read_argv(3, arg, sizeof(arg) - 1)
  208.  
  209. static admin_name[64], target_name[32]
  210. get_user_name(id, admin_name, sizeof(admin_name) - 1)
  211. get_user_name(target, target_name, sizeof(target_name) - 1)
  212.  
  213. static admin_authid[35]
  214. get_user_authid(id, admin_authid, sizeof(admin_authid) - 1)
  215.  
  216. GagAdd(target_name, target_authid, arg, floatround(length * 60.0, floatround_floor), ungag_time2)
  217.  
  218. GetGagTime(id, length, gag_time2, sizeof(gag_time2) - 1)
  219.  
  220. #if defined USE_COLOR_CHAT
  221. ColorChat(0, RED, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, arg, gag_time2, ungag_time2)
  222. #else
  223. NoColorChat(0, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, arg, gag_time2, ungag_time2)
  224. #endif
  225.  
  226. return PLUGIN_HANDLED
  227. }
  228.  
  229. public concmd_gag_ip(id, level, cid) {
  230. if(!cmd_access(id, level, cid, 4)) return PLUGIN_HANDLED
  231.  
  232. static arg[128]
  233. read_argv(1, arg, sizeof(arg) - 1)
  234.  
  235. new target = cmd_target(id, arg, GetTargetFlags(id))
  236. if(!target) return PLUGIN_HANDLED
  237.  
  238. static target_ip[35]
  239. get_user_ip(target, target_ip, sizeof(target_ip) - 1, 1)
  240.  
  241. if(TrieKeyExists(g_trie, target_ip)) {
  242. console_print(id, "%L", id, "ALREADY_GAGGED_IP", target_ip)
  243. return PLUGIN_HANDLED
  244. }
  245.  
  246. read_argv(2, arg, sizeof(arg) - 1)
  247. new Float:length = str_to_float(arg)
  248.  
  249. static ungag_time2[64], gag_time2[64]
  250.  
  251. if(length == 0.0) formatex(ungag_time2, sizeof(ungag_time2) - 1, "%L", id, "PERMANENT_GAG")
  252. else GenerateUnGagTime(length, ungag_time2, sizeof(ungag_time2) - 1)
  253.  
  254. read_argv(3, arg, sizeof(arg) - 1)
  255.  
  256. static admin_name[64], target_name[32]
  257. get_user_name(id, admin_name, sizeof(admin_name) - 1)
  258. get_user_name(target, target_name, sizeof(target_name) - 1)
  259.  
  260. static admin_authid[35]
  261. get_user_authid(id, admin_authid, sizeof(admin_authid) - 1)
  262.  
  263. GagAdd(target_name, target_ip, arg, floatround(length * 60.0, floatround_floor), ungag_time2)
  264.  
  265. GetGagTime(id, length, gag_time2, sizeof(gag_time2) - 1)
  266.  
  267. #if defined USE_COLOR_CHAT
  268. ColorChat(0, RED, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, arg, gag_time2, ungag_time2)
  269. #else
  270. NoColorChat(0, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, arg, gag_time2, ungag_time2)
  271. #endif
  272.  
  273. return PLUGIN_HANDLED
  274. }
  275.  
  276. public concmd_gag_add(id, level, cid) {
  277. if(!cmd_access(id, level, cid, 5)) return PLUGIN_HANDLED
  278.  
  279. static target_name[128], target_authid[128], gagtime[128], reason[128]
  280. read_argv(1, target_name, sizeof(target_name) - 1)
  281. read_argv(2, target_authid, sizeof(target_authid) - 1)
  282. read_argv(3, gagtime, sizeof(gagtime) - 1)
  283. read_argv(4, reason, sizeof(reason) - 1)
  284.  
  285. new bool:is_ip = bool:(containi(target_authid, ".") != -1)
  286.  
  287. if(TrieKeyExists(g_trie, target_authid)) {
  288. console_print(id, "%L", id, is_ip ? "ALREADY_GAGGED_IP" : "ALREADY_GAGGED_STEAMID", target_authid)
  289. return PLUGIN_HANDLED
  290. }
  291.  
  292. new Float:length = str_to_float(gagtime)
  293. static ungag_time2[64], gag_time2[64]
  294.  
  295. if(length == 0.0) formatex(ungag_time2, sizeof(ungag_time2) - 1, "%L", id, "PERMANENT_GAG")
  296. else GenerateUnGagTime(length, ungag_time2, sizeof(ungag_time2) - 1)
  297.  
  298. static admin_name[64]
  299. get_user_name(id, admin_name, sizeof(admin_name) - 1)
  300.  
  301. static admin_authid[35]
  302. get_user_authid(id, admin_authid, sizeof(admin_authid) - 1)
  303.  
  304. GagAdd(target_name, target_authid, reason, floatround(length * 60.0, floatround_floor), ungag_time2)
  305.  
  306. GetGagTime(id, length, gag_time2, sizeof(gag_time2) - 1)
  307.  
  308. #if defined USE_COLOR_CHAT
  309. ColorChat(0, RED, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, reason, gag_time2, ungag_time2)
  310. #else
  311. NoColorChat(0, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, reason, gag_time2, ungag_time2)
  312. #endif
  313.  
  314. return PLUGIN_HANDLED
  315. }
  316.  
  317. public concmd_ungag(id, level, cid) {
  318. if(!cmd_access(id, level, cid, 2)) return PLUGIN_HANDLED
  319.  
  320. static arg[35]
  321. read_argv(1, arg, sizeof(arg) - 1)
  322.  
  323. if(TrieKeyExists(g_trie, arg)) {
  324. static array_pos;
  325. TrieGetCell(g_trie, arg, array_pos);
  326.  
  327. static data[GagData]
  328. ArrayGetArray(g_array, array_pos, data)
  329.  
  330. static admin_name[64]
  331. get_user_name(id, admin_name, sizeof(admin_name) - 1)
  332.  
  333. static authid[35]
  334. get_user_authid(id, authid, sizeof(authid) - 1)
  335.  
  336. #if defined USE_COLOR_CHAT
  337. ColorChat(0, RED, "%L", LANG_PLAYER, "UNGAG_PLAYER", admin_name, authid, data[gag_name], data[gag_steamid], data[gag_reason])
  338. #else
  339. NoColorChat(0, "%L", LANG_PLAYER, "UNGAG_PLAYER", admin_name, authid, data[gag_name], data[gag_steamid], data[gag_reason])
  340. #endif
  341.  
  342. RemoveGag(array_pos, data[gag_steamid])
  343.  
  344. return PLUGIN_HANDLED
  345. }
  346.  
  347. console_print(id, "%L", id, "NOT_IN_GAG_LIST", arg)
  348.  
  349. return PLUGIN_HANDLED
  350. }
  351.  
  352. public concmd_gag_list(id, level, cid) {
  353. if(!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED
  354.  
  355. if(!total_gags) {
  356. console_print(id, "%L", id, "NO_GAGS")
  357. return PLUGIN_HANDLED;
  358. }
  359.  
  360. static start
  361. if(read_argc() > 1) {
  362. static arg[5]
  363. read_argv(1, arg, sizeof(arg) - 1)
  364.  
  365. start = min(str_to_num(arg), total_gags) - 1
  366. }
  367.  
  368. else start = 0
  369.  
  370. new last = min(start + 10, total_gags)
  371.  
  372. if(id == 0) server_cmd("echo ^"%L^"", id, "GAG_LIST_NUM", start + 1, last)
  373. else console_print(id, "%L", id, "GAG_LIST_NUM", start + 1, last)
  374.  
  375. for(new i = start; i < last; i++) {
  376. static data[GagData]
  377. ArrayGetArray(g_array, i, data)
  378.  
  379. PrintGagInfosToConsole(id, data[gag_name], data[gag_steamid], data[gag_length], data[gag_reason], data[ungag_time])
  380. }
  381.  
  382. if(++last < total_gags) {
  383. if(id == 0) server_cmd("echo ^"%L^"", id, "GAG_LIST_NEXT", last)
  384. else console_print(id, "%L", id, "GAG_LIST_NEXT", last)
  385. }
  386.  
  387. return PLUGIN_HANDLED
  388. }
  389.  
  390. public gag_menu(id) {
  391. if(!(get_user_flags(id) & GAG_FLAG))
  392. return PLUGIN_HANDLED
  393.  
  394. new menu_line[64], menu_newline[64], id_data[64]
  395. format(menu_line, charsmax(menu_line), "\w%L^n%L", id, "GAG_MENU1", id, "GAG_MENU2")
  396.  
  397. new menu = menu_create(menu_line, "gag_menu_handler")
  398.  
  399. new players[32], name[32], num
  400. get_players(players, num, "c")
  401.  
  402. for(new i = 0; i <num; i++) {
  403. new pid = players[i]
  404. get_user_name(pid, name, 31)
  405. num_to_str(pid, id_data, sizeof(id_data))
  406.  
  407. format(menu_newline, charsmax(menu_newline), "%s", name)
  408. menu_additem(menu, menu_newline, id_data, 0)
  409. }
  410.  
  411. menu_display(id, menu, 0)
  412. return PLUGIN_CONTINUE
  413. }
  414.  
  415. public ungag_menu(id) {
  416. if(!(get_user_flags(id) & GAG_FLAG))
  417. return PLUGIN_HANDLED
  418.  
  419. if(!total_gags) {
  420. #if defined USE_COLOR_CHAT
  421. ColorChat(id, RED, "%L", id, "NO_GAGS")
  422. #else
  423. client_print(id, print_chat, "%L", id, "NO_GAGS")
  424. #endif
  425.  
  426. return PLUGIN_HANDLED
  427. }
  428.  
  429. new menu_line[99], menu_newline[99]
  430. format(menu_line, charsmax(menu_line), "\w%L^n%L", id, "GAG_MENU3", id, "GAG_MENU4")
  431.  
  432. new menu = menu_create(menu_line, "ungag_menu_handler")
  433.  
  434. for(new i = 0; i < total_gags; i++) {
  435. static data[GagData]
  436. ArrayGetArray(g_array, i, data)
  437.  
  438. format(menu_newline, charsmax(menu_newline), "\r%s \w[%s]", data[gag_steamid], data[gag_reason])
  439. menu_additem(menu, menu_newline, data[gag_steamid], 0)
  440. }
  441.  
  442. menu_display(id, menu, 0)
  443. return PLUGIN_CONTINUE
  444. }
  445.  
  446. public gag_menu_handler(id, menu, item) {
  447. if(item == MENU_EXIT) {
  448. menu_destroy(menu)
  449. return PLUGIN_HANDLED
  450. }
  451.  
  452. new data[64], szName[64]
  453. new access, callback
  454. menu_item_getinfo(menu, item, access, data,charsmax(data), szName,charsmax(szName), callback)
  455.  
  456. tempid[id] = str_to_num(data)
  457.  
  458. static authid[35]
  459. get_user_authid(tempid[id], authid, sizeof(authid) - 1)
  460.  
  461. static ip[35]
  462. get_user_ip(tempid[id], ip, sizeof(ip) - 1, 1)
  463. static array_pos
  464.  
  465. if(get_user_flags(tempid[id]) & GAG_IMMUNITY) {
  466. #if defined USE_COLOR_CHAT
  467. ColorChat(id, RED, "%L", id, "PLAYER_IMMUNITY")
  468. #else
  469. NoColorChat(id, "%L", id, "PLAYER_IMMUNITY")
  470. #endif
  471.  
  472. gag_menu(id)
  473.  
  474. return PLUGIN_HANDLED
  475. }
  476.  
  477. else if(TrieGetCell(g_trie, authid, array_pos) || TrieGetCell(g_trie, ip, array_pos)) {
  478. static data[GagData]
  479. ArrayGetArray(g_array, array_pos, data)
  480.  
  481. static gag_length2[64]
  482. new Float:gag_len = float(data[gag_length]) / 60.0
  483. GetGagTime(id, gag_len, gag_length2, sizeof(gag_length2) - 1)
  484.  
  485. #if defined USE_COLOR_CHAT
  486. ColorChat(id, RED, "%L", id, "PLAYER_GAGGED", data[gag_reason], gag_length2, data[ungag_time])
  487. #else
  488. NoColorChat(id, "%L", id, "PLAYER_GAGGED", data[gag_reason], gag_length2, data[ungag_time])
  489. #endif
  490.  
  491. return PLUGIN_HANDLED
  492. }
  493.  
  494. else {
  495. #if defined USE_COLOR_CHAT
  496. ColorChat(id, RED, "%L", id, "TYPE_TIME")
  497. #else
  498. NoColorChat(id, "%L", id, "TYPE_TIME")
  499. #endif
  500.  
  501. client_cmd(id, "messagemode GAG_TIME")
  502. }
  503.  
  504. return PLUGIN_CONTINUE
  505. }
  506.  
  507. public ungag_menu_handler(id, menu, item) {
  508. if(item == MENU_EXIT) {
  509. menu_destroy(menu)
  510. return PLUGIN_HANDLED
  511. }
  512.  
  513. new data[64], szName[64]
  514. new access, callback
  515. menu_item_getinfo(menu, item, access, data, charsmax(data), szName, charsmax(szName), callback)
  516.  
  517. client_cmd(id, "ungag ^"%s^"", data)
  518.  
  519. return PLUGIN_CONTINUE
  520. }
  521.  
  522. public clcmd_time(id) {
  523. if(!(get_user_flags(id) & GAG_FLAG))
  524. return PLUGIN_HANDLED
  525.  
  526. new gag_times[33][100]
  527. read_args(gag_times[id], 99)
  528. remove_quotes(gag_times[id])
  529.  
  530. get_gag_time[id] = str_to_float(gag_times[id])
  531.  
  532. #if defined USE_COLOR_CHAT
  533. ColorChat(id, RED, "%L", id, "TYPE_REASON")
  534. #else
  535. NoColorChat(id, "%L", id, "TYPE_REASON")
  536. #endif
  537.  
  538. client_cmd(id, "messagemode GAG_REASON")
  539.  
  540. return PLUGIN_HANDLED
  541. }
  542.  
  543. public clcmd_reason(id) {
  544. if(!(get_user_flags(id) & GAG_FLAG))
  545. return PLUGIN_HANDLED
  546.  
  547. new get_gag_reason[33][100]
  548. read_args(get_gag_reason[id], 99)
  549. remove_quotes(get_gag_reason[id])
  550.  
  551. static target_authid[32]
  552. get_user_authid(tempid[id], target_authid, sizeof(target_authid) - 1)
  553.  
  554. client_cmd(id, "gag_authid ^"%s^" ^"%f^" ^"%s^"", target_authid, get_gag_time[id], get_gag_reason[id])
  555.  
  556. return PLUGIN_HANDLED
  557. }
  558.  
  559. public gag_say(id) {
  560. static authid[35]
  561. get_user_authid(id, authid, sizeof(authid) - 1)
  562.  
  563. static ip[35]
  564. get_user_ip(id, ip, sizeof(ip) - 1, 1)
  565.  
  566. static array_pos
  567. if(TrieGetCell(g_trie, authid, array_pos) || TrieGetCell(g_trie, ip, array_pos)) {
  568. static data[GagData]
  569. ArrayGetArray(g_array, array_pos, data)
  570.  
  571. static gag_length2[64]
  572. new Float:gag_len = float(data[gag_length]) / 60.0
  573. GetGagTime(id, gag_len, gag_length2, sizeof(gag_length2) - 1)
  574.  
  575. #if defined USE_COLOR_CHAT
  576. ColorChat(id, RED, "%L", id, "YOU_GAGGED", data[gag_reason], gag_length2, data[ungag_time])
  577. #else
  578. NoColorChat(id, "%L", id, "YOU_GAGGED", data[gag_reason], gag_length2, data[ungag_time])
  579. #endif
  580.  
  581. return PLUGIN_HANDLED
  582. }
  583.  
  584. return PLUGIN_CONTINUE
  585. }
  586.  
  587. public PrintGagInfosToConsole(index, const target_name[], const target_steamid[], const target_length, const target_reason[], const target_ungag_time[]) {
  588. static gag_length2[64]
  589. new bool:is_ip = bool:(containi(target_steamid, ".") != -1)
  590.  
  591. if(index == 0) {
  592. server_print("************************************************")
  593. server_print("%L", index, "GAG_INFORMATION")
  594. server_print("%L: %s", index, "GAG_NAME", target_name)
  595. server_print("%L: %s", index, !is_ip ? "GAG_STEAMID" : "GAG_IP", target_steamid)
  596. server_print("%L: %s", index, "GAG_REASON", target_reason)
  597. if(target_length > 0) {
  598. new Float:gag_len = float(target_length) / 60.0
  599. GetGagTime(index, gag_len, gag_length2, sizeof(gag_length2) - 1)
  600.  
  601. server_print("%L: %s", index, "GAG_TIME", gag_length2)
  602. }
  603. server_print("%L: %s", index, "UNGAG_TIME", target_ungag_time)
  604. server_print("************************************************")
  605. }
  606.  
  607. else {
  608. console_print(index, "************************************************")
  609. console_print(index, "%L", index, "GAG_INFORMATION")
  610. console_print(index, "%L: %s", index, "GAG_NAME", target_name)
  611. console_print(index, "%L: %s", index, !is_ip ? "GAG_STEAMID" : "GAG_IP", target_steamid)
  612. console_print(index, "%L: %s", index, "GAG_REASON", target_reason)
  613. if(target_length > 0) {
  614. new Float:gag_len = float(target_length) / 60.0
  615. GetGagTime(index, gag_len, gag_length2, sizeof(gag_length2) - 1)
  616.  
  617. console_print(index, "%L: %s", index, "GAG_TIME", gag_length2)
  618. }
  619. console_print(index, "%L: %s", index, "UNGAG_TIME", target_ungag_time)
  620. console_print(index, "************************************************")
  621. }
  622. }
  623.  
  624. public LoadGags() {
  625. if(total_gags) {
  626. TrieClear(g_trie)
  627. ArrayClear(g_array)
  628. total_gags = 0
  629. }
  630.  
  631. if(file_exists(gag_file)) {
  632. new f = fopen(gag_file, "rt")
  633. static filedata[512], length[10]
  634.  
  635. static data[GagData]
  636. while(!feof(f)){
  637. fgets(f, filedata, sizeof(filedata) - 1)
  638.  
  639. if(!filedata[0]) continue
  640.  
  641. parse(filedata,\
  642. data[gag_steamid], sizeof(data[gag_steamid]) - 1,\
  643. data[gag_name], sizeof(data[gag_name]) - 1,\
  644. length, sizeof(length) - 1,\
  645. data[ungag_time], sizeof(data[ungag_time]) - 1,\
  646. data[gag_reason], sizeof(data[gag_reason]) - 1
  647. )
  648.  
  649. data[gag_length] = str_to_num(length)
  650.  
  651. ArrayPushArray(g_array, data)
  652. TrieSetCell(g_trie, data[gag_steamid], total_gags)
  653.  
  654. total_gags++
  655. }
  656.  
  657. fclose(f)
  658. }
  659. }
  660.  
  661. public RemoveGag(pos, const authid[]) {
  662. TrieDeleteKey(g_trie, authid)
  663. ArrayDeleteItem(g_array, pos)
  664.  
  665. total_gags--
  666.  
  667. new f = fopen(gag_file, "wt")
  668. new data[GagData]
  669.  
  670. for(new i = 0; i < total_gags; i++ ) {
  671. ArrayGetArray(g_array, i, data)
  672. TrieSetCell(g_trie, data[gag_steamid], i)
  673.  
  674. fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^"^n",\
  675. data[gag_steamid],\
  676. data[gag_name],\
  677. data[gag_length],\
  678. data[ungag_time],\
  679. data[gag_reason]
  680. )
  681. }
  682.  
  683. fclose(f)
  684. }
  685.  
  686. public GagAdd(const target_name[], const target_steamid[], const reason[], const length, const ungag_time3[]) {
  687. new f = fopen(gag_file, "a+")
  688.  
  689. fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^"^n",\
  690. target_steamid,\
  691. target_name,\
  692. length,\
  693. ungag_time3,\
  694. reason
  695. )
  696.  
  697. fclose(f)
  698.  
  699. static data[GagData]
  700. copy(data[gag_name], sizeof(data[gag_name]) - 1, target_name)
  701. copy(data[gag_steamid], sizeof(data[gag_steamid]) - 1, target_steamid)
  702. data[gag_length] = length
  703. copy(data[ungag_time], sizeof(data[ungag_time]) - 1, ungag_time3)
  704. copy(data[gag_reason], sizeof(data[gag_reason]) - 1, reason)
  705.  
  706. TrieSetCell(g_trie, target_steamid, total_gags)
  707. ArrayPushArray(g_array, data)
  708.  
  709. total_gags++
  710. }
  711.  
  712. GetGagTime(index, Float:gagtime, length[], len) {
  713. new minutes = floatround(gagtime, floatround_floor)
  714. new seconds = floatround(floatfract(gagtime) * 60, floatround_floor)
  715. new hours = 0
  716. new days = 0
  717.  
  718. while(minutes >= 60) {
  719. minutes -= 60
  720. hours++
  721. }
  722.  
  723. while(hours >= 24) {
  724. hours -= 24
  725. days++
  726. }
  727.  
  728. new bool:add_before
  729. if(seconds) {
  730. formatex(length, len, "%i %L", seconds, index, "GAG_SECONDS")
  731. add_before = true
  732. }
  733.  
  734. if(minutes) {
  735. if(add_before) format(length, len, "%i %L, %s", minutes, index, "GAG_MINUTES", length)
  736.  
  737. else{
  738. formatex(length, len, "%i %L", minutes, index, "GAG_MINUTES")
  739. add_before = true
  740. }
  741. }
  742.  
  743. if(hours) {
  744. if(add_before) format(length, len, "%i %L, %s", hours, index, "GAG_HOURS", length)
  745.  
  746. else{
  747. formatex(length, len, "%i %L", hours, index, "GAG_HOURS")
  748. add_before = true
  749. }
  750. }
  751.  
  752. if(days) {
  753. if(add_before) format(length, len, "%i %L, %s", days, index, "GAG_DAYS", length)
  754.  
  755. else {
  756. formatex(length, len, "%i %L", days, index, "GAG_DAYS")
  757. add_before = true
  758. }
  759. }
  760.  
  761. if(!add_before) formatex(length, len, "%L", index, "PERMANENT_GAG")
  762. }
  763.  
  764. GetTargetFlags(index) {
  765. static const flags_no_immunity = (CMDTARGET_ALLOW_SELF|CMDTARGET_NO_BOTS)
  766. static const flags_immunity = (CMDTARGET_ALLOW_SELF|CMDTARGET_NO_BOTS|CMDTARGET_OBEY_IMMUNITY)
  767.  
  768. switch(get_pcvar_num(gag_immunity)) {
  769. case 1: return flags_immunity
  770. case 2: return access(index, GAG_IMMUNITY) ? flags_no_immunity : flags_immunity
  771. }
  772.  
  773. return flags_no_immunity
  774. }
  775.  
  776. GenerateUnGagTime(const Float:input, output[], const len) {
  777. static _hours[5], _minutes[5], _seconds[5], _month[5], _day[5], _year[7]
  778. format_time(_hours, sizeof(_hours) - 1, "%H")
  779. format_time(_minutes, sizeof(_minutes) - 1, "%M")
  780. format_time(_seconds, sizeof(_seconds) - 1, "%S")
  781. format_time(_month, sizeof(_month) - 1, "%m")
  782. format_time(_day, sizeof(_day) - 1, "%d")
  783. format_time(_year, sizeof(_year) - 1, "%Y")
  784.  
  785. new hours = str_to_num(_hours)
  786. new month = str_to_num(_month)
  787. new day = str_to_num(_day)
  788. new year = str_to_num(_year)
  789.  
  790. new minutes = floatround(input, floatround_floor) + str_to_num(_minutes)
  791. new seconds = floatround(floatfract(input) * 60, floatround_floor)
  792.  
  793. while(minutes >= 60) {
  794. minutes -= 60
  795. hours++
  796. }
  797.  
  798. while(hours >= 24) {
  799. hours -= 24
  800. day++
  801. }
  802.  
  803. new max_days = GetDaysInMonth(month, year)
  804. while(day > max_days) {
  805. day -= max_days
  806. month++
  807. }
  808.  
  809. while(month > 12) {
  810. month -= 12
  811. year++
  812. }
  813.  
  814. seconds += str_to_num(_seconds)
  815. if(seconds > 59) {
  816. seconds -= 60
  817. if(minutes < 59) minutes++
  818.  
  819. else {
  820. minutes = 0
  821. if(hours < 23) hours++
  822.  
  823. else {
  824. hours = 0
  825. if(day < max_days) day++
  826.  
  827. else {
  828. day = 1
  829. if(month < 12) month++
  830.  
  831. else {
  832. month = 1
  833. year++
  834. }
  835. }
  836. }
  837. }
  838. }
  839.  
  840. formatex(output, len, "%i:%02i:%02i %i/%i/%i", hours, minutes, seconds, month, day, year)
  841. }
  842.  
  843. GetDaysInMonth(month, year=0) {
  844. switch(month) {
  845. case 1: return 31 // January
  846. case 2: return ((year % 4) == 0) ? 29 : 28 // February
  847. case 3: return 31; // March
  848. case 4: return 30; // April
  849. case 5: return 31; // May
  850. case 6: return 30; // June
  851. case 7: return 31; // July
  852. case 8: return 31; // August
  853. case 9: return 30; // September
  854. case 10: return 31; // October
  855. case 11: return 30; // November
  856. case 12: return 31; // December
  857. }
  858.  
  859. return 30
  860. }
  861.  
  862. stock NoColorChat(const id, const input[], any:...) {
  863. new count = 1, players[32], i
  864. static msg[191]
  865. vformat(msg, 190, input, 3)
  866.  
  867. replace_all(msg, 190, "!g", "")
  868. replace_all(msg, 190, "!n", "")
  869. replace_all(msg, 190, "!t", "")
  870.  
  871. if(id)players[0] = id; else get_players(players, count, "ch")
  872.  
  873. for(i = 0; i < count; i++) {
  874. if(is_user_connected(players[i])) {
  875. message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i])
  876. write_byte(players[i])
  877. write_string(msg)
  878. message_end()
  879. }
  880. }
  881. }