-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.h
More file actions
53 lines (46 loc) · 1.19 KB
/
Server.h
File metadata and controls
53 lines (46 loc) · 1.19 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
49
50
51
52
53
#ifndef SERVER_H
#define SERVER_H
#include "UDPNetwork.h"
#include "PacketParser.h"
class Shape;
class Game;
struct client
{
client(int localID_, sf::IpAddress address, unsigned short port)
{
localID = localID_;
clientAddress = address;
clientPort = port;
}
int localID;
sf::IpAddress clientAddress;
unsigned short clientPort;
};
class Server: public UDPNetwork
{
public:
Server(Game* game);
~Server(void);
void handleNewPlayer(packetInfo& pack);
//returns nullptr if client not found
client* getClient(int localID);
//remove player from server either if player disconnects voluntarily or not
bool dropPlayer(int localID);
void playerEnteredLobby(packetInfo& pack);
void playerLeftLobby(int ID); // not yet implemented
bool isServer() override;
//broadcast a packet
void broadCast(sf::Packet packet);
//send packet to all players EXCEPT to the one with the address/port given as argument
void broadCastExcept(sf::IpAddress address, unsigned short port, sf::Packet packet);
vector<client*>& getClients()
{
return remoteConnections;
}
private:
Game* game;
sf::SocketSelector selector;
vector<client*> remoteConnections;
bool playerMoved;
};
#endif