Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

chanrec Class Reference

Holds all relevent information for a channel. More...

#include <channels.h>

Inheritance diagram for chanrec:

Inheritance graph
[legend]
Collaboration diagram for chanrec:

Collaboration graph
[legend]
List of all members.

Public Member Functions

void SetCustomMode (char mode, bool mode_on)
 Sets or unsets a custom mode in the channels info.
void SetCustomModeParam (char mode, char *parameter, bool mode_on)
 Sets or unsets the parameters for a custom mode in a channels info.
bool IsCustomModeSet (char mode)
 Returns true if a custom mode is set on a channel.
std::string GetModeParameter (char mode)
 Returns the parameter for a custom mode on a channel.
long GetUserCounter ()
 Obtain the channel "user counter" This returns the channel reference counter, which is initialized to 0 when the channel is created and incremented/decremented upon joins, parts quits and kicks.
void AddUser (char *castuser)
 Add a user pointer to the internal reference list.
void DelUser (char *castuser)
 Delete a user pointer to the internal reference list.
std::vector< char * > * GetUsers ()
 Obrain the internal reference list The internal reference list contains a list of userrec* cast to char*.
 chanrec ()
 Creates a channel record and initialises it with default values.
virtual ~chanrec ()

Public Attributes

char name [CHANMAX]
 The channels name.
char custom_modes [MAXMODES]
 Custom modes for the channel.
std::vector< char * > internal_userlist
 User list (casted to char*'s to stop forward declaration stuff) (chicken and egg scenario!).
char topic [MAXBUF]
 Channel topic.
time_t created
 Creation time.
time_t topicset
 Time topic was set.
char setby [NICKMAX]
 The last user to set the topic.
short int limit
 Contains the channel user limit.
char key [32]
 Contains the channel key.
char binarymodes
 Contains a bitmask of the CM_* builtin (RFC) binary mode symbols.
BanList bans
 The list of all bans set on the channel.

Detailed Description

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.

Definition at line 101 of file channels.h.


Constructor & Destructor Documentation

chanrec::chanrec  ) 
 

Creates a channel record and initialises it with default values.

Definition at line 73 of file channels.cpp.

References binarymodes, created, custom_modes, internal_userlist, key, limit, name, setby, topic, and topicset.

00074 {
00075         strcpy(name,"");
00076         strcpy(custom_modes,"");
00077         strcpy(topic,"");
00078         strcpy(setby,"");
00079         strcpy(key,"");
00080         created = topicset = limit = 0;
00081         binarymodes = 0;
00082         internal_userlist.clear();
00083 }

virtual chanrec::~chanrec  )  [inline, virtual]
 

Definition at line 224 of file channels.h.

00224 { /* stub */ }


Member Function Documentation

void chanrec::AddUser char *  castuser  ) 
 

Add a user pointer to the internal reference list.

Parameters:
castuser This should be a pointer to a userrec, casted to char*
The data inserted into the reference list is a table as it is an arbitary pointer compared to other users by its memory address, as this is a very fast 32 or 64 bit integer comparison.

Definition at line 166 of file channels.cpp.

References DEBUG, and internal_userlist.

00167 {
00168         internal_userlist.push_back(castuser);
00169         log(DEBUG,"Added casted user to channel's internal list");
00170 }

void chanrec::DelUser char *  castuser  ) 
 

Delete a user pointer to the internal reference list.

Parameters:
castuser This should be a pointer to a userrec, casted to char*
The data removed from the reference list is a table as it is an arbitary pointer compared to other users by its memory address, as this is a very fast 32 or 64 bit integer comparison.

Definition at line 172 of file channels.cpp.

References DEBUG, internal_userlist, and name.

00173 {
00174         for (std::vector<char*>::iterator a = internal_userlist.begin(); a < internal_userlist.end(); a++)
00175         {
00176                 if (*a == castuser)
00177                 {
00178                         log(DEBUG,"Removed casted user from channel's internal list");
00179                         internal_userlist.erase(a);
00180                         return;
00181                 }
00182         }
00183         log(DEBUG,"BUG BUG BUG! Attempt to remove an uncasted user from the internal list of %s!",name);
00184 }

std::string chanrec::GetModeParameter char  mode  ) 
 

Returns the parameter for a custom mode on a channel.

Parameters:
mode The mode character you wish to query
For example if "+L #foo" is set, and you pass this method 'L', it will return 'foo'. If the mode is not set on the channel, or the mode has no parameters associated with it, it will return an empty string.

Returns:
The parameter for this mode is returned, or an empty string

Definition at line 146 of file channels.cpp.

References custom_mode_params.

00147 {
00148         if (custom_mode_params.size())
00149         {
00150                 for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++)
00151                 {
00152                         if ((i->mode == mode) && (!strcasecmp(this->name,i->channel)))
00153                         {
00154                                 return i->parameter;
00155                         }
00156                 }
00157         }
00158         return "";
00159 }

long chanrec::GetUserCounter  ) 
 

Obtain the channel "user counter" This returns the channel reference counter, which is initialized to 0 when the channel is created and incremented/decremented upon joins, parts quits and kicks.

Returns:
The number of users on this channel

Definition at line 161 of file channels.cpp.

00162 {
00163         return (this->internal_userlist.size());
00164 }

std::vector< char * > * chanrec::GetUsers  ) 
 

Obrain the internal reference list The internal reference list contains a list of userrec* cast to char*.

These are used for rapid comparison to determine channel membership for PRIVMSG, NOTICE, QUIT, PART etc. The resulting pointer to the vector should be considered readonly and only modified via AddUser and DelUser.

