From e2c7434aa8c5ae3e4ed390c63bd0207ee1d29765 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 27 Oct 2019 21:46:30 +0000 Subject: SCUMM HE: Replace binary packet with JSON --- engines/scumm/he/moonbase/net_main.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'engines/scumm/he') diff --git a/engines/scumm/he/moonbase/net_main.cpp b/engines/scumm/he/moonbase/net_main.cpp index cef39c6ad1..ae143ee540 100644 --- a/engines/scumm/he/moonbase/net_main.cpp +++ b/engines/scumm/he/moonbase/net_main.cpp @@ -333,27 +333,26 @@ void Net::remoteStartScript(int typeOfSend, int sendTypeParam, int priority, int } int Net::remoteSendData(int typeOfSend, int sendTypeParam, int type, byte *data, int len, int defaultRes) { - byte *buf = (byte *)malloc(MAX_PACKET_SIZE + DATA_HEADER_SIZE); - Common::MemoryWriteStream pack(buf, MAX_PACKET_SIZE + DATA_HEADER_SIZE); + // Since I am lazy, instead of constructing the JSON object manually + // I'd rather parse it + Common::String res = Common::String::format( + "{\"sessionid\":%d, \"userid\":%d, \"to\":%d, \"toparam\": %d, " + "\"type\":%d, \"timestamp\": %d, \"data\": [", _sessionid, _myUserId, + typeOfSend, sendTypeParam, type, g_system->getMillis()); - pack.writeUint32LE(_sessionid); - pack.writeUint32LE(_myUserId); - pack.writeUint32LE(typeOfSend); - pack.writeUint32LE(sendTypeParam); - pack.writeUint32LE(type); - pack.writeUint32LE(len); - pack.writeUint32LE(g_system->getMillis()); - pack.write(data, len); + for (int i = 0; i < len - 1; i++) + res += Common::String::format("%d, ", data[i]); - debug("Package to send, to: %d (%d), %d(%x) bytes", typeOfSend, sendTypeParam, len + DATA_HEADER_SIZE, len); + res += Common::String::format("%d] }", data[len - 1]); - Common::hexdump(buf, len + DATA_HEADER_SIZE); + debug("Package to send: %s", res.c_str()); Networking::PostRequest rq(_serverprefix + "/packet", new Common::Callback(this, &Net::remoteSendDataCallback), new Common::Callback(this, &Net::remoteSendDataErrorCallback)); - rq.setPostData(buf, len + DATA_HEADER_SIZE); + rq.setPostData((byte *)res.c_str(), res.size()); + rq.setContentType("application/json"); rq.start(); -- cgit v1.2.3