File tree Expand file tree Collapse file tree 5 files changed +44
-3
lines changed
Expand file tree Collapse file tree 5 files changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -607,7 +607,8 @@ void cmdLineHelp()
607607 " --auto-end Automatically end network game after 1st player finished\n "
608608 " for some time (currently his finished time * 0.25 + 15.0). \n "
609609 " --team-choosing Allow choosing team in lobby, implicitly allowed in lan or\n "
610- " password protected server.\n "
610+ " password protected server. This function cannot be used in\n "
611+ " owner-less server.\n "
611612 " --soccer-timed Use time limit mode in network soccer game.\n "
612613 " --soccer-goals Use goals limit mode in network soccer game.\n "
613614 " --network-gp=n Specify number of tracks used in network grand prix.\n "
@@ -1158,7 +1159,8 @@ int handleCmdLine()
11581159 }
11591160 if (CommandLine::has (" --team-choosing" ))
11601161 {
1161- NetworkConfig::get ()->setTeamChoosing (true );
1162+ if (!NetworkConfig::get ()->isOwnerLess ())
1163+ NetworkConfig::get ()->setTeamChoosing (true );
11621164 }
11631165 if (CommandLine::has (" --connect-now" , &s))
11641166 {
Original file line number Diff line number Diff line change @@ -166,6 +166,7 @@ bool ClientLobby::notifyEventAsynchronous(Event* event)
166166 case LE_CONNECTION_REFUSED: connectionRefused (event); break ;
167167 case LE_VOTE: displayPlayerVote (event); break ;
168168 case LE_SERVER_OWNERSHIP: becomingServerOwner (); break ;
169+ case LE_BAD_TEAM: handleBadTeam (); break ;
169170 default : break ;
170171 } // switch
171172
@@ -610,10 +611,21 @@ void ClientLobby::updatePlayerList(Event* event)
610611 NetworkingLobby::getInstance ()->updatePlayers (players);
611612} // updatePlayerList
612613
614+ // -----------------------------------------------------------------------------
615+ void ClientLobby::handleBadTeam ()
616+ {
617+ SFXManager::get ()->quickSound (" anvil" );
618+ // I18N: Display when all players are in red or blue team, which the race
619+ // will not be allowed to start
620+ core::stringw msg = _ (" All players joined red or blue team." );
621+ MessageQueue::add (MessageQueue::MT_ERROR, msg);
622+ } // handleBadTeam
623+
613624// -----------------------------------------------------------------------------
614625void ClientLobby::becomingServerOwner ()
615626{
616627 SFXManager::get ()->quickSound (" wee" );
628+ // I18N: Display when a player is allow to control the server
617629 core::stringw msg = _ (" You are now the owner of server." );
618630 MessageQueue::add (MessageQueue::MT_GENERIC, msg);
619631 STKHost::get ()->setAuthorisedToControl (true );
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ class ClientLobby : public LobbyProtocol
4545 void updatePlayerList (Event* event);
4646 void handleChat (Event* event);
4747 void handleServerInfo (Event* event);
48+ void handleBadTeam ();
4849 void becomingServerOwner ();
4950
5051 void clearPlayers ();
Original file line number Diff line number Diff line change @@ -60,7 +60,8 @@ class LobbyProtocol : public Protocol
6060 LE_CHAT,
6161 LE_SERVER_OWNERSHIP,
6262 LE_KICK_HOST,
63- LE_CHANGE_TEAM
63+ LE_CHANGE_TEAM,
64+ LE_BAD_TEAM
6465 };
6566
6667 enum RejectReason : uint8_t
Original file line number Diff line number Diff line change @@ -761,6 +761,31 @@ void ServerLobby::startSelection(const Event *event)
761761 }
762762 }
763763
764+ if (NetworkConfig::get ()->hasTeamChoosing ())
765+ {
766+ int red_count = 0 ;
767+ int blue_count = 0 ;
768+ auto players = m_game_setup->getConnectedPlayers ();
769+ for (auto & player : players)
770+ {
771+ if (player->getTeam () == SOCCER_TEAM_RED)
772+ red_count++;
773+ else if (player->getTeam () == SOCCER_TEAM_BLUE)
774+ blue_count++;
775+ if (red_count != 0 && blue_count != 0 )
776+ break ;
777+ }
778+ if ((red_count == 0 || blue_count == 0 ) && players.size () != 1 )
779+ {
780+ Log::warn (" ServerLobby" , " Bad team choosing." );
781+ NetworkString* bt = getNetworkString ();
782+ bt->addUInt8 (LE_BAD_TEAM);
783+ sendMessageToPeers (bt, true /* reliable*/ );
784+ delete bt;
785+ return ;
786+ }
787+ }
788+
764789 ProtocolManager::lock ()->findAndTerminate (PROTOCOL_CONNECTION);
765790 if (NetworkConfig::get ()->isWAN ())
766791 {
You can’t perform that action at this time.
0 commit comments