summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/Discord/src/dispatch.cpp20
-rw-r--r--protocols/Discord/src/gateway.cpp23
-rw-r--r--protocols/Discord/src/utils.cpp1
-rw-r--r--protocols/Discord/src/version.h2
4 files changed, 29 insertions, 17 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index 0b7f96a33f..7f6365e085 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -148,16 +148,16 @@ void CDiscordProto::OnCommandReady(const JSONNode &pRoot)
for (auto it = channels.begin(); it != channels.end(); ++it) {
const JSONNode &p = *it;
- const JSONNode &user = p["recipient"];
- if (!user)
- continue;
-
- CDiscordUser *pUser = PrepareUser(user);
- pUser->lastMessageId = _wtoi64(p["last_message_id"].as_mstring());
- pUser->channelId = _wtoi64(p["id"].as_mstring());
- pUser->bIsPrivate = true;
-
- setId(pUser->hContact, DB_KEY_CHANNELID, pUser->channelId);
+ const JSONNode &recipients = p["recipients"];
+ for (auto it2 = recipients.begin(); it2 != recipients.end(); ++it2) {
+ const JSONNode &r = *it2;
+ CDiscordUser *pUser = PrepareUser(r);
+ pUser->lastMessageId = _wtoi64(r["last_message_id"].as_mstring());
+ pUser->channelId = _wtoi64(p["id"].as_mstring());
+ pUser->bIsPrivate = true;
+
+ setId(pUser->hContact, DB_KEY_CHANNELID, pUser->channelId);
+ }
}
}
diff --git a/protocols/Discord/src/gateway.cpp b/protocols/Discord/src/gateway.cpp
index 43c923ff00..7454383878 100644
--- a/protocols/Discord/src/gateway.cpp
+++ b/protocols/Discord/src/gateway.cpp
@@ -206,25 +206,36 @@ void CDiscordProto::GatewayThreadWorker()
// we have some additional data, not only opcode
if (bufSize > headerSize) {
- if (bIsFinal && dataBuf == NULL) { // it fits, no need to reallocate a buffer
+ if (bIsFinal && payloadSize < _countof(buf)) { // it fits, no need to reallocate a buffer
bDataBufAllocated = false;
dataBuf = (char*)buf + headerSize;
dataBufSize = bufSize - headerSize;
}
else {
bDataBufAllocated = true;
- size_t newSize = dataBufSize + bufSize - headerSize;
+ size_t newSize = dataBufSize + payloadSize;
+ size_t currPacketSize = bufSize - headerSize;
dataBuf = (char*)mir_realloc(dataBuf, newSize+1);
- memcpy(dataBuf + dataBufSize, buf + headerSize, bufSize - headerSize);
+ memcpy(dataBuf + dataBufSize, buf + headerSize, currPacketSize);
+ while (currPacketSize < payloadSize) {
+ int result = Netlib_Recv(m_hGatewayConnection, dataBuf + dataBufSize + currPacketSize, int(payloadSize - currPacketSize), 0);
+ if (result == 0) {
+ debugLogA("Gateway connection gracefully closed");
+ break;
+ }
+ if (result < 0) {
+ debugLogA("Gateway connection error, exiting");
+ break;
+ }
+ currPacketSize += result;
+ }
+
dataBufSize = newSize;
debugLogA("data buffer reallocated to %d bytes", dataBufSize);
}
dataBuf[dataBufSize] = 0;
}
- if (dataBufSize < payloadSize)
- continue;
-
switch (opCode){
case 0: // text packet
case 1: // binary packet
diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp
index ae610b8d21..ac9eb85c11 100644
--- a/protocols/Discord/src/utils.cpp
+++ b/protocols/Discord/src/utils.cpp
@@ -168,6 +168,7 @@ CDiscordUser* CDiscordProto::PrepareUser(const JSONNode &user)
MCONTACT hContact = db_add_contact();
Proto_AddToContact(hContact, m_szModuleName);
+ db_set_ws(hContact, "CList", "Group", m_wszDefaultGroup);
setId(hContact, DB_KEY_ID, id);
setWString(hContact, DB_KEY_NICK, username);
setDword(hContact, DB_KEY_DISCR, iDiscriminator);
diff --git a/protocols/Discord/src/version.h b/protocols/Discord/src/version.h
index 4753e0f013..d7b213ad39 100644
--- a/protocols/Discord/src/version.h
+++ b/protocols/Discord/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 1
#define __RELEASE_NUM 0
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>