diff --git a/src/opcodes/Heartbeat.ts b/src/opcodes/Heartbeat.ts
index 90a40230..4c8df739 100644
--- a/src/opcodes/Heartbeat.ts
+++ b/src/opcodes/Heartbeat.ts
@@ -4,6 +4,8 @@ import { setHeartbeat } from "../util/setHeartbeat";
import WebSocket from "../util/WebSocket";
export function onHeartbeat(this: WebSocket, data: Payload) {
+ // TODO: validate payload
+
setHeartbeat(this);
Send(this, { op: 11 });
diff --git a/src/opcodes/LazyRequest.ts b/src/opcodes/LazyRequest.ts
new file mode 100644
index 00000000..accff8de
--- /dev/null
+++ b/src/opcodes/LazyRequest.ts
@@ -0,0 +1,28 @@
+import { CLOSECODES, OPCODES, Payload } from "../util/Constants";
+import { Send } from "../util/Send";
+import WebSocket from "../util/WebSocket";
+
+export function onLazyRequest(this: WebSocket, { d }: Payload) {
+ // TODO: check data
+ const { guild_id, typing, channels, activities } = d;
+
+ Send(this, {
+ op: OPCODES.Dispatch,
+ s: this.sequence++,
+ t: "GUILD_MEMBER_LIST_UPDATE",
+ d: {
+ ops: [
+ {
+ range: [0, 99],
+ op: "SYNC",
+ items: [{ group: { id: "online", count: 0 } }],
+ },
+ ],
+ online_count: 1,
+ member_count: 1,
+ id: "everyone",
+ guild_id,
+ groups: [{ id: "online", count: 1 }],
+ },
+ });
+}
diff --git a/src/opcodes/PresenceUpdate.ts b/src/opcodes/PresenceUpdate.ts
index e6a389ba..3760f8a3 100644
--- a/src/opcodes/PresenceUpdate.ts
+++ b/src/opcodes/PresenceUpdate.ts
@@ -2,5 +2,5 @@ import { CLOSECODES, Payload } from "../util/Constants";
import WebSocket from "../util/WebSocket";
export function onPresenceUpdate(this: WebSocket, data: Payload) {
- return this.close(CLOSECODES.Unknown_error);
+ // return this.close(CLOSECODES.Unknown_error);
}
diff --git a/src/opcodes/RequestGuildMembers.ts b/src/opcodes/RequestGuildMembers.ts
index d7cecd3f..2701d978 100644
--- a/src/opcodes/RequestGuildMembers.ts
+++ b/src/opcodes/RequestGuildMembers.ts
@@ -3,5 +3,5 @@ import { CLOSECODES, Payload } from "../util/Constants";
import WebSocket from "../util/WebSocket";
export function onRequestGuildMembers(this: WebSocket, data: Payload) {
- return this.close(CLOSECODES.Unknown_error);
+ // return this.close(CLOSECODES.Unknown_error);
}
diff --git a/src/opcodes/Resume.ts b/src/opcodes/Resume.ts
index dd641e57..8badbb35 100644
--- a/src/opcodes/Resume.ts
+++ b/src/opcodes/Resume.ts
@@ -2,4 +2,6 @@ import { CLOSECODES, Payload } from "../util/Constants";
import WebSocket from "../util/WebSocket";
-export function onResume(this: WebSocket, data: Payload) {}
+export function onResume(this: WebSocket, data: Payload) {
+ return this.close(CLOSECODES.Session_timed_out);
+}
diff --git a/src/opcodes/experiments.json b/src/opcodes/experiments.json
new file mode 100644
index 00000000..0370b5da
--- /dev/null
+++ b/src/opcodes/experiments.json
@@ -0,0 +1,76 @@
+[
+ [4047587481, 0, 0, -1, 0],
+ [1509401575, 0, 1, -1, 0],
+ [1865079242, 0, 1, -1, 0],
+ [1962538549, 1, 0, -1, 0],
+ [3816091942, 3, 2, -1, 0],
+ [4130837190, 0, 10, -1, 0],
+ [1861568052, 0, 1, -1, 0],
+ [2290910058, 6, 2, -1, 0],
+ [1578940118, 1, 1, -1, 0],
+ [1571676964, 0, 1, -1, 2],
+ [3640172371, 0, 2, -1, 2],
+ [1658164312, 2, 1, -1, 0],
+ [98883956, 1, 1, -1, 0],
+ [3114091169, 0, 1, -1, 0],
+ [2570684145, 4, 1, -1, 2],
+ [4007615411, 0, 1, -1, 0],
+ [3665310159, 2, 1, -1, 1],
+ [852550504, 3, 1, -1, 0],
+ [2333572067, 0, 1, -1, 0],
+ [935994771, 1, 1, -1, 0],
+ [1127795596, 1, 1, -1, 0],
+ [4168223991, 0, 1, -1, 0],
+ [18585280, 0, 1, -1, 1],
+ [327482016, 0, 1, -1, 2],
+ [3458098201, 7, 1, -1, 0],
+ [478613943, 2, 1, -1, 1],
+ [2792197902, 0, 1, -1, 2],
+ [284670956, 0, 1, -1, 0],
+ [2099185390, 0, 1, -1, 0],
+ [1202202685, 0, 1, -1, 0],
+ [2122174751, 0, 1, -1, 0],
+ [3633864632, 0, 1, -1, 0],
+ [3103053065, 0, 1, -1, 0],
+ [820624960, 0, 1, -1, 0],
+ [1134479292, 0, 1, -1, 0],
+ [2511257455, 3, 1, -1, 3],
+ [2599708267, 0, 1, -1, 0],
+ [613180822, 1, 1, -1, 0],
+ [2885186814, 0, 1, -1, 0],
+ [221503477, 0, 1, -1, 0],
+ [1054317075, 0, 1, -1, 3],
+ [683872522, 0, 1, -1, 1],
+ [1739278764, 0, 2, -1, 0],
+ [2855249023, 0, 1, -1, 0],
+ [3721841948, 0, 1, -1, 0],
+ [1285203515, 0, 1, -1, 0],
+ [1365487849, 6, 1, -1, 0],
+ [955229746, 0, 1, -1, 0],
+ [3128009767, 0, 10, -1, 0],
+ [441885003, 0, 1, -1, 0],
+ [3433971238, 0, 1, -1, 2],
+ [1038765354, 3, 1, -1, 0],
+ [1174347196, 0, 1, -1, 0],
+ [3649806352, 1, 1, -1, 0],
+ [2973729510, 2, 1, -1, 0],
+ [2571931329, 1, 6, -1, 0],
+ [3884442008, 0, 1, -1, 0],
+ [978673395, 1, 1, -1, 0],
+ [4050927174, 0, 1, -1, 0],
+ [1260103069, 0, 1, -1, 0],
+ [4168894280, 0, 1, -1, 0],
+ [4045587091, 0, 1, -1, 0],
+ [2003494159, 1, 1, -1, 0],
+ [51193042, 0, 1, -1, 0],
+ [2634540382, 3, 1, -1, 0],
+ [886364171, 0, 1, -1, 0],
+ [3898604944, 0, 1, -1, 0],
+ [3388129398, 0, 1, -1, 0],
+ [3964382884, 2, 1, -1, 1],
+ [3305874255, 0, 1, -1, 0],
+ [156590431, 0, 1, -1, 0],
+ [3106485751, 0, 0, -1, 0],
+ [3035674767, 0, 1, -1, 0],
+ [851697110, 0, 1, -1, 0]
+]
diff --git a/src/opcodes/index.ts b/src/opcodes/index.ts
index d3b4180b..fa57f568 100644
--- a/src/opcodes/index.ts
+++ b/src/opcodes/index.ts
@@ -2,6 +2,7 @@ import { Payload } from "../util/Constants";
import WebSocket from "../util/WebSocket";
import { onHeartbeat } from "./Heartbeat";
import { onIdentify } from "./Identify";
+import { onLazyRequest } from "./LazyRequest";
import { onPresenceUpdate } from "./PresenceUpdate";
import { onRequestGuildMembers } from "./RequestGuildMembers";
import { onResume } from "./Resume";
@@ -14,6 +15,11 @@ export default {
2: onIdentify,
3: onPresenceUpdate,
4: onVoiceStateUpdate,
- 5: onResume,
+ // 5: Voice Server Ping
+ 6: onResume,
+ // 7: Reconnect: You should attempt to reconnect and resume immediately.
8: onRequestGuildMembers,
+ // 9: Invalid Session
+ // 10: Hello
+ 14: onLazyRequest,
};
diff --git a/src/opcodes/instanceOf.ts b/src/opcodes/instanceOf.ts
index b0c9bf26..752ea2b6 100644
--- a/src/opcodes/instanceOf.ts
+++ b/src/opcodes/instanceOf.ts
@@ -4,9 +4,9 @@ import WebSocket from "../util/WebSocket";
export function check(this: WebSocket, schema: any, data: any) {
try {
- return instanceOf(schema, data);
+ if (instanceOf(schema, data) !== true) throw "invalid";
} catch (error) {
- // invalid identify struct
+ // invalid payload
this.close(CLOSECODES.Decode_error);
return false;
}
diff --git a/src/util/Constants.ts b/src/util/Constants.ts
index e8e91d69..692f9028 100644
--- a/src/util/Constants.ts
+++ b/src/util/Constants.ts
@@ -1,16 +1,28 @@
export enum OPCODES {
- Dispatch,
- Heartbeat,
- Identify,
- Presence_Update,
- Voice_State_Update,
- Dummy_Value, // ? What is opcode 5?
- Resume,
- Reconnect,
- Request_Guild_Members,
- Invalid_Session,
- Hello,
- Heartbeat_ACK,
+ Dispatch = 0,
+ Heartbeat = 1,
+ Identify = 2,
+ Presence_Update = 3,
+ Voice_State_Update = 4,
+ Voice_Server_Ping = 5, // ? What is opcode 5?
+ Resume = 6,
+ Reconnect = 7,
+ Request_Guild_Members = 8,
+ Invalid_Session = 9,
+ Hello = 10,
+ Heartbeat_ACK = 11,
+ Guild_Sync = 12,
+ DM_Update = 13,
+ Lazy_Request = 14,
+ Lobby_Connect = 15,
+ Lobby_Disconnect = 16,
+ Lobby_Voice_States_Update = 17,
+ Stream_Create = 18,
+ Stream_Delete = 19,
+ Stream_Watch = 20,
+ Stream_Ping = 21,
+ Stream_Set_Paused = 22,
+ Request_Application_Commands = 24,
}
export enum CLOSECODES {
Unknown_error = 4000,
|