X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fusermanager.cpp;h=adec2fe16d9e91e5cd4be1e5528c39fdd3e48113;hb=40dc59986b3991d3db3cb3a761aa9aa7bab69737;hp=f8b1f0de257cfe4d4b4d53f8c911c810460ac055;hpb=f209cce90b394acd26e22eacef0bff61e8f5b4e1;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/usermanager.cpp b/src/usermanager.cpp index f8b1f0de2..adec2fe16 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -3,7 +3,7 @@ * +------------------------------------+ * * InspIRCd: (C) 2002-2009 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * See: http://wiki.inspircd.org/Credits * * This program is free but copyrighted software; see * the file COPYING for details. @@ -18,7 +18,7 @@ #include "bancache.h" /* add a client connection to the sockets list */ -void UserManager::AddUser(InspIRCd* Instance, int socket, int port, bool iscached, sockaddr* ip, const std::string &targetip) +void UserManager::AddUser(InspIRCd* Instance, int socket, ClientListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) { /* NOTE: Calling this one parameter constructor for User automatically * allocates a new UUID and places it in the hash_map. @@ -31,29 +31,22 @@ void UserManager::AddUser(InspIRCd* Instance, int socket, int port, bool iscache catch (...) { Instance->Logs->Log("USERS", DEFAULT,"*** WTF *** Duplicated UUID! -- Crack smoking monkies have been unleashed."); - Instance->SNO->WriteToSnoMask('A', "WARNING *** Duplicate UUID allocated!"); + Instance->SNO->WriteToSnoMask('a', "WARNING *** Duplicate UUID allocated!"); return; } - char ipaddr[MAXBUF]; -#ifdef IPV6 - if (ip->sa_family == AF_INET6) - inet_ntop(AF_INET6, &((const sockaddr_in6*)ip)->sin6_addr, ipaddr, sizeof(ipaddr)); - else -#endif - inet_ntop(AF_INET, &((const sockaddr_in*)ip)->sin_addr, ipaddr, sizeof(ipaddr)); - New->SetFd(socket); - New->SetSockAddr(ip->sa_family, ipaddr, port); + memcpy(&New->client_sa, client, sizeof(irc::sockets::sockaddrs)); + memcpy(&New->server_sa, server, sizeof(irc::sockets::sockaddrs)); /* Give each of the modules an attempt to hook the user for I/O */ - FOREACH_MOD_I(Instance, I_OnHookUserIO, OnHookUserIO(New, targetip)); + FOREACH_MOD_I(Instance, I_OnHookIO, OnHookIO(New, via)); if (New->GetIOHook()) { try { - New->GetIOHook()->OnRawSocketAccept(socket, ipaddr, port); + New->GetIOHook()->OnRawSocketAccept(socket, client, server); } catch (CoreException& modexcept) { @@ -106,7 +99,7 @@ void UserManager::AddUser(InspIRCd* Instance, int socket, int port, bool iscache if ((this->local_users.size() > Instance->Config->SoftLimit) || (this->local_users.size() >= (unsigned int)Instance->SE->GetMaxFds())) { - Instance->SNO->WriteToSnoMask('A', "Warning: softlimit value has been reached: %d clients", Instance->Config->SoftLimit); + Instance->SNO->WriteToSnoMask('a', "Warning: softlimit value has been reached: %d clients", Instance->Config->SoftLimit); this->QuitUser(New,"No more connections allowed"); return; } @@ -178,18 +171,97 @@ void UserManager::QuitUser(User *user, const std::string &quitreason, const char return; } - ServerInstance->Logs->Log("USERS", DEBUG,"QuitUser: %s '%s'", user->nick.c_str(), quitreason.c_str()); - user->Write("ERROR :Closing link: (%s@%s) [%s]", user->ident.c_str(), user->host.c_str(), *operreason ? operreason : quitreason.c_str()); user->quitting = true; - user->quietquit = false; - user->quitmsg = quitreason; - if (!*operreason) - user->operquitmsg = quitreason; + ServerInstance->Logs->Log("USERS", DEBUG, "QuitUser: %s '%s'", user->nick.c_str(), quitreason.c_str()); + user->Write("ERROR :Closing link: (%s@%s) [%s]", user->ident.c_str(), user->host.c_str(), *operreason ? operreason : quitreason.c_str()); + + std::string reason; + std::string oper_reason; + reason.assign(quitreason, 0, ServerInstance->Config->Limits.MaxQuit); + if (operreason && *operreason) + oper_reason.assign(operreason, 0, ServerInstance->Config->Limits.MaxQuit); else - user->operquitmsg = operreason; + oper_reason = quitreason; ServerInstance->GlobalCulls.AddItem(user); + + if (user->registered == REG_ALL) + { + FOREACH_MOD_I(ServerInstance,I_OnUserQuit,OnUserQuit(user, reason, oper_reason)); + user->PurgeEmptyChannels(); + user->WriteCommonQuit(reason, oper_reason); + } + + FOREACH_MOD_I(ServerInstance,I_OnUserDisconnect,OnUserDisconnect(user)); + + user->UpdateNickHash(user->uuid.c_str()); + + user_hash::iterator iter = this->clientlist->find(user->uuid); + + if (user->registered != REG_ALL) + if (ServerInstance->Users->unregistered_count) + ServerInstance->Users->unregistered_count--; + + if (IS_LOCAL(user)) + { + if (!user->sendq.empty()) + user->FlushWriteBuf(); + + if (user->GetIOHook()) + { + try + { + user->GetIOHook()->OnRawSocketClose(user->GetFd()); + } + catch (CoreException& modexcept) + { + ServerInstance->Logs->Log("USERS",DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); + } + } + + ServerInstance->SE->DelFd(user); + user->CloseSocket(); + } + + /* + * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything + * if they were an oper with +sn +qQ. + */ + if (user->registered == REG_ALL) + { + if (IS_LOCAL(user)) + { + if (!user->quietquit) + { + ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]", + user->nick.c_str(), user->ident.c_str(), user->host.c_str(), oper_reason.c_str()); + } + } + else + { + if ((!ServerInstance->SilentULine(user->server)) && (!user->quietquit)) + { + ServerInstance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [%s]", + user->server, user->nick.c_str(), user->ident.c_str(), user->host.c_str(), oper_reason.c_str()); + } + } + user->AddToWhoWas(); + } + + if (iter != this->clientlist->end()) + this->clientlist->erase(iter); + else + ServerInstance->Logs->Log("USERS", DEBUG, "iter == clientlist->end, can't remove them from hash... problematic.."); + + if (IS_LOCAL(user)) + { + std::vector::iterator x = find(local_users.begin(),local_users.end(),user); + if (x != local_users.end()) + local_users.erase(x); + else + ServerInstance->Logs->Log("USERS", DEBUG, "Failed to remove user from vector"); + } } @@ -197,19 +269,13 @@ void UserManager::AddLocalClone(User *user) { int range = 32; clonemap::iterator x; - switch (user->GetProtocolFamily()) + switch (user->client_sa.sa.sa_family) { -#ifdef SUPPORT_IP6LINKS case AF_INET6: - { range = ServerInstance->Config->c_ipv6_range; - } break; -#endif case AF_INET: - { range = ServerInstance->Config->c_ipv4_range; - } break; } @@ -224,19 +290,13 @@ void UserManager::AddGlobalClone(User *user) { int range = 32; clonemap::iterator x; - switch (user->GetProtocolFamily()) + switch (user->client_sa.sa.sa_family) { -#ifdef SUPPORT_IP6LINKS case AF_INET6: - { range = ServerInstance->Config->c_ipv6_range; - } break; -#endif case AF_INET: - { range = ServerInstance->Config->c_ipv4_range; - } break; } @@ -250,19 +310,13 @@ void UserManager::AddGlobalClone(User *user) void UserManager::RemoveCloneCounts(User *user) { int range = 32; - switch (user->GetProtocolFamily()) + switch (user->client_sa.sa.sa_family) { -#ifdef SUPPORT_IP6LINKS case AF_INET6: - { range = ServerInstance->Config->c_ipv6_range; - } break; -#endif case AF_INET: - { range = ServerInstance->Config->c_ipv4_range; - } break; } @@ -290,19 +344,13 @@ void UserManager::RemoveCloneCounts(User *user) unsigned long UserManager::GlobalCloneCount(User *user) { int range = 32; - switch (user->GetProtocolFamily()) + switch (user->client_sa.sa.sa_family) { -#ifdef SUPPORT_IP6LINKS case AF_INET6: - { range = ServerInstance->Config->c_ipv6_range; - } break; -#endif case AF_INET: - { range = ServerInstance->Config->c_ipv4_range; - } break; } clonemap::iterator x = global_clones.find(user->GetCIDRMask(range)); @@ -315,19 +363,13 @@ unsigned long UserManager::GlobalCloneCount(User *user) unsigned long UserManager::LocalCloneCount(User *user) { int range = 32; - switch (user->GetProtocolFamily()) + switch (user->client_sa.sa.sa_family) { -#ifdef SUPPORT_IP6LINKS case AF_INET6: - { range = ServerInstance->Config->c_ipv6_range; - } break; -#endif case AF_INET: - { range = ServerInstance->Config->c_ipv4_range; - } break; } clonemap::iterator x = local_clones.find(user->GetCIDRMask(range));