added choising spaceship type for multiplayer and some fix in respawn

This commit is contained in:
Vlad committed 2026-02-25 19:17:42 +06:00
1 parent 5216965496
commit 74c2f786a1
6 files changed
+196 -39

No files matched your search

+40 -2
View File
@@ -79,7 +79,6 @@ namespace ZL {
try {
int respawnedPlayerId = std::stoi(parts[1]);
pendingRespawns_.push_back(respawnedPlayerId);
remotePlayers.erase(respawnedPlayerId);
std::cout << "Client: Received RESPAWN_ACK for player " << respawnedPlayerId << std::endl;
}
catch (...) {}
@@ -202,6 +201,11 @@ namespace ZL {
{
auto& rp = remotePlayers[remoteId];
if (!rp.timedStates.empty()) {
const ClientState& last = rp.timedStates.back();
remoteState.nickname = last.nickname;
remoteState.shipType = last.shipType;
}
rp.add_state(remoteState);
}
}
@@ -218,7 +222,7 @@ namespace ZL {
if (playerParts.size() < 15) return; // ID + 14 полей ClientState
int rId = std::stoi(playerParts[0]);
if (rId == clientId) return; // Свое состояние игрок знает лучше всех (Client Side Prediction)
if (rId == clientId) return; // Свое состояние игрок знает лучше всех, (Client Side Prediction)
ClientState remoteState;
remoteState.id = rId;
@@ -230,6 +234,40 @@ namespace ZL {
remotePlayers[rId].add_state(remoteState);
}
}
if (msg.rfind("PLAYERINFO:", 0) == 0) {
if (parts.size() >= 4) {
try {
int pid = std::stoi(parts[1]);
if (pid == clientId) {
return;
}
std::string nick = parts[2];
int st = std::stoi(parts[3]);
auto it = remotePlayers.find(pid);
if (it != remotePlayers.end() && !it->second.timedStates.empty()) {
auto& states = it->second.timedStates;
states.back().nickname = nick;
states.back().shipType = st;
}
else {
ClientState cs;
cs.id = pid;
cs.nickname = nick;
cs.shipType = st;
cs.lastUpdateServerTime = std::chrono::system_clock::now();
remotePlayers[pid].add_state(cs);
}
std::cout << "Client: PLAYERINFO received. id=" << pid << " nick=" << nick << " shipType=" << st << std::endl;
}
catch (...) {
}
}
return;
}
}
std::string WebSocketClientBase::SignMessage(const std::string& msg) {