Add initial support for GP and soccer info in lobby

This commit is contained in:
Benau 2018-03-31 01:19:23 +08:00
parent 6c56939f49
commit 47a86cc36f
18 changed files with 322 additions and 129 deletions

View File

@ -210,6 +210,8 @@
#include "modes/cutscene_world.hpp"
#include "modes/demo_world.hpp"
#include "modes/profile_world.hpp"
#include "network/protocols/lobby_protocol.hpp"
#include "network/game_setup.hpp"
#include "network/network_config.hpp"
#include "network/network_string.hpp"
#include "network/rewind_manager.hpp"
@ -1014,7 +1016,6 @@ int handleCmdLine()
}
} // --type
if (CommandLine::has("--login", &s))
login = s.c_str();
if (CommandLine::has("--password", &s))
@ -1053,6 +1054,12 @@ int handleCmdLine()
NetworkConfig::get()->setPassword(server_password);
}
if (CommandLine::has("--motd", &s))
{
core::stringw motd = StringUtils::xmlDecode(s);
NetworkConfig::get()->setMOTD(motd);
}
if (CommandLine::has("--server-id-file", &s))
{
NetworkConfig::get()->setServerIdFile(
@ -1084,13 +1091,12 @@ int handleCmdLine()
irr::core::stringw name = StringUtils::utf8ToWide(ip.toString());
auto server = std::make_shared<Server>(0, name,
NetworkConfig::get()->getMaxPlayers(), 0,
race_manager->getDifficulty(),
NetworkConfig::get()->getServerGameMode(race_manager->getMinorMode(),
race_manager->getMajorMode()), ip, !server_password.empty());
race_manager->getDifficulty(), 0, ip, !server_password.empty());
NetworkingLobby::getInstance()->setJoinedServer(server);
STKHost::create(server);
}
std::shared_ptr<LobbyProtocol> server_lobby;
if (CommandLine::has("--wan-server", &s))
{
// Try to use saved user token if exists
@ -1115,7 +1121,7 @@ int handleCmdLine()
NetworkConfig::get()->setIsServer(true);
NetworkConfig::get()->setIsWAN();
NetworkConfig::get()->setIsPublicServer();
STKHost::create();
server_lobby = STKHost::create();
Log::info("main", "Creating a WAN server '%s'.", s.c_str());
}
}
@ -1124,7 +1130,7 @@ int handleCmdLine()
NetworkConfig::get()->setServerName(StringUtils::xmlDecode(s));
NetworkConfig::get()->setIsServer(true);
NetworkConfig::get()->setIsLAN();
STKHost::create();
server_lobby = STKHost::create();
Log::info("main", "Creating a LAN server '%s'.", s.c_str());
}
if (CommandLine::has("--auto-connect"))
@ -1132,6 +1138,34 @@ int handleCmdLine()
NetworkConfig::get()->setAutoConnect(true);
}
if (CommandLine::has("--extra-server-info", &n))
{
if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER)
{
LobbyProtocol::get<LobbyProtocol>()->getGameSetup()
->setSoccerGoalTarget((bool)n);
NetworkConfig::get()->setServerMode(
race_manager->getMinorMode(),
RaceManager::MAJOR_MODE_SINGLE);
}
else
{
LobbyProtocol::get<LobbyProtocol>()->getGameSetup()
->setGrandPrixTrack(n);
NetworkConfig::get()->setServerMode(
race_manager->getMinorMode(),
RaceManager::MAJOR_MODE_GRAND_PRIX);
}
}
else
{
NetworkConfig::get()->setServerMode(
race_manager->getMinorMode(), RaceManager::MAJOR_MODE_SINGLE);
}
// The extra server info has to be set before server lobby started
if (server_lobby)
server_lobby->requestStart();
/** Disable detection of LAN connection when connecting via WAN. This is
* mostly a debugging feature to force using WAN connection. */
if (CommandLine::has("--disable-lan"))
@ -1902,6 +1936,7 @@ int main(int argc, char *argv[] )
if (STKHost::existHost())
STKHost::get()->shutdown();
NetworkConfig::destroy();
cleanSuperTuxKart();
#ifdef DEBUG

