summaryrefslogtreecommitdiff
path: root/src/coremods
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2014-06-22 13:20:21 +0200
committerAttila Molnar <attilamolnar@hush.com>2014-06-22 13:20:21 +0200
commit8670d8c51f1debd8afb6732e782fc61d2e479349 (patch)
tree874f0255cd45816afc6f67e90613ac86b1a95c46 /src/coremods
parent21a5f346135811e2d5d063121db1563e83d62960 (diff)
core_ison Extract duplicated code into a function
Change append(" ") to push_back(' ')
Diffstat (limited to 'src/coremods')
-rw-r--r--src/coremods/core_ison.cpp47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/coremods/core_ison.cpp b/src/coremods/core_ison.cpp
index 3edef8275..8c1c3d2f5 100644
--- a/src/coremods/core_ison.cpp
+++ b/src/coremods/core_ison.cpp
@@ -24,6 +24,14 @@
*/
class CommandIson : public Command
{
+ /** Helper function to append a nick to an ISON reply
+ * @param user User doing the /ISON
+ * @param toadd User to append to the ISON reply
+ * @param reply Reply string to append the nick to
+ * @param pos If the reply gets too long it is sent to the user and truncated from this position
+ */
+ static bool AddNick(User* user, User* toadd, std::string& reply, const std::string::size_type pos);
+
public:
/** Constructor for ison.
*/
@@ -38,6 +46,21 @@ class CommandIson : public Command
CmdResult Handle(const std::vector<std::string>& parameters, User *user);
};
+bool CommandIson::AddNick(User* user, User* toadd, std::string& reply, const std::string::size_type pos)
+{
+ if ((toadd) && (toadd->registered == REG_ALL))
+ {
+ reply.append(toadd->nick).push_back(' ');
+ if (reply.length() > 450)
+ {
+ user->WriteServ(reply);
+ reply.erase(pos);
+ }
+ return true;
+ }
+ return false;
+}
+
/** Handle /ISON
*/
CmdResult CommandIson::Handle (const std::vector<std::string>& parameters, User *user)
@@ -49,16 +72,7 @@ CmdResult CommandIson::Handle (const std::vector<std::string>& parameters, User
for (unsigned int i = 0; i < parameters.size(); i++)
{
u = ServerInstance->FindNickOnly(parameters[i]);
- if ((u) && (u->registered == REG_ALL))
- {
- reply.append(u->nick).append(" ");
- if (reply.length() > 450)
- {
- user->WriteServ(reply);
- reply.erase(pos);
- }
- }
- else
+ if (!AddNick(user, u, reply, pos))
{
if ((i == parameters.size() - 1) && (parameters[i].find(' ') != std::string::npos))
{
@@ -68,18 +82,7 @@ CmdResult CommandIson::Handle (const std::vector<std::string>& parameters, User
std::string item;
while (list.GetToken(item))
- {
- u = ServerInstance->FindNickOnly(item);
- if ((u) && (u->registered == REG_ALL))
- {
- reply.append(u->nick).append(" ");
- if (reply.length() > 450)
- {
- user->WriteServ(reply);
- reply.erase(pos);
- }
- }
- }
+ AddNick(user, ServerInstance->FindNickOnly(item), reply, pos);
}
}
}