diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-16 18:23:50 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-16 18:23:50 +0000 |
commit | ab9d8fd1af3ebf028506ec543f74fd13471742dd (patch) | |
tree | d95fd9303718109daa304bd602dc69af1ebb1b05 | |
parent | 293df6a8b55e89c127e60e92711ef0ef1027bff8 (diff) |
Porting to new command system
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2535 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | src/modules/m_remove.cpp | 126 | ||||
-rw-r--r-- | src/modules/m_sajoin.cpp | 56 | ||||
-rw-r--r-- | src/modules/m_samode.cpp | 44 | ||||
-rw-r--r-- | src/modules/m_sanick.cpp | 33 | ||||
-rw-r--r-- | src/modules/m_sapart.cpp | 41 |
5 files changed, 176 insertions, 124 deletions
diff --git a/src/modules/m_remove.cpp b/src/modules/m_remove.cpp index a72b41da0..7962d6a1d 100644 --- a/src/modules/m_remove.cpp +++ b/src/modules/m_remove.cpp @@ -36,88 +36,98 @@ int chartolevel(std::string privs) else return 1; } - -void handle_remove(char **parameters, int pcnt, userrec *user) + +class cmd_remove : public command_t { - /* Look up the user we're meant to be removing from the channel */ - userrec* target = Srv->FindNick(std::string(parameters[0])); - /* And the channel we're meant to be removing them from */ - chanrec* channel = Srv->FindChannel(std::string(parameters[1])); - /* And see if the person calling the command has access to use it on the channel */ - std::string privs = Srv->ChanMode(user, channel); - /* Check what privs the person being removed has */ - std::string targetprivs = Srv->ChanMode(target, channel); - int tlevel; - int ulevel; - int n = 2; - std::string result; - - /* This turns all the parameters after the first two into a single string, so the part reason can be multi-word */ - while (n < pcnt) + public: + cmd_remove () : command_t("REMOVE", 0, 2) { - result=result + std::string(" ") + std::string(parameters[n]); - n++; + this->source = "m_remove.so"; } - - /* If the target nick exists... */ - if (target && channel) + + void Handle (char **parameters, int pcnt, userrec *user) { - for (unsigned int x = 0; x < strlen(parameters[1]); x++) + /* Look up the user we're meant to be removing from the channel */ + userrec* target = Srv->FindNick(std::string(parameters[0])); + /* And the channel we're meant to be removing them from */ + chanrec* channel = Srv->FindChannel(std::string(parameters[1])); + /* And see if the person calling the command has access to use it on the channel */ + std::string privs = Srv->ChanMode(user, channel); + /* Check what privs the person being removed has */ + std::string targetprivs = Srv->ChanMode(target, channel); + int tlevel; + int ulevel; + int n = 2; + std::string result; + + /* This turns all the parameters after the first two into a single string, so the part reason can be multi-word */ + while (n < pcnt) { - if ((parameters[1][0] != '#') || (parameters[1][x] == ' ') || (parameters[1][x] == ',')) - { - Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name"); - return; - } + result=result + std::string(" ") + std::string(parameters[n]); + n++; } - /* This is adding support for the +q and +a channel modes, basically if they are enabled, and the remover has them set. */ - /* Then we change the @|%|+ to & if they are +a, or ~ if they are +q */ - if (user->GetExt("cm_protect_"+std::string(channel->name))) - privs = std::string("&"); - if (user->GetExt("cm_founder_"+std::string(channel->name))) - privs = std::string("~"); + /* If the target nick exists... */ + if (target && channel) + { + for (unsigned int x = 0; x < strlen(parameters[1]); x++) + { + if ((parameters[1][0] != '#') || (parameters[1][x] == ' ') || (parameters[1][x] == ',')) + { + Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name"); + return; + } + } - /* Now it's the same idea, except for the target */ - if (target->GetExt("cm_protect_"+std::string(channel->name))) - targetprivs = std::string("&"); - if (target->GetExt("cm_founder_"+std::string(channel->name))) - targetprivs = std::string("~"); + /* This is adding support for the +q and +a channel modes, basically if they are enabled, and the remover has them set. */ + /* Then we change the @|%|+ to & if they are +a, or ~ if they are +q */ + if (user->GetExt("cm_protect_"+std::string(channel->name))) + privs = std::string("&"); + if (user->GetExt("cm_founder_"+std::string(channel->name))) + privs = std::string("~"); + + /* Now it's the same idea, except for the target */ + if (target->GetExt("cm_protect_"+std::string(channel->name))) + targetprivs = std::string("&"); + if (target->GetExt("cm_founder_"+std::string(channel->name))) + targetprivs = std::string("~"); + + tlevel = chartolevel(targetprivs); + ulevel = chartolevel(privs); - tlevel = chartolevel(targetprivs); - ulevel = chartolevel(privs); - - /* If the user calling the command is either an admin, owner, operator or a half-operator on the channel */ - if(ulevel > 1) - { - /* For now, we'll let everyone remove their level and below, eg ops can remove ops, halfops, voices, and those with no mode (no moders actually are set to 1) */ - if(ulevel >= tlevel) + /* If the user calling the command is either an admin, owner, operator or a half-operator on the channel */ + if(ulevel > 1) { - Srv->PartUserFromChannel(target,std::string(parameters[1]), "Remove by "+std::string(user->nick)+":"+result); - Srv->SendTo(NULL,user,"NOTICE "+std::string(channel->name)+" : "+std::string(user->nick)+" removed "+std::string(target->nick)+ " from the channel"); - Srv->SendTo(NULL,target,"NOTICE "+std::string(target->nick)+" :*** "+std::string(user->nick)+" removed you from "+std::string(channel->name)+" with the message:"+std::string(result)); + /* For now, we'll let everyone remove their level and below, eg ops can remove ops, halfops, voices, and those with no mode (no moders actually are set to 1) */ + if(ulevel >= tlevel) + { + Srv->PartUserFromChannel(target,std::string(parameters[1]), "Remove by "+std::string(user->nick)+":"+result); + Srv->SendTo(NULL,user,"NOTICE "+std::string(channel->name)+" : "+std::string(user->nick)+" removed "+std::string(target->nick)+ " from the channel"); + Srv->SendTo(NULL,target,"NOTICE "+std::string(target->nick)+" :*** "+std::string(user->nick)+" removed you from "+std::string(channel->name)+" with the message:"+std::string(result)); + } + else + { + Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** You do not have access to remove "+std::string(target->nick)+" from the "+std::string(channel->name)); + } } else { - Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** You do not have access to remove "+std::string(target->nick)+" from the "+std::string(channel->name)); + Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** You do not have access to use /remove on "+std::string(channel->name)); } } - else - { - Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** You do not have access to use /remove on "+std::string(channel->name)); - } } -} - +}; class ModuleRemove : public Module { + cmd_remove* mycommand; public: ModuleRemove(Server* Me) : Module::Module(Me) { Srv = Me; - Srv->AddCommand("REMOVE", handle_remove, 0, 3, "m_remove.so"); + mycommand = new cmd_remove(); + Srv->AddCommand(mycommand); } virtual void On005Numeric(std::string &output) diff --git a/src/modules/m_sajoin.cpp b/src/modules/m_sajoin.cpp index 553211c60..bbf683226 100644 --- a/src/modules/m_sajoin.cpp +++ b/src/modules/m_sajoin.cpp @@ -25,43 +25,53 @@ using namespace std; /* $ModDesc: Provides support for unreal-style SAJOIN command */ Server *Srv; - -void handle_sajoin(char **parameters, int pcnt, userrec *user) + +class cmd_sajoin : public command_t { - userrec* dest = Srv->FindNick(std::string(parameters[0])); - if (dest) + public: + cmd_sajoin() : command_t("SAJOIN", 'o', 2) { - /* might be nicer to make checking valid channel names an api function sometime --w00t */ - if (parameters[1][0] != '#') - { - /* we didn't need to check this for each character ;) */ - Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name"); - return; - } + this->source = "m_sajoin.cpp"; + } - for (unsigned int x = 0; x < strlen(parameters[1]); x++) + void Handle (char **parameters, int pcnt, userrec *user) + { + userrec* dest = Srv->FindNick(std::string(parameters[0])); + if (dest) { - if ((parameters[1][x] == ' ') || (parameters[1][x] == ',')) - { - Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name"); - return; - } - } + /* might be nicer to make checking valid channel names an api function sometime --w00t */ + if (parameters[1][0] != '#') + { + /* we didn't need to check this for each character ;) */ + Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name"); + return; + } - Srv->SendOpers(std::string(user->nick)+" used SAJOIN to make "+std::string(dest->nick)+" join "+parameters[1]); - Srv->JoinUserToChannel(dest,std::string(parameters[1]),std::string(dest->nick)); - } -} + for (unsigned int x = 0; x < strlen(parameters[1]); x++) + { + if ((parameters[1][x] == ' ') || (parameters[1][x] == ',')) + { + Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name"); + return; + } + } + Srv->SendOpers(std::string(user->nick)+" used SAJOIN to make "+std::string(dest->nick)+" join "+parameters[1]); + Srv->JoinUserToChannel(dest,std::string(parameters[1]),std::string(dest->nick)); + } + } +}; class ModuleSajoin : public Module { + cmd_sajoin* mycommand; public: ModuleSajoin(Server* Me) : Module::Module(Me) { Srv = Me; - Srv->AddCommand("SAJOIN",handle_sajoin,'o',2,"m_sajoin.so"); + mycommand = new cmd_sajoin(); + Srv->AddCommand(mycommand); } virtual ~ModuleSajoin() diff --git a/src/modules/m_samode.cpp b/src/modules/m_samode.cpp index e60f8bf03..fe699eb9a 100644 --- a/src/modules/m_samode.cpp +++ b/src/modules/m_samode.cpp @@ -38,34 +38,44 @@ using namespace std; Server *Srv; - -void handle_samode(char **parameters, int pcnt, userrec *user) +class cmd_samode : public command_t { - /* - * Handles an SAMODE request. Notifies all +s users. - */ - int n=0; - std::string result; - Srv->Log(DEBUG,"SAMODE: Being handled"); - Srv->SendMode(parameters,pcnt,user); - Srv->Log(DEBUG,"SAMODE: Modechange handled"); - result = std::string(user->nick) + std::string(" used SAMODE "); - while (n<pcnt) + public: + cmd_samode () : command_t("SAMODE", 'o', 2) { - result=result + std::string(" ") + std::string(parameters[n]); - n++; + this->source = "m_samode.so"; } - Srv->SendOpers(result); -} + + void Handle (char **parameters, int pcnt, userrec *user) + { + /* + * Handles an SAMODE request. Notifies all +s users. + */ + int n=0; + std::string result; + Srv->Log(DEBUG,"SAMODE: Being handled"); + Srv->SendMode(parameters,pcnt,user); + Srv->Log(DEBUG,"SAMODE: Modechange handled"); + result = std::string(user->nick) + std::string(" used SAMODE "); + while (n<pcnt) + { + result=result + std::string(" ") + std::string(parameters[n]); + n++; + } + Srv->SendOpers(result); + } +}; class ModuleSaMode : public Module { + cmd_samode* mycommand; public: ModuleSaMode(Server* Me) : Module::Module(Me) { Srv = Me; - Srv->AddCommand("SAMODE",handle_samode,'o',2,"m_samode.so"); + mycommand = new cmd_samode(); + Srv->AddCommand(mycommand); } virtual ~ModuleSaMode() diff --git a/src/modules/m_sanick.cpp b/src/modules/m_sanick.cpp index 056ccafd2..7146eb262 100644 --- a/src/modules/m_sanick.cpp +++ b/src/modules/m_sanick.cpp @@ -25,31 +25,42 @@ using namespace std; /* $ModDesc: Provides support for SANICK command */ Server *Srv; - -void handle_sanick(char **parameters, int pcnt, userrec *user) + +class cmd_sanick : public command_t { - userrec* source = Srv->FindNick(std::string(parameters[0])); - if (source) + public: + cmd_sanick () : command_t("SANICK", 'o', 2) { - if (Srv->IsNick(std::string(parameters[1]))) + this->source = "m_sanick.so"; + } + + void Handle (char **parameters, int pcnt, userrec *user) + { + userrec* source = Srv->FindNick(std::string(parameters[0])); + if (source) { - // FIX by brain: Cant use source->nick here because if it traverses a server link then - // source->nick becomes invalid as the object data moves in memory. - Srv->SendOpers(std::string(user->nick)+" used SANICK to change "+std::string(parameters[0])+" to "+parameters[1]); - Srv->ChangeUserNick(source,std::string(parameters[1])); + if (Srv->IsNick(std::string(parameters[1]))) + { + // FIX by brain: Cant use source->nick here because if it traverses a server link then + // source->nick becomes invalid as the object data moves in memory. + Srv->SendOpers(std::string(user->nick)+" used SANICK to change "+std::string(parameters[0])+" to "+parameters[1]); + Srv->ChangeUserNick(source,std::string(parameters[1])); + } } } -} +}; class ModuleSanick : public Module { + cmd_sanick* mycommand; public: ModuleSanick(Server* Me) : Module::Module(Me) { Srv = Me; - Srv->AddCommand("SANICK",handle_sanick,'o',2,"m_sanick.so"); + mycommand = new cmd_sanick(); + Srv->AddCommand(mycommand); } virtual ~ModuleSanick() diff --git a/src/modules/m_sapart.cpp b/src/modules/m_sapart.cpp index 21e2f7fbe..026a3bd7d 100644 --- a/src/modules/m_sapart.cpp +++ b/src/modules/m_sapart.cpp @@ -25,35 +25,46 @@ using namespace std; /* $ModDesc: Provides support for unreal-style SAPART command */ Server *Srv; - -void handle_sapart(char **parameters, int pcnt, userrec *user) + +class cmd_sapart : public command_t { - userrec* dest = Srv->FindNick(std::string(parameters[0])); - if (dest) + public: + cmd_sapart () : command_t("SAPART", 'o', 2) + { + this->source = "m_sapart.so"; + } + + void Handle (char **parameters, int pcnt, userrec *user) { - for (unsigned int x = 0; x < strlen(parameters[1]); x++) + userrec* dest = Srv->FindNick(std::string(parameters[0])); + if (dest) { - if ((parameters[1][0] != '#') || (parameters[1][x] == ' ') || (parameters[1][x] == ',')) - { - Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name"); - return; - } - } + for (unsigned int x = 0; x < strlen(parameters[1]); x++) + { + if ((parameters[1][0] != '#') || (parameters[1][x] == ' ') || (parameters[1][x] == ',')) + { + Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name"); + return; + } + } - Srv->SendOpers(std::string(user->nick)+" used SAPART to make "+std::string(dest->nick)+" part "+parameters[1]); - Srv->PartUserFromChannel(dest,std::string(parameters[1]),std::string(dest->nick)); + Srv->SendOpers(std::string(user->nick)+" used SAPART to make "+std::string(dest->nick)+" part "+parameters[1]); + Srv->PartUserFromChannel(dest,std::string(parameters[1]),std::string(dest->nick)); + } } -} +}; class ModuleSapart : public Module { + cmd_sapart* mycommand; public: ModuleSapart(Server* Me) : Module::Module(Me) { Srv = Me; - Srv->AddCommand("SAPART",handle_sapart,'o',2,"m_sapart.so"); + mycommand = new cmd_sapart(); + Srv->AddCommand(mycommand); } virtual ~ModuleSapart() |