mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-08 16:56:08 +00:00
implement udp connection
This commit is contained in:
@@ -29,6 +29,11 @@ struct Client {
|
||||
ClientID id;
|
||||
bmp::State state { bmp::State::None };
|
||||
|
||||
Sync<std::string> name;
|
||||
Sync<std::string> role;
|
||||
Sync<bool> is_guest;
|
||||
Sync<std::unordered_map<std::string /* identifier */, std::string /* value */>> identifiers;
|
||||
|
||||
/// Reads a single packet from the TCP stream. Blocks all other reads (not writes).
|
||||
Packet tcp_read();
|
||||
/// Writes the packet to the TCP stream. Blocks all other writes.
|
||||
@@ -37,16 +42,18 @@ struct Client {
|
||||
/// conjunction with something else. Blocks other writes.
|
||||
void tcp_write_file_raw(const std::filesystem::path& path);
|
||||
|
||||
Client(ClientID id, class Network& network, ip::tcp::socket&& tcp_socket);
|
||||
Client(ClientID id, class Network& network, ip::tcp::socket&& tcp_sockem_udp_endpointst);
|
||||
~Client();
|
||||
|
||||
ip::tcp::socket& tcp_socket() { return m_tcp_socket; }
|
||||
|
||||
[[nodiscard]] const ip::udp::endpoint& udp_endpoint() const { return m_udp_ep; }
|
||||
void set_udp_endpoint(const ip::udp::endpoint& ep) { m_udp_ep = ep; }
|
||||
|
||||
void start_tcp();
|
||||
|
||||
/// Used to associate the udp socket with this client.
|
||||
/// This isn't very secure and still allows spoofing of the UDP connection (technically),
|
||||
/// but better than simply using the ID like the old protocol.
|
||||
const uint64_t udp_magic;
|
||||
|
||||
private:
|
||||
|
||||
void tcp_main();
|
||||
@@ -55,7 +62,6 @@ private:
|
||||
std::mutex m_tcp_write_mtx;
|
||||
std::mutex m_udp_read_mtx;
|
||||
|
||||
ip::udp::endpoint m_udp_ep;
|
||||
ip::tcp::socket m_tcp_socket;
|
||||
|
||||
boost::scoped_thread<> m_tcp_thread;
|
||||
@@ -89,6 +95,8 @@ private:
|
||||
|
||||
Sync<std::unordered_map<ClientID, Client::Ptr>> m_clients {};
|
||||
Sync<std::unordered_map<VehicleID, Vehicle::Ptr>> m_vehicles {};
|
||||
Sync<std::unordered_map<uint64_t, ClientID>> m_client_magics {};
|
||||
Sync<std::unordered_map<ip::udp::endpoint, ClientID>> m_udp_endpoints {};
|
||||
|
||||
ClientID new_client_id() {
|
||||
static Sync<ClientID> s_id { 0 };
|
||||
@@ -105,5 +113,11 @@ private:
|
||||
thread_pool m_threadpool {};
|
||||
Sync<bool> m_shutdown { false };
|
||||
ip::udp::socket m_udp_socket { m_io };
|
||||
|
||||
void handle_identification(ClientID id, const Packet& packet, std::shared_ptr<Client>& client);
|
||||
|
||||
void handle_authentication(ClientID id, const Packet& packet, std::shared_ptr<Client>& client);
|
||||
|
||||
/// On failure, throws an exception with the error for the client.
|
||||
static void authenticate_user(const std::string& public_key, std::shared_ptr<Client>& client);
|
||||
};
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
#include "Common.h"
|
||||
#include "IThreaded.h"
|
||||
#include "TResourceManager.h"
|
||||
#include "TServer.h"
|
||||
|
||||
class THeartbeatThread : public IThreaded {
|
||||
public:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "TNetwork.h"
|
||||
#include "TServer.h"
|
||||
#include "Network.h"
|
||||
#include <any>
|
||||
#include <condition_variable>
|
||||
#include <filesystem>
|
||||
|
||||
Reference in New Issue
Block a user