diff options
author | Eugene Sandulenko | 2019-10-24 17:38:03 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2019-10-24 17:41:28 +0200 |
commit | 45d9824c49b0f2c044f347956c3f7fe84358dea1 (patch) | |
tree | 978a599876c68ccf84f260bb5258730b5ef38b83 /engines/scumm/he | |
parent | bbaebe594ea7a3b6afac4e40fbb367ed7b679e94 (diff) | |
download | scummvm-rg350-45d9824c49b0f2c044f347956c3f7fe84358dea1.tar.gz scummvm-rg350-45d9824c49b0f2c044f347956c3f7fe84358dea1.tar.bz2 scummvm-rg350-45d9824c49b0f2c044f347956c3f7fe84358dea1.zip |
SCUMM HE: Create sessions on the server
Diffstat (limited to 'engines/scumm/he')
-rw-r--r-- | engines/scumm/he/moonbase/net_main.cpp | 42 | ||||
-rw-r--r-- | engines/scumm/he/moonbase/net_main.h | 7 |
2 files changed, 46 insertions, 3 deletions
diff --git a/engines/scumm/he/moonbase/net_main.cpp b/engines/scumm/he/moonbase/net_main.cpp index 48fb044412..a2d76fef4f 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 54d1298b60..2a399d3f83 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 |