mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00: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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
game_configure_subgame(game_params, cmd_args);
|
return game_configure_subgame(game_params, cmd_args);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void game_configure_port(GameParams *game_params, const Settings &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()) {
|
if (game_params->game_spec.isValid()) {
|
||||||
gamespec = game_params->game_spec;
|
gamespec = game_params->game_spec;
|
||||||
infostream << "Using commanded gameid [" << gamespec.id << "]" << std::endl;
|
infostream << "Using commanded gameid [" << gamespec.id << "]" << std::endl;
|
||||||
} else {
|
} else if (game_params->is_dedicated_server) {
|
||||||
if (game_params->is_dedicated_server) {
|
auto games = getAvailableGameIds();
|
||||||
std::string contentdb_url = g_settings->get("contentdb_url");
|
// 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,
|
errorstream << "To run a " PROJECT_NAME_C " server, you need to select a game using the '--gameid' argument." << std::endl;
|
||||||
// print a friendly error pointing to ContentDB.
|
if (games.empty())
|
||||||
errorstream << "To run a " PROJECT_NAME_C " server, you need to select a game using the '--gameid' argument." << std::endl
|
errorstream << "Check out " << url << " for a selection of games to pick from and download." << std::endl;
|
||||||
<< "Check out " << contentdb_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
|
} else { // World exists
|
||||||
std::string world_gameid = getWorldGameId(game_params->world_path, false);
|
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 (!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."
|
errorstream << "Game [" << gamespec.id << "] could not be found."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue