[go: nahoru, domu]

Skip to content

Commit

Permalink
Add boss server
Browse files Browse the repository at this point in the history
  • Loading branch information
DrewML committed Dec 24, 2020
1 parent a55de7b commit f37daf4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
4 changes: 3 additions & 1 deletion bin/aimserver
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

const authHost = process.env.AUTH_HOST;
const authPort = process.env.AUTH_PORT;
const bossHost = process.env.BOSS_HOST;
const bossPort = process.env.BOSS_PORT;

require('../dist/cli')
.cli({ authHost, authPort })
.cli({ authHost, authPort, bossHost, bossPort })
.catch(err => {
console.error(err);
process.exit(1);
Expand Down
2 changes: 1 addition & 1 deletion src/AIMAuthServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class AIMAuthServer extends OscarServer {
// persistence is added
email: 'DrewML@users.noreply.github.com',
// Point to BOSS host/port
bosAddress: 'host.test:5190',
bosAddress: 'host.test:5191',
// TODO: Stop hardcoding BOSS cookie
authCookie: '111111111',
latestBetaVersion: '8.1.4',
Expand Down
8 changes: 8 additions & 0 deletions src/BossServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import assert from 'assert';
import { OscarServer, OscarSocket } from './OscarServer';

export class BossServer extends OscarServer {
onConnection(oscarSocket: OscarSocket) {
assert(false, 'onConnection not implemented in BossServer');
}
}
13 changes: 9 additions & 4 deletions src/OscarServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { createServer, Socket, Server, AddressInfo } from 'net';
import { MultiMap } from './MultiMap';

interface OscarServerOpts {
port?: number;
host?: string;
port: number;
host: string;
}

export class OscarServer {
Expand All @@ -15,8 +15,8 @@ export class OscarServer {
private port: number;

constructor(opts: OscarServerOpts) {
this.host = opts.host ?? '0.0.0.0';
this.port = opts.port ?? 5190;
this.host = opts.host;
this.port = opts.port;

this.server = createServer((socket) => {
this.onConnection(new OscarSocket(socket));
Expand Down Expand Up @@ -92,6 +92,11 @@ export class OscarSocket {

private onData(data: Buffer) {
const flap = parseFlap(data);
assert(
this.channelListeners.has(flap.channel),
`Channel ${flap.channel} has no handler in OscarSocket}`,
);

const listeners = this.channelListeners.get(flap.channel);
for (const listener of listeners) {
listener(flap);
Expand Down
21 changes: 17 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import { BossServer } from './BossServer';
import { AIMAuthServer } from './AIMAuthServer';

interface CLIOpts {
authHost?: string;
authPort?: string;
bossHost?: string;
bossPort?: string;
}

export async function cli(opts: CLIOpts) {
const authServer = new AIMAuthServer({
host: opts.authHost,
port: (opts.authPort && Number(opts.authPort)) || undefined,
host: opts.authHost || '0.0.0.0',
port: (opts.authPort && Number(opts.authPort)) || 5190,
});

const { address, port } = await authServer.start();
console.log(`Auth Service listening on ${address}:${port}`);
const bossServer = new BossServer({
host: opts.bossHost || '0.0.0.0',
port: (opts.bossPort && Number(opts.bossPort)) || 5191,
});

const [auth, boss] = await Promise.all([
authServer.start(),
bossServer.start(),
]);

console.log(`Auth Service listening on ${auth.address}:${auth.port}`);
console.log(`Boss Service listening on ${boss.address}: ${boss.port}`);
}

0 comments on commit f37daf4

Please sign in to comment.