From 18154f4d229cf8ebdcec0dac671ad6e2e0049fee Mon Sep 17 00:00:00 2001 From: aquanight Date: Fri, 8 Feb 2008 23:35:39 +0000 Subject: Support for /invite - if the user doesn't partake in time, the invite expires git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8854 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/users.cpp | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'src/users.cpp') 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; -- cgit v1.2.3