diff --git a/CacheManager.cpp b/CacheManager.cpp index 9e844c9..de94d1b 100644 --- a/CacheManager.cpp +++ b/CacheManager.cpp @@ -78,7 +78,7 @@ std::string CCacheManager::findNameNick(const std::string &name) std::string nick; if (name.empty()) return nick; - mux.unlock(); + mux.lock(); auto itn = NameNick.find(name); if (itn != NameNick.end()) nick.assign(itn->second); @@ -86,6 +86,20 @@ std::string CCacheManager::findNameNick(const std::string &name) return nick; } +std::string CCacheManager::findServerUser() +{ + std::string suser; + mux.lock(); + for (auto it=NameNick.begin(); it!=NameNick.end(); it++) { + if (0 == it->first.compare(0, 2, "s-")) { + suser.assign(it->first); + break; + } + } + mux.unlock(); + return suser; +} + void CCacheManager::updateUser(const std::string &user, const std::string &rptr, const std::string &gate, const std::string &addr, const std::string &time) { if (user.empty()) diff --git a/CacheManager.h b/CacheManager.h index 760edad..e62f1b2 100644 --- a/CacheManager.h +++ b/CacheManager.h @@ -36,6 +36,7 @@ public: std::string findNameNick(const std::string &name); std::string findUserRepeater(const std::string &user); std::string findGateAddress(const std::string &gate); + std::string findServerUser(); void eraseGate(const std::string &gate); void eraseName(const std::string &name); void clearGate(); diff --git a/ircddb/IRCDDBApp.cpp b/ircddb/IRCDDBApp.cpp index 4c2d4e1..9e035eb 100644 --- a/ircddb/IRCDDBApp.cpp +++ b/ircddb/IRCDDBApp.cpp @@ -9,18 +9,16 @@ IRCDDBApp::IRCDDBApp(const std::string &u_chan, CCacheManager *cache) : numberOfTables(2) { + updateChannel = u_chan; + this->cache = cache; maxTime = 950000000; // Feb 2000 wdTimer = -1; sendQ = NULL; initReady = false; - - userListReset(); - state = 0; timer = 0; myNick = "none"; - updateChannel = u_chan; terminateThread = false; tablePattern = std::regex("^[0-9]$"); @@ -28,7 +26,6 @@ IRCDDBApp::IRCDDBApp(const std::string &u_chan, CCacheManager *cache) : numberOf timePattern = std::regex("^((2[0-3])|([01][0-9])):[0-5][0-9]:[0-5][0-9]$"); dbPattern = std::regex("^[0-9A-Z_]{8}$"); modulePattern = std::regex("^.*[ABCD]D?$"); - this->cache = cache; } IRCDDBApp::~IRCDDBApp() @@ -184,9 +181,7 @@ void IRCDDBApp::stopWork() void IRCDDBApp::userJoin(const std::string &nick, const std::string &name, const std::string &addr) { - if ('-' == nick.at(1)) { - if ('s' == nick.at(0)) - setBestServer(nick); + if (0 == nick.compare(0, 2, "u-")) { return; } std::string gate(name); @@ -237,7 +232,11 @@ void IRCDDBApp::setBestServer(const std::string &ircUser) bool IRCDDBApp::findServerUser() { - return (!bestServer.empty() && !currentServer.empty()); + std::string suser(cache->findServerUser()); + if (suser.empty()) + return false; + currentServer.assign(suser); + return true; } // to is the gateway to which we are sending the message, (the gateway last used by URCall)