mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-02 15:55:30 +00:00
65 lines
1.3 KiB
C++
65 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "State.h"
|
|
#include "Sync.h"
|
|
#include "Transport.h"
|
|
#include <boost/asio.hpp>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <filesystem>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
using ClientID = uint32_t;
|
|
using VehicleID = uint16_t;
|
|
|
|
using namespace boost::asio;
|
|
|
|
struct Packet {
|
|
bmp::Purpose purpose;
|
|
bmp::Flags flags;
|
|
std::vector<uint8_t> data;
|
|
|
|
bmp::Header header() const;
|
|
};
|
|
|
|
struct Client {
|
|
using Ptr = std::shared_ptr<Client>;
|
|
ClientID id;
|
|
bmp::State state;
|
|
|
|
Packet tcp_read();
|
|
void tcp_write(const Packet& packet);
|
|
void tcp_write_file_raw(const std::filesystem::path& path);
|
|
Packet udp_read(ip::udp::socket& socket);
|
|
void udp_write(const Packet& packet, ip::udp::socket& socket);
|
|
|
|
Client(ip::udp::endpoint& ep, ip::tcp::socket&& socket);
|
|
~Client();
|
|
|
|
private:
|
|
std::mutex m_tcp_read_mtx;
|
|
std::mutex m_tcp_write_mtx;
|
|
std::mutex m_udp_read_mtx;
|
|
|
|
ip::udp::endpoint m_udp_ep;
|
|
ip::tcp::socket m_tcp_socket;
|
|
};
|
|
|
|
struct Vehicle {
|
|
using Ptr = std::shared_ptr<Vehicle>;
|
|
ClientID owner;
|
|
std::vector<uint8_t> data;
|
|
};
|
|
|
|
class Network {
|
|
public:
|
|
|
|
|
|
private:
|
|
Sync<std::unordered_map<ClientID, Client::Ptr>> m_clients;
|
|
Sync<std::unordered_map<VehicleID, Vehicle::Ptr>> m_vehicles;
|
|
boost::asio::io_context m_io;
|
|
};
|
|
|