Advertisement
Guest User

nms

a guest
Apr 24th, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.92 KB | None | 0 0
  1. /*
  2. ======================================================
  3.  
  4. Version 2.0
  5.  
  6. --- First release
  7.  
  8. Version 2.1
  9.  
  10. --- Added better regex pattern
  11.  
  12. Version 2.2
  13.  
  14. --- Added
  15. nms_nospam 0/1 disable/enable NoSpam function
  16. nms_badwords 0/1 disable/enable BadWords function
  17. nms_noadvert 0/1 disable/enable NoAdvert function
  18.  
  19. --- Removed colorchat include
  20.  
  21. Version 2.3
  22.  
  23. --- Added
  24. Exception words that are skipped when checking for spam
  25. Admin immunity from NoAdvert function
  26. Better regex pattern
  27.  
  28. Version 2.3.1 HotFix
  29.  
  30. --Works with advanced bans
  31.  
  32. Version 2.4
  33.  
  34. --Added ADMIN_BAN immunity to the plugin
  35. nms_adminimmune 1/0
  36.  
  37. Version 2.5
  38.  
  39. --Fixed a hole in detecting IP/DOMAINS
  40.  
  41. Version 2.5.1 HotFix
  42.  
  43. --Higher domain detection
  44.  
  45. Version 2.5.2 Hotfix
  46.  
  47. --nms_chatban "0" now works properly
  48.  
  49. Version 2.6
  50.  
  51. --IP/DOMAIN check in player's nick
  52. --Better NoSpam detection
  53. --Punish now stays after reconnection
  54. --Optimized Colorchat
  55.  
  56. Version 3.0 BETA
  57.  
  58. --Faster & Lighter words detection
  59. --Words will now detect properly
  60. --Optimized regex pattern
  61. --Regex patterns are now separated for better results
  62. --nms_chataction cvar added
  63.  
  64. Version 3.01 BETA
  65. --Fixed "replace buffer not big enough" when entering server
  66.  
  67. Version 3.02 BETA
  68. --Replaced TrieGet* with TrieKeyExist
  69.  
  70. Version 3.1
  71. --Added Old detection method
  72. --Added nms_method cvar
  73. --Added update notify
  74.  
  75. Version 3.2
  76. --Punishment will stay after reconnect
  77. --Some code refactored
  78.  
  79. ======================================================
  80. */
  81. #include <amxmodx>
  82. #include <amxmisc>
  83. #include <regex>
  84. #include <fakemeta>
  85.  
  86. #define PLUGIN "NoMoreSh!t"
  87. new const VERSION[] = "3.2";
  88. #define AUTHOR "SpeeDeeR@amxmodxbg"
  89.  
  90. #pragma semicolon 1
  91.  
  92. #define SAY_BLOCK PLUGIN_HANDLED
  93. #define SAY_OK PLUGIN_CONTINUE
  94.  
  95. #define MAXPLAYERS 32
  96.  
  97. #define IP_PATTERN "([0-9].*[*].*[1-9][0-9].*[*].*[0-9]{2}.*[*].*[0-9])"
  98. #define DOMAIN_PATTERN "[a-zA-Z0-9\-\.]+\.(com|org|net|bg|info|COM|ORG|NET|BG|INFO)"
  99.  
  100. enum
  101. {
  102. BAD_WORD,
  103. ADVERTISEMENT,
  104. SPAM,
  105.  
  106. TOTAL_REASONS
  107. };
  108.  
  109. new const szReasons[TOTAL_REASONS][] =
  110. {
  111. "Neprilichni dumi",
  112. "IP/DOMAIN REKLAMA",
  113. "SPAM"
  114. };
  115.  
  116. new g_returnvalue;
  117.  
  118. new
  119. Regex:g_IP_PATTERN,
  120. Regex:g_DOMAIN_PATTERN;
  121.  
  122. new
  123. pcvarTimesAllowed,
  124. pcvarChatAction,
  125. pcvarChatBan,
  126. pcvarNoSpamEnabled,
  127. pcvarBadWordsEnabled,
  128. pcvarNoAdvertEnabled,
  129. pcvarAdminImminuty,
  130. pcvarDetectionMethod;
  131.  
  132. new
  133. Trie:th_exc, //exceptions
  134. Trie:th_punish, //punished players
  135. Trie:th_words; //bad words
  136. //cvar dependency
  137. new Array: arr_words;
  138.  
  139.  
  140. new
  141. g_msg_SayText,
  142. g_msg_TeamInfo;
  143.  
  144. new g_iMaxPlayers;
  145.  
  146. enum Data {
  147. szName[32],
  148. PunishStart,
  149. LastSaid[128],
  150. SpamCount,
  151. bool: Connected,
  152. bool: Immunity,
  153. bool: Punished
  154. };
  155.  
  156.  
  157. new g_PData[MAXPLAYERS + 1][Data];
  158.  
  159.  
  160. new g_iBadWordsNum; //replacing ArraySize()
  161.  
  162. enum Color
  163. {
  164. NORMAL = 1, // clients scr_concolor cvar color
  165. GREEN, // Green Color
  166. TEAM_COLOR, // Red, grey, blue
  167. GREY, // grey
  168. RED, // Red
  169. BLUE, // Blue
  170. }
  171.  
  172. new const g_prefix[] = "[NoMoreSh!t]";
  173.  
  174. public plugin_init()
  175. {
  176. register_plugin(PLUGIN, VERSION, AUTHOR);
  177.  
  178. register_clcmd("say", "SayHandle");
  179. register_clcmd("say_team", "SayHandle");
  180.  
  181. register_concmd("nms_loadwords", "readBadWords");
  182. register_concmd("nms_loadexceptions", "readExceptions");
  183.  
  184. pcvarTimesAllowed = register_cvar("nms_chatcount", "5");
  185.  
  186. pcvarChatAction = register_cvar("nms_chataction", "1");
  187. pcvarChatBan = register_cvar("nms_chatban", "30");
  188.  
  189. pcvarNoSpamEnabled = register_cvar("nms_nospam", "1");
  190. pcvarBadWordsEnabled = register_cvar("nms_badwords", "1");
  191. pcvarNoAdvertEnabled = register_cvar("nms_noadvert", "1");
  192. pcvarAdminImminuty = register_cvar("nms_adminimmune", "1");
  193.  
  194. pcvarDetectionMethod = register_cvar("nms_method", "2"); /* 1 - Array (old method) | 2 - Trie */
  195.  
  196. register_cvar( "nms_version", VERSION, FCVAR_SERVER | FCVAR_SPONLY );
  197. set_cvar_string( "nms_version", VERSION );
  198.  
  199. register_forward(FM_ClientUserInfoChanged, "fwd_ClientUserInfoChanged");
  200.  
  201. th_exc = TrieCreate();
  202. th_punish = TrieCreate();
  203.  
  204. new error[1];
  205. g_IP_PATTERN = regex_compile(IP_PATTERN, g_returnvalue, error, charsmax(error) ,"s");
  206. g_DOMAIN_PATTERN = regex_compile(DOMAIN_PATTERN, g_returnvalue, error, charsmax(error), "s");
  207.  
  208. g_msg_SayText = get_user_msgid("SayText");
  209. g_msg_TeamInfo = get_user_msgid("TeamInfo");
  210.  
  211. g_iMaxPlayers = get_maxplayers();
  212.  
  213. readExceptions(0);
  214.  
  215. new ppcvar = get_pcvar_num(pcvarDetectionMethod);
  216.  
  217. if(ppcvar == 1)
  218. {
  219. arr_words = ArrayCreate(20);
  220. }
  221. else if(ppcvar == 2)
  222. {
  223. th_words = TrieCreate();
  224. }
  225.  
  226. readBadWords(0);
  227. }
  228.  
  229. public readBadWords(id)
  230. {
  231. if(!(get_user_flags(id) & ADMIN_RCON)) return;
  232.  
  233. new badwords_file[64];
  234. get_configsdir( badwords_file, charsmax(badwords_file) );
  235. add(badwords_file, charsmax(badwords_file), "/NMS_BADWORDS.ini");
  236.  
  237. if ( !file_exists(badwords_file) )
  238. {
  239. server_print ( "============================================" );
  240. server_print ( "[NoMoreSh!t] %s file not found", badwords_file );
  241. server_print ( "============================================" );
  242. return;
  243. }
  244.  
  245. g_iBadWordsNum = 0;
  246.  
  247. new ppcvar = get_pcvar_num(pcvarDetectionMethod);
  248.  
  249. if(ppcvar == 2 && th_words)
  250. {
  251. TrieClear(th_words);
  252. }
  253. else if(ppcvar == 1 && arr_words)
  254. {
  255. ArrayClear(arr_words);
  256. }
  257.  
  258. new file = fopen(badwords_file,"r");
  259. new badword[20], c;
  260. while(fgets(file, badword, charsmax(badword)))
  261. {
  262. trim(badword);
  263. if( !(c = badword[ 0 ])
  264. || c == ';'
  265. || c == '/') continue;
  266.  
  267. if(ppcvar == 1)
  268. {
  269. ArrayPushString(arr_words, badword);
  270. }
  271. else if(ppcvar == 2)
  272. {
  273. TrieSetCell(th_words, badword, true);
  274. }
  275.  
  276. g_iBadWordsNum++;
  277. }
  278.  
  279. server_print ("============================================");
  280. server_print ("[NoMoreSh!t] %i bad words loaded", g_iBadWordsNum);
  281. server_print ("============================================");
  282. }
  283.  
  284. public readExceptions(id)
  285. {
  286. if(!(get_user_flags(id) & ADMIN_RCON)) return;
  287.  
  288. new exceptions_file[64];
  289. get_configsdir( exceptions_file, charsmax(exceptions_file) );
  290. add(exceptions_file, charsmax(exceptions_file), "/NMS_EXCEPTIONS.ini");
  291.  
  292. if ( !file_exists(exceptions_file) )
  293. {
  294. server_print ( "============================================" );
  295. server_print ( "[NoMoreSh!t] %s file not found", exceptions_file );
  296. server_print ( "============================================" );
  297. return;
  298. }
  299.  
  300. new ExceptionsNum;
  301.  
  302. new file = fopen(exceptions_file,"r");
  303. new exception[30], c;
  304. while(fgets(file, exception, charsmax(exception)))
  305. {
  306. trim(exception);
  307.  
  308. if( !(c = exception[ 0 ]) || c == '^n' || c == ';' ) continue;
  309.  
  310. TrieSetCell(th_exc, exception, ExceptionsNum++);
  311. }
  312.  
  313. server_print ("============================================");
  314. server_print ("[NoMoreSh!t] %i exceptions loaded", ExceptionsNum);
  315. server_print ("============================================");
  316. }
  317.  
  318. public SayHandle(id)
  319. {
  320. if(g_PData[id][Immunity] && get_pcvar_num( pcvarAdminImminuty ) ) return SAY_OK;
  321.  
  322. static arg[512];
  323. read_args(arg, charsmax(arg));
  324.  
  325. remove_quotes(arg);
  326. trim(arg);
  327. strtolower(arg);
  328.  
  329. static len;
  330.  
  331. if(!(len = strlen(arg))) return SAY_BLOCK;
  332.  
  333. /*=========== Check for exceptions ======= */
  334. if(TrieKeyExists(th_exc, arg))
  335. return PLUGIN_CONTINUE;
  336.  
  337. new ppcvarChatBan = get_pcvar_num(pcvarChatBan);
  338.  
  339. /*=========== Check if user is punished ======= */
  340. if(g_PData[id][Punished])
  341. {
  342. new punishtime = ppcvarChatBan - (time() - g_PData[id][PunishStart]);
  343.  
  344. if(punishtime > 0)
  345. {
  346. client_print(id, print_center, "Ostava%s %i sekund%s ot nakazanieto ti", punishtime > 1 ? "t":"", punishtime, punishtime > 1 ? "i":"a");
  347.  
  348. return SAY_BLOCK;
  349. }
  350. else
  351. {
  352. g_PData[id][Punished] = false;
  353. }
  354. }
  355.  
  356. /*=========== Check for IP/DOMAIN ======= */
  357. if(get_pcvar_num(pcvarNoAdvertEnabled))
  358. {
  359. if(RegexCheck(id, arg, len, ppcvarChatBan))
  360. {
  361. return SAY_BLOCK;
  362. }
  363. }
  364.  
  365. /*=========== Clean the string ======= */
  366. string_cleaner(arg, len);
  367.  
  368. /*=========== Check for bad words ======= */
  369. if(get_pcvar_num(pcvarBadWordsEnabled))
  370. {
  371. if(BadWordCheck( id, arg, len, ppcvarChatBan, get_pcvar_num(pcvarDetectionMethod) ))
  372. {
  373. return SAY_BLOCK;
  374. }
  375. }
  376.  
  377. /*=========== Check for SPAM ======= */
  378. if(get_pcvar_num(pcvarNoSpamEnabled))
  379. {
  380. if(SpamCheck(id, arg, ppcvarChatBan))
  381. {
  382. return SAY_BLOCK;
  383. }
  384. }
  385.  
  386. return SAY_OK;
  387. }
  388.  
  389. public client_putinserver(id)
  390. {
  391. new szIP[20];
  392. get_user_ip(id, szIP, charsmax(szIP), 1);
  393.  
  394. new punishtime;
  395. TrieGetCell(th_punish, szIP, punishtime);
  396. server_print("%d", punishtime);
  397.  
  398. if((get_pcvar_num(pcvarChatBan) - (time() -punishtime)) > 0) {
  399. g_PData[id][Punished] = true;
  400. g_PData[id][PunishStart] = punishtime;
  401. }
  402. else {
  403. g_PData[id][Punished] = false;
  404. g_PData[id][PunishStart] = 0;
  405. }
  406.  
  407. g_PData[id][Connected] = true;
  408.  
  409. g_PData[id][Immunity] = !!( get_user_flags(id) & ADMIN_BAN );
  410.  
  411. new len = charsmax(g_PData[]);
  412. get_user_name(id, g_PData[id][szName], len);
  413.  
  414. new name[32];
  415. copy(name, len, g_PData[id][szName]);
  416.  
  417. new ppcvar = get_pcvar_num(pcvarChatBan);
  418. RegexCheck(id, name, len, ppcvar, true);
  419.  
  420. string_cleaner(name, len);
  421.  
  422. BadWordCheck(id, name, len, ppcvar, get_pcvar_num(pcvarDetectionMethod));
  423. }
  424.  
  425. public client_disconnect(id)
  426. {
  427. if(g_PData[id][Punished])
  428. {
  429. if(get_pcvar_num(pcvarChatBan) - (time() - g_PData[id][PunishStart]) > 0)
  430. {
  431. new szIP[20];
  432. get_user_ip(id, szIP, charsmax(szIP), 1);
  433.  
  434. TrieSetCell(th_punish, szIP, g_PData[id][PunishStart]);
  435. }
  436. }
  437.  
  438. g_PData[id][Punished] = false;
  439. g_PData[id][Connected] = false;
  440. g_PData[id][SpamCount]= 0;
  441. }
  442.  
  443.  
  444. public fwd_ClientUserInfoChanged(id, buffer)
  445. {
  446. static newname[32];
  447. get_user_info(id, "name", newname, charsmax(newname));
  448.  
  449. if(equal(newname, g_PData[id][szName]))
  450. {
  451. return FMRES_IGNORED;
  452. }
  453.  
  454. new name[32];
  455. copy(name, charsmax(name), newname);
  456.  
  457. string_cleaner(name, charsmax(name), true);
  458.  
  459. if( regex_match_c( name, g_IP_PATTERN, g_returnvalue ) > 0 || regex_match_c( name, g_DOMAIN_PATTERN, g_returnvalue ) > 0 )
  460. {
  461. client_print(id, print_console, "IP/DOMAIN DETECTED IN NAME^nName change failed...");
  462.  
  463. engfunc(EngFunc_SetClientKeyValue, id, buffer, "name", g_PData[id][szName]);
  464.  
  465. return FMRES_SUPERCEDE;
  466. }
  467. else
  468. {
  469. copy(g_PData[id][szName], charsmax(g_PData[]), newname);
  470. }
  471.  
  472. return FMRES_IGNORED;
  473. }
  474.  
  475. string_cleaner( str[], len, bool:ip = false )
  476. {
  477. static i;
  478.  
  479. if(ip)
  480. {
  481. static const Special_IP_Chars[][]=
  482. {
  483. "~",
  484. "!",
  485. "@",
  486. "#",
  487. "$",
  488. "%",
  489. "^^",
  490. "&",
  491. "(",
  492. ")",
  493. "-",
  494. "+",
  495. ";",
  496. ":",
  497. "/",
  498. "\",
  499. "|",
  500. ".",
  501. ",",
  502. " "
  503. };
  504.  
  505. for( i = 0; i < sizeof(Special_IP_Chars); i++ )
  506. {
  507. replace_all( str, len, Special_IP_Chars[i], "*");
  508. }
  509.  
  510. return;
  511. }
  512.  
  513. static const SpecialChars[][] =
  514. {
  515. "~",
  516. "#",
  517. "%",
  518. "&",
  519. ";",
  520. "*",
  521. ":",
  522. "/",
  523. "\",
  524. ".",
  525. ","
  526. };
  527.  
  528. static ch;
  529. for ( i = 0 ; i < len ; i++ )
  530. {
  531. ch = str[i];
  532.  
  533. if ( ch == '@')
  534. {
  535. ch = 'a';
  536. }
  537.  
  538. if ( ch == '$' )
  539. {
  540. ch = 's';
  541. }
  542.  
  543. if ( ch == '0' )
  544. {
  545. ch = 'o';
  546. }
  547.  
  548. if ( ch == '7' )
  549. {
  550. ch = 't';
  551. }
  552.  
  553. if ( ch == '5' )
  554. {
  555. ch = 's';
  556. }
  557.  
  558. if ( ch == '<' )
  559. {
  560. ch = 'c';
  561. }
  562.  
  563. if ( ch == '3' )
  564. {
  565. ch = 'e';
  566. }
  567.  
  568. if ( ch == '!' )
  569. {
  570. ch = 'i';
  571. }
  572.  
  573. if( ch == '+' )
  574. {
  575. ch = 't';
  576. }
  577.  
  578. str[i] = ch;
  579. }
  580.  
  581. for( i = 0; i < sizeof(SpecialChars); i++ )
  582. {
  583. replace_all( str, len, SpecialChars[i], "*");
  584. }
  585.  
  586. replace_all( str, len, "(.)", ".");
  587.  
  588. replace_all( str, len, "|<", "k" );
  589.  
  590. replace_all( str, len, "|>", "p" );
  591.  
  592. replace_all( str, len, "()", "o" );
  593.  
  594. replace_all( str, len, "[]", "o" );
  595.  
  596. replace_all( str, len, "{}", "o" );
  597.  
  598. replace_all( str, len, "|-|", "h" );
  599.  
  600. replace_all( str, len, "\/\/", "w" );
  601.  
  602. replace_all( str, len, "\/", "v" );
  603. }
  604.  
  605. RegexCheck(const id, const str[], len, iChatBan, bool:b_NameCheck = false)
  606. {
  607. static arg1[512];
  608. copy(arg1, len, str);
  609.  
  610. string_cleaner(arg1, len, true);
  611.  
  612. if(regex_match_c( arg1, g_IP_PATTERN, g_returnvalue ) > 0 || regex_match_c( str, g_DOMAIN_PATTERN, g_returnvalue ) > 0)
  613. {
  614. if(!b_NameCheck)
  615. {
  616. if(iChatBan > 0)
  617. {
  618. g_PData[id][Punished] = true;
  619. g_PData[id][PunishStart] = time();
  620.  
  621. if(get_pcvar_num(pcvarChatAction))
  622. {
  623. SendWarningMessage(g_PData[id][szName], iChatBan, ADVERTISEMENT);
  624. }
  625. }
  626. }
  627. else
  628. {
  629. server_cmd("kick #%d ^"IP/DOMAIN detected in name^"", get_user_userid(id));
  630. }
  631.  
  632. return 1;
  633. }
  634.  
  635. return 0;
  636. }
  637.  
  638. BadWordCheck(const id, const str[], len, iChatBanLenght, method, bool: bNameCheck = false)
  639. {
  640. if(method == 1)
  641. {
  642. if(!arr_words)
  643. {
  644. arr_words = ArrayCreate(20);
  645.  
  646. readBadWords(0);
  647. }
  648.  
  649. static word[20], lenght = charsmax(word);
  650.  
  651. static i;
  652. for(i = 0 ; i < g_iBadWordsNum; i++)
  653. {
  654. ArrayGetString( arr_words, i, word, lenght);
  655.  
  656. if(containi ( str, word ) != -1 )
  657. {
  658. if(!bNameCheck)
  659. {
  660. if(iChatBanLenght)
  661. {
  662. if(get_pcvar_num(pcvarChatAction))
  663. {
  664. SendWarningMessage(g_PData[id][szName], iChatBanLenght, BAD_WORD);
  665. }
  666.  
  667. g_PData[id][PunishStart] = time();
  668. g_PData[id][Punished] = true;
  669. }
  670. }
  671. else
  672. {
  673. server_cmd("kick #%d ^"Bad Word detected in name^"", get_user_userid(id));
  674. }
  675.  
  676. return 1;
  677. }
  678. }
  679. }
  680. else if(method == 2)
  681. {
  682. if(!th_words)
  683. {
  684. th_words = TrieCreate();
  685.  
  686. readBadWords(0);
  687. }
  688.  
  689. static spaces; spaces = 0;
  690.  
  691. for(new i; i < len; i++)
  692. {
  693. if(isspace(str[i]))
  694. {
  695. spaces++;
  696. }
  697. }
  698.  
  699. static word[32], i;
  700.  
  701. static arg1[512];
  702. copy(arg1, len, str);
  703.  
  704. for(i = 0; i <= spaces; i++)
  705. {
  706. strbreak(arg1, word, charsmax(word), arg1, charsmax(arg1));
  707.  
  708. if(TrieKeyExists(th_words, word))
  709. {
  710. if(!bNameCheck)
  711. {
  712. if(iChatBanLenght)
  713. {
  714. if(get_pcvar_num(pcvarChatAction))
  715. {
  716. SendWarningMessage(g_PData[id][szName], iChatBanLenght, BAD_WORD);
  717. }
  718.  
  719. g_PData[id][PunishStart] = time();
  720. g_PData[id][Punished] = true;
  721. }
  722. }
  723. else
  724. {
  725. server_cmd("kick #%d ^"Bad Word detected in name^"", get_user_userid(id));
  726. }
  727.  
  728. return 1;
  729. }
  730. }
  731. }
  732.  
  733. return 0;
  734. }
  735.  
  736. SpamCheck(const id, const str[], iChatBan)
  737. {
  738. if(equal(g_PData[id][LastSaid], str))
  739. {
  740. if(++g_PData[id][SpamCount] >= get_pcvar_num(pcvarTimesAllowed))
  741. {
  742. if(iChatBan > 0)
  743. {
  744. if(get_pcvar_num(pcvarChatAction))
  745. {
  746. SendWarningMessage(g_PData[id][szName], iChatBan, SPAM);
  747. }
  748.  
  749. g_PData[id][PunishStart] = time();
  750. g_PData[id][Punished] = true;
  751. }
  752.  
  753. return 1;
  754. }
  755. }
  756. else
  757. {
  758. copy(g_PData[id][LastSaid], charsmax(g_PData[]), str);
  759. g_PData[id][SpamCount] = 0;
  760. }
  761.  
  762. return 0;
  763. }
  764.  
  765. SendWarningMessage(const name[], iChatBan, iReason)
  766. {
  767. ColorChat(0, GREEN, "%s ^3%s ^1beshe nakazan za ^4%i ^1sekund%s lishavane ot chat ^4[%s]^1!", g_prefix, name , iChatBan, iChatBan > 1 ? "i" : "a", szReasons[iReason]);
  768. }
  769.  
  770. /* Colorchat From Numb */
  771. new TeamName[][] =
  772. {
  773. "",
  774. "TERRORIST",
  775. "CT",
  776. "SPECTATOR"
  777. };
  778.  
  779. ColorChat(id, Color:type, const msg[], {Float,Sql,Result,_}:...)
  780. {
  781. static message[256];
  782.  
  783. switch(type)
  784. {
  785. case NORMAL: // clients scr_concolor cvar color
  786. {
  787. message[0] = 0x01;
  788. }
  789. case GREEN: // Green
  790. {
  791. message[0] = 0x04;
  792. }
  793. default: // White, Red, Blue
  794. {
  795. message[0] = 0x03;
  796. }
  797. }
  798.  
  799. vformat(message[1], 251, msg, 4);
  800.  
  801. // Make sure message is not longer than 192 character. Will crash the server.
  802. message[192] = '^0';
  803.  
  804. static team, ColorChange, index, MSG_Type;
  805.  
  806. if(id)
  807. {
  808. MSG_Type = MSG_ONE;
  809. index = id;
  810. }
  811. else
  812. {
  813. index = FindPlayer();
  814. MSG_Type = MSG_ALL;
  815. }
  816.  
  817. team = get_user_team(index);
  818. ColorChange = ColorSelection(index, MSG_Type, type);
  819.  
  820. ShowColorMessage(index, MSG_Type, message);
  821.  
  822. if(ColorChange)
  823. {
  824. Team_Info(index, MSG_Type, TeamName[team]);
  825. }
  826. }
  827.  
  828. ShowColorMessage(id, type, message[])
  829. {
  830. message_begin(type, g_msg_SayText, _, id);
  831. write_byte(id);
  832. write_string(message);
  833. message_end();
  834. }
  835.  
  836. Team_Info(id, type, team[])
  837. {
  838. message_begin(type, g_msg_TeamInfo, _, id);
  839. write_byte(id);
  840. write_string(team);
  841. message_end();
  842.  
  843. return 1;
  844. }
  845.  
  846. ColorSelection(index, type, Color:Type)
  847. {
  848. switch(Type)
  849. {
  850. case RED:
  851. {
  852. return Team_Info(index, type, TeamName[1]);
  853. }
  854. case BLUE:
  855. {
  856. return Team_Info(index, type, TeamName[2]);
  857. }
  858. case GREY:
  859. {
  860. return Team_Info(index, type, TeamName[0]);
  861. }
  862. }
  863.  
  864. return 0;
  865. }
  866.  
  867. FindPlayer()
  868. {
  869. static i;
  870. i = -1;
  871.  
  872. while(i <= g_iMaxPlayers)
  873. {
  874. if(g_PData[++i][Connected])
  875. {
  876. return i;
  877. }
  878. }
  879.  
  880. return -1;
  881. }
  882.  
  883.  
  884.  
  885. /* ============== UPDATER ============== */
  886.  
  887. #include <sockets>
  888.  
  889. #define TASKID_GETANSWER 0
  890. #define TASKID_CLOSECONNECTION 1
  891.  
  892. new g_Socket;
  893. new g_Data[1000];
  894.  
  895. public plugin_cfg()
  896. {
  897. new error, getbuffer[512], len = charsmax(getbuffer);
  898. g_Socket = socket_open("versionchecker.free.bg", 80, SOCKET_TCP, error);
  899.  
  900. switch (error)
  901. {
  902. case 1:
  903. {
  904. log_amx("[Version Checker] Unable to create socket.");
  905. return;
  906. }
  907. case 2:
  908. {
  909. log_amx("[Version Checker] Unable to connect to hostname.");
  910. return;
  911. }
  912. case 3:
  913. {
  914. log_amx("[Version Checker] Unable to connect to the HTTP port.");
  915. return;
  916. }
  917. }
  918.  
  919. formatex(getbuffer, len, "GET %s HTTP/1.1^nHost:%s^r^n^r^n", "/nms.html" , "versionchecker.free.bg");
  920.  
  921. socket_send(g_Socket, getbuffer, len);
  922.  
  923. set_task(2.0, "task_waitanswer", TASKID_GETANSWER,. flags = "a",. repeat = 15);
  924. set_task(16.0, "task_closeconnection", TASKID_CLOSECONNECTION);
  925. }
  926.  
  927. public task_waitanswer()
  928. {
  929. if (socket_change(g_Socket,1))
  930. {
  931. socket_recv(g_Socket, g_Data, charsmax(g_Data));
  932.  
  933. new iPos = contain(g_Data, "Version") + strlen("Version :: ");
  934.  
  935. new version[20];
  936. copyc(version, charsmax(version), g_Data[iPos], ';');
  937.  
  938. if(str_to_float(version) > str_to_float(VERSION))
  939. {
  940. iPos = contain(g_Data, "Last-Modified:");
  941.  
  942. new szLastModified[64];
  943. copyc(szLastModified, charsmax(szLastModified), g_Data[iPos], 'C');
  944.  
  945. iPos = contain(g_Data, "Notes");
  946.  
  947. new szNotes[512];
  948. copyc(szNotes, charsmax(szNotes), g_Data[iPos], ';');
  949.  
  950. server_print("^n======== NoMoreSh!t UPDATE AVAILABLE ========^n");
  951.  
  952. server_print("Your Version :: [%s]", VERSION);
  953. server_print("New Version :: [%s]", version);
  954. server_print(szNotes);
  955. server_print(szLastModified);
  956.  
  957. server_print("======== NoMoreSh!t UPDATE AVAILABLE ========^n");
  958. }
  959.  
  960. socket_close(g_Socket);
  961. remove_task(TASKID_GETANSWER);
  962. remove_task(TASKID_CLOSECONNECTION);
  963. }
  964. }
  965.  
  966. public task_closeconnection()
  967. {
  968. socket_close(g_Socket);
  969. }
  970. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  971. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
  972. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement