Anope IRC Services  Version 2.0
Public Types | Public Member Functions | Static Public Member Functions | Data Fields | Private Member Functions | Private Attributes
Channel Class Reference

#include <channels.h>

Inheritance diagram for Channel:
Inheritance graph
[legend]
Collaboration diagram for Channel:
Collaboration graph
[legend]

Public Types

typedef std::multimap
< Anope::string, Anope::string
ModeList
 
typedef std::map< User
*, ChanUserContainer * > 
ChanUserList
 

Public Member Functions

 ~Channel ()
 
void Reset ()
 
void Sync ()
 
void CheckModes ()
 
bool CheckDelete ()
 
ChanUserContainerJoinUser (User *u, const ChannelStatus *status)
 
void DeleteUser (User *u)
 
ChanUserContainerFindUser (User *u) const
 
bool HasUserStatus (User *u, ChannelModeStatus *cms)
 
bool HasUserStatus (User *u, const Anope::string &name)
 
size_t HasMode (const Anope::string &name, const Anope::string &param="")
 
void SetModeInternal (MessageSource &source, ChannelMode *cm, const Anope::string &param="", bool enforce_mlock=true)
 
void RemoveModeInternal (MessageSource &source, ChannelMode *cm, const Anope::string &param="", bool enforce_mlock=true)
 
void SetMode (BotInfo *bi, ChannelMode *cm, const Anope::string &param="", bool enforce_mlock=true)
 
void SetMode (BotInfo *bi, const Anope::string &name, const Anope::string &param="", bool enforce_mlock=true)
 
void RemoveMode (BotInfo *bi, ChannelMode *cm, const Anope::string &param="", bool enforce_mlock=true)
 
void RemoveMode (BotInfo *bi, const Anope::string &name, const Anope::string &param="", bool enforce_mlock=true)
 
bool GetParam (const Anope::string &name, Anope::string &target) const
 
void SetModes (BotInfo *bi, bool enforce_mlock, const char *cmodes,...)
 
void SetModesInternal (MessageSource &source, const Anope::string &mode, time_t ts=0, bool enforce_mlock=true)
 
bool MatchesList (User *u, const Anope::string &list)
 
void KickInternal (const MessageSource &source, const Anope::string &nick, const Anope::string &reason)
 
bool Kick (BotInfo *bi, User *u, const char *reason=NULL,...)
 
const ModeListGetModes () const
 
std::pair< ModeList::iterator,
ModeList::iterator > 
GetModeList (const Anope::string &name)
 
Anope::string GetModes (bool complete, bool plus)
 
void ChangeTopicInternal (const Anope::string &user, const Anope::string &newtopic, time_t ts=Anope::CurTime)
 
void ChangeTopic (const Anope::string &user, const Anope::string &newtopic, time_t ts=Anope::CurTime)
 
void SetCorrectModes (User *u, bool give_modes)
 
bool Unban (User *u, const Anope::string &mode, bool full=false)
 
bool CheckKick (User *user)
 
- Public Member Functions inherited from Base
 Base ()
 
virtual ~Base ()
 
void AddReference (ReferenceBase *r)
 
void DelReference (ReferenceBase *r)
 
- Public Member Functions inherited from Extensible
virtual ~Extensible ()
 
template<typename T >
T * GetExt (const Anope::string &name) const
 
bool HasExt (const Anope::string &name) const
 
template<typename T >
T * Extend (const Anope::string &name, const T &what)
 
template<typename T >
T * Extend (const Anope::string &name)
 
template<typename T >
T * Require (const Anope::string &name)
 
template<typename T >
void Shrink (const Anope::string &name)
 
template<>
bool * Extend (const Anope::string &name, const bool &what)
 

Static Public Member Functions

static ChannelFind (const Anope::string &name)
 
static ChannelFindOrCreate (const Anope::string &name, bool &created, time_t ts=Anope::CurTime)
 
- Static Public Member Functions inherited from Extensible
static void ExtensibleSerialize (const Extensible *, const Serializable *, Serialize::Data &data)
 
static void ExtensibleUnserialize (Extensible *, Serializable *, Serialize::Data &data)
 

Data Fields

Anope::string name
 
Serialize::Reference< ChannelInfoci
 
time_t creation_time
 
bool syncing
 
bool botchannel
 
ChanUserList users
 
Anope::string topic
 
Anope::string topic_setter
 
time_t topic_ts
 
time_t topic_time
 
time_t server_modetime
 
time_t chanserv_modetime
 
int16_t server_modecount
 
