diff options
author | Attila Molnar <attilamolnar@hush.com> | 2016-02-25 16:40:50 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2016-02-25 16:40:50 +0100 |
commit | dbe5a1fc6f9e18765863f332a3e79d7c918d3e65 (patch) | |
tree | eb53116004bf80b3621da7e654207e508377f9a2 /src | |
parent | ee7567584e4792166a4d6455ca306731d8b5f28a (diff) |
Add User::WriteRemoteNumeric() and switch code using SendText() to send numerics to it
Diffstat (limited to 'src')
-rw-r--r-- | src/coremods/core_info/cmd_admin.cpp | 12 | ||||
-rw-r--r-- | src/coremods/core_info/cmd_info.cpp | 4 | ||||
-rw-r--r-- | src/coremods/core_info/cmd_modules.cpp | 11 | ||||
-rw-r--r-- | src/coremods/core_info/cmd_motd.cpp | 10 | ||||
-rw-r--r-- | src/coremods/core_info/cmd_time.cpp | 3 | ||||
-rw-r--r-- | src/modules/m_callerid.cpp | 4 | ||||
-rw-r--r-- | src/modules/m_globalload.cpp | 5 | ||||
-rw-r--r-- | src/modules/m_nicklock.cpp | 6 | ||||
-rw-r--r-- | src/modules/m_opermotd.cpp | 9 | ||||
-rw-r--r-- | src/modules/m_showfile.cpp | 6 | ||||
-rw-r--r-- | src/modules/m_spanningtree/override_map.cpp | 11 | ||||
-rw-r--r-- | src/modules/m_uninvite.cpp | 13 | ||||
-rw-r--r-- | src/users.cpp | 6 |
13 files changed, 49 insertions, 51 deletions
diff --git a/src/coremods/core_info/cmd_admin.cpp b/src/coremods/core_info/cmd_admin.cpp index 722ef8668..19037406b 100644 --- a/src/coremods/core_info/cmd_admin.cpp +++ b/src/coremods/core_info/cmd_admin.cpp @@ -34,15 +34,11 @@ CmdResult CommandAdmin::Handle (const std::vector<std::string>& parameters, User { if (parameters.size() > 0 && parameters[0] != ServerInstance->Config->ServerName) return CMD_SUCCESS; - user->SendText(":%s %03d %s :Administrative info for %s", ServerInstance->Config->ServerName.c_str(), - RPL_ADMINME, user->nick.c_str(),ServerInstance->Config->ServerName.c_str()); + user->WriteRemoteNumeric(RPL_ADMINME, InspIRCd::Format("Administrative info for %s", ServerInstance->Config->ServerName.c_str())); if (!AdminName.empty()) - user->SendText(":%s %03d %s :Name - %s", ServerInstance->Config->ServerName.c_str(), - RPL_ADMINLOC1, user->nick.c_str(), AdminName.c_str()); - user->SendText(":%s %03d %s :Nickname - %s", ServerInstance->Config->ServerName.c_str(), - RPL_ADMINLOC2, user->nick.c_str(), AdminNick.c_str()); - user->SendText(":%s %03d %s :E-Mail - %s", ServerInstance->Config->ServerName.c_str(), - RPL_ADMINEMAIL, user->nick.c_str(), AdminEmail.c_str()); + user->WriteRemoteNumeric(RPL_ADMINLOC1, InspIRCd::Format("Name - %s", AdminName.c_str())); + user->WriteRemoteNumeric(RPL_ADMINLOC2, InspIRCd::Format("Nickname - %s", AdminNick.c_str())); + user->WriteRemoteNumeric(RPL_ADMINEMAIL, InspIRCd::Format("E-Mail - %s", AdminEmail.c_str())); return CMD_SUCCESS; } diff --git a/src/coremods/core_info/cmd_info.cpp b/src/coremods/core_info/cmd_info.cpp index 8dad99453..e014fa4f2 100644 --- a/src/coremods/core_info/cmd_info.cpp +++ b/src/coremods/core_info/cmd_info.cpp @@ -83,9 +83,9 @@ CmdResult CommandInfo::Handle (const std::vector<std::string>& parameters, User int i=0; while (lines[i]) - user->SendText(":%s %03d %s :%s", ServerInstance->Config->ServerName.c_str(), RPL_INFO, user->nick.c_str(), lines[i++]); + user->WriteRemoteNumeric(RPL_INFO, lines[i++]); FOREACH_MOD(OnInfo, (user)); - user->SendText(":%s %03d %s :End of /INFO list", ServerInstance->Config->ServerName.c_str(), RPL_ENDOFINFO, user->nick.c_str()); + user->WriteRemoteNumeric(RPL_ENDOFINFO, "End of /INFO list"); return CMD_SUCCESS; } diff --git a/src/coremods/core_info/cmd_modules.cpp b/src/coremods/core_info/cmd_modules.cpp index 0a1420e13..16931e685 100644 --- a/src/coremods/core_info/cmd_modules.cpp +++ b/src/coremods/core_info/cmd_modules.cpp @@ -65,21 +65,18 @@ CmdResult CommandModules::Handle (const std::vector<std::string>& parameters, Us flags[pos] = '-'; #ifdef PURE_STATIC - user->SendText(":%s 702 %s :%s %s :%s", ServerInstance->Config->ServerName.c_str(), - user->nick.c_str(), m->ModuleSourceFile.c_str(), flags.c_str(), V.description.c_str()); + user->WriteRemoteNumeric(702, InspIRCd::Format("%s %s :%s", m->ModuleSourceFile.c_str(), flags.c_str(), V.description.c_str())); #else std::string srcrev = m->ModuleDLLManager->GetVersion(); - user->SendText(":%s 702 %s :%s %s :%s - %s", ServerInstance->Config->ServerName.c_str(), - user->nick.c_str(), m->ModuleSourceFile.c_str(), flags.c_str(), V.description.c_str(), srcrev.c_str()); + user->WriteRemoteNumeric(702, InspIRCd::Format("%s %s :%s - %s", m->ModuleSourceFile.c_str(), flags.c_str(), V.description.c_str(), srcrev.c_str())); #endif } else { - user->SendText(":%s 702 %s :%s %s", ServerInstance->Config->ServerName.c_str(), - user->nick.c_str(), m->ModuleSourceFile.c_str(), V.description.c_str()); + user->WriteRemoteNumeric(702, InspIRCd::Format("%s %s", m->ModuleSourceFile.c_str(), V.description.c_str())); } } - user->SendText(":%s 703 %s :End of MODULES list", ServerInstance->Config->ServerName.c_str(), user->nick.c_str()); + user->WriteRemoteNumeric(703, "End of MODULES list"); return CMD_SUCCESS; } diff --git a/src/coremods/core_info/cmd_motd.cpp b/src/coremods/core_info/cmd_motd.cpp index 57616094e..4772f8d2c 100644 --- a/src/coremods/core_info/cmd_motd.cpp +++ b/src/coremods/core_info/cmd_motd.cpp @@ -48,18 +48,16 @@ CmdResult CommandMotd::Handle (const std::vector<std::string>& parameters, User ConfigFileCache::iterator motd = ServerInstance->Config->Files.find(motd_name); if (motd == ServerInstance->Config->Files.end()) { - user->SendText(":%s %03d %s :Message of the day file is missing.", - ServerInstance->Config->ServerName.c_str(), ERR_NOMOTD, user->nick.c_str()); + user->WriteRemoteNumeric(ERR_NOMOTD, "Message of the day file is missing."); return CMD_SUCCESS; } - user->SendText(":%s %03d %s :%s message of the day", ServerInstance->Config->ServerName.c_str(), - RPL_MOTDSTART, user->nick.c_str(), ServerInstance->Config->ServerName.c_str()); + user->WriteRemoteNumeric(RPL_MOTDSTART, InspIRCd::Format("%s message of the day", ServerInstance->Config->ServerName.c_str())); for (file_cache::iterator i = motd->second.begin(); i != motd->second.end(); i++) - user->SendText(":%s %03d %s :- %s", ServerInstance->Config->ServerName.c_str(), RPL_MOTD, user->nick.c_str(), i->c_str()); + user->WriteRemoteNumeric(RPL_MOTD, InspIRCd::Format("- %s", i->c_str())); - user->SendText(":%s %03d %s :End of message of the day.", ServerInstance->Config->ServerName.c_str(), RPL_ENDOFMOTD, user->nick.c_str()); + user->WriteRemoteNumeric(RPL_ENDOFMOTD, "End of message of the day."); return CMD_SUCCESS; } diff --git a/src/coremods/core_info/cmd_time.cpp b/src/coremods/core_info/cmd_time.cpp index 95cfb12fd..a0b58efcc 100644 --- a/src/coremods/core_info/cmd_time.cpp +++ b/src/coremods/core_info/cmd_time.cpp @@ -32,8 +32,7 @@ CmdResult CommandTime::Handle (const std::vector<std::string>& parameters, User if (parameters.size() > 0 && parameters[0] != ServerInstance->Config->ServerName) return CMD_SUCCESS; - user->SendText(":%s %03d %s %s :%s", ServerInstance->Config->ServerName.c_str(), RPL_TIME, user->nick.c_str(), - ServerInstance->Config->ServerName.c_str(), InspIRCd::TimeString(ServerInstance->Time()).c_str()); + user->WriteRemoteNumeric(RPL_TIME, ServerInstance->Config->ServerName, InspIRCd::TimeString(ServerInstance->Time())); return CMD_SUCCESS; } diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp index 149767f18..e11b326de 100644 --- a/src/modules/m_callerid.cpp +++ b/src/modules/m_callerid.cpp @@ -399,8 +399,8 @@ public: if (now > (dat->lastnotify + (time_t)notify_cooldown)) { user->WriteNumeric(RPL_TARGNOTIFY, dest->nick, "has been informed that you messaged them."); - dest->SendText(":%s %03d %s %s %s@%s :is messaging you, and you have umode +g. Use /ACCEPT +%s to allow.", - ServerInstance->Config->ServerName.c_str(), RPL_UMODEGMSG, dest->nick.c_str(), user->nick.c_str(), user->ident.c_str(), user->dhost.c_str(), user->nick.c_str()); + dest->WriteRemoteNumeric(RPL_UMODEGMSG, user->nick, InspIRCd::Format("%s@%s", user->ident.c_str(), user->dhost.c_str()), InspIRCd::Format("is messaging you, and you have umode +g. Use /ACCEPT +%s to allow.", + user->nick.c_str())); dat->lastnotify = now; } return MOD_RES_DENY; diff --git a/src/modules/m_globalload.cpp b/src/modules/m_globalload.cpp index 2355cc979..b71f29fcc 100644 --- a/src/modules/m_globalload.cpp +++ b/src/modules/m_globalload.cpp @@ -93,8 +93,7 @@ class CommandGunloadmodule : public Command if (ServerInstance->Modules->Unload(m)) { ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBALLY UNLOADED BY '%s'",parameters[0].c_str(), user->nick.c_str()); - user->SendText(":%s 973 %s %s :Module successfully unloaded.", - ServerInstance->Config->ServerName.c_str(), user->nick.c_str(), parameters[0].c_str()); + user->WriteRemoteNumeric(973, parameters[0], "Module successfully unloaded."); } else { @@ -102,7 +101,7 @@ class CommandGunloadmodule : public Command } } else - user->SendText(":%s %03d %s %s :No such module", ServerInstance->Config->ServerName.c_str(), ERR_CANTUNLOADMODULE, user->nick.c_str(), parameters[0].c_str()); + user->WriteRemoteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "No such module"); } else ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBAL UNLOAD BY '%s' (not unloaded here)",parameters[0].c_str(), user->nick.c_str()); diff --git a/src/modules/m_nicklock.cpp b/src/modules/m_nicklock.cpp index 634982d14..a517e95ac 100644 --- a/src/modules/m_nicklock.cpp +++ b/src/modules/m_nicklock.cpp @@ -114,13 +114,11 @@ class CommandNickunlock : public Command if (locked.set(target, 0)) { ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used NICKUNLOCK on "+target->nick); - user->SendText(":%s 945 %s %s :Nickname now unlocked.", - ServerInstance->Config->ServerName.c_str(),user->nick.c_str(),target->nick.c_str()); + user->WriteRemoteNumeric(945, target->nick, "Nickname now unlocked."); } else { - user->SendText(":%s 946 %s %s :This user's nickname is not locked.", - ServerInstance->Config->ServerName.c_str(),user->nick.c_str(),target->nick.c_str()); + user->WriteRemoteNumeric(946, target->nick, "This user's nickname is not locked."); return CMD_FAILURE; } } diff --git a/src/modules/m_opermotd.cpp b/src/modules/m_opermotd.cpp index bd1853d43..010f4ae58 100644 --- a/src/modules/m_opermotd.cpp +++ b/src/modules/m_opermotd.cpp @@ -50,21 +50,20 @@ class CommandOpermotd : public Command void ShowOperMOTD(User* user) { - const std::string& servername = ServerInstance->Config->ServerName; if (opermotd.empty()) { - user->SendText(":%s 455 %s :OPERMOTD file is missing", servername.c_str(), user->nick.c_str()); + user->WriteRemoteNumeric(455, "OPERMOTD file is missing"); return; } - user->SendText(":%s 375 %s :- IRC Operators Message of the Day", servername.c_str(), user->nick.c_str()); + user->WriteRemoteNumeric(375, "- IRC Operators Message of the Day"); for (file_cache::const_iterator i = opermotd.begin(); i != opermotd.end(); ++i) { - user->SendText(":%s 372 %s :- %s", servername.c_str(), user->nick.c_str(), i->c_str()); + user->WriteRemoteNumeric(372, InspIRCd::Format("- %s", i->c_str())); } - user->SendText(":%s 376 %s :- End of OPERMOTD", servername.c_str(), user->nick.c_str()); + user->WriteRemoteNumeric(376, "- End of OPERMOTD"); } }; diff --git a/src/modules/m_showfile.cpp b/src/modules/m_showfile.cpp index cb51c4387..9973bf2b6 100644 --- a/src/modules/m_showfile.cpp +++ b/src/modules/m_showfile.cpp @@ -48,12 +48,12 @@ class CommandShowFile : public Command if (method == SF_NUMERIC) { if (!introtext.empty()) - user->SendText(":%s %03d %s :%s %s", sn.c_str(), intronumeric, user->nick.c_str(), sn.c_str(), introtext.c_str()); + user->WriteRemoteNumeric(intronumeric, introtext); for (file_cache::const_iterator i = contents.begin(); i != contents.end(); ++i) - user->SendText(":%s %03d %s :- %s", sn.c_str(), textnumeric, user->nick.c_str(), i->c_str()); + user->WriteRemoteNumeric(textnumeric, InspIRCd::Format("- %s", i->c_str())); - user->SendText(":%s %03d %s :%s", sn.c_str(), endnumeric, user->nick.c_str(), endtext.c_str()); + user->WriteRemoteNumeric(endnumeric, endtext.c_str()); } else { diff --git a/src/modules/m_spanningtree/override_map.cpp b/src/modules/m_spanningtree/override_map.cpp index 7ae6c6b4a..660d738e9 100644 --- a/src/modules/m_spanningtree/override_map.cpp +++ b/src/modules/m_spanningtree/override_map.cpp @@ -199,17 +199,14 @@ CmdResult CommandMap::Handle(const std::vector<std::string>& parameters, User* u std::vector<std::string> map = GetMap(user, Utils->TreeRoot, max, 0); for (std::vector<std::string>::const_iterator i = map.begin(); i != map.end(); ++i) - user->SendText(":%s %03d %s :%s", ServerInstance->Config->ServerName.c_str(), - RPL_MAP, user->nick.c_str(), i->c_str()); + user->WriteRemoteNumeric(RPL_MAP, *i); size_t totusers = ServerInstance->Users->GetUsers().size(); float avg_users = (float) totusers / Utils->serverlist.size(); - user->SendText(":%s %03d %s :%u server%s and %u user%s, average %.2f users per server", - ServerInstance->Config->ServerName.c_str(), RPL_MAPUSERS, user->nick.c_str(), - (unsigned int)Utils->serverlist.size(), (Utils->serverlist.size() > 1 ? "s" : ""), (unsigned int)totusers, (totusers > 1 ? "s" : ""), avg_users); - user->SendText(":%s %03d %s :End of /MAP", ServerInstance->Config->ServerName.c_str(), - RPL_ENDMAP, user->nick.c_str()); + user->WriteRemoteNumeric(RPL_MAPUSERS, InspIRCd::Format("%u server%s and %u user%s, average %.2f users per server", + (unsigned int)Utils->serverlist.size(), (Utils->serverlist.size() > 1 ? "s" : ""), (unsigned int)totusers, (totusers > 1 ? "s" : ""), avg_users)); + user->WriteRemoteNumeric(RPL_ENDMAP, "End of /MAP"); return CMD_SUCCESS; } diff --git a/src/modules/m_uninvite.cpp b/src/modules/m_uninvite.cpp index 94f71d9c1..d3045eadc 100644 --- a/src/modules/m_uninvite.cpp +++ b/src/modules/m_uninvite.cpp @@ -77,13 +77,22 @@ class CommandUninvite : public Command LocalUser* lu = IS_LOCAL(u); if (lu) { + // XXX: The source of the numeric we send must be the server of the user doing the /UNINVITE, + // so they don't see where the target user is connected to if (!invapi->Remove(lu, c)) { - user->SendText(":%s 505 %s %s %s :Is not invited to channel %s", user->server->GetName().c_str(), user->nick.c_str(), u->nick.c_str(), c->name.c_str(), c->name.c_str()); + Numeric::Numeric n(505); + n.SetServer(user->server); + n.push(u->nick).push(c->name).push(InspIRCd::Format("Is not invited to channel %s", c->name.c_str())); + user->WriteRemoteNumeric(n); return CMD_FAILURE; } - user->SendText(":%s 494 %s %s %s :Uninvited", user->server->GetName().c_str(), user->nick.c_str(), c->name.c_str(), u->nick.c_str()); + Numeric::Numeric n(494); + n.SetServer(user->server); + n.push(c->name).push(u->nick).push("Uninvited"); + user->WriteRemoteNumeric(n); + lu->WriteNumeric(493, InspIRCd::Format("You were uninvited from %s by %s", c->name.c_str(), user->nick.c_str())); std::string msg = "*** " + user->nick + " uninvited " + u->nick + "."; diff --git a/src/users.cpp b/src/users.cpp index b6fbc38a0..f6cdcc769 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -954,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) * |