From e1766da83ceb05e4457bab878c7953a28aaad58e Mon Sep 17 00:00:00 2001 From: Koncord Date: Sat, 27 May 2017 09:26:26 +0800 Subject: [PATCH] [Master] Fix REST API for old servers --- apps/master/RestServer.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/master/RestServer.cpp b/apps/master/RestServer.cpp index 6730d46b0..9c383d5fa 100644 --- a/apps/master/RestServer.cpp +++ b/apps/master/RestServer.cpp @@ -11,9 +11,9 @@ using namespace std; using namespace chrono; using namespace boost::property_tree; -static string response201 = "HTTP/1.1 201 Created\r\nContent-Length: 11\r\n\r\n201 Created"; -static string response202 = "HTTP/1.1 202 Accepted\r\nContent-Length: 12\r\n\r\n202 Accepted"; -static string response400 = "HTTP/1.1 400 Bad Request\r\nContent-Length: 15\r\n\r\n400 Bad Request"; +static string response201 = "HTTP/1.1 201 Created\r\nContent-Length: 7\r\n\r\nCreated"; +static string response202 = "HTTP/1.1 202 Accepted\r\nContent-Length: 8\r\n\r\nAccepted"; +static string response400 = "HTTP/1.1 400 Bad Request\r\nContent-Length: 11\r\n\r\nbad request"; inline void ResponseStr(HttpServer::Response &response, string content, string type = "", string code = "200 OK") { @@ -67,7 +67,7 @@ void RestServer::start() stringstream ss; ss << "{"; auto addr = request->path_match[1].str(); - auto port = (unsigned short)stoi(&(addr[addr.find(':')])); + auto port = (unsigned short)stoi(&(addr[addr.find(':')+1])); queryToStringStream(ss, "server", serverMap->at(RakNet::SystemAddress(addr.c_str(), port))); ss << "}"; ResponseStr(*response, ss.str(), "application/json"); @@ -110,7 +110,8 @@ void RestServer::start() MasterServer::SServer server; ptreeToServer(pt, server); - unsigned short port = pt.get("query_port"); + unsigned short port = pt.get("port"); + server.lastUpdate = steady_clock::now(); serverMap->insert({RakNet::SystemAddress(request->remote_endpoint_address.c_str(), port), server}); updatedCache = true; @@ -126,9 +127,9 @@ void RestServer::start() //Update query for < 0.6 servers httpServer.resource[ServersRegex]["PUT"] = [this](auto response, auto request) { auto addr = request->path_match[1].str(); - auto port = (unsigned short)stoi(&(addr[addr.find(':')])); + auto port = (unsigned short)stoi(&(addr[addr.find(':')+1])); - auto query = serverMap->find(RakNet::SystemAddress(addr.c_str(), port)); + auto query = serverMap->find(RakNet::SystemAddress(request->remote_endpoint_address.c_str(), port)); if(query == serverMap->end()) {