irccd  3.0.3
Public Types | Public Member Functions | Protected Attributes | List of all members
irccd::daemon::server Class Reference

The class that connect to a IRC server. More...

#include <server.hpp>

Inheritance diagram for irccd::daemon::server:
irccd::test::debug_server irccd::test::mock_server

Public Types

enum class  options : std::uint8_t {
  none = 0 , ipv4 = (1 << 0) , ipv6 = (1 << 1) , ssl = (1 << 2) ,
  auto_rejoin = (1 << 3) , auto_reconnect = (1 << 4) , join_invite = (1 << 5)
}
 Various options for server. More...
 
enum class  state : std::uint8_t { disconnected , connecting , identifying , connected }
 Describe current server state. More...
 
using connect_handler = std::function< void(std::error_code)>
 
using recv_handler = std::function< void(std::error_code, event)>
 

Public Member Functions

 server (boost::asio::io_service &service, std::string id, std::string hostname="localhost")
 
virtual ~server ()
 
auto get_state () const noexcept -> state
 
auto get_id () const noexcept -> const std::string &
 
auto get_hostname () const noexcept -> const std::string &
 
auto get_password () const noexcept -> const std::string &
 
void set_password (std::string password) noexcept
 
auto get_port () const noexcept -> std::uint16_t
 
void set_port (std::uint16_t port) noexcept
 
auto get_options () const noexcept -> options
 
void set_options (options flags) noexcept
 
auto get_nickname () const noexcept -> const std::string &
 
void set_nickname (std::string nickname)
 
auto get_username () const noexcept -> const std::string &
 
void set_username (std::string name) noexcept
 
auto get_realname () const noexcept -> const std::string &
 
void set_realname (std::string realname) noexcept
 
auto get_ctcp_version () const noexcept -> const std::string &
 
void set_ctcp_version (std::string ctcpversion)
 
auto get_command_char () const noexcept -> const std::string &
 
void set_command_char (std::string command_char) noexcept
 
auto get_reconnect_delay () const noexcept -> std::uint16_t
 
void set_reconnect_delay (std::uint16_t reconnect_delay) noexcept
 
auto get_ping_timeout () const noexcept -> std::uint16_t
 
void set_ping_timeout (std::uint16_t ping_timeout) noexcept
 
auto get_channels () const noexcept -> const std::set< std::string > &
 
auto is_self (std::string_view nick) const noexcept -> bool
 
virtual void connect (connect_handler handler) noexcept
 
virtual void disconnect ()
 
virtual void wait (connect_handler handler)
 
virtual void recv (recv_handler handler) noexcept
 
virtual void invite (std::string_view target, std::string_view channel)
 
virtual void join (std::string_view channel, std::string_view password="")
 
virtual void kick (std::string_view target, std::string_view channel, std::string_view reason="")
 
virtual void me (std::string_view target, std::string_view message)
 
virtual void message (std::string_view target, std::string_view message)
 
virtual void mode (std::string_view channel, std::string_view mode, std::string_view limit="", std::string_view user="", std::string_view mask="")
 
virtual void names (std::string_view channel)
 
virtual void notice (std::string_view target, std::string_view message)
 
virtual void part (std::string_view channel, std::string_view reason="")
 
virtual void send (std::string_view raw)
 
virtual void topic (std::string_view channel, std::string_view topic)
 
virtual void whois (std::string_view target)
 

Protected Attributes

state state_ {state::disconnected}
 Server state. More...
 

Detailed Description

The class that connect to a IRC server.

This class is higher level than irc connection, it does identify process, parsing message, translating messages and queue'ing user requests.

Member Typedef Documentation

◆ connect_handler

using irccd::daemon::server::connect_handler = std::function<void (std::error_code)>

Completion handler once network connection is complete.

◆ recv_handler

using irccd::daemon::server::recv_handler = std::function<void (std::error_code, event)>

Completion handler once a network message has arrived.

Member Enumeration Documentation

◆ options

enum irccd::daemon::server::options : std::uint8_t
strong

Various options for server.

Enumerator
none 

No options.

ipv4 

Connect using IPv4.

ipv6 

Connect using IPv6.

ssl 

Use SSL.

auto_rejoin 

Auto rejoin a kick.

auto_reconnect 

Auto reconnect on disconnection.

join_invite 

Join a channel on invitation.

◆ state

enum irccd::daemon::server::state : std::uint8_t
strong

Describe current server state.

Enumerator
disconnected 

not connected at all,

connecting 

network connection in progress,

identifying 

sending nick, user and password commands,

connected 

ready for use.

Constructor & Destructor Documentation

◆ server()

irccd::daemon::server::server ( boost::asio::io_service &  service,
std::string  id,
std::string  hostname = "localhost" 
)

