From e8ad4c8cb0d34aaeafd8ef5223b1dccdc752cc51 Mon Sep 17 00:00:00 2001 From: om Date: Mon, 3 Apr 2006 10:22:03 +0000 Subject: 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 --- src/commands.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'src') 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 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()); } } -- cgit v1.2.3