[go: nahoru, domu]

Skip to content

Commit

Permalink
Few more snacks in the boss server login sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
DrewML committed Dec 25, 2020
1 parent ea87e8f commit 98f4826
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 24 deletions.
28 changes: 25 additions & 3 deletions src/BossServer/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { timingSafeEqual } from 'crypto';
import { parseCookieRequest } from './clientSnacs';
import { OscarServer, OscarSocket } from '../OscarServer';
import { supportedFamiliesSnac } from './serverSnacs';
import { assert } from 'console';
import {
supportedFamiliesSnac,
familyVersionsSnac,
rateLimitInfoSnac,
} from './serverSnacs';
import assert from 'assert';
import { parseSnac, matchSnac } from '../snacUtils';

export class BossServer extends OscarServer {
onConnection(oscarSocket: OscarSocket) {
Expand All @@ -26,7 +31,24 @@ export class BossServer extends OscarServer {
});

oscarSocket.onChannel(0x2, (flap) => {
console.log('boss channel 2 flap: ', flap);
const snac = parseSnac(flap.data);

if (matchSnac(snac, 'GENERAL', 'CLIENT_FAMILY_VERSIONS')) {
return oscarSocket.write({
channel: 2,
data: familyVersionsSnac({ reqID: snac.requestID }),
});
}

if (matchSnac(snac, 'GENERAL', 'RATE_REQUEST')) {
assert(false, 'snac 01,07 not implemented yet');
return oscarSocket.write({
channel: 2,
data: rateLimitInfoSnac({ reqID: snac.requestID }),
});
}

console.log('boss unhandled channel 2 flap: ', flap);
});

oscarSocket.onChannel(0x3, (flap) => {
Expand Down
71 changes: 50 additions & 21 deletions src/BossServer/serverSnacs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { buildSnac } from '../snacUtils';
import { SNACS } from '../constants';
import { endianness } from 'os';
import { uint16BEBuffer } from '../buf';

/**
* @see http://iserverd.khstu.ru/oscar/snac_01_03.html
Expand All @@ -9,30 +9,59 @@ export function supportedFamiliesSnac(opts: { reqID: number }) {
/**
* @see http://iserverd.khstu.ru/oscar/families.html
*/
const families = Buffer.from(
Uint16Array.from([
SNACS.GENERAL.family,
SNACS.LOCATION.family,
SNACS.BUDDYLIST.family,
SNACS.ICBM.family,
SNACS.INVITATION.family,
SNACS.ADMINISTRATIVE.family,
SNACS.POPUP_NOTICE.family,
SNACS.PRIVACY_MGMT.family,
SNACS.USER_LOOKUP.family,
SNACS.USAGE_STATS.family,
SNACS.SSI.family,
SNACS.OFFLINE.family,
]).buffer,
);
// There has to be less noisy sugar for generating a BE
// list of 16 bit ints...
if (endianness() === 'LE') families.swap16();
const families = uint16BEBuffer([
SNACS.GENERAL.family,
SNACS.LOCATION.family,
SNACS.BUDDYLIST.family,
SNACS.ICBM.family,
SNACS.INVITATION.family,
SNACS.ADMINISTRATIVE.family,
SNACS.POPUP_NOTICE.family,
SNACS.PRIVACY_MGMT.family,
SNACS.USER_LOOKUP.family,
SNACS.USAGE_STATS.family,
SNACS.SSI.family,
SNACS.OFFLINE.family,
]);

return buildSnac({
family: SNACS.GENERAL.family,
subtype: SNACS.GENERAL.subtypes.SUPPORTED_FAMILIES,
reqID: opts.reqID,
data: Buffer.from(Uint16Array.from(families).buffer).swap16(),
data: families,
});
}

/**
* @see http://iserverd.khstu.ru/oscar/snac_01_18.html
*/
export function familyVersionsSnac(opts: { reqID: number }) {
// prettier-ignore
const versions = uint16BEBuffer([
// family, version
SNACS.GENERAL.family, 0x3,
SNACS.LOCATION.family, 0x1,
SNACS.BUDDYLIST.family, 0x1,
SNACS.ICBM.family, 0x1,
SNACS.INVITATION.family, 0x1,
SNACS.ADMINISTRATIVE.family, 0x1,
SNACS.POPUP_NOTICE.family, 0x1,
SNACS.PRIVACY_MGMT.family, 0x1,
SNACS.USER_LOOKUP.family, 0x1,
SNACS.USAGE_STATS.family, 0x1,
SNACS.SSI.family, 0x1,
SNACS.OFFLINE.family, 0x1,
]);

return buildSnac({
family: SNACS.GENERAL.family,
subtype: SNACS.GENERAL.subtypes.SERVER_FAMILY_VERSIONS,
reqID: opts.reqID,
data: versions,
});
}

export function rateLimitInfoSnac(opts: { reqID: number }) {
// TODO: Implement
return Buffer.alloc(0);
}
12 changes: 12 additions & 0 deletions src/buf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { endianness } from 'os';

const isLE = endianness() === 'LE';

/**
* @summary Create a UInt16BE buffer from an array of integers
*/
export function uint16BEBuffer(array: number[]) {
const buf = Buffer.from(Uint16Array.from(array).buffer);
if (isLE) buf.swap16();
return buf;
}
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export const SNACS = {
family: 0x1,
subtypes: {
SUPPORTED_FAMILIES: 0x3,
CLIENT_FAMILY_VERSIONS: 0x17,
SERVER_FAMILY_VERSIONS: 0x18,
RATE_REQUEST: 0x6,
},
},
LOCATION: {
Expand Down

0 comments on commit 98f4826

Please sign in to comment.