mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
work
This commit is contained in:
@@ -23,6 +23,7 @@ file(GLOB HEADERS "*.h"
|
||||
"McZapkie/*.h"
|
||||
"gl/*.h"
|
||||
"network/*.h"
|
||||
"network/backend/*.h"
|
||||
"widgets/*.h")
|
||||
|
||||
set(SOURCES
|
||||
@@ -116,8 +117,8 @@ set(SOURCES
|
||||
|
||||
"network/network.cpp"
|
||||
"network/message.cpp"
|
||||
"network/tcp.cpp"
|
||||
"network/manager.cpp"
|
||||
"network/backend/asio.cpp"
|
||||
|
||||
"widgets/vehiclelist.cpp"
|
||||
|
||||
|
||||
@@ -27,11 +27,7 @@ else()
|
||||
else()
|
||||
find_path(ASIO_ROOT include/asio.hpp
|
||||
PATHS
|
||||
# Where asio lives relative to it's official repository
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../asio/asio
|
||||
|
||||
# Where asio should live
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../asio
|
||||
${CMAKE_CURRENT_LIST_DIR}/../ref/asio/asio
|
||||
)
|
||||
if(NOT ASIO_ROOT)
|
||||
if(ASIO_FIND_REQUIRED)
|
||||
|
||||
@@ -5973,7 +5973,7 @@ bool TTrain::Update( double const Deltatime )
|
||||
// screens
|
||||
fScreenTimer += Deltatime;
|
||||
if( ( fScreenTimer > Global.PythonScreenUpdateRate * 0.001f )
|
||||
&& ( false == FreeFlyModeFlag ) ) { // don't bother if we're outside
|
||||
&& !FreeFlyModeFlag && simulation::Train == this ) { // don't bother if we're outside
|
||||
fScreenTimer = 0.f;
|
||||
for( auto const &screen : m_screens ) {
|
||||
Application.request( { std::get<0>(screen), GetTrainState(), GfxRenderer.Texture( std::get<1>(screen) ).id } );
|
||||
|
||||
@@ -182,10 +182,10 @@ eu07_application::run() {
|
||||
double slave_sync;
|
||||
|
||||
// if we're the server
|
||||
if (m_network && m_network->server)
|
||||
if (m_network && m_network->servers)
|
||||
{
|
||||
// fetch from network layer command requests received from clients
|
||||
command_queue::commands_map remote_commands = m_network->server->pop_commands();
|
||||
command_queue::commands_map remote_commands = m_network->servers->pop_commands();
|
||||
|
||||
// push these into local queue
|
||||
add_to_dequemap(local_commands, remote_commands);
|
||||
@@ -239,11 +239,11 @@ eu07_application::run() {
|
||||
}
|
||||
|
||||
// if we're the server
|
||||
if (m_network && m_network->server)
|
||||
if (m_network && m_network->servers)
|
||||
{
|
||||
// send delta, sync, and commands we just executed to clients
|
||||
double delta = Timer::GetDeltaTime();
|
||||
m_network->server->push_delta(delta, sync, commands_to_exec);
|
||||
m_network->servers->push_delta(delta, sync, commands_to_exec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -689,10 +689,10 @@ bool eu07_application::init_network() {
|
||||
if (Global.network_conf.is_server || Global.network_conf.is_client) {
|
||||
m_network.emplace();
|
||||
if (Global.network_conf.is_server) {
|
||||
m_network->create_server();
|
||||
m_network->create_server(Global.network_conf.server_host, Global.network_conf.server_port);
|
||||
}
|
||||
if (Global.network_conf.is_client) {
|
||||
m_network->connect();
|
||||
m_network->connect(Global.network_conf.client_host, Global.network_conf.client_port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,12 @@ image: Visual Studio 2017
|
||||
clone_depth: 1
|
||||
build_script:
|
||||
- ps: >-
|
||||
cd ref
|
||||
|
||||
git clone https://github.com/chriskohlhoff/asio --depth 1
|
||||
|
||||
cd ..
|
||||
|
||||
mkdir builds
|
||||
|
||||
cd builds
|
||||
|
||||
@@ -379,6 +379,7 @@ driver_mode::on_event_poll() {
|
||||
|
||||
void
|
||||
driver_mode::update_camera( double const Deltatime ) {
|
||||
Camera.Pos = Global.pCamera.Pos; // M7TODO
|
||||
|
||||
auto *controlled = (
|
||||
simulation::Train ?
|
||||
@@ -686,6 +687,7 @@ driver_mode::OnKeyDown(int cKey) {
|
||||
break;
|
||||
|
||||
TDynamicObject *dynamic = std::get<TDynamicObject *>( simulation::Region->find_vehicle( Global.pCamera.Pos, 50, true, false ) );
|
||||
if (dynamic) {
|
||||
TTrain *train = simulation::Trains.find(dynamic->name());
|
||||
if (train) {
|
||||
simulation::Train = train;
|
||||
@@ -693,6 +695,7 @@ driver_mode::OnKeyDown(int cKey) {
|
||||
} else {
|
||||
m_relay.post(user_command::entervehicle, 0.0, 0.0, GLFW_PRESS, 0);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
170
network/backend/asio.cpp
Normal file
170
network/backend/asio.cpp
Normal file
@@ -0,0 +1,170 @@
|
||||
#include "network/backend/asio.h"
|
||||
#include "sn_utils.h"
|
||||
#include "Logs.h"
|
||||
|
||||
network::tcp::connection::connection(asio::io_context &io_ctx, bool client)
|
||||
: network::connection(client), m_socket(io_ctx)
|
||||
{
|
||||
m_header_buffer.resize(8);
|
||||
}
|
||||
|
||||
void network::tcp::connection::disconnect()
|
||||
{
|
||||
network::connection::disconnect();
|
||||
m_socket.close();
|
||||
}
|
||||
|
||||
void network::tcp::connection::send_data(std::shared_ptr<std::string> buffer)
|
||||
{
|
||||
asio::async_write(m_socket, asio::buffer(*buffer.get()), std::bind(&connection::handle_send, this, buffer,
|
||||
std::placeholders::_1,
|
||||
std::placeholders::_2));
|
||||
}
|
||||
|
||||
void network::tcp::connection::connected()
|
||||
{
|
||||
network::connection::connected();
|
||||
read_header();
|
||||
}
|
||||
|
||||
void network::tcp::connection::read_header()
|
||||
{
|
||||
asio::async_read(m_socket, asio::buffer(m_header_buffer),
|
||||
std::bind(&connection::handle_header, this,
|
||||
std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
|
||||
void network::tcp::connection::handle_send(
|
||||
std::shared_ptr<std::string> buf, const asio::error_code &err, size_t bytes_transferred)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void network::tcp::connection::handle_header(const asio::error_code &err, size_t bytes_transferred)
|
||||
{
|
||||
std::istringstream header(m_header_buffer);
|
||||
if (m_header_buffer.size() != bytes_transferred) {
|
||||
disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t sig = sn_utils::ld_uint32(header);
|
||||
if (sig != NETWORK_MAGIC) {
|
||||
disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t len = sn_utils::ld_uint32(header);
|
||||
m_body_buffer.resize(len);
|
||||
if (len > MAX_MSG_SIZE) {
|
||||
disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
asio::async_read(m_socket, asio::buffer(m_body_buffer),
|
||||
std::bind(&connection::handle_data, this, std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
|
||||
void network::tcp::connection::handle_data(const asio::error_code &err, size_t bytes_transferred)
|
||||
{
|
||||
if (m_body_buffer.size() != bytes_transferred) {
|
||||
disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
std::istringstream stream(m_body_buffer);
|
||||
std::shared_ptr<message> msg = deserialize_message(stream);
|
||||
if (message_handler)
|
||||
message_handler(*msg);
|
||||
|
||||
read_header();
|
||||
}
|
||||
|
||||
void network::tcp::connection::send_message(const message &msg)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
sn_utils::ls_uint32(stream, NETWORK_MAGIC);
|
||||
sn_utils::ls_uint32(stream, 0);
|
||||
|
||||
serialize_message(msg, stream);
|
||||
|
||||
size_t size = (size_t)stream.tellp() - 8;
|
||||
if (size > MAX_MSG_SIZE) {
|
||||
ErrorLog("net: message too big", logtype::net);
|
||||
return;
|
||||
}
|
||||
stream.seekp(4, std::ios_base::beg);
|
||||
sn_utils::ls_uint32(stream, size);
|
||||
|
||||
stream.flush();
|
||||
|
||||
std::shared_ptr<std::string> buf = std::make_shared<std::string>(stream.str());
|
||||
send_data(buf);
|
||||
}
|
||||
|
||||
// -----------------
|
||||
|
||||
network::tcp::server::server(asio::io_context &io_ctx, const std::string &host, uint32_t port)
|
||||
: m_acceptor(io_ctx)
|
||||
{
|
||||
auto endpoint = asio::ip::tcp::endpoint(asio::ip::address::from_string(host), port);
|
||||
m_acceptor.open(endpoint.protocol());
|
||||
m_acceptor.set_option(asio::socket_base::reuse_address(true));
|
||||
m_acceptor.set_option(asio::ip::tcp::no_delay(true));
|
||||
m_acceptor.bind(endpoint);
|
||||
m_acceptor.listen(10);
|
||||
|
||||
accept_conn();
|
||||
}
|
||||
|
||||
void network::tcp::server::accept_conn()
|
||||
{
|
||||
std::shared_ptr<connection> conn = std::make_shared<connection>(m_acceptor.get_executor().context());
|
||||
conn->set_handler(std::bind(&server::handle_message, this, std::ref(*conn.get()), std::placeholders::_1));
|
||||
|
||||
m_acceptor.async_accept(conn->m_socket, std::bind(&server::handle_accept, this, conn, std::placeholders::_1));
|
||||
}
|
||||
|
||||
void network::tcp::server::handle_accept(std::shared_ptr<connection> conn, const asio::error_code &err)
|
||||
{
|
||||
if (!err)
|
||||
{
|
||||
clients.emplace_back(conn);
|
||||
conn->connected();
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLog(std::string("net: failed to accept client: " + err.message()), logtype::net);
|
||||
}
|
||||
|
||||
accept_conn();
|
||||
}
|
||||
|
||||
// ------------------
|
||||
|
||||
network::tcp::client::client(asio::io_context &io_ctx, const std::string &host, uint32_t port)
|
||||
{
|
||||
std::shared_ptr<connection> conn = std::make_shared<connection>(io_ctx, true);
|
||||
conn->set_handler(std::bind(&client::handle_message, this, std::ref(*conn.get()), std::placeholders::_1));
|
||||
|
||||
asio::ip::tcp::endpoint endpoint(
|
||||
asio::ip::address::from_string(host), port);
|
||||
conn->m_socket.open(endpoint.protocol());
|
||||
conn->m_socket.set_option(asio::ip::tcp::no_delay(true));
|
||||
conn->m_socket.async_connect(endpoint,
|
||||
std::bind(&client::handle_accept, this, std::placeholders::_1));
|
||||
|
||||
this->conn = conn;
|
||||
}
|
||||
|
||||
void network::tcp::client::handle_accept(const asio::error_code &err)
|
||||
{
|
||||
if (!err)
|
||||
{
|
||||
conn->connected();
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLog(std::string("net: failed to connect: " + err.message()), logtype::net);
|
||||
}
|
||||
}
|
||||
54
network/backend/asio.h
Normal file
54
network/backend/asio.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "network/network.h"
|
||||
#include <asio.hpp>
|
||||
|
||||
namespace network::tcp
|
||||
{
|
||||
const uint32_t NETWORK_MAGIC = 0x37305545;
|
||||
const uint32_t MAX_MSG_SIZE = 10000;
|
||||
|
||||
class connection : public network::connection
|
||||
{
|
||||
friend class server;
|
||||
friend class client;
|
||||
|
||||
public:
|
||||
connection(asio::io_context &io_ctx, bool client = false);
|
||||
|
||||
virtual void connected() override;
|
||||
virtual void disconnect() override;
|
||||
virtual void send_data(std::shared_ptr<std::string> buffer) override;
|
||||
virtual void send_message(const message &msg) override;
|
||||
|
||||
private:
|
||||
asio::ip::tcp::socket m_socket;
|
||||
|
||||
std::string m_header_buffer;
|
||||
std::string m_body_buffer;
|
||||
|
||||
void read_header();
|
||||
void handle_send(std::shared_ptr<std::string> buf, const asio::error_code &err, size_t bytes_transferred);
|
||||
void handle_header(const asio::error_code &err, size_t bytes_transferred);
|
||||
void handle_data(const asio::error_code &err, size_t bytes_transferred);
|
||||
};
|
||||
|
||||
class server : public network::server
|
||||
{
|
||||
private:
|
||||
void accept_conn();
|
||||
void handle_accept(std::shared_ptr<connection> conn, const asio::error_code &err);
|
||||
|
||||
asio::ip::tcp::acceptor m_acceptor;
|
||||
|
||||
public:
|
||||
server(asio::io_context &io_ctx, const std::string &host, uint32_t port);
|
||||
};
|
||||
|
||||
class client : public network::client
|
||||
{
|
||||
private:
|
||||
void handle_accept(const asio::error_code &err);
|
||||
|
||||
public:
|
||||
client(asio::io_context &io_ctx, const std::string &host, uint32_t port);
|
||||
};
|
||||
}
|
||||
@@ -1,42 +1,44 @@
|
||||
#include "network/manager.h"
|
||||
#include "network/tcp.h"
|
||||
#include "simulation.h"
|
||||
#include "network/backend/asio.h"
|
||||
|
||||
command_queue::commands_map network::server_manager::pop_commands()
|
||||
{
|
||||
command_queue::commands_map map;
|
||||
|
||||
for (auto srv : servers)
|
||||
add_to_dequemap(map, srv->pop_commands());
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
void network::server_manager::push_delta(double dt, double sync, const command_queue::commands_map &commands)
|
||||
{
|
||||
for (auto srv : servers)
|
||||
srv->push_delta(dt, sync, commands);
|
||||
}
|
||||
|
||||
void network::server_manager::create_server(asio::io_context &ctx, const std::string &host, uint32_t port)
|
||||
{
|
||||
servers.emplace_back(std::make_shared<tcp::server>(ctx, host, port));
|
||||
}
|
||||
|
||||
network::manager::manager()
|
||||
{
|
||||
}
|
||||
|
||||
void network::manager::create_server()
|
||||
{
|
||||
server = std::make_shared<tcp_server>(io_context);
|
||||
}
|
||||
|
||||
void network::manager::poll()
|
||||
{
|
||||
io_context.poll();
|
||||
}
|
||||
|
||||
void network::manager::connect()
|
||||
void network::manager::create_server(const std::string &host, uint32_t port)
|
||||
{
|
||||
client = std::make_shared<tcp_client>(io_context);
|
||||
servers.emplace();
|
||||
servers->create_server(io_context, host, port);
|
||||
}
|
||||
|
||||
std::tuple<double, double, command_queue::commands_map> network::manager::get_next_delta()
|
||||
void network::manager::connect(const std::string &host, uint32_t port)
|
||||
{
|
||||
return client->get_next_delta();
|
||||
}
|
||||
|
||||
void network::manager::push_delta(double delta, double sync, command_queue::commands_map commands)
|
||||
{
|
||||
server->push_delta(delta, sync, commands);
|
||||
}
|
||||
|
||||
command_queue::commands_map network::manager::pop_commands()
|
||||
{
|
||||
return server->pop_commands();
|
||||
}
|
||||
|
||||
void network::manager::send_commands(command_queue::commands_map commands)
|
||||
{
|
||||
client->send_commands(commands);
|
||||
client = std::make_shared<tcp::client>(io_context, host, port);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,17 @@
|
||||
|
||||
namespace network
|
||||
{
|
||||
class server_manager
|
||||
{
|
||||
private:
|
||||
std::vector<std::shared_ptr<server>> servers;
|
||||
|
||||
public:
|
||||
void push_delta(double dt, double sync, const command_queue::commands_map &commands);
|
||||
command_queue::commands_map pop_commands();
|
||||
void create_server(asio::io_context &ctx, const std::string &host, uint32_t port);
|
||||
};
|
||||
|
||||
class manager
|
||||
{
|
||||
asio::io_context io_context;
|
||||
@@ -13,16 +24,11 @@ namespace network
|
||||
public:
|
||||
manager();
|
||||
|
||||
std::shared_ptr<network::server> server;
|
||||
std::optional<server_manager> servers;
|
||||
std::shared_ptr<network::client> client;
|
||||
|
||||
void create_server();
|
||||
void connect();
|
||||
void create_server(const std::string &host, uint32_t port);
|
||||
void connect(const std::string &host, uint32_t port);
|
||||
void poll();
|
||||
|
||||
std::tuple<double, double, command_queue::commands_map> get_next_delta();
|
||||
void push_delta(double delta, double sync, command_queue::commands_map commands);
|
||||
command_queue::commands_map pop_commands();
|
||||
void send_commands(command_queue::commands_map commands);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,38 +1,35 @@
|
||||
#include "network/message.h"
|
||||
#include "sn_utils.h"
|
||||
|
||||
void network::message::serialize(std::ostream &stream)
|
||||
void network::client_hello::serialize(std::ostream &stream) const
|
||||
{
|
||||
|
||||
sn_utils::ls_int32(stream, version);
|
||||
}
|
||||
|
||||
void network::message::deserialize(std::istream &stream)
|
||||
void network::client_hello::deserialize(std::istream &stream)
|
||||
{
|
||||
|
||||
version = sn_utils::ld_int32(stream);
|
||||
}
|
||||
|
||||
void network::accept_message::serialize(std::ostream &stream)
|
||||
void network::server_hello::serialize(std::ostream &stream) const
|
||||
{
|
||||
sn_utils::ls_uint32(stream, seed);
|
||||
}
|
||||
|
||||
void network::accept_message::deserialize(std::istream &stream)
|
||||
void network::server_hello::deserialize(std::istream &stream)
|
||||
{
|
||||
seed = sn_utils::ld_uint32(stream);
|
||||
}
|
||||
|
||||
size_t network::accept_message::get_size()
|
||||
{
|
||||
return message::get_size() + 4;
|
||||
}
|
||||
|
||||
void::network::command_message::serialize(std::ostream &stream)
|
||||
void ::network::request_command::serialize(std::ostream &stream) const
|
||||
{
|
||||
sn_utils::ls_uint32(stream, commands.size());
|
||||
for (auto const &kv : commands) {
|
||||
for (auto const &kv : commands)
|
||||
{
|
||||
sn_utils::ls_uint32(stream, kv.first);
|
||||
sn_utils::ls_uint32(stream, kv.second.size());
|
||||
for (command_data const &data : kv.second) {
|
||||
for (command_data const &data : kv.second)
|
||||
{
|
||||
sn_utils::ls_uint32(stream, (uint32_t)data.command);
|
||||
sn_utils::ls_int32(stream, data.action);
|
||||
sn_utils::ls_float64(stream, data.param1);
|
||||
@@ -45,15 +42,17 @@ void::network::command_message::serialize(std::ostream &stream)
|
||||
}
|
||||
}
|
||||
|
||||
void network::command_message::deserialize(std::istream &stream)
|
||||
void network::request_command::deserialize(std::istream &stream)
|
||||
{
|
||||
uint32_t commands_size = sn_utils::ld_uint32(stream);
|
||||
for (uint32_t i = 0; i < commands_size; i++) {
|
||||
for (uint32_t i = 0; i < commands_size; i++)
|
||||
{
|
||||
uint32_t recipient = sn_utils::ld_uint32(stream);
|
||||
uint32_t sequence_size = sn_utils::ld_uint32(stream);
|
||||
|
||||
command_queue::commanddata_sequence sequence;
|
||||
for (uint32_t i = 0; i < sequence_size; i++) {
|
||||
for (uint32_t i = 0; i < sequence_size; i++)
|
||||
{
|
||||
command_data data;
|
||||
data.command = (user_command)sn_utils::ld_uint32(stream);
|
||||
data.action = sn_utils::ld_int32(stream);
|
||||
@@ -71,54 +70,20 @@ void network::command_message::deserialize(std::istream &stream)
|
||||
}
|
||||
}
|
||||
|
||||
size_t network::command_message::get_size()
|
||||
{
|
||||
size_t cmd_size = 4;
|
||||
|
||||
for (auto const &kv : commands) {
|
||||
cmd_size += 8;
|
||||
for (command_data const &data : kv.second) {
|
||||
cmd_size += 8 + 3 * 8 + 2 + 4 * 3;
|
||||
}
|
||||
}
|
||||
|
||||
return message::get_size() + cmd_size;
|
||||
}
|
||||
|
||||
size_t network::delta_message::get_size()
|
||||
{
|
||||
return command_message::get_size() + 16;
|
||||
}
|
||||
|
||||
void network::delta_message::serialize(std::ostream &stream)
|
||||
void network::frame_info::serialize(std::ostream &stream) const
|
||||
{
|
||||
sn_utils::ls_float64(stream, dt);
|
||||
sn_utils::ls_float64(stream, sync);
|
||||
|
||||
command_message::serialize(stream);
|
||||
request_command::serialize(stream);
|
||||
}
|
||||
|
||||
void network::delta_message::deserialize(std::istream &stream)
|
||||
void network::frame_info::deserialize(std::istream &stream)
|
||||
{
|
||||
dt = sn_utils::ld_float64(stream);
|
||||
sync = sn_utils::ld_float64(stream);
|
||||
|
||||
command_message::deserialize(stream);
|
||||
}
|
||||
|
||||
void network::string_message::serialize(std::ostream &stream)
|
||||
{
|
||||
sn_utils::s_str(stream, name);
|
||||
}
|
||||
|
||||
void network::string_message::deserialize(std::istream &stream)
|
||||
{
|
||||
name = sn_utils::d_str(stream);
|
||||
}
|
||||
|
||||
size_t network::string_message::get_size()
|
||||
{
|
||||
return message::get_size() + name.size() + 1;
|
||||
request_command::deserialize(stream);
|
||||
}
|
||||
|
||||
std::shared_ptr<network::message> network::deserialize_message(std::istream &stream)
|
||||
@@ -126,27 +91,23 @@ std::shared_ptr<network::message> network::deserialize_message(std::istream &str
|
||||
message::type_e type = (message::type_e)sn_utils::ld_uint16(stream);
|
||||
|
||||
std::shared_ptr<message> msg;
|
||||
if (type == message::CONNECT_ACCEPT) {
|
||||
auto m = std::make_shared<accept_message>();
|
||||
m->type = type;
|
||||
m->deserialize(stream);
|
||||
msg = m;
|
||||
}
|
||||
else if (type == message::STEP_INFO) {
|
||||
auto m = std::make_shared<delta_message>();
|
||||
m->type = type;
|
||||
m->deserialize(stream);
|
||||
msg = m;
|
||||
}
|
||||
else if (type == message::CLIENT_COMMAND) {
|
||||
auto m = std::make_shared<command_message>();
|
||||
m->type = type;
|
||||
m->deserialize(stream);
|
||||
msg = m;
|
||||
}
|
||||
else {
|
||||
msg = std::make_shared<message>(type);
|
||||
}
|
||||
|
||||
if (type == message::CLIENT_HELLO)
|
||||
msg = std::make_shared<client_hello>();
|
||||
else if (type == message::SERVER_HELLO)
|
||||
msg = std::make_shared<server_hello>();
|
||||
else if (type == message::FRAME_INFO)
|
||||
msg = std::make_shared<frame_info>();
|
||||
else if (type == message::REQUEST_COMMAND)
|
||||
msg = std::make_shared<request_command>();
|
||||
|
||||
msg->deserialize(stream);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
void network::serialize_message(const message &msg, std::ostream &stream)
|
||||
{
|
||||
sn_utils::ls_uint16(stream, (uint16_t)msg.type);
|
||||
msg.serialize(stream);
|
||||
}
|
||||
|
||||
@@ -9,66 +9,62 @@ namespace network
|
||||
{
|
||||
enum type_e
|
||||
{
|
||||
CONNECT_REQUEST = 0,
|
||||
CONNECT_ACCEPT,
|
||||
STEP_INFO,
|
||||
CLIENT_COMMAND,
|
||||
CLIENT_HELLO = 0,
|
||||
SERVER_HELLO,
|
||||
FRAME_INFO,
|
||||
REQUEST_COMMAND,
|
||||
TYPE_MAX
|
||||
};
|
||||
|
||||
type_e type;
|
||||
|
||||
message(type_e t) : type(t) {}
|
||||
virtual void serialize(std::ostream &stream);
|
||||
virtual void deserialize(std::istream &stream);
|
||||
virtual size_t get_size() { return 2; }
|
||||
virtual void serialize(std::ostream &stream) const {}
|
||||
virtual void deserialize(std::istream &stream) {}
|
||||
};
|
||||
|
||||
struct accept_message : public message
|
||||
struct client_hello : public message
|
||||
{
|
||||
accept_message() : message(CONNECT_ACCEPT) {}
|
||||
client_hello() : message(CLIENT_HELLO) {}
|
||||
|
||||
virtual void serialize(std::ostream &stream) const override;
|
||||
virtual void deserialize(std::istream &stream) override;
|
||||
|
||||
int32_t version;
|
||||
};
|
||||
|
||||
struct server_hello : public message
|
||||
{
|
||||
server_hello() : message(SERVER_HELLO) {}
|
||||
|
||||
uint32_t seed;
|
||||
|
||||
virtual void serialize(std::ostream &stream) override;
|
||||
virtual void serialize(std::ostream &stream) const override;
|
||||
virtual void deserialize(std::istream &stream) override;
|
||||
virtual size_t get_size() override;
|
||||
};
|
||||
|
||||
struct command_message : public message
|
||||
struct request_command : public message
|
||||
{
|
||||
command_message() : message(CLIENT_COMMAND) {}
|
||||
command_message(type_e type) : message(type) {}
|
||||
request_command(type_e type) : message(type) {}
|
||||
request_command() : message(REQUEST_COMMAND) {}
|
||||
|
||||
command_queue::commands_map commands;
|
||||
|
||||
virtual void serialize(std::ostream &stream) override;
|
||||
virtual void serialize(std::ostream &stream) const override;
|
||||
virtual void deserialize(std::istream &stream) override;
|
||||
virtual size_t get_size() override;
|
||||
};
|
||||
|
||||
struct delta_message : public command_message
|
||||
struct frame_info : public request_command
|
||||
{
|
||||
delta_message() : command_message(STEP_INFO) {}
|
||||
frame_info() : request_command(FRAME_INFO) {}
|
||||
|
||||
double dt;
|
||||
double sync;
|
||||
|
||||
virtual void serialize(std::ostream &stream) override;
|
||||
virtual void serialize(std::ostream &stream) const override;
|
||||
virtual void deserialize(std::istream &stream) override;
|
||||
virtual size_t get_size() override;
|
||||
};
|
||||
|
||||
struct string_message : public message
|
||||
{
|
||||
string_message(type_e type) : message(type) {}
|
||||
|
||||
std::string name;
|
||||
|
||||
virtual void serialize(std::ostream &stream) override;
|
||||
virtual void deserialize(std::istream &stream) override;
|
||||
virtual size_t get_size() override;
|
||||
};
|
||||
|
||||
std::shared_ptr<message> deserialize_message(std::istream &stream);
|
||||
}
|
||||
void serialize_message(const message &msg, std::ostream &stream);
|
||||
} // namespace network
|
||||
|
||||
@@ -5,8 +5,20 @@
|
||||
#include "Timer.h"
|
||||
#include "application.h"
|
||||
|
||||
// connection
|
||||
|
||||
void network::connection::disconnect() {
|
||||
WriteLog("net: peer dropped", logtype::net);
|
||||
state = DEAD;
|
||||
}
|
||||
|
||||
void network::connection::set_handler(std::function<void (const message &)> handler) {
|
||||
message_handler = handler;
|
||||
}
|
||||
|
||||
network::connection::connection(bool client) {
|
||||
is_client = client;
|
||||
state = AWAITING_HELLO;
|
||||
}
|
||||
|
||||
void network::connection::connected()
|
||||
@@ -14,50 +26,57 @@ void network::connection::connected()
|
||||
WriteLog("net: socket connected", logtype::net);
|
||||
|
||||
if (is_client) {
|
||||
std::shared_ptr<message> hello = std::make_shared<message>(message::CONNECT_REQUEST);
|
||||
send_message(hello);
|
||||
client_hello msg;
|
||||
msg.version = 1;
|
||||
send_message(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void network::connection::message_received(std::shared_ptr<message> &msg)
|
||||
{
|
||||
/*
|
||||
if (msg->type == message::TYPE_MAX)
|
||||
{
|
||||
disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg->type == message::CONNECT_REQUEST)
|
||||
{
|
||||
std::shared_ptr<accept_message> reply = std::make_shared<accept_message>();
|
||||
reply->seed = Global.random_seed;
|
||||
if (is_client) {
|
||||
if (msg->type == message::SERVER_HELLO) {
|
||||
auto cmd = std::dynamic_pointer_cast<server_hello>(msg);
|
||||
|
||||
WriteLog("client accepted", logtype::net);
|
||||
|
||||
send_message(reply);
|
||||
}
|
||||
else if (msg->type == message::CONNECT_ACCEPT)
|
||||
{
|
||||
auto cmd = std::dynamic_pointer_cast<accept_message>(msg);
|
||||
|
||||
WriteLog("accept received", logtype::net);
|
||||
state = ACTIVE;
|
||||
Global.random_seed = cmd->seed;
|
||||
Global.random_engine.seed(Global.random_seed);
|
||||
|
||||
WriteLog("net: accept received", logtype::net);
|
||||
}
|
||||
else if (msg->type == message::CLIENT_COMMAND)
|
||||
{
|
||||
auto cmd = std::dynamic_pointer_cast<command_message>(msg);
|
||||
for (auto const &kv : cmd->commands)
|
||||
client_commands_queue.emplace(kv);
|
||||
}
|
||||
else if (msg->type == message::STEP_INFO)
|
||||
{
|
||||
auto delta = std::dynamic_pointer_cast<delta_message>(msg);
|
||||
else if (msg->type == message::FRAME_INFO) {
|
||||
auto delta = std::dynamic_pointer_cast<frame_info>(msg);
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
delta_queue.push(std::make_pair(now, delta));
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (msg->type == message::CLIENT_HELLO) {
|
||||
server_hello reply;
|
||||
reply.seed = Global.random_seed;
|
||||
state = ACTIVE;
|
||||
|
||||
send_message(reply);
|
||||
|
||||
WriteLog("net: client accepted", logtype::net);
|
||||
}
|
||||
else if (msg->type == message::REQUEST_COMMAND) {
|
||||
auto cmd = std::dynamic_pointer_cast<request_command>(msg);
|
||||
|
||||
for (auto const &kv : cmd->commands)
|
||||
client_commands_queue.emplace(kv);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// --------------
|
||||
|
||||
/*
|
||||
std::tuple<double, double, command_queue::commands_map> network::connection::get_next_delta()
|
||||
{
|
||||
if (delta_queue.empty()) {
|
||||
@@ -90,70 +109,83 @@ command_queue::commands_map network::connection::pop_commands()
|
||||
client_commands_queue.clear();
|
||||
return map;
|
||||
}
|
||||
*/
|
||||
|
||||
void network::connection::data_received(std::string &buffer)
|
||||
{
|
||||
std::istringstream body(buffer);
|
||||
std::shared_ptr<message> msg = deserialize_message(body);
|
||||
|
||||
message_received(msg);
|
||||
}
|
||||
|
||||
void network::connection::send_message(std::shared_ptr<message> msg)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
sn_utils::ls_uint32(stream, 0x37305545);
|
||||
sn_utils::ls_uint32(stream, msg->get_size());
|
||||
sn_utils::ls_uint16(stream, (uint16_t)msg->type);
|
||||
msg->serialize(stream);
|
||||
stream.flush();
|
||||
|
||||
std::shared_ptr<std::string> buf = std::make_shared<std::string>(stream.str());
|
||||
send_data(buf);
|
||||
}
|
||||
// server
|
||||
|
||||
network::server::server()
|
||||
{
|
||||
recorder.open("recorder.bin", std::ios::trunc | std::ios::out | std::ios::binary);
|
||||
}
|
||||
|
||||
void network::server::push_delta(double dt, double sync, command_queue::commands_map commands)
|
||||
void network::server::push_delta(double dt, double sync, const command_queue::commands_map &commands)
|
||||
{
|
||||
if (dt == 0.0 && commands.empty())
|
||||
return;
|
||||
|
||||
std::shared_ptr<delta_message> msg = std::make_shared<delta_message>();
|
||||
msg->dt = dt;
|
||||
msg->sync = sync;
|
||||
msg->commands = commands;
|
||||
frame_info msg;
|
||||
msg.dt = dt;
|
||||
msg.sync = sync;
|
||||
msg.commands = commands;
|
||||
|
||||
sn_utils::ls_uint32(recorder, 0x37305545);
|
||||
sn_utils::ls_uint32(recorder, msg->get_size());
|
||||
sn_utils::ls_uint16(recorder, (uint16_t)msg->type);
|
||||
msg->serialize(recorder);
|
||||
sn_utils::ls_uint32(recorder, 0);
|
||||
sn_utils::ls_uint16(recorder, (uint16_t)msg.type);
|
||||
msg.serialize(recorder);
|
||||
recorder.flush();
|
||||
|
||||
for (auto c : clients)
|
||||
if (c->state == connection::ACTIVE)
|
||||
c->send_message(msg);
|
||||
}
|
||||
|
||||
command_queue::commands_map network::server::pop_commands()
|
||||
{
|
||||
command_queue::commands_map map;
|
||||
for (auto c : clients) {
|
||||
command_queue::commands_map cmap = c->pop_commands();
|
||||
for (auto const &kv : cmap) {
|
||||
auto lookup = map.emplace(kv.first, command_queue::commanddata_sequence());
|
||||
for (command_data const &data : kv.second)
|
||||
lookup.first->second.emplace_back(data);
|
||||
}
|
||||
}
|
||||
command_queue::commands_map map(client_commands_queue);
|
||||
client_commands_queue.clear();
|
||||
return map;
|
||||
}
|
||||
|
||||
void network::server::handle_message(connection &conn, const message &msg)
|
||||
{
|
||||
if (msg.type == message::TYPE_MAX)
|
||||
{
|
||||
conn.disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.type == message::CLIENT_HELLO) {
|
||||
server_hello reply;
|
||||
reply.seed = Global.random_seed;
|
||||
conn.state = connection::ACTIVE;
|
||||
|
||||
conn.send_message(reply);
|
||||
|
||||
WriteLog("net: client accepted", logtype::net);
|
||||
}
|
||||
else if (msg.type == message::REQUEST_COMMAND) {
|
||||
auto cmd = dynamic_cast<const request_command&>(msg);
|
||||
|
||||
for (auto const &kv : cmd.commands)
|
||||
client_commands_queue.emplace(kv);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------
|
||||
|
||||
// client
|
||||
|
||||
std::tuple<double, double, command_queue::commands_map> network::client::get_next_delta()
|
||||
{
|
||||
return conn->get_next_delta();
|
||||
if (delta_queue.empty()) {
|
||||
return std::tuple<double, double,
|
||||
command_queue::commands_map>(0.0, 0.0, command_queue::commands_map());
|
||||
}
|
||||
|
||||
auto entry = delta_queue.front();
|
||||
delta_queue.pop();
|
||||
|
||||
return std::make_tuple(entry.second.dt, entry.second.sync, entry.second.commands);
|
||||
}
|
||||
|
||||
void network::client::send_commands(command_queue::commands_map commands)
|
||||
@@ -161,8 +193,34 @@ void network::client::send_commands(command_queue::commands_map commands)
|
||||
if (commands.empty())
|
||||
return;
|
||||
|
||||
std::shared_ptr<command_message> msg = std::make_shared<command_message>();
|
||||
msg->commands = commands;
|
||||
request_command msg;
|
||||
msg.commands = commands;
|
||||
|
||||
conn->send_message(msg);
|
||||
}
|
||||
|
||||
void network::client::handle_message(connection &conn, const message &msg)
|
||||
{
|
||||
if (msg.type == message::TYPE_MAX)
|
||||
{
|
||||
conn.disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.type == message::SERVER_HELLO) {
|
||||
auto cmd = dynamic_cast<const server_hello&>(msg);
|
||||
|
||||
conn.state = connection::ACTIVE;
|
||||
Global.random_seed = cmd.seed;
|
||||
Global.random_engine.seed(Global.random_seed);
|
||||
|
||||
WriteLog("net: accept received", logtype::net);
|
||||
}
|
||||
else if (msg.type == message::FRAME_INFO) {
|
||||
auto delta = dynamic_cast<const frame_info&>(msg);
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
delta_queue.push(std::make_pair(now, delta));
|
||||
}
|
||||
}
|
||||
|
||||
// --------------
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include <asio.hpp>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
@@ -10,52 +9,73 @@
|
||||
|
||||
namespace network
|
||||
{
|
||||
class connection : public std::enable_shared_from_this<connection>
|
||||
class connection
|
||||
{
|
||||
friend class server;
|
||||
friend class client;
|
||||
|
||||
private:
|
||||
void message_received(std::shared_ptr<message> &msg);
|
||||
/*
|
||||
std::queue<
|
||||
std::pair<std::chrono::high_resolution_clock::time_point,
|
||||
std::shared_ptr<delta_message>>> delta_queue;
|
||||
std::shared_ptr<frame_info>>> delta_queue;
|
||||
|
||||
command_queue::commands_map client_commands_queue;
|
||||
bool is_client;
|
||||
|
||||
//std::chrono::high_resolution_clock::time_point last_time;
|
||||
//double accum = -1.0;
|
||||
*/
|
||||
bool is_client;
|
||||
|
||||
protected:
|
||||
std::function<void(const message &msg)> message_handler;
|
||||
|
||||
public:
|
||||
virtual void connected() = 0;
|
||||
virtual void send_message(const message &msg) = 0;
|
||||
|
||||
connection(bool client = false);
|
||||
void set_handler(std::function<void(const message &msg)> handler);
|
||||
|
||||
virtual void disconnect() = 0;
|
||||
virtual void send_data(std::shared_ptr<std::string> buffer) = 0;
|
||||
|
||||
void data_received(std::string &buffer);
|
||||
|
||||
public:
|
||||
connection(bool client = false);
|
||||
void send_message(std::shared_ptr<message> msg);
|
||||
virtual void connected();
|
||||
|
||||
std::tuple<double, double, command_queue::commands_map> get_next_delta();
|
||||
command_queue::commands_map pop_commands();
|
||||
enum peer_state {
|
||||
AWAITING_HELLO,
|
||||
CATCHING_UP,
|
||||
ACTIVE,
|
||||
DEAD
|
||||
};
|
||||
peer_state state;
|
||||
};
|
||||
|
||||
class server
|
||||
{
|
||||
protected:
|
||||
void handle_message(connection &conn, const message &msg);
|
||||
|
||||
std::vector<std::shared_ptr<connection>> clients;
|
||||
std::fstream recorder;
|
||||
|
||||
command_queue::commands_map client_commands_queue;
|
||||
|
||||
public:
|
||||
server();
|
||||
void push_delta(double dt, double sync, command_queue::commands_map commands);
|
||||
void push_delta(double dt, double sync, const command_queue::commands_map &commands);
|
||||
command_queue::commands_map pop_commands();
|
||||
};
|
||||
|
||||
class client
|
||||
{
|
||||
protected:
|
||||
void handle_message(connection &conn, const message &msg);
|
||||
std::shared_ptr<connection> conn;
|
||||
|
||||
std::queue<
|
||||
std::pair<std::chrono::high_resolution_clock::time_point,
|
||||
frame_info>> delta_queue;
|
||||
|
||||
public:
|
||||
std::tuple<double, double, command_queue::commands_map> get_next_delta();
|
||||
void send_commands(command_queue::commands_map commands);
|
||||
|
||||
141
network/tcp.cpp
141
network/tcp.cpp
@@ -1,141 +0,0 @@
|
||||
#include "network/tcp.h"
|
||||
#include "Logs.h"
|
||||
#include "sn_utils.h"
|
||||
#include "Globals.h"
|
||||
|
||||
network::tcp_conn::tcp_conn(asio::io_context &io_ctx, bool client)
|
||||
: connection(client), m_socket(io_ctx)
|
||||
{
|
||||
m_header_buffer.resize(8);
|
||||
}
|
||||
|
||||
void network::tcp_conn::disconnect()
|
||||
{
|
||||
WriteLog("network: client dropped", logtype::net);
|
||||
m_socket.close();
|
||||
}
|
||||
|
||||
void network::tcp_conn::connected()
|
||||
{
|
||||
connection::connected();
|
||||
read_header();
|
||||
}
|
||||
|
||||
void network::tcp_conn::read_header()
|
||||
{
|
||||
asio::async_read(m_socket, asio::buffer(m_header_buffer),
|
||||
std::bind(&tcp_conn::handle_header, this,
|
||||
std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
|
||||
void network::tcp_conn::handle_send(std::shared_ptr<std::string> buf, const asio::error_code &err, size_t bytes_transferred)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void network::tcp_conn::send_data(std::shared_ptr<std::string> buffer)
|
||||
{
|
||||
asio::async_write(m_socket, asio::buffer(*buffer.get()), std::bind(&tcp_conn::handle_send, this, buffer,
|
||||
std::placeholders::_1,
|
||||
std::placeholders::_2));
|
||||
}
|
||||
|
||||
void network::tcp_conn::handle_header(const asio::error_code &err, size_t bytes_transferred)
|
||||
{
|
||||
std::istringstream header(m_header_buffer);
|
||||
if (m_header_buffer.size() != bytes_transferred) {
|
||||
disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t sig = sn_utils::ld_uint32(header);
|
||||
if (sig != 0x37305545) {
|
||||
disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t len = sn_utils::ld_uint32(header);
|
||||
m_body_buffer.resize(len);
|
||||
if (len > 10000) {
|
||||
disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
asio::async_read(m_socket, asio::buffer(m_body_buffer),
|
||||
std::bind(&tcp_conn::handle_data, this, std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
|
||||
void network::tcp_conn::handle_data(const asio::error_code &err, size_t bytes_transferred)
|
||||
{
|
||||
if (m_body_buffer.size() != bytes_transferred) {
|
||||
disconnect();
|
||||
return;
|
||||
}
|
||||
data_received(m_body_buffer);
|
||||
read_header();
|
||||
}
|
||||
|
||||
asio::ip::tcp::socket& network::tcp_conn::socket()
|
||||
{
|
||||
return m_socket;
|
||||
}
|
||||
|
||||
network::tcp_server::tcp_server(asio::io_context &io_ctx)
|
||||
: m_acceptor(io_ctx)
|
||||
{
|
||||
auto endpoint = asio::ip::tcp::endpoint(asio::ip::address::from_string(Global.network_conf.server_host), Global.network_conf.server_port);
|
||||
m_acceptor.open(endpoint.protocol());
|
||||
m_acceptor.set_option(asio::socket_base::reuse_address(true));
|
||||
m_acceptor.set_option(asio::ip::tcp::no_delay(true));
|
||||
m_acceptor.bind(endpoint);
|
||||
m_acceptor.listen(10);
|
||||
|
||||
accept_conn();
|
||||
}
|
||||
|
||||
void network::tcp_server::accept_conn()
|
||||
{
|
||||
std::shared_ptr<tcp_conn> conn = std::make_shared<tcp_conn>(m_acceptor.get_executor().context());
|
||||
|
||||
m_acceptor.async_accept(conn->socket(), std::bind(&tcp_server::handle_accept, this, conn, std::placeholders::_1));
|
||||
}
|
||||
|
||||
void network::tcp_server::handle_accept(std::shared_ptr<tcp_conn> conn, const asio::error_code &err)
|
||||
{
|
||||
if (!err)
|
||||
{
|
||||
clients.emplace_back(conn);
|
||||
conn->connected();
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLog(std::string("net: failed to accept client: " + err.message()), logtype::net);
|
||||
}
|
||||
|
||||
accept_conn();
|
||||
}
|
||||
|
||||
network::tcp_client::tcp_client(asio::io_context &io_ctx)
|
||||
{
|
||||
conn = std::make_shared<tcp_conn>(io_ctx, true);
|
||||
auto tcpconn = std::static_pointer_cast<tcp_conn>(conn);
|
||||
|
||||
asio::ip::tcp::endpoint endpoint(
|
||||
asio::ip::address::from_string(Global.network_conf.client_host), Global.network_conf.client_port);
|
||||
tcpconn->socket().open(endpoint.protocol());
|
||||
tcpconn->socket().set_option(asio::ip::tcp::no_delay(true));
|
||||
tcpconn->socket().async_connect(endpoint,
|
||||
std::bind(&tcp_client::handle_accept, this, std::placeholders::_1));
|
||||
}
|
||||
|
||||
void network::tcp_client::handle_accept(const asio::error_code &err)
|
||||
{
|
||||
if (!err)
|
||||
{
|
||||
conn->connected();
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLog(std::string("net: failed to connect: " + err.message()), logtype::net);
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <asio.hpp>
|
||||
#include <memory>
|
||||
#include <array>
|
||||
#include "network/network.h"
|
||||
|
||||
namespace network
|
||||
{
|
||||
class tcp_conn
|
||||
: public connection
|
||||
{
|
||||
private:
|
||||
asio::ip::tcp::socket m_socket;
|
||||
|
||||
std::string m_header_buffer;
|
||||
std::string m_body_buffer;
|
||||
|
||||
void read_header();
|
||||
void handle_send(std::shared_ptr<std::string> buf, const asio::error_code &err, size_t bytes_transferred);
|
||||
void handle_header(const asio::error_code &err, size_t bytes_transferred);
|
||||
void handle_data(const asio::error_code &err, size_t bytes_transferred);
|
||||
|
||||
protected:
|
||||
void disconnect() override;
|
||||
void send_data(std::shared_ptr<std::string> buffer) override;
|
||||
|
||||
public:
|
||||
tcp_conn(asio::io_context &io_ctx, bool client = false);
|
||||
asio::ip::tcp::socket& socket();
|
||||
|
||||
void connected() override;
|
||||
};
|
||||
|
||||
class tcp_server : public server
|
||||
{
|
||||
public:
|
||||
tcp_server(asio::io_context &io_ctx);
|
||||
|
||||
private:
|
||||
void accept_conn();
|
||||
void handle_accept(std::shared_ptr<tcp_conn> conn, const asio::error_code &err);
|
||||
|
||||
asio::ip::tcp::acceptor m_acceptor;
|
||||
};
|
||||
|
||||
class tcp_client : public client
|
||||
{
|
||||
private:
|
||||
void handle_accept(const asio::error_code &err);
|
||||
|
||||
public:
|
||||
tcp_client(asio::io_context &io_ctx);
|
||||
};
|
||||
}
|
||||
@@ -20,7 +20,9 @@ void ui::vehiclelist_panel::render_contents() {
|
||||
else if (ImGui::TreeNode(vehicle, label.c_str())) {
|
||||
vehicle = vehicle->Next();
|
||||
while (vehicle) {
|
||||
ImGui::TextUnformatted(vehicle->name().c_str());
|
||||
if (ImGui::Button(vehicle->name().c_str())) {
|
||||
Global.pCamera.Pos = vehicle->GetPosition();
|
||||
}
|
||||
vehicle = vehicle->Next();
|
||||
}
|
||||
ImGui::TreePop();
|
||||
|
||||
Reference in New Issue
Block a user