GPR5100 - Rollback
Loading...
Searching...
No Matches
network_client.h
1#pragma once
2#include "client.h"
3#include <SFML/Network/TcpSocket.hpp>
4#include <SFML/Network/UdpSocket.hpp>
5
6#ifdef ENABLE_SQLITE
7#include "network/debug_db.h"
8#endif
9
10namespace game
11{
15class NetworkClient final : public Client
16{
17public:
18 enum class State
19 {
20 NONE,
21 JOINING,
22 JOINED,
23 GAME_STARTING,
24 GAME
25
26 };
27 enum class PacketSource
28 {
29 TCP,
30 UDP
31 };
32 void Begin() override;
33
34 void Update(sf::Time dt) override;
35
36 void End() override;
37
38 void DrawImGui() override;
39
40 void Draw(sf::RenderTarget& renderTarget) override;
41
42 void SendReliablePacket(std::unique_ptr<Packet> packet) override;
43
44 void SendUnreliablePacket(std::unique_ptr<Packet> packet) override;
45 void SetPlayerInput(PlayerInput playerInput);
46
47 void ReceivePacket(const Packet* packet) override;
48private:
49 void ReceiveNetPacket(sf::Packet& packet, PacketSource source);
50 sf::UdpSocket udpSocket_;
51 sf::TcpSocket tcpSocket_;
52
53 std::string serverAddress_ = "localhost";
54 unsigned short serverTcpPort_ = 12345;
55 unsigned short serverUdpPort_ = 0;
56
57
58 State currentState_ = State::NONE;
59
60#ifdef ENABLE_SQLITE
61 DebugDatabase debugDb_;
62#endif
63};
64}
Client is an interface of a player game manager and the net client interface (receive and send packet...
Definition: client.h:13
NetworkClient is a network client that uses SFML sockets.
Definition: network_client.h:16
void ReceivePacket(const Packet *packet) override
ReceiveNetPacket is a method called by an app owning a client when receiving a packet....
Definition: network_client.cpp:238
std::uint8_t PlayerInput
PlayerInput is a type defining the input data from a player.
Definition: game_globals.h:103
Packet is a interface that defines what a packet with a PacketType.
Definition: packet_type.h:37