Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
355f20c50b |
@@ -1,25 +0,0 @@
|
|||||||
import { existsSync, readFileSync } from "fs";
|
|
||||||
import * as os from "os";
|
|
||||||
|
|
||||||
const path = "./hostname.txt";
|
|
||||||
let myHostname: string;
|
|
||||||
|
|
||||||
if (!existsSync(path)) {
|
|
||||||
const osHostname = os.hostname();
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Hostname: ${path} does not exist, sending OS hostname "${osHostname}" to clients. This may be unreliable!`
|
|
||||||
);
|
|
||||||
|
|
||||||
myHostname = osHostname;
|
|
||||||
} else {
|
|
||||||
myHostname = readFileSync(path, { encoding: "ascii" }).trim();
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Hostname: Sending configured hostname "${myHostname}" to clients`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function hostname(): string {
|
|
||||||
return myHostname;
|
|
||||||
}
|
|
||||||
@@ -1,23 +1,21 @@
|
|||||||
import { LoadServerListRequest } from "../request/loadServerList";
|
import { LoadServerListRequest } from "../request/loadServerList";
|
||||||
import { LoadServerListResponse } from "../response/loadServerList";
|
import { LoadServerListResponse } from "../response/loadServerList";
|
||||||
import { Repositories } from "../repo";
|
import { Repositories } from "../repo";
|
||||||
import { hostname } from "../../hostname";
|
import { HOST_EXT, PORT_IDZ } from "../../switchboard";
|
||||||
|
|
||||||
export function loadServerList(
|
export function loadServerList(
|
||||||
w: Repositories,
|
w: Repositories,
|
||||||
req: LoadServerListRequest
|
req: LoadServerListRequest
|
||||||
): LoadServerListResponse {
|
): LoadServerListResponse {
|
||||||
const myHost = hostname();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: "load_server_list_res",
|
type: "load_server_list_res",
|
||||||
status: 1,
|
status: 1,
|
||||||
userDb: {
|
userDb: {
|
||||||
addr: myHost,
|
addr: HOST_EXT,
|
||||||
tcp: 10000,
|
tcp: 10000,
|
||||||
http: 10001,
|
http: 10001,
|
||||||
},
|
},
|
||||||
matchAddr: myHost,
|
matchAddr: HOST_EXT,
|
||||||
matchPort: {
|
matchPort: {
|
||||||
tcp: 10002,
|
tcp: 10002,
|
||||||
udpSend: 10003,
|
udpSend: 10003,
|
||||||
@@ -29,23 +27,23 @@ export function loadServerList(
|
|||||||
udpRecv: 10007,
|
udpRecv: 10007,
|
||||||
},
|
},
|
||||||
event: {
|
event: {
|
||||||
addr: myHost,
|
addr: HOST_EXT,
|
||||||
tcp: 10008,
|
tcp: 10008,
|
||||||
},
|
},
|
||||||
screenshot: {
|
screenshot: {
|
||||||
addr: myHost,
|
addr: HOST_EXT,
|
||||||
tcp: 10009,
|
tcp: 10009,
|
||||||
},
|
},
|
||||||
pingReturn: myHost,
|
pingReturn: HOST_EXT,
|
||||||
echo1: {
|
echo1: {
|
||||||
addr: myHost,
|
addr: HOST_EXT,
|
||||||
udp: 10010,
|
udp: 10010,
|
||||||
},
|
},
|
||||||
echo2: {
|
echo2: {
|
||||||
addr: myHost,
|
addr: HOST_EXT,
|
||||||
udp: 10011,
|
udp: 10011,
|
||||||
},
|
},
|
||||||
newsUrl: `http://${myHost}:10012/news`,
|
newsUrl: `http://${HOST_EXT}:10012/news`,
|
||||||
reportErrorUrl: `http://${myHost}:10013/error`,
|
reportErrorUrl: `http://${HOST_EXT}:10013/error`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
import { createSocket } from "dgram";
|
import { createSocket } from "dgram";
|
||||||
|
|
||||||
export default function createPing(port: number) {
|
export default function createPing(port: number, host: string) {
|
||||||
const socket = createSocket("udp4");
|
const socket = createSocket("udp4");
|
||||||
|
|
||||||
socket.bind(port);
|
socket.bind(port, host);
|
||||||
socket.on("message", (msg, rinfo) => {
|
socket.on("message", (msg, rinfo) => {
|
||||||
console.log(`Idz Ping: Ping from ${rinfo.address}:${rinfo.port}`);
|
console.log(`Idz Ping: Ping from ${rinfo.address}:${rinfo.port}`);
|
||||||
socket.send(msg, rinfo.port, rinfo.address);
|
socket.send(msg, rinfo.port, rinfo.address);
|
||||||
|
|||||||
+11
-10
@@ -12,23 +12,24 @@ import diva from "./diva";
|
|||||||
import idz from "./idz";
|
import idz from "./idz";
|
||||||
import idzPing from "./idz/ping";
|
import idzPing from "./idz/ping";
|
||||||
import startup from "./startup";
|
import startup from "./startup";
|
||||||
|
import * as Swb from "./switchboard";
|
||||||
|
|
||||||
const tls = {
|
const tls = {
|
||||||
cert: fs.readFileSync("pki/server.pem"),
|
cert: fs.readFileSync("pki/server.pem"),
|
||||||
key: fs.readFileSync("pki/server.key"),
|
key: fs.readFileSync("pki/server.key"),
|
||||||
};
|
};
|
||||||
|
|
||||||
net.createServer(aimedb).listen(22345);
|
net.createServer(aimedb).listen(Swb.PORT_AIMEDB, Swb.HOST_INT);
|
||||||
http.createServer(startup).listen(80);
|
http.createServer(startup).listen(Swb.PORT_STARTUP, Swb.HOST_INT);
|
||||||
https.createServer(tls, billing).listen(8443);
|
https.createServer(tls, billing).listen(Swb.PORT_BILLING, Swb.HOST_INT);
|
||||||
|
|
||||||
http.createServer(chunithm).listen(9000);
|
http.createServer(chunithm).listen(Swb.PORT_CHUNITHM, Swb.HOST_INT);
|
||||||
http.createServer(diva).listen(9001);
|
http.createServer(diva).listen(Swb.PORT_DIVA, Swb.HOST_INT);
|
||||||
|
|
||||||
net.createServer(idz).listen(10000);
|
net.createServer(idz).listen(Swb.PORT_IDZ.USERDB.TCP, Swb.HOST_INT);
|
||||||
idzPing(10001);
|
idzPing(10001, Swb.HOST_INT); // ?? tbd
|
||||||
idzPing(10003);
|
idzPing(Swb.PORT_IDZ.MATCH.UDP_SEND, Swb.HOST_INT);
|
||||||
idzPing(10010);
|
idzPing(Swb.PORT_IDZ.ECHO1, Swb.HOST_INT);
|
||||||
idzPing(10011);
|
idzPing(Swb.PORT_IDZ.ECHO2, Swb.HOST_INT);
|
||||||
|
|
||||||
console.log("Startup OK");
|
console.log("Startup OK");
|
||||||
|
|||||||
+3
-13
@@ -5,19 +5,9 @@ import read = require("raw-body");
|
|||||||
|
|
||||||
import { unzipSync } from "zlib";
|
import { unzipSync } from "zlib";
|
||||||
|
|
||||||
import { hostname } from "./hostname";
|
import { startupHost, startupUri } from "./switchboard";
|
||||||
|
|
||||||
const hourDelta = parseInt(process.env.HOUR_DELTA || "0");
|
const hourDelta = parseInt(process.env.HOUR_DELTA || "0");
|
||||||
const myHost = hostname();
|
|
||||||
const uris = new Map<string, string>();
|
|
||||||
|
|
||||||
uris.set("SDBT", `http://${myHost}:9000/`); // Chunithm
|
|
||||||
uris.set("SBZV", `http://${myHost}:9001/`); // Project Diva Future Tone
|
|
||||||
|
|
||||||
const hosts = new Map<string, string>();
|
|
||||||
|
|
||||||
hosts.set("SDDF", `${myHost}:10000`); // Initial D Zero
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
// Startup request is url-encoded-ish... except it's also zlibed and base64ed.
|
// Startup request is url-encoded-ish... except it's also zlibed and base64ed.
|
||||||
@@ -80,8 +70,8 @@ app.post("/sys/servlet/PowerOn", function(req, resp) {
|
|||||||
|
|
||||||
const resParams = {
|
const resParams = {
|
||||||
stat: 1,
|
stat: 1,
|
||||||
uri: uris.get(req.body.game_id) || "",
|
uri: startupUri(req.body.game_id),
|
||||||
host: hosts.get(req.body.game_id) || "",
|
host: startupHost(req.body.game_id),
|
||||||
place_id: "123",
|
place_id: "123",
|
||||||
name: process.env.SHOP_NAME,
|
name: process.env.SHOP_NAME,
|
||||||
nickname: process.env.SHOP_NAME,
|
nickname: process.env.SHOP_NAME,
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
import * as os from "os";
|
||||||
|
|
||||||
|
const cfgHostExt: string | undefined = process.env.HOST_EXT;
|
||||||
|
const cfgHostInt: string | undefined = process.env.HOST_INT;
|
||||||
|
|
||||||
|
export const HOST_EXT = cfgHostExt !== undefined ? cfgHostExt : os.hostname();
|
||||||
|
export const HOST_INT = cfgHostInt !== undefined ? cfgHostInt : "127.0.0.1";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Core services. These ports cannot be changed
|
||||||
|
//
|
||||||
|
|
||||||
|
export const PORT_AIMEDB = 22345;
|
||||||
|
export const PORT_BILLING = 8443;
|
||||||
|
export const PORT_STARTUP = 80;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Title services. These can be freely chosen.
|
||||||
|
//
|
||||||
|
|
||||||
|
export const PORT_CHUNITHM = 9001;
|
||||||
|
export const PORT_DIVA = 9000;
|
||||||
|
export const PORT_IDZ = {
|
||||||
|
// Most of these seem to be unused relics
|
||||||
|
|
||||||
|
USERDB: {
|
||||||
|
TCP: 10000,
|
||||||
|
HTTP: 10001,
|
||||||
|
},
|
||||||
|
MATCH: {
|
||||||
|
TCP: 10002,
|
||||||
|
UDP_SEND: 10003,
|
||||||
|
UDP_RECV: 10004,
|
||||||
|
},
|
||||||
|
TAG_MATCH: {
|
||||||
|
TCP: 10005,
|
||||||
|
UDP_SEND: 10006,
|
||||||
|
UDP_RECV: 10007,
|
||||||
|
},
|
||||||
|
EVENT: 10008,
|
||||||
|
SCREENSHOT: 10009,
|
||||||
|
ECHO1: 10010,
|
||||||
|
ECHO2: 10011,
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Startup responses
|
||||||
|
//
|
||||||
|
|
||||||
|
const startupHosts = new Map<string, string>();
|
||||||
|
|
||||||
|
startupHosts.set("SDDF", `${HOST_EXT}:${PORT_IDZ.USERDB.TCP}`);
|
||||||
|
|
||||||
|
const startupUris = new Map<string, string>();
|
||||||
|
|
||||||
|
startupUris.set("SDBT", `http://${HOST_EXT}:${PORT_CHUNITHM}/`);
|
||||||
|
startupUris.set("SBZV", `http://${HOST_EXT}:${PORT_DIVA}/`);
|
||||||
|
|
||||||
|
export function startupHost(model: string): string {
|
||||||
|
const val = startupHosts.get(model);
|
||||||
|
|
||||||
|
return val !== undefined ? val : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function startupUri(model: string): string {
|
||||||
|
const val = startupUris.get(model);
|
||||||
|
|
||||||
|
return val !== undefined ? val : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Diagnostic dump
|
||||||
|
//
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Switchboard: HOST_EXT: ${HOST_EXT} (Service host name sent to clients)`
|
||||||
|
);
|
||||||
|
console.log(`Switchboard: HOST_INT: ${HOST_INT} (Bind address)`);
|
||||||
|
|
||||||
|
if (cfgHostExt === undefined || cfgHostInt === undefined) {
|
||||||
|
console.log(
|
||||||
|
"Switchboard: Warning: Check .env and env vars! Using unreliable fallback."
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user