From 3cf1ae04704b4f1706daa1077b90fd14d1e72cef Mon Sep 17 00:00:00 2001 From: om Date: Sat, 1 Jul 2006 11:42:09 +0000 Subject: Replace rather craq'y loop with a couple of std::string calls Change GetServerDescription to take const char* rather than char* Change userrec::server from char* to const char*, this is more 'correct' as it's not safe to modify it (pointer as returned by std::string::c_str()) Change WhoWasGroup::server, see above about userrec::server git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4094 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/helperfuncs.cpp | 2 +- src/modules/m_spanningtree.cpp | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index c51a824a8..a30a669ae 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -670,7 +670,7 @@ void ChanExceptSender_NoFormat(chanrec* Ptr, userrec* user, char status, const c } } -std::string GetServerDescription(char* servername) +std::string GetServerDescription(const char* servername) { std::string description = ""; diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp index dc50140b2..efedb2b8c 100644 --- a/src/modules/m_spanningtree.cpp +++ b/src/modules/m_spanningtree.cpp @@ -1147,18 +1147,17 @@ class TreeSocket : public InspSocket // NICK age nick host dhost ident +modes ip :gecos // 0 123 4 56 7 time_t age = atoi(params[0].c_str()); - std::string modes = params[5]; - while (*(modes.c_str()) == '+') - { - char* m = (char*)modes.c_str(); - m++; - modes = m; - } - char* tempnick = (char*)params[1].c_str(); + + /* This used to have a pretty craq'y loop doing the same thing, + * now we just let the STL do the hard work (more efficiently) + */ + params[5] = params[5].substr(params[5].find_first_not_of('+')); + + const char* tempnick = params[1].c_str(); log(DEBUG,"Introduce client %s!%s@%s",tempnick,params[4].c_str(),params[2].c_str()); - user_hash::iterator iter; - iter = clientlist.find(tempnick); + user_hash::iterator iter = clientlist.find(tempnick); + if (iter != clientlist.end()) { // nick collision @@ -1172,12 +1171,13 @@ class TreeSocket : public InspSocket strlcpy(clientlist[tempnick]->nick, tempnick,NICKMAX-1); strlcpy(clientlist[tempnick]->host, params[2].c_str(),63); strlcpy(clientlist[tempnick]->dhost, params[3].c_str(),63); - clientlist[tempnick]->server = (char*)FindServerNamePtr(source.c_str()); + clientlist[tempnick]->server = FindServerNamePtr(source.c_str()); strlcpy(clientlist[tempnick]->ident, params[4].c_str(),IDENTMAX); strlcpy(clientlist[tempnick]->fullname, params[7].c_str(),MAXGECOS); clientlist[tempnick]->registered = 7; clientlist[tempnick]->signon = age; - strlcpy(clientlist[tempnick]->modes, modes.c_str(),53); + strlcpy(clientlist[tempnick]->modes, params[5].c_str(),53); + for (char *v = clientlist[tempnick]->modes; *v; v++) { switch (*v) -- cgit v1.2.3