opcodes

This commit is contained in:
Flam3rboy
2021-02-06 17:08:18 +01:00
parent 471d1d6b28
commit 4eba7f5068
8 changed files with 79 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
import { Payload } from "../util/Constants";
import { Send } from "../util/Send";
import { setHeartbeat } from "../util/setHeartbeat";
import WebSocket from "../util/WebSocket";
export function onHeartbeat(this: WebSocket, data: Payload) {
setHeartbeat(this);
Send(this, { op: 11 });
}
+18
View File
@@ -0,0 +1,18 @@
import { CLOSECODES, Payload } from "../util/Constants";
import Config from "../util/Config";
import WebSocket from "../util/WebSocket";
import { checkToken, IdentifySchema } from "discord-server-util";
import { check } from "./instanceOf";
export async function onIdentify(this: WebSocket, data: Payload) {
clearTimeout(this.readyTimeout);
if (check.call(this, IdentifySchema, data.d)) return;
const identify: IdentifySchema = data.d;
try {
var { id } = await checkToken(identify.token);
} catch (error) {
return this.close(CLOSECODES.Authentication_failed);
}
}
+4
View File
@@ -0,0 +1,4 @@
import { Payload } from "../util/Constants";
import WebSocket from "../util/WebSocket";
export function onPresenceUpdate(this: WebSocket, data: Payload) {}
+5
View File
@@ -0,0 +1,5 @@
import { Payload } from "../util/Constants";
import WebSocket from "../util/WebSocket";
export function onRequestGuildMembers(this: WebSocket, data: Payload) {}
+5
View File
@@ -0,0 +1,5 @@
import { Payload } from "../util/Constants";
import WebSocket from "../util/WebSocket";
export function onResume(this: WebSocket, data: Payload) {}
+5
View File
@@ -0,0 +1,5 @@
import { Payload } from "../util/Constants";
import WebSocket from "../util/WebSocket";
export function onVoiceStateUpdate(this: WebSocket, data: Payload) {}
+19
View File
@@ -0,0 +1,19 @@
import { Payload } from "../util/Constants";
import WebSocket from "../util/WebSocket";
import { onHeartbeat } from "./Heartbeat";
import { onIdentify } from "./Identify";
import { onPresenceUpdate } from "./PresenceUpdate";
import { onRequestGuildMembers } from "./RequestGuildMembers";
import { onResume } from "./Resume";
import { onVoiceStateUpdate } from "./VoiceStateUpdate";
export type OPCodeHandler = (this: WebSocket, data: Payload) => any;
export default {
1: onHeartbeat,
2: onIdentify,
3: onPresenceUpdate,
4: onVoiceStateUpdate,
5: onResume,
8: onRequestGuildMembers,
};
+13
View File
@@ -0,0 +1,13 @@
import { instanceOf } from "lambert-server";
import { CLOSECODES } from "../util/Constants";
import WebSocket from "../util/WebSocket";
export function check(this: WebSocket, schema: any, data: any) {
try {
return instanceOf(schema, data);
} catch (error) {
// invalid identify struct
this.close(CLOSECODES.Decode_error);
return false;
}
}