View File

@ -21,20 +21,12 @@
#include "config/player_manager.hpp"
#include "karts/abstract_kart.hpp"
#include "modes/world.hpp"
#include "network/network_config.hpp"
#include "network/network_player_profile.hpp"
#include "online/online_profile.hpp"
#include "race/race_manager.hpp"
#include "utils/log.hpp"
//-----------------------------------------------------------------------------
GameSetup::GameSetup()
{
m_num_local_players = 0;
m_local_master = 0;
m_laps = 0;
m_reverse = false;
} // GameSetup
//-----------------------------------------------------------------------------
/** Update and see if any player disconnects.
* \param remove_disconnected_players remove the disconnected players,
@ -61,9 +53,58 @@ void GameSetup::update(bool remove_disconnected_players)
//-----------------------------------------------------------------------------
void GameSetup::loadWorld()
{
assert(!m_track.empty());
assert(!m_tracks.empty());
// Disable accidentally unlocking of a challenge
PlayerManager::getCurrentPlayer()->setCurrentChallenge("");
race_manager->setTimeTarget(0.0f);
race_manager->setReverseTrack(m_reverse);
race_manager->startSingleRace(m_track, m_laps, false/*from_overworld*/);
if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER)
{
if (isSoccerGoalTarget())
race_manager->setMaxGoal(m_laps);
else
race_manager->setTimeTarget((float)m_laps * 60.0f);
}
else
{
race_manager->startSingleRace(m_tracks.back(), m_laps,
false/*from_overworld*/);
}
} // loadWorld
//-----------------------------------------------------------------------------
bool GameSetup::isGrandPrix() const
{
return m_extra_server_info != -1 &&
NetworkConfig::get()->getLocalGameMode().second ==
RaceManager::MAJOR_MODE_GRAND_PRIX;
} // isGrandPrix
//-----------------------------------------------------------------------------
void GameSetup::configClientAcceptConnection(NetworkString* ns)
{
assert(NetworkConfig::get()->isServer());
ns->encodeString(NetworkConfig::get()->getServerName());
ns->addUInt8(race_manager->getDifficulty())
.addUInt8((uint8_t)NetworkConfig::get()->getMaxPlayers())
.addUInt8((uint8_t)NetworkConfig::get()->getServerMode());
if (hasExtraSeverInfo())
{
if (isGrandPrix())
{
ns->addUInt8((uint8_t)2).addUInt8((uint8_t)m_tracks.size())
.addUInt8(getExtraServerInfo());
}
else
{
// Soccer mode
ns->addUInt8((uint8_t)1).addUInt8(getExtraServerInfo());
}
}
else
{
// No extra server info
ns->addUInt8((uint8_t)0);
}
ns->encodeString(NetworkConfig::get()->getMOTD());
} // configClientAcceptConnection

View File