Construct a server.

Precondition
!host.empty()
Parameters
servicethe service
idthe identifier
hostnamethe hostname

◆ ~server()

virtual irccd::daemon::server::~server ( )
virtual

Destructor. Close the connection if needed.

Member Function Documentation

◆ connect()

virtual void irccd::daemon::server::connect ( connect_handler  handler)
virtualnoexcept

Start connecting.

This only initiate TCP connection and/or SSL handshaking, the identifying process may take some time and you must repeatedly call recv() to wait for connect_event.

Precondition
handler != nullptr
Parameters
handlerthe completion handler
Note
the server must be kept alive until completion

Reimplemented in irccd::test::mock_server, and irccd::test::debug_server.

◆ disconnect()

virtual void irccd::daemon::server::disconnect ( )
virtual

Force disconnection.

Reimplemented in irccd::test::mock_server, and irccd::test::debug_server.

◆ get_channels()

auto irccd::daemon::server::get_channels ( ) const -> const std::set< std::string > &
noexcept

Get the list of channels joined.

Returns
the channels

◆ get_command_char()

auto irccd::daemon::server::get_command_char ( ) const -> const std::string &
noexcept

Get the command character.

Returns
the character

◆ get_ctcp_version()

auto irccd::daemon::server::get_ctcp_version ( ) const -> const std::string &
noexcept

Get the CTCP version.

Returns
the CTCP version

◆ get_hostname()

auto irccd::daemon::server::get_hostname ( ) const -> const std::string &
noexcept

Get the hostname.

Returns
the hostname

◆ get_id()

auto irccd::daemon::server::get_id ( ) const -> const std::string &
noexcept

Get the server identifier.

Returns
the id

◆ get_nickname()

auto irccd::daemon::server::get_nickname ( ) const -> const std::string &
noexcept

Get the nickname.

Returns
the nickname

◆ get_options()

auto irccd::daemon::server::get_options ( ) const -> options
noexcept

Get the options flags.

Returns
the flags

◆ get_password()

auto irccd::daemon::server::get_password ( ) const -> const std::string &
noexcept

Get the password.

Returns
the password

◆ get_ping_timeout()

auto irccd::daemon::server::get_ping_timeout ( ) const -> std::uint16_t
noexcept

Get the ping timeout.

Returns
the ping timeout

◆ get_port()

auto irccd::daemon::server::get_port ( ) const -> std::uint16_t
noexcept

Get the port.

Returns
the port

◆ get_realname()

auto irccd::daemon::server::get_realname ( ) const -> const std::string &
noexcept

Get the realname.

Returns
the realname

◆ get_reconnect_delay()

auto irccd::daemon::server::get_reconnect_delay ( ) const -> std::uint16_t
noexcept

Get the reconnection delay before retrying.

Returns
the number of seconds

◆ get_state()

auto irccd::daemon::server::get_state ( ) const -> state
noexcept

Get the current server state.

Returns
the state

◆ get_username()

auto irccd::daemon::server::get_username ( ) const -> const std::string &
noexcept

Get the username.

Returns
the username

◆ invite()

virtual void irccd::daemon::server::invite ( std::string_view  target,
std::string_view  channel 
)
virtual

Invite a user to a channel.

Parameters
targetthe target nickname
channelthe channel

Reimplemented in irccd::test::mock_server, and irccd::test::debug_server.

◆ is_self()

auto irccd::daemon::server::is_self ( std::string_view  nick) const -> bool
noexcept

Determine if the nickname is the bot itself.

Parameters
nickthe nickname to check
Returns
true if it is the bot

◆ join()

virtual void irccd::daemon::server::join ( std::string_view  channel,
std::string_view  password = "" 
)
virtual

Join a channel, the password is optional and can be kept empty.

Parameters
channelthe channel to join
passwordthe optional password

Reimplemented in irccd::test::mock_server, and irccd::test::debug_server.

◆ kick()

virtual void irccd::daemon::server::kick ( std::string_view  target,
std::string_view  channel,
std::string_view  reason = "" 
)
virtual

Kick someone from the channel. Please be sure to have the rights on that channel because errors won't be reported.

Parameters
targetthe target to kick
channelfrom which channel
reasonthe optional reason

Reimplemented in irccd::test::mock_server, and irccd::test::debug_server.

◆ me()

virtual void irccd::daemon::server::me ( std::string_view  target,
std::string_view  message 
)
virtual

Send a CTCP Action as known as /me. The target may be either a channel or a nickname.

Parameters
targetthe nickname or the channel
messagethe message

Reimplemented in irccd::test::mock_server, and irccd::test::debug_server.

◆ message()

virtual void irccd::daemon::server::message ( std::string_view  target,
std::string_view  message 
)
virtual

