| 2544 | } |
| 2545 | |
| 2546 | void NetworkBase::Client_Handle_GAMESTATE(Connection& connection, Packet& packet) |
| 2547 | { |
| 2548 | uint32_t tick; |
| 2549 | uint32_t totalSize; |
| 2550 | uint32_t offset; |
| 2551 | uint32_t dataSize; |
| 2552 | |
| 2553 | packet >> tick >> totalSize >> offset >> dataSize; |
| 2554 | |
| 2555 | if (offset == 0) |
| 2556 | { |
| 2557 | // Reset |
| 2558 | _serverGameState = MemoryStream(); |
| 2559 | } |
| 2560 | |
| 2561 | _serverGameState.SetPosition(offset); |
| 2562 | |
| 2563 | const uint8_t* data = packet.read(dataSize); |
| 2564 | _serverGameState.Write(data, dataSize); |
| 2565 | |
| 2566 | LOG_VERBOSE( |
| 2567 | "Received Game State %.02f%%", |
| 2568 | (static_cast<float>(_serverGameState.GetLength()) / static_cast<float>(totalSize)) * 100.0f); |
| 2569 | |
| 2570 | if (_serverGameState.GetLength() == totalSize) |
| 2571 | { |
| 2572 | _serverGameState.SetPosition(0); |
| 2573 | DataSerialiser ds(false, _serverGameState); |
| 2574 | |
| 2575 | IGameStateSnapshots* snapshots = GetContext().GetGameStateSnapshots(); |
| 2576 | |
| 2577 | GameStateSnapshot_t& serverSnapshot = snapshots->CreateSnapshot(); |
| 2578 | snapshots->SerialiseSnapshot(serverSnapshot, ds); |
| 2579 | |
| 2580 | const GameStateSnapshot_t* desyncSnapshot = snapshots->GetLinkedSnapshot(tick); |
| 2581 | if (desyncSnapshot != nullptr) |
| 2582 | { |
| 2583 | GameStateCompareData cmpData = snapshots->Compare(serverSnapshot, *desyncSnapshot); |
| 2584 | |
| 2585 | std::string outputPath = GetContext().GetPlatformEnvironment().GetDirectoryPath( |
| 2586 | DirBase::user, DirId::desyncLogs); |
| 2587 | |
| 2588 | Path::CreateDirectory(outputPath); |
| 2589 | |
| 2590 | char uniqueFileName[128] = {}; |
| 2591 | snprintf( |
| 2592 | uniqueFileName, sizeof(uniqueFileName), "desync_%llu_%u.txt", |
| 2593 | static_cast<long long unsigned>(Platform::GetDatetimeNowUTC()), tick); |
| 2594 | |
| 2595 | std::string outputFile = Path::Combine(outputPath, uniqueFileName); |
| 2596 | |
| 2597 | if (snapshots->LogCompareDataToFile(outputFile, cmpData)) |
| 2598 | { |
| 2599 | LOG_INFO("Wrote desync report to '%s'", outputFile.c_str()); |
| 2600 | |
| 2601 | auto ft = Formatter(); |
| 2602 | ft.Add<char*>(uniqueFileName); |
| 2603 |
nothing calls this directly
no test coverage detected