InspIRCd  2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations
Public Member Functions | Public Attributes | List of all members
User Class Referenceabstract

#include <users.h>

Inheritance diagram for User:
Extensible classbase FakeUser LocalUser RemoteUser

Public Member Functions

const char * GetIPString ()
 
irc::sockets::cidr_mask GetCIDRMask ()
 
virtual bool SetClientIP (const char *sip, bool recheck_eline=true)
 
virtual void SetClientIP (const irc::sockets::sockaddrs &sa, bool recheck_eline=true)
 
 User (const std::string &uid, const std::string &srv, int objtype)
 
bool CheckLines (bool doZline=false)
 
virtual const std::string & GetFullHost ()
 
virtual const std::string & GetFullRealHost ()
 
void InvalidateCache ()
 
const char * FormatNoticeMasks ()
 
std::string ProcessNoticeMasks (const char *sm)
 
bool IsNoticeMaskSet (unsigned char sm)
 
void SetNoticeMask (unsigned char sm, bool value)
 
const char * FormatModes (bool showparameters=false)
 
bool IsModeSet (unsigned char m)
 
void SetMode (unsigned char m, bool value)
 
virtual bool HasPermission (const std::string &command)
 
virtual bool HasPrivPermission (const std::string &privstr, bool noisy=false)
 
virtual bool HasModePermission (unsigned char mode, ModeType type)
 
char * MakeWildHost ()
 
const std::string & MakeHost ()
 
const std::string & MakeHostIP ()
 
void AddToWhoWas ()
 
void Oper (OperInfo *info)
 
bool ForceNickChange (const char *newnick)
 
void UnOper ()
 
virtual void Write (const std::string &text)
 
