summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commands/cmd_invite.cpp15
-rw-r--r--src/modules.cpp4
-rw-r--r--src/modules/m_noinvite.cpp2
-rw-r--r--src/modules/m_silence_ext.cpp2
-rw-r--r--src/users.cpp45
5 files changed, 54 insertions, 14 deletions
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;