UniverseClient: log packet type when a packet throws an exception

This commit is contained in:
Kae 2024-09-02 22:18:03 +10:00
parent ac7577b4df
commit efa57d3081

View File

@ -648,58 +648,64 @@ void UniverseClient::setPause(bool pause) {
void UniverseClient::handlePackets(List<PacketPtr> const& packets) { void UniverseClient::handlePackets(List<PacketPtr> const& packets) {
for (auto const& packet : packets) { for (auto const& packet : packets) {
if (auto clientContextUpdate = as<ClientContextUpdatePacket>(packet)) { try {
m_clientContext->readUpdate(clientContextUpdate->updateData); if (auto clientContextUpdate = as<ClientContextUpdatePacket>(packet)) {
m_playerStorage->applyShipUpdates(m_clientContext->playerUuid(), m_clientContext->newShipUpdates()); m_clientContext->readUpdate(clientContextUpdate->updateData);
m_playerStorage->applyShipUpdates(m_clientContext->playerUuid(), m_clientContext->newShipUpdates());
if (playerIsOriginal()) if (playerIsOriginal())
m_mainPlayer->setShipUpgrades(m_clientContext->shipUpgrades()); m_mainPlayer->setShipUpgrades(m_clientContext->shipUpgrades());
m_mainPlayer->setAdmin(m_clientContext->isAdmin()); m_mainPlayer->setAdmin(m_clientContext->isAdmin());
m_mainPlayer->setTeam(m_clientContext->team()); m_mainPlayer->setTeam(m_clientContext->team());
} else if (auto chatReceivePacket = as<ChatReceivePacket>(packet)) { } else if (auto chatReceivePacket = as<ChatReceivePacket>(packet)) {
m_pendingMessages.append(chatReceivePacket->receivedMessage); m_pendingMessages.append(chatReceivePacket->receivedMessage);
} else if (auto universeTimeUpdatePacket = as<UniverseTimeUpdatePacket>(packet)) { } else if (auto universeTimeUpdatePacket = as<UniverseTimeUpdatePacket>(packet)) {
m_universeClock->setTime(universeTimeUpdatePacket->universeTime); m_universeClock->setTime(universeTimeUpdatePacket->universeTime);
} else if (auto serverDisconnectPacket = as<ServerDisconnectPacket>(packet)) { } else if (auto serverDisconnectPacket = as<ServerDisconnectPacket>(packet)) {
reset(); reset();
m_disconnectReason = serverDisconnectPacket->reason; m_disconnectReason = serverDisconnectPacket->reason;
break; // Stop handling other packets break; // Stop handling other packets
} else if (auto celestialResponse = as<CelestialResponsePacket>(packet)) { } else if (auto celestialResponse = as<CelestialResponsePacket>(packet)) {
m_celestialDatabase->pushResponses(std::move(celestialResponse->responses)); m_celestialDatabase->pushResponses(std::move(celestialResponse->responses));
} else if (auto warpResult = as<PlayerWarpResultPacket>(packet)) { } else if (auto warpResult = as<PlayerWarpResultPacket>(packet)) {
if (m_mainPlayer->isDeploying() && m_warping && m_warping->is<WarpToPlayer>()) { if (m_mainPlayer->isDeploying() && m_warping && m_warping->is<WarpToPlayer>()) {
Uuid target = m_warping->get<WarpToPlayer>(); Uuid target = m_warping->get<WarpToPlayer>();
for (auto member : m_teamClient->members()) { for (auto member : m_teamClient->members()) {
if (member.uuid == target) { if (member.uuid == target) {
if (member.warpMode != WarpMode::DeployOnly && member.warpMode != WarpMode::BeamOrDeploy) if (member.warpMode != WarpMode::DeployOnly && member.warpMode != WarpMode::BeamOrDeploy)
m_mainPlayer->deployAbort(); m_mainPlayer->deployAbort();
break; break;
}
} }
} }
}
m_warping.reset(); m_warping.reset();
if (!warpResult->success) { if (!warpResult->success) {
m_mainPlayer->teleportAbort(); m_mainPlayer->teleportAbort();
if (warpResult->warpActionInvalid) if (warpResult->warpActionInvalid)
m_mainPlayer->universeMap()->invalidateWarpAction(warpResult->warpAction); m_mainPlayer->universeMap()->invalidateWarpAction(warpResult->warpAction);
}
} else if (auto planetTypeUpdate = as<PlanetTypeUpdatePacket>(packet)) {
m_celestialDatabase->invalidateCacheFor(planetTypeUpdate->coordinate);
} else if (auto pausePacket = as<PausePacket>(packet)) {
setPause(pausePacket->pause);
GlobalTimescale = clamp(pausePacket->timescale, 0.0f, 1024.f);
} else if (auto serverInfoPacket = as<ServerInfoPacket>(packet)) {
m_serverInfo = ServerInfo{serverInfoPacket->players, serverInfoPacket->maxPlayers};
} else if (!m_systemWorldClient->handleIncomingPacket(packet)) {
// see if the system world will handle it, otherwise pass it along to the world client
m_worldClient->handleIncomingPackets({packet});
} }
} else if (auto planetTypeUpdate = as<PlanetTypeUpdatePacket>(packet)) { }
m_celestialDatabase->invalidateCacheFor(planetTypeUpdate->coordinate); catch (StarException const& e) {
} else if (auto pausePacket = as<PausePacket>(packet)) { Logger::error("Exception thrown while handling {} packet", PacketTypeNames.getRight(packet->type()));
setPause(pausePacket->pause); throw;
GlobalTimescale = clamp(pausePacket->timescale, 0.0f, 1024.f);
} else if (auto serverInfoPacket = as<ServerInfoPacket>(packet)) {
m_serverInfo = ServerInfo{serverInfoPacket->players, serverInfoPacket->maxPlayers};
} else if (!m_systemWorldClient->handleIncomingPacket(packet)) {
// see if the system world will handle it, otherwise pass it along to the world client
m_worldClient->handleIncomingPackets({packet});
} }
} }
} }