#pragma once #include #include #include #include #include #include #include "ProxyServer.hh" #include "ServerState.hh" class HTTPServer { public: HTTPServer(std::shared_ptr state); HTTPServer(const HTTPServer&) = delete; HTTPServer(HTTPServer&&) = delete; HTTPServer& operator=(const HTTPServer&) = delete; HTTPServer& operator=(HTTPServer&&) = delete; virtual ~HTTPServer() = default; void listen(const std::string& socket_path); void listen(const std::string& addr, int port); void listen(int port); void add_socket(int fd); void schedule_stop(); void wait_for_stop(); protected: class http_error : public std::runtime_error { public: http_error(int code, const std::string& what); int code; }; std::shared_ptr state; std::shared_ptr base; std::shared_ptr http; std::thread th; void thread_fn(); static void dispatch_handle_request(struct evhttp_request* req, void* ctx); void handle_request(struct evhttp_request* req); static const std::unordered_map explanation_for_response_code; static void send_response(struct evhttp_request* req, int code, const char* content_type, struct evbuffer* b); static void send_response(struct evhttp_request* req, int code, const char* content_type, const char* fmt, ...); static std::unordered_multimap parse_url_params(const std::string& query); static std::unordered_map parse_url_params_unique(const std::string& query); static const std::string& get_url_param( const std::unordered_multimap& params, const std::string& key, const std::string* _default = nullptr); static JSON generate_quest_json_st(std::shared_ptr q); static JSON generate_client_config_json_st(const Client::Config& config); static JSON generate_account_json_st(std::shared_ptr a); static JSON generate_game_client_json_st(std::shared_ptr c, std::shared_ptr item_name_index); static JSON generate_proxy_client_json_st(std::shared_ptr ses); static JSON generate_lobby_json_st(std::shared_ptr l, std::shared_ptr item_name_index); JSON generate_game_server_clients_json() const; JSON generate_proxy_server_clients_json() const; JSON generate_server_info_json() const; JSON generate_lobbies_json() const; JSON generate_summary_json() const; JSON generate_all_json() const; JSON generate_ep3_cards_json(bool trial) const; JSON generate_common_tables_json() const; JSON generate_rare_tables_json() const; JSON generate_rare_table_json(const std::string& table_name) const; };