2019-01-09 20:44:58 +01:00
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
|
|
|
* Filename: ServerInfo.hpp
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
* Created: 22/01/2018 19:03:23
|
|
|
|
*
|
|
|
|
* Author: Quentin Bazin, <quent42340@gmail.com>
|
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
|
|
|
#ifndef SERVERINFO_HPP_
|
|
|
|
#define SERVERINFO_HPP_
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <SFML/Network.hpp>
|
|
|
|
|
|
|
|
#include <gk/core/Exception.hpp>
|
|
|
|
|
|
|
|
#include "NetworkInputHandler.hpp"
|
|
|
|
|
2019-02-21 09:44:16 +01:00
|
|
|
class Client {
|
|
|
|
public:
|
|
|
|
Client(u16 _id, sf::IpAddress _address, u16 _port, const std::shared_ptr<sf::TcpSocket> &socket)
|
|
|
|
: id(_id), address(_address), port(_port), tcpSocket(socket) {}
|
2019-01-09 20:44:58 +01:00
|
|
|
|
2019-02-21 09:44:16 +01:00
|
|
|
u16 id;
|
|
|
|
bool isReady = false;
|
2019-01-09 20:44:58 +01:00
|
|
|
|
2019-02-21 09:44:16 +01:00
|
|
|
sf::IpAddress address;
|
|
|
|
u16 port;
|
2019-01-09 20:44:58 +01:00
|
|
|
|
2019-02-21 09:44:16 +01:00
|
|
|
u32 previousKeyTimestamp = 0;
|
2019-01-09 20:44:58 +01:00
|
|
|
|
2019-02-21 09:44:16 +01:00
|
|
|
std::shared_ptr<sf::TcpSocket> tcpSocket;
|
2019-01-09 20:44:58 +01:00
|
|
|
|
2019-02-21 09:44:16 +01:00
|
|
|
NetworkInputHandler inputHandler;
|
2019-01-09 20:44:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class ServerInfo {
|
|
|
|
public:
|
|
|
|
Client &addClient(sf::IpAddress address, u16 port, const std::shared_ptr<sf::TcpSocket> &socket);
|
|
|
|
Client *getClient(u16 id);
|
|
|
|
void removeClient(u16 id);
|
|
|
|
|
|
|
|
std::vector<Client> &clients() { return m_clients; }
|
|
|
|
const std::vector<Client> &clients() const { return m_clients; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<Client> m_clients;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SERVERINFO_HPP_
|