summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2014-05-21 08:50:40 -0400
committerAdam <Adam@anope.org>2014-05-21 08:50:40 -0400
commitf627a3bacd0d058e94260dac1555790cafd9a926 (patch)
tree4ba71bf94b44ba07abc627ba0c26f3b8b94da439 /src
parent5a1257b7f0b44ee3fd4639e5be288d160ceb5095 (diff)
Core prep for p10 stuff
Diffstat (limited to 'src')
-rw-r--r--src/bots.cpp36
-rw-r--r--src/config.cpp2
-rw-r--r--src/init.cpp2
-rw-r--r--src/logger.cpp2
-rw-r--r--src/messages.cpp14
-rw-r--r--src/process.cpp71
-rw-r--r--src/protocol.cpp49
-rw-r--r--src/regchannel.cpp2
-rw-r--r--src/servers.cpp49
-rw-r--r--src/uplink.cpp15
-rw-r--r--src/users.cpp17
11 files changed, 141 insertions, 118 deletions
diff --git a/src/bots.cpp b/src/bots.cpp
index 9ce918a91..16e6a1cf9 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -21,7 +21,7 @@
Serialize::Checker<botinfo_map> BotListByNick("BotInfo"), BotListByUID("BotInfo");
-BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", Servers::TS6_UID_Retrieve(), NULL), Serializable("BotInfo"), channels("ChannelInfo"), botmodes(bmodes)
+BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", IRCD ? IRCD->UID_Retrieve() : "", NULL), Serializable("BotInfo"), channels("ChannelInfo"), botmodes(bmodes)
{
this->lastmsg = this->created = Anope::CurTime;
this->introduced = false;
@@ -96,7 +96,7 @@ Serializable* BotInfo::Unserialize(Serializable *obj, Serialize::Data &data)
BotInfo *bi;
if (obj)
bi = anope_dynamic_static_cast<BotInfo *>(obj);
- else if (!(bi = BotInfo::Find(nick)))
+ else if (!(bi = BotInfo::Find(nick, true)))
bi = new BotInfo(nick, user, host, realname);
data["created"] >> bi->created;
@@ -118,7 +118,7 @@ void BotInfo::GenerateUID()
UserListByUID.erase(this->uid);
}
- this->uid = Servers::TS6_UID_Retrieve();
+ this->uid = IRCD->UID_Retrieve();
(*BotListByUID)[this->uid] = this;
UserListByUID[this->uid] = this;
}
@@ -215,9 +215,9 @@ void BotInfo::Part(Channel *c, const Anope::string &reason)
IRCD->SendPart(this, c, "%s", !reason.empty() ? reason.c_str() : "");
- FOREACH_MOD(OnPartChannel, (this, c, c->name, reason));
-
c->DeleteUser(this);
+
+ FOREACH_MOD(OnPartChannel, (this, c, c->name, reason));
}
void BotInfo::OnMessage(User *u, const Anope::string &message)
@@ -248,22 +248,28 @@ CommandInfo *BotInfo::GetCommand(const Anope::string &cname)
BotInfo* BotInfo::Find(const Anope::string &nick, bool nick_only)
{
- BotInfo *bi = NULL;
- if (!nick_only && isdigit(nick[0]) && IRCD->RequiresID)
+ if (!nick_only && IRCD != NULL && IRCD->RequiresID)
{
botinfo_map::iterator it = BotListByUID->find(nick);
if (it != BotListByUID->end())
- bi = it->second;
+ {
+ BotInfo *bi = it->second;
+ bi->QueueUpdate();
+ return bi;
+ }
+
+ if (IRCD->AmbiguousID)
+ return NULL;
}
- else
+
+ botinfo_map::iterator it = BotListByNick->find(nick);
+ if (it != BotListByNick->end())
{
- botinfo_map::iterator it = BotListByNick->find(nick);
- if (it != BotListByNick->end())
- bi = it->second;
+ BotInfo *bi = it->second;
+ bi->QueueUpdate();
+ return bi;
}
- if (bi)
- bi->QueueUpdate();
- return bi;
+ return NULL;
}
diff --git a/src/config.cpp b/src/config.cpp
index 110045786..3ce4251e7 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -394,7 +394,7 @@ Conf::Conf() : Block("")
LogInfo l(logage, rawio, debug);
- l.bot = BotInfo::Find(log->Get<const Anope::string>("bot", "Global"));
+ l.bot = BotInfo::Find(log->Get<const Anope::string>("bot", "Global"), true);
spacesepstream(log->Get<const Anope::string>("target")).GetTokens(l.targets);
spacesepstream(log->Get<const Anope::string>("source")).GetTokens(l.sources);
spacesepstream(log->Get<const Anope::string>("admin")).GetTokens(l.admin);
diff --git a/src/init.cpp b/src/init.cpp
index 07f847d70..da91e2fcf 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -527,7 +527,7 @@ void Anope::Init(int ac, char **av)
/* Auto assign sid if applicable */
if (IRCD->RequiresID)
{
- Anope::string sid = Servers::TS6_SID_Retrieve();
+ Anope::string sid = IRCD->SID_Retrieve();
if (Me->GetSID() == Me->GetName())
Me->SetSID(sid);
for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
diff --git a/src/logger.cpp b/src/logger.cpp
index 4297bcab0..977af0a5f 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -90,7 +90,7 @@ Log::Log(LogType t, CommandSource &src, Command *_c, ChannelInfo *_ci) : u(src.G
size_t sl = c->name.find('/');
this->bi = NULL;
if (sl != Anope::string::npos)
- this->bi = BotInfo::Find(c->name.substr(0, sl));
+ this->bi = BotInfo::Find(c->name.substr(0, sl), true);
this->category = c->name;
}
diff --git a/src/messages.cpp b/src/messages.cpp
index 8e92d19c2..d6fd99143 100644
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -208,19 +208,23 @@ void Kill::Run(MessageSource &source, const std::vector<Anope::string> &params)
void Message::Mode::Run(MessageSource &source, const std::vector<Anope::string> &params)
{
+ Anope::string buf;
+ for (unsigned i = 1; i < params.size(); ++i)
+ buf += " " + params[i];
+
if (IRCD->IsChannelValid(params[0]))
{
Channel *c = Channel::Find(params[0]);
if (c)
- c->SetModesInternal(source, params[1], 0);
+ c->SetModesInternal(source, buf.substr(1), 0);
}
else
{
User *u = User::Find(params[0]);
if (u)
- u->SetModesInternal(source, "%s", params[1].c_str());
+ u->SetModesInternal(source, "%s", buf.substr(1).c_str());
}
}
@@ -313,10 +317,12 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> &param
* us, and strip it off. */
Anope::string botname = receiver;
size_t s = receiver.find('@');
+ bool nick_only = false;
if (s != Anope::string::npos)
{
Anope::string servername(receiver.begin() + s + 1, receiver.end());
botname = botname.substr(0, s);
+ nick_only = true;
if (!servername.equals_ci(Me->GetName()))
return;
}
@@ -330,7 +336,7 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> &param
return;
}
- BotInfo *bi = BotInfo::Find(botname);
+ BotInfo *bi = BotInfo::Find(botname, nick_only);
if (bi)
{
@@ -469,7 +475,7 @@ void Whois::Run(MessageSource &source, const std::vector<Anope::string> &params)
if (u && u->server == Me)
{
- const BotInfo *bi = BotInfo::Find(u->nick);
+ const BotInfo *bi = BotInfo::Find(u->GetUID());
IRCD->SendNumeric(311, source.GetSource(), "%s %s %s * :%s", u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str(), u->realname.c_str());
if (bi)
IRCD->SendNumeric(307, source.GetSource(), "%s :is a registered nick", bi->nick.c_str());
diff --git a/src/process.cpp b/src/process.cpp
index 16373b144..2d7a1561a 100644
--- a/src/process.cpp
+++ b/src/process.cpp
@@ -24,34 +24,10 @@ void Anope::Process(const Anope::string &buffer)
if (buffer.empty())
return;
- spacesepstream buf_sep(buffer);
-
- Anope::string source;
- if (buffer[0] == ':')
- {
- buf_sep.GetToken(source);
- source.erase(0, 1);
- }
-
- Anope::string command;
- if (!buf_sep.GetToken(command))
- return;
-
- Anope::string buf_token;
+ Anope::string source, command;
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);
- }
+
+ IRCD->Parse(buffer, source, command, params);
if (Anope::ProtocolDebug)
{
@@ -65,6 +41,12 @@ void Anope::Process(const Anope::string &buffer)
Log() << "params " << i << ": " << params[i];
}
+ if (command.empty())
+ {
+ Log(LOG_DEBUG) << "No command? " << buffer;
+ return;
+ }
+
static const Anope::string proto_name = ModuleManager::FindFirstOf(PROTOCOL) ? ModuleManager::FindFirstOf(PROTOCOL)->name : "";
MessageSource src(source);
@@ -91,3 +73,38 @@ void Anope::Process(const Anope::string &buffer)
m->Run(src, params);
}
+void IRCDProto::Parse(const Anope::string &buffer, Anope::string &source, Anope::string &command, std::vector<Anope::string> &params)
+{
+ spacesepstream sep(buffer);
+
+ if (buffer[0] == ':')
+ {
+ sep.GetToken(source);
+ source.erase(0, 1);
+ }
+
+ sep.GetToken(command);
+
+ for (Anope::string token; sep.GetToken(token);)
+ {
+ if (token[0] == ':')
+ {
+ if (!sep.StreamEnd())
+ params.push_back(token.substr(1) + " " + sep.GetRemaining());
+ else
+ params.push_back(token.substr(1));
+ break;
+ }
+ else
+ params.push_back(token);
+ }
+}
+
+Anope::string IRCDProto::Format(const Anope::string &source, const Anope::string &message)
+{
+ if (!source.empty())
+ return ":" + source + " " + message;
+ else
+ return message;
+}
+
diff --git a/src/protocol.cpp b/src/protocol.cpp
index a32f521f2..17b43e292 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -26,7 +26,7 @@ IRCDProto::IRCDProto(Module *creator, const Anope::string &p) : Service(creator,
{
DefaultPseudoclientModes = "+io";
CanSVSNick = CanSVSJoin = CanSetVHost = CanSetVIdent = CanSNLine = CanSQLine = CanSQLineChannel
- = CanSZLine = CanSVSHold = CanSVSO = CanCertFP = RequiresID = false;
+ = CanSZLine = CanSVSHold = CanSVSO = CanCertFP = RequiresID = AmbiguousID = false;
MaxModes = 3;
MaxLine = 512;
@@ -45,6 +45,53 @@ const Anope::string &IRCDProto::GetProtocolName()
return this->proto_name;
}
+static inline char& nextID(char &c)
+{
+ if (c == 'Z')
+ c = '0';
+ else if (c != '9')
+ ++c;
+ else
+ c = 'A';
+ return c;
+}
+
+Anope::string IRCDProto::UID_Retrieve()
+{
+ if (!IRCD || !IRCD->RequiresID)
+ return "";
+
+ static Anope::string current_uid = "AAAAAA";
+
+ do
+ {
+ int current_len = current_uid.length() - 1;
+ while (current_len >= 0 && nextID(current_uid[current_len--]) == 'A');
+ }
+ while (User::Find(Me->GetSID() + current_uid) != NULL);
+
+ return Me->GetSID() + current_uid;
+}
+
+Anope::string IRCDProto::SID_Retrieve()
+{
+ if (!IRCD || !IRCD->RequiresID)
+ return "";
+
+ static Anope::string current_sid = Config->GetBlock("serverinfo")->Get<const Anope::string>("id");
+ if (current_sid.empty())
+ current_sid = "00A";
+
+ do
+ {
+ int current_len = current_sid.length() - 1;
+ while (current_len >= 0 && nextID(current_sid[current_len--]) == 'A');
+ }
+ while (Server::Find(current_sid) != NULL);
+
+ return current_sid;
+}
+
void IRCDProto::SendKill(const MessageSource &source, const Anope::string &target, const Anope::string &reason)
{
UplinkSocket::Message(source) << "KILL " << target << " :" << reason;
diff --git a/src/regchannel.cpp b/src/regchannel.cpp
index 7e0ce300c..5c00e291a 100644
--- a/src/regchannel.cpp
+++ b/src/regchannel.cpp
@@ -271,7 +271,7 @@ Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data)
}
catch (const ConvertException &) { }
}
- BotInfo *bi = BotInfo::Find(sbi);
+ BotInfo *bi = BotInfo::Find(sbi, true);
if (*ci->bi != bi)
{
if (bi)
diff --git a/src/servers.cpp b/src/servers.cpp
index e1b66baa8..3427c2beb 100644
--- a/src/servers.cpp
+++ b/src/servers.cpp
@@ -95,7 +95,7 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano
{
User *u = it->second;
- BotInfo *bi = BotInfo::Find(u->nick);
+ BotInfo *bi = BotInfo::Find(u->GetUID());
if (bi)
{
XLine x(bi->nick, "Reserved for services");
@@ -352,53 +352,6 @@ Server *Server::Find(const Anope::string &name, bool name_only)
return NULL;
}
-static inline char& nextID(char &c)
-{
- if (c == 'Z')
- c = '0';
- else if (c != '9')
- ++c;
- else
- c = 'A';
- return c;
-}
-
-const Anope::string Servers::TS6_UID_Retrieve()
-{
- if (!IRCD || !IRCD->RequiresID)
- return "";
-
- static Anope::string current_uid = "AAAAAA";
-
- do
- {
- int current_len = current_uid.length() - 1;
- while (current_len >= 0 && nextID(current_uid[current_len--]) == 'A');
- }
- while (User::Find(Me->GetSID() + current_uid) != NULL);
-
- return Me->GetSID() + current_uid;
-}
-
-const Anope::string Servers::TS6_SID_Retrieve()
-{
- if (!IRCD || !IRCD->RequiresID)
- return "";
-
- static Anope::string current_sid = Config->GetBlock("serverinfo")->Get<const Anope::string>("id");
- if (current_sid.empty())
- current_sid = "00A";
-
- do
- {
- int current_len = current_sid.length() - 1;
- while (current_len >= 0 && nextID(current_sid[current_len--]) == 'A');
- }
- while (Server::Find(current_sid) != NULL);
-
- return current_sid;
-}
-
Server* Servers::GetUplink()
{
for (unsigned i = 0; Me && i < Me->GetLinks().size(); ++i)
diff --git a/src/uplink.cpp b/src/uplink.cpp
index 80727487a..549df85b3 100644
--- a/src/uplink.cpp
+++ b/src/uplink.cpp
@@ -77,7 +77,7 @@ UplinkSocket::~UplinkSocket()
{
/* Don't use quitmsg here, it may contain information you don't want people to see */
IRCD->SendQuit(u, "Shutting down");
- BotInfo* bi = BotInfo::Find(u->nick);
+ BotInfo* bi = BotInfo::Find(u->GetUID());
if (bi != NULL)
bi->introduced = false;
}
@@ -195,14 +195,7 @@ UplinkSocket::Message::~Message()
return;
}
- if (!message_source.empty())
- {
- UplinkSock->Write(":" + message_source + " " + this->buffer.str());
- Log(LOG_RAWIO) << "Sent: :" << message_source << " " << this->buffer.str();
- }
- else
- {
- UplinkSock->Write(this->buffer.str());
- Log(LOG_RAWIO) << "Sent: " << this->buffer.str();
- }
+ Anope::string sent = IRCD->Format(message_source, this->buffer.str());
+ UplinkSock->Write(sent);
+ Log(LOG_RAWIO) << "Sent: " << sent;
}
diff --git a/src/users.cpp b/src/users.cpp
index 8a4246e2f..2a04fca20 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -118,7 +118,7 @@ User* User::OnIntroduce(const Anope::string &snick, const Anope::string &sident,
// How IRCds handle collisions varies a lot, for safety well just always kill both sides
// With properly set qlines, this can almost never happen anyway
- User *u = User::Find(snick);
+ User *u = User::Find(snick, true);
if (u)
{
Collide(u, !suid.empty() ? suid : snick, "Nick collision");
@@ -814,18 +814,19 @@ bool User::BadPassword()
User* User::Find(const Anope::string &name, bool nick_only)
{
- if (!nick_only && isdigit(name[0]) && IRCD->RequiresID)
+ if (!nick_only && IRCD->RequiresID)
{
user_map::iterator it = UserListByUID.find(name);
if (it != UserListByUID.end())
return it->second;
+
+ if (IRCD->AmbiguousID)
+ return NULL;
}
- else
- {
- user_map::iterator it = UserListByNick.find(name);
- if (it != UserListByNick.end())
- return it->second;
- }
+
+ user_map::iterator it = UserListByNick.find(name);
+ if (it != UserListByNick.end())
+ return it->second;
return NULL;
}