summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-02-29 19:30:59 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-02-29 19:31:06 +0300
commit5792d59c3ed577096556b744a51bb375e59c325f (patch)
treeec81e22742dcdcc8f9133b5b1ed5927b7a253286
parent7869990f380805939298ef3d59e6ccf9b62bc834 (diff)
Discord:
- fixes #1953 ([Discord] Changing status post-sign-in doesn't work unless a normal client is also open); - fixes #705 ([Discord] System tray icon does not reflect actual status of Discord protocol); - version bump
-rw-r--r--protocols/Discord/src/gateway.cpp45
-rw-r--r--protocols/Discord/src/proto.h17
-rw-r--r--protocols/Discord/src/server.cpp19
-rw-r--r--protocols/Discord/src/version.h2
4 files changed, 58 insertions, 25 deletions
diff --git a/protocols/Discord/src/gateway.cpp b/protocols/Discord/src/gateway.cpp
index 46b7586539..5dfcea52f5 100644
--- a/protocols/Discord/src/gateway.cpp
+++ b/protocols/Discord/src/gateway.cpp
@@ -172,7 +172,7 @@ void CDiscordProto::GatewayProcess(const JSONNode &pRoot)
{
int opCode = pRoot["op"].as_int();
switch (opCode) {
- case 0: // process incoming command
+ case OPCODE_DISPATCH: // process incoming command
{
int iSeq = pRoot["s"].as_int();
if (iSeq != 0)
@@ -187,7 +187,7 @@ void CDiscordProto::GatewayProcess(const JSONNode &pRoot)
}
break;
- case 9: // session invalidated
+ case OPCODE_INVALID_SESSION: // session invalidated
if (pRoot["d"].as_bool()) // session can be resumed
GatewaySendResume();
else {
@@ -196,13 +196,13 @@ void CDiscordProto::GatewayProcess(const JSONNode &pRoot)
}
break;
- case 10: // hello
+ case OPCODE_HELLO: // hello
m_iHartbeatInterval = pRoot["d"]["heartbeat_interval"].as_int();
GatewaySendIdentify();
break;
- case 11: // heartbeat ack
+ case OPCODE_HEARTBEAT_ACK: // heartbeat ack
break;
default:
@@ -220,7 +220,7 @@ void CDiscordProto::GatewaySendHeartbeat()
return;
JSONNode root;
- root << INT_PARAM("op", 1) << INT_PARAM("d", m_iGatewaySeq);
+ root << INT_PARAM("op", OPCODE_HEARTBEAT) << INT_PARAM("d", m_iGatewaySeq);
GatewaySend(root);
}
@@ -245,7 +245,7 @@ void CDiscordProto::GatewaySendIdentify()
payload << CHAR_PARAM("token", m_szAccessToken) << props << BOOL_PARAM("compress", false) << INT_PARAM("large_threshold", 250);
JSONNode root;
- root << INT_PARAM("op", 2) << payload;
+ root << INT_PARAM("op", OPCODE_IDENTIFY) << payload;
GatewaySend(root);
}
@@ -260,3 +260,36 @@ void CDiscordProto::GatewaySendResume()
root << CHAR_PARAM("token", szRandom) << CHAR_PARAM("session_id", m_szGatewaySessionId) << INT_PARAM("seq", m_iGatewaySeq);
GatewaySend(root);
}
+
+void CDiscordProto::GatewaySendStatus(int iStatus, const wchar_t *pwszStatusText)
+{
+ if (iStatus == ID_STATUS_OFFLINE) {
+ Push(new AsyncHttpRequest(this, REQUEST_POST, "/auth/logout", nullptr));
+ return;
+ }
+
+ const char *pszStatus;
+ switch (iStatus) {
+ case ID_STATUS_AWAY:
+ case ID_STATUS_NA:
+ pszStatus = "idle"; break;
+ case ID_STATUS_DND:
+ pszStatus = "dnd"; break;
+ case ID_STATUS_INVISIBLE:
+ pszStatus = "invisible"; break;
+ default:
+ pszStatus = "online"; break;
+ }
+
+ JSONNode payload; payload.set_name("d");
+ payload << INT64_PARAM("since", __int64(time(0)) * 1000) << BOOL_PARAM("afk", true) << CHAR_PARAM("status", pszStatus);
+ if (pwszStatusText == nullptr)
+ payload << CHAR_PARAM("game", nullptr);
+ else {
+ JSONNode game; game.set_name("game"); game << WCHAR_PARAM("name", pwszStatusText) << INT_PARAM("type", 0);
+ payload << game;
+ }
+
+ JSONNode root; root << INT_PARAM("op", OPCODE_STATUS_UPDATE) << payload;
+ GatewaySend(root);
+}
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index a513ee59b3..c6e51cb341 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -136,6 +136,22 @@ struct CDiscordVoiceCall
/////////////////////////////////////////////////////////////////////////////////////////
+#define OPCODE_DISPATCH 0
+#define OPCODE_HEARTBEAT 1
+#define OPCODE_IDENTIFY 2
+#define OPCODE_STATUS_UPDATE 3
+#define OPCODE_VOICE_UPDATE 4
+#define OPCODE_VOICE_PING 5
+#define OPCODE_RESUME 6
+#define OPCODE_RECONNECT 7
+#define OPCODE_REQUEST_MEMBERS 8
+#define OPCODE_INVALID_SESSION 9
+#define OPCODE_HELLO 10
+#define OPCODE_HEARTBEAT_ACK 11
+#define OPCODE_REQUEST_SYNC 12
+#define OPCODE_REQUEST_SYNC_GROUP 13
+#define OPCODE_REQUEST_SYNC_CHANNEL 14
+
class CDiscordProto : public PROTO<CDiscordProto>
{
friend struct AsyncHttpRequest;
@@ -220,6 +236,7 @@ class CDiscordProto : public PROTO<CDiscordProto>
void GatewaySendHeartbeat(void);
void GatewaySendIdentify(void);
void GatewaySendResume(void);
+ void GatewaySendStatus(int iStatus, const wchar_t *pwszStatusText);
GatewayHandlerFunc GetHandler(const wchar_t*);
diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp
index c6b127c8cd..f1e3135aa4 100644
--- a/protocols/Discord/src/server.cpp
+++ b/protocols/Discord/src/server.cpp
@@ -207,24 +207,7 @@ void CDiscordProto::SetServerStatus(int iStatus)
if (!m_bOnline)
return;
- if (iStatus == ID_STATUS_OFFLINE)
- Push(new AsyncHttpRequest(this, REQUEST_POST, "/auth/logout", nullptr));
- else {
- const char *pszStatus;
- switch (iStatus) {
- case ID_STATUS_AWAY:
- case ID_STATUS_NA:
- pszStatus = "idle"; break;
- case ID_STATUS_DND:
- pszStatus = "dnd"; break;
- case ID_STATUS_INVISIBLE:
- pszStatus = "invisible"; break;
- default:
- pszStatus = "online"; break;
- }
- JSONNode root; root << CHAR_PARAM("status", pszStatus);
- Push(new AsyncHttpRequest(this, REQUEST_PATCH, "/users/@me/settings", nullptr, &root));
- }
+ GatewaySendStatus(iStatus, nullptr);
int iOldStatus = m_iStatus; m_iStatus = iStatus;
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)iOldStatus, m_iStatus);
diff --git a/protocols/Discord/src/version.h b/protocols/Discord/src/version.h
index eb2be75625..00d257e060 100644
--- a/protocols/Discord/src/version.h
+++ b/protocols/Discord/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 6
#define __RELEASE_NUM 2
-#define __BUILD_NUM 4
+#define __BUILD_NUM 5
#include <stdver.h>