/
GameServer.hpp
49 lines (39 loc) · 995 Bytes
/
GameServer.hpp
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
42
43
44
45
46
47
48
49
#ifndef GAMESERVER_HPP
#define GAMESERVER_HPP
#include "seasocks/PrintfLogger.h"
#include "seasocks/Server.h"
#include "seasocks/WebSocket.h"
#include "json.hpp"
#include <set>
#include <string>
#include "Message.hpp"
using namespace std;
using namespace seasocks;
using namespace nlohmann;
struct GameServer : WebSocket::Handler {
struct User{
User(WebSocket* ws);
User();
string nickname = "???";
WebSocket* ws;
int playerId=-1;
};
//helper functions
void onConnect(WebSocket *socket) override;
void onData(WebSocket * conn, const char *data) override;
void onDisconnect(WebSocket *socket) override;
void broadcast(const Message& m);
void send(WebSocket* c, const Message& m);
//logic implementation
map<WebSocket*,User> connections;
int afkCount;
map<string,function<void(WebSocket*,json)>> handlers;
enum State{
WAITING, PLAYING
} state = WAITING;
GameServer();
void updateUsers();
void resetGame();
void startPlaying();
};
#endif