mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-13 14:12:41 +01:00
🎨 add opcodes
This commit is contained in:
parent
9c04313826
commit
6b61c86e3f
@ -4,6 +4,8 @@ import { setHeartbeat } from "../util/setHeartbeat";
|
|||||||
import WebSocket from "../util/WebSocket";
|
import WebSocket from "../util/WebSocket";
|
||||||
|
|
||||||
export function onHeartbeat(this: WebSocket, data: Payload) {
|
export function onHeartbeat(this: WebSocket, data: Payload) {
|
||||||
|
// TODO: validate payload
|
||||||
|
|
||||||
setHeartbeat(this);
|
setHeartbeat(this);
|
||||||
|
|
||||||
Send(this, { op: 11 });
|
Send(this, { op: 11 });
|
||||||
|
28
src/opcodes/LazyRequest.ts
Normal file
28
src/opcodes/LazyRequest.ts
Normal file
@ -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 }],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
@ -2,5 +2,5 @@ import { CLOSECODES, Payload } from "../util/Constants";
|
|||||||
import WebSocket from "../util/WebSocket";
|
import WebSocket from "../util/WebSocket";
|
||||||
|
|
||||||
export function onPresenceUpdate(this: WebSocket, data: Payload) {
|
export function onPresenceUpdate(this: WebSocket, data: Payload) {
|
||||||
return this.close(CLOSECODES.Unknown_error);
|
// return this.close(CLOSECODES.Unknown_error);
|
||||||
}
|
}
|
||||||
|
@ -3,5 +3,5 @@ import { CLOSECODES, Payload } from "../util/Constants";
|
|||||||
import WebSocket from "../util/WebSocket";
|
import WebSocket from "../util/WebSocket";
|
||||||
|
|
||||||
export function onRequestGuildMembers(this: WebSocket, data: Payload) {
|
export function onRequestGuildMembers(this: WebSocket, data: Payload) {
|
||||||
return this.close(CLOSECODES.Unknown_error);
|
// return this.close(CLOSECODES.Unknown_error);
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,6 @@ import { CLOSECODES, Payload } from "../util/Constants";
|
|||||||
|
|
||||||
import WebSocket from "../util/WebSocket";
|
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);
|
||||||
|
}
|
||||||
|
76
src/opcodes/experiments.json
Normal file
76
src/opcodes/experiments.json
Normal file
@ -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]
|
||||||
|
]
|
@ -2,6 +2,7 @@ import { Payload } from "../util/Constants";
|
|||||||
import WebSocket from "../util/WebSocket";
|
import WebSocket from "../util/WebSocket";
|
||||||
import { onHeartbeat } from "./Heartbeat";
|
import { onHeartbeat } from "./Heartbeat";
|
||||||
import { onIdentify } from "./Identify";
|
import { onIdentify } from "./Identify";
|
||||||
|
import { onLazyRequest } from "./LazyRequest";
|
||||||
import { onPresenceUpdate } from "./PresenceUpdate";
|
import { onPresenceUpdate } from "./PresenceUpdate";
|
||||||
import { onRequestGuildMembers } from "./RequestGuildMembers";
|
import { onRequestGuildMembers } from "./RequestGuildMembers";
|
||||||
import { onResume } from "./Resume";
|
import { onResume } from "./Resume";
|
||||||
@ -14,6 +15,11 @@ export default {
|
|||||||
2: onIdentify,
|
2: onIdentify,
|
||||||
3: onPresenceUpdate,
|
3: onPresenceUpdate,
|
||||||
4: onVoiceStateUpdate,
|
4: onVoiceStateUpdate,
|
||||||
5: onResume,
|
// 5: Voice Server Ping
|
||||||
|
6: onResume,
|
||||||
|
// 7: Reconnect: You should attempt to reconnect and resume immediately.
|
||||||
8: onRequestGuildMembers,
|
8: onRequestGuildMembers,
|
||||||
|
// 9: Invalid Session
|
||||||
|
// 10: Hello
|
||||||
|
14: onLazyRequest,
|
||||||
};
|
};
|
||||||
|
@ -4,9 +4,9 @@ import WebSocket from "../util/WebSocket";
|
|||||||
|
|
||||||
export function check(this: WebSocket, schema: any, data: any) {
|
export function check(this: WebSocket, schema: any, data: any) {
|
||||||
try {
|
try {
|
||||||
return instanceOf(schema, data);
|
if (instanceOf(schema, data) !== true) throw "invalid";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// invalid identify struct
|
// invalid payload
|
||||||
this.close(CLOSECODES.Decode_error);
|
this.close(CLOSECODES.Decode_error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,28 @@
|
|||||||
export enum OPCODES {
|
export enum OPCODES {
|
||||||
Dispatch,
|
Dispatch = 0,
|
||||||
Heartbeat,
|
Heartbeat = 1,
|
||||||
Identify,
|
Identify = 2,
|
||||||
Presence_Update,
|
Presence_Update = 3,
|
||||||
Voice_State_Update,
|
Voice_State_Update = 4,
|
||||||
Dummy_Value, // ? What is opcode 5?
|
Voice_Server_Ping = 5, // ? What is opcode 5?
|
||||||
Resume,
|
Resume = 6,
|
||||||
Reconnect,
|
Reconnect = 7,
|
||||||
Request_Guild_Members,
|
Request_Guild_Members = 8,
|
||||||
Invalid_Session,
|
Invalid_Session = 9,
|
||||||
Hello,
|
Hello = 10,
|
||||||
Heartbeat_ACK,
|
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 {
|
export enum CLOSECODES {
|
||||||
Unknown_error = 4000,
|
Unknown_error = 4000,
|
||||||
|
Loading…
Reference in New Issue
Block a user