[Scummvm-git-logs] scummvm master -> 45d9824c49b0f2c044f347956c3f7fe84358dea1

sev- sev at scummvm.org
Thu Oct 24 17:41:44 CEST 2019


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
bbaebe594e NETWORKING: Reworked PostRequest to a more universal API
45d9824c49 SCUMM HE: Create sessions on the server


Commit: bbaebe594ea7a3b6afac4e40fbb367ed7b679e94
    https://github.com/scummvm/scummvm/commit/bbaebe594ea7a3b6afac4e40fbb367ed7b679e94
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2019-10-24T17:41:28+02:00

Commit Message:
NETWORKING: Reworked PostRequest to a more universal API

Changed paths:
    backends/networking/curl/postrequest.cpp
    backends/networking/curl/postrequest.h


diff --git a/backends/networking/curl/postrequest.cpp b/backends/networking/curl/postrequest.cpp
index 1dec36b..5e0bc1a 100644
--- a/backends/networking/curl/postrequest.cpp
+++ b/backends/networking/curl/postrequest.cpp
@@ -28,10 +28,11 @@
 
 namespace Networking {
 
-PostRequest::PostRequest(Common::String url, byte *postData, int postLen, Networking::JSONValueCallback cb, Networking::ErrorCallback ecb):
+PostRequest::PostRequest(Common::String url, Networking::JSONValueCallback cb, Networking::ErrorCallback ecb):
 	Networking::Request(nullptr, ecb), _url(url), _jsonCallback(cb),
-	_workingRequest(nullptr), _ignoreCallback(false), _postData(postData), _postLen(postLen) {
-	start();
+	_workingRequest(nullptr), _ignoreCallback(false), _postData(nullptr), _postLen(0), _jsonData(nullptr) {
+
+	_contentType = "application/octet-stream";
 }
 
 PostRequest::~PostRequest() {
@@ -41,6 +42,19 @@ PostRequest::~PostRequest() {
 	delete _jsonCallback;
 }
 
+void PostRequest::setPostData(byte *postData, int postLen) {
+	_postData = postData;
+	_postLen = postLen;
+
+	_contentType = "application/octet-stream";
+}
+
+void PostRequest::setJSONData(Common::JSONValue *jsonData) {
+	_jsonData = jsonData;
+
+	_contentType = "application/json";
+}
+
 void PostRequest::start() {
 	_ignoreCallback = true;
 	if (_workingRequest)
@@ -50,9 +64,21 @@ void PostRequest::start() {
 	Networking::JsonCallback innerCallback = new Common::Callback<PostRequest, Networking::JsonResponse>(this, &PostRequest::responseCallback);
 	Networking::ErrorCallback errorResponseCallback = new Common::Callback<PostRequest, Networking::ErrorResponse>(this, &PostRequest::errorCallback);
 	Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(innerCallback, errorResponseCallback, _url);
-	request->addHeader("Content-Type: application/json");
 
-	request->setBuffer(_postData, _postLen);
+	if (_postData && _jsonData) {
+		warning("Error, both data and JSON present while calling %s", _url.c_str());
+
+		_jsonData = nullptr;
+	}
+
+	request->addHeader(Common::String::format("Content-Type: %s", _contentType.c_str()));
+
+	if (_postData)
+		request->setBuffer(_postData, _postLen);
+
+
+	if (_jsonData)
+		request->addPostField(Common::JSON::stringify(_jsonData));
 
 	_workingRequest = ConnMan.addRequest(request);
 }
diff --git a/backends/networking/curl/postrequest.h b/backends/networking/curl/postrequest.h
index 5689794..8992d3a 100644
--- a/backends/networking/curl/postrequest.h
+++ b/backends/networking/curl/postrequest.h
@@ -37,15 +37,23 @@ class PostRequest: public Networking::Request {
 
 	byte *_postData;
 	int _postLen;
+	Common::JSONValue *_jsonData;
+
+	Common::String _contentType;
 
-	void start();
 	void responseCallback(Networking::JsonResponse response);
 	void errorCallback(Networking::ErrorResponse error);
 
 public:
-	PostRequest(Common::String url, byte *postData, int postLen, Networking::JSONValueCallback cb, Networking::ErrorCallback ecb);
+	PostRequest(Common::String url, Networking::JSONValueCallback cb, Networking::ErrorCallback ecb);
 	virtual ~PostRequest();
 
+	void start();
+
+	void setPostData(byte *postData, int postLen);
+	void setJSONData(Common::JSONValue *jsonData);
+	void setContentType(Common::String type) { _contentType = type; }
+
 	virtual void handle();
 	virtual void restart();
 	virtual Common::String date() const;


Commit: 45d9824c49b0f2c044f347956c3f7fe84358dea1
    https://github.com/scummvm/scummvm/commit/45d9824c49b0f2c044f347956c3f7fe84358dea1
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2019-10-24T17:41:28+02:00

Commit Message:
SCUMM HE: Create sessions on the server

Changed paths:
    engines/scumm/he/moonbase/net_main.cpp
    engines/scumm/he/moonbase/net_main.h


diff --git a/engines/scumm/he/moonbase/net_main.cpp b/engines/scumm/he/moonbase/net_main.cpp
index 48fb044..a2d76fe 100644
--- a/engines/scumm/he/moonbase/net_main.cpp
+++ b/engines/scumm/he/moonbase/net_main.cpp
@@ -34,6 +34,9 @@ Net::Net(ScummEngine_v100he *vm) : _latencyTime(1), _fakeLatency(false), _vm(vm)
 	_tmpbuffer = (byte *)malloc(MAX_PACKET_SIZE);
 
 	_myUserId = -1;
+	_lastResult = 0;
+
+	_sessionid = -1;
 }
 
 Net::~Net() {
@@ -91,10 +94,41 @@ int Net::whoAmI() {
 int Net::createSession(char *name) {
 	warning("STUB: Net::createSession(\"%s\")", name); // PN_CreateSession
 
-	// FAKE session creation. FIXME
+	Networking::PostRequest rq("http://localhost/moonbase/createsession",
+		new Common::Callback<Net, Common::JSONValue *>(this, &Net::startQuerySessionsCallback),
+		new Common::Callback<Net, Networking::ErrorResponse>(this, &Net::startQuerySessionsErrorCallback));
+
+	snprintf((char *)_tmpbuffer, MAX_PACKET_SIZE, "{\"name\":\"%s\"}", name);
+	rq.setPostData(_tmpbuffer, strlen((char *)_tmpbuffer));
+	rq.setContentType("application/json");
+
+	rq.start();
+
+	_sessionid = -1;
+
+	while(rq.state() == Networking::PROCESSING) {
+		g_system->delayMillis(5);
+	}
+
+	if (_sessionid == -1)
+		return 0;
+
 	return 1;
 }
 
+void Net::createSessionCallback(Common::JSONValue *response) {
+	Common::JSONObject info = response->asObject();
+
+	if (info.contains("sessionid")) {
+		_sessionid = info["sessionid"]->asIntegerNumber();
+	}
+	warning("Got: '%s' as %d", response->stringify().c_str(), _sessionid);
+}
+
+void Net::createSessionErrorCallback(Networking::ErrorResponse error) {
+	warning("Error in createSession(): %ld %s", error.httpResponseCode, error.response.c_str());
+}
+
 int Net::joinSession(int sessionIndex) {
 	warning("STUB: Net::joinSession(%d)", sessionIndex); // PN_JoinSession
 
@@ -151,10 +185,12 @@ bool Net::destroyPlayer(int32 playerDPID) {
 int32 Net::startQuerySessions() {
 	warning("STUB: Net::startQuerySessions()"); // StartQuerySessions
 
-	Networking::PostRequest rq("http://localhost/lobbies", NULL, 0,
+	Networking::PostRequest rq("http://localhost/moonbase/lobbies",
 		new Common::Callback<Net, Common::JSONValue *>(this, &Net::startQuerySessionsCallback),
 		new Common::Callback<Net, Networking::ErrorResponse>(this, &Net::startQuerySessionsErrorCallback));
 
+	rq.start();
+
 	while(rq.state() == Networking::PROCESSING) {
 		g_system->delayMillis(5);
 	}
@@ -168,7 +204,7 @@ void Net::startQuerySessionsCallback(Common::JSONValue *response) {
 }
 
 void Net::startQuerySessionsErrorCallback(Networking::ErrorResponse error) {
-	warning("Error in startQuerySessions()");
+	warning("Error in startQuerySessions(): %ld %s", error.httpResponseCode, error.response.c_str());
 }
 
 int32 Net::updateQuerySessions() {
diff --git a/engines/scumm/he/moonbase/net_main.h b/engines/scumm/he/moonbase/net_main.h
index 54d1298..2a399d3 100644
--- a/engines/scumm/he/moonbase/net_main.h
+++ b/engines/scumm/he/moonbase/net_main.h
@@ -71,6 +71,9 @@ private:
 	int getMessageCount();
 	void remoteReceiveData();
 
+	void createSessionCallback(Common::JSONValue *response);
+	void createSessionErrorCallback(Networking::ErrorResponse error);
+
 	void startQuerySessionsCallback(Common::JSONValue *response);
 	void startQuerySessionsErrorCallback(Networking::ErrorResponse error);
 
@@ -96,6 +99,10 @@ public:
 	byte *_tmpbuffer;
 
 	int _myUserId;
+
+	int _lastResult;
+
+	int _sessionid;
 };
 
 } // End of namespace Scumm





More information about the Scummvm-git-logs mailing list