Server list cleanup

This removes the hacky server_dedicated pseudo-setting.
This commit is contained in:
ShadowNinja 2015-10-15 13:04:15 -04:00 committed by SmallJoker
parent 2cc518dcaf
commit b8484ef24e
6 changed files with 56 additions and 50 deletions

@ -1899,7 +1899,7 @@ bool Game::createSingleplayerServer(const std::string map_dir,
} }
server = new Server(map_dir, gamespec, simple_singleplayer_mode, server = new Server(map_dir, gamespec, simple_singleplayer_mode,
bind_addr.isIPv6()); bind_addr.isIPv6(), false);
server->start(bind_addr); server->start(bind_addr);

@ -213,10 +213,6 @@ int main(int argc, char *argv[])
infostream << "Using commanded world path [" infostream << "Using commanded world path ["
<< game_params.world_path << "]" << std::endl; << game_params.world_path << "]" << std::endl;
//Run dedicated server if asked to or no other option
g_settings->set("server_dedicated",
game_params.is_dedicated_server ? "true" : "false");
if (game_params.is_dedicated_server) if (game_params.is_dedicated_server)
return run_dedicated_server(game_params, cmd_args) ? 0 : 1; return run_dedicated_server(game_params, cmd_args) ? 0 : 1;
@ -852,8 +848,8 @@ static bool run_dedicated_server(const GameParams &game_params, const Settings &
try { try {
// Create server // Create server
Server server(game_params.world_path, Server server(game_params.world_path, game_params.game_spec,
game_params.game_spec, false, bind_addr.isIPv6(), &iface); false, bind_addr.isIPv6(), true, &iface);
g_term_console.setup(&iface, &kill, admin_nick); g_term_console.setup(&iface, &kill, admin_nick);
@ -887,7 +883,7 @@ static bool run_dedicated_server(const GameParams &game_params, const Settings &
try { try {
// Create server // Create server
Server server(game_params.world_path, game_params.game_spec, false, Server server(game_params.world_path, game_params.game_spec, false,
bind_addr.isIPv6()); bind_addr.isIPv6(), true);
server.start(bind_addr); server.start(bind_addr);
// Run server // Run server

@ -148,11 +148,13 @@ Server::Server(
const SubgameSpec &gamespec, const SubgameSpec &gamespec,
bool simple_singleplayer_mode, bool simple_singleplayer_mode,
bool ipv6, bool ipv6,
bool dedicated,
ChatInterface *iface ChatInterface *iface
): ):
m_path_world(path_world), m_path_world(path_world),
m_gamespec(gamespec), m_gamespec(gamespec),
m_simple_singleplayer_mode(simple_singleplayer_mode), m_simple_singleplayer_mode(simple_singleplayer_mode),
m_dedicated(dedicated),
m_async_fatal_error(""), m_async_fatal_error(""),
m_env(NULL), m_env(NULL),
m_con(PROTOCOL_ID, m_con(PROTOCOL_ID,
@ -630,9 +632,9 @@ void Server::AsyncRunStep(bool initial_step)
{ {
float &counter = m_masterserver_timer; float &counter = m_masterserver_timer;
if (!isSingleplayer() && (!counter || counter >= 300.0) && if (!isSingleplayer() && (!counter || counter >= 300.0) &&
g_settings->getBool("server_announce")) g_settings->getBool("server_announce")) {
{ ServerList::sendAnnounce(counter ? ServerList::AA_UPDATE :
ServerList::sendAnnounce(counter ? "update" : "start", ServerList::AA_START,
m_bind_addr.getPort(), m_bind_addr.getPort(),
m_clients.getPlayerNames(), m_clients.getPlayerNames(),
m_uptime.get(), m_uptime.get(),
@ -640,7 +642,8 @@ void Server::AsyncRunStep(bool initial_step)
m_lag, m_lag,
m_gamespec.id, m_gamespec.id,
Mapgen::getMapgenName(m_emerge->mgparams->mgtype), Mapgen::getMapgenName(m_emerge->mgparams->mgtype),
m_mods); m_mods,
m_dedicated);
counter = 0.01; counter = 0.01;
} }
counter += dtime; counter += dtime;
@ -3574,16 +3577,6 @@ void dedicated_server_loop(Server &server, bool &kill)
} }
server.step(steplen); server.step(steplen);
if(server.getShutdownRequested() || kill)
{
infostream<<"Dedicated server quitting"<<std::endl;
#if USE_CURL
if(g_settings->getBool("server_announce"))
ServerList::sendAnnounce("delete", server.m_bind_addr.getPort());
#endif
break;
}
/* /*
Profiler Profiler
*/ */
@ -3596,4 +3589,11 @@ void dedicated_server_loop(Server &server, bool &kill)
} }
} }
} }
infostream << "Dedicated server quitting" << std::endl;
#if USE_CURL
if (g_settings->getBool("server_announce"))
ServerList::sendAnnounce(ServerList::AA_DELETE,
server.m_bind_addr.getPort());
#endif
} }

@ -148,6 +148,7 @@ public:
const SubgameSpec &gamespec, const SubgameSpec &gamespec,
bool simple_singleplayer_mode, bool simple_singleplayer_mode,
bool ipv6, bool ipv6,
bool dedicated,
ChatInterface *iface = NULL ChatInterface *iface = NULL
); );
~Server(); ~Server();
@ -510,6 +511,8 @@ private:
// functionality // functionality
bool m_simple_singleplayer_mode; bool m_simple_singleplayer_mode;
u16 m_max_chatmessage_length; u16 m_max_chatmessage_length;
// For "dedicated" server list flag
bool m_dedicated;
// Thread can set; step() will throw as ServerError // Thread can set; step() will throw as ServerError
MutexedVariable<std::string> m_async_fatal_error; MutexedVariable<std::string> m_async_fatal_error;

@ -196,7 +196,7 @@ const std::string serializeJson(const std::vector<ServerListSpec> &serverlist)
#if USE_CURL #if USE_CURL
void sendAnnounce(const std::string &action, void sendAnnounce(AnnounceAction action,
const u16 port, const u16 port,
const std::vector<std::string> &clients_names, const std::vector<std::string> &clients_names,
const double uptime, const double uptime,
@ -204,15 +204,17 @@ void sendAnnounce(const std::string &action,
const float lag, const float lag,
const std::string &gameid, const std::string &gameid,
const std::string &mg_name, const std::string &mg_name,
const std::vector<ModSpec> &mods) const std::vector<ModSpec> &mods,
bool dedicated)
{ {
static const char *aa_names[] = {"start", "update", "delete"};
Json::Value server; Json::Value server;
server["action"] = action; server["action"] = aa_names[action];
server["port"] = port; server["port"] = port;
if (g_settings->exists("server_address")) { if (g_settings->exists("server_address")) {
server["address"] = g_settings->get("server_address"); server["address"] = g_settings->get("server_address");
} }
if (action != "delete") { if (action != AA_DELETE) {
bool strict_checking = g_settings->getBool("strict_protocol_version_checking"); bool strict_checking = g_settings->getBool("strict_protocol_version_checking");
server["name"] = g_settings->get("server_name"); server["name"] = g_settings->get("server_name");
server["description"] = g_settings->get("server_description"); server["description"] = g_settings->get("server_description");
@ -237,20 +239,19 @@ void sendAnnounce(const std::string &action,
if (gameid != "") server["gameid"] = gameid; if (gameid != "") server["gameid"] = gameid;
} }
if (action == "start") { if (action == AA_START) {
server["dedicated"] = g_settings->getBool("server_dedicated"); server["dedicated"] = dedicated;
server["rollback"] = g_settings->getBool("enable_rollback_recording"); server["rollback"] = g_settings->getBool("enable_rollback_recording");
server["mapgen"] = mg_name; server["mapgen"] = mg_name;
server["privs"] = g_settings->get("default_privs"); server["privs"] = g_settings->get("default_privs");
server["can_see_far_names"] = g_settings->getS16("player_transfer_distance") <= 0; server["can_see_far_names"] = g_settings->getS16("player_transfer_distance") <= 0;
server["mods"] = Json::Value(Json::arrayValue); server["mods"] = Json::Value(Json::arrayValue);
for (std::vector<ModSpec>::const_iterator it = mods.begin(); for (std::vector<ModSpec>::const_iterator it = mods.begin();
it != mods.end(); it != mods.end(); ++it) {
++it) {
server["mods"].append(it->name); server["mods"].append(it->name);
} }
actionstream << "Announcing to " << g_settings->get("serverlist_url") << std::endl; actionstream << "Announcing to " << g_settings->get("serverlist_url") << std::endl;
} else { } else if (action == AA_UPDATE) {
if (lag) if (lag)
server["lag"] = lag; server["lag"] = lag;
} }
@ -265,3 +266,4 @@ void sendAnnounce(const std::string &action,
#endif #endif
} // namespace ServerList } // namespace ServerList

@ -31,20 +31,25 @@ namespace ServerList
{ {
std::vector<ServerListSpec> getLocal(); std::vector<ServerListSpec> getLocal();
std::vector<ServerListSpec> getOnline(); std::vector<ServerListSpec> getOnline();
bool deleteEntry(const ServerListSpec &server); bool deleteEntry(const ServerListSpec &server);
bool insert(const ServerListSpec &server); bool insert(const ServerListSpec &server);
std::vector<ServerListSpec> deSerialize(const std::string &liststring); std::vector<ServerListSpec> deSerialize(const std::string &liststring);
const std::string serialize(const std::vector<ServerListSpec> &serverlist); const std::string serialize(const std::vector<ServerListSpec> &serverlist);
std::vector<ServerListSpec> deSerializeJson(const std::string &liststring); std::vector<ServerListSpec> deSerializeJson(const std::string &liststring);
const std::string serializeJson(const std::vector<ServerListSpec> &serverlist); const std::string serializeJson(const std::vector<ServerListSpec> &serverlist);
#if USE_CURL #if USE_CURL
void sendAnnounce(const std::string &action, const u16 port, enum AnnounceAction {AA_START, AA_UPDATE, AA_DELETE};
void sendAnnounce(AnnounceAction, u16 port,
const std::vector<std::string> &clients_names = std::vector<std::string>(), const std::vector<std::string> &clients_names = std::vector<std::string>(),
const double uptime = 0, const u32 game_time = 0, double uptime = 0, u32 game_time = 0, float lag = 0,
const float lag = 0, const std::string &gameid = "", const std::string &gameid = "", const std::string &mg_name = "",
const std::string &mg_name = "", const std::vector<ModSpec> &mods = std::vector<ModSpec>(),
const std::vector<ModSpec> &mods = std::vector<ModSpec>()); bool dedicated = false);
#endif #endif
} // ServerList namespace
} // namespace ServerList
#endif #endif