* ---------------------------------------------------
*/
-#include <stdarg.h>
-#include "configreader.h"
#include "inspircd.h"
-#include "users.h"
-#include "modules.h"
+#include <stdarg.h>
#include "wildcard.h"
#include "mode.h"
void chanrec::AddUser(userrec* user)
{
- internal_userlist[user] = user;
+ internal_userlist[user] = user->nick;
}
unsigned long chanrec::DelUser(userrec* user)
void chanrec::AddOppedUser(userrec* user)
{
- internal_op_userlist[user] = user;
+ internal_op_userlist[user] = user->nick;
}
void chanrec::DelOppedUser(userrec* user)
void chanrec::AddHalfoppedUser(userrec* user)
{
- internal_halfop_userlist[user] = user;
+ internal_halfop_userlist[user] = user->nick;
}
void chanrec::DelHalfoppedUser(userrec* user)
void chanrec::AddVoicedUser(userrec* user)
{
- internal_voice_userlist[user] = user;
+ internal_voice_userlist[user] = user->nick;
}
void chanrec::DelVoicedUser(userrec* user)
return &internal_voice_userlist;
}
+void chanrec::SetDefaultModes()
+{
+ irc::spacesepstream list(ServerInstance->Config->DefaultModes);
+ 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)
+ {
+ if (mode->GetNumParams(true))
+ list.GetToken(parameter);
+ else
+ parameter.clear();
+
+ mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
+ }
+ }
+}
+
/*
* add a channel to a user, creating the record for it if needed and linking
* it to the user record
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;
+
+ /*
+ * 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;
+ }
+ }
+ }
+ }
- chanrec* Ptr = Instance->FindChan(cname);
+ 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)
{
/* As spotted by jilles, dont bother to set this on remote users */
if (IS_LOCAL(user))
- Ptr->modes[CM_TOPICLOCK] = Ptr->modes[CM_NOEXTERNAL] = 1;
+ Ptr->SetDefaultModes();
Ptr->created = TS ? TS : Instance->Time();
+ Ptr->age = Ptr->created;
*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 (*user->oper)
- {
- /* 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)
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- if (IS_LOCAL(i->second))
- i->second->Write(out);
+ if (IS_LOCAL(i->first))
+ i->first->Write(out);
}
}
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- if (IS_LOCAL(i->second))
- i->second->Write(out);
+ if (IS_LOCAL(i->first))
+ i->first->Write(out);
}
}
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- if ((IS_LOCAL(i->second)) && (except_list.find(i->second) == except_list.end()))
+ if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end()))
{
if (serversource)
- i->second->WriteServ(text);
+ i->first->WriteServ(text);
else
- i->second->Write(out);
+ i->first->Write(out);
}
}
}
void chanrec::WriteAllExceptSender(userrec* user, bool serversource, char status, const std::string& text)
{
CUList except_list;
- except_list[user] = user;
+ except_list[user] = user->nick;
this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
}
CUList *ulist= this->GetUsers();
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- if (!(i->second->modes[UM_INVISIBLE]))
+ if (!(i->first->IsModeSet('i')))
count++;
}
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);
/* compile a userlist of a channel into a string, each nick seperated by
* spaces and op, voice etc status shown as @ and +, and send it to 'user'
*/
-void chanrec::UserList(userrec *user)
+void chanrec::UserList(userrec *user, CUList *ulist)
{
char list[MAXBUF];
size_t dlen, curlen;
if (!IS_LOCAL(user))
return;
- FOREACH_RESULT(I_OnUserList,OnUserList(user, this));
+ FOREACH_RESULT(I_OnUserList,OnUserList(user, this, ulist));
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;
- CUList *ulist= this->GetUsers();
+ if (!ulist)
+ ulist = this->GetUsers();
/* Improvement by Brain - this doesnt change in value, so why was it inside
* the loop?
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- if ((!has_user) && (i->second->modes[UM_INVISIBLE]))
+ if ((!has_user) && (i->first->IsModeSet('i')))
{
/*
* user is +i, and source not on the channel, does not show
continue;
}
- size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", this->GetPrefixChar(i->second), i->second->nick);
+ if (i->first->Visibility && !i->first->Visibility->VisibleTo(user))
+ continue;
+
+ size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", this->GetPrefixChar(i->first), i->second.c_str());
+ /* OnUserList can change this - reset it back to normal */
+ i->second = i->first->nick;
curlen += ptrlen;
ptr += ptrlen;
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;