Returns:
This function returns a vector of userrec pointers, each of which has been casted to char* to prevent circular references

Definition at line 186 of file channels.cpp.

References internal_userlist.

Referenced by Server::GetUsers().

00187 {
00188         return &internal_userlist;
00189 }

bool chanrec::IsCustomModeSet char  mode  ) 
 

Returns true if a custom mode is set on a channel.

Parameters:
mode The mode character you wish to query
Returns:
True if the custom mode is set, false if otherwise

Definition at line 141 of file channels.cpp.

00142 {
00143         return (strchr(this->custom_modes,mode));
00144 }

void chanrec::SetCustomMode char  mode,
bool  mode_on
 

Sets or unsets a custom mode in the channels info.

Parameters:
mode The mode character to set or unset
mode_on True if you want to set the mode or false if you want to remove it

Definition at line 85 of file channels.cpp.

References custom_modes, DEBUG, and SetCustomModeParam().

00086 {
00087         if (mode_on) {
00088                 static char m[3];
00089                 m[0] = mode;
00090                 m[1] = '\0';
00091                 if (!strchr(this->custom_modes,mode))
00092                 {
00093                         strlcat(custom_modes,m,MAXMODES);
00094                 }
00095                 log(DEBUG,"Custom mode %c set",mode);
00096         }
00097         else {
00098 
00099                 std::string a = this->custom_modes;
00100                 int pos = a.find(mode);
00101                 a.erase(pos,1);
00102                 strncpy(this->custom_modes,a.c_str(),MAXMODES);
00103 
00104                 log(DEBUG,"Custom mode %c removed: modelist='%s'",mode,this->custom_modes);
00105                 this->SetCustomModeParam(mode,"",false);
00106         }
00107 }

void chanrec::SetCustomModeParam char  mode,
char *  parameter,
bool  mode_on
 

Sets or unsets the parameters for a custom mode in a channels info.

Parameters:
mode The mode character to set or unset
parameter The parameter string to associate with this mode character
mode_on True if you want to set the mode or false if you want to remove it

Definition at line 110 of file channels.cpp.

References ModeParameter::channel, custom_mode_params, DEBUG, ModeParameter::mode, and ModeParameter::parameter.

Referenced by SetCustomMode().

00111 {
00112 
00113         log(DEBUG,"SetCustomModeParam called");
00114         ModeParameter M;
00115         M.mode = mode;
00116         strlcpy(M.channel,this->name,CHANMAX);
00117         strlcpy(M.parameter,parameter,MAXBUF);
00118         if (mode_on)
00119         {
00120                 log(DEBUG,"Custom mode parameter %c %s added",mode,parameter);
00121                 custom_mode_params.push_back(M);
00122         }
00123         else
00124         {
00125                 if (custom_mode_params.size())
00126                 {
00127                         for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++)
00128                         {
00129                                 if ((i->mode == mode) && (!strcasecmp(this->name,i->channel)))
00130                                 {
00131                                         log(DEBUG,"Custom mode parameter %c %s removed",mode,parameter);
00132                                         custom_mode_params.erase(i);
00133                                         return;
00134                                 }
00135                         }
00136                 }
00137                 log(DEBUG,"*** BUG *** Attempt to remove non-existent mode parameter!");
00138         }
00139 }


Member Data Documentation

BanList chanrec::bans
 

The list of all bans set on the channel.

Definition at line 149 of file channels.h.

char chanrec::binarymodes
 

Contains a bitmask of the CM_* builtin (RFC) binary mode symbols.

Definition at line 145 of file channels.h.

Referenced by chanrec().

time_t chanrec::created
 

Creation time.

Definition at line 123 of file channels.h.

Referenced by chanrec().

char chanrec::custom_modes[MAXMODES]
 

Custom modes for the channel.

Plugins may use this field in any way they see fit.

Definition at line 110 of file channels.h.

Referenced by chanrec(), and SetCustomMode().

std::vector<char*> chanrec::internal_userlist
 

User list (casted to char*'s to stop forward declaration stuff) (chicken and egg scenario!).

Definition at line 115 of file channels.h.

Referenced by AddUser(), chanrec(), DelUser(), and GetUsers().

char chanrec::key[32]
 

Contains the channel key.

If this value is an empty string, there is no channel key in place.

Definition at line 141 of file channels.h.

Referenced by chanrec().

short int chanrec::limit
 

Contains the channel user limit.

If this value is zero, there is no limit in place.

Definition at line 136 of file channels.h.

Referenced by chanrec().

char chanrec::name[CHANMAX]
 

The channels name.

Definition at line 106 of file channels.h.

Referenced by chanrec(), DelUser(), and Server::PseudoToUser().

char chanrec::setby[NICKMAX]
 

The last user to set the topic.

If this member is an empty string, no topic was ever set.

Definition at line 131 of file channels.h.

Referenced by chanrec(), and Server::PseudoToUser().

char chanrec::topic[MAXBUF]
 

Channel topic.

If this is an empty string, no channel topic is set.

Definition at line 120 of file channels.h.

Referenced by chanrec(), and Server::PseudoToUser().

time_t chanrec::topicset
 

Time topic was set.

If no topic was ever set, this will be equal to chanrec::created

Definition at line 127 of file channels.h.

Referenced by chanrec(), and Server::PseudoToUser().


The documentation for this class was generated from the following files:
Generated on Wed Dec 14 15:55:48 2005 for InspIRCd by  doxygen 1.4.4-20050815