Premium Sanchez 2468 Posted February 13, 2014 Premium Share Posted February 13, 2014 Hi, In this thread I will show you how you can implement an advanced spam protection to your server. The player can write the same message just after 5 seconds. The player will receive 1 minute of chat ban if he is trying to send the same message more than 3 times in 5 seconds. You can specify a blockspamlist.lst file which contains words. If the user sending a message which contains a words from the list, the player will receive 5 minutes of chat ban. (You can specify the time of the chat ban) You can specify a bannspamlist.lst file which contains words. If the user sending a message which contains a words from the list, the player will receive a ban. (You can specify the time of the ban) Open game/input_main.cpp and search for this: if (ch->IncreaseChatCounter() >= 10) Add this over that: if (!strcmp(ch->LastPlayerMessage, buf) && (thecore_pulse() < (ch->LastMessageAt + SPAM_WAIT_SEC * 25)) && !ch->SpamAllowBuf(buf) && ch->GetGMLevel() < GM_LOW_WIZARD) { if (ch->BlockChatAfter < 2) { ch->ChatPacket(CHAT_TYPE_INFO, ("You must wait 5 seconds to repeat your message")); ch->BlockChatAfter++; return iExtraLen; } else { ch->BlockChatAfter = 0; ch->PlayerPunish(false, SPAM_CHAT_BAN_TIME); return iExtraLen; } } else { if (!ch->BannListCheck(buf) && ch->GetGMLevel() < GM_LOW_WIZARD) { ch->PlayerPunish(true, SPAM_BAN_TIME); return iExtraLen; } if (!ch->SpamListCheck(buf) && ch->GetGMLevel() < GM_LOW_WIZARD) { ch->ChatPacket(CHAT_TYPE_INFO, ("You wrote a not allowed words!")); ch->PlayerPunish(false, SPAM_CHAT_BAN_TIME); return iExtraLen; } } Still in input_main.cpp search for this: ch->GetMapIndex(), strlen(ch->GetName()))); Add this under that: strcpy(ch->LastPlayerMessage, buf); ch->LastMessageAt = thecore_pulse(); ch->BlockChatAfter = 0; Open game/char.h and search for this: BYTE GetChatCounter() const; Add this under that: int LastMessageAt; int BlockChatAfter; char LastPlayerMessage[CHAT_MAX_LEN + 1]; void PlayerPunish(bool PowerPunish, int Duration); bool SpamListCheck(const char *Message); bool BannListCheck(const char *Message); bool SpamAllowBuf(const char *Message); Open game/char.cpp and add these events: void CHARACTER::PlayerPunish(bool PowerPunish, int Duration) { if (!PowerPunish) { AddAffect(AFFECT_BLOCK_CHAT, POINT_NONE, 0, AFF_NONE, Duration, 0, true); sys_log(0, "%s[%d] has been chatbanned because of spamming/writing words which are in the spamlist.txt", GetName(), GetPlayerID()); } else { std::auto_ptr<SQLMsg> msg(DBManager::instance().DirectQuery("UPDATE account.account SET availDt = FROM_UNIXTIME(UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) + %i) WHERE id = %d", Duration, GetAID())); sys_log(0, "%s[%d] has been banned because of saying blacklisted word", GetName(), GetPlayerID()); GetDesc()->DelayedDisconnect(5); } } bool CHARACTER::SpamAllowBuf(const char *Message) { if (!strcmp(Message, "(Ȳ´ç)") || !strcmp(Message, "(µ·)") || !strcmp(Message, "(±â»Ý)") || !strcmp(Message, "(ÁÁľĆ)") || !strcmp(Message, "(»ç¶ű)") || !strcmp(Message, "(şĐłë)") || !strcmp(Message, "(ľĆÇĎ)") || !strcmp(Message, "(żěżď)") || !strcmp(Message, "(ÁËĽŰ)")) { return true; } return false; } bool CHARACTER::SpamListCheck(const char *Message) { for (int i = 0; i < SpamBlockListArray.size(); i++) { if (!strcmp(Message, SpamBlockListArray[i].c_str())) { return false; } } return true; } bool CHARACTER::BannListCheck(const char *Message) { for (int i = 0; i < SpamBannListArray.size(); i++) { if (!strcmp(Message, SpamBannListArray[i].c_str())) { return false; } } return true; } Add 2 new files to your project: spamblock.cpp spamblock.h Add these to the spamblock.cpp #include "fstream" #include "string" #include "sstream" #include "stdafx.h" #include "../../common/length.h" std::vector<std::string> SpamBlockListArray; std::vector<std::string> SpamBannListArray; void LoadBlockSpamList() { std::string TempBlockList; std::ifstream File("chat/blockspamlist.lst"); if (!File.is_open()) { sys_log(0, "WARNING: cannot open chat/blockspamlist.lst"); return; } SpamBlockListArray.clear(); while (!File.eof()) { File >> TempBlockList; SpamBlockListArray.push_back(TempBlockList); } File.close(); } void LoadBannSpamList() { std::string TempBannList; std::ifstream File("chat/bannspamlist.lst"); if (!File.is_open()) { sys_log(0, "WARNING: cannot open chat/bannspamlist.lst"); return; } SpamBannListArray.clear(); while (!File.eof()) { File >> TempBannList; SpamBannListArray.push_back(TempBannList); } File.close(); } Add these to the spamblock.h #include "string" #include "../../common/length.h" extern void LoadBlockSpamList(); extern void LoadBannSpamList(); extern std::vector<std::string> SpamBlockListArray; extern std::vector<std::string> SpamBannListArray; Add this to game/char.cpp #include "spamblock.h" Add this to game/main.cpp #include "spamblock.h" Search for this in game/main.cpp: PanamaLoad(); Add these under that: LoadBlockSpamList(); LoadBannSpamList(); Open common/length.h and add these: SPAM_WAIT_SEC = 5, // The player can duplicate his message after 5 sec SPAM_CHAT_BAN_TIME = 60, // The player will receive 60 seconds chat ban, if he is saying a spamlist word SPAM_BAN_TIME = 3600, // The player will receive 1 hour ban, if he is saying a banlist word Open game/cmd_gm.cpp and search for this event: ACMD(do_reload) Add this to the switch function: case 'b': ch->ChatPacket(CHAT_TYPE_INFO, "Reloading bann/spam list infomations."); LoadBlockSpamList(); LoadBannSpamList(); sys_log(0, "Reloading bann/spam list infomations."); break; Add this to the top of the file: #include "spamblock.h" How to set up: Make sure you added everything to your game Create a new folder called chat in your channels Create 2 files, blockspamlist.lst and bannspamlist.lst Upload the words to these files Restart your server blockspamlist.lst example: obsceneword1 obsceneword2 obsceneword3 obsceneword4 bannspamlist.lst example: WWW.CHEAP-FARM-SERVICE.COM WWW.CHEAP-GOLD.COM WWW.EASY-HACKS.COM WWW.FREE-YANG.COM If you have any question or suggestion, please just reply to this topic. Kind Regards,Sanchez 44 Link to comment Share on other sites More sharing options...
Saddler 680 Posted February 14, 2014 Share Posted February 14, 2014 Regards 2 Link to comment Share on other sites More sharing options...
Premium Shogun 4591 Posted February 14, 2014 Premium Share Posted February 14, 2014 Awesome I think we will use this. 1 Link to comment Share on other sites More sharing options...
Rumor 2608 Posted February 14, 2014 Share Posted February 14, 2014 that's really cool 1 Link to comment Share on other sites More sharing options...
-TÜRK- 23 Posted February 14, 2014 Share Posted February 14, 2014 Awesome! Thanks, sanchez... I will use it. 1 Link to comment Share on other sites More sharing options...
Honorable Member xP3NG3Rx 19685 Posted February 14, 2014 Honorable Member Share Posted February 14, 2014 Hmm, really nice. One idea is to: Extend the gm command by name reload to reloading the text files for example: /reload bann or something else if it is possible Sorry for my bad english, I hope you mean it. Magyarul: Bővítsd ki a /reload parancsot, hogy ne kelljen újraindítani a szervert ha frissülnek a szöveges fájlok. 1 Link to comment Share on other sites More sharing options...
Premium Sanchez 2468 Posted February 14, 2014 Author Premium Share Posted February 14, 2014 Great idea, thanks. Link to comment Share on other sites More sharing options...
Saddler 680 Posted February 14, 2014 Share Posted February 14, 2014 Can you add except GM's function? Regards 1 Link to comment Share on other sites More sharing options...
Premium Sanchez 2468 Posted February 14, 2014 Author Premium Share Posted February 14, 2014 Hi guys, The first post has been updated with these changes: You don't need to specify the length of the files anymore GMs can spam and write blacklisted words With the /reload b command you can reload the block and ban list, so you don't need to restart the server if you are added new words 1 1 Link to comment Share on other sites More sharing options...
-TÜRK- 23 Posted February 16, 2014 Share Posted February 16, 2014 Sanchez, today I tried to your system in my core development. But there is a little bug. 5 Second spam rule does not work, except this block spam & ban word works as well. if (buflen > 1 && *buf == '/') { interpret_command(ch, buf + 1, buflen - 1); return iExtraLen; } if (!strcmp(ch->LastPlayerMessage, buf) && (thecore_pulse() < (ch->LastMessageAt + SPAM_WAIT_SEC * 25)) && !ch->SpamAllowBuf(buf) && ch->GetGMLevel() < GM_LOW_WIZARD) { if (ch->BlockChatAfter < 2) { ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("You must wait 5 seconds to repeat your message.")); ch->BlockChatAfter++; return iExtraLen; } else { ch->BlockChatAfter = 0; ch->PlayerPunish(false, SPAM_CHAT_BAN_TIME); return iExtraLen; } } else { if (!ch->BannListCheck(buf) && ch->GetGMLevel() < GM_LOW_WIZARD) { ch->PlayerPunish(true, SPAM_BAN_TIME); ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("You has been banned %d minute because of saying blacklisted word."), SPAM_BAN_TIME); return iExtraLen; } if (!ch->SpamListCheck(buf) && ch->GetGMLevel() < GM_LOW_WIZARD) { ch->PlayerPunish(false, SPAM_CHAT_BAN_TIME); ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Your chat has been banned %d minute because of saying spamming word."), SPAM_CHAT_BAN_TIME); return iExtraLen; } } if (ch->IncreaseChatCounter() >= 10) { if (ch->GetChatCounter() == 10) { sys_log(0, "CHAT_HACK: %s", ch->GetName()); ch->GetDesc()->DelayedDisconnect(5); } return iExtraLen; } Interesting? 1 Link to comment Share on other sites More sharing options...
dukaibalu1 39 Posted February 16, 2014 Share Posted February 16, 2014 5 Second spam only works with the player character 1 Link to comment Share on other sites More sharing options...
Premium Sanchez 2468 Posted February 16, 2014 Author Premium Share Posted February 16, 2014 Sanchez, today I tried to your system in my core development. But there is a little bug. 5 Second spam rule does not work, except this block spam & ban word works as well. Interesting? Maybe because of in the last update I made a GM check. ch->GetGMLevel() < GM_LOW_WIZARD If your GM level is bigger than GM_LOW_WIZARD then you can spam and write blacklisted words. Link to comment Share on other sites More sharing options...
-TÜRK- 23 Posted February 16, 2014 Share Posted February 16, 2014 No, I tried in GM_PLAYER char. On same char, block list, spam list etc. working but no luck for 5 second spam func.. Link to comment Share on other sites More sharing options...
Premium Sanchez 2468 Posted February 16, 2014 Author Premium Share Posted February 16, 2014 Interesting, it works properly for me. Maybe check it with writing the line of the actual running code with this: sys_log(0, "%d", __LINE__); Link to comment Share on other sites More sharing options...
-TÜRK- 23 Posted February 16, 2014 Share Posted February 16, 2014 Which rev you are using? I am using novaline.? Link to comment Share on other sites More sharing options...
Premium Sanchez 2468 Posted February 16, 2014 Author Premium Share Posted February 16, 2014 I'm using the mainline, but I don't think there is "chat" different between these lines. If you give me Teamviewer I can check it for you. 1 Link to comment Share on other sites More sharing options...
Shichirojii 8 Posted March 18, 2014 Share Posted March 18, 2014 You're awesome, very good contributions to this forum Link to comment Share on other sites More sharing options...
Dumik 7 Posted March 30, 2014 Share Posted March 30, 2014 Hello everybody, i would like to ask you to one thing. You must create a new enum? For Spam system? if so how am I supposed to write Open common/length.h and add these: ? 1 2 3 SPAM_WAIT_SEC = 5, // The player can duplicate his message after 5 sec SPAM_CHAT_BAN_TIME = 60, // The player will receive 60 seconds chat ban, if he is saying a spamlist word SPAM_BAN_TIME = 3600, // The player will receive 1 hour ban, if he is saying a banlist word Thank you a lot Dumik Link to comment Share on other sites More sharing options...
Premium Sanchez 2468 Posted March 30, 2014 Author Premium Share Posted March 30, 2014 No, you don't need to create a new enum, just add to the EMisc. Link to comment Share on other sites More sharing options...
Dumik 7 Posted April 1, 2014 Share Posted April 1, 2014 Hello everybody, i have another problem. I add all codes. Compilation was successful but when i login as GM the client kick me out after loading window. in syserror is this: 0401 19:45:40573 :: Unknown packet header: 148, last: 45 81 Do you know how to fix it? Thank you a lot Best regards, Vojta Link to comment Share on other sites More sharing options...
Premium Sanchez 2468 Posted April 1, 2014 Author Premium Share Posted April 1, 2014 Interesting, because we not modifying the packets, are you sure you made just these changes? Link to comment Share on other sites More sharing options...
Dumik 7 Posted April 2, 2014 Share Posted April 2, 2014 Yes im pretty sure. i checked 10 times. Thank you. Best regards, Vojta (Dumik) Link to comment Share on other sites More sharing options...
Bot Metin2 Dev 4886 Posted May 10, 2014 Bot Share Posted May 10, 2014 i cant find game/input_main.cpp i searched everywhere on filezilla . where it could be guys? Link to comment Share on other sites More sharing options...
ronniwe 2 Posted July 31, 2014 Share Posted July 31, 2014 I have this error: linking ../game_r40999.... .obj/char.o: In function `std::vector<std::string, std::allocator<std::string> >::size() const': /usr/include/c++/4.2/bits/stl_vector.h:408: undefined reference to `SpamBlockListArray' /usr/include/c++/4.2/bits/stl_vector.h:408: undefined reference to `SpamBlockListArray' /usr/include/c++/4.2/bits/stl_vector.h:408: undefined reference to `SpamBannListArray' /usr/include/c++/4.2/bits/stl_vector.h:408: undefined reference to `SpamBannListArray' .obj/main.o: In function `main': /usr/xavi/source-server/Srcs/Server/game/src/main.cpp:512: undefined reference to `LoadBlockSpamList()' /usr/xavi/source-server/Srcs/Server/game/src/main.cpp:513: undefined reference to `LoadBannSpamList()' gmake: *** [../game_r40999] Error 1 Link to comment Share on other sites More sharing options...
Premium Sanchez 2468 Posted July 31, 2014 Author Premium Share Posted July 31, 2014 It looks you forgot to add #include "spamblock.h" to main.cpp. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now