diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/channels.cpp | 24 | ||||
-rw-r--r-- | src/sessions.cpp | 1 | ||||
-rw-r--r-- | src/users.cpp | 221 |
3 files changed, 98 insertions, 148 deletions
diff --git a/src/channels.cpp b/src/channels.cpp index 84870b1e9..8b3f053b1 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -587,18 +587,6 @@ void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const Anope::string &pa SetMode(bi, ModeManager::FindChannelModeByName(Name), param, EnforceMLock); } -/** - * Set a mode on a channel - * @param bi The client setting the modes - * @param Mode The mode - * @param param Optional param arg for the mode - * @param EnforceMLock true if mlocks should be enforced, false to override mlock - */ -void Channel::SetMode(BotInfo *bi, char Mode, const Anope::string ¶m, bool EnforceMLock) -{ - SetMode(bi, ModeManager::FindChannelModeByChar(Mode), param, EnforceMLock); -} - /** Remove a mode from a channel * @param bi The client setting the modes * @param cm The mode @@ -649,18 +637,6 @@ void Channel::RemoveMode(BotInfo *bi, ChannelModeName Name, const Anope::string RemoveMode(bi, ModeManager::FindChannelModeByName(Name), param, EnforceMLock); } -/** - * Remove a mode from a channel - * @param bi The client setting the modes - * @param Mode The mode - * @param param Optional param arg for the mode - * @param EnforceMLock true if mlocks should be enforced, false to override mlock - */ -void Channel::RemoveMode(BotInfo *bi, char Mode, const Anope::string ¶m, bool EnforceMLock) -{ - RemoveMode(bi, ModeManager::FindChannelModeByChar(Mode), param, EnforceMLock); -} - /** Get a param from the channel * @param Name The mode * @param Target a string to put the param into diff --git a/src/sessions.cpp b/src/sessions.cpp index a0ad66618..38dfedef5 100644 --- a/src/sessions.cpp +++ b/src/sessions.cpp @@ -98,7 +98,6 @@ Session *findsession(const Anope::string &host) /* Attempt to add a host to the session list. If the addition of the new host * causes the the session limit to be exceeded, kill the connecting user. - * Returns 1 if the host was added or 0 if the user was killed. */ void add_session(const Anope::string &nick, const Anope::string &host, const Anope::string &hostip) diff --git a/src/users.cpp b/src/users.cpp index b6556175e..8ebe339ea 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -507,16 +507,6 @@ void User::SetMode(BotInfo *bi, UserModeName Name, const Anope::string &Param) SetMode(bi, ModeManager::FindUserModeByName(Name), Param); } -/* Set a mode on the user - * @param bi The client setting the mode - * @param ModeChar The mode char - * @param param Optional param for the mode - */ -void User::SetMode(BotInfo *bi, char ModeChar, const Anope::string &Param) -{ - SetMode(bi, ModeManager::FindUserModeByChar(ModeChar), Param); -} - /** Remove a mode on the user * @param bi The client setting the mode * @param um The user mode @@ -539,15 +529,6 @@ void User::RemoveMode(BotInfo *bi, UserModeName Name) RemoveMode(bi, ModeManager::FindUserModeByName(Name)); } -/** Remove a mode from the user - * @param bi The client setting the mode - * @param ModeChar The mode char - */ -void User::RemoveMode(BotInfo *bi, char ModeChar) -{ - RemoveMode(bi, ModeManager::FindUserModeByChar(ModeChar)); -} - /** Set a string of modes on a user * @param bi The client setting the mode * @param umodes The modes @@ -596,6 +577,80 @@ void User::SetModes(BotInfo *bi, const char *umodes, ...) } } +void User::SetModesInternal(const char *umodes, ...) +{ + char buf[BUFSIZE] = ""; + va_list args; + Anope::string modebuf, sbuf; + int add = -1; + va_start(args, umodes); + vsnprintf(buf, BUFSIZE - 1, umodes, args); + va_end(args); + + spacesepstream sep(buf); + sep.GetToken(modebuf); + for (unsigned i = 0, end = modebuf.length(); i < end; ++i) + { + UserMode *um; + + switch (modebuf[i]) + { + case '+': + add = 1; + continue; + case '-': + add = 0; + continue; + default: + if (add == -1) + continue; + um = ModeManager::FindUserModeByChar(modebuf[i]); + if (!um) + continue; + } + + if (add) + { + if (um->Type == MODE_PARAM && sep.GetToken(sbuf)) + this->SetModeInternal(um, sbuf); + else + this->SetModeInternal(um); + } + else + this->RemoveModeInternal(um); + + switch (um->Name) + { + case UMODE_OPER: + if (add) + { + ++opcnt; + if (Config->WallOper) + ircdproto->SendGlobops(OperServ, "\2%s\2 is now an IRC operator.", this->nick.c_str()); + Log(OperServ) << this->nick << " is now an IRC operator"; + } + else + { + --opcnt; + + Log(OperServ) << this->nick << " is no longer an IRC operator"; + } + break; + case UMODE_REGISTERED: + if (add && !this->IsIdentified()) + this->RemoveMode(NickServ, UMODE_REGISTERED); + break; + case UMODE_CLOAK: + case UMODE_VHOST: + if (!add && !this->vhost.empty()) + this->vhost.clear(); + this->UpdateHost(); + default: + break; + } + } +} + /** Find the channel container for Channel c that the user is on * This is preferred over using FindUser in Channel, as there are usually more users in a channel * than channels a user is in @@ -669,30 +724,22 @@ User *finduser(const Anope::string &nick) /* Handle a server NICK command. */ -User *do_nick(const Anope::string &source, const Anope::string &nick, const Anope::string &username, const Anope::string &host, const Anope::string &server, const Anope::string &realname, time_t ts, const Anope::string &ip, const Anope::string &vhost, const Anope::string &uid) +User *do_nick(const Anope::string &source, const Anope::string &nick, const Anope::string &username, const Anope::string &host, const Anope::string &server, const Anope::string &realname, time_t ts, const Anope::string &ip, const Anope::string &vhost, const Anope::string &uid, const Anope::string &modes) { - User *user = NULL; - Anope::string vhost2 = vhost; - if (source.empty()) { - if (ircd->nickvhost && !vhost2.empty() && vhost2.equals_cs("*")) - { - vhost2.clear(); - } - /* This is a new user; create a User structure for it. */ Log(LOG_DEBUG) << "new user: " << nick; Server *serv = Server::Find(server); /* Allocate User structure and fill it in. */ - user = new User(nick, username, host, uid); + dynamic_reference<User> user = new User(nick, username, host, uid); user->server = serv; user->realname = realname; user->timestamp = ts; - if (!vhost2.empty()) - user->SetCloakedHost(vhost2); + if (!vhost.empty()) + user->SetCloakedHost(vhost); user->SetVIdent(username); if (!ip.empty()) @@ -711,28 +758,33 @@ User *do_nick(const Anope::string &source, const Anope::string &nick, const Anop } } - Log(user, "connect") << (ircd->nickvhost && !vhost2.empty() ? Anope::string("(") + vhost2 + ")" : "") << " (" << user->realname << ") " << (user->ip() ? Anope::string("[") + user->ip.addr() + "] " : "") << "connected to the network (" << serv->GetName() << ")"; + Log(*user, "connect") << (!vhost.empty() ? Anope::string("(") + vhost + ")" : "") << " (" << user->realname << ") " << (user->ip() ? Anope::string("[") + user->ip.addr() + "] " : "") << "connected to the network (" << serv->GetName() << ")"; EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreUserConnect, OnPreUserConnect(user)); + FOREACH_RESULT(I_OnPreUserConnect, OnPreUserConnect(*user)); if (MOD_RESULT == EVENT_STOP) - return finduser(nick); + return *user; if (Config->LimitSessions && !serv->IsULined()) add_session(nick, host, user->ip() ? user->ip.addr() : ""); - XLineManager::CheckAll(user); + if (!user) + return NULL; + + XLineManager::CheckAll(*user); /* User is no longer connected, return */ - if (!finduser(nick)) + if (!user) return NULL; - FOREACH_MOD(I_OnUserConnect, OnUserConnect(user)); + FOREACH_MOD(I_OnUserConnect, OnUserConnect(*user)); + + return user ? *user : NULL; } else { /* An old user changing nicks. */ - user = finduser(source); + User *user = finduser(source); if (!user) { @@ -789,9 +841,9 @@ User *do_nick(const Anope::string &source, const Anope::string &nick, const Anop return NULL; } } - } - return user; + return user; + } } /*************************************************************************/ @@ -810,7 +862,12 @@ void do_umode(const Anope::string &source, int ac, const char **av) return; } - UserSetInternalModes(user, ac - 1, &av[1]); + Log(user, "mode") << "changes modes to " << merge_args(ac - 1, av + 1); + + Anope::string modes = av[1]; + for (int i = 2; i < ac; ++i) + modes += Anope::string(" ") + av[i]; + user->SetModesInternal(modes.c_str()); } /*************************************************************************/ @@ -972,85 +1029,3 @@ Anope::string create_mask(User *u) return mask; } -/*************************************************************************/ - -/** Set modes internally on a user - * @param user The user - * @param ac Number of args - * @param av Args - */ -void UserSetInternalModes(User *user, int ac, const char **av) -{ - int add = -1, j = 0; - const char *modes = av[0]; - if (!user || !modes) - return; - - Log(user, "mode") << "changes modes to " << merge_args(ac, av); - - for (; *modes; ++modes) - { - UserMode *um; - - switch (*modes) - { - case '+': - add = 1; - continue; - case '-': - add = 0; - continue; - default: - if (add == -1) - continue; - um = ModeManager::FindUserModeByChar(*modes); - if (!um) - continue; - } - - if (um->Type == MODE_REGULAR) - { - if (add) - user->SetModeInternal(um); - else - user->RemoveModeInternal(um); - } - else if (++j < ac) - { - if (add) - user->SetModeInternal(um, av[j]); - else - user->RemoveModeInternal(um); - } - - switch (um->Name) - { - case UMODE_OPER: - if (add) - { - ++opcnt; - if (Config->WallOper) - ircdproto->SendGlobops(OperServ, "\2%s\2 is now an IRC operator.", user->nick.c_str()); - Log(OperServ) << user->nick << " is now an IRC operator"; - } - else - { - --opcnt; - - Log(OperServ) << user->nick << " is no longer an IRC operator"; - } - break; - case UMODE_REGISTERED: - if (add && !user->IsIdentified()) - user->RemoveMode(NickServ, UMODE_REGISTERED); - break; - case UMODE_CLOAK: - case UMODE_VHOST: - if (!add && !user->vhost.empty()) - user->vhost.clear(); - user->UpdateHost(); - default: - break; - } - } -} |