| 145 | } |
| 146 | |
| 147 | void NetworkServer::onReceiveStateRequestPacket(Client& client, const RequestStatePacket& request) |
| 148 | { |
| 149 | constexpr uint16_t kChunkSize = 4000; |
| 150 | |
| 151 | // Dump S5 data to stream |
| 152 | MemoryStream ms; |
| 153 | S5::exportGameStateToFile(ms, S5::SaveFlags::noWindowClose); |
| 154 | |
| 155 | // Append extra state |
| 156 | ExtraState extra; |
| 157 | extra.gameCommandIndex = _gameCommandIndex; |
| 158 | extra.tick = ScenarioManager::getScenarioTicks(); |
| 159 | ms.write(&extra, sizeof(extra)); |
| 160 | |
| 161 | RequestStateResponse response; |
| 162 | response.cookie = request.cookie; |
| 163 | response.totalSize = static_cast<uint32_t>(ms.getLength()); |
| 164 | response.numChunks = static_cast<uint16_t>((ms.getLength() + (kChunkSize - 1)) / kChunkSize); |
| 165 | client.connection->sendPacket(response); |
| 166 | |
| 167 | uint32_t offset = 0; |
| 168 | uint32_t remaining = response.totalSize; |
| 169 | uint16_t index = 0; |
| 170 | while (index < response.numChunks) |
| 171 | { |
| 172 | RequestStateResponseChunk chunk; |
| 173 | chunk.cookie = request.cookie; |
| 174 | chunk.index = index; |
| 175 | chunk.offset = offset; |
| 176 | chunk.dataSize = std::min<uint32_t>(kChunkSize, remaining - offset); |
| 177 | std::memcpy(chunk.data, reinterpret_cast<const uint8_t*>(ms.data()) + offset, chunk.dataSize); |
| 178 | |
| 179 | client.connection->sendPacket(chunk); |
| 180 | |
| 181 | offset += chunk.dataSize; |
| 182 | index++; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | void NetworkServer::onReceiveSendChatMessagePacket(Client& client, const SendChatMessage& packet) |
| 187 | { |
nothing calls this directly
no test coverage detected