-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working snac 01,03 for boss server. Also shuffed some things around
- Loading branch information
Showing
11 changed files
with
159 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import assert from 'assert'; | ||
import { parseTLVs } from '../parseTLVs'; | ||
import { TLVS } from '../constants'; | ||
|
||
/** | ||
* @see http://iserverd.khstu.ru/oscar/cli_cookie.html | ||
*/ | ||
export function parseCookieRequest(data: Buffer) { | ||
const flapVersion = data.readUInt32BE(0); | ||
assert(flapVersion === 0x1, 'Incorrect client FLAP version'); | ||
|
||
const tlvs = parseTLVs(data.subarray(4)); | ||
const authCookie = tlvs.first(TLVS.AUTH_COOKIE).value; | ||
|
||
return { authCookie }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { timingSafeEqual } from 'crypto'; | ||
import { parseCookieRequest } from './clientSnacs'; | ||
import { OscarServer, OscarSocket } from '../OscarServer'; | ||
import { supportedFamiliesSnac } from './serverSnacs'; | ||
import { assert } from 'console'; | ||
|
||
export class BossServer extends OscarServer { | ||
onConnection(oscarSocket: OscarSocket) { | ||
const { host, port } = oscarSocket.remoteAddress; | ||
console.log(`BossServer: New connection from ${host}:${port}`); | ||
|
||
oscarSocket.sendStartFlap(); | ||
|
||
oscarSocket.onChannel(0x1, (flap) => { | ||
const { authCookie } = parseCookieRequest(flap.data); | ||
// TODO: Grab cookie from shared storage with auth service | ||
const expectedCookie = Buffer.from('111111111', 'ascii'); | ||
const validCookie = timingSafeEqual(authCookie, expectedCookie); | ||
|
||
// TODO: Unsure of what client expects for invalid cookie, | ||
// maybe close via channel 4? | ||
assert(validCookie, 'BossServer: Invalid auth cookie'); | ||
|
||
const snac = supportedFamiliesSnac({ reqID: 1 }); | ||
oscarSocket.write({ channel: 2, data: snac }); | ||
}); | ||
|
||
oscarSocket.onChannel(0x2, (flap) => { | ||
console.log('boss channel 2 flap: ', flap); | ||
}); | ||
|
||
oscarSocket.onChannel(0x3, (flap) => { | ||
console.log('boss channel 3 flap: ', flap); | ||
}); | ||
|
||
oscarSocket.onChannel(0x4, (flap) => { | ||
console.log('boss channel 4 flap: ', flap); | ||
}); | ||
|
||
oscarSocket.onChannel(0x5, (flap) => { | ||
console.log('boss channel 5 flap: ', flap); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { buildSnac } from '../snacUtils'; | ||
import { SNACS } from '../constants'; | ||
import { endianness } from 'os'; | ||
|
||
/** | ||
* @see http://iserverd.khstu.ru/oscar/snac_01_03.html | ||
*/ | ||
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(); | ||
|
||
return buildSnac({ | ||
family: SNACS.GENERAL.family, | ||
subtype: SNACS.GENERAL.subtypes.SUPPORTED_FAMILIES, | ||
reqID: opts.reqID, | ||
data: Buffer.from(Uint16Array.from(families).buffer).swap16(), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters