-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.h
58 lines (44 loc) · 1.29 KB
/
client.h
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
54
55
56
57
58
#ifndef CLIENT_H
#define CLIENT_H
#include <SDL/SDL_net.h>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include "config.h"
#include "networkevent.h"
#include "translate.h"
/** Client connection and packet handling */
class Client
{
private:
std::ofstream tr;
IPaddress serverIP;
TCPsocket clientSocket;
SDLNet_SocketSet socketSet;
std::string serverName;
unsigned int port;
char buffer[BUFFER_SIZE];
char playerId;
bool success;
std::vector<NetworkEvent> packets;
public:
/**
* Constructor
* @param iServerName address to connect (can be IP or host name)
*/
Client(std::string iServerName);
/** Desctructor */
~Client();
/** Main loop, receive packets */
void mainLoop();
/** Send packets to server */
bool sendPackets(std::vector<NetworkEvent>& packetsOut);
/** Get packets (after mainLoop run) */
std::vector<NetworkEvent>& getPackets();
/** False if error occured. */
bool getSuccess() const;
/** Get the address we connected to */
std::string getHost() const { return serverName; }
};
#endif