[Download] Add serverlist info
This commit is contained in:
parent
179f34bd9f
commit
3f9f58d5f6
@ -465,6 +465,37 @@ namespace Components
|
|||||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Download::ServerlistHandler(mg_connection* nc, int ev, void* /*ev_data*/)
|
||||||
|
{
|
||||||
|
// Only handle http requests
|
||||||
|
if (ev != MG_EV_HTTP_REQUEST) return;
|
||||||
|
|
||||||
|
std::vector<json11::Json> servers;
|
||||||
|
|
||||||
|
// Build server list
|
||||||
|
for (auto& node : Node::GetNodes())
|
||||||
|
{
|
||||||
|
std::map<std::string, json11::Json> serverInfo;
|
||||||
|
serverInfo["address"] = "127.0.0.1:28960";
|
||||||
|
|
||||||
|
if (node.isValid())
|
||||||
|
{
|
||||||
|
serverInfo["address"] = node.address.getCString();
|
||||||
|
servers.push_back(serverInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mg_printf(nc,
|
||||||
|
"HTTP/1.1 200 OK\r\n"
|
||||||
|
"Content-Type: application/json\r\n"
|
||||||
|
"Connection: close\r\n"
|
||||||
|
"Access-Control-Allow-Origin: *\r\n"
|
||||||
|
"\r\n"
|
||||||
|
"%s", json11::Json(servers).dump().data());
|
||||||
|
|
||||||
|
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||||
|
}
|
||||||
|
|
||||||
void Download::MapHandler(mg_connection *nc, int ev, void* ev_data)
|
void Download::MapHandler(mg_connection *nc, int ev, void* ev_data)
|
||||||
{
|
{
|
||||||
// Only handle http requests
|
// Only handle http requests
|
||||||
@ -819,6 +850,7 @@ namespace Components
|
|||||||
mg_register_http_endpoint(nc, "/list", Download::ListHandler);
|
mg_register_http_endpoint(nc, "/list", Download::ListHandler);
|
||||||
mg_register_http_endpoint(nc, "/map", Download::MapHandler);
|
mg_register_http_endpoint(nc, "/map", Download::MapHandler);
|
||||||
mg_register_http_endpoint(nc, "/file/", Download::FileHandler);
|
mg_register_http_endpoint(nc, "/file/", Download::FileHandler);
|
||||||
|
mg_register_http_endpoint(nc, "/serverlist", Download::ServerlistHandler);
|
||||||
|
|
||||||
mg_set_protocol_http_websocket(nc);
|
mg_set_protocol_http_websocket(nc);
|
||||||
}
|
}
|
||||||
|
@ -217,6 +217,7 @@ namespace Components
|
|||||||
static void EventHandler(mg_connection *nc, int ev, void *ev_data);
|
static void EventHandler(mg_connection *nc, int ev, void *ev_data);
|
||||||
static void ListHandler(mg_connection *nc, int ev, void *ev_data);
|
static void ListHandler(mg_connection *nc, int ev, void *ev_data);
|
||||||
static void MapHandler(mg_connection *nc, int ev, void *ev_data);
|
static void MapHandler(mg_connection *nc, int ev, void *ev_data);
|
||||||
|
static void ServerlistHandler(mg_connection *nc, int ev, void *ev_data);
|
||||||
static void FileHandler(mg_connection *nc, int ev, void *ev_data);
|
static void FileHandler(mg_connection *nc, int ev, void *ev_data);
|
||||||
static void InfoHandler(mg_connection *nc, int ev, void *ev_data);
|
static void InfoHandler(mg_connection *nc, int ev, void *ev_data);
|
||||||
static void DownloadHandler(mg_connection *nc, int ev, void *ev_data);
|
static void DownloadHandler(mg_connection *nc, int ev, void *ev_data);
|
||||||
|
@ -153,6 +153,13 @@ namespace Components
|
|||||||
Node::Nodes.push_back(node);
|
Node::Nodes.push_back(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<Node::Entry> Node::GetNodes()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::recursive_mutex> _(Node::Mutex);
|
||||||
|
|
||||||
|
return Node::Nodes;
|
||||||
|
}
|
||||||
|
|
||||||
void Node::RunFrame()
|
void Node::RunFrame()
|
||||||
{
|
{
|
||||||
if (Dedicated::IsEnabled() && Dvar::Var("sv_lanOnly").get<bool>()) return;
|
if (Dedicated::IsEnabled() && Dvar::Var("sv_lanOnly").get<bool>()) return;
|
||||||
@ -264,6 +271,7 @@ namespace Components
|
|||||||
Node::Nodes.push_back(entry);
|
Node::Nodes.push_back(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::SendList(Network::Address address)
|
void Node::SendList(Network::Address address)
|
||||||
{
|
{
|
||||||
Proto::Node::List list;
|
Proto::Node::List list;
|
||||||
|
@ -41,6 +41,7 @@ namespace Components
|
|||||||
~Node();
|
~Node();
|
||||||
|
|
||||||
static void Add(Network::Address address);
|
static void Add(Network::Address address);
|
||||||
|
static std::vector<Entry> GetNodes();
|
||||||
static void RunFrame();
|
static void RunFrame();
|
||||||
static void Synchronize();
|
static void Synchronize();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user