#include <session.h>
Public Member Functions | |
session (listmode mode=automatic) | |
Creates a session. | |
bool | connect (const std::string &hostname, unsigned int port=6667, const std::string &password="", bool login=true) |
Connects to an IRC server. | |
void | run () |
Starts the IRC session running. | |
bool | service_socket (fd_set *readfds, fd_set *writefds, fd_set *exceptfds, int *maxfd) |
Services the socket connecting the session to the IRC server. | |
bool | connected () |
Returns whether the session is connected. | |
bool | disconnect () |
Disconnects from the IRC server. | |
bool | set_nick (const std::string &newnick) |
Sets the nickname. | |
bool | set_username (const std::string &username) |
Sets the username. | |
bool | set_realname (const std::string &realname) |
Sets the realname (gecos). | |
const user & | me () const |
Returns the "me" user object. | |
const user & | server () const |
Returns the "server" user object. | |
void | auto_pong (bool on) |
Enables or disables auto-pong. | |
bool | auto_pong () |
Returns whether or not auto-pong is enabled. | |
bool | has_capab (const std::string &name) |
Determine whether the irc server has a certain capability. | |
const std::string & | capab (const std::string &name) |
Return the value associated with a named server capability. | |
void | ptr (void *p) |
Sets the user-defined pointer. | |
void * | ptr () const |
Returns the user-defined pointer. | |
bool | cmd_raw (const std::string &rawline) |
Sends a raw line of data to the IRC server. | |
bool | cmd_pass (const std::string &password) |
Sends the PASS message to the IRC server. | |
bool | cmd_nick (const std::string &newnick) |
Sends the NICK message to the IRC server. | |
bool | cmd_user (const std::string &username, const std::string &hostname, const std::string &servername, const std::string &realname) |
Sends the USER message to the IRC server. | |
bool | cmd_quit (const std::string &quitmsg) |
Sends the QUIT message to the IRC server. | |
bool | cmd_join (const std::string &channel, const std::string &key="") |
Sends the JOIN message to the IRC server. | |
bool | cmd_part (const std::string &channel, const std::string &partmsg="") |
Sends the PART message to the IRC server. | |
bool | cmd_mode (const std::string &target, const std::string &modestring) |
Sends the MODE message to the IRC server. | |
bool | cmd_topic (const std::string &channel, const std::string &topic) |
Sends the TOPIC message to the IRC server. | |
bool | cmd_names (const std::string &channel) |
Sends the NAMES message to the IRC server. | |
bool | cmd_list (const std::string ¶ms="") |
Sends the LIST message to the IRC server. | |
bool | cmd_invite (const std::string &nick, const std::string &channel) |
Sends the INVITE message to the IRC server. | |
bool | cmd_kick (const std::string &nick, const std::string &channel, const std::string &reason="") |
Sends the KICK message to the IRC server. | |
bool | cmd_privmsg (const std::string &to, const std::string &message) |
Sends the PRIVMSG message to the IRC server. | |
bool | cmd_notice (const std::string &to, const std::string &message) |
Sends the NOTICE message to the IRC server. | |
bool | cmd_ctcp (const std::string &to, const std::string &command, const std::string ¶ms) |
Sends the CTCP message to the IRC server. | |
bool | cmd_ping (const std::string ¶ms) |
Sends the PING message to the IRC server. | |
bool | cmd_pong (const std::string ¶ms) |
Sends the PONG message to the IRC server. | |
bool | cmd_away (const std::string &message="") |
Sends the AWAY message to the IRC server. | |
bool | cmd_oper (const std::string &opernick, const std::string &operpass) |
Sends the OPER message to the IRC server. | |
bool | cmd_who (const std::string ¶ms) |
Sends the WHO message to the IRC server. | |
bool | cmd_whois (const std::string &target) |
Sends the WHOIS message to the IRC server. | |
listmode | list_mode () const |
Returns this session's list mode. | |
const channel & | find_channel (const std::string &name) const |
Finds a channel in the internal channel list. | |
const irclist < channel > ::iterator | channellist_begin () const |
Returns an iterator the beginning of the channel list. | |
const irclist < channel > ::iterator | channellist_end () const |
Returns an iterator the end of the channel list. | |
const user & | find_user (const std::string &nick) const |
Finds a user in the internal user list. | |
const irclist< user > ::iterator | userlist_begin () const |
Returns an iterator the beginning of the user list. | |
const irclist< user > ::iterator | userlist_end () const |
Returns an iterator the beginning of the user list. | |
Public Attributes | |
boost::signal0< void > | sig_connected |
Emitted when the session successfully connects to the IRC server. | |
boost::signal1< void, const std::string & > | sig_disconnected |
Emitted when the session is disconnected from the IRC server. | |
boost::signal2< void, const std::string &, const int > | sig_socket_error |
Emitted when a network socket error occurs. | |
boost::signal1< void, user * > | sig_user_deletable |
Emitted when a user may be safely deleted. | |
boost::signal1< void, channel * > | sig_channel_deletable |
Emitted when a channel may be safely deleted. | |
boost::signal1< void, const std::string & > | sig_parseerror |
Emitted when a parse error occurs If the parser cannot understand a line sent to it by the IRC server it will give up and emit this signal. | |
boost::signal1< void, const message & > | sig_all_msgs |
Emitted when any message is received. | |
boost::signal1< void, const message & > | sig_unknown_msg |
Emitted when an unknown message is received. | |
boost::signal1< void, const message & > | sig_numeric_msg |
Emitted when a numeric message is received. | |
boost::signal1< void, const message & > | sig_nick_msg |
Emitted when a NICK message is received. | |
boost::signal1< void, const message & > | sig_quit_msg |
Emitted when a QUIT message is received. | |
boost::signal1< void, const message & > | sig_join_msg |
Emitted when a JOIN message is received. | |
boost::signal1< void, const message & > | sig_part_msg |
Emitted when a PART message is received. | |
boost::signal1< void, const message & > | sig_mode_msg |
Emitted when a MODE message is received. | |
boost::signal1< void, const message & > | sig_singlemode_msg |
Emitted for each individual mode change. | |
boost::signal1< void, const message & > | sig_topic_msg |
Emitted when a TOPIC message is received. | |
boost::signal1< void, const message & > | sig_invite_msg |
Emitted when an INVITE message is received. | |
boost::signal1< void, const message & > | sig_kick_msg |
Emitted when a KICK message is received. | |
boost::signal1< void, const message & > | sig_privmsg_msg |
Emitted when a PRIVMSG message is received. | |
boost::signal1< void, const message & > | sig_ctcp_msg |
Emitted when a CTCP message is received. | |
boost::signal1< void, const message & > | sig_notice_msg |
Emitted when a NOTICE message is received. | |
boost::signal1< void, const message & > | sig_ping_msg |
Emitted when a PING message is received. | |
boost::signal1< void, const message & > | sig_pong_msg |
Emitted when a PONG message is received. | |
boost::signal1< void, const message & > | sig_error_msg |
Emitted when an ERROR message is received. |
The session is the starting point for using this library. The session is responsible for creating and handling all other objects, sending commands to the IRC server, and providing messages back to you from the IRC server.
The session object has some general management functions, for example connect(), disconnect(), service_socket(), run().
IRC commands like JOIN, PRIVMSG, are sent to the server using the session's cmd_ functions (e.g. cmd_join(), cmd_privmsg())
Messages from the IRC server are provided by signals such as sig_join_msg, sig_privmsg_msg, which can be connected to your own handler functions like this:
mysession->sig_join_msg.connect(myhandler);
The function myhandler will then be called whenever a JOIN message is received.
For more information, see the tutorials in the manual. (http://libircpp.sf.net/manual/)
ircpp::session::session | ( | listmode | mode = automatic |
) | [explicit] |
Creates a session.
Creates a new IRC session
mode | (optional) The mode of the user & channel lists. See the manual section on lists for more information (http://libircpp.sf.net/manual/lists.html). |
bool ircpp::session::connect | ( | const std::string & | hostname, | |
unsigned int | port = 6667 , |
|||
const std::string & | password = "" , |
|||
bool | login = true | |||
) |
Connects to an IRC server.
Before calling connect, you must specify a nick, username, and realname via the set_nick(), set_username(), and set_realname() functions.
hostname | The hostname of the irc server to connect to. | |
port | (optional) The port to connect to. Defaults to 6667 if omitted. | |
password | (optional) The password to supply to the irc server. Defaults to blank if omitted. | |
login | (optional) If set to false, the NICK and USER commands will not be sent on connect - you must send them manually. Defaults to true if omitted. |
void ircpp::session::run | ( | ) |
Starts the IRC session running.
The run function goes into an endless loop, processing incoming messages and generating signals. It will only return when you are disconnected from the IRC server. The run function repeatedly calls service_socket() and select().
Note: You do not have to use run() - it is there only for convenience. If your program uses other sockets, or you wish to have more control over the main loop, you may use service_socket(), and call select() in your own loop.
bool ircpp::session::service_socket | ( | fd_set * | readfds, | |
fd_set * | writefds, | |||
fd_set * | exceptfds, | |||
int * | maxfd | |||
) |
Services the socket connecting the session to the IRC server.
Note: For a simpler way to run a single irc session, consider using run() instead of service_socket()
This function should be used in conjunction with the system call select(). After calling select() with your three fd_set variables, supply the same fd_sets to service_socket, along with the address of an integer, maxfd, which will be updated with the maximum file descripter number used , as required by select(). service_socket() will read and write data as necessary, then add its socket's file descriptors to the fd_sets you have provided, ready for select() to be called again.
bool ircpp::session::connected | ( | ) |
bool ircpp::session::disconnect | ( | ) |
Disconnects from the IRC server.
This function disconnects from the IRC server immediately. You should probably use cmd_quit instead.
bool ircpp::session::set_nick | ( | const std::string & | newnick | ) |
Sets the nickname.
Sets or changes the nick to be used by the session.
This function is for use before the session is connected, to set the initial nickname supplied to the server on login. To change nick while connected, use cmd_nick()
bool ircpp::session::set_username | ( | const std::string & | username | ) |
bool ircpp::session::set_realname | ( | const std::string & | realname | ) |
const user & ircpp::session::me | ( | ) | const |
const user & ircpp::session::server | ( | ) | const |
Returns the "server" user object.
The server to which we are connected is represented by a user object because it has a name, and sends server messages to us. Server messages will come from this user.
void ircpp::session::auto_pong | ( | bool | on | ) |
Enables or disables auto-pong.
By default, libircpp will automatically reply to PING requests from the IRC server with a PONG reply. If you want to reply manually to PING requests, set auto-pong to false.
on | Sets auto-pong on if true, off if false |
bool ircpp::session::auto_pong | ( | ) |
Returns whether or not auto-pong is enabled.
bool ircpp::session::has_capab | ( | const std::string & | name | ) |
Determine whether the irc server has a certain capability.
Server capabilities are reported in the 005 numeric when connecting to an IRC server and contain such information as the number of channels that may be joined, the network name, and the availability of many other features.
This function returns whether or not the irc server has mentioned a named capability in the 005 numeric. For more information and a list of capability names, see: http://www.irc.org/tech_docs/005.html
name | the name of the capability to be queried |
const string & ircpp::session::capab | ( | const std::string & | name | ) |
Return the value associated with a named server capability.
Many of the server capabilities reported in the 005 numeric are name=value pairs.
This function returns the value associated with a certain capability, for example NETWORK returns the network name, MAXCHANNELS returns the maximum number of channels that may be joined.
Use has_capab() to determine whether the server has capabilities that are not name=value pairs. For more information and a list of capability names, see: http://www.irc.org/tech_docs/005.html
name | the name of the capability to be queried |
void ircpp::session::ptr | ( | void * | p | ) |
Sets the user-defined pointer.
To help keep track of sessions, you can save a user-defined pointer inside the session object.
The user-defined pointer is of type void *, and you can set it to anything you like
p | The user-defined pointer to set |
void * ircpp::session::ptr | ( | ) | const |
Returns the user-defined pointer.
If the user-defined pointer has not yet been set, it will be NULL
bool ircpp::session::cmd_raw | ( | const std::string & | rawline | ) |
Sends a raw line of data to the IRC server.
The supplied line of data will be sent to the irc server unprocessed, except for the addition of a CRLF to the end.
rawline | The raw line of data to be sent |
bool ircpp::session::cmd_pass | ( | const std::string & | password | ) |
Sends the PASS message to the IRC server.
This command is used at connection registration to send a server password.
Note that if the login parameter to connect() is true (the default), the password will be sent automatically, and you will not need to use this function.
password | The server password to be sent |
bool ircpp::session::cmd_nick | ( | const std::string & | newnick | ) |
Sends the NICK message to the IRC server.
This command is used at connection registration to send the nickname, and while connected to change nick.
Note that if the login parameter to connect() is true (the default), the nick will be sent automatically, and you will not need to use this function at login time.
newnick | The nickname to be sent |
bool ircpp::session::cmd_user | ( | const std::string & | username, | |
const std::string & | hostname, | |||
const std::string & | servername, | |||
const std::string & | realname | |||
) |
Sends the USER message to the IRC server.
This command is used at connection registration to set the username, hostname, servername, and realname
Note that if the login parameter to connect() is true (the default), these details will be sent automatically, and you will not need to use this function.
username | The username to be sent | |
hostname | The hostname to be sent | |
servername | The servername to be sent | |
realname | The realname to be sent |
bool ircpp::session::cmd_quit | ( | const std::string & | quitmsg | ) |
bool ircpp::session::cmd_join | ( | const std::string & | channel, | |
const std::string & | key = "" | |||
) |
bool ircpp::session::cmd_part | ( | const std::string & | channel, | |
const std::string & | partmsg = "" | |||
) |
Sends the PART message to the IRC server.
This command is used to leave a channel, and optionally display a part message.
Note that you can also use the channel object's cmd_part() function to leave a specific channel
bool ircpp::session::cmd_mode | ( | const std::string & | target, | |
const std::string & | modestring | |||
) |
Sends the MODE message to the IRC server.
This command is used to change a mode on a user or channel
Note that you can also use the entity object's cmd_mode() function to change the mode of a user or channel
target | The user or channel on which to change the mode. | |
modestring | A string describing the mode change (e.g. "+o Joebloggs") |
bool ircpp::session::cmd_topic | ( | const std::string & | channel, | |
const std::string & | topic | |||
) |
Sends the TOPIC message to the IRC server.
This command is used to change a channel's topic
Note that you can also use the channel object's cmd_topic() function to change a channel's topic
bool ircpp::session::cmd_names | ( | const std::string & | channel | ) |
Sends the NAMES message to the IRC server.
This command is used to request the list of nicknames that are in a channel
Note that you can also use the channel object's cmd_names() function to request the nickname list of a channel
bool ircpp::session::cmd_list | ( | const std::string & | params = "" |
) |
bool ircpp::session::cmd_invite | ( | const std::string & | nick, | |
const std::string & | channel | |||
) |
Sends the INVITE message to the IRC server.
This command is used to invite a user to a channel
Note that you can also use the channel object's cmd_names() function to request the nickname list of a channel
bool ircpp::session::cmd_kick | ( | const std::string & | nick, | |
const std::string & | channel, | |||
const std::string & | reason = "" | |||
) |
Sends the KICK message to the IRC server.
This command is used to kick a user from a channel
Note that you can also use the channel object's cmd_kick() function to kick a user from a channel
nick | The nickname to kick | |
channel | The channel to kick the user from | |
reason | (optional) The reason for kicking the user |
bool ircpp::session::cmd_privmsg | ( | const std::string & | to, | |
const std::string & | message | |||
) |
Sends the PRIVMSG message to the IRC server.
This command is used to send a message to a user or channel. Contrary to its name, PRIVMSG is used for both private messages and normal messages to channels.
Note that you can also use the entity object's cmd_privmsg() function to send a message to a user or channel
bool ircpp::session::cmd_notice | ( | const std::string & | to, | |
const std::string & | message | |||
) |
Sends the NOTICE message to the IRC server.
This command is used to send a notice to a user or channel
Note that you can also use the entity object's cmd_notice() function to send a notice to a user or channel
to | The name of the user or channel to send the notice to | |
message | The text of notice to send |
bool ircpp::session::cmd_ctcp | ( | const std::string & | to, | |
const std::string & | command, | |||
const std::string & | params | |||
) |
Sends the CTCP message to the IRC server.
This command is used to send a CTCP command to a user or channel
Note that you can also use the entity object's cmd_ctcp() function to send a CTCP command to a user or channel
to | The name of the user or channel to send the CTCP message to | |
command | The CTCP command to send (e.g. "ACTION") | |
params | The parameters of the command |
bool ircpp::session::cmd_ping | ( | const std::string & | params | ) |
Sends the PING message to the IRC server.
This command is used to send a PING message to the IRC server. Note that this is different from the more commonly used CTCP PING command, used to "ping" a user. To send a CTCP PING, use cmd_ctcp()
params | The parameters of the command |
bool ircpp::session::cmd_pong | ( | const std::string & | params | ) |
Sends the PONG message to the IRC server.
This command is used to send a PONG message to the IRC server.
Note that by default, libircpp automatically sends PONG messages in response to the server's PING messages. If you want to do this manually, turn auto_pong() off, then use this command.
params | The parameters of the command |
bool ircpp::session::cmd_away | ( | const std::string & | message = "" |
) |
bool ircpp::session::cmd_oper | ( | const std::string & | opernick, | |
const std::string & | operpass | |||
) |
Sends the OPER message to the IRC server.
This command is used to obtain IRC Operator status
opernick | Your operator nick, as set in your O: line | |
operpass | Your operator password, as set in your O: line |
bool ircpp::session::cmd_who | ( | const std::string & | params | ) |
bool ircpp::session::cmd_whois | ( | const std::string & | target | ) |
listmode ircpp::session::list_mode | ( | ) | const |
Returns this session's list mode.
See the manual section on lists for more information (http://libircpp.sf.net/manual/lists.html).
const channel & ircpp::session::find_channel | ( | const std::string & | name | ) | const |
Finds a channel in the internal channel list.
If the internal lists are enabled, libircpp will keep track of all the channels you are in. This function finds a channel object from the channel list. See the manual section on lists for more information (http://libircpp.sf.net/manual/lists.html).
If the channel cannot be found, a reference to the null channel will be returned. You can test for this with if(!ch), where ch is the returned reference.
name | The name of the channel to find |
const irclist< channel >::iterator ircpp::session::channellist_begin | ( | ) | const |
Returns an iterator the beginning of the channel list.
If the internal lists are enabled, libircpp will keep track of all the channels you are in. This function returns an iterator to the start of the channel list. See the manual section on lists for more information (http://libircpp.sf.net/manual/lists.html).
const irclist< channel >::iterator ircpp::session::channellist_end | ( | ) | const |
Returns an iterator the end of the channel list.
If the internal lists are enabled, libircpp will keep track of all the channels you are in. This function returns an iterator to the end of the channel list. See the manual section on lists for more information (http://libircpp.sf.net/manual/lists.html).
const user & ircpp::session::find_user | ( | const std::string & | nick | ) | const |
Finds a user in the internal user list.
If the internal lists are enabled, libircpp will keep track of all users who share a channel with you. This function finds a user object from the user list. See the manual section on lists for more information (http://libircpp.sf.net/manual/lists.html).
If the user cannot be found, a reference to the null user will be returned. You can test for this with if(!u), where u is the returned reference.
nick | The nick of the user to find |
const irclist< user >::iterator ircpp::session::userlist_begin | ( | ) | const |
Returns an iterator the beginning of the user list.
If the internal lists are enabled, libircpp will keep track of all users who share a channel with you. This function returns an iterator to the start of the user list. See the manual section on lists for more information (http://libircpp.sf.net/manual/lists.html).
const irclist< user >::iterator ircpp::session::userlist_end | ( | ) | const |
Returns an iterator the beginning of the user list.
If the internal lists are enabled, libircpp will keep track of all users who share a channel with you. This function returns an iterator to the end of the user list. See the manual section on lists for more information (http://libircpp.sf.net/manual/lists.html).
boost::signal0<void> ircpp::session::sig_connected |
boost::signal1<void, const std::string&> ircpp::session::sig_disconnected |
Emitted when the session is disconnected from the IRC server.
Whenever the session is disconnected, for any reason, this message will be emitted. The first parameter contains a brief textual description of the reason for disconnection, such as "Quit", or "Ping Timeout"
reason | The reason for disconnection |
boost::signal2<void, const std::string&, const int> ircpp::session::sig_socket_error |
Emitted when a network socket error occurs.
The parameters indicate a textual and integer representation of the error code, as detailed in the standard errno.h. Note that sig_disconnected will be emitted in addition to this signal
string | Textual error reason | |
int | Numerical error reason (see errno) |
boost::signal1<void, user*> ircpp::session::sig_user_deletable |
Emitted when a user may be safely deleted.
When the session has its lists set to manual mode, it is your responsibility to delete user and channel objects when finished with them. This signal indicates that libircpp has finshed with a user object, and you may safely delete it when you no longer need it. For more information, see the manual section on lists
boost::signal1<void, channel*> ircpp::session::sig_channel_deletable |
Emitted when a channel may be safely deleted.
When the session has its lists set to manual mode, it is your responsibility to delete user and channel objects when finished with them. This signal indicates that libircpp has finshed with a channel object, and you may safely delete it when you no longer need it. For more information, see the manual section on lists
boost::signal1<void, const std::string&> ircpp::session::sig_parseerror |
Emitted when a parse error occurs If the parser cannot understand a line sent to it by the IRC server it will give up and emit this signal.
string | The line that failed to parse. |
boost::signal1<void, const message &> ircpp::session::sig_all_msgs |
boost::signal1<void, const message &> ircpp::session::sig_unknown_msg |
boost::signal1<void, const message &> ircpp::session::sig_numeric_msg |
boost::signal1<void, const message &> ircpp::session::sig_nick_msg |
boost::signal1<void, const message &> ircpp::session::sig_quit_msg |
boost::signal1<void, const message &> ircpp::session::sig_join_msg |
boost::signal1<void, const message &> ircpp::session::sig_part_msg |
boost::signal1<void, const message &> ircpp::session::sig_mode_msg |
boost::signal1<void, const message &> ircpp::session::sig_singlemode_msg |
Emitted for each individual mode change.
Because each MODE message may contain more than one mode change, it is useful to split them up into individual mode changes.
Each time a MODE message arrives, libircpp first emits sig_mode_msg, then splits the MODE message up into individual mode changes, and for each one emits sig_singlemode_msg, which contains an artificial MODE message corresponding to that single mode.
Note that MODE messages emitted by this signal are not real messages which have arrived from the IRC server, but are generated artificially.
boost::signal1<void, const message &> ircpp::session::sig_topic_msg |
boost::signal1<void, const message &> ircpp::session::sig_invite_msg |
boost::signal1<void, const message &> ircpp::session::sig_kick_msg |
boost::signal1<void, const message &> ircpp::session::sig_privmsg_msg |
boost::signal1<void, const message &> ircpp::session::sig_ctcp_msg |
boost::signal1<void, const message &> ircpp::session::sig_notice_msg |
boost::signal1<void, const message &> ircpp::session::sig_ping_msg |
boost::signal1<void, const message &> ircpp::session::sig_pong_msg |
boost::signal1<void, const message &> ircpp::session::sig_error_msg |