X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmode.cpp;h=5b5523dfe4829d5ae1a402f3b8d5af293c8899ea;hb=6b43da7511ca875b64e58b84f72dd89485c0e7fd;hp=724a54693c6fbeb71a4367dbbe9e6305d51d0070;hpb=ec44d7c04efc334c3c225ce7ae4e145cb392223f;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/mode.cpp b/src/mode.cpp index 724a54693..5b5523dfe 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -85,13 +85,13 @@ char* ModeParser::Grant(userrec *d,chanrec *chan,int MASK) switch (MASK) { case UCMODE_OP: - d->chans[i].channel->AddOppedUser((char*)d); + d->chans[i].channel->AddOppedUser(d); break; case UCMODE_HOP: - d->chans[i].channel->AddHalfoppedUser((char*)d); + d->chans[i].channel->AddHalfoppedUser(d); break; case UCMODE_VOICE: - d->chans[i].channel->AddVoicedUser((char*)d); + d->chans[i].channel->AddVoicedUser(d); break; } log(DEBUG,"grant: %s %s",d->chans[i].channel->name,d->nick); @@ -116,13 +116,13 @@ char* ModeParser::Revoke(userrec *d,chanrec *chan,int MASK) switch (MASK) { case UCMODE_OP: - d->chans[i].channel->DelOppedUser((char*)d); + d->chans[i].channel->DelOppedUser(d); break; case UCMODE_HOP: - d->chans[i].channel->DelHalfoppedUser((char*)d); + d->chans[i].channel->DelHalfoppedUser(d); break; case UCMODE_VOICE: - d->chans[i].channel->DelVoicedUser((char*)d); + d->chans[i].channel->DelVoicedUser(d); break; } log(DEBUG,"revoke: %s %s",d->chans[i].channel->name,d->nick); @@ -397,33 +397,36 @@ char* ModeParser::TakeBan(userrec *user,char *dest,chanrec *chan,int status) return NULL; } -// tidies up redundant modes, e.g. +nt-nt+i becomes +-+i, -// a section further down the chain tidies up the +-+- crap. + +/** ModeParser::CompressModes() + * Tidies up redundant modes, + * e.g. +nt-nt+i becomes +-+i + * A section further down the chain tidies up the +-+- crap. + */ std::string ModeParser::CompressModes(std::string modes,bool channelmodes) { - int counts[127]; + /* + * OK, iterate over the mode string and count how many times a certain mode appears in it. + * Then, erase all instances of any character that appears more than once. + * This only operates on modes with no parameters, you can still +v-v+v-v+v-v to your heart's content. + */ + + /* Do we really need an int here? Can you fit enough modes in a line to overflow a short? */ + short counts[127]; bool active[127]; - memset(counts,0,sizeof(counts)); - memset(active,0,sizeof(active)); + memset(counts, 0, sizeof(counts)); + memset(active, 0, sizeof(active)); - for (unsigned int i = 0; i < modes.length(); i++) + for(unsigned char* i = (unsigned char*)modes.c_str(); *i; i++) { - if ((modes[i] == '+') || (modes[i] == '-')) + if((*i == '+') || (*i == '-')) continue; - if (channelmodes) - { - if ((strchr("itnmsp",modes[i])) || ((ModeDefined(modes[i],MT_CHANNEL)) && (ModeDefinedOn(modes[i],MT_CHANNEL)==0) && (ModeDefinedOff(modes[i],MT_CHANNEL)==0))) - { - log(DEBUG,"Tidy mode %c",modes[i]); - counts[(unsigned int)modes[i]]++; - active[(unsigned int)modes[i]] = true; - } - } - else + + if(!channelmodes || (channelmodes && (strchr("itnmsp", *i) || (ModeDefined(*i, MT_CHANNEL) && !ModeDefinedOn(*i,MT_CHANNEL) && !ModeDefinedOff(*i,MT_CHANNEL))))) { - log(DEBUG,"Tidy mode %c",modes[i]); - counts[(unsigned int)modes[i]]++; - active[(unsigned int)modes[i]] = true; + log(DEBUG,"Tidy mode %c", *i); + counts[*i]++; + active[*i] = true; } } @@ -1307,7 +1310,7 @@ void cmd_mode::Handle (char **parameters, int pcnt, userrec *user) if (pcnt == 1) { /* just /modes #channel */ - WriteServ(user->fd,"324 %s %s +%s",user->nick, Ptr->name, chanmodes(Ptr,has_channel(user,Ptr))); + WriteServ(user->fd,"324 %s %s +%s",user->nick, Ptr->name, chanmodes(Ptr,Ptr->HasUser(user))); WriteServ(user->fd,"329 %s %s %d", user->nick, Ptr->name, Ptr->created); return; } @@ -1339,7 +1342,7 @@ void cmd_mode::Handle (char **parameters, int pcnt, userrec *user) } } - if (((Ptr) && (!has_channel(user,Ptr))) && (!is_uline(user->server)) && (IS_LOCAL(user))) + if ((IS_LOCAL(user)) && (!is_uline(user->server)) && (!Ptr->HasUser(user))) { WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, Ptr->name); return; @@ -1354,7 +1357,7 @@ void cmd_mode::Handle (char **parameters, int pcnt, userrec *user) return; if (MOD_RESULT == ACR_DEFAULT) { - if ((cstatus(user,Ptr) < STATUS_HOP) && (IS_LOCAL(user))) + if ((IS_LOCAL(user)) && (cstatus(user,Ptr) < STATUS_HOP)) { WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, Ptr->name); return;