Skip to content

Commit f37daf4

Browse files
committedDec 24, 2020
Add boss server
1 parent a55de7b commit f37daf4

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed
 

‎bin/aimserver

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
const authHost = process.env.AUTH_HOST;
44
const authPort = process.env.AUTH_PORT;
5+
const bossHost = process.env.BOSS_HOST;
6+
const bossPort = process.env.BOSS_PORT;
57

68
require('../dist/cli')
7-
.cli({ authHost, authPort })
9+
.cli({ authHost, authPort, bossHost, bossPort })
810
.catch(err => {
911
console.error(err);
1012
process.exit(1);

‎src/AIMAuthServer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class AIMAuthServer extends OscarServer {
101101
// persistence is added
102102
email: 'DrewML@users.noreply.github.com',
103103
// Point to BOSS host/port
104-
bosAddress: 'host.test:5190',
104+
bosAddress: 'host.test:5191',
105105
// TODO: Stop hardcoding BOSS cookie
106106
authCookie: '111111111',
107107
latestBetaVersion: '8.1.4',

‎src/BossServer.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import assert from 'assert';
2+
import { OscarServer, OscarSocket } from './OscarServer';
3+
4+
export class BossServer extends OscarServer {
5+
onConnection(oscarSocket: OscarSocket) {
6+
assert(false, 'onConnection not implemented in BossServer');
7+
}
8+
}

‎src/OscarServer.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { createServer, Socket, Server, AddressInfo } from 'net';
55
import { MultiMap } from './MultiMap';
66

77
interface OscarServerOpts {
8-
port?: number;
9-
host?: string;
8+
port: number;
9+
host: string;
1010
}
1111

1212
export class OscarServer {
@@ -15,8 +15,8 @@ export class OscarServer {
1515
private port: number;
1616

1717
constructor(opts: OscarServerOpts) {
18-
this.host = opts.host ?? '0.0.0.0';
19-
this.port = opts.port ?? 5190;
18+
this.host = opts.host;
19+
this.port = opts.port;
2020

2121
this.server = createServer((socket) => {
2222
this.onConnection(new OscarSocket(socket));
@@ -92,6 +92,11 @@ export class OscarSocket {
9292

9393
private onData(data: Buffer) {
9494
const flap = parseFlap(data);
95+
assert(
96+
this.channelListeners.has(flap.channel),
97+
`Channel ${flap.channel} has no handler in OscarSocket}`,
98+
);
99+
95100
const listeners = this.channelListeners.get(flap.channel);
96101
for (const listener of listeners) {
97102
listener(flap);

‎src/cli.ts

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
1+
import { BossServer } from './BossServer';
12
import { AIMAuthServer } from './AIMAuthServer';
23

34
interface CLIOpts {
45
authHost?: string;
56
authPort?: string;
7+
bossHost?: string;
8+
bossPort?: string;
69
}
710

811
export async function cli(opts: CLIOpts) {
912
const authServer = new AIMAuthServer({
10-
host: opts.authHost,
11-
port: (opts.authPort && Number(opts.authPort)) || undefined,
13+
host: opts.authHost || '0.0.0.0',
14+
port: (opts.authPort && Number(opts.authPort)) || 5190,
1215
});
1316

14-
const { address, port } = await authServer.start();
15-
console.log(`Auth Service listening on ${address}:${port}`);
17+
const bossServer = new BossServer({
18+
host: opts.bossHost || '0.0.0.0',
19+
port: (opts.bossPort && Number(opts.bossPort)) || 5191,
20+
});
21+
22+
const [auth, boss] = await Promise.all([
23+
authServer.start(),
24+
bossServer.start(),
25+
]);
26+
27+
console.log(`Auth Service listening on ${auth.address}:${auth.port}`);
28+
console.log(`Boss Service listening on ${boss.address}: ${boss.port}`);
1629
}

0 commit comments

Comments
 (0)
Please sign in to comment.