diff options
author | Adam <Adam@anope.org> | 2010-10-04 13:59:30 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-10-04 13:59:30 -0400 |
commit | cf98cd3e06e4de0f9902824b0ef8239e947c5b6a (patch) | |
tree | fad06aca79be531d306eb8bf096e0160d6323f9c /src | |
parent | 632f8df76b31f1300e7ac72890567834eac5511e (diff) |
Changed the protocol handling system to use a vector of strings instead of C style arrays. Burned the old process/split_buf/memory.c code
Diffstat (limited to 'src')
-rw-r--r-- | src/channels.cpp | 164 | ||||
-rw-r--r-- | src/memory.cpp | 67 | ||||
-rw-r--r-- | src/messages.cpp | 33 | ||||
-rw-r--r-- | src/misc.cpp | 36 | ||||
-rw-r--r-- | src/modules.cpp | 2 | ||||
-rw-r--r-- | src/process.cpp | 148 | ||||
-rw-r--r-- | src/servers.cpp | 19 | ||||
-rw-r--r-- | src/users.cpp | 36 |
8 files changed, 147 insertions, 358 deletions
diff --git a/src/channels.cpp b/src/channels.cpp index 26623c24d..65298ad51 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -826,26 +826,26 @@ void Channel::SetModes(BotInfo *bi, bool EnforceMLock, const char *cmodes, ...) } } -/*************************************************************************/ - -/** Set modes internally on the channel - * @param c The channel - * @param ac Number of args - * @param av args +/** Set a string of modes internally on a channel + * @param setter The setter, if it is a user + * @param mode the modes + * @param EnforceMLock true to enforce mlock */ -void ChanSetInternalModes(Channel *c, int ac, const char **av, User *setter) +void Channel::SetModesInternal(User *setter, const Anope::string &modes, bool EnforceMLock) { - if (!ac) - return; + spacesepstream sep_modes(modes); + Anope::string m; + + sep_modes.GetToken(m); Anope::string modestring; Anope::string paramstring; - int k = 0, j = 0, add = -1; - for (unsigned int i = 0, end = strlen(av[0]); i < end; ++i) + int add = -1; + for (unsigned int i = 0, end = m.length(); i < end; ++i) { ChannelMode *cm; - switch (av[0][i]) + switch (m[i]) { case '+': modestring += '+'; @@ -858,7 +858,7 @@ void ChanSetInternalModes(Channel *c, int ac, const char **av, User *setter) default: if (add == -1) continue; - cm = ModeManager::FindChannelModeByChar(av[0][i]); + cm = ModeManager::FindChannelModeByChar(m[i]); if (!cm) continue; modestring += cm->ModeChar; @@ -867,9 +867,9 @@ void ChanSetInternalModes(Channel *c, int ac, const char **av, User *setter) if (cm->Type == MODE_REGULAR) { if (add) - c->SetModeInternal(cm); + this->SetModeInternal(cm, "", EnforceMLock); else - c->RemoveModeInternal(cm); + this->RemoveModeInternal(cm, "", EnforceMLock); continue; } else if (cm->Type == MODE_PARAM) @@ -878,32 +878,32 @@ void ChanSetInternalModes(Channel *c, int ac, const char **av, User *setter) if (!add && cmp->MinusNoArg) { - c->RemoveModeInternal(cm); - ++k; + this->RemoveModeInternal(cm, "", EnforceMLock); continue; } } - if (++j < ac) + Anope::string token; + if (sep_modes.GetToken(token)) { User *u = NULL; - if (cm->Type == MODE_STATUS && (u = finduser(av[j]))) + if (cm->Type == MODE_STATUS && (u = finduser(token))) paramstring += " " + u->nick; else - paramstring += " " + Anope::string(av[j]); + paramstring += " " + token; + if (add) - c->SetModeInternal(cm, av[j]); + this->SetModeInternal(cm, token, EnforceMLock); else - c->RemoveModeInternal(cm, av[j]); + this->RemoveModeInternal(cm, token, EnforceMLock); } else - Log() << "warning: ChanSetInternalModes() recieved more modes requiring params than params, modes: " << merge_args(ac, av) << ", ac: " << ac << ", j: " << j; + Log() << "warning: Channel::SetModesInternal() recieved more modes requiring params than params, modes: " << modes; } if (setter) - Log(setter, c, "mode") << modestring << paramstring; - - if (j + k + 1 < ac) - Log() << "warning: ChanSetInternalModes() recieved more params than modes requiring them, modes: " << merge_args(ac, av) << ", ac: " << ac << ", j: " << j << " k: " << k; + Log(setter, this, "mode") << modestring << paramstring; + else + Log(LOG_DEBUG) << "Setting " << this->name << " to " << modestring << paramstring; } /** Kick a user from a channel internally @@ -1127,22 +1127,21 @@ User *nc_on_chan(Channel *c, const NickCore *nc) /*************************** Message Handling ****************************/ /*************************************************************************/ -/* Handle a JOIN command. - * av[0] = channels to join +/** Handle a JOIN command + * @param source user joining + * @param channels being joined + * @param ts TS for the join */ - -void do_join(const Anope::string &source, int ac, const char **av) +void do_join(const Anope::string &source, const Anope::string &channels, const Anope::string &ts) { - User *user; - - user = finduser(source); + User *user = finduser(source); if (!user) { - Log() << "JOIN from nonexistent user " << source << ": " << merge_args(ac, av); + Log() << "JOIN from nonexistent user " << source << ": " << channels; return; } - commasepstream sep(av[0]); + commasepstream sep(channels); Anope::string buf; while (sep.GetToken(buf)) { @@ -1165,18 +1164,18 @@ void do_join(const Anope::string &source, int ac, const char **av) /* Channel doesn't exist, create it */ if (!chan) - chan = new Channel(av[0], Anope::CurTime); + chan = new Channel(buf, Anope::CurTime); /* Join came with a TS */ - if (ac == 2) + if (!ts.empty()) { - time_t ts = Anope::string(av[1]).is_pos_number_only() ? convertTo<time_t>(av[1]) : 0; + time_t t = Anope::string(ts).is_pos_number_only() ? convertTo<time_t>(ts) : 0; /* Their time is older, we lose */ - if (chan->creation_time > ts) + if (t && chan->creation_time > t) { Log(LOG_DEBUG) << "Recieved an older TS " << chan->name << " in JOIN, changing from " << chan->creation_time << " to " << ts; - chan->creation_time = ts; + chan->creation_time = t; chan->Reset(); } @@ -1205,41 +1204,36 @@ void do_join(const Anope::string &source, int ac, const char **av) /** Handle a KICK command. * @param source The source of the kick - * @param ac number of args - * @param av The channel, nick(s) being kicked, and reason + * @param users the user(s) being kicked + * @param reason The reason for the kick */ -void do_kick(const Anope::string &source, int ac, const char **av) +void do_kick(const Anope::string &source, const Anope::string &channel, const Anope::string &users, const Anope::string &reason) { - Channel *c = findchan(av[0]); + Channel *c = findchan(channel); if (!c) { - Log() << "Recieved kick for nonexistant channel " << av[0]; + Log() << "Recieved kick for nonexistant channel " << channel; return; } Anope::string buf; - commasepstream sep(av[1]); + commasepstream sep(users); while (sep.GetToken(buf)) - c->KickInternal(source, buf, av[2]); + c->KickInternal(source, buf, reason); } /*************************************************************************/ -/* Handle a PART command. - * av[0] = channels to leave - * av[1] = reason (optional) - */ - -void do_part(const Anope::string &source, int ac, const char **av) +void do_part(const Anope::string &source, const Anope::string &channels, const Anope::string &reason) { User *user = finduser(source); if (!user) { - Log() << "PART from nonexistent user " << source << ": " << merge_args(ac, av); + Log() << "PART from nonexistent user " << source << ": " << reason; return; } - commasepstream sep(av[0]); + commasepstream sep(channels); Anope::string buf; while (sep.GetToken(buf)) { @@ -1249,11 +1243,11 @@ void do_part(const Anope::string &source, int ac, const char **av) Log() << "Recieved PART from " << user->nick << " for nonexistant channel " << buf; else if (user->FindChannel(c)) { - Log(user, c, "part") << "Reason: " << (av[1] ? av[1] : "No reason"); + Log(user, c, "part") << "Reason: " << (!reason.empty() ? reason : "No reason"); FOREACH_MOD(I_OnPrePartChannel, OnPrePartChannel(user, c)); Anope::string ChannelName = c->name; c->DeleteUser(user); - FOREACH_MOD(I_OnPartChannel, OnPartChannel(user, findchan(ChannelName), ChannelName, av[1] ? av[1] : "")); + FOREACH_MOD(I_OnPartChannel, OnPartChannel(user, findchan(ChannelName), ChannelName, !reason.empty() ? reason : "")); } else Log() << "Recieved PART from " << user->nick << " for " << c->name << ", but " << user->nick << " isn't in " << c->name << "?"; @@ -1265,53 +1259,22 @@ void do_part(const Anope::string &source, int ac, const char **av) /** Process a MODE command from the server, and set the modes on the user/channel * it was sent for * @param source The source of the command - * @param ac Number of args in array.. - * @param av Array of args + * @param channel the channel to change modes on + * @param modes the mode changes + * @param ts the timestamp for the modes */ -void do_cmode(const Anope::string &source, int ac, const char **av) +void do_cmode(const Anope::string &source, const Anope::string &channel, const Anope::string &modes, const Anope::string &ts) { - Channel *c; - ChannelInfo *ci; - unsigned i, end; - const char *t; - - if (Capab.HasFlag(CAPAB_TSMODE)) - { - for (i = 0, end = strlen(av[1]); i < end; ++i) - if (!isdigit(av[1][i])) - break; - if (!av[1][i]) - { - t = av[0]; - av[0] = av[1]; - av[1] = t; - --ac; - ++av; - } - else - Log() << "TSMODE enabled but MODE has no valid TS"; - } - - /* :42XAAAAAO TMODE 1106409026 #ircops +b *!*@*.aol.com */ - if (ircd->ts6 && isdigit(av[0][0])) - { - --ac; - ++av; - } - - c = findchan(av[0]); + Channel *c = findchan(channel); if (!c) { - if (debug) - { - ci = cs_findchan(av[0]); - if (!ci || ci->HasFlag(CI_FORBIDDEN)) - Log(LOG_DEBUG) << "MODE " << merge_args(ac - 1, av + 1) << " for nonexistant channel " << av[0]; - } + Log(LOG_DEBUG) << "MODE " << modes << " for nonexistant channel " << channel; return; } - if (source.find('.') != Anope::string::npos && Anope::string(av[1]).find_first_of("bovahq") == Anope::string::npos) // XXX + Log(LOG_DEBUG) << "MODE " << channel << " " << modes << " ts: " << ts; + + if (source.find('.') != Anope::string::npos) { if (Anope::CurTime != c->server_modetime) { @@ -1321,10 +1284,7 @@ void do_cmode(const Anope::string &source, int ac, const char **av) ++c->server_modecount; } - --ac; - ++av; - - ChanSetInternalModes(c, ac, av); + c->SetModesInternal(finduser(source), modes); } /*************************************************************************/ diff --git a/src/memory.cpp b/src/memory.cpp deleted file mode 100644 index 12e0a1d08..000000000 --- a/src/memory.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* Memory management routines. - * - * (C) 2003-2010 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - */ - -#include "services.h" - -/* smalloc, scalloc, srealloc, sstrdup: - * Versions of the memory allocation functions which will cause the - * program to terminate with an "Out of memory" error if the memory - * cannot be allocated. (Hence, the return value from these functions - * is never NULL.) - */ - -/*************************************************************************/ - -/** - * calloc, replacement so we can trap for "out of memory" - * @param elsize to allocate - * @param els size of members - * @return void - */ -void *scalloc(long elsize, long els) -{ - void *buf; - - if (!elsize || !els) - elsize = els = 1; - buf = calloc(elsize, els); - if (!buf) - abort(); - return buf; -} - -/*************************************************************************/ - -/** - * realloc, replacement so we can trap for "out of memory" - * @param oldptr Old Pointer - * @param newsize Size of new pointer - * @return void - */ -void *srealloc(void *oldptr, long newsize) -{ - void *buf; - - if (!newsize) - newsize = 1; - buf = realloc(oldptr, newsize); - if (!buf) - abort(); - return buf; -} - -/*************************************************************************/ -/*************************************************************************/ - -/* In the future: malloc() replacements that tell us if we're leaking and - * maybe do sanity checks too... */ - -/*************************************************************************/ diff --git a/src/messages.cpp b/src/messages.cpp index 1cb0efd3b..5378164ea 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -51,14 +51,14 @@ int m_kill(const Anope::string &nick, const Anope::string &msg) /*************************************************************************/ -int m_time(const Anope::string &source, int ac, const char **av) +bool m_time(const Anope::string &source, const std::vector<Anope::string> &) { if (source.empty()) return MOD_CONT; - time_t *t; - time(t); - struct tm *tm = localtime(t); + time_t t; + time(&t); + struct tm *tm = localtime(&t); char buf[64]; strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y %Z", tm); ircdproto->SendNumeric(Config->ServerName, 391, source, "%s :%s", Config->ServerName.c_str(), buf); @@ -212,14 +212,14 @@ int m_privmsg(const Anope::string &source, const Anope::string &receiver, const /*************************************************************************/ -int m_stats(const Anope::string &source, int ac, const char **av) +bool m_stats(const Anope::string &source, const std::vector<Anope::string> ¶ms) { - if (ac < 1) - return MOD_CONT; + if (params.size() < 1) + return true; User *u = finduser(source); - switch (*av[0]) + switch (params[0][0]) { case 'l': if (u && is_oper(u)) @@ -228,13 +228,13 @@ int m_stats(const Anope::string &source, int ac, const char **av) ircdproto->SendNumeric(Config->ServerName, 211, source, "%s %d %d %d %d %d %d %ld", uplink_server->host.c_str(), UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, Anope::CurTime - start_time); } - ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", *av[0] ? *av[0] : '*'); + ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]); break; case 'o': case 'O': /* Check whether the user is an operator */ if (u && !is_oper(u) && Config->HideStatsO) - ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", *av[0] ? *av[0] : '*'); + ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]); else { std::list<std::pair<Anope::string, Anope::string> >::iterator it, it_end; @@ -248,7 +248,7 @@ int m_stats(const Anope::string &source, int ac, const char **av) ircdproto->SendNumeric(Config->ServerName, 243, source, "O * * %s %s 0", nick.c_str(), type.c_str()); } - ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", *av[0] ? *av[0] : '*'); + ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]); } break; @@ -258,19 +258,18 @@ int m_stats(const Anope::string &source, int ac, const char **av) time_t uptime = Anope::CurTime - start_time; ircdproto->SendNumeric(Config->ServerName, 242, source, ":Services up %d day%s, %02d:%02d:%02d", uptime / 86400, uptime / 86400 == 1 ? "" : "s", (uptime / 3600) % 24, (uptime / 60) % 60, uptime % 60); ircdproto->SendNumeric(Config->ServerName, 250, source, ":Current users: %d (%d ops); maximum %d", usercnt, opcnt, maxusercnt); - ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", *av[0] ? *av[0] : '*'); + ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]); break; } /* case 'u' */ default: - ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", *av[0] ? *av[0] : '*'); + ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]); } - return MOD_CONT; -} -/*************************************************************************/ + return true; +} -int m_version(const Anope::string &source, int ac, const char **av) +bool m_version(const Anope::string &source, const std::vector<Anope::string> &) { if (!source.empty()) ircdproto->SendNumeric(Config->ServerName, 351, source, "Anope-%s %s :%s -(%s) -- %s", Anope::Version().c_str(), Config->ServerName.c_str(), ircd->name, Config->EncModuleList.begin()->c_str(), Anope::Build().c_str()); diff --git a/src/misc.cpp b/src/misc.cpp index 72e991249..54e8bec78 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -557,42 +557,6 @@ Anope::string myStrGetTokenRemainder(const Anope::string &str, const char dilim, /*************************************************************************/ /** - * Clean up the buffer for extra spaces - * @param str to clean up - * @return void - */ -void doCleanBuffer(char *str) -{ - char *in, *out; - char ch; - - if (!str) - return; - - in = str; - out = str; - - while (issp(ch = *in++)); - if (ch) - for (;;) - { - *out++ = ch; - ch = *in++; - if (!ch) - break; - if (!issp(ch)) - continue; - while (issp(ch = *in++)); - if (!ch) - break; - *out++ = ' '; - } - *out = ch; /* == '\0' */ -} - -/*************************************************************************/ - -/** * Kill the user to enforce the sqline * @param nick to kill * @param killer whom is doing the killing diff --git a/src/modules.cpp b/src/modules.cpp index a31a94786..902b940db 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -92,7 +92,7 @@ Module *FindModule(const Anope::string &name) * @param func A callback function that will be called when this message is received * @return The new message object */ -Message *Anope::AddMessage(const Anope::string &name, int (*func)(const Anope::string &source, int ac, const char **av)) +Message *Anope::AddMessage(const Anope::string &name, bool (*func)(const Anope::string &source, const std::vector<Anope::string> ¶ms)) { Message *m = new Message(); diff --git a/src/process.cpp b/src/process.cpp index ba7679a52..285c4ae6b 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -214,138 +214,82 @@ int clear_ignores() return deleted; } -/*************************************************************************/ -/* split_buf: Split a buffer into arguments and store the arguments in an - * argument vector pointed to by argv (which will be malloc'd - * as necessary); return the argument count. If colon_special - * is non-zero, then treat a parameter with a leading ':' as - * the last parameter of the line, per the IRC RFC. Destroys - * the buffer by side effect. +/** Main process routine + * @param buffer A raw line from the uplink to do things with */ -int split_buf(char *buf, const char ***argv, int colon_special) -{ - int argvsize = 8; - int argc; - char *s; - - *argv = static_cast<const char **>(scalloc(sizeof(const char *) * argvsize, 1)); - argc = 0; - while (*buf) - { - if (argc == argvsize) - { - argvsize += 8; - *argv = static_cast<const char **>(srealloc(*argv, sizeof(const char *) * argvsize)); - } - if (*buf == ':') - { - (*argv)[argc++] = buf + 1; - buf = const_cast<char *>(""); // XXX: unsafe cast. - } - else - { - s = strpbrk(buf, " "); - if (s) - { - *s++ = 0; - while (*s == ' ') - ++s; - } - else - s = buf + strlen(buf); - (*argv)[argc++] = buf; - buf = s; - } - } - return argc; -} - -/*************************************************************************/ - -/* process: Main processing routine. Takes the string in inbuf (global - * variable) and does something appropriate with it. */ - void process(const Anope::string &buffer) { - int retVal = 0; - char source[64] = ""; - char cmd[64] = ""; - char buf[1024] = ""; // XXX InspIRCd 2.0 can send messages longer than 512 characters to servers... how disappointing. - char *s; - int ac; /* Parameters for the command */ - const char **av; - /* If debugging, log the buffer */ Log(LOG_RAWIO) << "Received: " << buffer; - /* First make a copy of the buffer so we have the original in case we - * crash - in that case, we want to know what we crashed on. */ - strscpy(buf, buffer.c_str(), sizeof(buf)); + /* Strip all extra spaces */ + Anope::string buf = buffer; + buf = buf.replace_all_cs(" ", " "); - doCleanBuffer(buf); + if (buf.empty()) + return; - /* Split the buffer into pieces. */ - if (*buf == ':') + Anope::string source; + if (buf[0] == ':') { - s = strpbrk(buf, " "); - if (!s) + size_t space = buf.find_first_of(" "); + if (space == Anope::string::npos) + return; + source = buf.substr(1, space - 1); + buf = buf.substr(space + 1); + if (source.empty() || buf.empty()) return; - *s = 0; - while (isspace(*++s)); - strscpy(source, buf + 1, sizeof(source)); - memmove(buf, s, strlen(s) + 1); } - else - *source = 0; - if (!*buf) - return; - s = strpbrk(buf, " "); - if (s) + + spacesepstream buf_sep(buf); + Anope::string buf_token; + + Anope::string command = buf; + if (buf_sep.GetToken(buf_token)) + command = buf_token; + + std::vector<Anope::string> params; + while (buf_sep.GetToken(buf_token)) { - *s = 0; - while (isspace(*++s)); + if (buf_token[0] == ':') + { + if (!buf_sep.StreamEnd()) + params.push_back(buf_token.substr(1) + " " + buf_sep.GetRemaining()); + else + params.push_back(buf_token.substr(1)); + break; + } + else + params.push_back(buf_token); } - else - s = buf + strlen(buf); - strscpy(cmd, buf, sizeof(cmd)); - ac = split_buf(s, &av, 1); if (protocoldebug) { - if (*source) - Log() << "Source " << source; - if (*cmd) - Log() << "Token " << cmd; - if (ac) - { - int i; - for (i = 0; i < ac; ++i) - Log() << "av[" << i << "] = " << av[i]; - } + Log() << "Source : " << (source.empty() ? "No source" : source); + Log() << "Command: " << command; + + if (params.empty()) + Log() << "No params"; else - Log() << "av[0] = NULL"; + for (unsigned i = 0; i < params.size(); ++i) + Log() << "params " << i << ": " << params[i]; } - /* Do something with the message. */ - std::vector<Message *> messages = Anope::FindMessage(cmd); + std::vector<Message *> messages = Anope::FindMessage(command); if (!messages.empty()) { - retVal = MOD_CONT; + bool retVal = true; - for (std::vector<Message *>::iterator it = messages.begin(), it_end = messages.end(); retVal == MOD_CONT && it != it_end; ++it) + for (std::vector<Message *>::iterator it = messages.begin(), it_end = messages.end(); retVal == true && it != it_end; ++it) { Message *m = *it; if (m->func) - retVal = m->func(source, ac, av); + retVal = m->func(source, params); } } else Log(LOG_DEBUG) << "unknown message from server (" << buffer << ")"; - - /* Free argument list we created */ - free(av); } -/*************************************************************************/ diff --git a/src/servers.cpp b/src/servers.cpp index d7517405a..fcb1406c9 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -353,18 +353,17 @@ void do_server(const Anope::string &source, const Anope::string &servername, uns /** * Handle removing the server from the Server struct - * @param source Name of the server leaving - * @param ac Number of arguments in av - * @param av Agruments as part of the SQUIT + * @param source Name of the server sending the squit + * @param server Name of the server leaving * @return void */ -void do_squit(const Anope::string &source, int ac, const char **av) +void do_squit(const Anope::string &source, const Anope::string &server) { - Server *s = Server::Find(av[0]); + Server *s = Server::Find(server); if (!s) { - Log() << "SQUIT for nonexistent server (" << av[0] << ")!!"; + Log() << "SQUIT for nonexistent server " << server; return; } @@ -395,16 +394,14 @@ void do_squit(const Anope::string &source, int ac, const char **av) /*************************************************************************/ /** Handle parsing the CAPAB/PROTOCTL messages - * @param ac Number of args - * @param av Args */ -void CapabParse(int ac, const char **av) +void CapabParse(const std::vector<Anope::string> ¶ms) { - for (int i = 0; i < ac; ++i) + for (unsigned i = 0; i < params.size(); ++i) { for (unsigned j = 0; !Capab_Info[j].Token.empty(); ++j) { - if (Capab_Info[j].Token.equals_ci(av[i])) + if (Capab_Info[j].Token.equals_ci(params[i])) { Capab.SetFlag(Capab_Info[j].Flag); break; diff --git a/src/users.cpp b/src/users.cpp index bf2b1b85a..ae9c59a75 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -855,52 +855,44 @@ User *do_nick(const Anope::string &source, const Anope::string &nick, const Anop /*************************************************************************/ -/* Handle a MODE command for a user. - * av[0] = nick to change mode for - * av[1] = modes - */ - -void do_umode(const Anope::string &source, int ac, const char **av) +void do_umode(const Anope::string &, const Anope::string &user, const Anope::string &modes) { - User *user = finduser(av[0]); - if (!user) + User *u = finduser(user); + if (!u) { - Log() << "user: MODE "<< av[1] << " for nonexistent nick "<< av[0] << ":" << merge_args(ac, av); + Log() << "user: MODE "<< modes << " for nonexistent nick "<< user; return; } - Log(user, "mode") << "changes modes to " << merge_args(ac - 1, av + 1); + Log(u, "mode") << "changes modes to " << modes; - Anope::string modes = av[1]; - for (int i = 2; i < ac; ++i) - modes += Anope::string(" ") + av[i]; - user->SetModesInternal(modes.c_str()); + u->SetModesInternal(modes.c_str()); } /*************************************************************************/ -/* Handle a QUIT command. - * av[0] = reason +/** Handle a QUIT command. + * @param source User quitting + * @param reason Quit reason */ - -void do_quit(const Anope::string &source, int ac, const char **av) +void do_quit(const Anope::string &source, const Anope::string &reason) { User *user = finduser(source); if (!user) { - Log() << "user: QUIT from nonexistent user " << source << ":" << merge_args(ac, av); + Log() << "user: QUIT from nonexistent user " << source << " (" << reason << ")"; return; } - Log(user, "quit") << "quit (Reason: " << (*av[0] ? av[0] : "no reason") << ")"; + Log(user, "quit") << "quit (Reason: " << (!reason.empty() ? reason : "no reason") << ")"; NickAlias *na = findnick(user->nick); if (na && !na->HasFlag(NS_FORBIDDEN) && !na->nc->HasFlag(NI_SUSPENDED) && (user->IsRecognized() || user->IsIdentified(true))) { na->last_seen = Anope::CurTime; - na->last_quit = *av[0] ? av[0] : ""; + na->last_quit = reason; } - FOREACH_MOD(I_OnUserQuit, OnUserQuit(user, *av[0] ? av[0] : "")); + FOREACH_MOD(I_OnUserQuit, OnUserQuit(user, reason)); delete user; } |