checkin
This commit is contained in:
commit
e1b0b9f3e2
9 changed files with 5427 additions and 0 deletions
33
.eslintrc.js
Normal file
33
.eslintrc.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
module.exports = {
|
||||
env: {
|
||||
browser: true,
|
||||
es2020: true,
|
||||
},
|
||||
extends: [
|
||||
"airbnb-base",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:prettier/recommended",
|
||||
],
|
||||
parser: "@typescript-eslint/parser",
|
||||
plugins: ["@typescript-eslint", "prettier", "react-hooks"],
|
||||
rules: {
|
||||
"prettier/prettier": "error",
|
||||
"one-var": "off", // WHO CARES?????
|
||||
"no-use-before-define": "off", // YOU ARE WRONG
|
||||
"import/extensions": "off",
|
||||
"import/no-unresolved": "off",
|
||||
"no-param-reassign": "off",
|
||||
"no-alert": "off",
|
||||
"no-console": "off",
|
||||
"func-names": "off",
|
||||
"dot-notation": ["error", { allowPattern: "^[A-Z][a-z]+$" }],
|
||||
"@typescript-eslint/ban-ts-comment": [
|
||||
"error",
|
||||
{
|
||||
"ts-expect-error": "allow-with-description",
|
||||
},
|
||||
],
|
||||
"react-hooks/rules-of-hooks": "error",
|
||||
"react-hooks/exhaustive-deps": "warn",
|
||||
},
|
||||
};
|
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
dist
|
||||
.cache
|
||||
node_modules
|
||||
generated
|
||||
debug.log
|
4
.prettierrc
Normal file
4
.prettierrc
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"singleQuote": false,
|
||||
"endOfLine": "auto"
|
||||
}
|
15
package.json
Normal file
15
package.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "client",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@msgpack/msgpack": "^2.2.0",
|
||||
"parcel-bundler": "^1.12.4",
|
||||
"sass": "^1.26.11",
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "parcel src/index.html"
|
||||
}
|
||||
}
|
12
src/index.html
Normal file
12
src/index.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>NSS Odyssey</title>
|
||||
<link rel="stylesheet" href="style.scss" />
|
||||
</head>
|
||||
<body>
|
||||
<script src="index.ts"></script>
|
||||
</body>
|
||||
</html>
|
14
src/index.ts
Normal file
14
src/index.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import messages, { decode } from "./network/messages";
|
||||
|
||||
const url = "ws://localhost:9000";
|
||||
const protocols = ["odyssey-1-unstable"];
|
||||
const webSocket = new WebSocket(url, protocols);
|
||||
webSocket.binaryType = "arraybuffer";
|
||||
webSocket.onopen = function (event) {
|
||||
console.log(event);
|
||||
webSocket.send(messages.Hello());
|
||||
};
|
||||
webSocket.onmessage = function (ev) {
|
||||
const data = decode(ev.data);
|
||||
console.log("Received ", data);
|
||||
};
|
58
src/network/messages.ts
Normal file
58
src/network/messages.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
import { encode as encodeMP, decode as decodeMP } from "@msgpack/msgpack";
|
||||
|
||||
const CLIENT_PROTOCOL = "odynet-a1";
|
||||
|
||||
interface ServerCmdHello {
|
||||
type: "Hello";
|
||||
server_name: string;
|
||||
protocol_ver: string;
|
||||
}
|
||||
|
||||
interface ServerCmdError {
|
||||
type: "Error";
|
||||
error_msg: string;
|
||||
}
|
||||
|
||||
type ServerMessage = ServerCmdHello | ServerCmdError;
|
||||
|
||||
interface ClientCmdHello {
|
||||
type: "Hello";
|
||||
}
|
||||
|
||||
type ClientMessage = ClientCmdHello;
|
||||
|
||||
export enum ServerMessageCode {
|
||||
Hello = 0,
|
||||
Error = 1,
|
||||
}
|
||||
|
||||
export enum ClientMessageCode {
|
||||
Hello = 0,
|
||||
}
|
||||
|
||||
export function decode(data: ArrayBuffer): ServerMessage {
|
||||
const obj = decodeMP(data);
|
||||
const msgtype = parseInt(Object.keys(obj)[0], 10) as ServerMessageCode;
|
||||
const payload = obj[msgtype] as any[];
|
||||
switch (msgtype) {
|
||||
case ServerMessageCode.Hello:
|
||||
return {
|
||||
type: "Hello",
|
||||
server_name: payload[0],
|
||||
protocol_ver: payload[1],
|
||||
};
|
||||
case ServerMessageCode.Error:
|
||||
return { type: "Error", error_msg: payload[0] };
|
||||
}
|
||||
}
|
||||
|
||||
export function encode(data: ClientMessage) {
|
||||
switch (data.type) {
|
||||
case "Hello":
|
||||
return encodeMP({ Hello: [] });
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
Hello: () => encode({ type: "Hello" }),
|
||||
};
|
6
src/style.scss
Normal file
6
src/style.scss
Normal file
|
@ -0,0 +1,6 @@
|
|||
html,
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: black;
|
||||
}
|
Loading…
Reference in a new issue