-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.h
More file actions
48 lines (42 loc) · 1.03 KB
/
server.h
File metadata and controls
48 lines (42 loc) · 1.03 KB
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
#ifndef _SERVER_H_
#define _SERVER_H_
#include <SFML/Graphics.hpp>
#include <list>
#include <set>
#include "ticker.h"
#include "imageManager.h"
#include "entity/world.h"
#include "network/NetworkClient.h"
#include "network/packet.h"
#include <enet/enet.h>
class Server
{
public:
Server();
~Server();
void run();
void stop();
void update(sf::Time frametime);
void init();
void setPort(int port);
private:
void addClient(ENetPeer *peer);
void removeClient(unsigned int ip, unsigned int port);
NetworkClient *getClientByPeer(ENetPeer *peer);
void handlePacket(sf::Packet p, ENetPeer *peer);
void broadcastReliable(Packet *p);
void broadcast(Packet *p);
void sendReliable(ENetPeer *peer, Packet *p);
void sendFullWorldUpdate(ENetPeer *peer);
std::string getUniquePseudo(std::string p);
bool _running;
Ticker *_ticker;
World *_world;
int _port;
int _max_client;
int _last_client_id;
std::list<NetworkClient *> _clients;
ENetHost *_server;
std::set<std::string> _client_names;
};
#endif /* _SERVER_H_ */