player connect-disconnect

This commit is contained in:
Vladislav Khorev committed 2026-11-06 22:07:47 +06:00
1 parent 3f68a8ba07
commit 2e6b93f3ac
16 files changed
+305 -62

No files matched your search

+49 -2
View File
@@ -34,11 +34,16 @@ int main()
{
FRG::CampaignConfig campaign;
campaign.id = "test_lockstep";
campaign.networkPlayerSlots = {"player", "player2"};
FRG::InternalGameServer authoritative;
authoritative.startCampaign(campaign, {}, true, false);
nlohmann::json initialState;
authoritative.save(initialState);
initialState["players"]["player2"] = initialState["players"]["player"];
authoritative.load(initialState);
FRG::WebsocketGameServer server(
authoritative, {"player"}, "lockstep-v2:test_lockstep",
authoritative, {"player", "player2"}, "lockstep-v2:test_lockstep",
"127.0.0.1", 0);
auto client = std::make_unique<FRG::WebsocketGameClient>(
"127.0.0.1", std::to_string(server.port()), "/");
@@ -54,6 +59,18 @@ int main()
"client did not receive initial state");
require(client->localPlayerId() == "player", "wrong player slot assigned");
auto secondClient = std::make_unique<FRG::WebsocketGameClient>(
"127.0.0.1", std::to_string(server.port()), "/");
require(
waitFor([&]() {
secondClient->update(0);
return secondClient->initialized();
}),
"second client did not receive initial state");
require(
secondClient->localPlayerId() == "player2",
"second client received the wrong player slot");
FRG::WebsocketGameClient overflow(
"127.0.0.1", std::to_string(server.port()), "/");
require(
@@ -63,6 +80,18 @@ int main()
}),
"connection beyond configured slots was not rejected");
server.update();
require(
waitFor([&]() {
client->update(0);
secondClient->update(0);
return client->snapshot()->players.at("player2").state.enabled &&
secondClient->snapshot()->players.at("player").state.enabled;
}) &&
authoritative.snapshot()->players.at("player").state.enabled &&
authoritative.snapshot()->players.at("player2").state.enabled,
"connection presence was not broadcast to all replicas");
client->submit(FRG::SetCharacterDestinationCommand{
{}, "spoofed", Eigen::Vector3f(1.234f, 0.f, 2.345f), "ignored"});
std::this_thread::sleep_for(std::chrono::milliseconds(20));
@@ -75,8 +104,17 @@ int main()
}),
"client did not consume finalized lockstep ticks");
client.reset();
secondClient.reset();
std::this_thread::sleep_for(std::chrono::milliseconds(50));
server.update();
require(
waitFor([&]() {
client->update(0);
return !client->snapshot()->players.at("player2").state.enabled;
}) &&
!authoritative.snapshot()->players.at("player2").state.enabled,
"disconnect presence was not propagated");
FRG::WebsocketGameClient replacement(
"127.0.0.1", std::to_string(server.port()), "/");
require(
@@ -85,6 +123,15 @@ int main()
return replacement.initialized();
}),
"disconnected player slot was not reusable");
server.update();
require(
waitFor([&]() {
client->update(0);
replacement.update(0);
return client->snapshot()->players.at("player2").state.enabled;
}) &&
authoritative.snapshot()->players.at("player2").state.enabled,
"reconnected player was not enabled");
return EXIT_SUCCESS;
}