Add server broadcasts, fake client, timestamps
Enable transform broadcast testing and time syncing: server now assigns incrementing player IDs, sends a welcome packet with playerId and serverTime, and appends serverTime/playerId to incoming transform packets before broadcasting them to all other connected clients. Added thread-safe client tracking, send_packet helper, client removal on send errors, and improved logging. Plugin now includes a clientTime timestamp in transform packets. Added server/fake_client.py to receive and print welcome and broadcasted transform packets, and updated server README and dev-log with usage and test notes.
This commit is contained in:
@@ -148,6 +148,8 @@ namespace F4T::Networking
|
||||
|
||||
g_socket = localSocket;
|
||||
REX::INFO("Connected to Fallout 4 Together local server.");
|
||||
// TODO: Read and log the server welcome packet once the plugin has a small
|
||||
// non-blocking receive path. For now the server owns player IDs entirely.
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -181,16 +183,20 @@ namespace F4T::Networking
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto clientTime =
|
||||
std::chrono::duration<double>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
|
||||
std::array<char, 320> packet{};
|
||||
auto packetSize = std::snprintf(
|
||||
packet.data(),
|
||||
packet.size(),
|
||||
"{\"type\":\"transform\",\"x\":%.2f,\"y\":%.2f,\"z\":%.2f,\"angleZ\":%.2f,\"movementType\":\"%s\"",
|
||||
"{\"type\":\"transform\",\"x\":%.2f,\"y\":%.2f,\"z\":%.2f,\"angleZ\":%.2f,\"movementType\":\"%s\",\"clientTime\":%.3f",
|
||||
a_x,
|
||||
a_y,
|
||||
a_z,
|
||||
a_angleZ,
|
||||
a_movementType ? a_movementType : "normal");
|
||||
a_movementType ? a_movementType : "normal",
|
||||
clientTime);
|
||||
|
||||
if (packetSize <= 0 || static_cast<std::size_t>(packetSize) >= packet.size()) {
|
||||
REX::WARN("Could not format Fallout 4 Together transform packet.");
|
||||
|
||||
Reference in New Issue
Block a user