| 2328 | } |
| 2329 | |
| 2330 | void NetworkBase::ServerHandleRequestGamestate(Connection& connection, Packet& packet) |
| 2331 | { |
| 2332 | uint32_t tick; |
| 2333 | packet >> tick; |
| 2334 | |
| 2335 | if (_serverState.gamestateSnapshotsEnabled == false) |
| 2336 | { |
| 2337 | // Ignore this if this is off. |
| 2338 | return; |
| 2339 | } |
| 2340 | |
| 2341 | IGameStateSnapshots* snapshots = GetContext().GetGameStateSnapshots(); |
| 2342 | |
| 2343 | const GameStateSnapshot_t* snapshot = snapshots->GetLinkedSnapshot(tick); |
| 2344 | if (snapshot != nullptr) |
| 2345 | { |
| 2346 | MemoryStream snapshotMemory; |
| 2347 | DataSerialiser ds(true, snapshotMemory); |
| 2348 | |
| 2349 | snapshots->SerialiseSnapshot(const_cast<GameStateSnapshot_t&>(*snapshot), ds); |
| 2350 | |
| 2351 | uint32_t bytesSent = 0; |
| 2352 | uint32_t length = static_cast<uint32_t>(snapshotMemory.GetLength()); |
| 2353 | while (bytesSent < length) |
| 2354 | { |
| 2355 | uint32_t dataSize = kChunkSize; |
| 2356 | if (bytesSent + dataSize > snapshotMemory.GetLength()) |
| 2357 | { |
| 2358 | dataSize = snapshotMemory.GetLength() - bytesSent; |
| 2359 | } |
| 2360 | |
| 2361 | Packet packetGameStateChunk(Command::gameState); |
| 2362 | packetGameStateChunk << tick << length << bytesSent << dataSize; |
| 2363 | packetGameStateChunk.write(static_cast<const uint8_t*>(snapshotMemory.GetData()) + bytesSent, dataSize); |
| 2364 | |
| 2365 | connection.queuePacket(std::move(packetGameStateChunk)); |
| 2366 | |
| 2367 | bytesSent += dataSize; |
| 2368 | } |
| 2369 | } |
| 2370 | } |
| 2371 | |
| 2372 | void NetworkBase::ServerHandleHeartbeat(Connection& connection, Packet& packet) |
| 2373 | { |
nothing calls this directly
no test coverage detected