Send a message to the specified target or channel.

Parameters
targetthe target
messagethe message

Reimplemented in irccd::test::mock_server, and irccd::test::debug_server.

◆ mode()

virtual void irccd::daemon::server::mode ( std::string_view  channel,
std::string_view  mode,
std::string_view  limit = "",
std::string_view  user = "",
std::string_view  mask = "" 
)
virtual

Change channel/user mode.

Parameters
channelthe channel or nickname
modethe mode
limitthe optional limit
userthe optional user
maskthe optional ban mask

Reimplemented in irccd::test::mock_server, and irccd::test::debug_server.

◆ names()

virtual void irccd::daemon::server::names ( std::string_view  channel)
virtual

Request the list of names.

Parameters
channelthe channel

Reimplemented in irccd::test::mock_server, and irccd::test::debug_server.

◆ notice()

virtual void irccd::daemon::server::notice ( std::string_view  target,
std::string_view  message 
)
virtual

Send a private notice.

Parameters
targetthe target
messagethe notice message

Reimplemented in irccd::test::mock_server, and irccd::test::debug_server.

◆ part()

virtual void irccd::daemon::server::part ( std::string_view  channel,
std::string_view  reason = "" 
)
virtual

Part from a channel.

Please note that the reason is not supported on all servers so if you want portability, don't provide it.

Parameters
channelthe channel to leave
reasonthe optional reason

Reimplemented in irccd::test::mock_server, and irccd::test::debug_server.

◆ recv()

virtual void irccd::daemon::server::recv ( recv_handler  handler)
virtualnoexcept

Receive next event.

Precondition
handler != nullptr
Parameters
handlerthe handler
Note
the server must be kept alive until completion

◆ send()

virtual void irccd::daemon::server::send ( std::string_view  raw)
virtual

Send a raw message to the IRC server. You don't need to add message terminators.

If the server is not yet connected, the command is postponed and will be ran when ready.

Parameters
rawthe raw message (without \r\n\r\n)

Reimplemented in irccd::test::mock_server, and irccd::test::debug_server.

◆ set_command_char()

void irccd::daemon::server::set_command_char ( std::string  command_char)
noexcept

Set the command character.

Precondition
!command_char_.empty()
Parameters
command_charthe command character

◆ set_ctcp_version()

void irccd::daemon::server::set_ctcp_version ( std::string  ctcpversion)

Set the CTCP version.

Parameters
ctcpversionthe version

◆ set_nickname()

void irccd::daemon::server::set_nickname ( std::string  nickname)

Set the nickname.

If the server is connected, send a nickname command to the IRC server, otherwise change it instantly.

Parameters
nicknamethe nickname

◆ set_options()

void irccd::daemon::server::set_options ( options  flags)
noexcept

Set the options flags.

Parameters
flagsthe flags

◆ set_password()

void irccd::daemon::server::set_password ( std::string  password)
noexcept

Set the password.

An empty password means no password.

Parameters
passwordthe password

◆ set_ping_timeout()

void irccd::daemon::server::set_ping_timeout ( std::uint16_t  ping_timeout)
noexcept

Set the ping timeout before considering a server as dead.

Parameters
ping_timeoutthe delay in seconds

◆ set_port()

void irccd::daemon::server::set_port ( std::uint16_t  port)
noexcept

Set the port.

Parameters
portthe port

◆ set_realname()

void irccd::daemon::server::set_realname ( std::string  realname)
noexcept

Set the realname.

Parameters
realnamethe username
Note
the username will be changed on the next connection

◆ set_reconnect_delay()

void irccd::daemon::server::set_reconnect_delay ( std::uint16_t  reconnect_delay)
noexcept

Set the number of seconds before retrying.

Parameters
reconnect_delaythe number of seconds

◆ set_username()

void irccd::daemon::server::set_username ( std::string  name)
noexcept

Set the username.

Parameters
namethe username
Note
the username will be changed on the next connection

◆ topic()

virtual void irccd::daemon::server::topic ( std::string_view  channel,
std::string_view  topic 
)
virtual

Change the channel topic.

Parameters
channelthe channel
topicthe desired topic

Reimplemented in irccd::test::mock_server, and irccd::test::debug_server.

◆ wait()

virtual void irccd::daemon::server::wait ( connect_handler  handler)
virtual

Wait for reconnect delay.

Precondition
another wait operation must not be running
get_state() == state::disconnected

◆ whois()

virtual void irccd::daemon::server::whois ( std::string_view  target)
virtual

Request for whois information.

Parameters
targetthe target nickname

Reimplemented in irccd::test::mock_server, and irccd::test::debug_server.

Member Data Documentation

◆ state_

state irccd::daemon::server::state_ {state::disconnected}
protected

Server state.


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