Skip to content

Commit

Permalink
Server list cleanup
Browse files Browse the repository at this point in the history
This removes the hacky server_dedicated pseudo-setting.
  • Loading branch information
ShadowNinja authored and SmallJoker committed Mar 18, 2017
1 parent 2cc518d commit b8484ef
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/game.cpp
Expand Up @@ -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);

Expand Down
10 changes: 3 additions & 7 deletions src/main.cpp
Expand Up @@ -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;

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

Expand Down Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions src/server.cpp
Expand Up @@ -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,
Expand Down Expand Up @@ -629,18 +631,19 @@ 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(),
m_env->getGameTime(),
m_lag,
m_gamespec.id,
Mapgen::getMapgenName(m_emerge->mgparams->mgtype),
m_mods);
m_mods,
m_dedicated);
counter = 0.01;
}
counter += dtime;
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
}
3 changes: 3 additions & 0 deletions src/server.h
Expand Up @@ -148,6 +148,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
const SubgameSpec &gamespec,
bool simple_singleplayer_mode,
bool ipv6,
bool dedicated,
ChatInterface *iface = NULL
);
~Server();
Expand Down Expand Up @@ -510,6 +511,8 @@ class Server : public con::PeerHandler, public MapEventReceiver,
// 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;
Expand Down
22 changes: 12 additions & 10 deletions src/serverlist.cpp
Expand Up @@ -196,23 +196,25 @@ 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,
const u32 game_time,
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");
Expand All @@ -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;
}
Expand All @@ -264,4 +265,5 @@ void sendAnnounce(const std::string &action,
}
#endif

} //namespace ServerList
} // namespace ServerList

39 changes: 22 additions & 17 deletions src/serverlist.h
Expand Up @@ -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

0 comments on commit b8484ef

Please sign in to comment.