Browse Source

checkin

master
Hamcha 6 months ago
commit
e1b0b9f3e2
Signed by: Hamcha GPG Key ID: 41467804B19A3315
9 changed files with 5427 additions and 0 deletions
  1. +33
    -0
      .eslintrc.js
  2. +5
    -0
      .gitignore
  3. +4
    -0
      .prettierrc
  4. +15
    -0
      package.json
  5. +12
    -0
      src/index.html
  6. +14
    -0
      src/index.ts
  7. +58
    -0
      src/network/messages.ts
  8. +6
    -0
      src/style.scss
  9. +5280
    -0
      yarn.lock

+ 33
- 0
.eslintrc.js View 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
- 0
.gitignore View File

@ -0,0 +1,5 @@
dist
.cache
node_modules
generated
debug.log

+ 4
- 0
.prettierrc View File

@ -0,0 +1,4 @@
{
"singleQuote": false,
"endOfLine": "auto"
}

+ 15
- 0
package.json View 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
- 0
src/index.html View 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
- 0
src/index.ts View 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
- 0
src/network/messages.ts View 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
- 0
src/style.scss View File

@ -0,0 +1,6 @@
html,
body {
margin: 0;
padding: 0;
background-color: black;
}

+ 5280
- 0
yarn.lock
File diff suppressed because it is too large
View File


Loading…
Cancel
Save