return memb;
}
-unsigned long Channel::DelUser(User* user)
+void Channel::DelUser(User* user)
{
UserMembIter a = userlist.find(user);
if (a != userlist.end())
{
+ a->second->cull();
delete a->second;
userlist.erase(a);
}
- return userlist.size();
+ if (userlist.empty())
+ {
+ ModResult res;
+ FIRST_MOD_RESULT(OnChannelPreDelete, res, (this));
+ if (res == MOD_RES_DENY)
+ return;
+ chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
+ /* kill the record */
+ if (iter != ServerInstance->chanlist->end())
+ {
+ FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
+ ServerInstance->chanlist->erase(iter);
+ }
+ ServerInstance->GlobalCulls.AddItem(this);
+ }
}
bool Channel::HasUser(User* user)
void Channel::SetDefaultModes()
{
- ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s", ServerInstance->Config->DefaultModes);
+ ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s",
+ ServerInstance->Config->DefaultModes.c_str());
irc::spacesepstream list(ServerInstance->Config->DefaultModes);
std::string modeseq;
std::string parameter;
* remove a channel from a users record, and return the number of users left.
* Therefore, if this function returns 0 the caller should delete the Channel.
*/
-long Channel::PartUser(User *user, std::string &reason)
+void Channel::PartUser(User *user, std::string &reason)
{
if (!user)
- return this->GetUserCounter();
+ return;
Membership* memb = GetUser(user);
this->RemoveAllPrefixes(user);
}
- if (!this->DelUser(user)) /* if there are no users left on the channel... */
- {
- chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
- /* kill the record */
- if (iter != ServerInstance->chanlist->end())
- {
- ModResult res;
- FIRST_MOD_RESULT(OnChannelPreDelete, res, (this));
- if (res == MOD_RES_DENY)
- return 1; // delete halted by module
- FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
- ServerInstance->chanlist->erase(iter);
- }
- return 0;
- }
-
- return this->GetUserCounter();
+ this->DelUser(user);
}
-long Channel::ServerKickUser(User* user, const char* reason, const char* servername)
+void Channel::ServerKickUser(User* user, const char* reason, const std::string& servername)
{
- if (servername == NULL || *ServerInstance->Config->HideWhoisServer)
- servername = ServerInstance->Config->ServerName;
+ if (servername.empty() || !ServerInstance->Config->HideWhoisServer.empty())
+ ServerInstance->FakeClient->server = ServerInstance->Config->ServerName;
+ else
+ ServerInstance->FakeClient->server = servername;
- ServerInstance->FakeClient->server = servername;
- return this->KickUser(ServerInstance->FakeClient, user, reason);
+ KickUser(ServerInstance->FakeClient, user, reason);
}
-long Channel::KickUser(User *src, User *user, const char* reason)
+void Channel::KickUser(User *src, User *user, const char* reason)
{
if (!src || !user || !reason)
- return this->GetUserCounter();
+ return;
Membership* memb = GetUser(user);
if (IS_LOCAL(src))
if (!memb)
{
src->WriteNumeric(ERR_USERNOTINCHANNEL, "%s %s %s :They are not on that channel",src->nick.c_str(), user->nick.c_str(), this->name.c_str());
- return this->GetUserCounter();
+ return;
}
if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
{
src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :Only a u-line may kick a u-line from a channel.",src->nick.c_str(), this->name.c_str());
- return this->GetUserCounter();
+ return;
}
ModResult res;
FIRST_MOD_RESULT(OnUserPreKick, res, (src,memb,reason));
if (res == MOD_RES_DENY)
- return this->GetUserCounter();
+ return;
if (res == MOD_RES_PASSTHRU)
{
if ((them < HALFOP_VALUE) || (them < us))
{
src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",src->nick.c_str(), this->name.c_str(), them >= HALFOP_VALUE ? "" : "half-");
- return this->GetUserCounter();
+ return;
}
}
}
this->RemoveAllPrefixes(user);
}
- if (!this->DelUser(user))
- /* if there are no users left on the channel */
- {
- chan_hash::iterator iter = ServerInstance->chanlist->find(this->name.c_str());
-
- /* kill the record */
- if (iter != ServerInstance->chanlist->end())
- {
- ModResult res;
- FIRST_MOD_RESULT(OnChannelPreDelete, res, (this));
- if (res == MOD_RES_DENY)
- return 1; // delete halted by module
- FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
- ServerInstance->chanlist->erase(iter);
- }
- return 0;
- }
-
- return this->GetUserCounter();
+ this->DelUser(user);
}
void Channel::WriteChannel(User* user, const char* text, ...)
}
}
-void Channel::WriteChannelWithServ(const char* ServName, const char* text, ...)
+void Channel::WriteChannelWithServ(const std::string& ServName, const char* text, ...)
{
char textbuffer[MAXBUF];
va_list argsPtr;
this->WriteChannelWithServ(ServName, std::string(textbuffer));
}
-void Channel::WriteChannelWithServ(const char* ServName, const std::string &text)
+void Channel::WriteChannelWithServ(const std::string& ServName, const std::string &text)
{
char tb[MAXBUF];
- snprintf(tb,MAXBUF,":%s %s", ServName ? ServName : ServerInstance->Config->ServerName, text.c_str());
+ snprintf(tb,MAXBUF,":%s %s", ServName.empty() ? ServerInstance->Config->ServerName.c_str() : ServName.c_str(), text.c_str());
std::string out = tb;
for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
{
char tb[MAXBUF];
- snprintf(tb,MAXBUF,":%s %s", serversource ? ServerInstance->Config->ServerName : user->GetFullHost().c_str(), text.c_str());
+ snprintf(tb,MAXBUF,":%s %s", serversource ? ServerInstance->Config->ServerName.c_str() : user->GetFullHost().c_str(), text.c_str());
std::string out = tb;
this->RawWriteAllExcept(user, serversource, status, except_list, std::string(tb));