summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/channels.h111
-rw-r--r--include/modules.h7
-rw-r--r--src/channels.cpp37
-rw-r--r--src/cmd_join.cpp4
-rw-r--r--src/modules.cpp5
-rw-r--r--src/modules/m_operjoin.cpp4
-rw-r--r--src/modules/m_redirect.cpp2
-rw-r--r--src/modules/m_sajoin.cpp2
-rw-r--r--src/modules/m_spanningtree.cpp4
9 files changed, 81 insertions, 95 deletions
diff --git a/include/channels.h b/include/channels.h
index 906297104..effb65873 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -38,6 +38,7 @@ enum ChannelModes {
};
class userrec;
+class chanrec;
/** Holds an entry for a ban list, exemption list, or invite list.
* This class contains a single element in a channel list, such as a banlist.
@@ -96,12 +97,55 @@ typedef CUList::const_iterator CUListConstIter;
*/
typedef std::map<char,char*> CustomModeList;
+
+/** used to hold a channel and a users modes on that channel, e.g. +v, +h, +o
+ * needs to come AFTER struct chanrec */
+enum UserChannelModes {
+ UCMODE_OP = 1,
+ UCMODE_VOICE = 2,
+ UCMODE_HOP = 4
+};
+
+/** Holds a user's modes on a channel
+ * This class associates a users privilages with a channel by creating a pointer link between
+ * a userrec and chanrec class. The uc_modes member holds a bitmask of which privilages the user
+ * has on the channel, such as op, voice, etc.
+ */
+class ucrec : public classbase
+{
+ public:
+ /** Contains a bitmask of the UCMODE_OP ... UCMODE_FOUNDER values.
+ * If this value is zero, the user has no privilages upon the channel.
+ */
+ char uc_modes;
+
+ /** Points to the channel record where the given modes apply.
+ * If the record is not in use, this value will be NULL.
+ */
+ chanrec *channel;
+
+ /** Constructor for ucrec
+ */
+ ucrec() : uc_modes(0), channel(NULL) { /* stub */ }
+
+ /** Destructor for ucrec
+ */
+ virtual ~ucrec() { /* stub */ }
+};
+
+
/** Holds all relevent information for a channel.
* This class represents a channel, and contains its name, modes, time created, topic, topic set time,
* etc, and an instance of the BanList type.
*/
class chanrec : public Extensible
{
+ private:
+
+ /** Connect a chanrec to a userrec
+ */
+ static chanrec* ForceChan(chanrec* Ptr,ucrec *a,userrec* user, int created);
+
public:
/** The channels name.
*/
@@ -245,7 +289,7 @@ class chanrec : public Extensible
*/
chanrec();
- /* Make src kick user from this channel with the given reason.
+ /** Make src kick user from this channel with the given reason.
* @param src The source of the kick
* @param user The user being kicked (must be on this channel)
* @param reason The reason for the kick
@@ -254,16 +298,16 @@ class chanrec : public Extensible
*/
long KickUser(userrec *src, userrec *user, const char* reason);
- /* Make the server kick user from this channel with the given reason.
- * @param user The user being kicked (must be on this channel)
- * @param reason The reason for the kick
- * @param triggerevents True if you wish this kick to trigger module events
- * @return The number of users left on the channel. If this is zero
- * when the method returns, you MUST delete the chanrec immediately!
+ /** Make the server kick user from this channel with the given reason.
+ * @param user The user being kicked (must be on this channel)
+ * @param reason The reason for the kick
+ * @param triggerevents True if you wish this kick to trigger module events
+ * @return The number of users left on the channel. If this is zero
+ * when the method returns, you MUST delete the chanrec immediately!
*/
long ServerKickUser(userrec* user, const char* reason, bool triggerevents);
- /* Part a user from this channel with the given reason.
+ /** Part a user from this channel with the given reason.
* If the reason field is NULL, no reason will be sent.
* @param user The user who is parting (must be on this channel)
* @param reason The (optional) part reason
@@ -272,49 +316,20 @@ class chanrec : public Extensible
*/
long PartUser(userrec *user, const char* reason = NULL);
- /** Destructor for chanrec
+ /* Join a user to a channel. May be a channel that doesnt exist yet.
+ * @param user The user to join to the channel.
+ * @param cn The channel name to join to. Does not have to exist.
+ * @param key The key of the channel, if given
+ * @param override If true, override all join restrictions such as +bkil
+ * @return A pointer to the chanrec the user was joined to. A new chanrec may have
+ * been created if the channel did not exist before the user was joined to it.
+ * If the user could not be joined to a channel, the return value may be NULL.
*/
- virtual ~chanrec() { /* stub */ }
-};
+ static chanrec* JoinUser(userrec *user, const char* cn, bool override, const char* key = "");
-/** used to hold a channel and a users modes on that channel, e.g. +v, +h, +o
- * needs to come AFTER struct chanrec */
-enum UserChannelModes {
- UCMODE_OP = 1,
- UCMODE_VOICE = 2,
- UCMODE_HOP = 4
-};
-
-/** Holds a user's modes on a channel
- * This class associates a users privilages with a channel by creating a pointer link between
- * a userrec and chanrec class. The uc_modes member holds a bitmask of which privilages the user
- * has on the channel, such as op, voice, etc.
- */
-class ucrec : public classbase
-{
- public:
- /** Contains a bitmask of the UCMODE_OP ... UCMODE_FOUNDER values.
- * If this value is zero, the user has no privilages upon the channel.
- */
- char uc_modes;
-
- /** Points to the channel record where the given modes apply.
- * If the record is not in use, this value will be NULL.
- */
- chanrec *channel;
-
- /** Constructor for ucrec
- */
- ucrec() : uc_modes(0), channel(NULL) { /* stub */ }
-
- /** Destructor for ucrec
+ /** Destructor for chanrec
*/
- virtual ~ucrec() { /* stub */ }
+ virtual ~chanrec() { /* stub */ }
};
-chanrec* add_channel(userrec *user, const char* cn, const char* key, bool override);
-//chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool local);
-//void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason);
-//void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool triggerevents);
-
#endif
diff --git a/include/modules.h b/include/modules.h
index 39265fcee..ebd810c41 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -1513,13 +1513,6 @@ class Server : public Extensible
*/
virtual void SendToModeMask(const std::string &modes, int flags, const std::string &text);
- /** Forces a user to join a channel.
- * This is similar to svsjoin and can be used to implement redirection, etc.
- * On success, the return value is a valid pointer to a chanrec* of the channel the user was joined to.
- * On failure, the result is NULL.
- */
- virtual chanrec* JoinUserToChannel(userrec* user, const std::string &cname, const std::string &key);
-
/** Forces a user nickchange.
* This command works similarly to SVSNICK, and can be used to implement Q-lines etc.
* If you specify an invalid nickname, the nick change will be dropped and the target user will receive
diff --git a/src/channels.cpp b/src/channels.cpp
index 6d8cb756f..caae1a714 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -46,9 +46,6 @@ extern std::vector<ircd_module*> factory;
extern time_t TIME;
extern chan_hash chanlist;
-
-chanrec* ForceChan(chanrec* Ptr,ucrec *a,userrec* user, int created);
-
chanrec::chanrec()
{
*name = *topic = *setby = *key = 0;
@@ -219,22 +216,15 @@ CUList* chanrec::GetVoicedUsers()
* add a channel to a user, creating the record for it if needed and linking
* it to the user record
*/
-
-chanrec* add_channel(userrec *user, const char* cn, const char* key, bool override)
+chanrec* chanrec::JoinUser(userrec *user, const char* cn, bool override, const char* key)
{
- if ((!user) || (!cn))
- {
- log(DEFAULT,"*** BUG *** add_channel was given an invalid parameter");
- return 0;
- }
+ if (!user || !cn)
+ return NULL;
int created = 0;
char cname[MAXBUF];
int MOD_RESULT = 0;
strlcpy(cname,cn,CHANMAX);
- log(DEBUG,"cname='%s' cn='%s'",cname,cn);
-
- log(DEBUG,"add_channel: %s %s",user->nick,cname);
chanrec* Ptr = FindChan(cname);
@@ -258,7 +248,7 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
strlcpy(chanlist[cname]->setby, user->nick,NICKMAX-1);
chanlist[cname]->topicset = 0;
Ptr = chanlist[cname];
- log(DEBUG,"add_channel: created: %s",cname);
+ log(DEBUG,"chanrec::JoinUser(): created: %s",cname);
/*
* set created to 2 to indicate user
* is the first in the channel
@@ -294,7 +284,7 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
{
if (!key)
{
- log(DEBUG,"add_channel: no key given in JOIN");
+ log(DEBUG,"chanrec::JoinUser(): no key given in JOIN");
WriteServ(user->fd,"475 %s %s :Cannot join channel (Requires key)",user->nick, Ptr->name);
return NULL;
}
@@ -302,7 +292,7 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
{
if (strcmp(key,Ptr->key))
{
- log(DEBUG,"add_channel: bad key given in JOIN");
+ log(DEBUG,"chanrec::JoinUser(): bad key given in JOIN");
WriteServ(user->fd,"475 %s %s :Cannot join channel (Incorrect key)",user->nick, Ptr->name);
return NULL;
}
@@ -316,7 +306,6 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
FOREACH_RESULT(I_OnCheckInvite,OnCheckInvite(user, Ptr));
if (!MOD_RESULT)
{
- log(DEBUG,"add_channel: channel is +i");
if (user->IsInvited(xname))
{
/* user was invited to channel */
@@ -345,7 +334,6 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
}
if (Ptr->bans.size())
{
- log(DEBUG,"add_channel: about to walk banlist");
MOD_RESULT = 0;
FOREACH_RESULT(I_OnCheckBan,OnCheckBan(user, Ptr));
char mask[MAXBUF];
@@ -370,18 +358,16 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
}
else
{
- log(DEBUG,"Overridden checks");
+ log(DEBUG,"chanrec::JoinUser(): Overridden checks");
}
created = 1;
}
- log(DEBUG,"Passed channel checks");
-
for (UserChanList::const_iterator index = user->chans.begin(); index != user->chans.end(); index++)
{
if ((*index)->channel == NULL)
{
- return ForceChan(Ptr, *index, user, created);
+ return chanrec::ForceChan(Ptr, *index, user, created);
}
}
@@ -393,7 +379,7 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
if (!IS_LOCAL(user)) /* was a check on fd < 0 */
{
ucrec* a = new ucrec();
- chanrec* c = ForceChan(Ptr,a,user,created);
+ chanrec* c = chanrec::ForceChan(Ptr,a,user,created);
user->chans.push_back(a);
return c;
}
@@ -403,13 +389,12 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
if (user->chans.size() < OPERMAXCHANS)
{
ucrec* a = new ucrec();
- chanrec* c = ForceChan(Ptr,a,user,created);
+ chanrec* c = chanrec::ForceChan(Ptr,a,user,created);
user->chans.push_back(a);
return c;
}
}
- log(DEBUG,"add_channel: user channel max exceeded: %s %s",user->nick,cname);
WriteServ(user->fd,"405 %s %s :You are on too many channels",user->nick, cname);
if (created == 2)
@@ -446,7 +431,7 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
return NULL;
}
-chanrec* ForceChan(chanrec* Ptr,ucrec *a,userrec* user, int created)
+chanrec* chanrec::ForceChan(chanrec* Ptr,ucrec *a,userrec* user, int created)
{
if (created == 2)
{
diff --git a/src/cmd_join.cpp b/src/cmd_join.cpp
index 728038c2e..4af887585 100644
--- a/src/cmd_join.cpp
+++ b/src/cmd_join.cpp
@@ -31,7 +31,7 @@ void cmd_join::Handle (const char** parameters, int pcnt, userrec *user)
if (IsValidChannelName(parameters[0]))
{
- add_channel(user, parameters[0], parameters[1], false);
+ chanrec::JoinUser(user, parameters[0], false, parameters[1]);
return;
}
}
@@ -42,7 +42,7 @@ void cmd_join::Handle (const char** parameters, int pcnt, userrec *user)
if (IsValidChannelName(parameters[0]))
{
- add_channel(user, parameters[0], "", false);
+ chanrec::JoinUser(user, parameters[0], false);
return;
}
}
diff --git a/src/modules.cpp b/src/modules.cpp
index a171e427f..d012d2c71 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -400,11 +400,6 @@ void Server::SendToModeMask(const std::string &modes, int flags, const std::stri
WriteMode(modes.c_str(),flags,"%s",text.c_str());
}
-chanrec* Server::JoinUserToChannel(userrec* user, const std::string &cname, const std::string &key)
-{
- return add_channel(user,cname.c_str(),key.c_str(),false);
-}
-
chanuserlist Server::GetUsers(chanrec* chan)
{
chanuserlist userl;
diff --git a/src/modules/m_operjoin.cpp b/src/modules/m_operjoin.cpp
index a0a81f7ed..bf3088053 100644
--- a/src/modules/m_operjoin.cpp
+++ b/src/modules/m_operjoin.cpp
@@ -72,9 +72,7 @@ class ModuleOperjoin : public Module
std::vector<std::string> operChans;
tokenize(operChan,operChans);
for(std::vector<std::string>::iterator it = operChans.begin(); it != operChans.end(); it++)
- {
- Srv->JoinUserToChannel(user,(*it),"");
- }
+ chanrec::JoinUser(user, it->c_str(), false);
}
}
diff --git a/src/modules/m_redirect.cpp b/src/modules/m_redirect.cpp
index a30073355..bbddb0f18 100644
--- a/src/modules/m_redirect.cpp
+++ b/src/modules/m_redirect.cpp
@@ -138,7 +138,7 @@ class ModuleRedirect : public Module
{
std::string channel = chan->GetModeParameter('L');
WriteServ(user->fd,"470 %s :%s has become full, so you are automatically being transferred to the linked channel %s",user->nick,cname,channel.c_str());
- Srv->JoinUserToChannel(user,channel.c_str(),"");
+ chanrec::JoinUser(user, channel.c_str(), false);
return 1;
}
}
diff --git a/src/modules/m_sajoin.cpp b/src/modules/m_sajoin.cpp
index a94e03958..0c7387213 100644
--- a/src/modules/m_sajoin.cpp
+++ b/src/modules/m_sajoin.cpp
@@ -54,7 +54,7 @@ class cmd_sajoin : public command_t
}
Srv->SendOpers(std::string(user->nick)+" used SAJOIN to make "+std::string(dest->nick)+" join "+parameters[1]);
- Srv->JoinUserToChannel(dest,std::string(parameters[1]),std::string(dest->nick));
+ chanrec::JoinUser(dest, parameters[1], true);
}
}
};
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp
index d3f8e9a21..d8292a669 100644
--- a/src/modules/m_spanningtree.cpp
+++ b/src/modules/m_spanningtree.cpp
@@ -1430,7 +1430,7 @@ class TreeSocket : public InspSocket
who = Srv->FindNick(usr);
if (who)
{
- Srv->JoinUserToChannel(who,channel,key);
+ chanrec::JoinUser(who, channel.c_str(), true, key);
if (modectr >= (MAXMODES-1))
{
/* theres a mode for this user. push them onto the mode queue, and flush it
@@ -2030,7 +2030,7 @@ class TreeSocket : public InspSocket
if (u)
{
- Srv->JoinUserToChannel(u,params[1],"");
+ chanrec::JoinUser(u, params[1].c_str(), false);
DoOneToAllButSender(prefix,"SVSJOIN",params,prefix);
}
return true;