fork download
  1. bool has_string_ip_ad(const std::string& s)
  2. {
  3. static const boost::regex e(".*0*([1-9][0-9]?|1[0-9]{2}|2[0-4][0-9]|25[0-5])[^0-9]+([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])[^0-9]+([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])[^0-9]+([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])[^0-9]+0*(102[4-9]|10[3-9][0-9]|1[1-9][0-9]{2}|[2-9][0-9]{3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-6]).*");
  4. return boost::regex_match(s, e);
  5. }
  6.  
  7. const std::vector<std::string> badwords =
  8. {
  9. "jebac",
  10. "jeban",
  11. "kurw",
  12. "korwa",
  13. "pierdol",
  14. "pierdal",
  15. "huj",
  16. "choj",
  17. "pizd",
  18. "kutas",
  19. "fuck",
  20. "cipa",
  21. "pedale",
  22. "szmato",
  23. "szmata",
  24. "szmaty",
  25. "szmatko",
  26. "szmatka",
  27. "szmatki",
  28. "zajebie",
  29. "zjeb",
  30. "suka",
  31. "suko",
  32. "suki",
  33. "ciota",
  34. "cioto",
  35. "cioty"
  36. };
  37.  
  38. const std::vector<std::string> badword_sizes =
  39. {
  40. "",
  41. "*",
  42. "**",
  43. "***",
  44. "****",
  45. "*****",
  46. "******",
  47. "*******",
  48. "********",
  49. "*********",
  50. "**********",
  51. "***********",
  52. "************",
  53. "*************",
  54. "**************",
  55. "***************"
  56. };
  57.  
  58. char PolishReplacement[0xFF];
  59.  
  60. const std::map<std::string, std::string> PolishReplacementMap =
  61. {
  62. { "ł","l" },
  63. { "ą","a" },
  64. { "ę","e" },
  65. { "ć","c" },
  66. { "ż","z" },
  67. { "ź","z" },
  68. { "ó","o" },
  69. { "ś","s" },
  70. { "ń","n" },
  71. { "Ł","L" },
  72. { "Ą","A" },
  73. { "Ę","E" },
  74. { "Ć","C" },
  75. { "Ż","Z" },
  76. { "Ź","Z" },
  77. { "Ó","O" },
  78. { "Ś","S" },
  79. { "Ń","N" }
  80. };
  81.  
  82. struct CPolishReplacementInitHack
  83. {
  84. CPolishReplacementInitHack()
  85. {
  86. for (unsigned char c = 0; c < 0xFF; ++c)
  87. {
  88. char tmpstr[2] = { c, 0 };
  89. std::string tmpstdstr(tmpstr);
  90. auto replacement = PolishReplacementMap.find(tmpstdstr);
  91. if (replacement == PolishReplacementMap.end())
  92. PolishReplacement[c] = boost::to_lower_copy(tmpstdstr)[0];
  93. else
  94. PolishReplacement[c] = boost::to_lower_copy(replacement->second)[0];
  95. }
  96. }
  97. } _CPolishReplacementInitHack;
  98.  
  99.  
  100. void FilterBadWords(std::string& s)
  101. {
  102. std::string str_copy(s);
  103. for (auto& character : str_copy)
  104. character = PolishReplacement[(unsigned char)character];
  105.  
  106. for (auto &badword : badwords)
  107. {
  108. size_t pos = str_copy.find(badword);
  109. size_t size;
  110. size_t possize;
  111. while (pos != std::string::npos)
  112. {
  113. size = badword.size();
  114. possize = pos + size;
  115.  
  116. s.replace(s.begin() + pos, s.begin() + possize, badword_sizes[size]);
  117. str_copy.replace(str_copy.begin() + pos, str_copy.begin() + possize, badword_sizes[size]);
  118.  
  119. pos = str_copy.find(badword);
  120. }
  121. }
  122. }
  123.  
  124. bool is_message_allowed(std::string& s, bool allowmodify = true, bool modify_only_if_allowed = false)
  125. {
  126. bool allowed = has_string_ip_ad(s);
  127. if (allowmodify && (modify_only_if_allowed ? allowed : true))
  128. FilterBadWords(s);
  129. return !allowed;
  130. }
  131.  
  132. extern std::vector<std::string> testing;
  133.  
  134. class tester : public Extension::Base
  135. {
  136. public:
  137. bool OnGameModeInit()
  138. {
  139. int IP_ads = 0;
  140. int NOIP_ads = 0;
  141. unsigned long long times[2] = { Functions::GetTime(), 0 };
  142. for (auto& i : testing)
  143. {
  144. if (!is_message_allowed(i))
  145. {
  146. ++IP_ads;
  147. //std::cout << "BAD MESSAGE: ('" << i << "')" << std::endl;
  148. }
  149. else ++NOIP_ads;
  150. }
  151. times[1] = Functions::GetTime();
  152. std::cout << "Time: " << times[1] - times[0] << " ms. |" << IP_ads << "/" << NOIP_ads << "|" << std::endl;
  153. return true;
  154. }
  155. } _tester;
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:34: error: 'string' in namespace 'std' does not name a type
 bool has_string_ip_ad(const std::string& s)
                                  ^
