summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorom <om@e03df62e-2008-0410-955e-edbf42e46eb7>2006-04-03 10:22:03 +0000
committerom <om@e03df62e-2008-0410-955e-edbf42e46eb7>2006-04-03 10:22:03 +0000
commite8ad4c8cb0d34aaeafd8ef5223b1dccdc752cc51 (patch)
tree2e925d66baa992594ae900378bb151044a155626
parente3ebbb9292c6ea0b84b90611b78108a085caed63 (diff)
split_clist will never send lines over 512 chars, also should be faster
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3804 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/commands.h2
-rw-r--r--src/commands.cpp37
2 files changed, 27 insertions, 12 deletions
diff --git a/include/commands.h b/include/commands.h
index 1981b1688..ff6365d78 100644
--- a/include/commands.h
+++ b/include/commands.h
@@ -35,7 +35,7 @@ bool host_matches_everyone(const std::string &mask, userrec* user);
bool ip_matches_everyone(const std::string &ip, userrec* user);
bool nick_matches_everyone(const std::string &nick, userrec* user);
int operstrcmp(char* data,char* input);
-void split_chlist(userrec* user, userrec* dest, std::string &cl);
+void split_chlist(userrec* user, userrec* dest, const std::string &cl);
/* XXX Serious WTFness XXX
*
diff --git a/src/commands.cpp b/src/commands.cpp
index aea43482f..1715a9ace 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -89,24 +89,39 @@ extern std::vector<userrec*> local_users;
extern userrec* fd_ref_table[MAX_DESCRIPTORS];
-void split_chlist(userrec* user, userrec* dest, std::string &cl)
+void split_chlist(userrec* user, userrec* dest, const std::string &cl)
{
- std::stringstream channels(cl);
- std::string line = "";
- std::string cname = "";
- while (!channels.eof())
+ std::string line;
+ std::ostringstream prefix;
+ std::string::size_type start, pos, length;
+
+ prefix << ":" << Config->ServerName << " 319 " << user->nick << " " << dest->nick << " :";
+ line = prefix.str();
+
+ for (start = 0; pos = cl.find(' ', start); start = pos+1)
{
- channels >> cname;
- line = line + cname + " ";
- if (line.length() > 400)
+ length = (pos == std::string::npos) ? cl.length() : pos;
+
+ if (line.length() + length - start > 510)
+ {
+ Write_NoFormat(user->fd, line.c_str());
+ line = prefix.str();
+ }
+
+ if(pos == std::string::npos)
{
- WriteServ(user->fd,"319 %s %s :%s",user->nick, dest->nick, line.c_str());
- line = "";
+ line += cl.substr(start, length - start);
+ break;
+ }
+ else
+ {
+ line += cl.substr(start, length - start + 1);
}
}
+
if (line.length())
{
- WriteServ(user->fd,"319 %s %s :%s",user->nick, dest->nick, line.c_str());
+ Write_NoFormat(user->fd, line.c_str());
}
}