int16_t chanserv_modecount
 
int16_t bouncy_modes
 
- Data Fields inherited from Extensible
std::set< ExtensibleBase * > extension_items
 

Private Member Functions

 Channel (const Anope::string &nname, time_t ts=Anope::CurTime)
 

Private Attributes

ModeList modes
 

Detailed Description

Definition at line 33 of file channels.h.

Member Typedef Documentation

Definition at line 55 of file channels.h.

Definition at line 36 of file channels.h.

Constructor & Destructor Documentation

Channel::Channel ( const Anope::string nname,
time_t  ts = Anope::CurTime 
)
private

Constructor

Parameters
nameThe channel name
tsThe time the channel was created

Definition at line 31 of file channels.cpp.

References botchannel, bouncy_modes, chanserv_modecount, chanserv_modetime, creation_time, Anope::string::empty(), ChannelInfo::Find(), FOREACH_MOD, Server::IsSynced(), Me, name, server_modecount, server_modetime, syncing, topic_time, and topic_ts.

Referenced by FindOrCreate().

Channel::~Channel ( )

Destructor

Definition at line 53 of file channels.cpp.

References FOREACH_MOD, Server::IsSynced(), Me, name, and ModeManager::StackerDel().

Member Function Documentation

void Channel::ChangeTopic ( const Anope::string user,
const Anope::string newtopic,
time_t  ts = Anope::CurTime 
)

Update the topic of the channel, and reset it if topiclock etc says to

Parameters
userThe user setting the topic
newtopicThe new topic
tsThe time when the new topic is being set

Definition at line 800 of file channels.cpp.

References Anope::CurTime, User::Find(), FOREACH_MOD, IRCD, User::nick, IRCDProto::SendTopic(), topic, topic_setter, topic_time, and topic_ts.

Referenced by CommandCSTopic::Set().

void Channel::ChangeTopicInternal ( const Anope::string user,
const Anope::string newtopic,
time_t  ts = Anope::CurTime 
)

Update the topic of the channel internally, and reset it if topiclock etc says to

Parameters
userThe user setting the new topic
newtopicThe new topic
tsThe time the new topic is being set

Definition at line 786 of file channels.cpp.

References Anope::CurTime, User::Find(), FOREACH_MOD, LOG_DEBUG, name, User::nick, topic, topic_setter, topic_time, and topic_ts.

Referenced by Message::Topic::Run(), IRCDMessageChaninfo::Run(), IRCDMessageTopic::Run(), and IRCDMessageFTopic::Run().

bool Channel::CheckDelete ( )

Check if this channel should be deleted

Definition at line 122 of file channels.cpp.

References EVENT_STOP, FOREACH_RESULT, HasMode(), syncing, and users.

Referenced by DeleteUser(), RemoveModeInternal(), Message::Join::SJoin(), and ChannelInfo::~ChannelInfo().

bool Channel::CheckKick ( User user)

Check whether a user is permitted to be on this channel

Parameters
uThe user
Returns
true if they are allowed, false if they aren't and were kicked

Definition at line 890 of file channels.cpp.

References User::Account(), Anope::string::c_str(), CHAN_NOT_ALLOWED_TO_JOIN, Anope::string::empty(), EVENT_STOP, FOREACH_RESULT, User::IsProtected(), Kick(), LOG_DEBUG, name, User::nick, SetMode(), User::super_admin, and Language::Translate().

Referenced by CommandCSAKick::DoEnforce(), and Message::Join::SJoin().

void Channel::CheckModes ( )
void Channel::DeleteUser ( User u)

Remove a user internally from the channel

Parameters
uThe user

Definition at line 154 of file channels.cpp.

References User::chans, CheckDelete(), User::FindChannel(), FOREACH_MOD, Server::IsSynced(), LOG_DEBUG, name, User::nick, User::Quitting(), User::server, and users.

Referenced by KickInternal(), BotInfo::Part(), Message::Join::Run(), and Message::Part::Run().

Channel * Channel::Find ( const Anope::string name)
static
Channel * Channel::FindOrCreate ( const Anope::string name,
bool &  created,
time_t  ts = Anope::CurTime 
)
static

Finds or creates a channel

Parameters
nameThe channel name
createdSet to true if the channel was just created
tsThe time the channel was created

Definition at line 929 of file channels.cpp.

References Channel(), and name.

Referenced by CommandCSSetPersist::Execute(), CSSet::Persist::ExtensibleUnserialize(), BotInfo::Join(), ChanServCore::OnPreUplinkSync(), IRCDMessageChaninfo::Run(), and Message::Join::SJoin().

