X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fusers.cpp;h=adfa7642cffc7278cfb0aa4fd8592db9422a4324;hb=21f7e4a8cdad2f29fda2768215c3a5352a9fa632;hp=aebc66bfc48472110fb375c1dbe5a0fa1950ec28;hpb=569a742b9420b62a538c27fbd38a2bb8db6b9ca6;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/users.cpp b/src/users.cpp index aebc66bfc..adfa7642c 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -219,31 +219,16 @@ User::User(const std::string &uid, const std::string& sid, int type) LocalUser::LocalUser(int myfd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* servaddr) : User(ServerInstance->GetUID(), ServerInstance->Config->ServerName, USERTYPE_LOCAL), eh(this), + localuseriter(ServerInstance->Users->local_users.end()), bytes_in(0), bytes_out(0), cmds_in(0), cmds_out(0), nping(0), CommandFloodPenalty(0), already_sent(0) { ident = "unknown"; lastping = 0; eh.SetFd(myfd); + memcpy(&client_sa, client, sizeof(irc::sockets::sockaddrs)); memcpy(&server_sa, servaddr, sizeof(irc::sockets::sockaddrs)); - - /* - * Initialize host and dhost here to the user's IP. - * It is important to do this before calling SetClientIP() - * as that passes execution to modules that expect these - * fields to be valid. - * - * We cannot call GetIPString() now as that will access - * client_sa, and that's only initialized after the first - * SetClientIP() call. - */ - - int port; - irc::sockets::satoap(*client, host, port); - if (host[0] == ':') - host.insert(0, 1, '0'); - dhost = host; - SetClientIP(*client); + dhost = host = GetIPString(); } User::~User() @@ -555,11 +540,11 @@ CullResult User::cull() CullResult LocalUser::cull() { - std::vector::iterator x = find(ServerInstance->Users->local_users.begin(),ServerInstance->Users->local_users.end(),this); - if (x != ServerInstance->Users->local_users.end()) - ServerInstance->Users->local_users.erase(x); - else - ServerInstance->Logs->Log("USERS", DEBUG, "Failed to remove user from vector"); + // The iterator is initialized to local_users.end() in the constructor. It is + // overwritten in UserManager::AddUser() with the real iterator so this check + // is only a precaution currently. + if (localuseriter != ServerInstance->Users->local_users.end()) + ServerInstance->Users->local_users.erase(localuseriter); ClearInvites(); eh.cull(); @@ -814,13 +799,13 @@ void LocalUser::FullConnect() std::vector parameters; FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, this, true, command)); if (!MOD_RESULT) - ServerInstance->CallCommandHandler(command, parameters, this); + ServerInstance->Parser->CallHandler(command, parameters, this); MOD_RESULT = MOD_RES_PASSTHRU; command = "LUSERS"; FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, this, true, command)); if (!MOD_RESULT) - ServerInstance->CallCommandHandler(command, parameters, this); + ServerInstance->Parser->CallHandler(command, parameters, this); if (ServerInstance->Config->RawLog) WriteServ("PRIVMSG %s :*** Raw I/O logging is enabled on this server. All messages, passwords, and commands are being recorded.", nick.c_str()); @@ -1002,34 +987,39 @@ irc::sockets::cidr_mask User::GetCIDRMask() return irc::sockets::cidr_mask(client_sa, range); } -bool User::SetClientIP(const char* sip) +bool User::SetClientIP(const char* sip, bool recheck_eline) { cachedip.clear(); + cached_hostip.clear(); return irc::sockets::aptosa(sip, 0, client_sa); } -void User::SetClientIP(const irc::sockets::sockaddrs& sa) +void User::SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline) { cachedip.clear(); + cached_hostip.clear(); memcpy(&client_sa, &sa, sizeof(irc::sockets::sockaddrs)); } -bool LocalUser::SetClientIP(const char* sip) +bool LocalUser::SetClientIP(const char* sip, bool recheck_eline) { irc::sockets::sockaddrs sa; if (!irc::sockets::aptosa(sip, 0, sa)) // Invalid return false; - LocalUser::SetClientIP(sa); + LocalUser::SetClientIP(sa, recheck_eline); return true; } -void LocalUser::SetClientIP(const irc::sockets::sockaddrs& sa) +void LocalUser::SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline) { if (sa != client_sa) { User::SetClientIP(sa); + if (recheck_eline) + this->exempt = (ServerInstance->XLines->MatchesLine("E", this) != NULL); + FOREACH_MOD(I_OnSetUserIP,OnSetUserIP(this)); } } @@ -1496,7 +1486,7 @@ bool User::ChangeIdent(const char* newident) std::string quitstr = ":" + GetFullHost() + " QUIT :Changing ident"; - this->ident.assign(newident, 0, ServerInstance->Config->Limits.IdentMax + 1); + this->ident.assign(newident, 0, ServerInstance->Config->Limits.IdentMax); this->InvalidateCache(); @@ -1518,7 +1508,7 @@ void User::SendAll(const char* command, const char* text, ...) snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost().c_str(), command, textbuffer); std::string fmt = formatbuffer; - for (std::vector::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++) + for (LocalUserList::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++) { if ((*i)->registered == REG_ALL) (*i)->Write(fmt);