diff --git a/.gitmodules b/.gitmodules index 79f9ee86..7e2ab279 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,4 +6,4 @@ url = https://github.com/libsdl-org/SDL [submodule "libs/liborts"] path = libs/liborts - url = https://github.com/Milek7/liborts + url = https://github.com/cesarBLG/liborts diff --git a/EVC/CMakeLists.txt b/EVC/CMakeLists.txt index 3f863c25..73e651ac 100644 --- a/EVC/CMakeLists.txt +++ b/EVC/CMakeLists.txt @@ -19,7 +19,7 @@ NationalFN/nationalfn.cpp NationalFN/asfa.cpp add_definitions(-DNO_THREADS) if (NOT WASM) - list(APPEND SOURCES ../platform/console_platform.cpp ../platform/console_fd_poller.cpp ../platform/tcp_socket.cpp ../platform/bus_socket_impl.cpp ../platform/tcp_listener.cpp ../platform/libc_time_impl.cpp ../platform/fstream_file_impl.cpp ../platform/bus_socket_server.cpp ../platform/bus_tcp_bridge.cpp) + list(APPEND SOURCES ../platform/console_platform.cpp ../platform/console_fd_poller.cpp ../platform/tcp_socket.cpp ../platform/bus_socket_impl.cpp ../platform/tcp_listener.cpp ../platform/libc_time_impl.cpp ../platform/fstream_file_impl.cpp ../platform/bus_socket_server.cpp ../platform/bus_tcp_bridge.cpp ../libs/liborts/client.cpp) else() list(APPEND SOURCES ../platform/simrail_platform.cpp) add_definitions(-DJSON_TEST_KEEP_MACROS=1 -DJSON_HAS_FILESYSTEM=0 -DJSON_HAS_EXPERIMENTAL_FILESYSTEM=0) diff --git a/libs/liborts b/libs/liborts index 26cd7939..bc9ce9a6 160000 --- a/libs/liborts +++ b/libs/liborts @@ -1 +1 @@ -Subproject commit 26cd79395f2e71d8766ca9c425d6082fba380950 +Subproject commit bc9ce9a66acc4a524f5366b420e29d64379b5062 diff --git a/platform/bus_tcp_bridge.cpp b/platform/bus_tcp_bridge.cpp index 5baf35f1..54c393b8 100644 --- a/platform/bus_tcp_bridge.cpp +++ b/platform/bus_tcp_bridge.cpp @@ -10,7 +10,7 @@ #include #include "bus_tcp_bridge.h" -void BusTcpBridge::BridgedTcpSocket::tcp_rx(std::string &&data) +void BridgedTcpSocket::tcp_rx(std::string &&data) { if (data.empty()) { alive = false; @@ -48,7 +48,7 @@ void BusTcpBridge::BridgedTcpSocket::tcp_rx(std::string &&data) } } -void BusTcpBridge::BridgedTcpSocket::bus_rx(BasePlatform::BusSocket::ReceiveResult &&result) +void BridgedTcpSocket::bus_rx(BasePlatform::BusSocket::ReceiveResult &&result) { if (!alive) return; @@ -65,14 +65,14 @@ void BusTcpBridge::BridgedTcpSocket::bus_rx(BasePlatform::BusSocket::ReceiveResu tcp_socket->send(msg.data); } -BusTcpBridge::BridgedTcpSocket::BridgedTcpSocket(std::unique_ptr &&bus, std::unique_ptr &&tcp, std::optional tid, bool nl) : +BridgedTcpSocket::BridgedTcpSocket(std::unique_ptr &&bus, std::unique_ptr &&tcp, std::optional tid, bool nl) : bus_socket(std::move(bus)), tcp_socket(std::move(tcp)), bus_tid(tid), newline_framing(nl), alive(true) { tcp_rx_promise = tcp_socket->receive().then(std::bind(&BridgedTcpSocket::tcp_rx, this, std::placeholders::_1)); bus_rx_promise = bus_socket->receive().then(std::bind(&BridgedTcpSocket::bus_rx, this, std::placeholders::_1)); } -bool BusTcpBridge::BridgedTcpSocket::is_alive() const { +bool BridgedTcpSocket::is_alive() const { return alive; } @@ -93,7 +93,7 @@ BusTcpBridge::BusTcpBridge(const std::string_view bus, uint32_t rx_tid, std::opt { accept_promise = listener.accept().then(std::bind(&BusTcpBridge::on_new_client, this, std::placeholders::_1)); } - +#include BusTcpBridgeManager::BusTcpBridgeManager(const std::string_view load_path, FdPoller &fd, BusSocketImpl &impl) { std::ifstream file(std::string(load_path) + "tcp_bus_bridge.conf", std::ios::binary); @@ -125,6 +125,15 @@ BusTcpBridgeManager::BusTcpBridgeManager(const std::string_view load_path, FdPol if (tx_tid != "*") txt = BasePlatform::BusSocket::PeerId::fourcc(tx_tid); bool newline_framing = (!nl.empty() && nl[0] == 'n'); - bridges.push_back(std::make_unique(busname, rxt, txt, newline_framing, tcphost, std::stoi(tcpport), fd, impl)); + if (busname == "evc_sim") { + std::unique_ptr bus_socket = impl.open_bus_socket(busname, rxt); + if (!bus_socket) + continue; + tcphost = ORserver::TCPclient::discover_server_ip(); + auto sock = std::make_unique(tcphost, std::stoi(tcpport), fd); + client_bridges.push_back(std::make_unique(std::move(bus_socket), std::move(sock), txt, newline_framing)); + } else { + server_bridges.push_back(std::make_unique(busname, rxt, txt, newline_framing, tcphost, std::stoi(tcpport), fd, impl)); + } } } diff --git a/platform/bus_tcp_bridge.h b/platform/bus_tcp_bridge.h index 2d7be6c4..dfe197d2 100644 --- a/platform/bus_tcp_bridge.h +++ b/platform/bus_tcp_bridge.h @@ -8,10 +8,7 @@ #include "tcp_listener.h" #include "bus_socket_impl.h" - -class BusTcpBridge : private PlatformUtil::NoCopy { -private: - class BridgedTcpSocket : private PlatformUtil::NoCopy { +class BridgedTcpSocket : private PlatformUtil::NoCopy { private: std::unique_ptr bus_socket; PlatformUtil::Promise bus_rx_promise; @@ -32,6 +29,8 @@ class BusTcpBridge : private PlatformUtil::NoCopy { BridgedTcpSocket(std::unique_ptr &&bus, std::unique_ptr &&tcp, std::optional tid, bool nl); bool is_alive() const; }; +class BusTcpBridge : private PlatformUtil::NoCopy { +private: void on_new_client(std::unique_ptr &&sock); @@ -51,7 +50,8 @@ class BusTcpBridge : private PlatformUtil::NoCopy { class BusTcpBridgeManager : private PlatformUtil::NoCopy { private: - std::vector> bridges; + std::vector> client_bridges; + std::vector> server_bridges; public: BusTcpBridgeManager(const std::string_view load_path, FdPoller &fd, BusSocketImpl &impl); };