diff options
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/m_chghost.cpp | 49 | ||||
-rw-r--r-- | src/modules/m_globops.cpp | 30 | ||||
-rw-r--r-- | src/modules/m_helpop.cpp | 105 | ||||
-rw-r--r-- | src/modules/m_knock.cpp | 63 | ||||
-rw-r--r-- | src/modules/m_nicklock.cpp | 92 | ||||
-rw-r--r-- | src/modules/m_opermd5.cpp | 23 | ||||
-rw-r--r-- | src/modules/m_opermotd.cpp | 22 | ||||
-rw-r--r-- | src/modules/m_park.cpp | 235 | ||||
-rw-r--r-- | src/modules/m_randquote.cpp | 58 |
9 files changed, 404 insertions, 273 deletions
diff --git a/src/modules/m_chghost.cpp b/src/modules/m_chghost.cpp index 6a5845e72..be8154013 100644 --- a/src/modules/m_chghost.cpp +++ b/src/modules/m_chghost.cpp @@ -25,40 +25,53 @@ using namespace std; /* $ModDesc: Provides support for the CHGHOST command */ Server *Srv; - -void handle_chghost(char **parameters, int pcnt, userrec *user) + + +class cmd_chghost : public command_t { - for (unsigned int x = 0; x < strlen(parameters[1]); x++) + public: + cmd_chghost () : command_t("CHGHOST",'o',2) + { + this->source = "m_chghost.so"; + } + + void Handle(char **parameters, int pcnt, userrec *user) { - if (((tolower(parameters[1][x]) < 'a') || (tolower(parameters[1][x]) > 'z')) && (parameters[1][x] != '.')) + for (unsigned int x = 0; x < strlen(parameters[1]); x++) { - if (((parameters[1][x] < '0') || (parameters[1][x]> '9')) && (parameters[1][x] != '-')) + if (((tolower(parameters[1][x]) < 'a') || (tolower(parameters[1][x]) > 'z')) && (parameters[1][x] != '.')) { - Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname"); - return; + if (((parameters[1][x] < '0') || (parameters[1][x]> '9')) && (parameters[1][x] != '-')) + { + Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname"); + return; + } } - } - } userrec* dest = Srv->FindNick(std::string(parameters[0])); - if (dest) - { - Srv->ChangeHost(dest,parameters[1]); - if (!Srv->IsUlined(user->server)) + } + userrec* dest = Srv->FindNick(std::string(parameters[0])); + if (dest) { - // fix by brain - ulines set hosts silently - Srv->SendOpers(std::string(user->nick)+" used CHGHOST to make the displayed host of "+std::string(dest->nick)+" become "+std::string(parameters[1])); + Srv->ChangeHost(dest,parameters[1]); + if (!Srv->IsUlined(user->server)) + { + // fix by brain - ulines set hosts silently + Srv->SendOpers(std::string(user->nick)+" used CHGHOST to make the displayed host of "+std::string(dest->nick)+" become "+std::string(parameters[1])); + } } } -} +}; class ModuleChgHost : public Module { + cmd_chghost* mycommand; public: ModuleChgHost(Server* Me) : Module::Module(Me) { Srv = Me; - Srv->AddCommand("CHGHOST",handle_chghost,'o',2,"m_chghost.so"); + mycommand = new cmd_chghost(); + Srv->AddCommand(mycommand); } virtual ~ModuleChgHost() @@ -67,7 +80,7 @@ class ModuleChgHost : public Module virtual Version GetVersion() { - return Version(1,0,0,1,VF_VENDOR); + return Version(1,2,0,1,VF_VENDOR); } }; diff --git a/src/modules/m_globops.cpp b/src/modules/m_globops.cpp index 48b406dcb..301290363 100644 --- a/src/modules/m_globops.cpp +++ b/src/modules/m_globops.cpp @@ -27,20 +27,30 @@ using namespace std; /* $ModDesc: Provides support for unreal-style GLOBOPS and umode +g */ Server *Srv; - -void handle_globops(char **parameters, int pcnt, userrec *user) + +class cmd_globops : public command_t { - std::string line = "*** GLOBOPS - From " + std::string(user->nick) + ": "; - for (int i = 0; i < pcnt; i++) + public: + cmd_globops () : command_t("GLOBOPS",'o',1) { - line = line + std::string(parameters[i]) + " "; + this->source = "m_globops.so"; } - Srv->SendToModeMask("og",WM_AND,line); -} + + void Handle (char **parameters, int pcnt, userrec *user) + { + std::string line = "*** GLOBOPS - From " + std::string(user->nick) + ": "; + for (int i = 0; i < pcnt; i++) + { + line = line + std::string(parameters[i]) + " "; + } + Srv->SendToModeMask("og",WM_AND,line); + } +}; class ModuleGlobops : public Module { + cmd_globops* mycommand; public: ModuleGlobops(Server* Me) : Module::Module(Me) @@ -53,7 +63,11 @@ class ModuleGlobops : public Module printf("Could not claim usermode +g for this module!"); return; } - else Srv->AddCommand("GLOBOPS",handle_globops,'o',1,"m_globops.so"); + else + { + mycommand = new cmd_globops(); + Srv->AddCommand(mycommand); + } } virtual ~ModuleGlobops() diff --git a/src/modules/m_helpop.cpp b/src/modules/m_helpop.cpp index 2a0a0e62b..1aeb69b12 100644 --- a/src/modules/m_helpop.cpp +++ b/src/modules/m_helpop.cpp @@ -30,67 +30,76 @@ void handle_helpop(char**, int, userrec*); bool do_helpop(char**, int, userrec*); void sendtohelpop(userrec*, int, char**); - /* $ModDesc: /helpop Command, Works like Unreal helpop */ -void handle_helpop(char **parameters, int pcnt, userrec *user) +class cmd_helpop : public command_t { - char a[MAXBUF]; - std::string output = " "; - - if (!helpop) - return; + public: + cmd_helpop () : command_t("HELPOP",0,0) + { + this->source = "m_helpop.so"; + } - if (pcnt < 1) + void Handle (char **parameters, int pcnt, userrec *user) { - do_helpop(NULL,pcnt,user); - return; - } + char a[MAXBUF]; + std::string output = " "; - if (parameters[0][0] == '!') - { - // Force send to all +h users - sendtohelpop(user, pcnt, parameters); - } - else if (parameters[0][0] == '?') - { - // Force to the helpop system with no forward if not found. - if (do_helpop(parameters, pcnt, user) == false) + if (!helpop) + return; + + if (pcnt < 1) { - // Not handled by the Database, Tell the user, and bail. - for (int i = 1; output != ""; i++) - { - snprintf(a,MAXBUF,"line%d",i); - output = helpop->ReadValue("nohelp", std::string(a), 0); + do_helpop(NULL,pcnt,user); + return; + } - if(output != "") + if (parameters[0][0] == '!') + { + // Force send to all +h users + sendtohelpop(user, pcnt, parameters); + } + else if (parameters[0][0] == '?') + { + // Force to the helpop system with no forward if not found. + if (do_helpop(parameters, pcnt, user) == false) + { + // Not handled by the Database, Tell the user, and bail. + for (int i = 1; output != ""; i++) { - Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output); + snprintf(a,MAXBUF,"line%d",i); + output = helpop->ReadValue("nohelp", std::string(a), 0); + + if(output != "") + { + Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output); + } } } } - } - else - { - // Check with the helpop database, if not found send to +h - if (do_helpop(parameters, pcnt, user) == false) + else { - // Not handled by the Database, Tell the user, and forward. - for (int i = 1; output != ""; i++) - { - snprintf(a,MAXBUF,"line%d",i); - /* "nohelpo" for opers "nohelp" for users */ - output = helpop->ReadValue("nohelpo", std::string(a), 0); - if (output != "") - { - Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output); - } - } - // Forward. - sendtohelpop(user, pcnt, parameters); + // Check with the helpop database, if not found send to +h + if (do_helpop(parameters, pcnt, user) == false) + { + // Not handled by the Database, Tell the user, and forward. + for (int i = 1; output != ""; i++) + { + snprintf(a,MAXBUF,"line%d",i); + /* "nohelpo" for opers "nohelp" for users */ + output = helpop->ReadValue("nohelpo", std::string(a), 0); + if (output != "") + { + Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output); + } + } + // Forward. + sendtohelpop(user, pcnt, parameters); + } } } -} +}; + bool do_helpop(char **parameters, int pcnt, userrec *src) { @@ -156,6 +165,7 @@ class ModuleHelpop : public Module private: ConfigReader *conf; std::string h_file; + cmd_helpop* mycommand; public: ModuleHelpop(Server* Me) @@ -170,7 +180,8 @@ class ModuleHelpop : public Module return; } - Srv->AddCommand("HELPOP",handle_helpop,0,0,"m_helpop.so"); + mycommand = new cmd_helpop(); + Srv->AddCommand(mycommand); } virtual void ReadConfig() diff --git a/src/modules/m_knock.cpp b/src/modules/m_knock.cpp index 08ce7ece4..7948dc0db 100644 --- a/src/modules/m_knock.cpp +++ b/src/modules/m_knock.cpp @@ -26,47 +26,56 @@ using namespace std; /* $ModDesc: Provides support for /KNOCK and mode +K */ Server *Srv; - -void handle_knock(char **parameters, int pcnt, userrec *user) -{ - chanrec* c = Srv->FindChannel(parameters[0]); - std::string line = ""; - - for (int i = 1; i < pcnt - 1; i++) - { - line = line + std::string(parameters[i]) + " "; - } - line = line + std::string(parameters[pcnt-1]); - if (c->IsCustomModeSet('K')) - { - WriteServ(user->fd,"480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name); - return; - } - if (c->binarymodes & CM_INVITEONLY) +class cmd_knock : public command_t +{ + public: + cmd_knock () : command_t("KNOCK", 0, 2) { - WriteChannelWithServ((char*)Srv->GetServerName().c_str(),c,"NOTICE %s :User %s is KNOCKing on %s (%s)",c->name,user->nick,c->name,line.c_str()); - WriteServ(user->fd,"NOTICE %s :KNOCKing on %s",user->nick,c->name); - return; + this->source = "m_knock.so"; } - else + + void Handle (char **parameters, int pcnt, userrec *user) { - WriteServ(user->fd,"480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name); - return; - } -} + chanrec* c = Srv->FindChannel(parameters[0]); + std::string line = ""; + for (int i = 1; i < pcnt - 1; i++) + { + line = line + std::string(parameters[i]) + " "; + } + line = line + std::string(parameters[pcnt-1]); + + if (c->IsCustomModeSet('K')) + { + WriteServ(user->fd,"480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name); + return; + } + if (c->binarymodes & CM_INVITEONLY) + { + WriteChannelWithServ((char*)Srv->GetServerName().c_str(),c,"NOTICE %s :User %s is KNOCKing on %s (%s)",c->name,user->nick,c->name,line.c_str()); + WriteServ(user->fd,"NOTICE %s :KNOCKing on %s",user->nick,c->name); + return; + } + else + { + WriteServ(user->fd,"480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name); + return; + } + } +}; class ModuleKnock : public Module { + cmd_knock* mycommand; public: ModuleKnock(Server* Me) : Module::Module(Me) { Srv = Me; - Srv->AddExtendedMode('K',MT_CHANNEL,false,0,0); - Srv->AddCommand("KNOCK",handle_knock,0,2,"m_knock.so"); + mycommand = new cmd_knock(); + Srv->AddCommand(mycommand); } virtual void On005Numeric(std::string &output) diff --git a/src/modules/m_nicklock.cpp b/src/modules/m_nicklock.cpp index efdfcca4d..37e9d49bd 100644 --- a/src/modules/m_nicklock.cpp +++ b/src/modules/m_nicklock.cpp @@ -27,64 +27,86 @@ using namespace std; /* $ModDesc: Provides the NICKLOCK command, allows an oper to chage a users nick and lock them to it until they quit */ Server *Srv; - -void handle_nicklock(char **parameters, int pcnt, userrec *user) + +class cmd_nicklock : public command_t { - userrec* source = Srv->FindNick(std::string(parameters[0])); - irc::string server; - irc::string me; + public: + cmd_nicklock () : command_t("NICKLOCK", 'o', 2) + { + this->source = "m_nicklock.so"; + } - if (source) + void Handle(char **parameters, int pcnt, userrec *user) { - if (source->GetExt("nick_locked")) - { - WriteServ(user->fd,"946 %s %s :This user's nickname is already locked.",user->nick,source->nick); - return; - } - if (Srv->IsNick(std::string(parameters[1]))) - { - server = user->server; - me = Srv->GetServerName().c_str(); + userrec* source = Srv->FindNick(std::string(parameters[0])); + irc::string server; + irc::string me; - if (server == me) + if (source) + { + if (source->GetExt("nick_locked")) { - // give them a lock flag - Srv->SendOpers(std::string(user->nick)+" used NICKLOCK to change and hold "+std::string(parameters[0])+" to "+parameters[1]); - Srv->ChangeUserNick(source,std::string(parameters[1])); - // only attempt to set their lockflag after we know the change succeeded - source = Srv->FindNick(std::string(parameters[1])); - if (source) - source->Extend("nick_locked", "ON"); + WriteServ(user->fd,"946 %s %s :This user's nickname is already locked.",user->nick,source->nick); + return; } - else + if (Srv->IsNick(std::string(parameters[1]))) { - WriteServ(user->fd,"947 %s %s :Can't lock the nickname of a non-local user",user->nick,source->nick); + server = user->server; + me = Srv->GetServerName().c_str(); + + if (server == me) + { + // give them a lock flag + Srv->SendOpers(std::string(user->nick)+" used NICKLOCK to change and hold "+std::string(parameters[0])+" to "+parameters[1]); + Srv->ChangeUserNick(source,std::string(parameters[1])); + // only attempt to set their lockflag after we know the change succeeded + source = Srv->FindNick(std::string(parameters[1])); + if (source) + source->Extend("nick_locked", "ON"); + } + else + { + WriteServ(user->fd,"947 %s %s :Can't lock the nickname of a non-local user",user->nick,source->nick); + } } } } -} +}; -void handle_nickunlock(char **parameters, int pcnt, userrec *user) +class cmd_nickunlock : public command_t { - userrec* source = Srv->FindNick(std::string(parameters[0])); - if (source) + public: + cmd_nickunlock () : command_t("NICKUNLOCK", 'o', 1) { - source->Shrink("nick_locked"); - WriteServ(user->fd,"945 %s %s :Nickname now unlocked.",user->nick,source->nick); - Srv->SendOpers(std::string(user->nick)+" used NICKUNLOCK on "+std::string(parameters[0])); + this->source = "m_nickunlock.so"; } -} + + void Handle (char **parameters, int pcnt, userrec *user) + { + userrec* source = Srv->FindNick(std::string(parameters[0])); + if (source) + { + source->Shrink("nick_locked"); + WriteServ(user->fd,"945 %s %s :Nickname now unlocked.",user->nick,source->nick); + Srv->SendOpers(std::string(user->nick)+" used NICKUNLOCK on "+std::string(parameters[0])); + } + } +}; class ModuleNickLock : public Module { + cmd_nicklock* cmd1; + cmd_nickunlock* cmd2; public: ModuleNickLock(Server* Me) : Module::Module(Me) { Srv = Me; - Srv->AddCommand("NICKLOCK",handle_nicklock,'o',2,"m_nicklock.so"); - Srv->AddCommand("NICKUNLOCK",handle_nickunlock,'o',1,"m_nicklock.so"); + cmd1 = new cmd_nicklock(); + cmd2 = new cmd_nickunlock(); + Srv->AddCommand(cmd1); + Srv->AddCommand(cmd2); } virtual ~ModuleNickLock() diff --git a/src/modules/m_opermd5.cpp b/src/modules/m_opermd5.cpp index 6ce0cab2f..44b029082 100644 --- a/src/modules/m_opermd5.cpp +++ b/src/modules/m_opermd5.cpp @@ -261,22 +261,33 @@ void GenHash(const char* src, char* dest) strcpy(dest,hash); } -void handle_mkpasswd(char **parameters, int pcnt, userrec *user) +class cmd_mkpasswd : public command_t { - char buffer[MAXBUF]; - GenHash(parameters[0],buffer); - WriteServ(user->fd,"NOTICE %s :MD5 hashed password for %s is %s",user->nick,parameters[0],buffer); -} + public: + cmd_mkpasswd () : command_t("MKPASSWD", 'o', 1) + { + this->source = "m_opermd5.so"; + } + + void Handle (char **parameters, int pcnt, userrec *user) + { + char buffer[MAXBUF]; + GenHash(parameters[0],buffer); + WriteServ(user->fd,"NOTICE %s :MD5 hashed password for %s is %s",user->nick,parameters[0],buffer); + } +}; class ModuleOperMD5 : public Module { + cmd_mkpasswd* mycommand; public: ModuleOperMD5(Server* Me) : Module::Module(Me) { Srv = Me; - Srv->AddCommand("MKPASSWD",handle_mkpasswd,'o',1,"m_opermd5.so"); + mycommand = new cmd_mkpasswd(); + Srv->AddCommand(mycommand); } virtual ~ModuleOperMD5() diff --git a/src/modules/m_opermotd.cpp b/src/modules/m_opermotd.cpp index a2a3c0312..7fd19122b 100644 --- a/src/modules/m_opermotd.cpp +++ b/src/modules/m_opermotd.cpp @@ -13,8 +13,6 @@ using namespace std; FileReader* opermotd; Server* Srv; -void do_opermotd(char** parameters, int pcnt, userrec* user); - void LoadOperMOTD() { ConfigReader* conf = new ConfigReader; @@ -45,20 +43,30 @@ void ShowOperMOTD(userrec* user) } -void do_opermotd(char** parameters, int pcnt, userrec* user) +class cmd_opermotd : public command_t { - ShowOperMOTD(user); -} + public: + cmd_opermotd () : command_t("OPERMOTD", 'o', 0) + { + this->source = "m_opermotd.so"; + } + + void Handle (char** parameters, int pcnt, userrec* user) + { + ShowOperMOTD(user); + } +}; class ModuleOpermotd : public Module { + cmd_opermotd* mycommand; public: ModuleOpermotd(Server* Me) : Module::Module(Me) { Srv = Me; - - Srv->AddCommand("OPERMOTD",do_opermotd,'o',0,"m_opermotd.so"); + mycommand = new cmd_opermotd(); + Srv->AddCommand(mycommand); opermotd = new FileReader(); LoadOperMOTD(); } diff --git a/src/modules/m_park.cpp b/src/modules/m_park.cpp index 6a640f318..264a3ba0f 100644 --- a/src/modules/m_park.cpp +++ b/src/modules/m_park.cpp @@ -51,129 +51,159 @@ long ConcurrentParks; long ParkMaxMsgs; parkedinfo pi; -void handle_park(char **parameters, int pcnt, userrec *user) +class cmd_park : public command_t { - /** Parking. easy stuff. - * - * We duplicate and switch the users file descriptor, so that they can remain forever as a 'ghost' - * We then disconnect the real user leaving a controlled ghost in their place :) - */ - int othersessions = 0; - if (pinfo.size()) - for (parkinfo::iterator j = pinfo.begin(); j != pinfo.end(); j++) - if (j->host == std::string(user->host)) - othersessions++; - if (othersessions >= ConcurrentParks) + public: + cmd_park () : command_t("PARK", 0, 0) { - Srv->SendServ(user->fd,"927 "+std::string(user->nick)+" :You are already parked up to the maximum number of allowed times."); + this->source = "m_park.so"; } - else + + void Handle (char **parameters, int pcnt, userrec *user) { - awaylog* aw; - char msg[MAXBUF]; - unsigned long key = abs(random() * 12345); - snprintf(msg,MAXBUF,"You are now parked. To unpark use /UNPARK %s %lu",user->nick,key); - Srv->UserToPseudo(user,std::string(msg)); - aw = new awaylog; - user->Extend("park_awaylog",(char*)aw); - user->Extend("park_key",(char*)key); - pi.nick = user->nick; - pi.host = user->host; - pi.parktime = time(NULL); - pinfo.push_back(pi); + /** Parking. easy stuff. + * + * We duplicate and switch the users file descriptor, so that they can remain forever as a 'ghost' + * We then disconnect the real user leaving a controlled ghost in their place :) + */ + int othersessions = 0; + if (pinfo.size()) + for (parkinfo::iterator j = pinfo.begin(); j != pinfo.end(); j++) + if (j->host == std::string(user->host)) + othersessions++; + if (othersessions >= ConcurrentParks) + { + Srv->SendServ(user->fd,"927 "+std::string(user->nick)+" :You are already parked up to the maximum number of allowed times."); + } + else + { + awaylog* aw; + char msg[MAXBUF]; + unsigned long key = abs(random() * 12345); + snprintf(msg,MAXBUF,"You are now parked. To unpark use /UNPARK %s %lu",user->nick,key); + Srv->UserToPseudo(user,std::string(msg)); + aw = new awaylog; + user->Extend("park_awaylog",(char*)aw); + user->Extend("park_key",(char*)key); + pi.nick = user->nick; + pi.host = user->host; + pi.parktime = time(NULL); + pinfo.push_back(pi); + } } -} -void handle_parkstats(char **parameters, int pcnt, userrec *user) -{ - char status[MAXBUF]; - snprintf(status,MAXBUF,"NOTICE %s :There are a total of %lu parked clients on this server, with a maximum of %lu parked sessions allowed per user.",user->nick,(unsigned long)pinfo.size(),(unsigned long)ConcurrentParks); - Srv->SendServ(user->fd,status); -} +}; -void handle_unpark(char **parameters, int pcnt, userrec *user) +class cmd_parkstats : public command_t { - /** Unparking. complicated stuff. - * - * Unparking is done in several steps: - * - * (1) Check if the user is parked - * (2) Check the key of the user against the one provided - * (3) Part the user who issued the command from all of their channels so as not to confuse clients - * (4) Remove all the users UMODEs - * (5) Duplicate and switch file descriptors on the two users, and disconnect the dead one - * (6) Force a nickchange onto the user who issued the command forcing them to change to the parked nick - * (7) Force join the user into all the channels the parked nick is currently in (send them localized join and namelist) - * (8) Send the user the umodes of their new 'persona' - * (9) Spool any awaylog messages to the user - * - * And there you have it, easy huh (NOT)... - */ - userrec* unpark = Srv->FindNick(std::string(parameters[0])); - if (!unpark) + public: + cmd_parkstats () : command_t("PARKSTATS", 'o', 0) { - WriteServ(user->fd,"942 %s %s :Invalid user specified.",user->nick, parameters[0]); - return; + this->source = "m_park.so"; } - awaylog* awy = (awaylog*)unpark->GetExt("park_awaylog"); - long key = (long)unpark->GetExt("park_key"); - if (!awy) + + void Handle (char **parameters, int pcnt, userrec *user) { - WriteServ(user->fd,"943 %s %s :This user is not parked.",user->nick, unpark->nick); - return; + char status[MAXBUF]; + snprintf(status,MAXBUF,"NOTICE %s :There are a total of %lu parked clients on this server, with a maximum of %lu parked sessions allowed per user.",user->nick,(unsigned long)pinfo.size(),(unsigned long)ConcurrentParks); + Srv->SendServ(user->fd,status); } - if (key == atoi(parameters[1])) +}; + +class cmd_unpark : public command_t +{ + public: + cmd_unpark () : command_t("UNPARK", 0, 2) { - // first part the user from all chans theyre on, so things dont get messy - for (int i = 0; i < user->chans.size(); i++) - { - if (user->chans[i].channel != NULL) - { - if (user->chans[i].channel->name) - { - Srv->PartUserFromChannel(user,user->chans[i].channel->name,"Unparking"); - } - } + this->source = "m_park.so"; + } + + void Handle (char **parameters, int pcnt, userrec *user) + { + /** Unparking. complicated stuff. + * + * Unparking is done in several steps: + * + * (1) Check if the user is parked + * (2) Check the key of the user against the one provided + * (3) Part the user who issued the command from all of their channels so as not to confuse clients + * (4) Remove all the users UMODEs + * (5) Duplicate and switch file descriptors on the two users, and disconnect the dead one + * (6) Force a nickchange onto the user who issued the command forcing them to change to the parked nick + * (7) Force join the user into all the channels the parked nick is currently in (send them localized join and namelist) + * (8) Send the user the umodes of their new 'persona' + * (9) Spool any awaylog messages to the user + * + * And there you have it, easy huh (NOT)... + */ + userrec* unpark = Srv->FindNick(std::string(parameters[0])); + if (!unpark) + { + WriteServ(user->fd,"942 %s %s :Invalid user specified.",user->nick, parameters[0]); + return; } - // remove all their old modes - WriteServ(user->fd,"MODE %s -%s",user->nick,user->modes); - // now, map them to the parked user, while nobody can see :p - Srv->PseudoToUser(user,unpark,"Unparked to "+std::string(parameters[0])); - // set all their new modes - WriteServ(unpark->fd,"MODE %s +%s",unpark->nick,unpark->modes); - // spool their away log to them - WriteServ(unpark->fd,"NOTICE %s :*** You are now unparked. You have successfully taken back the nickname and privilages of %s.",unpark->nick,unpark->nick); - for (awaylog::iterator i = awy->begin(); i != awy->end(); i++) + awaylog* awy = (awaylog*)unpark->GetExt("park_awaylog"); + long key = (long)unpark->GetExt("park_key"); + if (!awy) { - char timebuf[MAXBUF]; - tm *timeinfo = localtime(&i->tm); - strlcpy(timebuf,asctime(timeinfo),MAXBUF); - timebuf[strlen(timebuf)-1] = '\0'; - WriteServ(unpark->fd,"NOTICE %s :From %s at %s: \2%s\2",unpark->nick,i->from.c_str(),timebuf,i->text.c_str()); + WriteServ(user->fd,"943 %s %s :This user is not parked.",user->nick, unpark->nick); + return; } - delete awy; - unpark->Shrink("park_awaylog"); - unpark->Shrink("park_key"); - for (parkinfo::iterator j = pinfo.begin(); j != pinfo.end(); j++) + if (key == atoi(parameters[1])) { - if (j->nick == std::string(unpark->nick)) + // first part the user from all chans theyre on, so things dont get messy + for (int i = 0; i < user->chans.size(); i++) + { + if (user->chans[i].channel != NULL) + { + if (user->chans[i].channel->name) + { + Srv->PartUserFromChannel(user,user->chans[i].channel->name,"Unparking"); + } + } + } + // remove all their old modes + WriteServ(user->fd,"MODE %s -%s",user->nick,user->modes); + // now, map them to the parked user, while nobody can see :p + Srv->PseudoToUser(user,unpark,"Unparked to "+std::string(parameters[0])); + // set all their new modes + WriteServ(unpark->fd,"MODE %s +%s",unpark->nick,unpark->modes); + // spool their away log to them + WriteServ(unpark->fd,"NOTICE %s :*** You are now unparked. You have successfully taken back the nickname and privilages of %s.",unpark->nick,unpark->nick); + for (awaylog::iterator i = awy->begin(); i != awy->end(); i++) { - pinfo.erase(j); - break; + char timebuf[MAXBUF]; + tm *timeinfo = localtime(&i->tm); + strlcpy(timebuf,asctime(timeinfo),MAXBUF); + timebuf[strlen(timebuf)-1] = '\0'; + WriteServ(unpark->fd,"NOTICE %s :From %s at %s: \2%s\2",unpark->nick,i->from.c_str(),timebuf,i->text.c_str()); + } + delete awy; + unpark->Shrink("park_awaylog"); + unpark->Shrink("park_key"); + for (parkinfo::iterator j = pinfo.begin(); j != pinfo.end(); j++) + { + if (j->nick == std::string(unpark->nick)) + { + pinfo.erase(j); + break; + } } } + else + { + Srv->SendServ(user->fd,"928 "+std::string(user->nick)+" :Incorrect park key."); + } } - else - { - Srv->SendServ(user->fd,"928 "+std::string(user->nick)+" :Incorrect park key."); - } -} - +}; class ModulePark : public Module { protected: ConfigReader* Conf; + cmd_park* cmd1; + cmd_unpark* cmd2; + cmd_parkstats* cmd3; public: virtual void ReadSettings() { @@ -190,11 +220,14 @@ class ModulePark : public Module Srv = Me; pinfo.clear(); this->ReadSettings(); - Srv->AddCommand("PARK",handle_park,0,0,"m_park.so"); - Srv->AddCommand("UNPARK",handle_unpark,0,2,"m_park.so"); - Srv->AddCommand("PARKSTATS",handle_parkstats,'o',0,"m_park.so"); + cmd1 = new cmd_park(); + cmd2 = new cmd_unpark(); + cmd3 = new cmd_parkstats(); + Srv->AddCommand(cmd1); + Srv->AddCommand(cmd2); + Srv->AddCommand(cmd3); } - + virtual ~ModulePark() { } diff --git a/src/modules/m_randquote.cpp b/src/modules/m_randquote.cpp index f75d3f1aa..73bf9b3b1 100644 --- a/src/modules/m_randquote.cpp +++ b/src/modules/m_randquote.cpp @@ -33,33 +33,40 @@ std::string suffix = ""; /* $ModDesc: Provides random Quotes on Connect. */ -void handle_randquote(char** parameters, int pcntl, userrec *user) +class cmd_randquote : public command_t { - std::string str; - int fsize; - char buf[MAXBUF]; - if (q_file == "" || quotes->Exists()) + public: + cmd_randquote () : command_t("RANDQUOTE", 0, 0) { - fsize = quotes->FileSize(); - str = quotes->GetLine(rand() % fsize); - sprintf(buf,"NOTICE %s :%s%s%s",user->nick,prefix.c_str(),str.c_str(),suffix.c_str()); - Srv->SendServ(user->fd, buf); + this->source = "m_randquote.so"; } - else + + void Handle (char** parameters, int pcntl, userrec *user) { - sprintf(buf, "NOTICE %s :Your administrator specified an invalid quotes file, please bug them about this.", user->nick); - Srv->SendServ(user->fd, buf); + std::string str; + int fsize; + char buf[MAXBUF]; + if (q_file == "" || quotes->Exists()) + { + fsize = quotes->FileSize(); + str = quotes->GetLine(rand() % fsize); + sprintf(buf,"NOTICE %s :%s%s%s",user->nick,prefix.c_str(),str.c_str(),suffix.c_str()); + Srv->SendServ(user->fd, buf); + } + else + { + sprintf(buf, "NOTICE %s :Your administrator specified an invalid quotes file, please bug them about this.", user->nick); + Srv->SendServ(user->fd, buf); + } + return; } - return; -} - - +}; class ModuleRandQuote : public Module { private: - + cmd_randquote* mycommand; ConfigReader *conf; public: ModuleRandQuote(Server* Me) @@ -74,6 +81,8 @@ class ModuleRandQuote : public Module prefix = conf->ReadValue("randquote","prefix",0); suffix = conf->ReadValue("randquote","suffix",0); + mycommand = NULL; + if (q_file == "") { log(DEFAULT,"m_randquote: Quotefile not specified - Please check your config."); @@ -86,8 +95,12 @@ class ModuleRandQuote : public Module log(DEFAULT,"m_randquote: QuoteFile not Found!! Please check your config - module will not function."); return; } - /* Hidden Command -- Mode clients assume /quote sends raw data to an IRCd >:D */ - else Srv->AddCommand("QUOTE",handle_randquote,0,0,"m_randquote.so"); + else + { + /* Hidden Command -- Mode clients assume /quote sends raw data to an IRCd >:D */ + mycommand = new cmd_randquote(); + Srv->AddCommand(mycommand); + } } virtual ~ModuleRandQuote() @@ -103,11 +116,8 @@ class ModuleRandQuote : public Module virtual void OnUserConnect(userrec* user) { - // Make a fake pointer to be passed to handle_randquote() - // Dont try this at home kiddies :D - /* Or do things a slightly nicer way, and pass NULL */ - //char *rar = "RAR"; - handle_randquote(NULL, 0, user); + if (mycommand) + mycommand->Handle(NULL, 0, user); } }; |