ChanUserContainer * Channel::FindUser ( User u) const
std::pair< Channel::ModeList::iterator, Channel::ModeList::iterator > Channel::GetModeList ( const Anope::string name)

Get a list of modes on a channel

Parameters
nameA mode name to get the list of
Returns
a pair of iterators for the beginning and end of the list

Definition at line 243 of file channels.cpp.

References modes.

Referenced by CommandCSAKick::DoAdd(), MyXMLRPCEvent::DoChannel(), CommandCSMode::DoSet(), HasMode(), MatchesList(), WebCPanel::ChanServ::Modes::OnRequest(), RemoveModeInternal(), and Unban().

const Channel::ModeList & Channel::GetModes ( ) const

Get all modes set on this channel, excluding status modes.

Returns
a map of modes and their optional parameters.

Definition at line 238 of file channels.cpp.

References modes.

Referenced by CommandOSChanList::Execute(), CommandOSMode::Execute(), CommandCSSetKeepModes::Execute(), IRC2SQL::OnChannelCreate(), IRC2SQL::OnChannelModeSet(), and Server::Server().

Anope::string Channel::GetModes ( bool  complete,
bool  plus 
)

Get a string of the modes set on this channel

Parameters
completeInclude mode parameters
plusIf set to false (with complete), mode parameters will not be given for modes requring no parameters to be unset
Returns
A mode string

Definition at line 212 of file channels.cpp.

References anope_dynamic_static_cast(), ModeManager::FindChannelModeByName(), Mode::mchar, ChannelModeParam::minus_no_arg, MODE_LIST, MODE_PARAM, modes, and Mode::type.

bool Channel::GetParam ( const Anope::string name,
Anope::string target 
) const

Get a modes parameter for the channel

Parameters
nameThe mode
targeta string to put the param into
Returns
true if the parameter was fetched, false if on error (mode not set) etc.

Definition at line 513 of file channels.cpp.

References Anope::string::clear(), and modes.

Referenced by CommandNSAJoin::DoAdd(), CommandCSEnforce::DoLimit(), CommandCSGetKey::Execute(), NSAJoin::OnUserLogin(), RemoveMode(), and SetMode().

size_t Channel::HasMode ( const Anope::string name,
const Anope::string param = "" 
)
bool Channel::HasUserStatus ( User u,
ChannelModeStatus cms 
)

Check if a user has a status on a channel

Parameters
uThe user
cmsThe status mode, or NULL to represent no status
Returns
true or false

Definition at line 181 of file channels.cpp.

References ChannelStatus::Empty(), User::FindChannel(), ChannelStatus::HasMode(), Mode::mchar, and ChanUserContainer::status.

Referenced by CommandCSRegister::Execute(), HasUserStatus(), RemoveMode(), and SetMode().

bool Channel::HasUserStatus ( User u,
const Anope::string name 
)

Check if a user has a status on a channel Use the overloaded function for ChannelModeStatus* to check for no status

Parameters
uThe user
nameThe mode name, eg CMODE_OP, CMODE_VOICE
Returns
true or false

Definition at line 196 of file channels.cpp.

References ModeManager::FindChannelModeByName(), and HasUserStatus().

ChanUserContainer * Channel::JoinUser ( User u,
const ChannelStatus status 
)

Join a user internally to the channel

Parameters
uThe user
statusThe status to give the user, if any
Returns
The UserContainer for the user

Definition at line 140 of file channels.cpp.

References User::chans, Server::IsSynced(), User::server, ChanUserContainer::status, and users.

Referenced by BotInfo::Join(), and Message::Join::SJoin().

bool Channel::Kick ( BotInfo bi,
User u,
const char *  reason = NULL,
  ... 
)

Kick a user from the channel

Parameters
biThe sender, can be NULL for the service bot for this channel
uThe user being kicked
reasonThe reason for the kick
Returns
true if the kick was scucessful, false if a module blocked the kick

Definition at line 762 of file channels.cpp.

References BUFSIZE, EVENT_STOP, FOREACH_RESULT, IRCD, User::IsProtected(), KickInternal(), User::nick, and IRCDProto::SendKick().

Referenced by BSKick::bot_kick(), CheckKick(), CommandCSEnforce::DoBans(), CommandCSEnforce::DoLimit(), CommandCSEnforce::DoRegOnly(), CommandCSEnforce::DoRestricted(), CommandCSEnforce::DoSSLOnly(), CommandOSKick::Execute(), CommandCSKick::Execute(), CommandCSBan::Execute(), CommandCSSuspend::Execute(), CommandOSForbid::Execute(), and CommandOSSQLine::OnAdd().

