summary refs log tree commit diff
path: root/src/index.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-02-04 10:25:41 +0100
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-02-04 10:25:41 +0100
commitf5a723d9b491005ec5dd9377802e5d143100e346 (patch)
treec9d7805c918949c05298a11209e8d92dc1e861d9 /src/index.ts
parentUpdate README.md (diff)
downloadserver-f5a723d9b491005ec5dd9377802e5d143100e346.tar.xz
Merge branch 'master' of https://github.com/discord-open-source/discord-gateway into main
Diffstat (limited to 'src/index.ts')
-rw-r--r--src/index.ts43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/index.ts b/src/index.ts
new file mode 100644

index 00000000..45374721 --- /dev/null +++ b/src/index.ts
@@ -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();