Add actual reporting of compatibility.

This commit is contained in:
Unknown W. Brackets 2014-09-27 15:37:53 -07:00
parent d068622b4e
commit af822b1647
5 changed files with 72 additions and 15 deletions

View file

@ -34,6 +34,7 @@
#include "net/resolve.h"
#include "net/url.h"
#include "base/stringutil.h"
#include "base/buffer.h"
#include "thread/thread.h"
#include "file/zip_read.h"
@ -62,6 +63,7 @@ namespace Reporting
enum RequestType
{
MESSAGE,
COMPAT,
};
struct Payload
@ -69,6 +71,9 @@ namespace Reporting
RequestType type;
std::string string1;
std::string string2;
int int1;
int int2;
int int3;
};
static Payload payloadBuffer[PAYLOAD_BUFFER_SIZE];
static int payloadBufferPos = 0;
@ -153,7 +158,7 @@ namespace Reporting
if (http.Resolve(ServerHostname(), ServerPort()))
{
http.Connect();
http.POST("/report/message", data, mimeType, output);
http.POST(uri, data, mimeType, output);
http.Disconnect();
result = true;
}
@ -289,7 +294,7 @@ namespace Reporting
{
Payload &payload = payloadBuffer[pos];
MultipartFormDataEncoder postdata;
UrlEncoder postdata;
AddSystemInfo(postdata);
AddGameInfo(postdata);
AddConfigInfo(postdata);
@ -306,6 +311,17 @@ namespace Reporting
postdata.Finish();
SendReportRequest("/report/message", postdata.ToString(), postdata.GetMimeType());
break;
case COMPAT:
postdata.Add("compat", payload.string1);
postdata.Add("graphics", StringFromFormat("%d", payload.int1));
postdata.Add("speed", StringFromFormat("%d", payload.int2));
postdata.Add("gameplay", StringFromFormat("%d", payload.int3));
payload.string1.clear();
postdata.Finish();
SendReportRequest("/report/compat", postdata.ToString(), postdata.GetMimeType());
break;
}
return 0;
@ -387,4 +403,21 @@ namespace Reporting
th.detach();
}
void ReportCompatibility(const char *compat, int graphics, int speed, int gameplay)
{
if (!IsEnabled())
return;
int pos = payloadBufferPos++ % PAYLOAD_BUFFER_SIZE;
Payload &payload = payloadBuffer[pos];
payload.type = COMPAT;
payload.string1 = compat;
payload.int1 = graphics;
payload.int2 = speed;
payload.int3 = gameplay;
std::thread th(Process, pos);
th.detach();
}
}

View file

@ -65,6 +65,9 @@ namespace Reporting
// Report a message string, using the format string as a key.
void ReportMessage(const char *message, ...);
// Report the compatibility of the current game / configuration.
void ReportCompatibility(const char *compat, int graphics, int speed, int gameplay);
// Returns true if that identifier has not been logged yet.
bool ShouldLogOnce(const char *identifier);
}

View file

@ -1177,13 +1177,12 @@ void GamePauseScreen::CreateViews() {
if (g_Config.bEnableCheats) {
rightColumnItems->Add(new Choice(i->T("Cheats")))->OnClick.Handle(this, &GamePauseScreen::OnCwCheat);
}
#if 0
// TODO, also might be nice to show overall compat rating here?
// Based on their platform or even cpu/gpu/config. Would add an API for it.
if (Reporting::IsEnabled()) {
I18NCategory *rp = GetI18NCategory("Reporting");
rightColumnItems->Add(new Choice(rp->T("ReportButton", "Report Feedback")))->OnClick.Handle(this, &GamePauseScreen::OnReportFeedback);
}
#endif
rightColumnItems->Add(new Spacer(25.0));
rightColumnItems->Add(new Choice(i->T("Exit to menu")))->OnClick.Handle(this, &GamePauseScreen::OnExitToMenu);

View file

@ -90,7 +90,8 @@ EventReturn RatingChoice::OnChoiceClick(EventParams &e) {
e2.v = e.v;
e2.a = *value_;
// Dispatch immediately (we're already on the UI thread as we're in an event handler).
return OnChoice.Dispatch(e2);
OnChoice.Dispatch(e2);
return EVENT_DONE;
}
class CompatRatingChoice : public RatingChoice {
@ -112,11 +113,11 @@ CompatRatingChoice::CompatRatingChoice(const char *captionKey, int *value, Layou
void CompatRatingChoice::SetupChoices() {
I18NCategory *rp = GetI18NCategory("Reporting");
group_->Clear();
AddChoice(1, rp->T("Perfect"));
AddChoice(2, rp->T("Plays"));
AddChoice(3, rp->T("In-game"));
AddChoice(4, rp->T("Menu/Intro"));
AddChoice(5, rp->T("Nothing"));
AddChoice(0, rp->T("Perfect"));
AddChoice(1, rp->T("Plays"));
AddChoice(2, rp->T("In-game"));
AddChoice(3, rp->T("Menu/Intro"));
AddChoice(4, rp->T("Nothing"));
}
ReportScreen::ReportScreen(const std::string &gamePath)
@ -146,11 +147,9 @@ void ReportScreen::CreateViews() {
leftColumnItems->Add(new RatingChoice("Gameplay", &gameplay_))->OnChoice.Handle(this, &ReportScreen::HandleChoice);
rightColumnItems->SetSpacing(0.0f);
// TODO: Handle.
rightColumnItems->Add(new Choice(rp->T("Open Browser")));
rightColumnItems->Add(new Choice(rp->T("Open Browser")))->OnClick.Handle(this, &ReportScreen::HandleBrowser);
submit_ = new Choice(rp->T("Submit Feedback"));
// TODO: Handle.
rightColumnItems->Add(submit_);
rightColumnItems->Add(submit_)->OnClick.Handle(this, &ReportScreen::HandleSubmit);
submit_->SetEnabled(overall_ >= 0 && graphics_ >= 0 && speed_ >= 0 && gameplay_ >= 0);
rightColumnItems->Add(new Spacer(25.0));
@ -161,6 +160,26 @@ void ReportScreen::CreateViews() {
root_->Add(rightColumn);
leftColumn->Add(leftColumnItems);
rightColumn->Add(rightColumnItems);
}
EventReturn ReportScreen::HandleSubmit(EventParams &e) {
const char *compat;
switch (overall_) {
case 0: compat = "perfect"; break;
case 1: compat = "playable"; break;
case 2: compat = "ingame"; break;
case 3: compat = "menu"; break;
case 4: compat = "none"; break;
default: compat = "unknown"; break;
}
Reporting::ReportCompatibility(compat, graphics_ + 1, speed_ + 1, gameplay_ + 1);
screenManager()->finishDialog(this, DR_OK);
return EVENT_DONE;
}
EventReturn ReportScreen::HandleBrowser(EventParams &e) {
LaunchBrowser("http://report.ppsspp.org/");
return EVENT_DONE;
}

View file

@ -28,6 +28,9 @@ public:
protected:
UI::EventReturn HandleChoice(UI::EventParams &e);
UI::EventReturn HandleSubmit(UI::EventParams &e);
UI::EventReturn HandleBrowser(UI::EventParams &e);
virtual void CreateViews();
UI::Choice *submit_;