Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libs/s25main/network/GameServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,10 +938,12 @@ bool GameServer::OnGameMessage(const GameMessage_Server_Password& msg)
} else
playerInfos[msg.senderPlayerID].isHost = false;

player->sendMsgAsync(new GameMessage_Server_Password(passwordok));

if(passwordok == "false")
{
player->sendMsg(GameMessage_Server_Password(passwordok));
KickPlayer(msg.senderPlayerID, KickReason::WrongPassword, __LINE__);
} else
player->sendMsgAsync(new GameMessage_Server_Password(passwordok));
return true;
}

Expand Down
28 changes: 28 additions & 0 deletions tests/s25Main/network/testGameClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,34 @@ BOOST_AUTO_TEST_CASE(ClientDetectsMapBufferOverflow)
BOOST_TEST(client.GetState() == ClientState::Stopped);
}

BOOST_AUTO_TEST_CASE(ClientReportsWrongPasswordResponse)
{
GameClient client;
GameMessageInterface& clientMsgInterface = client;
MockClientInterface callbacks;
client.SetInterface(&callbacks);
TestServer server;
const auto serverPort = server.tryListen();
BOOST_TEST_REQUIRE(serverPort >= 0);
const auto serverType = rttr::test::randomEnum<ServerType>();
mock::sequence s;
MOCK_EXPECT(callbacks.CI_NextConnectState).in(s).with(ConnectState::Initiated).once();
MOCK_EXPECT(callbacks.CI_NextConnectState).in(s).with(ConnectState::VerifyServer).once();
MOCK_EXPECT(callbacks.CI_NextConnectState).in(s).with(ConnectState::QueryPw).once();
MOCK_EXPECT(callbacks.CI_Error).in(s).with(ClientError::WrongPassword).once();

BOOST_TEST_REQUIRE(client.Connect("localhost", rttr::test::randString(10), serverType, serverPort, false, false));
clientMsgInterface.OnGameMessage(GameMessage_Player_Id(1));
clientMsgInterface.OnGameMessage(GameMessage_Server_TypeOK(GameMessage_Server_TypeOK::StatusCode::Ok, ""));
BOOST_TEST_REQUIRE(boost::dynamic_pointer_cast<GameMessage_Server_Type>(client.GetMainPlayer().sendQueue.pop()));
BOOST_TEST_REQUIRE(
boost::dynamic_pointer_cast<GameMessage_Server_Password>(client.GetMainPlayer().sendQueue.pop()));

clientMsgInterface.OnGameMessage(GameMessage_Server_Password("false"));

BOOST_TEST(client.GetState() == ClientState::Stopped);
}

using namespace std::chrono_literals;

BOOST_AUTO_TEST_CASE(CanSetNewSpeed)
Expand Down
Loading