2013-03-01 16:58:05 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2013-03-24 17:18:22 +00:00
|
|
|
#include "Core/Reporting.h"
|
|
|
|
|
2013-04-29 01:56:09 +00:00
|
|
|
#include "Common/CPUDetect.h"
|
2013-03-02 07:11:34 +00:00
|
|
|
#include "Common/StdThread.h"
|
2013-05-20 03:20:41 +00:00
|
|
|
#include "Core/CoreTiming.h"
|
2013-03-01 16:58:05 +00:00
|
|
|
#include "Core/Config.h"
|
|
|
|
#include "Core/System.h"
|
2013-05-20 03:20:41 +00:00
|
|
|
#include "Core/HLE/sceDisplay.h"
|
|
|
|
#include "Core/HLE/sceKernelMemory.h"
|
2013-04-29 00:49:17 +00:00
|
|
|
#include "GPU/GPUInterface.h"
|
|
|
|
#include "GPU/GPUState.h"
|
2013-03-01 16:58:05 +00:00
|
|
|
|
|
|
|
#include "net/http_client.h"
|
|
|
|
#include "net/resolve.h"
|
2013-05-31 21:10:14 +00:00
|
|
|
#include "net/url.h"
|
|
|
|
|
2013-03-01 16:58:05 +00:00
|
|
|
#include "base/buffer.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string>
|
2013-03-02 07:11:34 +00:00
|
|
|
#include <cstdarg>
|
2013-03-02 06:34:02 +00:00
|
|
|
|
2013-03-01 16:58:05 +00:00
|
|
|
namespace Reporting
|
|
|
|
{
|
|
|
|
const int DEFAULT_PORT = 80;
|
2013-03-02 07:11:34 +00:00
|
|
|
const u32 SPAM_LIMIT = 100;
|
2013-03-02 06:34:02 +00:00
|
|
|
const int PAYLOAD_BUFFER_SIZE = 100;
|
2013-03-01 20:56:51 +00:00
|
|
|
|
|
|
|
// Internal limiter on number of requests per instance.
|
|
|
|
static u32 spamProtectionCount = 0;
|
|
|
|
// Temporarily stores a reference to the hostname.
|
|
|
|
static std::string lastHostname;
|
2013-03-01 16:58:05 +00:00
|
|
|
|
2013-03-02 06:34:02 +00:00
|
|
|
enum RequestType
|
|
|
|
{
|
|
|
|
MESSAGE,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Payload
|
|
|
|
{
|
|
|
|
RequestType type;
|
2013-03-04 07:36:24 +00:00
|
|
|
std::string string1;
|
|
|
|
std::string string2;
|
2013-03-02 06:34:02 +00:00
|
|
|
};
|
|
|
|
static Payload payloadBuffer[PAYLOAD_BUFFER_SIZE];
|
|
|
|
static int payloadBufferPos = 0;
|
|
|
|
|
2013-04-14 08:25:25 +00:00
|
|
|
// Returns the full host (e.g. report.ppsspp.org:80.)
|
2013-03-24 16:53:41 +00:00
|
|
|
inline std::string ServerHost()
|
|
|
|
{
|
|
|
|
if (g_Config.sReportHost.compare("default") == 0)
|
|
|
|
return "";
|
|
|
|
return g_Config.sReportHost;
|
|
|
|
}
|
|
|
|
|
2013-04-14 08:25:25 +00:00
|
|
|
// Returns the length of the hostname part (e.g. before the :80.)
|
2013-03-01 16:58:05 +00:00
|
|
|
static size_t ServerHostnameLength()
|
|
|
|
{
|
2013-03-24 16:53:41 +00:00
|
|
|
if (!IsEnabled())
|
2013-03-01 16:58:05 +00:00
|
|
|
return g_Config.sReportHost.npos;
|
|
|
|
|
|
|
|
// IPv6 literal?
|
2013-03-24 16:53:41 +00:00
|
|
|
std::string host = ServerHost();
|
|
|
|
if (host[0] == '[')
|
2013-03-01 16:58:05 +00:00
|
|
|
{
|
2013-03-24 16:53:41 +00:00
|
|
|
size_t length = host.find("]:");
|
|
|
|
if (length != host.npos)
|
2013-03-01 16:58:05 +00:00
|
|
|
++length;
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
else
|
2013-03-24 16:53:41 +00:00
|
|
|
return host.find(':');
|
2013-03-01 16:58:05 +00:00
|
|
|
}
|
|
|
|
|
2013-04-14 08:25:25 +00:00
|
|
|
// Returns only the hostname part (e.g. "report.ppsspp.org".)
|
2013-03-01 16:58:05 +00:00
|
|
|
static const char *ServerHostname()
|
|
|
|
{
|
2013-03-24 16:53:41 +00:00
|
|
|
if (!IsEnabled())
|
2013-03-01 16:58:05 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-03-24 16:53:41 +00:00
|
|
|
std::string host = ServerHost();
|
2013-03-01 16:58:05 +00:00
|
|
|
size_t length = ServerHostnameLength();
|
|
|
|
|
2013-04-14 08:25:25 +00:00
|
|
|
// This means there's no port number - it's already the hostname.
|
|
|
|
if (length == host.npos)
|
|
|
|
lastHostname = host;
|
|
|
|
else
|
|
|
|
lastHostname = host.substr(0, length);
|
2013-03-01 16:58:05 +00:00
|
|
|
return lastHostname.c_str();
|
|
|
|
}
|
|
|
|
|
2013-04-14 08:25:25 +00:00
|
|
|
// Returns only the port part (e.g. 80) as an int.
|
2013-03-01 16:58:05 +00:00
|
|
|
static int ServerPort()
|
|
|
|
{
|
2013-03-24 16:53:41 +00:00
|
|
|
if (!IsEnabled())
|
2013-03-01 16:58:05 +00:00
|
|
|
return 0;
|
|
|
|
|
2013-03-24 16:53:41 +00:00
|
|
|
std::string host = ServerHost();
|
2013-03-01 16:58:05 +00:00
|
|
|
size_t offset = ServerHostnameLength();
|
2013-04-14 08:25:25 +00:00
|
|
|
// If there's no port, use the default one.
|
2013-03-24 16:53:41 +00:00
|
|
|
if (offset == host.npos)
|
2013-03-01 16:58:05 +00:00
|
|
|
return DEFAULT_PORT;
|
|
|
|
|
|
|
|
// Skip the colon.
|
2013-03-24 16:53:41 +00:00
|
|
|
std::string port = host.substr(offset + 1);
|
2013-03-01 16:58:05 +00:00
|
|
|
return atoi(port.c_str());
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:56:51 +00:00
|
|
|
// Should only be called once per request.
|
|
|
|
bool CheckSpamLimited()
|
|
|
|
{
|
|
|
|
return ++spamProtectionCount >= SPAM_LIMIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SendReportRequest(const char *uri, const std::string &data, Buffer *output = NULL)
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
http::Client http;
|
|
|
|
Buffer theVoid;
|
|
|
|
|
|
|
|
if (output == NULL)
|
|
|
|
output = &theVoid;
|
|
|
|
|
|
|
|
net::Init();
|
|
|
|
if (http.Resolve(ServerHostname(), ServerPort()))
|
|
|
|
{
|
|
|
|
http.Connect();
|
2013-03-24 16:37:25 +00:00
|
|
|
http.POST("/report/message", data, "application/x-www-form-urlencoded", output);
|
2013-03-01 20:56:51 +00:00
|
|
|
http.Disconnect();
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
net::Shutdown();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-04-29 01:27:51 +00:00
|
|
|
std::string StripTrailingNull(const std::string &str)
|
|
|
|
{
|
|
|
|
size_t pos = str.find_first_of('\0');
|
|
|
|
if (pos != str.npos)
|
|
|
|
return str.substr(0, pos);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2013-04-29 01:56:09 +00:00
|
|
|
std::string GetPlatformIdentifer()
|
|
|
|
{
|
|
|
|
// TODO: Do we care about OS version?
|
|
|
|
#if defined(ANDROID)
|
|
|
|
return "Android";
|
2013-04-29 02:36:15 +00:00
|
|
|
#elif defined(_WIN64)
|
|
|
|
return "Windows 64";
|
2013-04-29 01:56:09 +00:00
|
|
|
#elif defined(_WIN32)
|
|
|
|
return "Windows";
|
|
|
|
#elif defined(IOS)
|
|
|
|
return "iOS";
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
return "Mac";
|
|
|
|
#elif defined(__SYMBIAN32__)
|
|
|
|
return "Symbian";
|
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
return "BSD";
|
|
|
|
#elif defined(BLACKBERRY)
|
|
|
|
return "Blackberry";
|
|
|
|
#elif defined(LOONGSON)
|
|
|
|
return "Loongson";
|
2013-04-29 02:36:15 +00:00
|
|
|
#elif defined(MEEGO_EDITION_HARMATTAN)
|
|
|
|
return "Nokia N9/N950";
|
|
|
|
#elif defined(__linux__)
|
|
|
|
return "Linux";
|
2013-04-29 01:56:09 +00:00
|
|
|
#else
|
|
|
|
return "Unknown";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-03-02 06:34:02 +00:00
|
|
|
int Process(int pos)
|
|
|
|
{
|
|
|
|
Payload &payload = payloadBuffer[pos];
|
|
|
|
|
2013-04-29 07:30:54 +00:00
|
|
|
std::string gpuPrimary, gpuFull;
|
2013-05-18 16:47:17 +00:00
|
|
|
if (gpu)
|
|
|
|
gpu->GetReportingInfo(gpuPrimary, gpuFull);
|
2013-04-29 00:49:17 +00:00
|
|
|
|
2013-04-29 01:27:51 +00:00
|
|
|
UrlEncoder postdata;
|
|
|
|
postdata.Add("version", PPSSPP_GIT_VERSION);
|
|
|
|
// TODO: Maybe ParamSFOData shouldn't include nulls in std::strings? Don't work to break savedata, though...
|
|
|
|
postdata.Add("game", StripTrailingNull(g_paramSFO.GetValueString("DISC_ID")) + "_" + StripTrailingNull(g_paramSFO.GetValueString("DISC_VERSION")));
|
|
|
|
postdata.Add("game_title", StripTrailingNull(g_paramSFO.GetValueString("TITLE")));
|
2013-04-29 07:30:54 +00:00
|
|
|
postdata.Add("gpu", gpuPrimary);
|
|
|
|
postdata.Add("gpu_full", gpuFull);
|
2013-04-29 01:56:09 +00:00
|
|
|
postdata.Add("cpu", cpu_info.Summarize());
|
|
|
|
postdata.Add("platform", GetPlatformIdentifer());
|
2013-05-20 03:20:41 +00:00
|
|
|
postdata.Add("sdkver", sceKernelGetCompiledSdkVersion());
|
|
|
|
postdata.Add("pixel_width", PSP_CoreParameter().pixelWidth);
|
|
|
|
postdata.Add("pixel_height", PSP_CoreParameter().pixelHeight);
|
2013-06-01 05:31:05 +00:00
|
|
|
postdata.Add("ticks", (const uint64_t)CoreTiming::GetTicks());
|
2013-05-20 03:20:41 +00:00
|
|
|
|
2013-06-19 05:08:29 +00:00
|
|
|
if (g_Config.iShowFPSCounter)
|
2013-05-20 03:20:41 +00:00
|
|
|
{
|
|
|
|
float vps, fps;
|
|
|
|
__DisplayGetAveragedFPS(&vps, &fps);
|
|
|
|
postdata.Add("vps", vps);
|
2013-06-30 02:57:25 +00:00
|
|
|
postdata.Add("fps", fps);
|
2013-05-20 03:20:41 +00:00
|
|
|
}
|
2013-04-29 01:56:09 +00:00
|
|
|
|
|
|
|
// TODO: Settings, savestate/savedata status, some measure of speed/fps?
|
2013-03-02 06:34:02 +00:00
|
|
|
|
|
|
|
switch (payload.type)
|
|
|
|
{
|
|
|
|
case MESSAGE:
|
2013-04-29 01:27:51 +00:00
|
|
|
postdata.Add("message", payload.string1);
|
|
|
|
postdata.Add("value", payload.string2);
|
2013-03-04 07:36:24 +00:00
|
|
|
payload.string1.clear();
|
|
|
|
payload.string2.clear();
|
2013-03-02 06:34:02 +00:00
|
|
|
|
2013-04-29 01:27:51 +00:00
|
|
|
SendReportRequest("/report/message", postdata.ToString());
|
2013-03-02 06:34:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-24 16:53:41 +00:00
|
|
|
bool IsEnabled()
|
2013-03-01 16:58:05 +00:00
|
|
|
{
|
2013-03-24 16:53:41 +00:00
|
|
|
if (g_Config.sReportHost.empty())
|
|
|
|
return false;
|
2013-03-01 16:58:05 +00:00
|
|
|
// Disabled by default for now.
|
|
|
|
if (g_Config.sReportHost.compare("default") == 0)
|
2013-03-24 16:53:41 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportMessage(const char *message, ...)
|
|
|
|
{
|
|
|
|
if (!IsEnabled() || CheckSpamLimited())
|
2013-03-01 16:58:05 +00:00
|
|
|
return;
|
|
|
|
|
2013-03-01 17:51:10 +00:00
|
|
|
const int MESSAGE_BUFFER_SIZE = 32768;
|
|
|
|
char temp[MESSAGE_BUFFER_SIZE];
|
2013-03-01 16:58:05 +00:00
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, message);
|
2013-03-02 06:34:02 +00:00
|
|
|
vsnprintf(temp, MESSAGE_BUFFER_SIZE - 1, message, args);
|
|
|
|
temp[MESSAGE_BUFFER_SIZE - 1] = '\0';
|
2013-03-01 16:58:05 +00:00
|
|
|
va_end(args);
|
|
|
|
|
2013-03-02 06:34:02 +00:00
|
|
|
int pos = payloadBufferPos++ % PAYLOAD_BUFFER_SIZE;
|
|
|
|
Payload &payload = payloadBuffer[pos];
|
|
|
|
payload.type = MESSAGE;
|
2013-03-04 07:36:24 +00:00
|
|
|
payload.string1 = message;
|
|
|
|
payload.string2 = temp;
|
2013-03-02 06:34:02 +00:00
|
|
|
|
|
|
|
std::thread th(Process, pos);
|
|
|
|
th.detach();
|
2013-03-01 16:58:05 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 05:31:05 +00:00
|
|
|
}
|