diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-16 18:10:38 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-16 18:10:38 +0000 |
commit | 293df6a8b55e89c127e60e92711ef0ef1027bff8 (patch) | |
tree | da33b32cfdd5b6e93cabaf288316671af9a51297 /src/modules/m_park.cpp | |
parent | 0d6f3c83f101e3cb1f6cd6768cc4d17de24db489 (diff) |
Split all commands into seperate files and redid command system to take classes, not function pointers (function pointers suck ass)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2534 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/m_park.cpp')
-rw-r--r-- | src/modules/m_park.cpp | 235 |
1 files changed, 134 insertions, 101 deletions
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() { } |