Skip to content

Commit 9c5ddfe

Browse files
committed
Store received savegames in save folder
1 parent 37e4166 commit 9c5ddfe

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

libs/s25main/network/GameClient.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,8 @@ bool GameClient::OnGameMessage(const GameMessage_Map_Info& msg)
928928
OnError(ClientError::InvalidMap);
929929
return true;
930930
}
931-
mapinfo.filepath = RTTRCONFIG.ExpandPath(s25::folders::mapsPlayed) / portFilename;
931+
const auto targetFolder = (msg.mt == MapType::Savegame) ? s25::folders::save : s25::folders::mapsPlayed;
932+
mapinfo.filepath = RTTRCONFIG.ExpandPath(targetFolder) / portFilename;
932933
mapinfo.type = msg.mt;
933934

934935
// lua script file path

tests/s25Main/network/testGameClient.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,51 @@ BOOST_DATA_TEST_CASE(ClientFollowsConnectProtocol, usesLuaScriptValues, usesLuaS
244244
}
245245
}
246246

247+
BOOST_AUTO_TEST_CASE(ClientStoresReceivedSavegamesInSaveFolder)
248+
{
249+
GameClient client;
250+
GameMessageInterface& clientMsgInterface = client;
251+
MockClientInterface callbacks;
252+
client.SetInterface(&callbacks);
253+
TestServer server;
254+
const auto serverPort = server.tryListen();
255+
BOOST_TEST_REQUIRE(serverPort >= 0);
256+
const auto pw = rttr::test::randString(10);
257+
const auto serverType = rttr::test::randomEnum<ServerType>();
258+
259+
mock::sequence s;
260+
MOCK_EXPECT(callbacks.CI_NextConnectState).in(s).with(ConnectState::Initiated).once();
261+
MOCK_EXPECT(callbacks.CI_NextConnectState).in(s).with(ConnectState::VerifyServer).once();
262+
MOCK_EXPECT(callbacks.CI_NextConnectState).in(s).with(ConnectState::QueryPw).once();
263+
MOCK_EXPECT(callbacks.CI_NextConnectState).in(s).with(ConnectState::QueryMapInfo).once();
264+
MOCK_EXPECT(callbacks.CI_NextConnectState).in(s).with(ConnectState::ReceiveMap).once();
265+
266+
BOOST_TEST_REQUIRE(client.Connect("localhost", pw, serverType, serverPort, false, false));
267+
clientMsgInterface.OnGameMessage(GameMessage_Player_Id(1));
268+
BOOST_TEST_REQUIRE(boost::dynamic_pointer_cast<GameMessage_Server_Type>(client.GetMainPlayer().sendQueue.pop()));
269+
270+
clientMsgInterface.OnGameMessage(GameMessage_Server_TypeOK(GameMessage_Server_TypeOK::StatusCode::Ok, ""));
271+
BOOST_TEST_REQUIRE(boost::dynamic_pointer_cast<GameMessage_Server_Password>(client.GetMainPlayer().sendQueue.pop()));
272+
273+
clientMsgInterface.OnGameMessage(GameMessage_Server_Password("true"));
274+
BOOST_TEST_REQUIRE(dynamic_cast<GameMessage_Player_Name*>(client.GetMainPlayer().sendQueue.pop().get()));
275+
BOOST_TEST_REQUIRE(dynamic_cast<GameMessage_Player_Portrait*>(client.GetMainPlayer().sendQueue.pop().get()));
276+
const auto infoRequest = boost::dynamic_pointer_cast<GameMessage_MapRequest>(client.GetMainPlayer().sendQueue.pop());
277+
BOOST_TEST_REQUIRE(infoRequest);
278+
BOOST_TEST(infoRequest->requestInfo);
279+
280+
clientMsgInterface.OnGameMessage(GameMessage_Map_Info("received.sav", MapType::Savegame, 100, 10, 0, 0));
281+
282+
const auto expectedSavePath = RTTRCONFIG.ExpandPath(s25::folders::save) / "received.sav";
283+
const auto unexpectedMapsPath = RTTRCONFIG.ExpandPath(s25::folders::mapsPlayed) / "received.sav";
284+
BOOST_TEST(client.GetMapType() == MapType::Savegame);
285+
BOOST_TEST(client.GetMapPath() == expectedSavePath);
286+
BOOST_TEST(client.GetMapPath() != unexpectedMapsPath);
287+
288+
const auto transferRequest = boost::dynamic_pointer_cast<GameMessage_MapRequest>(client.GetMainPlayer().sendQueue.pop());
289+
BOOST_TEST_REQUIRE(transferRequest);
290+
BOOST_TEST(!transferRequest->requestInfo);
291+
}
247292
BOOST_AUTO_TEST_CASE(ClientDetectsMapBufferOverflow)
248293
{
249294
rttr::test::LogAccessor _suppressLogOutput;

0 commit comments

Comments
 (0)