@ -24,12 +24,14 @@
#include "network/remote_kart_info.hpp"
#include <cassert>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
class NetworkPlayerProfile;
class NetworkString;
// ============================================================================
/*! \class GameSetup
@ -47,19 +49,22 @@ private:
/** Stores the number of local players. */
int m_num_local_players;
/** The player id of the local game master, used in
* kart selection screen. */
uint8_t m_local_master;
std::string m_track;
std::vector<std::string> m_tracks;
unsigned m_laps;
bool m_reverse;
int m_extra_server_info;
public:
// ------------------------------------------------------------------------
GameSetup();
GameSetup()
{
m_num_local_players = 0;
m_extra_server_info = -1;
reset();
}
// ------------------------------------------------------------------------
~GameSetup() {}
// ------------------------------------------------------------------------
@ -69,7 +74,7 @@ public:
void update(bool remove_disconnected_players);
// ------------------------------------------------------------------------
/** Sets the number of local players. */
void setNumLocalPlayers(int n) { m_num_local_players = n; }
void setNumLocalPlayers(int n) { m_num_local_players = n; }
// ------------------------------------------------------------------------
/** Returns the nunber of local players. */
int getNumLocalPlayers() const { return m_num_local_players; }
@ -104,17 +109,51 @@ public:
return (unsigned)m_players.size();
}
// ------------------------------------------------------------------------
/** Returns the id of the local master. */
int getLocalMasterID() const { return m_local_master; }
// ------------------------------------------------------------------------
void setRace(const std::string& track, unsigned laps, bool reverse)
{
m_track = track;
m_tracks.push_back(track);
m_laps = laps;
m_reverse = reverse;
}
// ------------------------------------------------------------------------
void reset()
{
m_tracks.clear();
m_laps = 0;
m_reverse = false;
}
// ------------------------------------------------------------------------
void setGrandPrixTrack(int tracks_no) { m_extra_server_info = tracks_no; }
// ------------------------------------------------------------------------
void configClientAcceptConnection(NetworkString* ns);
// ------------------------------------------------------------------------
void loadWorld();
// ------------------------------------------------------------------------
bool isGrandPrix() const;
// ------------------------------------------------------------------------
bool hasExtraSeverInfo() const { return m_extra_server_info != -1; }
// ------------------------------------------------------------------------
uint8_t getExtraServerInfo() const
{
assert(hasExtraSeverInfo());
return (uint8_t)m_extra_server_info;
}
// ------------------------------------------------------------------------
unsigned getTotalGrandPrixTracks() const
{
assert(isGrandPrix());
return m_extra_server_info;
}
// ------------------------------------------------------------------------
void setSoccerGoalTarget(bool val) { m_extra_server_info = (int)val; }
// ------------------------------------------------------------------------
bool isSoccerGoalTarget() const
{
assert(hasExtraSeverInfo());
return (bool)m_extra_server_info;
}
// ------------------------------------------------------------------------
const std::vector<std::string>& getAllTracks() const { return m_tracks; }
};
#endif // GAME_SETUP_HPP

View File

