#ifndef _INSTANCE_HPP #define _INSTANCE_HPP #include "config.hpp" #include #include #include #include #include #include #include #include struct ParseError : public std::runtime_error { using std::runtime_error::runtime_error; }; struct ConnectionError : public std::runtime_error { using std::runtime_error::runtime_error; }; struct Event { AnyUID sender; std::string name, args, text; std::string dump() const { return fmt::format(":{} {} {}{}\n", sender.str(), name, args, (text.empty()?"":":"+text)); } void parse(std::string_view str); }; struct Command { std::string name, args, text; std::string dump() const { return fmt::format("{} {}{}\n", name, args, (text.empty()?"":":"+text)); } void parse(std::string_view str); }; struct User { SUID server; // ... == "EUID" std::string nick; size_t hops; time_t ts; std::string umode; std::string ident; std::string host; std::string realhost; UUID id; std::string realname; User() { ts = time(nullptr); } Event dump() const { return Event{ .sender = SUID(server), .name = "EUID", .args = fmt::format("{} 1 {} {} {} {} 0 {} * * :{}", nick, ts, umode, ident, host, id.str(), realname) }; } void parse(Event event); }; class Instance { uvpp::loop_service &s; const Config& config; uvpp::Addr addr; uvpp::tcp *socket = nullptr; Config::Server connected_server; bool server_bursting = true, client_bursting = true; bool authed = false; std::unordered_map users; public: Instance(uvpp::loop_service &s, const Config& config) : s(s), config(config) { addr = uvpp::make_ipv4(config.connection.addr, config.connection.port); } ~Instance() { if (socket) delete socket; } async::result run(); async::result login(); async::result burst(); async::result process(const Command); async::result process(const Event); async::result send_ping(); }; #endif