diff options
-rw-r--r-- | src/modules/m_setname.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_silence.cpp | 141 | ||||
-rw-r--r-- | src/modules/m_swhois.cpp | 49 | ||||
-rw-r--r-- | src/modules/m_testcommand.cpp | 48 |
4 files changed, 135 insertions, 105 deletions
diff --git a/src/modules/m_setname.cpp b/src/modules/m_setname.cpp index 892d934c0..39185744b 100644 --- a/src/modules/m_setname.cpp +++ b/src/modules/m_setname.cpp @@ -30,7 +30,7 @@ Server *Srv; class cmd_setname : public command_t { public: - cmd_setname () : command_t("SETNAME", 0, 1); + cmd_setname () : command_t("SETNAME", 0, 1) { this->source = "m_setname.so"; } diff --git a/src/modules/m_silence.cpp b/src/modules/m_silence.cpp index 9933cc9bf..86f12633d 100644 --- a/src/modules/m_silence.cpp +++ b/src/modules/m_silence.cpp @@ -33,103 +33,112 @@ using namespace std; // have one of these structures associated with their user record. typedef std::vector<std::string> silencelist; - -void handle_silence(char **parameters, int pcnt, userrec *user) +class cmd_silence : public command_t { - if (!pcnt) + public: + cmd_silence() : command_t("SILENCE", 0, 1) { - // no parameters, show the current silence list. - // Use Extensible::GetExt to fetch the silence list - silencelist* sl = (silencelist*)user->GetExt("silence_list"); - // if the user has a silence list associated with their user record, show it - if (sl) - { - for (silencelist::const_iterator c = sl->begin(); c < sl->end(); c++) - { - WriteServ(user->fd,"271 %s %s %s!*@*",user->nick, user->nick,c->c_str()); - } - } - WriteServ(user->fd,"272 %s :End of Silence List",user->nick); + this->source = "m_silence.so"; } - else if (pcnt > 0) + + void Handle (char **parameters, int pcnt, userrec *user) { - // one or more parameters, add or delete entry from the list (only the first parameter is used) - char *nick = parameters[0]; - if (nick[0] == '-') + if (!pcnt) { - // removing an item from the list - nick++; - // fetch their silence list + // no parameters, show the current silence list. + // Use Extensible::GetExt to fetch the silence list silencelist* sl = (silencelist*)user->GetExt("silence_list"); - // does it contain any entries and does it exist? + // if the user has a silence list associated with their user record, show it if (sl) { - if (sl->size()) - { - for (silencelist::iterator i = sl->begin(); i != sl->end(); i++) - { - // search through for the item - irc::string listitem = i->c_str(); - irc::string target = nick; - if (listitem == target) - { - sl->erase(i); - WriteServ(user->fd,"950 %s %s :Removed %s!*@* from silence list",user->nick, user->nick,nick); - // we have modified the vector from within a loop, we must now bail out - return; - } - } - } - if (!sl->size()) + for (silencelist::const_iterator c = sl->begin(); c < sl->end(); c++) { - // tidy up -- if a user's list is empty, theres no use having it - // hanging around in the user record. - delete sl; - user->Shrink("silence_list"); + WriteServ(user->fd,"271 %s %s %s!*@*",user->nick, user->nick,c->c_str()); } } + WriteServ(user->fd,"272 %s :End of Silence List",user->nick); } - else if (nick[0] == '+') + else if (pcnt > 0) { - nick++; - // fetch the user's current silence list - silencelist* sl = (silencelist*)user->GetExt("silence_list"); - // what, they dont have one??? WE'RE ALL GONNA DIE! ...no, we just create an empty one. - if (!sl) + // one or more parameters, add or delete entry from the list (only the first parameter is used) + char *nick = parameters[0]; + if (nick[0] == '-') { - sl = new silencelist; - user->Extend(std::string("silence_list"),(char*)sl); + // removing an item from the list + nick++; + // fetch their silence list + silencelist* sl = (silencelist*)user->GetExt("silence_list"); + // does it contain any entries and does it exist? + if (sl) + { + if (sl->size()) + { + for (silencelist::iterator i = sl->begin(); i != sl->end(); i++) + { + // search through for the item + irc::string listitem = i->c_str(); + irc::string target = nick; + if (listitem == target) + { + sl->erase(i); + WriteServ(user->fd,"950 %s %s :Removed %s!*@* from silence list",user->nick, user->nick,nick); + // we have modified the vector from within a loop, we must now bail out + return; + } + } + } + if (!sl->size()) + { + // tidy up -- if a user's list is empty, theres no use having it + // hanging around in the user record. + delete sl; + user->Shrink("silence_list"); + } + } } - // add the nick to it -- silence only takes nicks for some reason even though its list shows masks - for (silencelist::iterator n = sl->begin(); n != sl->end(); n++) + else if (nick[0] == '+') { - irc::string listitem = n->c_str(); - irc::string target = nick; - if (listitem == target) + nick++; + // fetch the user's current silence list + silencelist* sl = (silencelist*)user->GetExt("silence_list"); + // what, they dont have one??? WE'RE ALL GONNA DIE! ...no, we just create an empty one. + if (!sl) + { + sl = new silencelist; + user->Extend(std::string("silence_list"),(char*)sl); + } + // add the nick to it -- silence only takes nicks for some reason even though its list shows masks + for (silencelist::iterator n = sl->begin(); n != sl->end(); n++) { - WriteServ(user->fd,"952 %s %s :%s is already on your silence list",user->nick, user->nick,nick); - return; + irc::string listitem = n->c_str(); + irc::string target = nick; + if (listitem == target) + { + WriteServ(user->fd,"952 %s %s :%s is already on your silence list",user->nick, user->nick,nick); + return; + } } + sl->push_back(std::string(nick)); + WriteServ(user->fd,"951 %s %s :Added %s!*@* to silence list",user->nick, user->nick,nick); + return; } - sl->push_back(std::string(nick)); - WriteServ(user->fd,"951 %s %s :Added %s!*@* to silence list",user->nick, user->nick,nick); - return; } + return; } - return; -} - +}; class ModuleSilence : public Module { Server *Srv; + cmd_silence* mycommand; public: ModuleSilence(Server* Me) : Module::Module(Me) { Srv = Me; - Srv->AddCommand("SILENCE",handle_silence,0,0,"m_silence.so"); + mycommand = new cmd_silence(); + Srv->AddCommand(mycommand); } virtual void OnUserQuit(userrec* user, std::string reason) diff --git a/src/modules/m_swhois.cpp b/src/modules/m_swhois.cpp index 887d17e39..040845139 100644 --- a/src/modules/m_swhois.cpp +++ b/src/modules/m_swhois.cpp @@ -26,38 +26,49 @@ using namespace std; Server *Srv; -void handle_swhois(char **parameters, int pcnt, userrec *user) +class cmd_swhois : public command_t { - userrec* dest = Srv->FindNick(std::string(parameters[0])); - if (dest) + public: + cmd_swhois () : command_t("SWHOIS",'o',2) { - std::string line = ""; - for (int i = 1; i < pcnt; i++) - { - if (i != 1) - line = line + " "; - line = line + std::string(parameters[i]); - } - char* field = dest->GetExt("swhois"); - if (field) + this->source = "m_swhois.so"; + } + + void Handle (char **parameters, int pcnt, userrec *user) + { + userrec* dest = Srv->FindNick(std::string(parameters[0])); + if (dest) { - std::string* text = (std::string*)field; - dest->Shrink("swhois"); - delete text; + std::string line = ""; + for (int i = 1; i < pcnt; i++) + { + if (i != 1) + line = line + " "; + line = line + std::string(parameters[i]); + } + char* field = dest->GetExt("swhois"); + if (field) + { + std::string* text = (std::string*)field; + dest->Shrink("swhois"); + delete text; + } + std::string* text = new std::string(line); + dest->Extend("swhois",(char*)text); } - std::string* text = new std::string(line); - dest->Extend("swhois",(char*)text); } -} +}; class ModuleSWhois : public Module { + cmd_swhois* mycommand; public: ModuleSWhois(Server* Me) : Module::Module(Me) { Srv = Me; - Srv->AddCommand("SWHOIS",handle_swhois,'o',2,"m_swhois.so"); + mycommand = new cmd_swhois(); + Srv->AddCommand(mycommand); } // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games. diff --git a/src/modules/m_testcommand.cpp b/src/modules/m_testcommand.cpp index de13cca17..15405d80c 100644 --- a/src/modules/m_testcommand.cpp +++ b/src/modules/m_testcommand.cpp @@ -25,28 +25,37 @@ using namespace std; Server *Srv; - -void handle_woot(char **parameters, int pcnt, userrec *user) +class cmd_woot : public command_t { - Srv->Log(DEBUG,"woot handler"); - // Here is a sample of how to send servermodes. Note that unless remote - // servers in your net are u:lined, they may reverse this, but its a - // quick and effective modehack. - - // NOTE: DO NOT CODE LIKE THIS!!! This has no checks and can send - // invalid or plain confusing mode changes, code some checking! - char* modes[3]; - modes[0] = "#chatspike"; - modes[1] = "+o"; - modes[2] = user->nick; - - // run the mode change, send numerics (such as "no such channel") back - // to "user". - Srv->SendMode(modes,3,user); -} + public: + cmd_woot () : command_t("WOOT", 0, 0); + { + this->source = "m_testcommand.so"; + } + + void Handle (char **parameters, int pcnt, userrec *user) + { + Srv->Log(DEBUG,"woot handler"); + // Here is a sample of how to send servermodes. Note that unless remote + // servers in your net are u:lined, they may reverse this, but its a + // quick and effective modehack. + + // NOTE: DO NOT CODE LIKE THIS!!! This has no checks and can send + // invalid or plain confusing mode changes, code some checking! + char* modes[3]; + modes[0] = "#chatspike"; + modes[1] = "+o"; + modes[2] = user->nick; + + // run the mode change, send numerics (such as "no such channel") back + // to "user". + Srv->SendMode(modes,3,user); + } +}; class ModuleTestCommand : public Module { + cmd_woot* newcommand; public: ModuleTestCommand(Server* Me) : Module::Module(Me) @@ -58,7 +67,8 @@ class ModuleTestCommand : public Module // 0 in the modes parameter signifies that // anyone can issue the command, and the // command takes only one parameter. - Srv->AddCommand("WOOT",handle_woot,0,0,"m_testcommand.so"); + newcommand = new cmd_woot(); + Srv->AddCommand(mycommand); // Add a mode +Z for channels with no parameters Srv->AddExtendedMode('Z',MT_CHANNEL,false,1,0); |