summaryrefslogtreecommitdiff
path: root/src/users.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/users.cpp')
-rw-r--r--src/users.cpp47
1 files changed, 30 insertions, 17 deletions
diff --git a/src/users.cpp b/src/users.cpp
index fd4afbcef..f6cdcc769 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -348,7 +348,7 @@ void User::Oper(OperInfo* info)
ServerInstance->SNO->WriteToSnoMask('o',"%s (%s@%s) is now an IRC operator of type %s (using oper '%s')",
nick.c_str(), ident.c_str(), host.c_str(), oper->name.c_str(), opername.c_str());
- this->WriteNumeric(RPL_YOUAREOPER, ":You are now %s %s", strchr("aeiouAEIOU", oper->name[0]) ? "an" : "a", oper->name.c_str());
+ this->WriteNumeric(RPL_YOUAREOPER, InspIRCd::Format("You are now %s %s", strchr("aeiouAEIOU", oper->name[0]) ? "an" : "a", oper->name.c_str()));
ServerInstance->Logs->Log("OPER", LOG_DEFAULT, "%s opered as type: %s", GetFullRealHost().c_str(), oper->name.c_str());
ServerInstance->Users->all_opers.push_back(this);
@@ -524,12 +524,12 @@ void LocalUser::FullConnect()
if (quitting)
return;
- this->WriteNumeric(RPL_WELCOME, ":Welcome to the %s IRC Network %s", ServerInstance->Config->Network.c_str(), GetFullRealHost().c_str());
- this->WriteNumeric(RPL_YOURHOSTIS, ":Your host is %s, running version %s", ServerInstance->Config->ServerName.c_str(), INSPIRCD_BRANCH);
- this->WriteNumeric(RPL_SERVERCREATED, ":This server was created %s %s", __TIME__, __DATE__);
+ this->WriteNumeric(RPL_WELCOME, InspIRCd::Format("Welcome to the %s IRC Network %s", ServerInstance->Config->Network.c_str(), GetFullRealHost().c_str()));
+ this->WriteNumeric(RPL_YOURHOSTIS, InspIRCd::Format("Your host is %s, running version %s", ServerInstance->Config->ServerName.c_str(), INSPIRCD_BRANCH));
+ this->WriteNumeric(RPL_SERVERCREATED, InspIRCd::Format("This server was created %s %s", __TIME__, __DATE__));
const std::string& modelist = ServerInstance->Modes->GetModeListFor004Numeric();
- this->WriteNumeric(RPL_SERVERVERSION, "%s %s %s", ServerInstance->Config->ServerName.c_str(), INSPIRCD_BRANCH, modelist.c_str());
+ this->WriteNumeric(RPL_SERVERVERSION, ServerInstance->Config->ServerName, INSPIRCD_BRANCH, modelist);
ServerInstance->ISupport.SendTo(this);
@@ -615,7 +615,7 @@ bool User::ChangeNick(const std::string& newnick, time_t newts)
{
/* force the camper to their UUID, and ask them to re-send a NICK. */
InUse->WriteFrom(InUse, "NICK %s", InUse->uuid.c_str());
- InUse->WriteNumeric(ERR_NICKNAMEINUSE, "%s :Nickname overruled.", InUse->nick.c_str());
+ InUse->WriteNumeric(ERR_NICKNAMEINUSE, InUse->nick, "Nickname overruled.");
InUse->registered &= ~REG_NICK;
InUse->ChangeNick(InUse->uuid);
@@ -623,7 +623,7 @@ bool User::ChangeNick(const std::string& newnick, time_t newts)
else
{
/* No camping, tell the incoming user to stop trying to change nick ;p */
- this->WriteNumeric(ERR_NICKNAMEINUSE, "%s :Nickname is already in use.", newnick.c_str());
+ this->WriteNumeric(ERR_NICKNAMEINUSE, newnick, "Nickname is already in use.");
return false;
}
}
@@ -786,25 +786,32 @@ void User::WriteCommand(const char* command, const std::string& text)
this->WriteServ(command + (this->registered & REG_NICK ? " " + this->nick : " *") + " " + text);
}
-void User::WriteNumeric(unsigned int numeric, const char* text, ...)
+namespace
{
- std::string textbuffer;
- VAFORMAT(textbuffer, text, text);
- this->WriteNumeric(numeric, textbuffer);
+ std::string BuildNumeric(const std::string& source, User* targetuser, unsigned int num, const std::vector<std::string>& params)
+ {
+ const char* const target = (targetuser->registered & REG_NICK ? targetuser->nick.c_str() : "*");
+ std::string raw = InspIRCd::Format(":%s %03u %s", source.c_str(), num, target);
+ if (!params.empty())
+ {
+ for (std::vector<std::string>::const_iterator i = params.begin(); i != params.end()-1; ++i)
+ raw.append(1, ' ').append(*i);
+ raw.append(" :").append(params.back());
+ }
+ return raw;
+ }
}
-void User::WriteNumeric(unsigned int numeric, const std::string &text)
+void User::WriteNumeric(const Numeric::Numeric& numeric)
{
ModResult MOD_RESULT;
- FIRST_MOD_RESULT(OnNumeric, MOD_RESULT, (this, numeric, text));
+ FIRST_MOD_RESULT(OnNumeric, MOD_RESULT, (this, numeric));
if (MOD_RESULT == MOD_RES_DENY)
return;
- const std::string message = InspIRCd::Format(":%s %03u %s %s", ServerInstance->Config->ServerName.c_str(),
- numeric, this->registered & REG_NICK ? this->nick.c_str() : "*", text.c_str());
- this->Write(message);
+ this->Write(BuildNumeric(ServerInstance->Config->ServerName, this, numeric.GetNumeric(), numeric.GetParams()));
}
void User::WriteFrom(User *user, const std::string &text)
@@ -947,6 +954,12 @@ void User::SendText(const std::string& linePrefix, std::stringstream& textStream
SendText(linePrefix + line);
}
+void User::WriteRemoteNumeric(const Numeric::Numeric& numeric)
+{
+ const std::string& servername = (numeric.GetServer() ? numeric.GetServer()->GetName() : ServerInstance->Config->ServerName);
+ SendText(BuildNumeric(servername, this, numeric.GetNumeric(), numeric.GetParams()));
+}
+
/* return 0 or 1 depending if users u and u2 share one or more common channels
* (used by QUIT, NICK etc which arent channel specific notices)
*
@@ -1010,7 +1023,7 @@ bool User::ChangeDisplayedHost(const std::string& shost)
this->InvalidateCache();
if (IS_LOCAL(this))
- this->WriteNumeric(RPL_YOURDISPLAYEDHOST, "%s :is now your displayed host", this->dhost.c_str());
+ this->WriteNumeric(RPL_YOURDISPLAYEDHOST, this->dhost, "is now your displayed host");
return true;
}