xbot/client.hpp

104 lines
2.7 KiB
C++
Raw Normal View History

2023-11-26 16:48:21 -08:00
#pragma once
2025-01-24 14:48:15 -08:00
#include "connection.hpp"
2025-01-25 12:25:38 -08:00
#include "sasl_mechanism.hpp"
2025-01-24 14:48:15 -08:00
2024-03-03 12:27:36 -08:00
#include <string>
#include <unordered_set>
2025-01-27 17:46:07 -08:00
#include <span>
2023-11-26 16:48:21 -08:00
struct Connection;
2024-03-03 12:53:59 -08:00
struct IrcMsg;
2023-11-26 16:48:21 -08:00
2025-01-25 21:24:33 -08:00
enum class Casemap
{
Rfc1459,
Rfc1459_Strict,
Ascii,
};
2025-01-27 17:46:07 -08:00
struct Chat {
std::span<const irctag> tags;
bool is_notice;
char status_msg;
std::string_view source;
std::string_view target;
std::string_view message;
};
2024-03-03 12:27:36 -08:00
/**
* @brief Thread to track this connection's identity, and IRC state.
2025-01-25 15:45:31 -08:00
*
2024-03-03 12:27:36 -08:00
*/
2025-01-26 19:35:56 -08:00
class Client
2023-11-26 16:48:21 -08:00
{
2025-01-25 15:45:31 -08:00
Connection &connection_;
2025-01-25 12:25:38 -08:00
2023-11-26 16:48:21 -08:00
std::string nickname_;
std::string mode_;
2024-03-03 12:27:36 -08:00
std::unordered_set<std::string> channels_;
2025-01-25 12:25:38 -08:00
// RPL_ISUPPORT state
2025-01-24 14:48:15 -08:00
std::unordered_map<std::string, std::string> isupport_;
2025-01-25 12:25:38 -08:00
std::unique_ptr<SaslMechanism> sasl_mechanism_;
2025-01-25 21:24:33 -08:00
Casemap casemap_;
std::string channel_prefix_;
2025-01-27 17:46:07 -08:00
std::string status_msg_;
2025-01-25 21:24:33 -08:00
2025-01-27 11:08:16 -08:00
std::unordered_map<std::string, std::string> caps_available_;
std::unordered_set<std::string> caps_;
2025-01-25 15:45:31 -08:00
auto on_welcome(const IrcMsg &irc) -> void;
auto on_isupport(const IrcMsg &irc) -> void;
auto on_nick(const IrcMsg &irc) -> void;
auto on_umodeis(const IrcMsg &irc) -> void;
auto on_join(const IrcMsg &irc) -> void;
auto on_kick(const IrcMsg &irc) -> void;
auto on_part(const IrcMsg &irc) -> void;
auto on_mode(const IrcMsg &irc) -> void;
2025-01-27 11:08:16 -08:00
auto on_cap(const IrcMsg &irc) -> void;
2025-01-25 12:25:38 -08:00
auto on_authenticate(std::string_view) -> void;
2025-01-25 21:24:33 -08:00
auto on_registered() -> void;
2025-01-27 17:46:07 -08:00
auto on_chat(bool, const IrcMsg &irc) -> void;
2024-03-03 12:53:59 -08:00
2023-11-26 16:48:21 -08:00
public:
2025-01-26 19:35:56 -08:00
boost::signals2::signal<void()> sig_registered;
2025-01-27 11:08:16 -08:00
boost::signals2::signal<void(const std::unordered_map<std::string, std::string> &)> sig_cap_ls;
2025-01-27 17:46:07 -08:00
boost::signals2::signal<void(const Chat &)> sig_chat;
2025-01-26 19:35:56 -08:00
Client(Connection &connection)
2025-01-25 15:45:31 -08:00
: connection_{connection}
2025-01-25 21:24:33 -08:00
, casemap_{Casemap::Rfc1459}
, channel_prefix_{"#&"}
2025-01-27 17:46:07 -08:00
, status_msg_{"+@"}
2025-01-25 15:45:31 -08:00
{
}
2025-01-26 19:35:56 -08:00
auto get_connection() -> Connection & { return connection_; }
2025-01-26 19:35:56 -08:00
static auto start(Connection &) -> std::shared_ptr<Client>;
2024-03-03 12:27:36 -08:00
2025-01-25 12:25:38 -08:00
auto start_sasl(std::unique_ptr<SaslMechanism> mechanism) -> void;
2025-01-25 21:24:33 -08:00
auto get_connection() const -> std::shared_ptr<Connection>
{
return connection_.shared_from_this();
}
2025-01-27 20:02:31 -08:00
auto get_my_nick() const -> const std::string &;
2025-01-25 15:45:31 -08:00
auto get_my_mode() const -> const std::string &;
auto get_my_channels() const -> const std::unordered_set<std::string> &;
2024-03-03 12:27:36 -08:00
2025-01-27 11:08:16 -08:00
auto list_caps() -> void;
2024-03-03 12:27:36 -08:00
auto is_my_nick(std::string_view nick) const -> bool;
2025-01-25 21:24:33 -08:00
auto is_my_mask(std::string_view mask) const -> bool;
auto is_channel(std::string_view name) const -> bool;
auto casemap(std::string_view) const -> std::string;
auto casemap_compare(std::string_view, std::string_view) const -> int;
2025-01-26 19:35:56 -08:00
auto shutdown() -> void;
2023-11-26 16:48:21 -08:00
};