diff options
-rw-r--r-- | include/modules.h | 6 | ||||
-rw-r--r-- | include/users.h | 7 | ||||
-rw-r--r-- | src/commands/cmd_invite.cpp | 15 | ||||
-rw-r--r-- | src/modules.cpp | 4 | ||||
-rw-r--r-- | src/modules/m_noinvite.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_silence_ext.cpp | 2 | ||||
-rw-r--r-- | src/users.cpp | 45 |
7 files changed, 62 insertions, 19 deletions
diff --git a/include/modules.h b/include/modules.h index e14b13c9b..09b1f954b 100644 --- a/include/modules.h +++ b/include/modules.h @@ -626,9 +626,10 @@ class CoreExport Module : public Extensible * @param source The user who is issuing the INVITE * @param dest The user being invited * @param channel The channel the user is being invited to + * @param timeout The time the invite will expire (0 == never) * @return 1 to deny the invite, 0 to allow */ - virtual int OnUserPreInvite(User* source,User* dest,Channel* channel); + virtual int OnUserPreInvite(User* source,User* dest,Channel* channel, time_t timeout); /** Called after a user has been successfully invited to a channel. * You cannot prevent the invite from occuring using this function, to do that, @@ -636,8 +637,9 @@ class CoreExport Module : public Extensible * @param source The user who is issuing the INVITE * @param dest The user being invited * @param channel The channel the user is being invited to + * @param timeout The time the invite will expire (0 == never) */ - virtual void OnUserInvite(User* source,User* dest,Channel* channel); + virtual void OnUserInvite(User* source,User* dest,Channel* channel, time_t timeout); /** Called whenever a user is about to PRIVMSG A user or a channel, before any processing is done. * Returning any nonzero value from this function stops the process immediately, causing no diff --git a/include/users.h b/include/users.h index 1fca831ef..a7b6f5629 100644 --- a/include/users.h +++ b/include/users.h @@ -360,9 +360,9 @@ public: } }; -/** Holds a complete list of all channels to which a user has been invited and has not yet joined. +/** Holds a complete list of all channels to which a user has been invited and has not yet joined, and the time at which they'll expire. */ -typedef std::vector<irc::string> InvitedList; +typedef std::vector< std::pair<irc::string, time_t> > InvitedList; /** Holds a complete list of all allow and deny tags from the configuration file (connection classes) */ @@ -736,8 +736,9 @@ class CoreExport User : public connection /** Adds a channel to a users invite list (invites them to a channel) * @param channel A channel name to add + * @param timeout When the invite should expire (0 == never) */ - virtual void InviteTo(const irc::string &channel); + virtual void InviteTo(const irc::string &channel, time_t timeout); /** Removes a channel from a users invite list. * This member function is called on successfully joining an invite only channel diff --git a/src/commands/cmd_invite.cpp b/src/commands/cmd_invite.cpp index 978b26123..42905d9bf 100644 --- a/src/commands/cmd_invite.cpp +++ b/src/commands/cmd_invite.cpp @@ -25,10 +25,15 @@ CmdResult CommandInvite::Handle (const char** parameters, int pcnt, User *user) { int MOD_RESULT = 0; - if (pcnt == 2) + if (pcnt == 2 || pcnt == 3) { User* u = ServerInstance->FindNick(parameters[0]); Channel* c = ServerInstance->FindChan(parameters[1]); + time_t timeout = 0; + if (pcnt == 3) + { + timeout = time(NULL) + ServerInstance->Duration(parameters[2]); + } if ((!c) || (!u)) { @@ -65,14 +70,14 @@ CmdResult CommandInvite::Handle (const char** parameters, int pcnt, User *user) return CMD_FAILURE; } - FOREACH_RESULT(I_OnUserPreInvite,OnUserPreInvite(user,u,c)); + FOREACH_RESULT(I_OnUserPreInvite,OnUserPreInvite(user,u,c,timeout)); if (MOD_RESULT == 1) { return CMD_FAILURE; } - u->InviteTo(c->name); + u->InviteTo(c->name, timeout); u->WriteFrom(user,"INVITE %s :%s",u->nick,c->name); user->WriteServ("341 %s %s %s",user->nick,u->nick,c->name); switch (ServerInstance->Config->AnnounceInvites) @@ -93,7 +98,7 @@ CmdResult CommandInvite::Handle (const char** parameters, int pcnt, User *user) /* Nobody */ break; } - FOREACH_MOD(I_OnUserInvite,OnUserInvite(user,u,c)); + FOREACH_MOD(I_OnUserInvite,OnUserInvite(user,u,c,timeout)); } else { @@ -102,7 +107,7 @@ CmdResult CommandInvite::Handle (const char** parameters, int pcnt, User *user) InvitedList* il = user->GetInviteList(); for (InvitedList::iterator i = il->begin(); i != il->end(); i++) { - user->WriteServ("346 %s :%s",user->nick,i->c_str()); + user->WriteServ("346 %s :%s",user->nick,i->first.c_str()); } user->WriteServ("347 %s :End of INVITE list",user->nick); } diff --git a/src/modules.cpp b/src/modules.cpp index 0142749cf..64b560d89 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -123,7 +123,7 @@ void Module::OnOper(User*, const std::string&) { } void Module::OnPostOper(User*, const std::string&, const std::string &) { } void Module::OnInfo(User*) { } void Module::OnWhois(User*, User*) { } -int Module::OnUserPreInvite(User*, User*, Channel*) { return 0; } +int Module::OnUserPreInvite(User*, User*, Channel*, time_t) { return 0; } int Module::OnUserPreMessage(User*, void*, int, std::string&, char, CUList&) { return 0; } int Module::OnUserPreNotice(User*, void*, int, std::string&, char, CUList&) { return 0; } int Module::OnUserPreNick(User*, const std::string&) { return 0; } @@ -164,7 +164,7 @@ int Module::OnRawSocketRead(int, char*, unsigned int, int&) { return 0; } void Module::OnUserMessage(User*, void*, int, const std::string&, char, const CUList&) { } void Module::OnUserNotice(User*, void*, int, const std::string&, char, const CUList&) { } void Module::OnRemoteKill(User*, User*, const std::string&, const std::string&) { } -void Module::OnUserInvite(User*, User*, Channel*) { } +void Module::OnUserInvite(User*, User*, Channel*, time_t) { } void Module::OnPostLocalTopicChange(User*, Channel*, const std::string&) { } void Module::OnGetServerDescription(const std::string&, std::string&) { } void Module::OnSyncUser(User*, Module*, void*) { } diff --git a/src/modules/m_noinvite.cpp b/src/modules/m_noinvite.cpp index d29942bc8..cff191db0 100644 --- a/src/modules/m_noinvite.cpp +++ b/src/modules/m_noinvite.cpp @@ -58,7 +58,7 @@ class ModuleNoInvite : public Module } - virtual int OnUserPreInvite(User* user,User* dest,Channel* channel) + virtual int OnUserPreInvite(User* user,User* dest,Channel* channel, time_t timeout) { if (channel->IsModeSet('V')) { diff --git a/src/modules/m_silence_ext.cpp b/src/modules/m_silence_ext.cpp index f37d67b13..886fa3fc5 100644 --- a/src/modules/m_silence_ext.cpp +++ b/src/modules/m_silence_ext.cpp @@ -334,7 +334,7 @@ class ModuleSilence : public Module return PreText(user, dest, target_type, text, status, exempt_list, SILENCE_NOTICE); } - virtual int OnUserPreInvite(User* source,User* dest,Channel* channel) + virtual int OnUserPreInvite(User* source,User* dest,Channel* channel, time_t timeout) { return MatchPattern(dest, source, SILENCE_INVITE); } diff --git a/src/users.cpp b/src/users.cpp index be51cc46a..4bf2986b8 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -367,10 +367,20 @@ char* User::GetFullRealHost() bool User::IsInvited(const irc::string &channel) { - for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++) + time_t now = time(NULL); + InvitedList::iterator safei; + for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i) { - if (channel == *i) + if (channel == i->first) { + if (i->second != 0 && now > i->second) + { + /* Expired invite, remove it. */ + safei = i; + --i; + invites.erase(safei); + continue; + } return true; } } @@ -379,19 +389,44 @@ bool User::IsInvited(const irc::string &channel) InvitedList* User::GetInviteList() { + time_t now = time(NULL); + /* Weed out expired invites here. */ + InvitedList::iterator safei; + for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i) + { + if (i->second != 0 && now > i->second) + { + /* Expired invite, remove it. */ + safei = i; + --i; + invites.erase(safei); + } + } return &invites; } -void User::InviteTo(const irc::string &channel) +void User::InviteTo(const irc::string &channel, time_t timeout) { - invites.push_back(channel); + time_t now = time(NULL); + if (timeout != 0 && now > timeout) return; /* Don't add invites that are expired from the get-go. */ + for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i) + { + if (channel == i->first) + { + if (i->second != 0 && timeout > i->second) + { + i->second = timeout; + } + } + } + invites.push_back(std::make_pair(channel, timeout)); } void User::RemoveInvite(const irc::string &channel) { for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++) { - if (channel == *i) + if (channel == i->first) { invites.erase(i); return; |