Skip to content

Commit

Permalink
Add limited game auto-selection to dedicated server
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Jan 19, 2025
1 parent a262be6 commit 3cb07d5
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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");

// 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;
} 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");

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);
Expand All @@ -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;
Expand Down

0 comments on commit 3cb07d5

Please sign in to comment.