void Channel::KickInternal ( const MessageSource source,
const Anope::string nick,
const Anope::string reason 
)

Kick a user from a channel internally

Parameters
sourceThe sender of the kick
nickThe nick being kicked
reasonThe reason for the kick

Definition at line 730 of file channels.cpp.

References DeleteUser(), User::Find(), User::FindChannel(), FOREACH_MOD, MessageSource::GetSource(), MessageSource::GetUser(), LOG_DEBUG, name, User::nick, and ChanUserContainer::status.

Referenced by Kick(), and Message::Kick::Run().

bool Channel::MatchesList ( User u,
const Anope::string list 
)

Does the given user match the given list? (CMODE_BAN, CMODE_EXCEPT, etc, a list mode)

Parameters
uThe user
listThe mode of the list to check (eg CMODE_BAN)
Returns
true if the user matches the list

Definition at line 713 of file channels.cpp.

References GetModeList(), HasMode(), and Entry::Matches().

Referenced by CommandCSEnforce::DoBans(), CommandCSBan::Execute(), and NSAJoin::OnUserLogin().

void Channel::RemoveMode ( BotInfo bi,
ChannelMode cm,
const Anope::string param = "",
bool  enforce_mlock = true 
)
void Channel::RemoveMode ( BotInfo bi,
const Anope::string name,
const Anope::string param = "",
bool  enforce_mlock = true 
)

Remove a mode from a channel

Parameters
biThe client setting the modes
nameThe mode name
paramOptional param arg for the mode
enforce_mlocktrue if mlocks should be enforced, false to override mlock

Definition at line 508 of file channels.cpp.

References ModeManager::FindChannelModeByName(), and RemoveMode().

void Channel::RemoveModeInternal ( MessageSource source,
ChannelMode cm,
const Anope::string param = "",
bool  enforce_mlock = true 
)

Remove a mode internally on a channel, this is not sent out to the IRCd

Parameters
setterThe Setter
cmThe mode
paramThe param
enforce_mlocktrue if mlocks should be enforced, false to override mlock

Definition at line 321 of file channels.cpp.

References anope_dynamic_static_cast(), CheckDelete(), CheckModes(), ChannelStatus::DelMode(), Anope::string::empty(), Anope::string::equals_ci(), EVENT_STOP, BotInfo::Find(), User::Find(), User::FindChannel(), FOREACH_RESULT, GetModeList(), LOG_DEBUG, Mode::mchar, MODE_LIST, MODE_STATUS, modes, Mode::name, name, User::nick, ChannelModeList::OnDel(), SetCorrectModes(), ChanUserContainer::status, Mode::type, and ChannelMode::Unwrap().

Referenced by RemoveMode(), and SetModesInternal().

void Channel::Reset ( )

Call if we need to unset all modes and clear all user status (internally). Only useful if we get a SJOIN with a TS older than what we have here

Definition at line 68 of file channels.cpp.

References ChannelStatus::Clear(), ModeManager::FindChannelModeByChar(), User::GetUID(), Anope::string::length(), Me, modes, ChannelStatus::Modes(), User::server, SetCorrectModes(), SetMode(), ChanUserContainer::status, Sync(), syncing, ChanUserContainer::user, and users.

Referenced by SetModesInternal(), and Message::Join::SJoin().

void Channel::SetCorrectModes ( User u,
bool  give_modes 
)

Set the correct modes, or remove the ones granted without permission, for the specified user.

Parameters
userThe user to give/remove modes to/from
give_modesif true modes may be given to the user

Definition at line 816 of file channels.cpp.

References FOREACH_MOD, ModeManager::GetStatusChannelModesByRank(), User::GetUID(), Server::IsSynced(), Server::IsULined(), LOG_DEBUG, Mode::name, name, User::nick, RemoveMode(), User::server, SetMode(), ChannelModeStatus::symbol, and syncing.

Referenced by CommandCSEnforce::DoSecureOps(), CommandCSSync::Execute(), CommandCSRegister::Execute(), CommandCSClone::Execute(), NickServCore::OnNickIdentify(), NickServCore::OnNickUpdate(), RemoveModeInternal(), Reset(), SetModeInternal(), and Message::Join::SJoin().

