From: brain Date: Wed, 9 Aug 2006 19:56:08 +0000 (+0000) Subject: Move more stuff into userrec X-Git-Tag: v2.0.23~7479 X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=e2b1ad588d34c3d1d0e4e330acef7ca177b13daf;p=user%2Fhenk%2Fcode%2Finspircd.git Move more stuff into userrec git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4823 e03df62e-2008-0410-955e-edbf42e46eb7 --- diff --git a/include/commands.h b/include/commands.h index 0a2e9fbd7..81e28fbaf 100644 --- a/include/commands.h +++ b/include/commands.h @@ -35,7 +35,6 @@ 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(const char* data,const char* input); -void split_chlist(userrec* user, userrec* dest, const std::string &cl); /* XXX Serious WTFness XXX * diff --git a/include/message.h b/include/message.h index f53f3d9d2..b1af53bbc 100644 --- a/include/message.h +++ b/include/message.h @@ -32,7 +32,6 @@ int isident(const char* n); int isnick(const char* n); const char* cmode(userrec *user, chanrec *chan); int cstatus(userrec *user, chanrec *chan); -std::string chlist(userrec *user, userrec* source); int cflags(userrec *user, chanrec *chan); #endif diff --git a/include/users.h b/include/users.h index d0ed021a6..1d8e918aa 100644 --- a/include/users.h +++ b/include/users.h @@ -646,6 +646,10 @@ class userrec : public connection void NoticeAll(char* text, ...); + std::string ChannelList(userrec* source); + + void SplitChanList(userrec* dest, const std::string &cl); + /** Default destructor */ virtual ~userrec(); diff --git a/src/cmd_whois.cpp b/src/cmd_whois.cpp index 600751585..5f980750b 100644 --- a/src/cmd_whois.cpp +++ b/src/cmd_whois.cpp @@ -50,12 +50,12 @@ void do_whois(userrec* user, userrec* dest,unsigned long signon, unsigned long i { user->WriteServ("378 %s %s :is connecting from *@%s %s",user->nick, dest->nick, dest->host, dest->GetIPString()); } - std::string cl = chlist(dest,user); + std::string cl = dest->ChannelList(user); if (cl.length()) { if (cl.length() > 400) { - split_chlist(user,dest,cl); + user->SplitChanList(dest,cl); } else { diff --git a/src/message.cpp b/src/message.cpp index f2a41a59b..6d5941f7e 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -183,28 +183,3 @@ int cstatus(userrec *user, chanrec *chan) return STATUS_NORMAL; } -std::string chlist(userrec *user,userrec* source) -{ - std::string list; - - if (!user || !source) - return ""; - - for (std::vector::const_iterator i = user->chans.begin(); i != user->chans.end(); i++) - { - ucrec* rec = *i; - - if(rec->channel && rec->channel->name) - { - /* If the target is the same as the sender, let them see all their channels. - * If the channel is NOT private/secret OR the user shares a common channel - * If the user is an oper, and the option is set. - */ - if ((source == user) || (*source->oper && ServerInstance->Config->OperSpyWhois) || (((!rec->channel->modes[CM_PRIVATE]) && (!rec->channel->modes[CM_SECRET])) || (rec->channel->HasUser(source)))) - { - list.append(cmode(user, rec->channel)).append(rec->channel->name).append(" "); - } - } - } - return list; -} diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index f697c4670..7dcb86d38 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -89,7 +89,7 @@ class cmd_check : public command_t user->WriteServ(checkstr + " onport " + ConvToStr(targuser->GetPort())); } - chliststr = chlist(targuser, targuser); + chliststr = targuser->ChannelList(targuser); std::stringstream dump(chliststr); Srv->DumpText(user,checkstr + " onchans ", dump); diff --git a/src/users.cpp b/src/users.cpp index 35aea8b0f..4dccb07f0 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -1651,3 +1651,63 @@ void userrec::NoticeAll(char* text, ...) } } + +std::string userrec::ChannelList(userrec* source) +{ + std::string list; + for (std::vector::const_iterator i = this->chans.begin(); i != this->chans.end(); i++) + { + ucrec* rec = *i; + + if(rec->channel && rec->channel->name) + { + /* If the target is the same as the sender, let them see all their channels. + * If the channel is NOT private/secret OR the user shares a common channel + * If the user is an oper, and the option is set. + */ + if ((source == this) || (*source->oper && ServerInstance->Config->OperSpyWhois) || (((!rec->channel->modes[CM_PRIVATE]) && (!rec->channel->modes[CM_SECRET])) || (rec->channel->HasUser(source)))) + { + list.append(cmode(this, rec->channel)).append(rec->channel->name).append(" "); + } + } + } + return list; +} + +void userrec::SplitChanList(userrec* dest, const std::string &cl) +{ + std::string line; + std::ostringstream prefix; + std::string::size_type start, pos, length; + + prefix << ":" << ServerInstance->Config->ServerName << " 319 " << this->nick << " " << dest->nick << " :"; + line = prefix.str(); + + for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1) + { + length = (pos == std::string::npos) ? cl.length() : pos; + + if (line.length() + length - start > 510) + { + this->Write(line); + line = prefix.str(); + } + + if(pos == std::string::npos) + { + line += cl.substr(start, length - start); + break; + } + else + { + line += cl.substr(start, length - start + 1); + } + } + + if (line.length()) + { + this->Write(line); + } +} + +