- virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
- {
- if (target_type == TYPE_USER)
- {
- return MatchPattern((userrec*)dest, user, SILENCE_PRIVATE);
- }
- return 0;
- }
-
- virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
- {
- return MatchPattern((userrec*)dest, user, SILENCE_NOTICE);
- }
-
- virtual int OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel)
- {
- return MatchPattern(dest, source, SILENCE_INVITE);
- }
-
- int MatchPattern(userrec* dest, userrec* source, int pattern)
- {
- silencelist* sl;
- dest->GetExt("silence_list", sl);
- if (sl)
- {
- for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
- {
- if ((match(source->GetFullHost(), c->first.c_str())) && ( ((c->second & pattern) > 0)) || ((c->second & SILENCE_ALL) > 0))
- {
- if (((c->second & SILENCE_EXCLUDE) > 0))
- {
- return 0;
- }
- else {
- return 1;
- }
- }
- }
- }
- return 0;
- }
-
- virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
- {
- /* Implement the part of cmd_privmsg.cpp that handles *channel* messages, if cmd_privmsg.cpp
- * is changed this probably needs updating too. Also implement the actual write to the users
- * on the channel. This code is from channels.cpp, and should also be changed if channels.cpp
- * updates it's corresponding code
- */
- if ((validated) && (command == "PRIVMSG"))
- {
- char status = 0;
- if ((*parameters[0] == '@') || (*parameters[0] == '%') || (*parameters[0] == '+'))
- {
- status = *parameters[0];
- parameters[0]++;
- }
- if (parameters[0][0] == '#')
- {
- chanrec *chan;
- user->idle_lastmsg = ServerInstance->Time();
- chan = ServerInstance->FindChan(parameters[0]);
- if (chan)
- {
- if (IS_LOCAL(user))
- {
- if ((chan->modes[CM_NOEXTERNAL]) && (!chan->HasUser(user)))
- {
- user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
- return 1;
- }
- if ((chan->modes[CM_MODERATED]) && (chan->GetStatus(user) < STATUS_VOICE))
- {
- user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
- return 1;
- }
- }
- int MOD_RESULT = 0;
-
- std::string temp = parameters[1];
- FOREACH_RESULT(I_OnUserPreMessage,OnUserPreMessage(user,chan,TYPE_CHANNEL,temp,status));
- if (MOD_RESULT) {
- return 1;
- }
- parameters[1] = temp.c_str();
-
- if (temp == "")
- {
- user->WriteServ("412 %s No text to send", user->nick);
- return 1;
- }
-
- /* This next call into channel.cpp is the one that gets replaced by our modified method
- * chan->WriteAllExceptSender(user, false, status, "PRIVMSG %s :%s", chan->name, parameters[1]);
- */
- WriteAllExceptSenderAndSilenced(chan, user, false, status, "PRIVMSG %s :%s", chan->name, parameters[1]);
-
- FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,chan,TYPE_CHANNEL,parameters[1],status));
- return 1;
- }
- else
- {
- /* no such nick/channel */
- user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
- return 1;
- }
- return 1;
- }
- else
- {
- command_t* privmsg_command = ServerInstance->Parser->GetHandler("PRIVMSG");
- if (privmsg_command)
- {
- privmsg_command->Handle(parameters, pcnt, user);
- return 1;
- }
- else
- {
- ServerInstance->Log(DEBUG, "Could not find PRIVMSG Command!");
- }
- }
- }
- return 0;
- }
-
- /* Taken from channels.cpp and slightly modified, see OnPreCommand above*/
- void WriteAllExceptSenderAndSilenced(chanrec* chan, userrec* user, bool serversource, char status, char* text, ...)
- {
- char textbuffer[MAXBUF];
- va_list argsPtr;
-
- if (!text)
- return;
-
- va_start(argsPtr, text);
- vsnprintf(textbuffer, MAXBUF, text, argsPtr);
- va_end(argsPtr);
-
- this->WriteAllExceptSenderAndSilenced(chan, user, serversource, status, std::string(textbuffer));
- }
-
- /* Taken from channels.cpp and slightly modified, see OnPreCommand above*/
- void WriteAllExceptSenderAndSilenced(chanrec* chan, userrec* user, bool serversource, char status, const std::string& text)