HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <regex>
  4.  
  5. // Preprocessor macros (Config)
  6. #define BAN_TIME 200
  7. #define BAN_NICK_REASON "Spam miatt kickelve!"
  8. #define BAN_MSG_REASON "Spam uzenet!"
  9. #define IN_GAME_WARNING_MSG "Figyelmeztetes! Ne hirdess, semmifele szerveren"
  10.  
  11. public plugin_init()
  12. {
  13. register_plugin("Anti-Spam Lite", "1.0.4", "NullWarez")
  14. register_clcmd("say","check_player_msg")
  15. register_clcmd("say_team","check_player_msg")
  16. }
  17.  
  18. // Check the nick when connecting
  19. public client_connect(id)
  20. {
  21. if(is_user_admin(id))
  22. return PLUGIN_CONTINUE
  23.  
  24. new g_name[32]
  25. get_user_name(id, g_name,31)
  26.  
  27. if(is_invalid(g_name))
  28. {
  29. server_cmd("amx_ban BAN_TIME #%d BAN_NICK_REASON", get_user_userid(id))
  30. return PLUGIN_CONTINUE
  31. }
  32. set_task(20.0, "showWarning", id)
  33. return PLUGIN_CONTINUE
  34. }
  35.  
  36. // Checks the message for spam
  37. bool:is_invalid(const text[])
  38. {
  39. new error[50], num
  40. new Regex:regex = regex_match (text, "[a-z0-9-]{3,}\.[a-z]{1,2}(\S)", num, error, 49, "i")
  41. if(regex >= REGEX_OK)
  42. {
  43. regex_free(regex)
  44. return true
  45. }
  46.  
  47. regex = regex_match(text, "([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}", num, error, 49)
  48. if(regex >= REGEX_OK)
  49. {
  50. regex_free(regex)
  51. return true
  52. }
  53.  
  54. return false
  55. }
  56.  
  57. // Displays a warning ban for spam
  58. public showWarning(id)
  59. {
  60. if(is_user_connected(id))
  61. client_print(id, print_chat, "IN_GAME_WARNING_MSG")
  62. }
  63.  
  64. // Check say or say_team message
  65. public check_player_msg(id)
  66. {
  67. if(is_user_admin(id))
  68. return PLUGIN_CONTINUE
  69.  
  70. new text[128]
  71. read_args(text,127)
  72. if(is_invalid(text))
  73. {
  74. server_cmd("amx_ban BAN_TIME #%d BAN_MSG_REASON", get_user_userid(id))
  75. return PLUGIN_HANDLED
  76. }
  77. return PLUGIN_CONTINUE
  78. }
  79.  
  80. // Called when set name
  81. public client_infochanged(id)
  82. {
  83. if(is_user_admin(id))
  84. return PLUGIN_CONTINUE
  85.  
  86. if(!is_user_alive(id)) // loop fix
  87. return PLUGIN_CONTINUE
  88.  
  89. new g_name[32]
  90. get_user_name(id, g_name,31)
  91.  
  92. if(is_invalid(g_name))
  93. {
  94. server_cmd("amx_ban BAN_TIME #%d BAN_NICK_REASON", get_user_userid(id))
  95. return PLUGIN_CONTINUE
  96. }
  97. return PLUGIN_CONTINUE
  98. }
  99.