summaryrefslogtreecommitdiff
path: root/protocols/Discord/src/proto.h
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Discord/src/proto.h')
-rw-r--r--protocols/Discord/src/proto.h80
1 files changed, 74 insertions, 6 deletions
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index b822bbf323..15a6a9eeeb 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -3,6 +3,7 @@ typedef __int64 SnowFlake;
class CDiscordProto;
typedef void (CDiscordProto::*HttpCallback)(NETLIBHTTPREQUEST*, struct AsyncHttpRequest*);
+typedef void (CDiscordProto::*GatewayHandlerFunc)(const JSONNode&);
struct AsyncHttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject
{
@@ -16,6 +17,7 @@ struct AsyncHttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject
CMStringA m_szParam;
HttpCallback m_pCallback;
int m_iErrorCode, m_iReqNum;
+ bool m_bMainSite;
void *pUserInfo;
};
@@ -26,6 +28,15 @@ struct PARAM
{}
};
+struct BOOL_PARAM : public PARAM
+{
+ bool bValue;
+ __forceinline BOOL_PARAM(LPCSTR _name, bool _value) :
+ PARAM(_name), bValue(_value)
+ {}
+};
+AsyncHttpRequest* operator<<(AsyncHttpRequest*, const BOOL_PARAM&);
+
struct INT_PARAM : public PARAM
{
int iValue;
@@ -35,6 +46,15 @@ struct INT_PARAM : public PARAM
};
AsyncHttpRequest* operator<<(AsyncHttpRequest*, const INT_PARAM&);
+struct INT64_PARAM : public PARAM
+{
+ SnowFlake iValue;
+ __forceinline INT64_PARAM(LPCSTR _name, SnowFlake _value) :
+ PARAM(_name), iValue(_value)
+ {}
+};
+AsyncHttpRequest* operator<<(AsyncHttpRequest*, const INT64_PARAM&);
+
struct CHAR_PARAM : public PARAM
{
LPCSTR szValue;
@@ -54,6 +74,7 @@ struct WCHAR_PARAM : public PARAM
AsyncHttpRequest* operator<<(AsyncHttpRequest*, const WCHAR_PARAM&);
JSONNode& operator<<(JSONNode &json, const INT_PARAM &param);
+JSONNode& operator<<(JSONNode &json, const BOOL_PARAM &param);
JSONNode& operator<<(JSONNode &json, const CHAR_PARAM &param);
JSONNode& operator<<(JSONNode &json, const WCHAR_PARAM &param);
@@ -91,6 +112,7 @@ class CDiscordProto : public PROTO<CDiscordProto>
void __cdecl ServerThread(void*);
void __cdecl SearchThread(void *param);
+ void __cdecl SendMessageAckThread(void* param);
//////////////////////////////////////////////////////////////////////////////////////
// session control
@@ -119,14 +141,27 @@ class CDiscordProto : public PROTO<CDiscordProto>
//////////////////////////////////////////////////////////////////////////////////////
// gateway
- CMStringA m_szGateway;
+ CMStringA
+ m_szGateway, // gateway url
+ m_szGatewaySessionId; // current session id
+
HANDLE
m_hGatewayNetlibUser, // the separate netlib user handle for gateways
m_hGatewayConnection; // gateway connection
+
void __cdecl GatewayThread(void*);
- void GatewaySend(int opCode, const char*);
+ void CDiscordProto::GatewayThreadWorker(void);
+
+ void GatewaySend(const JSONNode&, int opCode = 1);
+ void GatewayProcess(const JSONNode&);
- void OnReceiveGateway(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+ void GatewaySendHeartbeat(void);
+ void GatewaySendIdentify(void);
+
+ GatewayHandlerFunc GetHandler(const wchar_t*);
+
+ int m_iHartbeatInterval; // in milliseconds
+ int m_iGatewaySeq; // gateway sequence number
//////////////////////////////////////////////////////////////////////////////////////
// options
@@ -139,9 +174,13 @@ class CDiscordProto : public PROTO<CDiscordProto>
SnowFlake m_ownId;
+ mir_cs csMarkReadQueue;
+ LIST<CDiscordUser> arMarkReadQueue;
+
OBJLIST<CDiscordUser> arUsers;
CDiscordUser* FindUser(SnowFlake id);
CDiscordUser* FindUser(const wchar_t *pwszUsername, int iDiscriminator);
+ CDiscordUser* FindUserByChannel(SnowFlake channelId);
CDiscordUser* PrepareUser(const JSONNode&);
//////////////////////////////////////////////////////////////////////////////////////
@@ -168,26 +207,45 @@ public:
virtual int __cdecl AuthRequest(MCONTACT hContact, const wchar_t*) override;
+ virtual int __cdecl RecvMsg(MCONTACT hContact, PROTORECVEVENT *evt) override;
+ virtual int __cdecl SendMsg(MCONTACT hContact, int flags, const char* pszSrc) override;
+
virtual int __cdecl SetStatus(int iNewStatus) override;
virtual int __cdecl OnEvent(PROTOEVENTTYPE, WPARAM, LPARAM) override;
// Services
+ INT_PTR __cdecl SvcCreateAccMgrUI(WPARAM, LPARAM);
INT_PTR __cdecl GetStatus(WPARAM, LPARAM);
+ INT_PTR __cdecl GetAvatarCaps(WPARAM, LPARAM);
+ INT_PTR __cdecl GetAvatarInfo(WPARAM, LPARAM);
+ INT_PTR __cdecl GetMyAvatar(WPARAM, LPARAM);
+ INT_PTR __cdecl SetMyAvatar(WPARAM, LPARAM);
+
// Events
int __cdecl OnModulesLoaded(WPARAM, LPARAM);
int __cdecl OnPreShutdown(WPARAM, LPARAM);
int __cdecl OnOptionsInit(WPARAM, LPARAM);
- int __cdecl OnSrmmEvent(WPARAM, LPARAM);
+ int __cdecl OnDbEventRead(WPARAM, LPARAM);
+
+ // dispatch commands
+ void OnCommandMessage(const JSONNode&);
+ void OnCommandPresence(const JSONNode&);
+ void OnCommandReady(const JSONNode&);
+ void OnCommandTyping(const JSONNode&);
+ void OnCommandUserUpdate(const JSONNode&);
void OnLoggedIn();
void OnLoggedOut();
void OnReceiveAuth(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
- void OnReceiveToken(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
- void OnReceiveGuilds(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveChannels(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveFriends(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+ void OnReceiveGateway(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+ void OnReceiveGuilds(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+ void OnReceiveMessage(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+ void OnReceiveMessageAck(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+ void OnReceiveToken(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void RetrieveUserInfo(MCONTACT hContact);
void OnReceiveUserInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
@@ -195,6 +253,16 @@ public:
void RetrieveHistory(MCONTACT hContact, CDiscordHitoryOp iOp = MSG_NOFILTER, SnowFlake msgid = 0, int iLimit = 50);
void OnReceiveHistory(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+ bool RetrieveAvatar(MCONTACT hContact);
+ void OnReceiveAvatar(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+
// Misc
void SetServerStatus(int iStatus);
+
+ CMStringW GetAvatarFilename(MCONTACT hContact);
+
+ __forceinline int getHeartbeatInterval() const { return m_iHartbeatInterval; }
+
+ static void CALLBACK HeartbeatTimerProc(HWND hwnd, UINT msg, UINT_PTR id, DWORD);
+ static void CALLBACK MarkReadTimerProc(HWND hwnd, UINT msg, UINT_PTR id, DWORD);
};