aboutsummaryrefslogtreecommitdiff
path: root/engines/scumm/he
diff options
context:
space:
mode:
authorEugene Sandulenko2019-10-25 09:22:59 +0200
committerEugene Sandulenko2019-10-25 12:30:26 +0100
commit6c259f4fd064007b83b1b41dacbcb5a9ca8c8ae0 (patch)
treee8a31772eb7593d464609750f921fcd2009e3b69 /engines/scumm/he
parentf1b0ec772c52a6ab0ac6ef6c27b650eb28a94d48 (diff)
downloadscummvm-rg350-6c259f4fd064007b83b1b41dacbcb5a9ca8c8ae0.tar.gz
scummvm-rg350-6c259f4fd064007b83b1b41dacbcb5a9ca8c8ae0.tar.bz2
scummvm-rg350-6c259f4fd064007b83b1b41dacbcb5a9ca8c8ae0.zip
SCUMM HE: Implemented startQuerySessions() for Moonbase Commander
Diffstat (limited to 'engines/scumm/he')
-rw-r--r--engines/scumm/he/moonbase/net_main.cpp34
-rw-r--r--engines/scumm/he/moonbase/net_main.h2
2 files changed, 31 insertions, 5 deletions
diff --git a/engines/scumm/he/moonbase/net_main.cpp b/engines/scumm/he/moonbase/net_main.cpp
index 764c028db3..f634c0c14b 100644
--- a/engines/scumm/he/moonbase/net_main.cpp
+++ b/engines/scumm/he/moonbase/net_main.cpp
@@ -37,6 +37,7 @@ Net::Net(ScummEngine_v100he *vm) : _latencyTime(1), _fakeLatency(false), _vm(vm)
_lastResult = 0;
_sessionid = -1;
+ _sessions = nullptr;
_serverprefix = "http://localhost/moonbase";
}
@@ -44,6 +45,8 @@ Net::Net(ScummEngine_v100he *vm) : _latencyTime(1), _fakeLatency(false), _vm(vm)
Net::~Net() {
free(_tmpbuffer);
free(_packbuffer);
+
+ delete _sessions;
}
int Net::hostGame(char *sessionName, char *userName) {
@@ -216,24 +219,32 @@ bool Net::destroyPlayer(int32 playerDPID) {
}
int32 Net::startQuerySessions() {
- warning("STUB: Net::startQuerySessions()"); // StartQuerySessions
+ debug(1, "Net::startQuerySessions()"); // StartQuerySessions
Networking::PostRequest rq(_serverprefix + "/lobbies",
new Common::Callback<Net, Common::JSONValue *>(this, &Net::startQuerySessionsCallback),
new Common::Callback<Net, Networking::ErrorResponse>(this, &Net::startQuerySessionsErrorCallback));
+ delete _sessions;
+
rq.start();
while(rq.state() == Networking::PROCESSING) {
g_system->delayMillis(5);
}
- // FAKE 1 session. FIXME
- return 1;
+ if (!_sessions)
+ return 0;
+
+ debug(1, "Net::startQuerySessions(): got %lu", _sessions->countChildren());
+
+ return _sessions->countChildren();
}
void Net::startQuerySessionsCallback(Common::JSONValue *response) {
- warning("startQuerySessions: Got: '%s'", response->stringify().c_str());
+ debug(1, "startQuerySessions: Got: '%s' which is %lu", response->stringify().c_str(), response->countChildren());
+
+ _sessions = new Common::JSONValue(*response);
}
void Net::startQuerySessionsErrorCallback(Networking::ErrorResponse error) {
@@ -344,8 +355,21 @@ bool Net::getIPfromName(char *ip, int ipLength, char *nameBuffer) {
}
void Net::getSessionName(int sessionNumber, char *buffer, int length) {
+ warning("STUB: Net::getSessionName(%d, ..., %d)", sessionNumber, length); // PN_GetSessionName
+
+ if (!_sessions) {
+ *buffer = '\0';
+ warning("Net::getSessionName(): no sessions");
+ return;
+ }
+
+ if (sessionNumber >= _sessions->countChildren()) {
+ *buffer = '\0';
+ warning("Net::getSessionName(): session number too big: %d >= %lu", sessionNumber, _sessions->countChildren());
+ return;
+ }
// FIXME
- strcpy(buffer, "test");
+ strcpy(buffer, _sessions->child(sessionNumber)->child("name")->asString().c_str());
warning("STUB: Net::getSessionName(%d, \"%s\", %d)", sessionNumber, buffer, length); // PN_GetSessionName
}
diff --git a/engines/scumm/he/moonbase/net_main.h b/engines/scumm/he/moonbase/net_main.h
index af71398031..02988858c4 100644
--- a/engines/scumm/he/moonbase/net_main.h
+++ b/engines/scumm/he/moonbase/net_main.h
@@ -107,6 +107,8 @@ public:
int _sessionid;
+ Common::JSONValue *_sessions;
+
Common::String _serverprefix;
};