[Chat] block links

Pls help me

class System_Censure : public PlayerScript{

public:

System_Censure() : PlayerScript(“System_Censure”) {}

void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg)

{

if (msg == “http://” || msg == “www” || msg == “.org” || msg == “.biz” || msg == “.ru” || msg == “.com”)

msg = “[Реклама запрещена]”;

}

void OnChat(Player *player, uint32 /type/, uint32 /lang/, std::string& msg, Player *receiver)

{

if (msg == “http://” || msg == “www” || msg == “.org” || msg == “.biz” || msg == “.ru” || msg == “.com”)

msg = “[Реклама запрещена]”;

}

void OnChat(Player *player, uint32 type, uint32 /lang/, std::string& msg, Group *group)

{

if (msg == “http://” || msg == “www” || msg == “.org” || msg == “.biz” || msg == “.ru” || msg == “.com”)

msg = “[Реклама запрещена]”;

}

void OnChat(Player *player, uint32 type, uint32 lang, std::string& msg, Guild *guild)

{

if (msg == “http://” || msg == “www” || msg == “.org” || msg == “.biz” || msg == “.ru” || msg == “.com”)

msg = “[Реклама запрещена]”;

}

void OnChat(Player *player, uint32 /type/, uint32 /lang/, std::string& msg, Channel *channel)

{

if (msg == “http://” || msg == “www” || msg == “.org” || msg == “.biz” || msg == “.ru” || msg == “.com”)

msg = “[Реклама запрещена]”;

}

};

void AddSC_System_Censure()

{

new System_Censure();

}

help me finish this mod.

http://www.trinitycore.org/f/topic/6489-chat-filter/

It only works if the message is “.com”, “.org”, etc… use strstr instead, strstr(msg, “.com”)

example?

strstr? you mean substr?

Yes

You can add chat censor for custom .chat command to?

I believe the regex library is part of the C++11 spec. As we’re supposed to be using C++11 capable compilers already, why not just implement a new table that holds regex patterns to filter, read that into an array and have your check cycle through the array for any matches? Regex may be cryptic to start with, but it can provide for a very flexible filtering system. In fact, in the data we extracted from the client, you should have SpamMessages.dbc (a file that is full of regex patterns). I even tried to suggest that regex be implemented a little over a month ago (see http://www.trinitycore.org/f/topic/9214-updated-trinitycore-requirements-deprecation-of-old-compilers/page-2?hl=regex#entry63371).

Further checking shows that currently available C++11 compilers are inconsistent on the regex implementation. Even gcc needs to be a 4.9 version to have it, so a 3rd party regex would need to be added at this time to allow the supported platforms to use regex in the core. I still think that regex would be the best way to go with any sort of chat filtering system, though.