#pragma once #include "State.h" #include "Sync.h" #include "Transport.h" #include #include #include #include #include #include using ClientID = uint32_t; using VehicleID = uint16_t; using namespace boost::asio; struct Packet { bmp::Purpose purpose; bmp::Flags flags; std::vector data; bmp::Header header() const; }; struct Client { using Ptr = std::shared_ptr; 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; ClientID owner; std::vector data; }; class Network { public: private: Sync> m_clients; Sync> m_vehicles; boost::asio::io_context m_io; };