From f5a723d9b491005ec5dd9377802e5d143100e346 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Thu, 4 Feb 2021 10:25:41 +0100 Subject: [PATCH] Merge branch 'master' of https://github.com/discord-open-source/discord-gateway into main --- .DS_Store | Bin 0 -> 6148 bytes README.md | 2 +- client.js | 16 ++++++++++ package-lock.json | Bin 0 -> 30445 bytes package.json | 22 +++++++++++++ src/.DS_Store | Bin 0 -> 6148 bytes src/assets/codes.ts | 31 ++++++++++++++++++ src/assets/datastru.ts | 15 +++++++++ src/extras/Database.ts | 5 +++ src/index.ts | 43 +++++++++++++++++++++++++ tsconfig.json | 71 +++++++++++++++++++++++++++++++++++++++++ 11 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 client.js create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 src/.DS_Store create mode 100644 src/assets/codes.ts create mode 100644 src/assets/datastru.ts create mode 100644 src/extras/Database.ts create mode 100644 src/index.ts create mode 100644 tsconfig.json diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..33dabc803464b4de1fcd9c3c073808093f2e696d GIT binary patch literal 6148 zcmeHKOHRWu5FOJ&w$w?eBi{@2(HIc|@vAQ1ezcb=BjGPtP|sEw3L& zE1I{imsrom8E^)i0cXG&AOpCwDbtyv&(44|;0$~)!1Ezu5R+k6EJp{X(gFY*n2SJX zFTtE>m<+QbJdmKNKurzSVgyZxJz88c%!-;W!J3a?mEW6}P^x49Si&VFMW3AkXP{W|bBmkhHaccHzc1N}#!5aN?F@CyvQ0fA>k%>V!Z literal 0 HcmV?d00001 diff --git a/README.md b/README.md index 8a658fde..7ea97482 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # discord-gateway Open Source Discord WebSocket Gateway Server -For the WebSocket we use [ws](https://www.npmjs.com/package/ws) and we'll write our own packet handler for the individual opcodes and events. +## [Wiki](https://github.com/discord-open-source/discord-gateway/wiki/) diff --git a/client.js b/client.js new file mode 100644 index 00000000..7e8c6d5c --- /dev/null +++ b/client.js @@ -0,0 +1,16 @@ +const WebSocket = require("ws"); + +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: "check_auth", token: "" })); + // op: 0, + // d: {}, + // s: 42, + // t: "GATEWAY_EVENT_NAME", +}); + +ws.on("message", (data) => { + console.log(data); +}); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000000000000000000000000000000000000..62ab65ac206e92ef3fce41089b7adaef214edc89 GIT binary patch literal 30445 zcmeHwS(CEZw&45u6&2s(rTrKMy%9H}RX`C?5eMXrh?*Gi{$Vy=_ zVgvi_=KXL47!GfTYkvTshF)Qr%}nepi_-su;lw&PX_nN#gUCOozr*AJ-@t`CE%;6g z=y!HFU4c14W*rhIs~c#kt#whX<8PM5E?CXg=?OQCsIn8hJX9NBww#?4Y@w5Pl1{j+ zY_+LRqjWAH-KiB*0bk;Bp!2@&S=(-$2;**H)>{i6^i#zy|Lec5qux;GjPR8bL1?zC z@E^Zg0{!*ZzuM1#H8i}w<%hu`H1#JW!+(=MC)qn_K(+U)P7Cg9!jZdKJYJx-+trV2 zR&#tv3RyPiNOXIgI1>gP&a5GUt_BFAm>5r;#)M~VYe9%%CF3HT%tfsz8=0 z;jy7$(#wQc{LB-rM`}lkp<%!rq4j9I6TPG#tGNPW120R9G8xAaBG}BfMqms3egn<s*E_C_d(Z|}s3bKx_rH#^lL_HFiukWjkD_B6j>z7Uo?Q1eF)mb?+JeGn)8Sd%y zfkHI@fMaHDsbjTr=v?yEiWdf+bWHH$xE3mi;9a-dThA#PlgtClNu#jHXtz#^Ap zQh7lYo0gs*03m)6kFA%kd0JptX2;hu!+t`stAFtwb#o6IQ0@Lkr-k}w%Ap-cUoCwt zO(-|8SeHETL@-}EXq92c2mR5kI7xJl&x8j3-TjSzTWBs&+xfqb0HzLL{dww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y|9+9mjX(A;zFDZ zjnl?j?AH-J70OUpA$Ep(#I78Ubf*_h2ZhBjX5dchMZH?U{%N@{Z<`sOc@g)=wEw%w zU|j9MMaKVsV&q5d0eAi8k9h89wXiE#z;D+t!0UJ^W1SzZSU0S}@KB0s#Y_Vio6tLq z_JXwv^+N{OKmN4Z>~|9ud613?OD7 z?f|>jG@{??^>*}+9aoKqI@~yuni6vz*e+D8#zU0AtDHSfWZbk?2bT{OrS_G$_8rc=_43=1pRd+!rv8&?w7bY zNXJvs3Ci3xb6ZCYb^*Sv&pcgd&m}z34%JTaX;#Vqv_>nY;OJIdJbxR3um&^ z49+FVEtTu^Dqpbpka^`8)=SpwkI~jA5Wj{ac>#_dWs?a1HH@qOHR@x@#l(Sv5Y6q77*TSMb5 zJ7@fU6$IpDL`R56Nkf|Qz1~S!`%|coOWhfZ%tC`ng3?{N%7&de3J&k15vlFv9u58~ z$KgaRDeF_nbUxes(NZ-Q`TMB05WxzypKUhb1!RW;hp#+zwZ#{OM?5VSPAv6uzAa!5oPs*hA+ZxJ_V=;}1pcFOq3Y`ft>i};zyfd7upD+d6cj|h7^ z+Wn%z?;EHty=ae!^fP{b1KCiiJ#X$c{>@~m56(py#z&=^xjVKPAQJea6MPnZCGR1dtotGL}rx(LB^ptO`H*0`Q}^JrNbkK}4UUsW^jFu}UKU%lF{ zgqJ2bx>Bv6_hIV zidYH)!|9~H>n@>E4YF?Z!pV!be?g`(*8grS=bgWMIh(zG+(e)s#S+luU;p^mKmHfH C2J~zI literal 0 HcmV?d00001 diff --git a/package.json b/package.json new file mode 100644 index 00000000..4573e81a --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "websocket_learn", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "lambert-db": "^1.1.2", + "node-fetch": "^2.6.1", + "uuid": "^8.3.2", + "ws": "^7.4.2" + }, + "devDependencies": { + "@types/uuid": "^8.3.0", + "@types/ws": "^7.4.0" + } +} diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b1f8af5073011d954adf62af3aa5858b02df974c GIT binary patch literal 6148 zcmeHK%}&EG47Rrk4RP6#V@}-n24N~suoqxs6C74`VocgG&&Gpr;~}{5Iku*@q2h+n zWLM6YI(F)Q{c%D>yf|*=L^C3qLIp?HXnqhG7cFFD78&F`#~U4X&-3L|Q|}9JH~dEi zL3goe+6LNT!e0uNE zsy{xMM{AC{8OWpM)6GM^0~cq&8E^(Jo&nTsk?D=1x6Xhw;0&A@kpDw~3P!`En13B; z@)iI%fjJBMc?|^&VgN?NqzDUyH590!Y+DT0aM*+SMZ=`1;l%mMn8&WnwnJfC!Ewm$ z#8J^(XTTZgGBDQDnbiM>;r)L%$j_VsXW*h3;7PTt7Puv=t;NkrtqssesEGI_#d8Qc hxfH`!O7Sf;3+zEUz-X8hVS)HUAk*NDGw`Pjd;?5KO>6)F literal 0 HcmV?d00001 diff --git a/src/assets/codes.ts b/src/assets/codes.ts new file mode 100644 index 00000000..5b9a5546 --- /dev/null +++ b/src/assets/codes.ts @@ -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 {} diff --git a/src/assets/datastru.ts b/src/assets/datastru.ts new file mode 100644 index 00000000..038102ec --- /dev/null +++ b/src/assets/datastru.ts @@ -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; +} diff --git a/src/extras/Database.ts b/src/extras/Database.ts new file mode 100644 index 00000000..9de00f9f --- /dev/null +++ b/src/extras/Database.ts @@ -0,0 +1,5 @@ +import { MongoDatabase } from "lambert-db"; + +const db = new MongoDatabase(); + +export default db; 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 { + 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(); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..f02e8ec0 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,71 @@ +{ + "include": ["src/**/*.ts"], + "exclude": ["*.js", "dist", "marion", "attachments"], + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "ES6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, + "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, + "lib": ["ES2015", "DOM"] /* Specify library files to be included in the compilation. */, + "allowJs": true /* Allow javascript files to be compiled. */, + "checkJs": true /* Report errors in .js files. */, + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + "declaration": true /* Generates corresponding '.d.ts' file. */, + "declarationMap": false /* Generates a sourcemap for each corresponding '.d.ts' file. */, + // "sourceMap": true /* Generates corresponding '.map' file. */, + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "./dist/" /* Redirect output structure to the directory. */, + "rootDir": "./src/" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": false /* Enable all strict type-checking options. */, + "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + "strictPropertyInitialization": false /* Enable strict checking of property initialization in classes. */, + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + "types": ["node"] /* Type declaration files to be included in compilation. */, + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + "inlineSourceMap": true /* Emit a single file with source maps instead of having a separate file. */, + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "skipLibCheck": true /* Skip type checking of declaration files. */, + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } +}