00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "inspircd.h"
00015
00016
00017
00020 class User_d : public ModeHandler
00021 {
00022 public:
00023 User_d(InspIRCd* Instance) : ModeHandler(Instance, 'd', 0, 0, false, MODETYPE_USER, false) { }
00024
00025 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
00026 {
00027 if (adding)
00028 {
00029 if (!dest->IsModeSet('d'))
00030 {
00031 dest->WriteServ("NOTICE %s :*** You have enabled usermode +d, deaf mode. This mode means you WILL NOT receive any messages from any channels you are in. If you did NOT mean to do this, use /mode %s -d.", dest->nick.c_str(), dest->nick.c_str());
00032 dest->SetMode('d',true);
00033 return MODEACTION_ALLOW;
00034 }
00035 }
00036 else
00037 {
00038 if (dest->IsModeSet('d'))
00039 {
00040 dest->SetMode('d',false);
00041 return MODEACTION_ALLOW;
00042 }
00043 }
00044 return MODEACTION_DENY;
00045 }
00046 };
00047
00048 class ModuleDeaf : public Module
00049 {
00050 User_d* m1;
00051
00052 std::string deaf_bypasschars;
00053 std::string deaf_bypasschars_uline;
00054
00055 public:
00056 ModuleDeaf(InspIRCd* Me)
00057 : Module(Me)
00058 {
00059 m1 = new User_d(ServerInstance);
00060 if (!ServerInstance->Modes->AddMode(m1))
00061 throw ModuleException("Could not add new modes!");
00062
00063 OnRehash(NULL, "");
00064 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnRehash, I_OnBuildExemptList };
00065 ServerInstance->Modules->Attach(eventlist, this, 4);
00066 }
00067
00068
00069 virtual void OnRehash(User* user, const std::string&)
00070 {
00071 ConfigReader* conf = new ConfigReader(ServerInstance);
00072 deaf_bypasschars = conf->ReadValue("deaf", "bypasschars", 0);
00073 deaf_bypasschars_uline = conf->ReadValue("deaf", "bypasscharsuline", 0);
00074
00075 delete conf;
00076 }
00077
00078 virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
00079 {
00080 if (target_type == TYPE_CHANNEL)
00081 {
00082 Channel* chan = (Channel*)dest;
00083 if (chan)
00084 this->BuildDeafList(MSG_NOTICE, chan, user, status, text, exempt_list);
00085 }
00086
00087 return 0;
00088 }
00089
00090 virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
00091 {
00092 if (target_type == TYPE_CHANNEL)
00093 {
00094 Channel* chan = (Channel*)dest;
00095 if (chan)
00096 this->BuildDeafList(MSG_PRIVMSG, chan, user, status, text, exempt_list);
00097 }
00098
00099 return 0;
00100 }
00101
00102 virtual void OnBuildExemptList(MessageType message_type, Channel* chan, User* sender, char status, CUList &exempt_list, const std::string &text)
00103 {
00104 BuildDeafList(message_type, chan, sender, status, text, exempt_list);
00105 }
00106
00107 virtual void BuildDeafList(MessageType message_type, Channel* chan, User* sender, char status, const std::string &text, CUList &exempt_list)
00108 {
00109 CUList *ulist = chan->GetUsers();
00110 bool is_a_uline;
00111 bool is_bypasschar, is_bypasschar_avail;
00112 bool is_bypasschar_uline, is_bypasschar_uline_avail;
00113
00114 is_bypasschar = is_bypasschar_avail = is_bypasschar_uline = is_bypasschar_uline_avail = 0;
00115 if (!deaf_bypasschars.empty())
00116 {
00117 is_bypasschar_avail = 1;
00118 if (deaf_bypasschars.find(text[0], 0) != std::string::npos)
00119 is_bypasschar = 1;
00120 }
00121 if (!deaf_bypasschars_uline.empty())
00122 {
00123 is_bypasschar_uline_avail = 1;
00124 if (deaf_bypasschars_uline.find(text[0], 0) != std::string::npos)
00125 is_bypasschar_uline = 1;
00126 }
00127
00128
00129
00130
00131
00132 if (!is_bypasschar_uline_avail && is_bypasschar)
00133 return;
00134
00135 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
00136 {
00137
00138 if (!i->first->IsModeSet('d'))
00139 continue;
00140
00141 if (is_bypasschar && is_bypasschar_uline)
00142 continue;
00143
00144 is_a_uline = ServerInstance->ULine(i->first->server);
00145
00146 if (is_bypasschar_uline && is_a_uline)
00147 continue;
00148
00149 if (is_bypasschar && !is_a_uline)
00150 continue;
00151
00152 if (status && !strchr(chan->GetAllPrefixChars(i->first), status))
00153 continue;
00154
00155
00156 exempt_list[i->first] = i->first->nick;
00157 }
00158 }
00159
00160 virtual ~ModuleDeaf()
00161 {
00162 ServerInstance->Modes->DelMode(m1);
00163 delete m1;
00164 }
00165
00166 virtual Version GetVersion()
00167 {
00168 return Version("$Id: m_deaf.cpp 10622 2008-10-04 21:27:52Z brain $", VF_COMMON|VF_VENDOR,API_VERSION);
00169 }
00170
00171 };
00172
00173 MODULE_INIT(ModuleDeaf)