mirror of
https://github.com/minetest/minetest.git
synced 2025-03-06 20:48:40 +01:00
Add limited game auto-selection to dedicated server
This commit is contained in:
parent
a262be6a47
commit
3cb07d5fb6
1 changed files with 20 additions and 12 deletions
32
src/main.cpp
32
src/main.cpp
|
@ -830,9 +830,7 @@ static bool game_configure(GameParams *game_params, const Settings &cmd_args)
|
|||
return false;
|
||||
}
|
||||
|
||||
game_configure_subgame(game_params, cmd_args);
|
||||
|
||||
return true;
|
||||
return game_configure_subgame(game_params, cmd_args);
|
||||
}
|
||||
|
||||
static void game_configure_port(GameParams *game_params, const Settings &cmd_args)
|
||||
|
@ -1014,17 +1012,25 @@ static bool determine_subgame(GameParams *game_params)
|
|||
if (game_params->game_spec.isValid()) {
|
||||
gamespec = game_params->game_spec;
|
||||
infostream << "Using commanded gameid [" << gamespec.id << "]" << std::endl;
|
||||
} else {
|
||||
if (game_params->is_dedicated_server) {
|
||||
std::string contentdb_url = g_settings->get("contentdb_url");
|
||||
} else if (game_params->is_dedicated_server) {
|
||||
auto games = getAvailableGameIds();
|
||||
// If there's exactly one obvious choice then do the right thing
|
||||
if (games.size() > 1)
|
||||
games.erase("devtest");
|
||||
if (games.size() == 1) {
|
||||
gamespec = findSubgame(*games.begin());
|
||||
infostream << "Automatically selecting gameid [" << gamespec.id << "]" << std::endl;
|
||||
} else {
|
||||
// Else, force the user to choose
|
||||
auto &url = g_settings->get("contentdb_url");
|
||||
|
||||
// If this is a dedicated server and no gamespec has been specified,
|
||||
// print a friendly error pointing to ContentDB.
|
||||
errorstream << "To run a " PROJECT_NAME_C " server, you need to select a game using the '--gameid' argument." << std::endl
|
||||
<< "Check out " << contentdb_url << " for a selection of games to pick from and download." << std::endl;
|
||||
errorstream << "To run a " PROJECT_NAME_C " server, you need to select a game using the '--gameid' argument." << std::endl;
|
||||
if (games.empty())
|
||||
errorstream << "Check out " << url << " for a selection of games to pick from and download." << std::endl;
|
||||
else
|
||||
errorstream << "Use '--gameid list' to print a list of all installed games." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} else { // World exists
|
||||
std::string world_gameid = getWorldGameId(game_params->world_path, false);
|
||||
|
@ -1045,6 +1051,8 @@ static bool determine_subgame(GameParams *game_params)
|
|||
}
|
||||
|
||||
if (!gamespec.isValid()) {
|
||||
if (!game_params->is_dedicated_server)
|
||||
return true; // not an error, this would prevent the main menu from running
|
||||
errorstream << "Game [" << gamespec.id << "] could not be found."
|
||||
<< std::endl;
|
||||
return false;
|
||||
|
|
Loading…
Add table
Reference in a new issue