Update server for new xml code
And initial work for starting a complete stk server
This commit is contained in:
parent
6c18664967
commit
d8007c4518
@ -15,9 +15,9 @@
|
||||
|
||||
<div width="100%" height="fit" layout="horizontal-row" >
|
||||
<label proportion="1" text_align="left" I18N="In the server creation screen" text="Max. number of players"/>
|
||||
<gauge id="max_players" proportion="1" min_value="2" max_value="12"/>
|
||||
<gauge id="max_players" proportion="1" min_value="2"/>
|
||||
</div>
|
||||
|
||||
|
||||
<spacer height="20" width="20"/>
|
||||
|
||||
<div width="100%" height="fit" layout="horizontal-row" >
|
||||
|
@ -205,7 +205,7 @@ public:
|
||||
|
||||
irr::core::stringc toString() const;
|
||||
void revertToDefaults() { m_value = m_default_value; }
|
||||
|
||||
int getDefaultValue() { return m_default_value; }
|
||||
operator int() const { return m_value; }
|
||||
int& operator++(int dummy) { m_value++; return m_value; }
|
||||
int& operator=(const int& v) { m_value = v; return m_value; }
|
||||
@ -713,7 +713,7 @@ namespace UserConfigParams
|
||||
// ---- Networking
|
||||
|
||||
PARAM_PREFIX IntUserConfigParam m_server_max_players
|
||||
PARAM_DEFAULT( IntUserConfigParam(16, "server_max_players",
|
||||
PARAM_DEFAULT( IntUserConfigParam(12, "server_max_players",
|
||||
"Maximum number of players on the server.") );
|
||||
|
||||
PARAM_PREFIX StringListUserConfigParam m_stun_servers
|
||||
|
111
src/main.cpp
111
src/main.cpp
@ -986,10 +986,67 @@ int handleCmdLine()
|
||||
UserConfigParams::m_check_debug=true;
|
||||
}
|
||||
|
||||
if (CommandLine::has( "--difficulty", &s))
|
||||
{
|
||||
int n = atoi(s.c_str());
|
||||
if(n<0 || n>RaceManager::DIFFICULTY_LAST)
|
||||
Log::warn("main", "Invalid difficulty '%s' - ignored.\n",
|
||||
s.c_str());
|
||||
else
|
||||
race_manager->setDifficulty(RaceManager::Difficulty(n));
|
||||
} // --mode
|
||||
|
||||
if (CommandLine::has("--type", &n))
|
||||
{
|
||||
switch (n)
|
||||
{
|
||||
case 0: race_manager->setMinorMode(RaceManager::MINOR_MODE_NORMAL_RACE);
|
||||
break;
|
||||
case 1: race_manager->setMinorMode(RaceManager::MINOR_MODE_TIME_TRIAL);
|
||||
break;
|
||||
case 2: race_manager->setMinorMode(RaceManager::MINOR_MODE_FOLLOW_LEADER);
|
||||
break;
|
||||
case 3: race_manager->setMinorMode(RaceManager::MINOR_MODE_3_STRIKES);
|
||||
break;
|
||||
case 4: race_manager->setMinorMode(RaceManager::MINOR_MODE_SOCCER);
|
||||
break;
|
||||
default:
|
||||
Log::warn("main", "Invalid race type '%d' - ignored.", n);
|
||||
}
|
||||
} // --type
|
||||
|
||||
|
||||
if(CommandLine::has("--login", &s) )
|
||||
{
|
||||
login = s.c_str();
|
||||
try_login = true;
|
||||
} // --login
|
||||
|
||||
if(CommandLine::has("--password", &s))
|
||||
password = s.c_str();
|
||||
if (try_login)
|
||||
{
|
||||
irr::core::stringw s;
|
||||
Online::XMLRequest* request =
|
||||
PlayerManager::requestSignIn(login, password);
|
||||
|
||||
if (request->isSuccess())
|
||||
{
|
||||
Log::info("Main", "Logged in from command-line.");
|
||||
}
|
||||
}
|
||||
|
||||
// Networking command lines
|
||||
if(CommandLine::has("--start-console"))
|
||||
STKHost::m_enable_console = true;
|
||||
|
||||
if (CommandLine::has("--server-password", &s))
|
||||
{
|
||||
NetworkConfig::get()->setPassword(s);
|
||||
}
|
||||
|
||||
if(CommandLine::has("--max-players", &n))
|
||||
UserConfigParams::m_server_max_players=n;
|
||||
NetworkConfig::get()->
|
||||
setMaxPlayers(UserConfigParams::m_server_max_players);
|
||||
if (CommandLine::has("--port", &n))
|
||||
@ -1051,25 +1108,10 @@ int handleCmdLine()
|
||||
STKHost::create();
|
||||
Log::info("main", "Creating a LAN server '%s'.", s.c_str());
|
||||
}
|
||||
if (CommandLine::has("--server-password", &s))
|
||||
{
|
||||
NetworkConfig::get()->setPassword(s);
|
||||
}
|
||||
if (CommandLine::has("--auto-connect"))
|
||||
{
|
||||
NetworkConfig::get()->setAutoConnect(true);
|
||||
}
|
||||
if(CommandLine::has("--max-players", &n))
|
||||
UserConfigParams::m_server_max_players=n;
|
||||
|
||||
if(CommandLine::has("--login", &s) )
|
||||
{
|
||||
login = s.c_str();
|
||||
try_login = true;
|
||||
} // --login
|
||||
|
||||
if(CommandLine::has("--password", &s))
|
||||
password = s.c_str();
|
||||
|
||||
/** Disable detection of LAN connection when connecting via WAN. This is
|
||||
* mostly a debugging feature to force using WAN connection. */
|
||||
@ -1128,31 +1170,6 @@ int handleCmdLine()
|
||||
race_manager->setNumKarts((int)l.size()+1);
|
||||
} // --ai
|
||||
|
||||
if(CommandLine::has( "--mode", &s) || CommandLine::has( "--difficulty", &s))
|
||||
{
|
||||
int n = atoi(s.c_str());
|
||||
if(n<0 || n>RaceManager::DIFFICULTY_LAST)
|
||||
Log::warn("main", "Invalid difficulty '%s' - ignored.\n",
|
||||
s.c_str());
|
||||
else
|
||||
race_manager->setDifficulty(RaceManager::Difficulty(n));
|
||||
} // --mode
|
||||
|
||||
if(CommandLine::has("--type", &n))
|
||||
{
|
||||
switch (n)
|
||||
{
|
||||
case 0: race_manager->setMinorMode(RaceManager::MINOR_MODE_NORMAL_RACE);
|
||||
break;
|
||||
case 1: race_manager->setMinorMode(RaceManager::MINOR_MODE_TIME_TRIAL);
|
||||
break;
|
||||
case 2: race_manager->setMinorMode(RaceManager::MINOR_MODE_FOLLOW_LEADER);
|
||||
break;
|
||||
default:
|
||||
Log::warn("main", "Invalid race type '%d' - ignored.", n);
|
||||
}
|
||||
} // --type
|
||||
|
||||
if(CommandLine::has("--track", &s) || CommandLine::has("-t", &s))
|
||||
{
|
||||
race_manager->setTrack(s);
|
||||
@ -1341,24 +1358,12 @@ int handleCmdLine()
|
||||
|
||||
CommandLine::reportInvalidParameters();
|
||||
|
||||
if(ProfileWorld::isProfileMode())
|
||||
if (ProfileWorld::isProfileMode() || ProfileWorld::isNoGraphics())
|
||||
{
|
||||
UserConfigParams::m_sfx = false; // Disable sound effects
|
||||
UserConfigParams::m_music = false;// and music when profiling
|
||||
}
|
||||
|
||||
if (try_login)
|
||||
{
|
||||
irr::core::stringw s;
|
||||
Online::XMLRequest* request =
|
||||
PlayerManager::requestSignIn(login, password);
|
||||
|
||||
if (request->isSuccess())
|
||||
{
|
||||
Log::info("Main", "Logged in from command-line.");
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
} // handleCmdLine
|
||||
|
||||
|
@ -48,7 +48,7 @@ NetworkConfig::NetworkConfig()
|
||||
m_client_port = 2759;
|
||||
} // NetworkConfig
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Sets if this instance is a server or client. It also assigns the
|
||||
* private port depending if this is a server or client.
|
||||
*/
|
||||
@ -56,3 +56,53 @@ void NetworkConfig::setIsServer(bool b)
|
||||
{
|
||||
m_is_server = b;
|
||||
} // setIsServer
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
unsigned NetworkConfig::getServerGameMode(RaceManager::MinorRaceModeType mode,
|
||||
bool gp)
|
||||
{
|
||||
if (gp)
|
||||
{
|
||||
if (mode == RaceManager::MINOR_MODE_NORMAL_RACE)
|
||||
return 0;
|
||||
else if (mode == RaceManager::MINOR_MODE_TIME_TRIAL)
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mode == RaceManager::MINOR_MODE_NORMAL_RACE)
|
||||
return 2;
|
||||
else if (mode == RaceManager::MINOR_MODE_TIME_TRIAL)
|
||||
return 3;
|
||||
else if (mode == RaceManager::MINOR_MODE_3_STRIKES)
|
||||
return 4;
|
||||
else if (mode == RaceManager::MINOR_MODE_SOCCER)
|
||||
return 5;
|
||||
}
|
||||
return 0;
|
||||
} // getServerGameMode
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
std::pair<RaceManager::MinorRaceModeType, bool>
|
||||
NetworkConfig::getLocalGameMode(unsigned id)
|
||||
{
|
||||
switch(id)
|
||||
{
|
||||
case 0:
|
||||
return { RaceManager::MINOR_MODE_NORMAL_RACE, true };
|
||||
case 1:
|
||||
return { RaceManager::MINOR_MODE_TIME_TRIAL, true };
|
||||
case 2:
|
||||
return { RaceManager::MINOR_MODE_NORMAL_RACE, false };
|
||||
case 3:
|
||||
return { RaceManager::MINOR_MODE_TIME_TRIAL, false };
|
||||
case 4:
|
||||
return { RaceManager::MINOR_MODE_3_STRIKES, false };
|
||||
case 5:
|
||||
return { RaceManager::MINOR_MODE_SOCCER, false };
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return { RaceManager::MINOR_MODE_NORMAL_RACE, false };
|
||||
|
||||
} // getLocalGameMode
|
||||
|
@ -23,6 +23,7 @@
|
||||
#define HEADER_NETWORK_CONFIG
|
||||
|
||||
#include "network/transport_address.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "utils/synchronised.hpp"
|
||||
|
||||
#include "irrString.h"
|
||||
@ -154,35 +155,41 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the maximum number of players for this server. */
|
||||
void setMaxPlayers(int n) { m_max_players = n; }
|
||||
// --------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the maximum number of players for this server. */
|
||||
int getMaxPlayers() const { return m_max_players; }
|
||||
// --------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns if this instance is a server. */
|
||||
bool isServer() const { return m_is_server; }
|
||||
// --------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns if this instance is a client. */
|
||||
bool isClient() const { return !m_is_server; }
|
||||
// --------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the name of this server. */
|
||||
void setServerName(const irr::core::stringw &name)
|
||||
{
|
||||
m_server_name = name;
|
||||
} // setServerName
|
||||
// --------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the server name. */
|
||||
const irr::core::stringw& getServerName() const
|
||||
{
|
||||
assert(isServer());
|
||||
return m_server_name;
|
||||
} // getServerName
|
||||
// --------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets if a client should immediately connect to the first server. */
|
||||
void setAutoConnect(bool b) { m_auto_connect = b; }
|
||||
// --------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns if an immediate connection to the first server was
|
||||
* requested. */
|
||||
bool isAutoConnect() const { return m_auto_connect; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the game mode id for server database. */
|
||||
unsigned getServerGameMode(RaceManager::MinorRaceModeType mode, bool gp);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the game mode id and if grandprix from server database id. */
|
||||
std::pair<RaceManager::MinorRaceModeType, bool> getLocalGameMode(unsigned);
|
||||
|
||||
}; // class NetworkConfig
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "network/stk_peer.hpp"
|
||||
#include "online/online_profile.hpp"
|
||||
#include "online/request_manager.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "states_screens/networking_lobby.hpp"
|
||||
#include "states_screens/race_result_gui.hpp"
|
||||
#include "states_screens/waiting_for_others.hpp"
|
||||
@ -355,10 +356,14 @@ void ServerLobby::registerServer()
|
||||
request->addParameter("private_port",
|
||||
STKHost::get()->getPrivatePort() );
|
||||
request->addParameter("name", NetworkConfig::get()->getServerName() );
|
||||
request->addParameter("max_players",
|
||||
UserConfigParams::m_server_max_players );
|
||||
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() == RaceManager::MAJOR_MODE_GRAND_PRIX));
|
||||
Log::info("ServerLobby", "Public server addr %s", addr.toString().c_str());
|
||||
|
||||
|
||||
request->executeNow();
|
||||
|
||||
const XMLNode * result = request->getXMLData();
|
||||
@ -520,6 +525,7 @@ void ServerLobby::checkIncomingConnectionRequests()
|
||||
const TransportAddress &addr = STKHost::get()->getPublicAddress();
|
||||
request->addParameter("address", addr.getIP() );
|
||||
request->addParameter("port", addr.getPort());
|
||||
request->addParameter("current_players", STKHost::get()->getPeerCount());
|
||||
|
||||
request->executeNow();
|
||||
assert(request->isDone());
|
||||
|
@ -16,7 +16,7 @@
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "network/server.hpp"
|
||||
|
||||
#include "network/network_config.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
@ -38,8 +38,11 @@ Server::Server(const XMLNode & xml, bool is_lan)
|
||||
m_current_players = 0;
|
||||
m_max_players = 0;
|
||||
m_is_lan = is_lan;
|
||||
m_minor_mode = RaceManager::MINOR_MODE_NORMAL_RACE;
|
||||
m_difficulty = RaceManager::DIFFICULTY_HARD;
|
||||
unsigned server_data = 0;
|
||||
xml.get("game_mode", &server_data);
|
||||
m_minor_mode = NetworkConfig::get()->getLocalGameMode(server_data).first;
|
||||
xml.get("difficulty", &server_data);
|
||||
m_difficulty = (RaceManager::Difficulty)server_data;
|
||||
|
||||
xml.get("name", &m_lower_case_name);
|
||||
m_name = StringUtils::xmlDecode(m_lower_case_name);
|
||||
|
@ -44,9 +44,12 @@ public:
|
||||
/** Set the sort order used in the comparison function. */
|
||||
enum SortOrder
|
||||
{
|
||||
SO_SCORE = 1, // Sorted on satisfaction score
|
||||
SO_NAME = 2, // Sorted alphabetically by name
|
||||
SO_PLAYERS = 4
|
||||
SO_NAME = 0, // Sorted alphabetically by name
|
||||
SO_PLAYERS = 1,
|
||||
SO_DIFFICULTY = 2,
|
||||
SO_GAME_MODE = 3,
|
||||
SO_SCORE = 4 // Sorted on satisfaction score (unused)
|
||||
|
||||
};
|
||||
|
||||
protected:
|
||||
@ -142,6 +145,12 @@ public:
|
||||
case SO_PLAYERS:
|
||||
return m_current_players < server.m_current_players;
|
||||
break;
|
||||
case SO_DIFFICULTY:
|
||||
return m_difficulty < server.m_difficulty;
|
||||
break;
|
||||
case SO_GAME_MODE:
|
||||
return m_minor_mode < server.m_minor_mode;
|
||||
break;
|
||||
} // switch
|
||||
|
||||
return true;
|
||||
|
@ -227,7 +227,7 @@ public:
|
||||
#undef BATTLE_ARENA
|
||||
|
||||
/** Game difficulty. */
|
||||
enum Difficulty { DIFFICULTY_EASY,
|
||||
enum Difficulty { DIFFICULTY_EASY = 0,
|
||||
DIFFICULTY_FIRST = DIFFICULTY_EASY,
|
||||
DIFFICULTY_MEDIUM,
|
||||
DIFFICULTY_HARD,
|
||||
|
@ -59,7 +59,9 @@ void CreateServerScreen::loadedFromFile()
|
||||
|
||||
m_max_players_widget = getWidget<SpinnerWidget>("max_players");
|
||||
assert(m_max_players_widget != NULL);
|
||||
m_max_players_widget->setValue(8);
|
||||
m_max_players_widget
|
||||
->setMax(UserConfigParams::m_server_max_players.getDefaultValue());
|
||||
m_max_players_widget->setValue(UserConfigParams::m_server_max_players);
|
||||
|
||||
m_info_widget = getWidget<LabelWidget>("info");
|
||||
assert(m_info_widget != NULL);
|
||||
@ -162,15 +164,10 @@ void CreateServerScreen::createServer()
|
||||
SFXManager::get()->quickSound("anvil");
|
||||
return;
|
||||
}
|
||||
else if (max_players < 2 || max_players > 12)
|
||||
{
|
||||
m_info_widget->setText(
|
||||
_("The maxinum number of players has to be between 2 and 12."),
|
||||
false);
|
||||
SFXManager::get()->quickSound("anvil");
|
||||
return;
|
||||
}
|
||||
assert(max_players > 1 &&
|
||||
max_players <= UserConfigParams::m_server_max_players.getDefaultValue());
|
||||
|
||||
UserConfigParams::m_server_max_players = max_players;
|
||||
// In case of a LAN game, we can create the new server object now
|
||||
if (NetworkConfig::get()->isLAN())
|
||||
{
|
||||
|
@ -162,6 +162,8 @@ void ServerSelection::onColumnClicked(int column_id)
|
||||
{
|
||||
case 0: Server::setSortOrder(Server::SO_NAME); break;
|
||||
case 1: Server::setSortOrder(Server::SO_PLAYERS); break;
|
||||
case 2: Server::setSortOrder(Server::SO_DIFFICULTY); break;
|
||||
case 3: Server::setSortOrder(Server::SO_GAME_MODE); break;
|
||||
default: assert(0); break;
|
||||
} // switch
|
||||
/** \brief Toggle the sort order after column click **/
|
||||
|
Loading…
Reference in New Issue
Block a user