aboutsummaryrefslogtreecommitdiff
path: root/src/handler.h
blob: 32d26dc92cc7156b5a6226e732f1adc1ddcd7ff4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef HANDLER_H
#define HANDLER_H

#include <functional>

#include <rapidjson/document.h>

#include "rpc_server.h"
#include "plugin.h"
#include "internal/convarproxy.h"

#define DEFAULT_PORT "26503"

typedef std::function<rapidjson::Value(rapidjson::MemoryPoolAllocator<>&, rapidjson::Value&)> method_callback;
typedef std::map<std::string, method_callback> callback_list;

class ServerHandler
{
    private:
        bool init = false;
        Plugin* plugin;

        WSADATA wsaData;

        bool running = false;
        HANDLE thread = nullptr;

        ConVarProxy* Convar_Port = nullptr;

        callback_list methods;
    public:
        ServerHandler(Plugin* parent);

        void register_callback(std::string name, method_callback callback) { this->methods.try_emplace(name, callback); }

        void start();
        void stop();
        void run();
};

#endif