]> git.localhorst.tv Git - blank.git/blob - src/net/Server.hpp
defined and implemented join and part packets
[blank.git] / src / net / Server.hpp
1 #ifndef BLANK_NET_SERVER_HPP
2 #define BLANK_NET_SERVER_HPP
3
4 #include <list>
5 #include <SDL_net.h>
6
7
8 namespace blank {
9
10 class Connection;
11 class World;
12
13 class Server {
14
15 public:
16         struct Config {
17                 Uint16 port = 12354;
18         };
19
20 public:
21         Server(const Config &, World &);
22         ~Server();
23
24         void Handle();
25
26         void Update(int dt);
27
28 private:
29         void HandlePacket(const UDPpacket &);
30
31         Connection &GetClient(const IPaddress &);
32
33         void OnConnect(Connection &);
34         void OnDisconnect(Connection &);
35
36         void HandleLogin(Connection &client, const UDPpacket &);
37         void HandlePart(Connection &client, const UDPpacket &);
38
39 private:
40         UDPsocket serv_sock;
41         UDPpacket serv_pack;
42         std::list<Connection> clients;
43
44         World &world;
45
46 };
47
48 }
49
50 #endif