http: Report local address to server.

This allows matching inside a network.
This commit is contained in:
Unknown W. Brackets committed 2016-07-03 22:13:51 -07:00
1 parent bde07bf9e7
commit 3eee81953a
3 files changed
+45 -2

No files matched your search

+24 -1
View File
@@ -16,6 +16,8 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "i18n/i18n.h"
#include "file/fd_util.h"
#include "net/http_client.h"
#include "net/http_server.h"
#include "net/resolve.h"
#include "net/sinks.h"
@@ -51,6 +53,26 @@ static ServerStatus RetrieveStatus() {
return serverStatus;
}
// This reports the local IP address to report.ppsspp.org, which can then
// relay that address to a mobile device searching for the server.
static void RegisterServer(int port) {
bool result = false;
net::AutoInit netInit;
http::Client http;
Buffer theVoid;
if (http.Resolve("report.ppsspp.org", 80)) {
http.Connect();
char resource[1024] = {};
std::string ip = fd_util::GetLocalIP(http.sock());
snprintf(resource, sizeof(resource) - 1, "/match/update?local=%s&port=%d", ip.c_str(), port);
http.GET(resource, &theVoid);
http.Disconnect();
}
}
static void ExecuteServer() {
setCurrentThreadName("HTTPServer");
@@ -131,9 +153,10 @@ static void ExecuteServer() {
}
http->Listen(0);
// TODO: Report local IP and port.
UpdateStatus(ServerStatus::RUNNING);
RegisterServer(http->Port());
while (RetrieveStatus() == ServerStatus::RUNNING) {
http->RunSlice(5.0);
}