summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2012-06-27 16:29:21 -0700
committerAttila Molnar <attilamolnar@hush.com>2012-06-27 16:29:21 -0700
commitf89e68d78684dab66f9c99aaf8bd8a37ec62bfce (patch)
treecdabc56abaf267f501308be387269bed655ac724 /src
parentb1dedaba2400b7ce7acfa98b9a63fd54ae674a41 (diff)
parentd2e189102b643f38418f3caf065dbb91f2ce4266 (diff)
Merge pull request #235 from attilamolnar/insp20+invitefix
Diffstat (limited to 'src')
-rw-r--r--src/channels.cpp88
-rw-r--r--src/commands/cmd_invite.cpp6
-rw-r--r--src/inspircd.cpp1
-rw-r--r--src/modules/m_spanningtree/fjoin.cpp1
-rw-r--r--src/users.cpp79
5 files changed, 117 insertions, 58 deletions
diff --git a/src/channels.cpp b/src/channels.cpp
index 4a927cedb..f1dba5315 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -172,6 +172,8 @@ void Channel::DelUser(User* user)
FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
ServerInstance->chanlist->erase(iter);
}
+
+ ClearInvites();
ServerInstance->GlobalCulls.AddItem(this);
}
}
@@ -969,3 +971,89 @@ void Channel::RemoveAllPrefixes(User* user)
m->second->modes.clear();
}
}
+
+void Invitation::Create(Channel* c, LocalUser* u, time_t timeout)
+{
+ if ((timeout != 0) && (ServerInstance->Time() >= timeout))
+ // Expired, don't bother
+ return;
+
+ ServerInstance->Logs->Log("INVITATION", DEBUG, "Invitation::Create chan=%s user=%s", c->name.c_str(), u->uuid.c_str());
+
+ Invitation* inv = Invitation::Find(c, u, false);
+ if (inv)
+ {
+ if ((inv->expiry == 0) || (inv->expiry > timeout))
+ return;
+ inv->expiry = timeout;
+ ServerInstance->Logs->Log("INVITATION", DEBUG, "Invitation::Create changed expiry in existing invitation %p", (void*) inv);
+ }
+ else
+ {
+ inv = new Invitation(c, u, timeout);
+ c->invites.push_back(inv);
+ u->invites.push_back(inv);
+ ServerInstance->Logs->Log("INVITATION", DEBUG, "Invitation::Create created new invitation %p", (void*) inv);
+ }
+}
+
+Invitation* Invitation::Find(Channel* c, LocalUser* u, bool check_expired)
+{
+ ServerInstance->Logs->Log("INVITATION", DEBUG, "Invitation::Find chan=%s user=%s check_expired=%d", c ? c->name.c_str() : "NULL", u ? u->uuid.c_str() : "NULL", check_expired);
+ if (!u || u->invites.empty())
+ return NULL;
+
+ InviteList locallist;
+ locallist.swap(u->invites);
+
+ Invitation* result = NULL;
+ for (InviteList::iterator i = locallist.begin(); i != locallist.end(); )
+ {
+ Invitation* inv = *i;
+ if ((check_expired) && (inv->expiry != 0) && (inv->expiry <= ServerInstance->Time()))
+ {
+ /* Expired invite, remove it. */
+ ServerInstance->Logs->Log("INVITATION", DEBUG, "Invitation::Find ecountered expired entry: %p timed out at %lu", (void*) inv, inv->expiry);
+ i = locallist.erase(i);
+ inv->cull();
+ delete inv;
+ }
+ else
+ {
+ /* Is it what we're searching for? */
+ if (inv->chan == c)
+ {
+ result = inv;
+ break;
+ }
+ ++i;
+ }
+ }
+
+ locallist.swap(u->invites);
+ ServerInstance->Logs->Log("INVITATION", DEBUG, "Invitation::Find result=%p", (void*) result);
+ return result;
+}
+
+Invitation::~Invitation()
+{
+ // Remove this entry from both lists
+ InviteList::iterator it = std::find(chan->invites.begin(), chan->invites.end(), this);
+ if (it != chan->invites.end())
+ chan->invites.erase(it);
+ it = std::find(user->invites.begin(), user->invites.end(), this);
+ if (it != user->invites.end())
+ user->invites.erase(it);
+}
+
+void InviteBase::ClearInvites()
+{
+ ServerInstance->Logs->Log("INVITEBASE", DEBUG, "InviteBase::ClearInvites %p", (void*) this);
+ InviteList locallist;
+ locallist.swap(invites);
+ for (InviteList::const_iterator i = locallist.begin(); i != locallist.end(); ++i)
+ {
+ (*i)->cull();
+ delete *i;
+ }
+}
diff --git a/src/commands/cmd_invite.cpp b/src/commands/cmd_invite.cpp
index 3baa9cb03..200cce4a3 100644
--- a/src/commands/cmd_invite.cpp
+++ b/src/commands/cmd_invite.cpp
@@ -132,10 +132,10 @@ CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, Use
{
// pinched from ircu - invite with not enough parameters shows channels
// youve been invited to but haven't joined yet.
- InvitedList* il = IS_LOCAL(user)->GetInviteList();
- for (InvitedList::iterator i = il->begin(); i != il->end(); i++)
+ InviteList& il = IS_LOCAL(user)->GetInviteList();
+ for (InviteList::const_iterator i = il.begin(); i != il.end(); ++i)
{
- user->WriteNumeric(RPL_INVITELIST, "%s :%s",user->nick.c_str(),i->first.c_str());
+ user->WriteNumeric(RPL_INVITELIST, "%s :%s",user->nick.c_str(), (*i)->chan->name.c_str());
}
user->WriteNumeric(RPL_ENDOFINVITELIST, "%s :End of INVITE list",user->nick.c_str());
}
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 005a11dd7..cf8c22633 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -220,6 +220,7 @@ void InspIRCd::RehashUsersAndChans()
for (std::vector<LocalUser*>::const_iterator i = Users->local_users.begin(); i != Users->local_users.end(); i++)
{
(**i).already_sent = 0;
+ (**i).RemoveExpiredInvites();
}
}
diff --git a/src/modules/m_spanningtree/fjoin.cpp b/src/modules/m_spanningtree/fjoin.cpp
index 50775be1d..929ace474 100644
--- a/src/modules/m_spanningtree/fjoin.cpp
+++ b/src/modules/m_spanningtree/fjoin.cpp
@@ -105,6 +105,7 @@ CmdResult CommandFJoin::Handle(const std::vector<std::string>& params, User *src
// while the name is equal in case-insensitive compare, it might differ in case; use the remote version
chan->name = channel;
chan->age = TS;
+ chan->ClearInvites();
param_list.push_back(channel);
this->RemoveStatus(ServerInstance->FakeClient, param_list);
}
diff --git a/src/users.cpp b/src/users.cpp
index 39be81272..020c1a9bf 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -333,75 +333,45 @@ const std::string& User::GetFullRealHost()
bool LocalUser::IsInvited(const irc::string &channel)
{
- time_t now = ServerInstance->Time();
- InvitedList::iterator safei;
- for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++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;
- }
- }
- return false;
+ Channel* chan = ServerInstance->FindChan(channel.c_str());
+ if (!chan)
+ return false;
+
+ return (Invitation::Find(chan, this) != NULL);
}
-InvitedList* LocalUser::GetInviteList()
+InviteList& LocalUser::GetInviteList()
{
- time_t now = ServerInstance->Time();
- /* 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;
+ RemoveExpiredInvites();
+ return invites;
}
void LocalUser::InviteTo(const irc::string &channel, time_t invtimeout)
{
- time_t now = ServerInstance->Time();
- if (invtimeout != 0 && now > invtimeout) 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 && invtimeout > i->second)
- {
- i->second = invtimeout;
- }
-
- return;
- }
- }
- invites.push_back(std::make_pair(channel, invtimeout));
+ Channel* chan = ServerInstance->FindChan(channel.c_str());
+ if (chan)
+ Invitation::Create(chan, this, invtimeout);
}
void LocalUser::RemoveInvite(const irc::string &channel)
{
- for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
+ Channel* chan = ServerInstance->FindChan(channel.c_str());
+ if (chan)
{
- if (channel == i->first)
+ Invitation* inv = Invitation::Find(chan, this);
+ if (inv)
{
- invites.erase(i);
- return;
- }
+ inv->cull();
+ delete inv;
+ }
}
}
+void LocalUser::RemoveExpiredInvites()
+{
+ Invitation::Find(NULL, this);
+}
+
bool User::HasModePermission(unsigned char, ModeType)
{
return true;
@@ -560,8 +530,6 @@ CullResult User::cull()
ServerInstance->Users->QuitUser(this, "Culled without QuitUser");
PurgeEmptyChannels();
- this->InvalidateCache();
-
if (client_sa.sa.sa_family != AF_UNSPEC)
ServerInstance->Users->RemoveCloneCounts(this);
@@ -576,6 +544,7 @@ CullResult LocalUser::cull()
else
ServerInstance->Logs->Log("USERS", DEBUG, "Failed to remove user from vector");
+ ClearInvites();
eh.cull();
return User::cull();
}