virtual void Write (const char *text,...) CUSTOM_PRINTF(2
 
virtual void void WriteServ (const std::string &text)
 
void WriteServ (const char *text,...) CUSTOM_PRINTF(2
 
void void WriteNumeric (unsigned int numeric, const char *text,...) CUSTOM_PRINTF(3
 
void void void WriteNumeric (unsigned int numeric, const std::string &text)
 
void WriteFrom (User *user, const std::string &text)
 
void WriteFrom (User *user, const char *text,...) CUSTOM_PRINTF(3
 
void void WriteTo (User *dest, const std::string &data)
 
void WriteTo (User *dest, const char *data,...) CUSTOM_PRINTF(3
 
void void WriteCommonRaw (const std::string &line, bool include_self=true)
 
void WriteCommon (const char *text,...) CUSTOM_PRINTF(2
 
void void WriteCommonExcept (const char *text,...) CUSTOM_PRINTF(2
 
void void void WriteCommonQuit (const std::string &normal_text, const std::string &oper_text)
 
void SendText (const std::string &LinePrefix, std::stringstream &TextStream)
 
virtual void SendText (const std::string &line)=0
 
void SendText (const char *text,...) CUSTOM_PRINTF(2
 
void bool SharesChannelWith (User *other)
 
void DoHostCycle (const std::string &quitline)
 
bool ChangeDisplayedHost (const char *host)
 
bool ChangeIdent (const char *newident)
 
bool ChangeName (const char *gecos)
 
bool ChangeNick (const std::string &newnick, bool force=false)
 
void SendAll (const char *command, const char *text,...) CUSTOM_PRINTF(3
 
void std::string ChannelList (User *source, bool spy)
 
void SplitChanList (User *dest, const std::string &cl)
 
void PurgeEmptyChannels ()
 
virtual ConnectClassGetClass ()
 
virtual ~User ()
 
virtual CullResult cull ()
 
- Public Member Functions inherited from Extensible
const ExtensibleStore & GetExtList () const
 
void doUnhookExtensions (const std::vector< reference< ExtensionItem > > &toRemove)
 

Public Attributes

std::string host
 
time_t age
 
time_t signon
 
time_t idle_lastmsg
 
irc::sockets::sockaddrs client_sa
 
std::string nick
 
const std::string uuid
 
std::string ident
 
std::string dhost
 
std::string fullname
 
std::bitset< 64 > modes
 
std::bitset< 64 > snomasks
 
UserChanList chans
 
const std::string server
 
std::string awaymsg
 
time_t awaytime
 
reference< OperInfooper
 
unsigned int registered:3
 
unsigned int dns_done:1
 
unsigned int quietquit:1
 
unsigned int quitting:1
 
unsigned int quitting_sendq:1
 
unsigned int exempt:1
 
unsigned int lastping:1
 
const unsigned int usertype:2
 

Additional Inherited Members

- Public Types inherited from Extensible
typedef std::map< reference
< ExtensionItem >, void * > 
ExtensibleStore
 

Detailed Description

Holds all information about a user This class stores all information about a user connected to the irc server. Everything about a connection is stored here primarily, from the user's socket ID (file descriptor) through to the user's nickname and hostname.

Constructor & Destructor Documentation

User::User ( const std::string &  uid,
const std::string &  srv,
int  objtype 
)

Constructor

Exceptions
CoreExceptionif the UID allocated to the user already exists
User::~User ( )
virtual

Default destructor

Member Function Documentation

void User::AddToWhoWas ( )

Add the user to WHOWAS system

bool User::ChangeDisplayedHost ( const char *  host)

Change the displayed host of a user. ALWAYS use this function, rather than writing User::dhost directly, as this triggers module events allowing the change to be syncronized to remote servers. This will also emulate a QUIT and rejoin (where configured) before setting their host field.

Parameters
hostThe new hostname to set
Returns
True if the change succeeded, false if it didn't
bool User::ChangeIdent ( const char *  newident)

Change the ident (username) of a user. ALWAYS use this function, rather than writing User::ident directly, as this correctly causes the user to seem to quit (where configured) before setting their ident field.

Parameters
newidentThe new ident to set
Returns
True if the change succeeded, false if it didn't
bool User::ChangeName ( const char *  gecos)

Change a users realname field. ALWAYS use this function, rather than writing User::fullname directly, as this triggers module events allowing the change to be syncronized to remote servers.

Parameters
gecosThe user's new realname
Returns
True if the change succeeded, false if otherwise
bool User::ChangeNick ( const std::string &  newnick,
bool  force = false 
)

Change a user's nick

Parameters
newnickThe new nick
forceTrue if the change is being forced (should not be blocked by modes like +N)
Returns
True if the change succeeded
std::string User::ChannelList ( User source,
bool  spy 
)

Compile a channel list for this user. Used internally by WHOIS

Parameters
sourceThe user to prepare the channel list for
spyWhether to return the spy channel list rather than the normal one
Returns
This user's channel list
bool User::CheckLines ( bool  doZline = false)

Check if the user matches a G or K line, and disconnect them if they do.

Parameters
doZlineTrue if ZLines should be checked (if IP has changed since initial connect) Returns true if the user matched a ban, false else.
CullResult User::cull ( )
virtual

Called just prior to destruction via cull list.

Reimplemented from Extensible.

Reimplemented in FakeUser, and LocalUser.

void User::DoHostCycle ( const std::string &  quitline)

Send fake quit/join messages for host or ident cycle. Run this after the item in question has changed. You should not need to use this function, call ChangeDisplayedHost instead

Parameters
quitlineThe entire QUIT line, including the source using the old value
bool User::ForceNickChange ( const char *  newnick)
inline

Force a nickname change. If the nickname change fails (for example, because the nick in question already exists) this function will return false, and you must then either output an error message, or quit the user for nickname collision.

Parameters
newnickThe nickname to change to
Returns
True if the nickchange was successful.
const char * User::FormatModes ( bool  showparameters = false)

Create a displayable mode string for this users umodes

Parameters
showparametersThe mode string
const char * User::FormatNoticeMasks ( )

Create a displayable mode string for this users snomasks

Returns
The notice mask character sequence
irc::sockets::cidr_mask User::GetCIDRMask ( )

Get CIDR mask, using default range, for this user

ConnectClass * User::GetClass ( )
virtual

Get the connect class which this user belongs to. NULL for remote users.

Returns
A pointer to this user's connect class.

Reimplemented in LocalUser.

const std::string & User::GetFullHost ( )
virtual

Returns the full displayed host of the user This member function returns the hostname of the user as seen by other users on the server, in nick!ident@host form.

Returns
The full masked host of the user

Reimplemented in FakeUser.

const std::string & User::GetFullRealHost ( )
virtual

Returns the full real host of the user This member function returns the hostname of the user as seen by other users on the server, in nick!ident@host form. If any form of hostname cloaking is in operation, e.g. through a module, then this method will ignore it and return the true hostname.

Returns
The full real host of the user

Reimplemented in FakeUser.

const char * User::GetIPString ( )

Get client IP string from sockaddr, using static internal buffer

Returns
The IP string
bool User::HasModePermission ( unsigned char  mode,
ModeType  type 
)
virtual

Returns true or false if a user can set a privileged user or channel mode. This is done by looking up their oper type from User::oper, then referencing this to their oper classes, and checking the modes they can set.

Parameters
modeThe mode the check
typeModeType (MODETYPE_CHANNEL or MODETYPE_USER).
Returns
True if the user can set or unset this mode.

Reimplemented in LocalUser.

bool User::HasPermission ( const std::string &  command)
virtual

Returns true or false for if a user can execute a privilaged oper command. This is done by looking up their oper type from User::oper, then referencing this to their oper classes and checking the commands they can execute.

Parameters
commandA command (should be all CAPS)
Returns
True if this user can execute the command

Reimplemented in LocalUser.

bool User::HasPrivPermission ( const std::string &  privstr,
bool  noisy = false 
)
virtual

Returns true if a user has a given permission. This is used to check whether or not users may perform certain actions which admins may not wish to give to all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.

Parameters
privstrThe priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
noisyIf set to true, the user is notified that they do not have the specified permission where applicable. If false, no notification is sent.
Returns
True if this user has the permission in question.

Reimplemented in LocalUser.

void User::InvalidateCache ( )

This clears any cached results that are used for GetFullRealHost() etc. The results of these calls are cached as generating them can be generally expensive.

bool User::IsModeSet ( unsigned char  m)

Returns true if a specific mode is set

Parameters
mThe user mode
Returns
True if the mode is set
bool User::IsNoticeMaskSet ( unsigned char  sm)

Returns true if a notice mask is set

Parameters
smA notice mask character to check
Returns
True if the notice mask is set
const std::string & User::MakeHost ( )

Creates a usermask with real host. Takes a buffer to use and fills the given buffer with the hostmask in the format user@host

Returns
the usermask in the format user@host
const std::string & User::MakeHostIP ( )

Creates a usermask with real ip. Takes a buffer to use and fills the given buffer with the ipmask in the format user@ip

Returns
the usermask in the format user@ip
char * User::MakeWildHost ( )

Creates a wildcard host. Takes a buffer to use and fills the given buffer with the host in the format *!*@hostname

Returns
The wildcarded hostname in *!*@host form
void User::Oper ( OperInfo info)

Oper up the user using the given opertype. This will also give the +o usermode.

std::string User::ProcessNoticeMasks ( const char *  sm)

Process a snomask modifier string, e.g. +abc-de

Parameters
smA sequence of notice mask characters
Returns
The cleaned mode sequence which can be output, e.g. in the above example if masks c and e are not valid, this function will return +ab-d
void User::PurgeEmptyChannels ( )

Remove this user from all channels they are on, and delete any that are now empty. This is used by QUIT, and will not send part messages!

void User::SendAll ( const char *  command,
const char *  text,
  ... 
)

Send a command to all local users from this user The command given must be able to send text with the first parameter as a servermask (e.g. $*), so basically you should use PRIVMSG or NOTICE.

Parameters
commandthe command to send
textThe text format string to send
...Format arguments
void User::SendText ( const std::string &  LinePrefix,
std::stringstream &  TextStream 
)

Dump text to a user target, splitting it appropriately to fit

Parameters
LinePrefixtext to prefix each complete line with
TextStreamthe text to send to the user
virtual void User::SendText ( const std::string &  line)
pure virtual

Write to the user, routing the line if the user is remote.

Implemented in FakeUser, RemoteUser, and LocalUser.

void User::SendText ( const char *  text,
  ... 
)

Write to the user, routing the line if the user is remote.

bool User::SetClientIP ( const char *  sip,
bool  recheck_eline = true 
)
virtual

Sets the client IP for this user

Returns
true if the conversion was successful

Reimplemented in LocalUser.

void User::SetMode ( unsigned char  m,
bool  value 
)

Set a specific usermode to on or off

Parameters
mThe user mode
valueOn or off setting of the mode
void User::SetNoticeMask ( unsigned char  sm,
bool  value 
)

Changed a specific notice mask value

Parameters
smThe server notice mask to change
valueAn on/off value for this mask
bool User::SharesChannelWith ( User other)

Return true if the user shares at least one channel with another user

Parameters
otherThe other user to compare the channel list against
Returns
True if the given user shares at least one channel with this user
void User::SplitChanList ( User dest,
const std::string &  cl 
)

Split the channel list in cl which came from dest, and spool it to this user Used internally by WHOIS

Parameters
destThe user the original channel list came from
clThe channel list as a string obtained from User::ChannelList()
void User::UnOper ( )

Oper down. This will clear the +o usermode and unset the user's oper type

void User::Write ( const std::string &  text)
virtual

Write text to this user, appending CR/LF. Works on local users only.

Parameters
textA std::string to send to the user

Reimplemented in LocalUser.

void User::Write ( const char *  text,
  ... 
)
virtual

Write text to this user, appending CR/LF. Works on local users only.

Parameters
textThe format string for text to send to the user
...POD-type format arguments

Reimplemented in LocalUser.

void User::WriteCommon ( const char *  text,
  ... 
)

Write to all users that can see this user (including this user in the list), appending CR/LF

Parameters
textThe format string for text to send to the users
...POD-type format arguments
void User::WriteCommonExcept ( const char *  text,
  ... 
)

Write to all users that can see this user (not including this user in the list), appending CR/LF

Parameters
textThe format string for text to send to the users
...POD-type format arguments
void User::WriteCommonQuit ( const std::string &  normal_text,
const std::string &  oper_text 
)

Write a quit message to all common users, as in User::WriteCommonExcept but with a specific quit message for opers only.

Parameters
normal_textNormal user quit message
oper_textOper only quit message
void User::WriteCommonRaw ( const std::string &  line,
bool  include_self = true 
)

Write to all users that can see this user (including this user in the list if include_self is true), appending CR/LF

Parameters
lineA std::string to send to the users
include_selfShould the message be sent back to the author?
void User::WriteFrom ( User user,
const std::string &  text 
)

Write text to this user, appending CR/LF and prepending :nick!user@host of the user provided in the first parameter.

Parameters
userThe user to prepend the :nick!user@host of
textA std::string to send to the user
void User::WriteFrom ( User user,
const char *  text,
  ... 
)

Write text to this user, appending CR/LF and prepending :nick!user@host of the user provided in the first parameter.

Parameters
userThe user to prepend the :nick!user@host of
textThe format string for text to send to the user
...POD-type format arguments
void User::WriteServ ( const std::string &  text)

Write text to this user, appending CR/LF and prepending :server.name Works on local users only.

Parameters
textA std::string to send to the user
void User::WriteServ ( const char *  text,
  ... 
)

Write text to this user, appending CR/LF and prepending :server.name Works on local users only.

Parameters
textThe format string for text to send to the user
...POD-type format arguments

WriteServ() Same as Write(), except `text' is prefixed with `:server.name '.

void User::WriteTo ( User dest,
const std::string &  data 
)

Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user@host.

Parameters
destThe user to route the message to
dataA std::string to send to the user
void User::WriteTo ( User dest,
const char *  data,
  ... 
)

Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user@host.

Parameters
destThe user to route the message to
dataThe format string for text to send to the user
...POD-type format arguments

Member Data Documentation

time_t User::age

Time that the object was instantiated (used for TS calculation etc)

std::string User::awaymsg

The user's away message. If this string is empty, the user is not marked as away.

time_t User::awaytime

Time the user last went away. This is ONLY RELIABLE if user IS_AWAY()!

UserChanList User::chans

Channels this user is on

irc::sockets::sockaddrs User::client_sa

Client address that the user is connected from. Do not modify this value directly, use SetClientIP() to change it. Port is not valid for remote users.

std::string User::dhost

The host displayed to non-opers (used for cloaking etc). This usually matches the value of User::host.

unsigned int User::dns_done

True when DNS lookups are completed. The UserResolver classes res_forward and res_reverse will set this value once they complete.

unsigned int User::exempt

This is true if the user matched an exception (E:Line). It is used to save time on ban checks.

std::string User::fullname

The users full name (GECOS).

std::string User::host

Hostname of connection. This should be valid as per RFC1035.

std::string User::ident

The users ident reply. Two characters are added to the user-defined limit to compensate for the tilde etc.

time_t User::idle_lastmsg

Time that the connection last sent a message, used to calculate idle time

unsigned int User::lastping

has the user responded to their previous ping?

std::bitset<64> User::modes

The user's mode list. NOT a null terminated string. Also NOT an array. Much love to the STL for giving us an easy to use bitset, saving us RAM. if (modes[modeletter-65]) is set, then the mode is set, for example, to work out if mode +s is set, we check the field User::modes['s'-65] != 0. The following RFC characters o, w, s, i have constants defined via an enum, such as UM_SERVERNOTICE and UM_OPETATOR.

std::string User::nick

The users nickname. An invalid nickname indicates an unregistered connection prior to the NICK command. Use InspIRCd::IsNick() to validate nicknames.

reference<OperInfo> User::oper

The oper type they logged in as, if they are an oper.

unsigned int User::quietquit

Whether or not to send an snotice about this user's quitting

unsigned int User::quitting

If this is set to true, then all socket operations for the user are dropped into the bit-bucket. This value is set by QuitUser, and is not needed seperately from that call. Please note that setting this value alone will NOT cause the user to quit.

unsigned int User::quitting_sendq

Recursion fix: user is out of SendQ and will be quit as soon as possible. This can't be handled normally because QuitUser itself calls Write on other users, which could trigger their SendQ to overrun.

unsigned int User::registered

Used by User to indicate the registration status of the connection It is a bitfield of the REG_NICK, REG_USER and REG_ALL bits to indicate the connection state.

const std::string User::server

The server the user is connected to.

time_t User::signon

Time the connection was created, set in the constructor. This may be different from the time the user's classbase object was created.

std::bitset<64> User::snomasks

What snomasks are set on this user. This functions the same as the above modes.

const unsigned int User::usertype

What type of user is this?

const std::string User::uuid

The user's unique identifier. This is the unique identifier which the user has across the network.


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