19 #ifndef IRCCD_DAEMON_SERVER_HPP
20 #define IRCCD_DAEMON_SERVER_HPP
27 #include <irccd/sysconfig.hpp>
85 std::shared_ptr<class server>
server;
93 std::shared_ptr<class server>
server;
231 using event = std::variant<
256 class server :
public std::enable_shared_from_this<server> {
299 std::vector<channel> rchannels_;
300 std::set<std::string> jchannels_;
306 std::string hostname_;
307 std::string password_;
308 std::uint16_t port_{6667};
312 std::string nickname_{
"irccd"};
313 std::string username_{
"irccd"};
314 std::string realname_{
"IRC Client Daemon"};
315 std::string ctcpversion_{
"IRC Client Daemon"};
318 std::string command_char_{
"!"};
319 std::uint16_t recodelay_{30};
320 std::uint16_t timeout_{1000};
323 std::map<channel_mode, char> modes_;
326 boost::asio::io_service& service_;
327 boost::asio::deadline_timer timer_;
328 std::shared_ptr<irc::connection> conn_;
329 std::deque<std::string> queue_;
330 std::map<std::string, std::set<std::string>> names_map_;
331 std::map<std::string, whois_info> whois_map_;
333 auto dispatch_connect(
const irc::message&,
const recv_handler&) -> bool;
334 auto dispatch_endofnames(
const irc::message&,
const recv_handler&) -> bool;
335 auto dispatch_endofwhois(
const irc::message&,
const recv_handler&) -> bool;
336 auto dispatch_invite(
const irc::message&,
const recv_handler&) -> bool;
337 auto dispatch_isupport(
const irc::message&) -> bool;
338 auto dispatch_join(
const irc::message&,
const recv_handler&) -> bool;
339 auto dispatch_kick(
const irc::message&,
const recv_handler&) -> bool;
340 auto dispatch_mode(
const irc::message&,
const recv_handler&) -> bool;
341 auto dispatch_namreply(
const irc::message&) -> bool;
342 auto dispatch_nick(
const irc::message&,
const recv_handler&) -> bool;
343 auto dispatch_notice(
const irc::message&,
const recv_handler&) -> bool;
344 auto dispatch_part(
const irc::message&,
const recv_handler&) -> bool;
345 auto dispatch_ping(
const irc::message&) -> bool;
346 auto dispatch_privmsg(
const irc::message&,
const recv_handler&) -> bool;
347 auto dispatch_topic(
const irc::message&,
const recv_handler&) -> bool;
348 auto dispatch_whoischannels(
const irc::message&) -> bool;
349 auto dispatch_whoisuser(
const irc::message&) -> bool;
350 auto dispatch(
const irc::message&,
const recv_handler&) -> bool;
355 void handle_send(
const std::error_code&);
356 void handle_recv(
const std::error_code&,
const irc::message&,
const recv_handler&);
368 server(boost::asio::io_service& service, std::string
id, std::string hostname =
"localhost");
620 std::string_view reason = "");
650 std::string_view limit = "",
651 std::string_view user = "",
652 std::string_view mask = "");
720 return static_cast<server::options>(
static_cast<unsigned>(v1) ^
static_cast<unsigned>(v2));
732 return static_cast<server::options>(
static_cast<unsigned>(v1) &
static_cast<unsigned>(v2));
744 return static_cast<server::options>(
static_cast<unsigned>(v1) |
static_cast<unsigned>(v2));
830 invalid_reconnect_delay,
854 invalid_ping_timeout,
857 invalid_ctcp_version,
860 invalid_command_char,
Server error.
Definition: server.hpp:802
error
Server related errors.
Definition: server.hpp:807
server_error(error code) noexcept
The class that connect to a IRC server.
Definition: server.hpp:256
auto get_state() const noexcept -> state
auto get_command_char() const noexcept -> const std::string &
virtual void message(std::string_view target, std::string_view message)
std::function< void(std::error_code, event)> recv_handler
Definition: server.hpp:266
virtual void invite(std::string_view target, std::string_view channel)
virtual void part(std::string_view channel, std::string_view reason="")
server(boost::asio::io_service &service, std::string id, std::string hostname="localhost")
auto is_self(std::string_view nick) const noexcept -> bool
virtual void wait(connect_handler handler)
virtual void kick(std::string_view target, std::string_view channel, std::string_view reason="")
options
Various options for server.
Definition: server.hpp:271
@ ipv4
Connect using IPv4.
@ auto_rejoin
Auto rejoin a kick.
@ auto_reconnect
Auto reconnect on disconnection.
@ join_invite
Join a channel on invitation.
@ ipv6
Connect using IPv6.
auto get_ping_timeout() const noexcept -> std::uint16_t
void set_nickname(std::string nickname)
void set_port(std::uint16_t port) noexcept
auto get_nickname() const noexcept -> const std::string &
state
Describe current server state.
Definition: server.hpp:284
@ connected
ready for use.
@ disconnected
not connected at all,
@ connecting
network connection in progress,
@ identifying
sending nick, user and password commands,
void set_options(options flags) noexcept
auto get_port() const noexcept -> std::uint16_t
void set_reconnect_delay(std::uint16_t reconnect_delay) noexcept
virtual void notice(std::string_view target, std::string_view message)
auto get_ctcp_version() const noexcept -> const std::string &
std::function< void(std::error_code)> connect_handler
Definition: server.hpp:261
auto get_reconnect_delay() const noexcept -> std::uint16_t
auto get_channels() const noexcept -> const std::set< std::string > &
void set_ping_timeout(std::uint16_t ping_timeout) noexcept
virtual void topic(std::string_view channel, std::string_view topic)
state state_
Server state.
Definition: server.hpp:295
auto get_password() const noexcept -> const std::string &
auto get_username() const noexcept -> const std::string &
auto get_hostname() const noexcept -> const std::string &
virtual void disconnect()
virtual void me(std::string_view target, std::string_view message)
virtual void connect(connect_handler handler) noexcept
void set_username(std::string name) noexcept
void set_command_char(std::string command_char) noexcept
auto get_id() const noexcept -> const std::string &
virtual void mode(std::string_view channel, std::string_view mode, std::string_view limit="", std::string_view user="", std::string_view mask="")
void set_realname(std::string realname) noexcept
void set_ctcp_version(std::string ctcpversion)
virtual void send(std::string_view raw)
virtual void join(std::string_view channel, std::string_view password="")
auto get_options() const noexcept -> options
virtual void names(std::string_view channel)
virtual void whois(std::string_view target)
auto get_realname() const noexcept -> const std::string &
void set_password(std::string password) noexcept
virtual void recv(recv_handler handler) noexcept
std::variant< std::monostate, connect_event, disconnect_event, invite_event, join_event, kick_event, me_event, message_event, mode_event, names_event, nick_event, notice_event, part_event, topic_event, whois_event > event
Store all possible events.
Definition: server.hpp:247
channel_mode
Prefixes for nicknames.
Definition: server.hpp:51
@ creator
Channel creator.
Main irccd namespace.
Definition: bot.hpp:41
auto server_category() -> const std::error_category &
auto make_error_code(bot_error::error e) noexcept -> std::error_code
Parent namespace.
Definition: acceptor.hpp:43
A channel to join with an optional password.
Definition: server.hpp:63
std::string name
the channel to join
Definition: server.hpp:64
std::string password
the optional password
Definition: server.hpp:65
Connection success event.
Definition: server.hpp:84
std::shared_ptr< class server > server
The server.
Definition: server.hpp:85
Connection success event.
Definition: server.hpp:92
std::shared_ptr< class server > server
The server.
Definition: server.hpp:93
Invite event.
Definition: server.hpp:100
std::string nickname
The nickname (you).
Definition: server.hpp:104
std::string origin
The originator.
Definition: server.hpp:102
std::shared_ptr< class server > server
The server.
Definition: server.hpp:101
std::string channel
The channel.
Definition: server.hpp:103
Join event.
Definition: server.hpp:111
std::string channel
The channel.
Definition: server.hpp:114
std::string origin
The originator.
Definition: server.hpp:113
std::shared_ptr< class server > server
The server.
Definition: server.hpp:112
Kick event.
Definition: server.hpp:121
std::string reason
The reason (Optional).
Definition: server.hpp:126
std::string origin
The originator.
Definition: server.hpp:123
std::shared_ptr< class server > server
The server.
Definition: server.hpp:122
std::string channel
The channel.
Definition: server.hpp:124
std::string target
The target.
Definition: server.hpp:125
CTCP action event.
Definition: server.hpp:144
std::shared_ptr< class server > server
The server.
Definition: server.hpp:145
std::string origin
The originator.
Definition: server.hpp:146
std::string channel
The channel.
Definition: server.hpp:147
std::string message
The message.
Definition: server.hpp:148
Message event.
Definition: server.hpp:133
std::shared_ptr< class server > server
The server.
Definition: server.hpp:134
std::string message
The message.
Definition: server.hpp:137
std::string origin
The originator.
Definition: server.hpp:135
std::string channel
The channel.
Definition: server.hpp:136
Mode event.
Definition: server.hpp:155
std::string channel
The channel or target.
Definition: server.hpp:158
std::string limit
The optional limit.
Definition: server.hpp:160
std::shared_ptr< class server > server
The server.
Definition: server.hpp:156
std::string mode
The mode.
Definition: server.hpp:159
std::string mask
The optional ban mask.
Definition: server.hpp:162
std::string user
The optional user.
Definition: server.hpp:161
std::string origin
The originator.
Definition: server.hpp:157
Names listing event.
Definition: server.hpp:169
std::string channel
The channel.
Definition: server.hpp:171
std::vector< std::string > names
The names.
Definition: server.hpp:172
std::shared_ptr< class server > server
The server.
Definition: server.hpp:170
Nick change event.
Definition: server.hpp:179
std::string origin
The originator.
Definition: server.hpp:181
std::shared_ptr< class server > server
The server.
Definition: server.hpp:180
std::string nickname
The new nickname.
Definition: server.hpp:182
Notice event.
Definition: server.hpp:189
std::string channel
The channel or target.
Definition: server.hpp:192
std::string origin
The originator.
Definition: server.hpp:191
std::string message
The message.
Definition: server.hpp:193
std::shared_ptr< class server > server
The server.
Definition: server.hpp:190
Part event.
Definition: server.hpp:200
std::string reason
The reason.
Definition: server.hpp:204
std::string origin
The originator.
Definition: server.hpp:202
std::string channel
The channel.
Definition: server.hpp:203
std::shared_ptr< class server > server
The server.
Definition: server.hpp:201
Topic event.
Definition: server.hpp:211
std::string origin
The originator.
Definition: server.hpp:213
std::string topic
The topic message.
Definition: server.hpp:215
std::shared_ptr< class server > server
The server.
Definition: server.hpp:212
std::string channel
The channel.
Definition: server.hpp:214
Whois event.
Definition: server.hpp:222
std::shared_ptr< class server > server
The server.
Definition: server.hpp:223
whois_info whois
The whois information.
Definition: server.hpp:224
Describe a whois information.
Definition: server.hpp:72
std::string nick
user's nickname
Definition: server.hpp:73
std::string hostname
hostname
Definition: server.hpp:75
std::string user
user's user
Definition: server.hpp:74
std::string realname
realname
Definition: server.hpp:76
std::vector< std::string > channels
the channels where the user is
Definition: server.hpp:77