#include "inspircd.h"
#include <stdarg.h>
-#include "configreader.h"
-#include "users.h"
-#include "modules.h"
#include "wildcard.h"
#include "mode.h"
void chanrec::SetDefaultModes()
{
irc::spacesepstream list(ServerInstance->Config->DefaultModes);
- std::string modeseq = list.GetToken();
+ std::string modeseq;
+ std::string parameter;
+
+ list.GetToken(modeseq);
for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
{
ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
if (mode)
{
- this->SetMode(*n, true);
if (mode->GetNumParams(true))
- this->SetModeParam(*n, list.GetToken().c_str(), true);
+ list.GetToken(parameter);
+ else
+ parameter.clear();
+
+ mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
}
}
}
if (!user || !cn)
return NULL;
- bool new_channel = false;
char cname[MAXBUF];
int MOD_RESULT = 0;
- strlcpy(cname,cn,CHANMAX);
-
std::string privs;
+ chanrec *Ptr;
- chanrec* Ptr = Instance->FindChan(cname);
+ /*
+ * We don't restrict the number of channels that remote users or users that are override-joining may be in.
+ * We restrict local users to MaxChans channels.
+ * We restrict local operators to OperMaxChans channels.
+ * This is a lot more logical than how it was formerly. -- w00t
+ */
+ if (IS_LOCAL(user) && !override)
+ {
+ if (user->GetMaxChans())
+ {
+ if (user->chans.size() >= user->GetMaxChans())
+ {
+ user->WriteServ("405 %s %s :You are on too many channels",user->nick, cn);
+ return NULL;
+ }
+ }
+ else
+ {
+ if (IS_OPER(user))
+ {
+ if (user->chans.size() >= Instance->Config->OperMaxChans)
+ {
+ user->WriteServ("405 %s %s :You are on too many channels",user->nick, cn);
+ return NULL;
+ }
+ }
+ else
+ {
+ if (user->chans.size() >= Instance->Config->MaxChans)
+ {
+ user->WriteServ("405 %s %s :You are on too many channels",user->nick, cn);
+ return NULL;
+ }
+ }
+ }
+ }
+
+ strlcpy(cname, cn, CHANMAX);
+ Ptr = Instance->FindChan(cname);
if (!Ptr)
{
- if ((!IS_LOCAL(user)) && (!TS))
- Instance->Log(DEBUG,"*** BUG *** chanrec::JoinUser called for REMOTE user '%s' on channel '%s' but no TS given!", user->nick, cn);
-
- privs = "@";
+ /*
+ * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t
+ */
+ if (!IS_LOCAL(user))
+ {
+ if (!TS)
+ Instance->Log(DEBUG,"*** BUG *** chanrec::JoinUser called for REMOTE user '%s' on channel '%s' but no TS given!", user->nick, cn);
+ }
+ else
+ {
+ privs = "@";
+ }
if (IS_LOCAL(user) && override == false)
{
*Ptr->topic = 0;
*Ptr->setby = 0;
Ptr->topicset = 0;
- new_channel = true;
}
else
{
}
}
}
- if (Ptr->modes[CM_INVITEONLY])
+ if (Ptr->IsModeSet('i'))
{
MOD_RESULT = 0;
FOREACH_RESULT_I(Instance,I_OnCheckInvite,OnCheckInvite(user, Ptr));
if (!MOD_RESULT)
{
- if (user->IsInvited(Ptr->name))
- {
- /* user was invited to channel */
- /* there may be an optional channel NOTICE here */
- }
- else
+ if (!user->IsInvited(Ptr->name))
{
user->WriteServ("473 %s %s :Cannot join channel (Invite only)",user->nick, Ptr->name);
return NULL;
}
}
- /* NOTE: If the user is an oper here, we can extend their user->chans by up to
- * OperMaxchans. For remote users which are not bound by the channel limits,
- * we can extend infinitely. Otherwise, nope, youre restricted to MaxChans.
- */
- if (!IS_LOCAL(user) || override == true)
- {
- return chanrec::ForceChan(Instance, Ptr, user, privs);
- }
- else if (IS_OPER(user))
- {
- /* Oper allows extension up to the OperMaxchans value */
- if (user->chans.size() < Instance->Config->OperMaxChans)
- {
- return chanrec::ForceChan(Instance, Ptr, user, privs);
- }
- }
- else if (user->chans.size() < Instance->Config->MaxChans)
- {
- return chanrec::ForceChan(Instance, Ptr, user, privs);
- }
-
-
- user->WriteServ("405 %s %s :You are on too many channels",user->nick, cname);
-
- if (new_channel)
- {
- /* Things went seriously pear shaped, so take this away. bwahaha. */
- chan_hash::iterator n = Instance->chanlist->find(cname);
- if (n != Instance->chanlist->end())
- {
- Ptr->DelUser(user);
- DELETE(Ptr);
- Instance->chanlist->erase(n);
- }
- }
-
- return NULL;
+ return chanrec::ForceChan(Instance, Ptr, user, privs);
}
chanrec* chanrec::ForceChan(InspIRCd* Instance, chanrec* Ptr, userrec* user, const std::string &privs)
{
- userrec* dummyuser = new userrec(Instance);
std::string nick = user->nick;
bool silent = false;
- dummyuser->SetFd(FD_MAGIC_NUMBER);
Ptr->AddUser(user);
/* Just in case they have no permissions */
{
Ptr->SetPrefix(user, status, mh->GetPrefixRank(), true);
/* Make sure that the mode handler knows this mode was now set */
- mh->OnModeChange(dummyuser, dummyuser, Ptr, nick, true);
+ mh->OnModeChange(Instance->FakeClient, Instance->FakeClient, Ptr, nick, true);
switch (mh->GetPrefix())
{
}
}
- delete dummyuser;
-
FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(user, Ptr, silent));
if (!silent)
if(this->modes[n])
{
*offset++ = n + 65;
- extparam = "";
+ extparam.clear();
switch (n)
{
case CM_KEY:
extparam = this->GetModeParameter(n + 65);
break;
}
- if (extparam != "")
+ if (!extparam.empty())
{
charlcat(sparam,' ',MAXBUF);
strlcat(sparam,extparam.c_str(),MAXBUF);
if (MOD_RESULT == 1)
return;
- dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, this->name);
+ dlen = curlen = snprintf(list,MAXBUF,"353 %s %c %s :", user->nick, this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name);
int numusers = 0;
char* ptr = list + dlen;
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- if ((!has_user) && (i->first->modes[UM_INVISIBLE]))
+ if ((!has_user) && (i->first->IsModeSet('i')))
{
/*
* user is +i, and source not on the channel, does not show
user->WriteServ(std::string(list));
/* reset our lengths */
- dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, this->name);
+ dlen = curlen = snprintf(list,MAXBUF,"353 %s %c %s :", user->nick, this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name);
ptr = list + dlen;
ptrlen = 0;