VegaS1234

[C++] Auto Block Chat System

Aug 13th, 2017
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. //1.) Search for:
  2. extern int g_nPortalLimitTime;
  3. //2.) Add after:
  4. #include <boost/format.hpp>
  5. #define AUTO_BLOCK_CHAT_TIME 60
  6. #define AUTO_BLOCK_CHAT_FILE "locale/country/banword.txt"
  7.  
  8. //1.) Search for:
  9.     if (true == SpamBlockCheck(ch, buf, buflen))
  10.     {
  11.         return iExtraLen;
  12.     }
  13. //2.) Add after:
  14.     // START OF AUTO BLOCK CHAT //
  15.     std::string c_pszContent(buf);
  16.     std::string c_pszCommand = str(boost::format("%s %d") % ch->GetName() % AUTO_BLOCK_CHAT_TIME);
  17.     std::string c_pszDelimiter = ",";
  18.  
  19.     FILE *fp = fopen(AUTO_BLOCK_CHAT_FILE, "r");
  20.     if (!fp)
  21.     {
  22.         sys_err("Cannot open %s", AUTO_BLOCK_CHAT_FILE);
  23.         return iExtraLen;
  24.     }
  25.  
  26.     char szLine[1024];
  27.     fscanf(fp, "%[^\n]", szLine);
  28.     std::string c_pszString(szLine);
  29.        
  30.     size_t pos = 0;
  31.     std::string token;
  32.     while ((pos = c_pszString.find(c_pszDelimiter)) != std::string::npos)
  33.     {
  34.         token = c_pszString.substr(0, pos);
  35.         c_pszString.erase(0, pos + c_pszDelimiter.length());
  36.         std::size_t position = c_pszContent.find(token);
  37.  
  38.         if (position != std::string::npos)
  39.         {
  40.             if (!ch->FindAffect(AFFECT_BLOCK_CHAT))
  41.             {
  42.                 char buf[256];
  43.                 snprintf(buf, sizeof(buf), "Player %s has been blocked chat for %d seconds.", ch->GetName(), AUTO_BLOCK_CHAT_TIME);
  44.                 SendNotice(buf);
  45.                 interpret_command(NULL, "block_chat", 10);
  46.             }
  47.         }
  48.     }
  49.     fclose(fp);
  50.     // END OF AUTO BLOCK CHAT //
Advertisement
Add Comment
Please, Sign In to add comment