mirror of
https://github.com/djhackersdev/minime.git
synced 2026-04-26 01:47:22 -05:00
Switch to TypeScript
This just makes the minimum changes necessary to "compile".
This commit is contained in:
parent
e51f428a41
commit
2f1c9dd476
|
|
@ -9,7 +9,7 @@ insert_final_newline = true
|
|||
trim_trailing_whitespace = true
|
||||
max_line_length = 79
|
||||
|
||||
[*.js]
|
||||
[*.ts]
|
||||
indent_size = 2
|
||||
|
||||
[*.json]
|
||||
|
|
|
|||
19
package.json
19
package.json
|
|
@ -11,12 +11,25 @@
|
|||
"morgan": "^1.9.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "jest",
|
||||
"start": "node src/index.js"
|
||||
"start": "ts-node src/index.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^23.6.0",
|
||||
"prettier": "^1.16.4"
|
||||
"@types/express": "^4.16.1",
|
||||
"@types/jest": "^24.0.11",
|
||||
"@types/node": "^11.11.3",
|
||||
"jest": "^24.5.0",
|
||||
"jest-haste-map": "^24.5.0",
|
||||
"jest-resolve": "^24.5.0",
|
||||
"prettier": "^1.16.4",
|
||||
"ts-jest": "^24.0.0",
|
||||
"ts-node": "^8.0.3",
|
||||
"typescript": "^3.3.3333"
|
||||
},
|
||||
"jest": {
|
||||
"preset": "ts-jest",
|
||||
"testEnvironment": "node"
|
||||
},
|
||||
"prettier": {
|
||||
"trailingComma": "es5"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const { Decoder } = require("./cmd");
|
||||
import { Decoder } from "./cmd";
|
||||
|
||||
function decode(req) {
|
||||
const decoder = new Decoder();
|
||||
const decoder = new Decoder({});
|
||||
|
||||
decoder.write(req);
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
const { Transform } = require("stream");
|
||||
import { Transform } from "stream";
|
||||
|
||||
class Decoder extends Transform {
|
||||
export class Decoder extends Transform {
|
||||
constructor(options) {
|
||||
super({
|
||||
readableObjectMode: true,
|
||||
|
|
@ -95,7 +95,13 @@ class Decoder extends Transform {
|
|||
}
|
||||
}
|
||||
|
||||
class Encoder extends Transform {
|
||||
const registerLevels = {
|
||||
none: 0,
|
||||
portal: 1,
|
||||
segaid: 2,
|
||||
};
|
||||
|
||||
export class Encoder extends Transform {
|
||||
constructor(options) {
|
||||
super({
|
||||
readableObjectMode: true,
|
||||
|
|
@ -147,7 +153,7 @@ class Encoder extends Transform {
|
|||
buf.writeUInt16LE(0x0010, 0x0004); // cmd code
|
||||
buf.writeUInt16LE(chunk.status, 0x0008);
|
||||
buf.writeInt32LE(chunk.aimeId || -1, 0x0020);
|
||||
buf.writeUInt8(Encoder.registerLevels[chunk.registerLevel], 0x0024);
|
||||
buf.writeUInt8(registerLevels[chunk.registerLevel], 0x0024);
|
||||
|
||||
break;
|
||||
|
||||
|
|
@ -167,7 +173,7 @@ class Encoder extends Transform {
|
|||
break;
|
||||
|
||||
default:
|
||||
return callback(new Error(`Unimplemented response: ${cmd}`));
|
||||
return callback(new Error(`Unimplemented response: ${chunk.cmd}`));
|
||||
}
|
||||
|
||||
console.log("Aimedb: Send", buf);
|
||||
|
|
@ -175,14 +181,3 @@ class Encoder extends Transform {
|
|||
return callback(null, buf);
|
||||
}
|
||||
}
|
||||
|
||||
Encoder.registerLevels = {
|
||||
none: 0,
|
||||
portal: 1,
|
||||
segaid: 2,
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
Decoder,
|
||||
Encoder,
|
||||
};
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
const { Transform } = require("stream");
|
||||
import { Transform } from "stream";
|
||||
|
||||
export class Deframer extends Transform {
|
||||
private state: Buffer;
|
||||
|
||||
class Deframer extends Transform {
|
||||
constructor(options) {
|
||||
super({
|
||||
readableObjectMode: true,
|
||||
|
|
@ -38,7 +40,3 @@ class Deframer extends Transform {
|
|||
return callback(null, frame);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Deframer,
|
||||
};
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
const setup = require("./pipeline");
|
||||
import { setup } from "./pipeline";
|
||||
|
||||
async function aimedb(socket) {
|
||||
export default async function aimedb(socket) {
|
||||
console.log("Aimedb: Connection opened");
|
||||
|
||||
const { input, output } = setup(socket);
|
||||
|
|
@ -62,5 +62,3 @@ async function aimedb(socket) {
|
|||
console.log("Aimedb: Connection closed\n");
|
||||
socket.end();
|
||||
}
|
||||
|
||||
module.exports = aimedb;
|
||||
|
|
@ -1,20 +1,20 @@
|
|||
const crypto = require("crypto");
|
||||
const { pipeline } = require("stream");
|
||||
import * as crypto from "crypto";
|
||||
import { pipeline } from "stream";
|
||||
|
||||
const { Deframer } = require("./frame");
|
||||
const { Decoder, Encoder } = require("./cmd");
|
||||
import { Decoder, Encoder } from "./cmd";
|
||||
import { Deframer } from "./frame";
|
||||
|
||||
const K = Buffer.from("Copyright(C)SEGA", "utf8");
|
||||
|
||||
function setup(socket) {
|
||||
export function setup(socket) {
|
||||
const input = pipeline(
|
||||
socket,
|
||||
crypto.createDecipheriv("aes-128-ecb", K, null).setAutoPadding(false),
|
||||
new Deframer(),
|
||||
new Decoder()
|
||||
new Deframer({}),
|
||||
new Decoder({})
|
||||
);
|
||||
|
||||
const output = new Encoder();
|
||||
const output = new Encoder({});
|
||||
|
||||
pipeline(
|
||||
output,
|
||||
|
|
@ -24,5 +24,3 @@ function setup(socket) {
|
|||
|
||||
return { input, output };
|
||||
}
|
||||
|
||||
module.exports = setup;
|
||||
|
|
@ -1,8 +1,12 @@
|
|||
const bodyParser = require("body-parser");
|
||||
const express = require("express");
|
||||
const crypto = require("crypto");
|
||||
const zlib = require("zlib");
|
||||
const fs = require("fs");
|
||||
import bodyParser = require("body-parser");
|
||||
import express = require("express");
|
||||
import * as crypto from "crypto";
|
||||
import * as zlib from "zlib";
|
||||
import * as fs from "fs";
|
||||
|
||||
interface Kvps {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
const billingKeyPair = fs.readFileSync("pki/billing.key");
|
||||
|
||||
|
|
@ -13,7 +17,7 @@ const nearfull = 0x00010200;
|
|||
|
||||
const app = express();
|
||||
|
||||
function decodeRequest(buf) {
|
||||
function decodeRequest(buf): Kvps[] {
|
||||
const reqBytes = zlib.inflateRawSync(buf);
|
||||
const reqStr = reqBytes.toString();
|
||||
|
||||
|
|
@ -73,25 +77,25 @@ app.post("/request/", function(req, resp) {
|
|||
|
||||
// Assemble other params
|
||||
|
||||
const respItems = [];
|
||||
const respItems: Kvps[] = [];
|
||||
|
||||
respItems.push({
|
||||
// 0 or 6 is success, anything else is an error
|
||||
result: 0,
|
||||
result: "0",
|
||||
|
||||
// ???
|
||||
waittime: 100,
|
||||
waittime: "100",
|
||||
|
||||
// Some sort of bandwidth-limiting thing..?
|
||||
// "line" refers to the shop's internet connection
|
||||
linelimit: 1,
|
||||
linelimit: "1",
|
||||
|
||||
// Server error message, copied to ALLNet debug log
|
||||
message: "",
|
||||
|
||||
// Keychip odometer limit. Game will lock out if the odometer reaches
|
||||
// this value
|
||||
playlimit,
|
||||
playlimit: playlimit.toString(),
|
||||
|
||||
// RSA-SHA1 signature for new odometer limit.
|
||||
playlimitsig,
|
||||
|
|
@ -103,19 +107,19 @@ app.post("/request/", function(req, resp) {
|
|||
// is the actual "nearfull" value. Not sure exactly what nearfull is, at a
|
||||
// guess it causes the client to check-in with the billing server when the
|
||||
// odometer is fewer than this many ticks away from its current limit.
|
||||
nearfull,
|
||||
nearfull: nearfull.toString(),
|
||||
|
||||
// RSA-SHA1 signature for the 32-bit nearfull value.
|
||||
nearfullsig,
|
||||
|
||||
// ???
|
||||
fixlogcnt: 0,
|
||||
fixlogcnt: "0",
|
||||
|
||||
// ???
|
||||
fixinterval: 5,
|
||||
fixinterval: "5",
|
||||
|
||||
// Monthly play count summary, visible in operator menu. The value below
|
||||
// is for a virgin machine fresh from the factory. Another example might be:
|
||||
// is for a virgin machine fresh from the factory. Another example might be
|
||||
//
|
||||
// 201809/123:201810/456:201811/789
|
||||
//
|
||||
|
|
@ -135,4 +139,4 @@ app.post("/request/", function(req, resp) {
|
|||
resp.send(respStr);
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
export default app;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
const express = require("express");
|
||||
const zlib = require("zlib");
|
||||
import express = require("express");
|
||||
import * as zlib from "zlib";
|
||||
|
||||
const app = express();
|
||||
|
||||
|
|
@ -17,9 +17,11 @@ app.use(function(req, resp, next) {
|
|||
const comp = zlib.deflateSync(buf);
|
||||
|
||||
resp.set("Content-Type", "application/json");
|
||||
resp.set("Content-Length", comp.length);
|
||||
resp.set("Content-Length", comp.length.toString());
|
||||
resp.set("Transfer-Encoding", "deflate");
|
||||
resp.send(comp);
|
||||
|
||||
return resp;
|
||||
};
|
||||
|
||||
next();
|
||||
|
|
@ -38,6 +40,8 @@ app.use(function(req, resp, next) {
|
|||
|
||||
resp.json = prevJson;
|
||||
resp.json.apply(this, arguments);
|
||||
|
||||
return resp;
|
||||
};
|
||||
|
||||
next();
|
||||
|
|
@ -197,4 +201,4 @@ app.post("/ChuniServlet/GetGameChargeApi", function(req, resp) {
|
|||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
export default app;
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
const fs = require("fs");
|
||||
const https = require("https");
|
||||
const http = require("http");
|
||||
const net = require("net");
|
||||
import fs = require("fs");
|
||||
import https = require("https");
|
||||
import http = require("http");
|
||||
import net = require("net");
|
||||
|
||||
const aimedb = require("./aimedb");
|
||||
const billing = require("./billing");
|
||||
const startup = require("./startup");
|
||||
const chunithm = require("./chunithm");
|
||||
import aimedb from "./aimedb";
|
||||
import billing from "./billing";
|
||||
import startup from "./startup";
|
||||
import chunithm from "./chunithm";
|
||||
|
||||
const tls = {
|
||||
cert: fs.readFileSync("pki/server.pem"),
|
||||
|
|
@ -1,14 +1,17 @@
|
|||
const bodyParser = require("body-parser");
|
||||
const leftPad = require("left-pad"); // the infamous...
|
||||
const express = require("express");
|
||||
const zlib = require("zlib");
|
||||
const os = require("os");
|
||||
import bodyParser = require("body-parser");
|
||||
import express = require("express");
|
||||
import * as zlib from "zlib";
|
||||
import * as os from "os";
|
||||
|
||||
interface Kvps {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
const services = new Map();
|
||||
|
||||
services.set("SDBT", 9000); // Chunithm
|
||||
|
||||
function decodeRequest(req) {
|
||||
function decodeRequest(req): Kvps {
|
||||
const buf = Buffer.from(req, "base64");
|
||||
const bytes = zlib.unzipSync(buf);
|
||||
const str = bytes.toString().trim();
|
||||
|
|
@ -89,4 +92,4 @@ app.post("/sys/servlet/PowerOn", function(req, resp) {
|
|||
resp.send(respStrZ);
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
export default app;
|
||||
11
tsconfig.json
Normal file
11
tsconfig.json
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["es2017", "esnext.asynciterable"],
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "./bin/",
|
||||
"strictNullChecks": true,
|
||||
"target": "es2017"
|
||||
},
|
||||
"include": ["./src/"]
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user