void Channel::SetMode ( BotInfo bi,
ChannelMode cm,
const Anope::string param = "",
bool  enforce_mlock = true 
)
void Channel::SetMode ( BotInfo bi,
const Anope::string name,
const Anope::string param = "",
bool  enforce_mlock = true 
)

Set a mode on a channel

Parameters
biThe client setting the modes
nameThe mode name
paramOptional param arg for the mode
enforce_mlocktrue if mlocks should be enforced, false to override mlock

Definition at line 454 of file channels.cpp.

References ModeManager::FindChannelModeByName(), and SetMode().

void Channel::SetModeInternal ( MessageSource source,
ChannelMode cm,
const Anope::string param = "",
bool  enforce_mlock = true 
)

Set a mode internally on a channel, this is not sent out to the IRCd

Parameters
setterThe setter
cmThe mode
paramThe param
enforce_mlocktrue if mlocks should be enforced, false to override mlock

Definition at line 251 of file channels.cpp.

References ChannelStatus::AddMode(), anope_dynamic_static_cast(), CheckModes(), Anope::string::empty(), EVENT_STOP, User::Find(), User::FindChannel(), FOREACH_RESULT, HasMode(), LOG_DEBUG, Mode::mchar, MODE_LIST, MODE_REGULAR, MODE_STATUS, modes, Mode::name, name, User::nick, ChannelModeList::OnAdd(), SetCorrectModes(), ChanUserContainer::status, Mode::type, and ChannelMode::Unwrap().

Referenced by IRCDMessageBMask::Run(), IRCDMessageSJoin::Run(), Server::Server(), SetMode(), and SetModesInternal().

void Channel::SetModes ( BotInfo bi,
bool  enforce_mlock,
const char *  cmodes,
  ... 
)

Set a string of modes on the channel

Parameters
biThe client setting the modes
enforce_mlockShould mlock be enforced on this mode change
cmodesThe modes to set

Definition at line 528 of file channels.cpp.

References BUFSIZE, User::Find(), ModeManager::FindChannelModeByChar(), sepstream::GetToken(), User::GetUID(), Anope::string::length(), MODE_REGULAR, MODE_STATUS, RemoveMode(), SetMode(), and Mode::type.

void Channel::SetModesInternal ( MessageSource source,
const Anope::string mode,
time_t  ts = 0,
bool  enforce_mlock = true 
)
void Channel::Sync ( )

Restore the channel topic, set mlock (key), set stickied bans, etc

Definition at line 98 of file channels.cpp.

References CheckModes(), FOREACH_MOD, and syncing.

Referenced by CommandCSSetPersist::Execute(), CSSet::Persist::ExtensibleUnserialize(), Reset(), Message::Join::SJoin(), and Server::Sync().

bool Channel::Unban ( User u,
const Anope::string mode,
bool  full = false 
)

Unbans a user from this channel.

Parameters
uThe user to unban
modeThe mode to unban
fullWhether or not to match using the user's real host and IP
Returns
whether or not a ban was removed

Definition at line 868 of file channels.cpp.

References Entry::GetMask(), GetModeList(), HasMode(), Entry::Matches(), and RemoveMode().

Referenced by CommandCSUnban::Execute().

Field Documentation

bool Channel::botchannel

Definition at line 52 of file channels.h.

Referenced by Channel(), and Configuration::Conf::Conf().

int16_t Channel::bouncy_modes

Definition at line 74 of file channels.h.

Referenced by Channel(), CheckModes(), CommandOSKick::Execute(), and CommandOSMode::Execute().

int16_t Channel::chanserv_modecount

Definition at line 73 of file channels.h.

Referenced by Channel(), CheckModes(), RemoveMode(), and SetMode().

time_t Channel::chanserv_modetime

Definition at line 71 of file channels.h.

Referenced by Channel(), RemoveMode(), and SetMode().

time_t Channel::creation_time
ModeList Channel::modes
private

A map of channel modes with their parameters set on this channel

Definition at line 40 of file channels.h.

Referenced by GetModeList(), GetModes(), GetParam(), HasMode(), RemoveModeInternal(), Reset(), and SetModeInternal().

Anope::string Channel::name
int16_t Channel::server_modecount

Definition at line 72 of file channels.h.

Referenced by Channel(), CheckModes(), and SetModesInternal().

time_t Channel::server_modetime

Definition at line 70 of file channels.h.

Referenced by Channel(), and SetModesInternal().

bool Channel::syncing
Anope::string Channel::topic
Anope::string Channel::topic_setter
time_t Channel::topic_time
time_t Channel::topic_ts
ChanUserList Channel::users

The documentation for this class was generated from the following files: