Server list cleanup

This removes the hacky server_dedicated pseudo-setting.
master
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

View File

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

View File

@ -213,10 +213,6 @@ int main(int argc, char *argv[])
infostream << "Using commanded world path ["
<< 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)
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 {
// Create server
Server server(game_params.world_path,
game_params.game_spec, false, bind_addr.isIPv6(), &iface);
Server server(game_params.world_path, game_params.game_spec,
false, bind_addr.isIPv6(), true, &iface);
g_term_console.setup(&iface, &kill, admin_nick);
@ -887,7 +883,7 @@ static bool run_dedicated_server(const GameParams &game_params, const Settings &
try {
// Create server
Server server(game_params.world_path, game_params.game_spec, false,
bind_addr.isIPv6());
bind_addr.isIPv6(), true);
server.start(bind_addr);
// Run server

View File

@ -148,11 +148,13 @@ Server::Server(
const SubgameSpec &gamespec,
bool simple_singleplayer_mode,
bool ipv6,
bool dedicated,
ChatInterface *iface
):
m_path_world(path_world),
m_gamespec(gamespec),
m_simple_singleplayer_mode(simple_singleplayer_mode),
m_dedicated(dedicated),
m_async_fatal_error(""),
m_env(NULL),
m_con(PROTOCOL_ID,
@ -629,10 +631,10 @@ void Server::AsyncRunStep(bool initial_step)
// send masterserver announce
{
float &counter = m_masterserver_timer;
if(!isSingleplayer() && (!counter || counter >= 300.0) &&
g_settings->getBool("server_announce"))
{
ServerList::sendAnnounce(counter ? "update" : "start",
if (!isSingleplayer() && (!counter || counter >= 300.0) &&
g_settings->getBool("server_announce")) {
ServerList::sendAnnounce(counter ? ServerList::AA_UPDATE :
ServerList::AA_START,
m_bind_addr.getPort(),
m_clients.getPlayerNames(),
m_uptime.get(),
@ -640,7 +642,8 @@ void Server::AsyncRunStep(bool initial_step)
m_lag,
m_gamespec.id,
Mapgen::getMapgenName(m_emerge->mgparams->mgtype),
m_mods);
m_mods,
m_dedicated);
counter = 0.01;
}
counter += dtime;
@ -3574,16 +3577,6 @@ void dedicated_server_loop(Server &server, bool &kill)
}
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
*/
@ -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
}

View File

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

View File

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

View File

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