prog.cpp: In function 'bool has_string_ip_ad(const int&)':
prog.cpp:3:15: error: 'boost' does not name a type
  static const boost::regex e(".*0*([1-9][0-9]?|1[0-9]{2}|2[0-4][0-9]|25[0-5])[^0-9]+([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])[^0-9]+([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])[^0-9]+([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])[^0-9]+0*(102[4-9]|10[3-9][0-9]|1[1-9][0-9]{2}|[2-9][0-9]{3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-6]).*");
               ^
prog.cpp:4:9: error: 'boost' has not been declared
  return boost::regex_match(s, e);
         ^
prog.cpp:4:31: error: 'e' was not declared in this scope
  return boost::regex_match(s, e);
                               ^
prog.cpp: At global scope:
prog.cpp:7:12: error: 'vector' in namespace 'std' does not name a template type
 const std::vector<std::string> badwords = 
            ^
prog.cpp:38:12: error: 'vector' in namespace 'std' does not name a template type
 const std::vector<std::string> badword_sizes =
            ^
prog.cpp:60:12: error: 'map' in namespace 'std' does not name a template type
 const std::map<std::string, std::string> PolishReplacementMap =
            ^
prog.cpp: In constructor 'CPolishReplacementInitHack::CPolishReplacementInitHack()':
prog.cpp:88:28: warning: narrowing conversion of 'c' from 'unsigned char' to 'char' inside { } [-Wnarrowing]
    char tmpstr[2] = { c, 0 };
                            ^
prog.cpp:89:4: error: 'string' is not a member of 'std'
    std::string tmpstdstr(tmpstr);
    ^
prog.cpp:90:23: error: 'PolishReplacementMap' was not declared in this scope
    auto replacement = PolishReplacementMap.find(tmpstdstr);
                       ^
prog.cpp:90:49: error: 'tmpstdstr' was not declared in this scope
    auto replacement = PolishReplacementMap.find(tmpstdstr);
                                                 ^
prog.cpp:92:28: error: 'boost' has not been declared
     PolishReplacement[c] = boost::to_lower_copy(tmpstdstr)[0];
                            ^
prog.cpp:94:28: error: 'boost' has not been declared
     PolishReplacement[c] = boost::to_lower_copy(replacement->second)[0];
                            ^
prog.cpp: At global scope:
prog.cpp:100:26: error: variable or field 'FilterBadWords' declared void
 void FilterBadWords(std::string& s)
                          ^
prog.cpp:100:21: error: 'string' is not a member of 'std'
 void FilterBadWords(std::string& s)
                     ^
prog.cpp:100:34: error: 's' was not declared in this scope
 void FilterBadWords(std::string& s)
                                  ^
stdout
Standard output is empty