This commit is contained in:
Flam3rboy
2021-02-04 10:25:41 +01:00
parent 1c57e93f81
commit f5a723d9b4
11 changed files with 963 additions and 1 deletions
BIN
View File
Binary file not shown.
+31
View File
@@ -0,0 +1,31 @@
export enum OPCODES {
Dispatch,
Heartbeat,
Identify,
Presence_Update,
Voice_State_Update,
Resume,
Reconnect,
Request_Guild_Members,
Invalid_Session,
Hello,
Heartbeat_ACK,
}
export enum CLOSECODES {
Unknown_error = 4000,
Unknown_opcode,
Decode_error,
Not_authenticated,
Authentication_failed,
Already_authenticated,
Invalid_session,
Invalid_seq,
Rate_limited,
Session_timed_out,
Invalid_shard,
Sharding_required,
Invalid_API_version,
Invalid_intent,
Disallowed_intent,
}
export enum SEQUENCENUM {}
+15
View File
@@ -0,0 +1,15 @@
//* https://discord.com/developers/docs/topics/gateway
import { OPCODES, SEQUENCENUM } from "./codes";
export interface message_prod {
op: OPCODES;
d: object;
s: SEQUENCENUM;
t: string;
}
export interface message_dev {
req_type: "new_auth" | "check_auth";
token?: string;
}
+5
View File
@@ -0,0 +1,5 @@
import { MongoDatabase } from "lambert-db";
const db = new MongoDatabase();
export default db;
+43
View File
@@ -0,0 +1,43 @@
import WebSocket from "ws";
import DB from "./extras/Database";
import { message_dev } from "./assets/datastru";
import { v4 } from "uuid";
class Server {
db: any;
constructor() {
this.db = DB;
}
async listen(): Promise<void> {
await this.db.init();
const wss = new WebSocket.Server({ port: 8080 });
wss.on("connection", (ws) => {
ws.on("message", async (msg: any) => {
const message: message_dev = msg;
if (message.req_type) {
switch (message.req_type) {
case "new_auth":
const token = v4();
await this.db.data.auth.push({ token });
return ws.send({ new_token: token });
case "check_auth":
if (!message.token) {
return ws.send({ error: "token not providen" });
}
return this.db.data.auth({ token: message.token }).get();
}
} else {
ws.send({ error: "req_type not providen" });
}
});
ws.send("connected");
});
}
}
const s = new Server();
s.listen();