summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/actions.cpp29
-rw-r--r--src/botserv.cpp59
-rw-r--r--src/command.cpp6
-rw-r--r--src/commands.cpp2
-rw-r--r--src/ircd.cpp34
-rw-r--r--src/messages.cpp316
-rw-r--r--src/misc.cpp64
-rw-r--r--src/modes.cpp4
-rw-r--r--src/operserv.cpp14
-rw-r--r--src/process.cpp2
-rw-r--r--src/protocol.cpp329
-rw-r--r--src/regchannel.cpp2
-rw-r--r--src/servers.cpp61
-rw-r--r--src/sessions.cpp29
-rw-r--r--src/users.cpp70
15 files changed, 487 insertions, 534 deletions
diff --git a/src/actions.cpp b/src/actions.cpp
index 6b3a96a24..b583cafae 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -30,7 +30,7 @@ bool bad_password(User *u)
u->invalid_pw_time = Anope::CurTime;
if (u->invalid_pw_count >= Config->BadPassLimit)
{
- kill_user("", u->nick, "Too many invalid passwords");
+ kill_user("", u, "Too many invalid passwords");
return true;
}
@@ -41,48 +41,41 @@ bool bad_password(User *u)
/**
* Remove a user from the IRC network.
- * @param source is the nick which should generate the kill, or NULL for a server-generated kill.
+ * @param source is the nick which should generate the kill, or empty for a server-generated kill.
* @param user to remove
* @param reason for the kill
* @return void
*/
-void kill_user(const Anope::string &source, const Anope::string &user, const Anope::string &reason)
+void kill_user(const Anope::string &source, User *user, const Anope::string &reason)
{
- if (user.empty())
+ if (!user)
return;
Anope::string real_source = source.empty() ? Config->ServerName : source;
Anope::string buf = real_source + " (" + reason + ")";
- ircdproto->SendSVSKill(findbot(source), finduser(user), "%s", buf.c_str());
+ ircdproto->SendSVSKill(findbot(source), user, "%s", buf.c_str());
- if (!ircd->quitonkill && finduser(user))
+ if (!ircd->quitonkill)
do_kill(user, buf);
}
/*************************************************************************/
/**
- * Unban the nick from a channel
+ * Unban the user from a channel
* @param ci channel info for the channel
- * @param nick to remove the ban for
+ * @param u The user to unban
* @return void
*/
-void common_unban(ChannelInfo *ci, const Anope::string &nick)
+void common_unban(ChannelInfo *ci, User *u)
{
- if (!ci || !ci->c || nick.empty())
- return;
-
- User *u = finduser(nick);
- if (!u)
- return;
-
- if (!ci->c->HasMode(CMODE_BAN))
+ if (!u || !ci || !ci->c || !ci->c->HasMode(CMODE_BAN))
return;
if (ircd->svsmode_unban)
- ircdproto->SendBanDel(ci->c, nick);
+ ircdproto->SendBanDel(ci->c, u->nick);
else
{
std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> bans = ci->c->GetModeList(CMODE_BAN);
diff --git a/src/botserv.cpp b/src/botserv.cpp
index 32b6a42a3..ddd8dc15f 100644
--- a/src/botserv.cpp
+++ b/src/botserv.cpp
@@ -504,13 +504,14 @@ static void bot_kick(ChannelInfo *ci, User *u, LanguageString message, ...)
/*************************************************************************/
-/* Makes a simple ban and kicks the target */
-
-void bot_raw_ban(User *requester, ChannelInfo *ci, const Anope::string &nick, const Anope::string &reason)
+/* Makes a simple ban and kicks the target
+ * @param requester The user requesting the kickban
+ * @param ci The channel
+ * @param u The user being kicked
+ * @param reason The reason
+ */
+void bot_raw_ban(User *requester, ChannelInfo *ci, User *u, const Anope::string &reason)
{
- Anope::string mask;
- User *u = finduser(nick);
-
if (!u || !ci)
return;
@@ -522,7 +523,7 @@ void bot_raw_ban(User *requester, ChannelInfo *ci, const Anope::string &nick, co
ChanAccess *u_access = ci->GetAccess(u), *req_access = ci->GetAccess(requester);
int16 u_level = u_access ? u_access->level : 0, req_level = req_access ? req_access->level : 0;
- if (ci->HasFlag(CI_PEACE) && !requester->nick.equals_ci(nick) && u_level >= req_level)
+ if (ci->HasFlag(CI_PEACE) && !requester->nick.equals_ci(u->nick) && u_level >= req_level)
return;
if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && is_excepted(ci, u) == 1)
@@ -531,6 +532,7 @@ void bot_raw_ban(User *requester, ChannelInfo *ci, const Anope::string &nick, co
return;
}
+ Anope::string mask;
get_idealban(ci, u, mask);
ci->c->SetMode(NULL, CMODE_BAN, mask);
@@ -544,12 +546,14 @@ void bot_raw_ban(User *requester, ChannelInfo *ci, const Anope::string &nick, co
/*************************************************************************/
-/* Makes a kick with a "dynamic" reason ;) */
-
-void bot_raw_kick(User *requester, ChannelInfo *ci, const Anope::string &nick, const Anope::string &reason)
+/* Makes a kick with a "dynamic" reason ;)
+ * @param requester The user requesting the kick
+ * @param ci The channel
+ * @param u The user being kicked
+ * @param reason The reason for the kick
+ */
+void bot_raw_kick(User *requester, ChannelInfo *ci, User *u, const Anope::string &reason)
{
- User *u = finduser(nick);
-
if (!u || !ci || !ci->c || !ci->c->FindUser(u))
return;
@@ -561,7 +565,7 @@ void bot_raw_kick(User *requester, ChannelInfo *ci, const Anope::string &nick, c
ChanAccess *u_access = ci->GetAccess(u), *req_access = ci->GetAccess(requester);
int16 u_level = u_access ? u_access->level : 0, req_level = req_access ? req_access->level : 0;
- if (ci->HasFlag(CI_PEACE) && !requester->nick.equals_ci(nick) && u_level >= req_level)
+ if (ci->HasFlag(CI_PEACE) && !requester->nick.equals_ci(u->nick) && u_level >= req_level)
return;
if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !check_access(requester, ci, CA_SIGNKICK)))
@@ -572,35 +576,6 @@ void bot_raw_kick(User *requester, ChannelInfo *ci, const Anope::string &nick, c
/*************************************************************************/
-/* Makes a mode operation on a channel for a nick */
-
-void bot_raw_mode(User *requester, ChannelInfo *ci, const Anope::string &mode, const Anope::string &nick)
-{
- char buf[BUFSIZE] = "";
- User *u;
-
- u = finduser(nick);
-
- if (!u || !ci || !ci->c || !ci->c->FindUser(u))
- return;
-
- snprintf(buf, BUFSIZE - 1, "%ld", static_cast<long>(Anope::CurTime));
-
- if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && mode[0] == '-' && requester != u)
- {
- ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", GetString(requester, ACCESS_DENIED).c_str());
- return;
- }
-
- ChanAccess *u_access = ci->GetAccess(u), *req_access = ci->GetAccess(requester);
- int16 u_level = u_access ? u_access->level : 0, req_level = req_access ? req_access->level : 0;
- if (mode[0] == '-' && ci->HasFlag(CI_PEACE) && !requester->nick.equals_ci(nick) && u_level >= req_level)
- return;
-
- ci->c->SetModes(NULL, "%s %s", mode.c_str(), nick.c_str());
-}
-
-/*************************************************************************/
/**
* Normalize buffer stripping control characters and colors
* @param A string to be parsed for control and color codes
diff --git a/src/command.cpp b/src/command.cpp
index f7edbfaa2..290f74d1f 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -16,7 +16,7 @@ CommandSource::~CommandSource()
// Send to the user if the reply is more than one line
if (!this->fantasy || !this->ci || this->reply.size() > 1)
- u->SendMessage(this->service->nick, message);
+ u->SendMessage(this->service, message);
else if (this->ci->botflags.HasFlag(BS_MSG_PRIVMSG))
ircdproto->SendPrivmsg(this->service, this->ci->name, message.c_str());
else if (this->ci->botflags.HasFlag(BS_MSG_NOTICE))
@@ -24,7 +24,7 @@ CommandSource::~CommandSource()
else if (this->ci->botflags.HasFlag(BS_MSG_NOTICEOPS))
ircdproto->SendNoticeChanops(this->service, this->ci->c, message.c_str());
else
- u->SendMessage(this->service->nick, message);
+ u->SendMessage(this->service, message);
}
}
@@ -60,7 +60,7 @@ void CommandSource::Reply(const char *message, ...)
va_start(args, message);
vsnprintf(buf, BUFSIZE - 1, message, args);
- this->reply.push_back(message);
+ this->reply.push_back(buf);
va_end(args);
}
diff --git a/src/commands.cpp b/src/commands.cpp
index e9671f3bd..6c5c556e5 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -187,7 +187,7 @@ void mod_help_cmd(BotInfo *bi, User *u, ChannelInfo *ci, const Anope::string &cm
u->SendMessage(bi, NO_HELP_AVAILABLE, cmd.c_str());
else
{
- u->SendMessage(bi->nick, " ");
+ u->SendMessage(bi, " ");
/* Inform the user what permission is required to use the command */
if (!c->permission.empty())
diff --git a/src/ircd.cpp b/src/ircd.cpp
deleted file mode 100644
index edab02be4..000000000
--- a/src/ircd.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/* Main ircd functions.
- *
- * (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"
-#include "extern.h"
-
-IRCDProto *ircdproto;
-
-/**
- * Globals we want from the protocol file
- **/
-IRCDVar *ircd;
-
-void pmodule_ircd_proto(IRCDProto *proto)
-{
- ircdproto = proto;
-}
-
-/**
- * Set routines for modules to set the prefered function for dealing with things.
- **/
-void pmodule_ircd_var(IRCDVar *ircdvar)
-{
- ircd = ircdvar;
-}
-
diff --git a/src/messages.cpp b/src/messages.cpp
index 945414f05..0f3e7f1a1 100644
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -12,207 +12,7 @@
#include "services.h"
#include "modules.h"
-/*************************************************************************/
-
-int m_nickcoll(const Anope::string &user)
-{
- introduce_user(user);
- return MOD_CONT;
-}
-
-/*************************************************************************/
-
-int m_away(const Anope::string &source, const Anope::string &msg)
-{
- User *u = finduser(source);
-
- if (u && msg.empty()) /* un-away */
- check_memos(u);
- return MOD_CONT;
-}
-
-/*************************************************************************/
-
-int m_kill(const Anope::string &nick, const Anope::string &msg)
-{
- BotInfo *bi;
-
- /* Recover if someone kills us. */
- if (!Config->s_BotServ.empty() && (bi = findbot(nick)))
- {
- introduce_user(nick);
- bi->RejoinAll();
- }
- else
- do_kill(nick, msg);
-
- return MOD_CONT;
-}
-
-/*************************************************************************/
-
-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);
- 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);
- return MOD_CONT;
-}
-
-/*************************************************************************/
-
-int m_motd(const Anope::string &source)
-{
- if (source.empty())
- return MOD_CONT;
-
- FILE *f = fopen(Config->MOTDFilename.c_str(), "r");
- if (f)
- {
- ircdproto->SendNumeric(Config->ServerName, 375, source, ":- %s Message of the Day", Config->ServerName.c_str());
- char buf[BUFSIZE];
- while (fgets(buf, sizeof(buf), f))
- {
- buf[strlen(buf) - 1] = 0;
- ircdproto->SendNumeric(Config->ServerName, 372, source, ":- %s", buf);
- }
- fclose(f);
- ircdproto->SendNumeric(Config->ServerName, 376, source, ":End of /MOTD command.");
- }
- else
- ircdproto->SendNumeric(Config->ServerName, 422, source, ":- MOTD file not found! Please contact your IRC administrator.");
- return MOD_CONT;
-}
-
-/*************************************************************************/
-
-int m_privmsg(const Anope::string &source, const Anope::string &receiver, const Anope::string &message)
-{
- if (source.empty() || receiver.empty() || message.empty())
- return MOD_CONT;
-
- User *u = finduser(source);
-
- if (!u)
- {
- Log() << message << ": user record for " << source << " not found";
-
- BotInfo *bi = findbot(receiver);
- if (bi)
- ircdproto->SendMessage(bi, source, "%s", GetString(USER_RECORD_NOT_FOUND).c_str());
-
- return MOD_CONT;
- }
-
- if (receiver[0] == '#' && !Config->s_BotServ.empty())
- {
- ChannelInfo *ci = cs_findchan(receiver);
- if (ci)
- {
- /* Some paranoia checks */
- if (!ci->HasFlag(CI_FORBIDDEN) && ci->c && ci->bi)
- botchanmsgs(u, ci, message);
- }
- }
- else
- {
- /* Check if we should ignore. Operators always get through. */
- if (allow_ignore && !is_oper(u))
- {
- if (get_ignore(source))
- {
- Anope::string target = myStrGetToken(message, ' ', 0);
- BotInfo *bi = findbot(target);
- if (bi)
- Log(bi) << "Ignored message from " << source << " using command " << target;
- return MOD_CONT;
- }
- }
-
- /* If a server is specified (nick@server format), make sure it matches
- * us, and strip it off. */
- Anope::string botname = receiver;
- size_t s = receiver.find('@');
- if (s != Anope::string::npos)
- {
- Anope::string servername(receiver.begin() + s + 1, receiver.end());
- botname = botname.substr(0, s);
- if (!servername.equals_ci(Config->ServerName))
- return MOD_CONT;
- }
- else if (Config->UseStrictPrivMsg)
- {
- BotInfo *bi = findbot(receiver);
- if (!bi)
- return MOD_CONT;
- Log(LOG_DEBUG) << "Ignored PRIVMSG without @ from " << source;
- u->SendMessage(bi, INVALID_TARGET, receiver.c_str(), receiver.c_str(), Config->ServerName.c_str(), receiver.c_str());
- return MOD_CONT;
- }
-
- BotInfo *bi = findbot(botname);
-
- if (bi)
- {
- if (message[0] == '\1' && message[message.length() - 1] == '\1')
- {
- if (message.substr(0, 6).equals_ci("\1PING "))
- {
- Anope::string buf = message;
- buf.erase(buf.begin());
- buf.erase(buf.end() - 1);
- ircdproto->SendCTCP(bi, u->nick, "%s", buf.c_str());
- }
- else if (message.substr(0, 9).equals_ci("\1VERSION\1"))
- {
- ircdproto->SendCTCP(bi, u->nick, "VERSION 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());
- }
- }
- if (bi == NickServ || bi == MemoServ || bi == BotServ)
- mod_run_cmd(bi, u, message, false);
- else if (bi == ChanServ)
- {
- if (!is_oper(u) && Config->CSOpersOnly)
- u->SendMessage(ChanServ, ACCESS_DENIED);
- else
- mod_run_cmd(bi, u, message, false);
- }
- else if (bi == HostServ)
- {
- if (!ircd->vhost)
- u->SendMessage(HostServ, SERVICE_OFFLINE, Config->s_HostServ.c_str());
- else
- mod_run_cmd(bi, u, message, false);
- }
- else if (bi == OperServ)
- {
- if (!is_oper(u) && Config->OSOpersOnly)
- {
- u->SendMessage(OperServ, ACCESS_DENIED);
- if (Config->WallBadOS)
- ircdproto->SendGlobops(OperServ, "Denied access to %s from %s!%s@%s (non-oper)", Config->s_OperServ.c_str(), u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str());
- }
- else
- {
- Log(OperServ) << u->nick << ": " << message;
- mod_run_cmd(bi, u, message, false);
- }
- }
- }
- }
-
- return MOD_CONT;
-}
-
-/*************************************************************************/
-
-bool m_stats(const Anope::string &source, const std::vector<Anope::string> &params)
+bool OnStats(const Anope::string &source, const std::vector<Anope::string> &params)
{
if (params.size() < 1)
return true;
@@ -222,7 +22,7 @@ bool m_stats(const Anope::string &source, const std::vector<Anope::string> &para
switch (params[0][0])
{
case 'l':
- if (u && is_oper(u))
+ if (u && u->HasMode(UMODE_OPER))
{
ircdproto->SendNumeric(Config->ServerName, 211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
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, static_cast<long>(Anope::CurTime - start_time));
@@ -233,7 +33,7 @@ bool m_stats(const Anope::string &source, const std::vector<Anope::string> &para
case 'o':
case 'O':
/* Check whether the user is an operator */
- if (u && !is_oper(u) && Config->HideStatsO)
+ if (u && !u->HasMode(UMODE_OPER) && Config->HideStatsO)
ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]);
else
{
@@ -269,45 +69,103 @@ bool m_stats(const Anope::string &source, const std::vector<Anope::string> &para
return true;
}
-bool m_version(const Anope::string &source, const std::vector<Anope::string> &)
+bool OnTime(const Anope::string &source, const std::vector<Anope::string> &)
+{
+ if (source.empty())
+ return true;
+
+ 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);
+ return true;
+}
+
+bool OnVersion(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());
- return MOD_CONT;
+ return true;
}
-/*************************************************************************/
-
-int m_whois(const Anope::string &source, const Anope::string &who)
+/* XXX We should cache the file somewhere not open/read/close it on every request */
+bool OnMotd(const Anope::string &source, const std::vector<Anope::string> &)
{
- if (!source.empty() && !who.empty())
+ if (source.empty())
+ return true;
+
+ FILE *f = fopen(Config->MOTDFilename.c_str(), "r");
+ if (f)
{
- User *u;
- BotInfo *bi = findbot(who);
- if (bi)
- {
- ircdproto->SendNumeric(Config->ServerName, 311, source, "%s %s %s * :%s", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str());
- ircdproto->SendNumeric(Config->ServerName, 307, source, "%s :is a registered nick", bi->nick.c_str());
- ircdproto->SendNumeric(Config->ServerName, 312, source, "%s %s :%s", bi->nick.c_str(), Config->ServerName.c_str(), Config->ServerDesc.c_str());
- ircdproto->SendNumeric(Config->ServerName, 317, source, "%s %ld %ld :seconds idle, signon time", bi->nick.c_str(), static_cast<long>(Anope::CurTime - bi->lastmsg), static_cast<long>(start_time));
- ircdproto->SendNumeric(Config->ServerName, 318, source, "%s :End of /WHOIS list.", who.c_str());
- }
- else if (!ircd->svshold && (u = finduser(who)) && u->server == Me)
+ ircdproto->SendNumeric(Config->ServerName, 375, source, ":- %s Message of the Day", Config->ServerName.c_str());
+ char buf[BUFSIZE];
+ while (fgets(buf, sizeof(buf), f))
{
- ircdproto->SendNumeric(Config->ServerName, 311, source, "%s %s %s * :%s", u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str(), u->realname.c_str());
- ircdproto->SendNumeric(Config->ServerName, 312, source, "%s %s :%s", u->nick.c_str(), Config->ServerName.c_str(), Config->ServerDesc.c_str());
- ircdproto->SendNumeric(Config->ServerName, 318, source, "%s :End of /WHOIS list.", u->nick.c_str());
+ buf[strlen(buf) - 1] = 0;
+ ircdproto->SendNumeric(Config->ServerName, 372, source, ":- %s", buf);
}
- else
- ircdproto->SendNumeric(Config->ServerName, 401, source, "%s :No such service.", who.c_str());
+ fclose(f);
+ ircdproto->SendNumeric(Config->ServerName, 376, source, ":End of /MOTD command.");
}
- return MOD_CONT;
+ else
+ ircdproto->SendNumeric(Config->ServerName, 422, source, ":- MOTD file not found! Please contact your IRC administrator.");
+
+ return true;
}
+#define ProtocolFunc(x) \
+ inline bool x(const Anope::string &source, const std::vector<Anope::string> &params) \
+ { \
+ return ircdmessage->x(source, params); \
+ }
+
+ProtocolFunc(On436)
+ProtocolFunc(OnAway)
+ProtocolFunc(OnJoin)
+ProtocolFunc(OnKick)
+ProtocolFunc(OnKill)
+ProtocolFunc(OnMode)
+ProtocolFunc(OnNick)
+ProtocolFunc(OnUID)
+ProtocolFunc(OnPart)
+ProtocolFunc(OnPing)
+ProtocolFunc(OnPrivmsg)
+ProtocolFunc(OnQuit)
+ProtocolFunc(OnServer)
+ProtocolFunc(OnSQuit)
+ProtocolFunc(OnTopic)
+ProtocolFunc(OnWhois)
+ProtocolFunc(OnCapab)
+ProtocolFunc(OnSJoin)
+ProtocolFunc(OnError)
+
void init_core_messages()
{
- static Message message_stats("STATS", m_stats);
- static Message message_time("TIME", m_time);
- static Message message_verssion("VERSION", m_version);
+ static Message message_stats("STATS", OnStats);
+ static Message message_time("TIME", OnTime);
+ static Message message_verssion("VERSION", OnVersion);
+ static Message message_motd("MOTD", OnMotd);
+
+ static Message message_436("436", On436);
+ static Message message_away("AWAY", OnAway);
+ static Message message_join("JOIN", OnJoin);
+ static Message message_kick("KICK", OnKick);
+ static Message message_kill("KILL", OnKill);
+ static Message message_mode("MODE", OnMode);
+ static Message message_nick("NICK", OnNick);
+ static Message message_uid("UID", OnUID);
+ static Message message_part("PART", OnPart);
+ static Message message_ping("PING", OnPing);
+ static Message message_privmsg("PRIVMSG", OnPrivmsg);
+ static Message message_quit("QUIT", OnQuit);
+ static Message message_server("SERVER", OnServer);
+ static Message message_squit("SQUIT", OnSQuit);
+ static Message message_topic("TOPIC", OnTopic);
+ static Message message_whois("WHOIS", OnWhois);
+ static Message message_capab("CAPAB", OnCapab);
+ static Message message_sjoin("SJOIN", OnSJoin);
+ static Message message_error("ERROR", OnError);
}
diff --git a/src/misc.cpp b/src/misc.cpp
index c885188f8..51899270b 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -70,68 +70,6 @@ int tolower(char c)
/*************************************************************************/
/**
- * strscpy: Copy at most len-1 characters from a string to a buffer, and
- * add a null terminator after the last character copied.
- * @param d Buffer to copy into
- * @param s Data to copy int
- * @param len Length of data
- * @return updated buffer
- */
-char *strscpy(char *d, const char *s, size_t len)
-{
- char *d_orig = d;
-
- if (!len)
- return d;
- while (--len && (*d++ = *s++));
- *d = '\0';
- return d_orig;
-}
-
-/*************************************************************************/
-
-/**
- * strnrepl: Replace occurrences of `old' with `new' in string `s'. Stop
- * replacing if a replacement would cause the string to exceed
- * `size' bytes (including the null terminator). Return the
- * string.
- * @param s String
- * @param size size of s
- * @param old character to replace
- * @param newstr character to replace with
- * @return updated s
- */
-char *strnrepl(char *s, int32 size, const char *old, const char *newstr)
-{
- char *ptr = s;
- int32 left = strlen(s);
- int32 avail = size - (left + 1);
- int32 oldlen = strlen(old);
- int32 newlen = strlen(newstr);
- int32 diff = newlen - oldlen;
-
- while (left >= oldlen)
- {
- if (strncmp(ptr, old, oldlen))
- {
- --left;
- ++ptr;
- continue;
- }
- if (diff > avail)
- break;
- if (diff)
- memmove(ptr + oldlen + diff, ptr + oldlen, left + 1 - oldlen);
- strncpy(ptr, newstr, newlen);
- ptr += newlen;
- left -= oldlen;
- }
- return s;
-}
-
-/*************************************************************************/
-
-/**
* merge_args: Take an argument count and argument vector and merge them
* into a single string in which each argument is separated by
* a space.
@@ -576,7 +514,7 @@ void EnforceQlinedNick(const Anope::string &nick, const Anope::string &killer)
if (u2)
{
Log(LOG_NORMAL, "xline") << "Killed Q-lined nick: " << u2->GetMask();
- kill_user(killer, u2->nick, "This nick is reserved for Services. Please use a non Q-Lined nick.");
+ kill_user(killer, u2, "This nick is reserved for Services. Please use a non Q-Lined nick.");
}
}
diff --git a/src/modes.cpp b/src/modes.cpp
index 7439c852c..1daea86b3 100644
--- a/src/modes.cpp
+++ b/src/modes.cpp
@@ -256,7 +256,7 @@ bool ChannelModeKey::IsValid(const Anope::string &value) const
*/
bool ChannelModeAdmin::CanSet(User *u) const
{
- if (u && is_oper(u))
+ if (u && u->HasMode(UMODE_OPER))
return true;
return false;
@@ -268,7 +268,7 @@ bool ChannelModeAdmin::CanSet(User *u) const
*/
bool ChannelModeOper::CanSet(User *u) const
{
- if (u && is_oper(u))
+ if (u && u->HasMode(UMODE_OPER))
return true;
return false;
diff --git a/src/operserv.cpp b/src/operserv.cpp
index e7de407bd..911384e79 100644
--- a/src/operserv.cpp
+++ b/src/operserv.cpp
@@ -587,8 +587,8 @@ XLine *SNLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_
User *user = *it;
++it;
- if (!is_oper(user) && Anope::Match(user->realname, x->Mask))
- kill_user(Config->ServerName, user->nick, rreason);
+ if (!user->HasMode(UMODE_OPER) && Anope::Match(user->realname, x->Mask))
+ kill_user(Config->ServerName, user, rreason);
}
}
@@ -605,7 +605,7 @@ void SNLineManager::OnMatch(User *u, XLine *x)
ircdproto->SendSGLine(x);
Anope::string reason = "G-Lined: " + x->Reason;
- kill_user(Config->s_OperServ, u->nick, reason);
+ kill_user(Config->s_OperServ, u, reason);
}
void SNLineManager::OnExpire(XLine *x)
@@ -675,7 +675,7 @@ XLine *SQLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_
UserContainer *uc = *it;
++it;
- if (is_oper(uc->user))
+ if (uc->user->HasMode(UMODE_OPER))
continue;
c->Kick(NULL, uc->user, "%s", reason.c_str());
}
@@ -688,8 +688,8 @@ XLine *SQLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_
User *user = *it;
++it;
- if (!is_oper(user) && Anope::Match(user->nick, x->Mask))
- kill_user(Config->ServerName, user->nick, rreason);
+ if (!user->HasMode(UMODE_OPER) && Anope::Match(user->nick, x->Mask))
+ kill_user(Config->ServerName, user, rreason);
}
}
}
@@ -709,7 +709,7 @@ void SQLineManager::OnMatch(User *u, XLine *x)
ircdproto->SendSQLine(x);
Anope::string reason = "Q-Lined: " + x->Reason;
- kill_user(Config->s_OperServ, u->nick, reason);
+ kill_user(Config->s_OperServ, u, reason);
}
void SQLineManager::OnExpire(XLine *x)
diff --git a/src/process.cpp b/src/process.cpp
index 285c4ae6b..4a7811c69 100644
--- a/src/process.cpp
+++ b/src/process.cpp
@@ -101,7 +101,7 @@ IgnoreData *get_ignore(const Anope::string &nick)
if (u)
{
/* Opers are not ignored, even if a matching entry may be present. */
- if (is_oper(u))
+ if (u->HasMode(UMODE_OPER))
return NULL;
for (; ign != ign_end; ++ign)
if (match_usermask((*ign)->mask, u))
diff --git a/src/protocol.cpp b/src/protocol.cpp
index 545824681..cc4112970 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -1,4 +1,24 @@
#include "services.h"
+#include "modules.h"
+
+IRCDProto *ircdproto;
+IRCDVar *ircd;
+IRCdMessage *ircdmessage;
+
+void pmodule_ircd_proto(IRCDProto *proto)
+{
+ ircdproto = proto;
+}
+
+void pmodule_ircd_var(IRCDVar *ircdvar)
+{
+ ircd = ircdvar;
+}
+
+void pmodule_ircd_message(IRCdMessage *message)
+{
+ ircdmessage = message;
+}
void IRCDProto::SendMessageInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf)
{
@@ -269,3 +289,312 @@ bool IRCDProto::IsChannelValid(const Anope::string &chan)
return true;
}
+
+bool IRCdMessage::On436(const Anope::string &, const std::vector<Anope::string> &params)
+{
+ if (!params.empty())
+ introduce_user(params[0]);
+ return true;
+}
+
+bool IRCdMessage::OnAway(const Anope::string &source, const std::vector<Anope::string> &params)
+{
+ User *u = finduser(source);
+ if (u && params.empty()) /* un-away */
+ check_memos(u);
+ return true;
+}
+
+bool IRCdMessage::OnJoin(const Anope::string &source, const std::vector<Anope::string> &params)
+{
+ if (!params.empty())
+ do_join(source, params[0], params.size() > 1 ? params[1] : "");
+ return true;
+}
+
+bool IRCdMessage::OnKick(const Anope::string &source, const std::vector<Anope::string> &params)
+{
+ if (params.size() > 2)
+ do_kick(source, params[0], params[1], params[2]);
+ return true;
+}
+
+/** Called on KILL
+ * @params[0] The nick
+ * @params[1] The reason
+ */
+bool IRCdMessage::OnKill(const Anope::string &source, const std::vector<Anope::string> &params)
+{
+ User *u = finduser(params[0]);
+ BotInfo *bi;
+
+ if (!u)
+ return true;
+
+ /* Recover if someone kills us. */
+ if (!Config->s_BotServ.empty() && u->server == Me && (bi = dynamic_cast<BotInfo *>(u)))
+ {
+ introduce_user(bi->nick);
+ bi->RejoinAll();
+ }
+ else
+ do_kill(u, params[1]);
+
+
+ return true;
+}
+
+bool IRCdMessage::OnUID(const Anope::string &source, const std::vector<Anope::string> &params)
+{
+ return true;
+}
+
+bool IRCdMessage::OnPart(const Anope::string &source, const std::vector<Anope::string> &params)
+{
+ if (!params.empty())
+ do_part(source, params[0], params.size() > 1 ? params[1] : "");
+ return true;
+}
+
+bool IRCdMessage::OnPing(const Anope::string &, const std::vector<Anope::string> &params)
+{
+ if (!params.empty())
+ ircdproto->SendPong(params.size() > 1 ? params[1] : Config->ServerName, params[0]);
+ return true;
+}
+
+bool IRCdMessage::OnPrivmsg(const Anope::string &source, const std::vector<Anope::string> &params)
+{
+ const Anope::string &receiver = params.size() > 0 ? params[0] : "";
+ const Anope::string &message = params.size() > 1 ? params[1] : "";
+
+ /* Messages from servers can happen on some IRCds, check for . */
+ if (source.empty() || receiver.empty() || message.empty() || source.find('.') != Anope::string::npos)
+ return true;
+
+ User *u = finduser(source);
+
+ if (!u)
+ {
+ Log() << message << ": user record for " << source << " not found";
+
+ BotInfo *bi = findbot(receiver);
+ if (bi)
+ ircdproto->SendMessage(bi, source, "%s", GetString(USER_RECORD_NOT_FOUND).c_str());
+
+ return MOD_CONT;
+ }
+
+ if (receiver[0] == '#' && !Config->s_BotServ.empty())
+ {
+ ChannelInfo *ci = cs_findchan(receiver);
+ /* Some paranoia checks */
+ if (ci && !ci->HasFlag(CI_FORBIDDEN) && ci->c && ci->bi)
+ botchanmsgs(u, ci, message);
+ }
+ else
+ {
+ /* Check if we should ignore. Operators always get through. */
+ if (allow_ignore && !u->HasMode(UMODE_OPER))
+ {
+ if (get_ignore(source))
+ {
+ Anope::string target = myStrGetToken(message, ' ', 0);
+ BotInfo *bi = findbot(target);
+ if (bi)
+ Log(bi) << "Ignored message from " << source << " using command " << target;
+ return MOD_CONT;
+ }
+ }
+
+ /* If a server is specified (nick@server format), make sure it matches
+ * us, and strip it off. */
+ Anope::string botname = receiver;
+ size_t s = receiver.find('@');
+ if (s != Anope::string::npos)
+ {
+ Anope::string servername(receiver.begin() + s + 1, receiver.end());
+ botname = botname.substr(0, s);
+ if (!servername.equals_ci(Config->ServerName))
+ return MOD_CONT;
+ }
+ else if (Config->UseStrictPrivMsg)
+ {
+ BotInfo *bi = findbot(receiver);
+ if (!bi)
+ return MOD_CONT;
+ Log(LOG_DEBUG) << "Ignored PRIVMSG without @ from " << source;
+ u->SendMessage(bi, INVALID_TARGET, receiver.c_str(), receiver.c_str(), Config->ServerName.c_str(), receiver.c_str());
+ return MOD_CONT;
+ }
+
+ BotInfo *bi = findbot(botname);
+
+ if (bi)
+ {
+ if (message[0] == '\1' && message[message.length() - 1] == '\1')
+ {
+ if (message.substr(0, 6).equals_ci("\1PING "))
+ {
+ Anope::string buf = message;
+ buf.erase(buf.begin());
+ buf.erase(buf.end() - 1);
+ ircdproto->SendCTCP(bi, u->nick, "%s", buf.c_str());
+ }
+ else if (message.substr(0, 9).equals_ci("\1VERSION\1"))
+ {
+ ircdproto->SendCTCP(bi, u->nick, "VERSION 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());
+ }
+ }
+ else if (bi == ChanServ)
+ {
+ if (!u->HasMode(UMODE_OPER) && Config->CSOpersOnly)
+ u->SendMessage(ChanServ, ACCESS_DENIED);
+ else
+ mod_run_cmd(bi, u, message, false);
+ }
+ else if (bi == HostServ)
+ {
+ if (!ircd->vhost)
+ u->SendMessage(HostServ, SERVICE_OFFLINE, Config->s_HostServ.c_str());
+ else
+ mod_run_cmd(bi, u, message, false);
+ }
+ else if (bi == OperServ)
+ {
+ if (!u->HasMode(UMODE_OPER) && Config->OSOpersOnly)
+ {
+ u->SendMessage(OperServ, ACCESS_DENIED);
+ if (Config->WallBadOS)
+ ircdproto->SendGlobops(OperServ, "Denied access to %s from %s!%s@%s (non-oper)", Config->s_OperServ.c_str(), u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str());
+ }
+ else
+ {
+ Log(OperServ) << u->nick << ": " << message;
+ mod_run_cmd(bi, u, message, false);
+ }
+ }
+ else
+ mod_run_cmd(bi, u, message, false);
+ }
+ }
+
+ return true;
+}
+
+bool IRCdMessage::OnQuit(const Anope::string &source, const std::vector<Anope::string> &params)
+{
+ const Anope::string &reason = !params.empty() ? params[0] : "";
+ User *user = finduser(source);
+ if (!user)
+ {
+ Log() << "user: QUIT from nonexistent user " << source << " (" << reason << ")";
+ return true;
+ }
+
+ 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 = reason;
+ }
+ FOREACH_MOD(I_OnUserQuit, OnUserQuit(user, reason));
+ delete user;
+
+ return true;
+}
+
+bool IRCdMessage::OnSQuit(const Anope::string &source, const std::vector<Anope::string> &params)
+{
+ const Anope::string &server = source;
+
+ Server *s = Server::Find(server);
+
+ if (!s)
+ {
+ Log() << "SQUIT for nonexistent server " << server;
+ return true;
+ }
+
+ FOREACH_MOD(I_OnServerQuit, OnServerQuit(s));
+
+ Anope::string buf;
+ /* If this is a juped server, send a nice global to inform the online
+ * opers that we received it.
+ */
+ if (s->HasFlag(SERVER_JUPED))
+ {
+ buf = "Received SQUIT for juped server " + s->GetName();
+ ircdproto->SendGlobops(OperServ, "%s", buf.c_str());
+ }
+
+ buf = s->GetName() + " " + s->GetUplink()->GetName();
+
+ if (s->GetUplink() == Me && Capab.HasFlag(CAPAB_UNCONNECT))
+ {
+ Log(LOG_DEBUG) << "Sending UNCONNECT SQUIT for " << s->GetName();
+ /* need to fix */
+ ircdproto->SendSquit(s->GetName(), buf);
+ }
+
+ s->Delete(buf);
+
+ return true;
+}
+
+bool IRCdMessage::OnWhois(const Anope::string &source, const std::vector<Anope::string> &params)
+{
+ const Anope::string &who = params[0];
+
+ if (!source.empty() && !who.empty())
+ {
+ User *u;
+ BotInfo *bi = findbot(who);
+ if (bi)
+ {
+ ircdproto->SendNumeric(Config->ServerName, 311, source, "%s %s %s * :%s", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str());
+ ircdproto->SendNumeric(Config->ServerName, 307, source, "%s :is a registered nick", bi->nick.c_str());
+ ircdproto->SendNumeric(Config->ServerName, 312, source, "%s %s :%s", bi->nick.c_str(), Config->ServerName.c_str(), Config->ServerDesc.c_str());
+ ircdproto->SendNumeric(Config->ServerName, 317, source, "%s %ld %ld :seconds idle, signon time", bi->nick.c_str(), static_cast<long>(Anope::CurTime - bi->lastmsg), static_cast<long>(start_time));
+ ircdproto->SendNumeric(Config->ServerName, 318, source, "%s :End of /WHOIS list.", who.c_str());
+ }
+ else if (!ircd->svshold && (u = finduser(who)) && u->server == Me)
+ {
+ ircdproto->SendNumeric(Config->ServerName, 311, source, "%s %s %s * :%s", u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str(), u->realname.c_str());
+ ircdproto->SendNumeric(Config->ServerName, 312, source, "%s %s :%s", u->nick.c_str(), Config->ServerName.c_str(), Config->ServerDesc.c_str());
+ ircdproto->SendNumeric(Config->ServerName, 318, source, "%s :End of /WHOIS list.", u->nick.c_str());
+ }
+ else
+ ircdproto->SendNumeric(Config->ServerName, 401, source, "%s :No such service.", who.c_str());
+ }
+
+ return true;
+}
+
+bool IRCdMessage::OnCapab(const Anope::string &, const std::vector<Anope::string> &params)
+{
+ 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(params[i]))
+ {
+ Capab.SetFlag(Capab_Info[j].Flag);
+ break;
+ }
+ }
+ }
+
+ return true;
+}
+
+bool IRCdMessage::OnError(const Anope::string &, const std::vector<Anope::string> &params)
+{
+ if (!params.empty())
+ Log(LOG_DEBUG) << params[0];
+
+ return true;
+}
+
diff --git a/src/regchannel.cpp b/src/regchannel.cpp
index e89bbee5c..1932da4e8 100644
--- a/src/regchannel.cpp
+++ b/src/regchannel.cpp
@@ -729,7 +729,7 @@ bool ChannelInfo::CheckKick(User *user)
do_kick = true;
Anope::string mask, reason;
- if (!is_oper(user) && (this->HasFlag(CI_SUSPENDED) || this->HasFlag(CI_FORBIDDEN)))
+ if (!user->HasMode(UMODE_OPER) && (this->HasFlag(CI_SUSPENDED) || this->HasFlag(CI_FORBIDDEN)))
{
get_idealban(this, user, mask);
reason = this->forbidreason.empty() ? GetString(user, CHAN_MAY_NOT_BE_USED) : this->forbidreason;
diff --git a/src/servers.cpp b/src/servers.cpp
index f7bef6ec7..dc5dc4cf0 100644
--- a/src/servers.cpp
+++ b/src/servers.cpp
@@ -349,67 +349,6 @@ 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 sending the squit
- * @param server Name of the server leaving
- * @return void
- */
-void do_squit(const Anope::string &source, const Anope::string &server)
-{
- Server *s = Server::Find(server);
-
- if (!s)
- {
- Log() << "SQUIT for nonexistent server " << server;
- return;
- }
-
- FOREACH_MOD(I_OnServerQuit, OnServerQuit(s));
-
- Anope::string buf;
- /* If this is a juped server, send a nice global to inform the online
- * opers that we received it.
- */
- if (s->HasFlag(SERVER_JUPED))
- {
- buf = "Received SQUIT for juped server " + s->GetName();
- ircdproto->SendGlobops(OperServ, "%s", buf.c_str());
- }
-
- buf = s->GetName() + " " + s->GetUplink()->GetName();
-
- if (s->GetUplink() == Me && Capab.HasFlag(CAPAB_UNCONNECT))
- {
- Log(LOG_DEBUG) << "Sending UNCONNECT SQUIT for " << s->GetName();
- /* need to fix */
- ircdproto->SendSquit(s->GetName(), buf);
- }
-
- s->Delete(buf);
-}
-
-/*************************************************************************/
-
-/** Handle parsing the CAPAB/PROTOCTL messages
- */
-void CapabParse(const std::vector<Anope::string> &params)
-{
- 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(params[i]))
- {
- Capab.SetFlag(Capab_Info[j].Flag);
- break;
- }
- }
- }
-}
-
-/*************************************************************************/
-
/* TS6 UID generator common code.
*
* Derived from atheme-services, uid.c (hg 2954:116d46894b4c).
diff --git a/src/sessions.cpp b/src/sessions.cpp
index a90364160..a6032b572 100644
--- a/src/sessions.cpp
+++ b/src/sessions.cpp
@@ -91,9 +91,10 @@ Session *findsession(const Anope::string &host)
* causes the the session limit to be exceeded, kill the connecting user.
*/
-void add_session(const Anope::string &nick, const Anope::string &host, const Anope::string &hostip)
+void add_session(User *u)
{
- Session *session = findsession(host);
+ const Anope::string &hostip = u->ip() ? u->ip.addr() : "";
+ Session *session = findsession(u->host);
if (session)
{
@@ -101,7 +102,7 @@ void add_session(const Anope::string &nick, const Anope::string &host, const Ano
if (Config->DefSessionLimit && session->count >= Config->DefSessionLimit)
{
kill = true;
- Exception *exception = find_hostip_exception(host, hostip);
+ Exception *exception = find_hostip_exception(u->host, hostip);
if (exception)
{
kill = false;
@@ -113,9 +114,9 @@ void add_session(const Anope::string &nick, const Anope::string &host, const Ano
if (kill)
{
if (!Config->SessionLimitExceeded.empty())
- ircdproto->SendMessage(OperServ, nick, Config->SessionLimitExceeded.c_str(), host.c_str());
+ u->SendMessage(OperServ, Config->SessionLimitExceeded.c_str(), u->host.c_str());
if (!Config->SessionLimitDetailsLoc.empty())
- ircdproto->SendMessage(OperServ, nick, "%s", Config->SessionLimitDetailsLoc.c_str());
+ u->SendMessage(OperServ, "%s", Config->SessionLimitDetailsLoc.c_str());
/* Previously on IRCds that send a QUIT (InspIRCD) when a user is killed, the session for a host was
* decremented in do_quit, which caused problems and fixed here
@@ -125,12 +126,12 @@ void add_session(const Anope::string &nick, const Anope::string &host, const Ano
* decremented in do_kill or in do_quit - Adam
*/
++session->count;
- kill_user(Config->s_OperServ, nick, "Session limit exceeded");
+ kill_user(Config->s_OperServ, u, "Session limit exceeded");
++session->hits;
if (Config->MaxSessionKill && session->hits >= Config->MaxSessionKill && SGLine)
{
- Anope::string akillmask = "*@" + host;
+ const Anope::string &akillmask = "*@" + u->host;
XLine *x = new XLine(akillmask, Config->s_OperServ, Anope::CurTime + Config->SessionAutoKillExpiry, "Session limit exceeded");
SGLine->AddXLine(x);
ircdproto->SendGlobops(OperServ, "Added a temporary AKILL for \2%s\2 due to excessive connections", akillmask.c_str());
@@ -144,7 +145,7 @@ void add_session(const Anope::string &nick, const Anope::string &host, const Ano
else
{
session = new Session();
- session->host = host;
+ session->host = u->host;
session->count = 1;
session->hits = 0;
@@ -152,7 +153,7 @@ void add_session(const Anope::string &nick, const Anope::string &host, const Ano
}
}
-void del_session(const Anope::string &host)
+void del_session(User *u)
{
if (!Config->LimitSessions)
{
@@ -160,7 +161,7 @@ void del_session(const Anope::string &host)
return;
}
- if (host.empty())
+ if (!u)
{
Log(LOG_DEBUG) << "del_session called with NULL values";
return;
@@ -168,14 +169,14 @@ void del_session(const Anope::string &host)
Log(LOG_DEBUG_2) << "del_session() called";
- Session *session = findsession(host);
+ Session *session = findsession(u->host);
if (!session)
{
if (debug)
{
- ircdproto->SendGlobops(OperServ, "WARNING: Tried to delete non-existant session: \2%s", host.c_str());
- Log() << "session: Tried to delete non-existant session: " << host;
+ ircdproto->SendGlobops(OperServ, "WARNING: Tried to delete non-existant session: \2%s", u->host.c_str());
+ Log() << "session: Tried to delete non-existant session: " << u->host;
}
return;
}
@@ -188,8 +189,6 @@ void del_session(const Anope::string &host)
SessionList.erase(session->host);
- Log(LOG_DEBUG_2) << "del_session(): free session structure";
-
delete session;
Log(LOG_DEBUG_2) << "del_session() done";
diff --git a/src/users.cpp b/src/users.cpp
index f6c0983ef..0290e9efb 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -198,14 +198,14 @@ User::~User()
--usercnt;
- if (is_oper(this))
+ if (this->HasMode(UMODE_OPER))
--opcnt;
while (!this->chans.empty())
this->chans.front()->chan->DeleteUser(this);
if (Config->LimitSessions && !this->server->IsULined())
- del_session(this->host);
+ del_session(this);
UserListByNick.erase(this->nick);
if (!this->uid.empty())
@@ -218,7 +218,7 @@ User::~User()
Log(LOG_DEBUG_2) << "User::~User() done";
}
-void User::SendMessage(const Anope::string &source, const char *fmt, ...)
+void User::SendMessage(BotInfo *source, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
@@ -234,7 +234,7 @@ void User::SendMessage(const Anope::string &source, const char *fmt, ...)
}
}
-void User::SendMessage(const Anope::string &source, const Anope::string &msg)
+void User::SendMessage(BotInfo *source, const Anope::string &msg)
{
/* Send privmsg instead of notice if:
* - UsePrivmsg is enabled
@@ -242,9 +242,9 @@ void User::SendMessage(const Anope::string &source, const Anope::string &msg)
* - The user is registered and has set /ns set msg on
*/
if (Config->UsePrivmsg && ((!this->nc && Config->NSDefFlags.HasFlag(NI_MSG)) || (this->nc && this->nc->HasFlag(NI_MSG))))
- ircdproto->SendPrivmsg(findbot(source), this->nick, "%s", msg.c_str());
+ ircdproto->SendPrivmsg(source, this->nick, "%s", msg.c_str());
else
- ircdproto->SendNotice(findbot(source), this->nick, "%s", msg.c_str());
+ ircdproto->SendNotice(source, this->nick, "%s", msg.c_str());
}
void User::SendMessage(BotInfo *source, LanguageString message, ...)
@@ -272,7 +272,7 @@ void User::SendMessage(BotInfo *source, LanguageString message, ...)
Anope::string line;
while (sep.GetToken(line))
- this->SendMessage(source->nick, line.empty() ? " " : line);
+ this->SendMessage(source, line.empty() ? " " : line);
}
/** Collides a nick.
@@ -349,7 +349,7 @@ void User::Collide(NickAlias *na)
ircdproto->SendForceNickChange(this, guestnick, Anope::CurTime);
}
else
- kill_user(Config->s_NickServ, this->nick, "Services nickname-enforcer kill");
+ kill_user(Config->s_NickServ, this, "Services nickname-enforcer kill");
}
/** Login the user to a NickCore
@@ -757,7 +757,7 @@ User *do_nick(const Anope::string &source, const Anope::string &nick, const Anop
if (user && MOD_RESULT != EVENT_STOP)
{
if (Config->LimitSessions && !serv->IsULined())
- add_session(nick, host, user->ip() ? user->ip.addr() : "");
+ add_session(*user);
if (!user)
return NULL;
@@ -828,7 +828,7 @@ User *do_nick(const Anope::string &source, const Anope::string &nick, const Anop
if (ircd->sqline)
{
- if (!is_oper(user) && SQLine->Check(user))
+ if (user->HasMode(UMODE_OPER) && SQLine->Check(user))
return NULL;
}
}
@@ -855,47 +855,13 @@ void do_umode(const Anope::string &, const Anope::string &user, const Anope::str
/*************************************************************************/
-/** Handle a QUIT command.
- * @param source User quitting
- * @param reason Quit reason
- */
-void do_quit(const Anope::string &source, const Anope::string &reason)
-{
- User *user = finduser(source);
- if (!user)
- {
- Log() << "user: QUIT from nonexistent user " << source << " (" << reason << ")";
- return;
- }
-
- 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 = reason;
- }
- FOREACH_MOD(I_OnUserQuit, OnUserQuit(user, reason));
- delete user;
-}
-
-/*************************************************************************/
/* Handle a KILL command.
- * av[0] = nick being killed
- * av[1] = reason
+ * @param user the user being killed
+ * @param msg why
*/
-
-void do_kill(const Anope::string &nick, const Anope::string &msg)
+void do_kill(User *user, const Anope::string &msg)
{
- User *user = finduser(nick);
- if (!user)
- {
- Log() << "KILL of nonexistent nick: " << nick;
- return;
- }
-
Log(user, "killed") << "was killed (Reason: " << msg << ")";
NickAlias *na = findnick(user->nick);
@@ -910,16 +876,6 @@ void do_kill(const Anope::string &nick, const Anope::string &msg)
/*************************************************************************/
/*************************************************************************/
-/* Is the given nick an oper? */
-
-bool is_oper(User *user)
-{
- return user && user->HasMode(UMODE_OPER);
-}
-
-/*************************************************************************/
-/*************************************************************************/
-
/* Is the given user ban-excepted? */
bool is_excepted(ChannelInfo *ci, User *user)
{