MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / checkReplayValid

Method checkReplayValid

source/modes/MenuModeReplay.cpp:218–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216}
217
218bool MenuModeReplay::checkReplayValid(const std::string& replayFileName, std::string& mapDescription, std::string& errorMsg)
219{
220 // We open the replay to get the level file name
221 std::ifstream is(replayFileName, std::ios::in | std::ios::binary);
222 ODPacket packet;
223 ServerNotificationType type;
224 do
225 {
226 packet.readPacket(is);
227 OD_ASSERT_TRUE(packet >> type);
228 if(is.eof())
229 break;
230 } while(type != ServerNotificationType::loadLevel);
231
232 if(is.eof())
233 {
234 errorMsg = "Invalid replay file";
235 return false;
236 }
237
238 std::string odVersion;
239 std::string tmpStr;
240 int32_t tmpInt;
241 // OD version
242 OD_ASSERT_TRUE(packet >> odVersion);
243 // mapSizeX
244 OD_ASSERT_TRUE(packet >> tmpInt);
245 // mapSizeY
246 OD_ASSERT_TRUE(packet >> tmpInt);
247 // LevelFileName
248 OD_ASSERT_TRUE(packet >> tmpStr);
249 // LevelDescription
250 OD_ASSERT_TRUE(packet >> mapDescription);
251
252 if(odVersion.compare(std::string("OpenDungeons V ") + ODApplication::VERSION) != 0)
253 {
254 errorMsg = odVersion + " (Wrong version)\n\n" + mapDescription;
255 return false;
256 }
257
258 return true;
259}

Callers

nothing calls this directly

Calls 1

readPacketMethod · 0.80

Tested by

no test coverage detected