1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Readd Server proto

This commit is contained in:
DustyBagel 2025-01-02 17:23:07 -06:00
parent 6c614eb0dc
commit 283159c5ff

View file

@ -69,6 +69,7 @@ typedef int socket_t;
const char* adv_multicast_addr = "224.1.1.1"; const char* adv_multicast_addr = "224.1.1.1";
const static unsigned short int adv_port = 29998; const static unsigned short int adv_port = 29998;
const char* proto = "Luanti";
static std::string ask_str; static std::string ask_str;
bool use_ipv6 = true; bool use_ipv6 = true;
@ -84,6 +85,7 @@ void lan_adv::ask()
if (ask_str.empty()) { if (ask_str.empty()) {
Json::Value j; Json::Value j;
j["cmd"] = "ask"; j["cmd"] = "ask";
j["proto"] = proto;
ask_str = fastWriteJson(j); ask_str = fastWriteJson(j);
} }
@ -258,6 +260,7 @@ void *lan_adv::run()
server["port"] = server_port; server["port"] = server_port;
server["clients"] = clients_num.load(); server["clients"] = clients_num.load();
server["clients_max"] = g_settings->getU16("max_users"); server["clients_max"] = g_settings->getU16("max_users");
server["proto"] = proto;
send_string(fastWriteJson(server)); send_string(fastWriteJson(server));
} }
@ -280,7 +283,7 @@ void *lan_adv::run()
if (server_port) { if (server_port) {
if (p["cmd"] == "ask" && limiter[addr_str] < now) { if (p["cmd"] == "ask" && limiter[addr_str] < now) {
(clients_num.load() ? infostream : actionstream) (clients_num.load() ? infostream : actionstream)
<< "lan: want play " << addr_str << std::endl; << "lan: want play " << addr_str << " " << p["proto"] << std::endl;
server["clients"] = clients_num.load(); server["clients"] = clients_num.load();
answer_str = fastWriteJson(server); answer_str = fastWriteJson(server);
@ -292,7 +295,7 @@ void *lan_adv::run()
} }
} else { } else {
if (p["cmd"] == "ask") { if (p["cmd"] == "ask") {
actionstream << "lan: want play " << addr_str << std::endl; actionstream << "lan: want play " << addr_str << " " << p["proto"] << std::endl;
} }
if (p["port"].isInt()) { if (p["port"].isInt()) {
p["address"] = addr_str; p["address"] = addr_str;
@ -302,7 +305,7 @@ void *lan_adv::run()
//infostream << "server shutdown " << key << "\n"; //infostream << "server shutdown " << key << "\n";
collected.erase(key); collected.erase(key);
fresh = true; fresh = true;
} else { } else if (p["proto"] == proto) {
if (!collected.count(key)) if (!collected.count(key))
actionstream << "lan server start " << key << "\n"; actionstream << "lan server start " << key << "\n";
collected.insert_or_assign(key, p); collected.insert_or_assign(key, p);