Don't allow the game to start if all players joined red or blue team

This commit is contained in:
Benau 2018-07-19 15:50:01 +08:00
parent 639883ca48
commit f124bd9df3
5 changed files with 44 additions and 3 deletions

View File

@ -607,7 +607,8 @@ void cmdLineHelp()
" --auto-end Automatically end network game after 1st player finished\n"
" for some time (currently his finished time * 0.25 + 15.0). \n"
" --team-choosing Allow choosing team in lobby, implicitly allowed in lan or\n"
" password protected server.\n"
" password protected server. This function cannot be used in\n"
" owner-less server.\n"
" --soccer-timed Use time limit mode in network soccer game.\n"
" --soccer-goals Use goals limit mode in network soccer game.\n"
" --network-gp=n Specify number of tracks used in network grand prix.\n"
@ -1158,7 +1159,8 @@ int handleCmdLine()
}
if (CommandLine::has("--team-choosing"))
{
NetworkConfig::get()->setTeamChoosing(true);
if (!NetworkConfig::get()->isOwnerLess())
NetworkConfig::get()->setTeamChoosing(true);
}
if (CommandLine::has("--connect-now", &s))
{

View File

@ -166,6 +166,7 @@ bool ClientLobby::notifyEventAsynchronous(Event* event)
case LE_CONNECTION_REFUSED: connectionRefused(event); break;
case LE_VOTE: displayPlayerVote(event); break;
case LE_SERVER_OWNERSHIP: becomingServerOwner(); break;
case LE_BAD_TEAM: handleBadTeam(); break;
default: break;
} // switch
@ -610,10 +611,21 @@ void ClientLobby::updatePlayerList(Event* event)
NetworkingLobby::getInstance()->updatePlayers(players);
} // updatePlayerList
//-----------------------------------------------------------------------------
void ClientLobby::handleBadTeam()
{
SFXManager::get()->quickSound("anvil");
//I18N: Display when all players are in red or blue team, which the race
//will not be allowed to start
core::stringw msg = _("All players joined red or blue team.");
MessageQueue::add(MessageQueue::MT_ERROR, msg);
} // handleBadTeam
//-----------------------------------------------------------------------------
void ClientLobby::becomingServerOwner()
{
SFXManager::get()->quickSound("wee");
//I18N: Display when a player is allow to control the server
core::stringw msg = _("You are now the owner of server.");
MessageQueue::add(MessageQueue::MT_GENERIC, msg);
STKHost::get()->setAuthorisedToControl(true);

View File

@ -45,6 +45,7 @@ private:
void updatePlayerList(Event* event);
void handleChat(Event* event);
void handleServerInfo(Event* event);
void handleBadTeam();
void becomingServerOwner();
void clearPlayers();

View File

@ -60,7 +60,8 @@ public:
LE_CHAT,
LE_SERVER_OWNERSHIP,
LE_KICK_HOST,
LE_CHANGE_TEAM
LE_CHANGE_TEAM,
LE_BAD_TEAM
};
enum RejectReason : uint8_t

View File

@ -761,6 +761,31 @@ void ServerLobby::startSelection(const Event *event)
}
}
if (NetworkConfig::get()->hasTeamChoosing())
{
int red_count = 0;
int blue_count = 0;
auto players = m_game_setup->getConnectedPlayers();
for (auto& player : players)
{
if (player->getTeam() == SOCCER_TEAM_RED)
red_count++;
else if (player->getTeam() == SOCCER_TEAM_BLUE)
blue_count++;
if (red_count != 0 && blue_count != 0)
break;
}
if ((red_count == 0 || blue_count == 0) && players.size() != 1)
{
Log::warn("ServerLobby", "Bad team choosing.");
NetworkString* bt = getNetworkString();
bt->addUInt8(LE_BAD_TEAM);
sendMessageToPeers(bt, true/*reliable*/);
delete bt;
return;
}
}
ProtocolManager::lock()->findAndTerminate(PROTOCOL_CONNECTION);
if (NetworkConfig::get()->isWAN())
{