1
0
mirror of https://github.com/anope/anope.git synced 2026-07-08 03:43:13 +02:00

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

This commit is contained in:
Adam
2010-10-04 13:59:30 -04:00
parent 632f8df76b
commit cf98cd3e06
19 changed files with 1417 additions and 1739 deletions
+62 -102
View File
@@ -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);
}
/*************************************************************************/
-67
View File
@@ -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... */
/*************************************************************************/
+16 -17
View File
@@ -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> &params)
{
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());
-36
View File
@@ -556,42 +556,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
+1 -1
View File
@@ -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> &params))
{
Message *m = new Message();
+49 -105
View File
@@ -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);
/* Split the buffer into pieces. */
if (*buf == ':')
{
s = strpbrk(buf, " ");
if (!s)
return;
*s = 0;
while (isspace(*++s));
strscpy(source, buf + 1, sizeof(source));
memmove(buf, s, strlen(s) + 1);
}
else
*source = 0;
if (!*buf)
if (buf.empty())
return;
s = strpbrk(buf, " ");
if (s)
Anope::string source;
if (buf[0] == ':')
{
*s = 0;
while (isspace(*++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;
}
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))
{
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);
}
/*************************************************************************/
+8 -11
View File
@@ -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> &params)
{
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;
+14 -22
View File
@@ -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;
}