@ -72,39 +72,38 @@ void NetworkConfig::setIsServer(bool b)
} // setIsServer
// ----------------------------------------------------------------------------
unsigned NetworkConfig::getServerGameMode(RaceManager::MinorRaceModeType minor,
RaceManager::MajorRaceModeType major)
void NetworkConfig::setServerMode(RaceManager::MinorRaceModeType minor,
RaceManager::MajorRaceModeType major)
{
if (major == RaceManager::MAJOR_MODE_GRAND_PRIX)
{
if (minor == RaceManager::MINOR_MODE_NORMAL_RACE)
return 0;
m_server_mode = 0;
else if (minor == RaceManager::MINOR_MODE_TIME_TRIAL)
return 1;
m_server_mode = 1;
else if (minor == RaceManager::MINOR_MODE_FOLLOW_LEADER)
return 2;
m_server_mode = 2;
}
else
{
if (minor == RaceManager::MINOR_MODE_NORMAL_RACE)
return 3;
m_server_mode = 3;
else if (minor == RaceManager::MINOR_MODE_TIME_TRIAL)
return 4;
m_server_mode = 4;
else if (minor == RaceManager::MINOR_MODE_FOLLOW_LEADER)
return 5;
m_server_mode = 5;
else if (minor == RaceManager::MINOR_MODE_3_STRIKES)
return 6;
m_server_mode = 6;
else if (minor == RaceManager::MINOR_MODE_SOCCER)
return 7;
m_server_mode = 7;
}
return 0;
} // getServerGameMode
} // setServerMode
// ----------------------------------------------------------------------------
std::pair<RaceManager::MinorRaceModeType, RaceManager::MajorRaceModeType>
NetworkConfig::getLocalGameMode(unsigned id)
NetworkConfig::getLocalGameMode()
{
switch(id)
switch (m_server_mode)
{
case 0:
return { RaceManager::MINOR_MODE_NORMAL_RACE,
@ -147,3 +146,25 @@ void NetworkConfig::setUserDetails(Online::XMLRequest* r,
r->addParameter("userid", m_cur_user_id);
r->addParameter("token", m_cur_user_token);
} // setUserDetails
// ----------------------------------------------------------------------------
core::stringw NetworkConfig::getModeName(unsigned id)
{
switch(id)
{
case 0:
return _("Normal Race (Grand Prix)");
case 1:
return _("Time Trial (Grand Prix)");
case 3:
return _("Normal Race");
case 4:
return _("Time Trial");
case 6:
return _("3 Strikes Battle");
case 7:
return _("Soccer");
default:
return L"";
}
} // getModeName

View File

@ -86,6 +86,8 @@ private:
/** If this is a server, the server name. */
irr::core::stringw m_server_name;
unsigned m_server_mode;
/** Used by wan server. */
uint32_t m_cur_user_id;
std::string m_cur_user_token;
@ -96,6 +98,8 @@ private:
std::vector<std::tuple<InputDevice*, PlayerProfile*,
/*is_handicap*/bool> > m_network_players;
core::stringw m_motd;
NetworkConfig();
public:
@ -249,13 +253,9 @@ public:
* requested. */
bool isAutoConnect() const { return m_auto_connect; }
// ------------------------------------------------------------------------
/** Returns the game mode id for server database. */
unsigned getServerGameMode(RaceManager::MinorRaceModeType mode,
RaceManager::MajorRaceModeType);
// ------------------------------------------------------------------------
/** Returns the minor and majar game mode from server database id. */
std::pair<RaceManager::MinorRaceModeType, RaceManager::MajorRaceModeType>
getLocalGameMode(unsigned);
getLocalGameMode();
// ------------------------------------------------------------------------
void setCurrentUserId(uint32_t id) { m_cur_user_id = id ; }
// ------------------------------------------------------------------------
@ -270,6 +270,19 @@ public:
void setServerIdFile(const std::string& id) { m_server_id_file = id; }
// ------------------------------------------------------------------------
const std::string& getServerIdFile() const { return m_server_id_file; }
// ------------------------------------------------------------------------
void setMOTD(const core::stringw& motd) { m_motd = motd; }
// ------------------------------------------------------------------------
const core::stringw& getMOTD() const { return m_motd; }
// ------------------------------------------------------------------------
void setServerMode(RaceManager::MinorRaceModeType mode,
RaceManager::MajorRaceModeType);
// ------------------------------------------------------------------------
void setServerMode(unsigned mode) { m_server_mode = mode; }
// ------------------------------------------------------------------------
unsigned getServerMode() const { return m_server_mode; }
// ------------------------------------------------------------------------
core::stringw getModeName(unsigned id);
}; // class NetworkConfig

View File

@ -135,6 +135,7 @@ bool ClientLobby::notifyEvent(Event* event)
case LE_EXIT_RESULT: exitResultScreen(event); break;
case LE_UPDATE_PLAYER_LIST: updatePlayerList(event); break;
case LE_CHAT: handleChat(event); break;
case LE_CONNECTION_ACCEPTED: connectionAccepted(event); break;
default:
return false;
break;
@ -159,7 +160,6 @@ bool ClientLobby::notifyEventAsynchronous(Event* event)
case LE_PLAYER_DISCONNECTED : disconnectedPlayer(event); break;
case LE_START_RACE: startGame(event); break;
case LE_CONNECTION_REFUSED: connectionRefused(event); break;
case LE_CONNECTION_ACCEPTED: connectionAccepted(event); break;
case LE_VOTE: displayPlayerVote(event); break;
case LE_SERVER_OWNERSHIP: becomingServerOwner(); break;
default: break;
@ -419,8 +419,8 @@ void ClientLobby::disconnectedPlayer(Event* event)
*/
void ClientLobby::connectionAccepted(Event* event)
{
// At least 4 byte should remain now
if (!checkDataSize(event, 4)) return;
// At least 10 bytes should remain now
if (!checkDataSize(event, 10)) return;
NetworkString &data = event->data();
STKPeer* peer = event->getPeer();
@ -437,6 +437,73 @@ void ClientLobby::connectionAccepted(Event* event)
uint32_t token = data.getToken();
if (!peer->isClientServerTokenSet())
peer->setClientServerToken(token);
// Add server info
core::stringw str, each_line;
uint8_t u_data;
data.decodeStringW(&str);
//I18N: In the networking lobby
each_line = _("Server name: %s", str);
NetworkingLobby::getInstance()->addMoreServerInfo(each_line);
u_data = data.getUInt8();
const core::stringw& difficulty_name =
race_manager->getDifficultyName((RaceManager::Difficulty)u_data);
race_manager->setDifficulty((RaceManager::Difficulty)u_data);
//I18N: In the networking lobby
each_line = _("Difficulty: %s", difficulty_name);
NetworkingLobby::getInstance()->addMoreServerInfo(each_line);
u_data = data.getUInt8();
//I18N: In the networking lobby
each_line = _("Max players: %d", (int)u_data);
NetworkingLobby::getInstance()->addMoreServerInfo(each_line);
u_data = data.getUInt8();
NetworkConfig::get()->setServerMode(u_data);
auto game_mode = NetworkConfig::get()->getLocalGameMode();
race_manager->setMinorMode(game_mode.first);
// We may use single mode in network even it's grand prix
//race_manager->setMajorMode(game_mode.second);
//I18N: In the networking lobby
each_line = _("Game mode: %s", NetworkConfig::get()->getModeName(u_data));
NetworkingLobby::getInstance()->addMoreServerInfo(each_line);
uint8_t extra_server_info = data.getUInt8();
switch (extra_server_info)
{
case 0:
break;
case 1:
{
u_data = data.getUInt8();
core::stringw tl = _("Time limit");
core::stringw gl = _("Goals limit");
core::stringw sgt = u_data == 0 ? tl : gl;
m_game_setup->setSoccerGoalTarget((bool)u_data);
//I18N: In the networking lobby
each_line = _("Soccer game type: %s", sgt);
NetworkingLobby::getInstance()->addMoreServerInfo(each_line);
break;
}
case 2:
{
unsigned cur_gp_track = data.getUInt8();
unsigned total_gp_track = data.getUInt8();
m_game_setup->setGrandPrixTrack(total_gp_track);
each_line = _("Grand prix progress: %d / %d", cur_gp_track,
total_gp_track);
NetworkingLobby::getInstance()->addMoreServerInfo(each_line);
break;
}
}
// MOTD
data.decodeStringW(&str);
if (!str.empty())
NetworkingLobby::getInstance()->addMoreServerInfo(str);
m_state = CONNECTED;
} // connectionAccepted
@ -537,7 +604,7 @@ void ClientLobby::connectionRefused(Event* event)
//-----------------------------------------------------------------------------
/*! \brief Called when the server broadcasts to start the race to all clients.
* \param event : Event providing the information (no additional information
* \param event : Event providing the information (no additional informati
* in this case).
*/
void ClientLobby::startGame(Event* event)

View File

@ -64,7 +64,7 @@ public:
virtual void setup() OVERRIDE;
virtual void update(int ticks) OVERRIDE;
virtual bool waitingForPlayers() const OVERRIDE
{ return m_state == LINKED; }
{ return m_state == CONNECTED; }
virtual void asynchronousUpdate() OVERRIDE {}
};

View File

@ -36,14 +36,13 @@ std::weak_ptr<LobbyProtocol> LobbyProtocol::m_lobby;
LobbyProtocol::LobbyProtocol(CallbackObject* callback_object)
: Protocol(PROTOCOL_LOBBY_ROOM, callback_object)
{
m_game_setup = NULL;
m_game_setup = new GameSetup();
} // LobbyProtocol
// ----------------------------------------------------------------------------
LobbyProtocol::~LobbyProtocol()
{
if (m_game_setup)
delete m_game_setup;
delete m_game_setup;
} // ~LobbyProtocol
//-----------------------------------------------------------------------------
@ -140,7 +139,5 @@ void LobbyProtocol::configRemoteKart(
*/
void LobbyProtocol::setup()
{
if (m_game_setup)
delete m_game_setup;
m_game_setup = new GameSetup();
m_game_setup->reset();
} // setupNewGame

View File

@ -476,9 +476,7 @@ void ServerLobby::registerServer()
request->addParameter("max_players",
NetworkConfig::get()->getMaxPlayers());
request->addParameter("difficulty", race_manager->getDifficulty());
request->addParameter("game_mode",
NetworkConfig::get()->getServerGameMode(race_manager->getMinorMode(),
race_manager->getMajorMode()));
request->addParameter("game_mode", NetworkConfig::get()->getServerMode());
request->addParameter("password",
(unsigned)(!NetworkConfig::get()->getPassword().empty()));
request->addParameter("version",
@ -927,9 +925,11 @@ void ServerLobby::connectionRequested(Event* event)
peer->setClientServerToken(token);
}
// send a message to the one that asked to connect
NetworkString *message_ack = getNetworkString(4);
NetworkString* message_ack = getNetworkString(4);
message_ack->setSynchronous(true);
// connection success -- return the host id of peer
message_ack->addUInt8(LE_CONNECTION_ACCEPTED).addUInt32(peer->getHostId());
m_game_setup->configClientAcceptConnection(message_ack);
peer->sendPacket(message_ack);
delete message_ack;

View File

@ -39,10 +39,9 @@ Server::Server(const XMLNode& xml)
m_current_players = 0;
m_max_players = 0;
m_distance = 0.0f;
m_server_mode = 0;
xml.get("game_mode", &m_server_mode);
unsigned server_data = 0;
xml.get("game_mode", &server_data);
m_minor_mode = NetworkConfig::get()->getLocalGameMode(server_data).first;
m_major_mode = NetworkConfig::get()->getLocalGameMode(server_data).second;
xml.get("difficulty", &server_data);
m_difficulty = (RaceManager::Difficulty)server_data;
@ -121,8 +120,7 @@ Server::Server(unsigned server_id, const core::stringw &name, int max_players,
// In case of LAN server, public and private port are the same.
m_private_port = m_address.getPort();
m_difficulty = (RaceManager::Difficulty)difficulty;
m_minor_mode = NetworkConfig::get()->getLocalGameMode(server_mode).first;
m_major_mode = NetworkConfig::get()->getLocalGameMode(server_mode).second;
m_server_mode = server_mode;
m_password_protected = password_protected;
m_distance = 0.0f;
} // server(server_id, ...)

View File

@ -68,9 +68,7 @@ protected:
* connection using the private port with a broadcast is possible. */
uint16_t m_private_port;
RaceManager::MinorRaceModeType m_minor_mode;
RaceManager::MajorRaceModeType m_major_mode;
unsigned m_server_mode;
RaceManager::Difficulty m_difficulty;
@ -115,11 +113,7 @@ public:
/** Returns the number of currently connected players. */
const int getCurrentPlayers() const { return m_current_players; }
// ------------------------------------------------------------------------
RaceManager::MinorRaceModeType getRaceMinorMode() const
{ return m_minor_mode; }
// ------------------------------------------------------------------------
RaceManager::MajorRaceModeType getRaceMajorMode() const
{ return m_major_mode; }
unsigned getServerMode() const { return m_server_mode; }
// ------------------------------------------------------------------------
RaceManager::Difficulty getDifficulty() const { return m_difficulty; }
// ------------------------------------------------------------------------

View File

@ -67,14 +67,15 @@
STKHost *STKHost::m_stk_host = NULL;
bool STKHost::m_enable_console = false;
void STKHost::create(std::shared_ptr<Server> server, SeparateProcess* p)
std::shared_ptr<LobbyProtocol> STKHost::create(std::shared_ptr<Server> server,
SeparateProcess* p)
{
assert(m_stk_host == NULL);
std::shared_ptr<LobbyProtocol> lp;
if (NetworkConfig::get()->isServer())
{
std::shared_ptr<ServerLobby> sl = LobbyProtocol::create<ServerLobby>();
lp = LobbyProtocol::create<ServerLobby>();
m_stk_host = new STKHost(NetworkConfig::get()->getServerName());
sl->requestStart();
}
else
{
@ -86,6 +87,7 @@ void STKHost::create(std::shared_ptr<Server> server, SeparateProcess* p)
delete m_stk_host;
m_stk_host = NULL;
}
return lp;
} // create
// ============================================================================
@ -941,9 +943,7 @@ void STKHost::handleDirectSocketRequest(Network* direct_socket,
s.addUInt8((uint8_t)sl->getGameSetup()->getPlayerCount());
s.addUInt16(m_private_port);
s.addUInt8((uint8_t)race_manager->getDifficulty());
s.addUInt8((uint8_t)
NetworkConfig::get()->getServerGameMode(race_manager->getMinorMode(),
race_manager->getMajorMode()));
s.addUInt8((uint8_t)NetworkConfig::get()->getServerMode());
s.addUInt8(!NetworkConfig::get()->getPassword().empty());
direct_socket->sendRawPacket(s, sender);
} // if message is server-requested

View File

@ -43,6 +43,7 @@
#include <tuple>
class GameSetup;
class LobbyProtocol;
class NetworkPlayerProfile;
class Server;
class ServerLobby;
@ -154,9 +155,9 @@ public:
/** Creates the STKHost. It takes all confifguration parameters from
* NetworkConfig. This STKHost can either be a client or a server.
*/
static void create(std::shared_ptr<Server> server = nullptr,
SeparateProcess* p = NULL);
static std::shared_ptr<LobbyProtocol>
create(std::shared_ptr<Server> server = nullptr,
SeparateProcess* p = NULL);
// ------------------------------------------------------------------------
/** Returns the instance of STKHost. */
static STKHost *get()

View File

@ -250,8 +250,7 @@ void CreateServerScreen::createServer()
auto server = std::make_shared<Server>(0/*server_id*/, name,
max_players, /*current_player*/0, (RaceManager::Difficulty)
difficulty_widget->getSelection(PLAYER_ID_GAME_MASTER),
NetworkConfig::get()->getServerGameMode(race_manager->getMinorMode(),
race_manager->getMajorMode()), server_address, !password.empty());
0, server_address, !password.empty());
#undef USE_GRAPHICS_SERVER
#ifdef USE_GRAPHICS_SERVER
@ -276,7 +275,9 @@ void CreateServerScreen::createServer()
race_manager->setMinorMode(RaceManager::MINOR_MODE_NORMAL_RACE);
race_manager->setReverseTrack(false);
STKHost::create();
auto sl = STKHost::create();
assert(sl);
sl->requestStart();
#else
NetworkConfig::get()->setIsServer(false);
@ -311,6 +312,22 @@ void CreateServerScreen::createServer()
" --server-id-file=" << server_id_file <<
" --log=1 --no-console-log";
if (m_more_options_spinner->isVisible())
{
int esi = m_more_options_spinner->getValue();
if (gamemode_widget->getSelection(PLAYER_ID_GAME_MASTER)
!= 3/*is soccer*/)
{
// Grand prix track count
if (esi > 0)
server_cfg << " --extra-server-info=" << esi;
}
else
{
server_cfg << " --extra-server-info=" << esi;
}
}
SeparateProcess* sp =
new SeparateProcess(SeparateProcess::getCurrentExecutableLocation(),
server_cfg.str() + password);

View File

@ -60,7 +60,7 @@ ServerInfoDialog::ServerInfoDialog(std::shared_ptr<Server> server)
GUIEngine::LabelWidget *lbldifficulty = getWidget<LabelWidget>("server_difficulty");
lbldifficulty->setText(difficulty, false);
core::stringw mode = RaceManager::getNameOf(server->getRaceMinorMode());
core::stringw mode = NetworkConfig::get()->getModeName(server->getServerMode());
GUIEngine::LabelWidget *gamemode = getWidget<LabelWidget>("server_game_mode");
gamemode->setText(mode, false);

View File

@ -152,44 +152,6 @@ void NetworkingLobby::init()
} // init
// ----------------------------------------------------------------------------
void NetworkingLobby::setJoinedServer(std::shared_ptr<Server> server)
{
if (server == m_joined_server)
return;
m_joined_server = server;
m_server_info.clear();
if (!m_joined_server)
return;
core::stringw each_line;
//I18N: In the networking lobby
each_line = _("Server name: %s", m_joined_server->getName());
m_server_info.push_back(each_line);
const core::stringw& difficulty_name =
race_manager->getDifficultyName(m_joined_server->getDifficulty());
//I18N: In the networking lobby
each_line = _("Difficulty: %s", difficulty_name);
m_server_info.push_back(each_line);
//I18N: In the networking lobby
each_line = _("Max players: %d", m_joined_server->getMaxPlayers());
m_server_info.push_back(each_line);
//I18N: In the networking lobby
core::stringw mode = RaceManager::getNameOf(m_joined_server->getRaceMinorMode());
each_line = _("Game mode: %s", mode);
race_manager->setMinorMode(m_joined_server->getRaceMinorMode());
race_manager->setMajorMode(m_joined_server->getRaceMajorMode());
race_manager->setDifficulty(m_joined_server->getDifficulty());
m_server_info.push_back(each_line);
} // setJoinedServer
// ----------------------------------------------------------------------------
void NetworkingLobby::addMoreServerInfo(core::stringw info)
{

View File

@ -115,7 +115,14 @@ public:
void finishAddingPlayers();
void addMoreServerInfo(core::stringw info);
void setJoinedServer(std::shared_ptr<Server> server);
void setJoinedServer(std::shared_ptr<Server> server)
{
if (server == m_joined_server)
return;
m_joined_server = server;
m_server_info.clear();
}
void updatePlayers(const std::vector<std::tuple<uint32_t/*host id*/,
uint32_t/*online id*/, core::stringw/*player name*/,
int/*icon id*/> >& p);

View File

@ -149,7 +149,7 @@ void ServerSelection::loadList(unsigned sort_case)
return c->getDifficulty() > d->getDifficulty();
break;
case 3:
return c->getRaceMinorMode() > d->getRaceMinorMode();
return c->getServerMode() > d->getServerMode();
break;
case 4:
return c->getServerOwnerName() > d->getServerOwnerName();
@ -175,7 +175,8 @@ void ServerSelection::loadList(unsigned sort_case)
race_manager->getDifficultyName(server->getDifficulty());
row.push_back(GUIEngine::ListWidget::ListCell(difficulty, -1, 1, true));
core::stringw mode = RaceManager::getNameOf(server->getRaceMinorMode());
core::stringw mode =
NetworkConfig::get()->getModeName(server->getServerMode());
row.push_back(GUIEngine::ListWidget::ListCell(mode, -1, 2, true));
if (NetworkConfig::get()->isWAN())