summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-08-01 13:16:18 +0000
committerAdam <Adam@anope.org>2013-08-01 13:39:35 +0000
commit1e625b6837fdf96616cfc49700aa28d184a7c171 (patch)
tree6b6f06deaf769dd6b1a7853f90d26183828986f1 /src
parent402c624e455d13cc811bef2e8d1639846e892a34 (diff)
Use MessageSource as the source for many IRCDProto funcs
Keep track of what user modes are oper only/server only/etc
Diffstat (limited to 'src')
-rw-r--r--src/bots.cpp2
-rw-r--r--src/channels.cpp6
-rw-r--r--src/logger.cpp14
-rw-r--r--src/mail.cpp2
-rw-r--r--src/messages.cpp4
-rw-r--r--src/modes.cpp45
-rw-r--r--src/protocol.cpp111
-rw-r--r--src/servers.cpp4
-rw-r--r--src/uplink.cpp35
-rw-r--r--src/users.cpp59
10 files changed, 136 insertions, 146 deletions
diff --git a/src/bots.cpp b/src/bots.cpp
index 315045b86..ddffe53fe 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -38,7 +38,7 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A
{
Anope::string tmodes = !this->botmodes.empty() ? ("+" + this->botmodes) : (IRCD ? IRCD->DefaultPseudoclientModes : "");
if (!tmodes.empty())
- this->SetModesInternal(tmodes.c_str());
+ this->SetModesInternal(this, tmodes.c_str());
XLine x(this->nick, "Reserved for services");
IRCD->SendSQLine(NULL, &x);
diff --git a/src/channels.cpp b/src/channels.cpp
index 58083df00..84e90792d 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -24,6 +24,7 @@
#include "access.h"
#include "sockets.h"
#include "language.h"
+#include "uplink.h"
channel_map ChannelList;
@@ -681,7 +682,7 @@ bool Channel::MatchesList(User *u, const Anope::string &mode)
return false;
}
-void Channel::KickInternal(MessageSource &source, const Anope::string &nick, const Anope::string &reason)
+void Channel::KickInternal(const MessageSource &source, const Anope::string &nick, const Anope::string &reason)
{
User *sender = source.GetUser();
User *target = User::Find(nick);
@@ -737,8 +738,7 @@ bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...)
if (MOD_RESULT == EVENT_STOP)
return false;
IRCD->SendKick(bi, this, u, "%s", buf);
- MessageSource ms(bi);
- this->KickInternal(ms, u->nick, buf);
+ this->KickInternal(bi, u->nick, buf);
return true;
}
diff --git a/src/logger.cpp b/src/logger.cpp
index cd2dbd504..dca46f6d8 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -75,11 +75,11 @@ const Anope::string &LogFile::GetName() const
return this->filename;
}
-Log::Log(LogType t, const Anope::string &cat, const BotInfo *b) : bi(b), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), type(t), category(cat)
+Log::Log(LogType t, const Anope::string &cat, BotInfo *b) : bi(b), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), type(t), category(cat)
{
}
-Log::Log(LogType t, CommandSource &src, Command *_c, const ChannelInfo *_ci) : u(src.GetUser()), nc(src.nc), c(_c), source(&src), chan(NULL), ci(_ci), s(NULL), m(NULL), type(t)
+Log::Log(LogType t, CommandSource &src, Command *_c, ChannelInfo *_ci) : u(src.GetUser()), nc(src.nc), c(_c), source(&src), chan(NULL), ci(_ci), s(NULL), m(NULL), type(t)
{
if (!c)
throw CoreException("Invalid pointers passed to Log::Log");
@@ -94,25 +94,25 @@ Log::Log(LogType t, CommandSource &src, Command *_c, const ChannelInfo *_ci) : u
this->category = c->name;
}
-Log::Log(const User *_u, Channel *ch, const Anope::string &cat) : bi(NULL), u(_u), nc(NULL), c(NULL), source(NULL), chan(ch), ci(chan ? *chan->ci : NULL), s(NULL), m(NULL), type(LOG_CHANNEL), category(cat)
+Log::Log(User *_u, Channel *ch, const Anope::string &cat) : bi(NULL), u(_u), nc(NULL), c(NULL), source(NULL), chan(ch), ci(chan ? *chan->ci : NULL), s(NULL), m(NULL), type(LOG_CHANNEL), category(cat)
{
if (!chan)
throw CoreException("Invalid pointers passed to Log::Log");
}
-Log::Log(const User *_u, const Anope::string &cat, const BotInfo *_bi) : bi(_bi), u(_u), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(LOG_USER), category(cat)
+Log::Log(User *_u, const Anope::string &cat, BotInfo *_bi) : bi(_bi), u(_u), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(LOG_USER), category(cat)
{
if (!u)
throw CoreException("Invalid pointers passed to Log::Log");
}
-Log::Log(Server *serv, const Anope::string &cat, const BotInfo *_bi) : bi(_bi), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(serv), m(NULL), type(LOG_SERVER), category(cat)
+Log::Log(Server *serv, const Anope::string &cat, BotInfo *_bi) : bi(_bi), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(serv), m(NULL), type(LOG_SERVER), category(cat)
{
if (!s)
throw CoreException("Invalid pointer passed to Log::Log");
}
-Log::Log(const BotInfo *b, const Anope::string &cat) : bi(b), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(LOG_NORMAL), category(cat)
+Log::Log(BotInfo *b, const Anope::string &cat) : bi(b), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(LOG_NORMAL), category(cat)
{
}
@@ -362,7 +362,7 @@ void LogInfo::ProcessMessage(const Log *l)
if (!c)
continue;
- const BotInfo *bi = l->bi;
+ BotInfo *bi = l->bi;
if (!bi)
bi = this->bot;
if (!bi)
diff --git a/src/mail.cpp b/src/mail.cpp
index d52089a7a..7b30b7403 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -51,7 +51,7 @@ void Mail::Message::Run()
SetExitState();
}
-bool Mail::Send(User *u, NickCore *nc, const BotInfo *service, const Anope::string &subject, const Anope::string &message)
+bool Mail::Send(User *u, NickCore *nc, BotInfo *service, const Anope::string &subject, const Anope::string &message)
{
if (!nc || !service || subject.empty() || message.empty())
return false;
diff --git a/src/messages.cpp b/src/messages.cpp
index a41cd6ba3..b5332f716 100644
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -216,7 +216,7 @@ void Message::Mode::Run(MessageSource &source, const std::vector<Anope::string>
User *u = User::Find(params[0]);
if (u)
- u->SetModesInternal("%s", params[1].c_str());
+ u->SetModesInternal(source, "%s", params[1].c_str());
}
}
@@ -318,7 +318,7 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> &param
}
else if (!IRCD->RequiresID && Config->UseStrictPrivmsg)
{
- const BotInfo *bi = BotInfo::Find(receiver);
+ BotInfo *bi = BotInfo::Find(receiver);
if (!bi)
return;
Log(LOG_DEBUG) << "Ignored PRIVMSG without @ from " << u->nick;
diff --git a/src/modes.cpp b/src/modes.cpp
index fc343c0d2..41c2ac663 100644
--- a/src/modes.cpp
+++ b/src/modes.cpp
@@ -13,6 +13,7 @@
#include "sockets.h"
#include "protocol.h"
#include "channels.h"
+#include "uplink.h"
struct StackerInfo;
@@ -40,7 +41,7 @@ struct StackerInfo
/* Modes to be deleted */
std::list<std::pair<Mode *, Anope::string> > DelModes;
/* Bot this is sent from */
- const BotInfo *bi;
+ BotInfo *bi;
StackerInfo() : bi(NULL) { }
@@ -116,11 +117,12 @@ Mode::~Mode()
{
}
-UserMode::UserMode(const Anope::string &un, char mch) : Mode(un, MC_USER, mch, MODE_REGULAR)
+bool Mode::CanSet(User *u) const
{
+ return true;
}
-UserMode::~UserMode()
+UserMode::UserMode(const Anope::string &un, char mch) : Mode(un, MC_USER, mch, MODE_REGULAR)
{
}
@@ -133,10 +135,6 @@ ChannelMode::ChannelMode(const Anope::string &cm, char mch) : Mode(cm, MC_CHANNE
{
}
-ChannelMode::~ChannelMode()
-{
-}
-
bool ChannelMode::CanSet(User *u) const
{
EventReturn MOD_RESULT;
@@ -149,53 +147,40 @@ ChannelModeList::ChannelModeList(const Anope::string &cm, char mch) : ChannelMod
this->type = MODE_LIST;
}
-ChannelModeList::~ChannelModeList()
-{
-}
-
ChannelModeParam::ChannelModeParam(const Anope::string &cm, char mch, bool ma) : ChannelMode(cm, mch), minus_no_arg(ma)
{
this->type = MODE_PARAM;
}
-ChannelModeParam::~ChannelModeParam()
-{
-}
-
ChannelModeStatus::ChannelModeStatus(const Anope::string &mname, char modeChar, char msymbol, short mlevel) : ChannelMode(mname, modeChar), symbol(msymbol), level(mlevel)
{
this->type = MODE_STATUS;
}
-ChannelModeStatus::~ChannelModeStatus()
+bool UserModeOperOnly::CanSet(User *u) const
{
+ return u && u->HasMode("OPER");
}
-bool ChannelModeKey::IsValid(const Anope::string &value) const
+bool UserModeNoone::CanSet(User *u) const
{
- if (!value.empty() && value.find(':') == Anope::string::npos && value.find(',') == Anope::string::npos)
- return true;
-
return false;
}
-bool ChannelModeAdmin::CanSet(User *u) const
+bool ChannelModeKey::IsValid(const Anope::string &value) const
{
- if (u && u->HasMode("OPER"))
+ if (!value.empty() && value.find(':') == Anope::string::npos && value.find(',') == Anope::string::npos)
return true;
return false;
}
-bool ChannelModeOper::CanSet(User *u) const
+bool ChannelModeOperOnly::CanSet(User *u) const
{
- if (u && u->HasMode("OPER"))
- return true;
-
- return false;
+ return u && u->HasMode("OPER");
}
-bool ChannelModeRegistered::CanSet(User *u) const
+bool ChannelModeNoone::CanSet(User *u) const
{
return false;
}
@@ -526,7 +511,7 @@ void ModeManager::RebuildStatusModes()
std::sort(ChannelModesByStatus.begin(), ChannelModesByStatus.end(), statuscmp);
}
-void ModeManager::StackerAdd(const BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param)
+void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param)
{
StackerInfo *s = GetInfo(ChannelStackerObjects, c);
s->AddMode(cm, Set, Param);
@@ -540,7 +525,7 @@ void ModeManager::StackerAdd(const BotInfo *bi, Channel *c, ChannelMode *cm, boo
modePipe->Notify();
}
-void ModeManager::StackerAdd(const BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param)
+void ModeManager::StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param)
{
StackerInfo *s = GetInfo(UserStackerObjects, u);
s->AddMode(um, Set, Param);
diff --git a/src/protocol.cpp b/src/protocol.cpp
index b5ee8da3f..9ece3b529 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -44,40 +44,40 @@ const Anope::string &IRCDProto::GetProtocolName()
return this->proto_name;
}
-void IRCDProto::SendSVSKillInternal(const BotInfo *source, User *user, const Anope::string &buf)
+void IRCDProto::SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf)
{
UplinkSocket::Message(source) << "KILL " << user->GetUID() << " :" << buf;
}
-void IRCDProto::SendModeInternal(const BotInfo *bi, const Channel *dest, const Anope::string &buf)
+void IRCDProto::SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf)
{
- UplinkSocket::Message(bi) << "MODE " << dest->name << " " << buf;
+ UplinkSocket::Message(source) << "MODE " << dest->name << " " << buf;
}
-void IRCDProto::SendModeInternal(const BotInfo *bi, const User *dest, const Anope::string &buf)
+void IRCDProto::SendModeInternal(const MessageSource &source, User *dest, const Anope::string &buf)
{
- UplinkSocket::Message(bi) << "MODE " << dest->GetUID() << " " << buf;
+ UplinkSocket::Message(source) << "MODE " << dest->GetUID() << " " << buf;
}
-void IRCDProto::SendKickInternal(const BotInfo *bi, const Channel *c, const User *u, const Anope::string &r)
+void IRCDProto::SendKickInternal(const MessageSource &source, const Channel *c, User *u, const Anope::string &r)
{
if (!r.empty())
- UplinkSocket::Message(bi) << "KICK " << c->name << " " << u->GetUID() << " :" << r;
+ UplinkSocket::Message(source) << "KICK " << c->name << " " << u->GetUID() << " :" << r;
else
- UplinkSocket::Message(bi) << "KICK " << c->name << " " << u->GetUID();
+ UplinkSocket::Message(source) << "KICK " << c->name << " " << u->GetUID();
}
-void IRCDProto::SendNoticeInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &msg)
+void IRCDProto::SendNoticeInternal(const MessageSource &source, const Anope::string &dest, const Anope::string &msg)
{
- UplinkSocket::Message(bi) << "NOTICE " << dest << " :" << msg;
+ UplinkSocket::Message(source) << "NOTICE " << dest << " :" << msg;
}
-void IRCDProto::SendPrivmsgInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf)
+void IRCDProto::SendPrivmsgInternal(const MessageSource &source, const Anope::string &dest, const Anope::string &buf)
{
- UplinkSocket::Message(bi) << "PRIVMSG " << dest << " :" << buf;
+ UplinkSocket::Message(source) << "PRIVMSG " << dest << " :" << buf;
}
-void IRCDProto::SendQuitInternal(const User *u, const Anope::string &buf)
+void IRCDProto::SendQuitInternal(User *u, const Anope::string &buf)
{
if (!buf.empty())
UplinkSocket::Message(u) << "QUIT :" << buf;
@@ -85,26 +85,23 @@ void IRCDProto::SendQuitInternal(const User *u, const Anope::string &buf)
UplinkSocket::Message(u) << "QUIT";
}
-void IRCDProto::SendPartInternal(const BotInfo *bi, const Channel *chan, const Anope::string &buf)
+void IRCDProto::SendPartInternal(User *u, const Channel *chan, const Anope::string &buf)
{
if (!buf.empty())
- UplinkSocket::Message(bi) << "PART " << chan->name << " :" << buf;
+ UplinkSocket::Message(u) << "PART " << chan->name << " :" << buf;
else
- UplinkSocket::Message(bi) << "PART " << chan->name;
+ UplinkSocket::Message(u) << "PART " << chan->name;
}
-void IRCDProto::SendGlobopsInternal(const BotInfo *source, const Anope::string &buf)
+void IRCDProto::SendGlobopsInternal(const MessageSource &source, const Anope::string &buf)
{
- if (source)
- UplinkSocket::Message(source) << "GLOBOPS :" << buf;
- else
- UplinkSocket::Message(Me) << "GLOBOPS :" << buf;
+ UplinkSocket::Message(source) << "GLOBOPS :" << buf;
}
-void IRCDProto::SendCTCPInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf)
+void IRCDProto::SendCTCPInternal(const MessageSource &source, const Anope::string &dest, const Anope::string &buf)
{
Anope::string s = Anope::NormalizeBuffer(buf);
- this->SendNoticeInternal(bi, dest, "\1" + s + "\1");
+ this->SendNoticeInternal(source, dest, "\1" + s + "\1");
}
void IRCDProto::SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf)
@@ -117,12 +114,12 @@ void IRCDProto::SendNumericInternal(int numeric, const Anope::string &dest, cons
UplinkSocket::Message(Me) << n << " " << dest << " " << buf;
}
-void IRCDProto::SendTopic(BotInfo *bi, Channel *c)
+void IRCDProto::SendTopic(const MessageSource &source, Channel *c)
{
- UplinkSocket::Message(bi) << "TOPIC " << c->name << " :" << c->topic;
+ UplinkSocket::Message(source) << "TOPIC " << c->name << " :" << c->topic;
}
-void IRCDProto::SendSVSKill(const BotInfo *source, User *user, const char *fmt, ...)
+void IRCDProto::SendSVSKill(const MessageSource &source, User *user, const char *fmt, ...)
{
if (!user || !fmt)
return;
@@ -135,29 +132,29 @@ void IRCDProto::SendSVSKill(const BotInfo *source, User *user, const char *fmt,
SendSVSKillInternal(source, user, buf);
}
-void IRCDProto::SendMode(const BotInfo *bi, const Channel *dest, const char *fmt, ...)
+void IRCDProto::SendMode(const MessageSource &source, const Channel *dest, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
va_start(args, fmt);
vsnprintf(buf, BUFSIZE - 1, fmt, args);
va_end(args);
- SendModeInternal(bi, dest, buf);
+ SendModeInternal(source, dest, buf);
}
-void IRCDProto::SendMode(const BotInfo *bi, const User *u, const char *fmt, ...)
+void IRCDProto::SendMode(const MessageSource &source, User *u, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
va_start(args, fmt);
vsnprintf(buf, BUFSIZE - 1, fmt, args);
va_end(args);
- SendModeInternal(bi, u, buf);
+ SendModeInternal(source, u, buf);
}
-void IRCDProto::SendKick(const BotInfo *bi, const Channel *chan, const User *user, const char *fmt, ...)
+void IRCDProto::SendKick(const MessageSource &source, const Channel *chan, User *user, const char *fmt, ...)
{
- if (!bi || !chan || !user)
+ if (!chan || !user)
return;
va_list args;
@@ -165,20 +162,20 @@ void IRCDProto::SendKick(const BotInfo *bi, const Channel *chan, const User *use
va_start(args, fmt);
vsnprintf(buf, BUFSIZE - 1, fmt, args);
va_end(args);
- SendKickInternal(bi, chan, user, buf);
+ SendKickInternal(source, chan, user, buf);
}
-void IRCDProto::SendNotice(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...)
+void IRCDProto::SendNotice(const MessageSource &source, const Anope::string &dest, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
va_start(args, fmt);
vsnprintf(buf, BUFSIZE - 1, fmt, args);
va_end(args);
- SendNoticeInternal(bi, dest, buf);
+ SendNoticeInternal(source, dest, buf);
}
-void IRCDProto::SendAction(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...)
+void IRCDProto::SendAction(const MessageSource &source, const Anope::string &dest, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
@@ -186,20 +183,20 @@ void IRCDProto::SendAction(const BotInfo *bi, const Anope::string &dest, const c
vsnprintf(buf, BUFSIZE - 1, fmt, args);
va_end(args);
Anope::string actionbuf = Anope::string("\1ACTION ") + buf + '\1';
- SendPrivmsgInternal(bi, dest, actionbuf);
+ SendPrivmsgInternal(source, dest, actionbuf);
}
-void IRCDProto::SendPrivmsg(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...)
+void IRCDProto::SendPrivmsg(const MessageSource &source, const Anope::string &dest, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
va_start(args, fmt);
vsnprintf(buf, BUFSIZE - 1, fmt, args);
va_end(args);
- SendPrivmsgInternal(bi, dest, buf);
+ SendPrivmsgInternal(source, dest, buf);
}
-void IRCDProto::SendQuit(const User *u, const char *fmt, ...)
+void IRCDProto::SendQuit(User *u, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
@@ -231,12 +228,12 @@ void IRCDProto::SendPong(const Anope::string &servname, const Anope::string &who
UplinkSocket::Message(Me) << "PONG " << servname << " " << who;
}
-void IRCDProto::SendInvite(const BotInfo *bi, const Channel *c, const User *u)
+void IRCDProto::SendInvite(const MessageSource &source, const Channel *c, User *u)
{
- UplinkSocket::Message(bi) << "INVITE " << u->GetUID() << " " << c->name;
+ UplinkSocket::Message(source) << "INVITE " << u->GetUID() << " " << c->name;
}
-void IRCDProto::SendPart(const BotInfo *bi, const Channel *chan, const char *fmt, ...)
+void IRCDProto::SendPart(User *user, const Channel *chan, const char *fmt, ...)
{
if (fmt)
{
@@ -245,13 +242,13 @@ void IRCDProto::SendPart(const BotInfo *bi, const Channel *chan, const char *fmt
va_start(args, fmt);
vsnprintf(buf, BUFSIZE - 1, fmt, args);
va_end(args);
- SendPartInternal(bi, chan, buf);
+ SendPartInternal(user, chan, buf);
}
else
- SendPartInternal(bi, chan, "");
+ SendPartInternal(user, chan, "");
}
-void IRCDProto::SendGlobops(const BotInfo *source, const char *fmt, ...)
+void IRCDProto::SendGlobops(const MessageSource &source, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
@@ -266,24 +263,24 @@ void IRCDProto::SendSquit(Server *s, const Anope::string &message)
UplinkSocket::Message() << "SQUIT " << s->GetSID() << " :" << message;
}
-void IRCDProto::SendNickChange(const User *u, const Anope::string &newnick)
+void IRCDProto::SendNickChange(User *u, const Anope::string &newnick)
{
UplinkSocket::Message(u) << "NICK " << newnick << " " << Anope::CurTime;
}
-void IRCDProto::SendForceNickChange(const User *u, const Anope::string &newnick, time_t when)
+void IRCDProto::SendForceNickChange(User *u, const Anope::string &newnick, time_t when)
{
UplinkSocket::Message() << "SVSNICK " << u->nick << " " << newnick << " " << when;
}
-void IRCDProto::SendCTCP(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...)
+void IRCDProto::SendCTCP(const MessageSource &source, const Anope::string &dest, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
va_start(args, fmt);
vsnprintf(buf, BUFSIZE - 1, fmt, args);
va_end(args);
- SendCTCPInternal(bi, dest, buf);
+ SendCTCPInternal(source, dest, buf);
}
void IRCDProto::SendNumeric(int numeric, const Anope::string &dest, const char *fmt, ...)
@@ -382,6 +379,7 @@ unsigned IRCDProto::GetMaxListFor(Channel *c)
MessageSource::MessageSource(const Anope::string &src) : source(src), u(NULL), s(NULL)
{
+ /* no source for incoming message is our uplink */
if (src.empty())
this->s = Servers::GetUplink();
else if (IRCD->RequiresID || src.find('.') != Anope::string::npos)
@@ -398,7 +396,7 @@ MessageSource::MessageSource(Server *_s) : source(_s ? _s->GetName() : ""), u(NU
{
}
-const Anope::string MessageSource::GetName()
+const Anope::string &MessageSource::GetName() const
{
if (this->s)
return this->s->GetName();
@@ -408,17 +406,22 @@ const Anope::string MessageSource::GetName()
return this->source;
}
-const Anope::string &MessageSource::GetSource()
+const Anope::string &MessageSource::GetSource() const
{
return this->source;
}
-User *MessageSource::GetUser()
+User *MessageSource::GetUser() const
{
return this->u;
}
-Server *MessageSource::GetServer()
+BotInfo *MessageSource::GetBot() const
+{
+ return BotInfo::Find(this->GetName(), true);
+}
+
+Server *MessageSource::GetServer() const
{
return this->s;
}
diff --git a/src/servers.cpp b/src/servers.cpp
index 77431eeab..c3ec328f9 100644
--- a/src/servers.cpp
+++ b/src/servers.cpp
@@ -53,7 +53,7 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano
BotInfo *bi = it->second;
Anope::string modes = !bi->botmodes.empty() ? ("+" + bi->botmodes) : IRCD->DefaultPseudoclientModes;
- bi->SetModesInternal(modes.c_str());
+ bi->SetModesInternal(bi, modes.c_str());
for (unsigned i = 0; i < bi->botchannels.size(); ++i)
{
size_t h = bi->botchannels[i].find('#');
@@ -297,7 +297,7 @@ bool Server::IsJuped() const
return juped;
}
-void Server::Notice(const BotInfo *source, const Anope::string &message)
+void Server::Notice(BotInfo *source, const Anope::string &message)
{
if (Config->UsePrivmsg && Config->DefPrivmsg)
IRCD->SendGlobalPrivmsg(source, this, message);
diff --git a/src/uplink.cpp b/src/uplink.cpp
index d29af3bea..b5439dda1 100644
--- a/src/uplink.cpp
+++ b/src/uplink.cpp
@@ -58,7 +58,6 @@ void Uplink::Connect()
UplinkSock->Connect(ip, u.port);
}
-
UplinkSocket::UplinkSocket() : Socket(-1, Config->Uplinks[Anope::CurrentUplink].ipv6), ConnectionSocket(), BufferedSocket()
{
UplinkSock = this;
@@ -142,50 +141,48 @@ void UplinkSocket::OnError(const Anope::string &error)
Log(LOG_TERMINAL) << "Unable to connect to uplink #" << (Anope::CurrentUplink + 1) << " (" << Config->Uplinks[Anope::CurrentUplink].host << ":" << Config->Uplinks[Anope::CurrentUplink].port << ")" << (!error.empty() ? (": " + error) : "");
}
-UplinkSocket::Message::Message() : server(NULL), user(NULL)
-{
-}
-
-UplinkSocket::Message::Message(const Server *s) : server(s), user(NULL)
+UplinkSocket::Message::Message() : source(Me)
{
}
-UplinkSocket::Message::Message(const User *u) : server(NULL), user(u)
+UplinkSocket::Message::Message(const MessageSource &src) : source(src)
{
- if (!u)
- server = Me;
}
UplinkSocket::Message::~Message()
{
- Anope::string message_source = "";
+ Anope::string message_source;
- if (this->server != NULL)
+ if (this->source.GetServer() != NULL)
{
- if (this->server != Me && !this->server->IsJuped())
+ const Server *s = this->source.GetServer();
+
+ if (s != Me && !s->IsJuped())
{
- Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << this->server->GetName() << " who is not from me?";
+ Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << s->GetName() << " who is not from me?";
return;
}
- message_source = this->server->GetSID();
+ message_source = s->GetSID();
}
- else if (this->user != NULL)
+ else if (this->source.GetUser() != NULL)
{
- if (this->user->server != Me && !this->user->server->IsJuped())
+ const User *u = this->source.GetUser();
+
+ if (u->server != Me && !u->server->IsJuped())
{
- Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << this->user->nick << " who is not from me?";
+ Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << u->nick << " who is not from me?";
return;
}
- const BotInfo *bi = BotInfo::Find(this->user->nick);
+ const BotInfo *bi = this->source.GetBot();
if (bi != NULL && bi->introduced == false)
{
Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << bi->nick << " when not introduced";
return;
}
- message_source = this->user->GetUID();
+ message_source = u->GetUID();
}
if (!UplinkSock)
diff --git a/src/users.cpp b/src/users.cpp
index c614a02ca..f44a6f62d 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -23,6 +23,7 @@
#include "opertype.h"
#include "language.h"
#include "sockets.h"
+#include "uplink.h"
user_map UserListByNick, UserListByUID;
@@ -52,7 +53,7 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope:
this->server = sserver;
this->realname = srealname;
this->timestamp = this->signon = ssignon;
- this->SetModesInternal("%s", smodes.c_str());
+ this->SetModesInternal(sserver, "%s", smodes.c_str());
this->uid = suid;
this->super_admin = false;
this->nc = NULL;
@@ -255,7 +256,7 @@ User::~User()
FOREACH_MOD(OnPostUserLogoff, (this));
}
-void User::SendMessage(const BotInfo *source, const char *fmt, ...)
+void User::SendMessage(BotInfo *source, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
@@ -270,7 +271,7 @@ void User::SendMessage(const BotInfo *source, const char *fmt, ...)
va_end(args);
}
-void User::SendMessage(const BotInfo *source, const Anope::string &msg)
+void User::SendMessage(BotInfo *source, const Anope::string &msg)
{
const char *translated_message = Language::Translate(this, msg.c_str());
@@ -453,55 +454,55 @@ bool User::HasMode(const Anope::string &mname) const
return this->modes.count(mname);
}
-void User::SetModeInternal(UserMode *um, const Anope::string &param)
+void User::SetModeInternal(const MessageSource &source, UserMode *um, const Anope::string &param)
{
if (!um)
return;
this->modes[um->name] = param;
- FOREACH_MOD(OnUserModeSet, (this, um->name));
+ FOREACH_MOD(OnUserModeSet, (source, this, um->name));
}
-void User::RemoveModeInternal(UserMode *um)
+void User::RemoveModeInternal(const MessageSource &source, UserMode *um)
{
if (!um)
return;
this->modes.erase(um->name);
- FOREACH_MOD(OnUserModeUnset, (this, um->name));
+ FOREACH_MOD(OnUserModeUnset, (source, this, um->name));
}
-void User::SetMode(const BotInfo *bi, UserMode *um, const Anope::string &Param)
+void User::SetMode(BotInfo *bi, UserMode *um, const Anope::string &param)
{
if (!um || HasMode(um->name))
return;
- ModeManager::StackerAdd(bi, this, um, true, Param);
- SetModeInternal(um, Param);
+ ModeManager::StackerAdd(bi, this, um, true, param);
+ SetModeInternal(bi, um, param);
}
-void User::SetMode(const BotInfo *bi, const Anope::string &uname, const Anope::string &Param)
+void User::SetMode(BotInfo *bi, const Anope::string &uname, const Anope::string &param)
{
- SetMode(bi, ModeManager::FindUserModeByName(uname), Param);
+ SetMode(bi, ModeManager::FindUserModeByName(uname), param);
}
-void User::RemoveMode(const BotInfo *bi, UserMode *um)
+void User::RemoveMode(BotInfo *bi, UserMode *um)
{
if (!um || !HasMode(um->name))
return;
ModeManager::StackerAdd(bi, this, um, false);
- RemoveModeInternal(um);
+ RemoveModeInternal(bi, um);
}
-void User::RemoveMode(const BotInfo *bi, const Anope::string &name)
+void User::RemoveMode(BotInfo *bi, const Anope::string &name)
{
RemoveMode(bi, ModeManager::FindUserModeByName(name));
}
-void User::SetModes(const BotInfo *bi, const char *umodes, ...)
+void User::SetModes(BotInfo *bi, const char *umodes, ...)
{
char buf[BUFSIZE] = "";
va_list args;
@@ -545,7 +546,7 @@ void User::SetModes(const BotInfo *bi, const char *umodes, ...)
}
}
-void User::SetModesInternal(const char *umodes, ...)
+void User::SetModesInternal(const MessageSource &source, const char *umodes, ...)
{
char buf[BUFSIZE] = "";
va_list args;
@@ -583,12 +584,12 @@ void User::SetModesInternal(const char *umodes, ...)
if (add)
{
if (um->type == MODE_PARAM && sep.GetToken(sbuf))
- this->SetModeInternal(um, sbuf);
+ this->SetModeInternal(source, um, sbuf);
else
- this->SetModeInternal(um);
+ this->SetModeInternal(source, um);
}
else
- this->RemoveModeInternal(um);
+ this->RemoveModeInternal(source, um);
if (um->name == "OPER")
{
@@ -610,8 +611,7 @@ Anope::string User::GetModes() const
{
Anope::string m, params;
- typedef std::map<Anope::string, Anope::string> mode_map;
- for (mode_map::const_iterator it = this->modes.begin(), it_end = this->modes.end(); it != it_end; ++it)
+ for (ModeList::const_iterator it = this->modes.begin(), it_end = this->modes.end(); it != it_end; ++it)
{
UserMode *um = ModeManager::FindUserModeByName(it->first);
if (um == NULL)
@@ -626,6 +626,11 @@ Anope::string User::GetModes() const
return m + params;
}
+const User::ModeList &User::GetModeList() const
+{
+ return modes;
+}
+
ChanUserContainer *User::FindChannel(Channel *c) const
{
User::ChanUserList::const_iterator it = this->chans.find(c);
@@ -642,14 +647,14 @@ bool User::IsProtected() const
return false;
}
-void User::Kill(const Anope::string &source, const Anope::string &reason)
+void User::Kill(const MessageSource &source, const Anope::string &reason)
{
- Anope::string real_reason = (source.empty() ? Me->GetName() : source) + " (" + reason + ")";
+ Anope::string real_reason = source.GetName() + " (" + reason + ")";
- IRCD->SendSVSKill(BotInfo::Find(source), this, "%s", real_reason.c_str());
+ IRCD->SendSVSKill(source, this, "%s", real_reason.c_str());
}
-void User::KillInternal(const Anope::string &source, const Anope::string &reason)
+void User::KillInternal(const MessageSource &source, const Anope::string &reason)
{
if (this->quit)
{
@@ -657,7 +662,7 @@ void User::KillInternal(const Anope::string &source, const Anope::string &reason
return;
}
- Log(this, "killed") << "was killed by " << source << " (Reason: " << reason << ")";
+ Log(this, "killed") << "was killed by " << source.GetName() << " (Reason: " << reason << ")";
this->Quit(reason);
}