From 471d1d6b28f8a6b62680408756e389e8a0b71be0 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sat, 6 Feb 2021 17:08:08 +0100 Subject: :sparkles: Base Server --- client.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'client.js') diff --git a/client.js b/client.js index 7e8c6d5c..ceb97bdd 100644 --- a/client.js +++ b/client.js @@ -1,9 +1,11 @@ +require("missing-native-js-functions"); const WebSocket = require("ws"); +const Constants = require("./dist/util/Constants"); const ws = new WebSocket("ws://127.0.0.1:8080"); ws.on("open", () => { - ws.send(JSON.stringify({ req_type: "new_auth" })); + // ws.send(JSON.stringify({ req_type: "new_auth" })); // ws.send(JSON.stringify({ req_type: "check_auth", token: "" })); // op: 0, // d: {}, @@ -11,6 +13,33 @@ ws.on("open", () => { // t: "GATEWAY_EVENT_NAME", }); -ws.on("message", (data) => { +function send(data) { + ws.send(JSON.stringify(data)); +} + +ws.on("message", (buffer) => { + let data = JSON.parse(buffer.toString()); console.log(data); + + switch (data.op) { + case 10: + setIntervalNow(() => { + send({ op: 1 }); + }, data.d.heartbeat_interval); + + send({ + op: 2, + d: { + token: "", + intents: 0n, + properties: {}, + }, + }); + + break; + } +}); + +ws.on("close", (code, reason) => { + console.log(code, reason, Constants.CLOSECODES[code]); }); -- cgit 1.5.1