TOC ("Talk to OSCAR") is a simplified, text-based way to talk to an AIM server. The original TOC server was just an OSCAR client that listened on a socket and translated between the two protocols. So instead of binary SNACs, you send and receive readable commands. Open OSCAR Server implements it itself, so the TOC listener on 9898 plays that role for you. Wikipedia Everything below comes from the TOC2 spec as I remember it. I've noted where I'm sure and where you should check the repo's docs/TOC.md. 1. The three layers TCP: Node opens a plain socket to 9898. FLAP framing: every message is wrapped in a 6-byte header. TCP is a stream with no message boundaries, so the header tells you where each message ends. TOC commands: the text inside each frame, such as toc_chat_join 4 "lobby". Frame header (6 bytes): Byte(s) Meaning 0 Always * (0x2A) 1 Frame type: 1 = sign-on, 2 = data 2-3 Sequence number (16-bit, big-endian, you increment it) 4-5 Length of the body (big-endian) Data frames carry ASCII text ending in a null byte. Sign-on frames carry a small binary body. 2. Logging in Connect and send the plain text FLAPON\r\n\r\n. This is what separates a TOC client from a web browser on that port, and it's why your earlier probe got HTTP errors. The server replies with a sign-on frame (type 1). You reply with your own sign-on frame: version 00000001, then a TLV (tag 1, length, your screen name). You send the command toc2_signon ... as a data frame. It carries a roasted password, a language, a client name, and a numeric code. I'm fairly sure the argument list is host port screenname roasted-password language "client name" 160 code, but verify it against docs/TOC.md. The server answers SIGN_ON:TOC2.0, then your configuration (buddy list). You send toc_init_done. Until you do, the server holds back events. Roasting is not security. It's XOR-ing the password with a fixed key, then hex-encoding it with 0x in front. The key is the string "Tic/Toc," and the password has to be roasted when connecting over FLAP. Use TLS or a trusted network, because the password is trivially reversible. mit 3. Sending commands Commands are one line of text. Arguments are space-separated, and any text with spaces goes in double quotes with a backslash before special characters. The server drops the connection if a command exceeds 2048 bytes, so cap message length. mit You want to Command Send an IM toc2_send_im "" Add a buddy toc2_add_buddy (names are lowercase, no spaces) Join a room toc_chat_join "" Say something in a room toc_chat_send "" Invite someone toc_chat_invite "" Accept an invite toc_chat_accept Leave a room toc_chat_leave toc_chat_invite is used once you're inside a room, toc_chat_accept answers an invite, and the server then replies with a CHAT_JOIN. The room id is a number the server gives you, not the room name. The spec says the exchange should currently always be 4. Open OSCAR Server has both private (4) and public (5) exchanges, so test both. mit mit 4. Events you receive Server messages are colon-separated. The message text is the last field and can itself contain colons, so split only a fixed number of times. The room-related ones are: apple CHAT_JOIN:: means you're in; remember the id. CHAT_IN:::: is a room message. CHAT_INVITE:::: is an invite. This is how invites arrive. CHAT_LEFT: means you left. There are also IM_IN2 (incoming IM), UPDATE_BUDDY2 (buddy online/offline), CHAT_UPDATE_BUDDY (who is in a room), and ERROR. I'm less sure of their exact field layouts, so log them in Milestone 0 before relying on them. Your own chat messages come back to you as CHAT_IN, so don't add them to the screen yourself when you send. IMs are not echoed back. mit 5. A learning script This signs on and prints everything the server sends. It's an untested sketch, and the toc2_signon details are from memory. ``` js // toc-demo.mjs // Run: TOC_HOST=oscar.claytonia.net TOC_USER=you TOC_PASS=secret node toc-demo.mjs import net from 'node:net'; const { TOC_HOST, TOC_USER, TOC_PASS } = process.env; const TOC_PORT = Number(process.env.TOC_PORT ?? 9898); // Roasting: XOR each password byte with the repeating key 'Tic/Toc', as hex. function roast(pw) { const key = Buffer.from('Tic/Toc'); const bytes = Array.from(Buffer.from(pw), (b, i) => b ^ key[i % key.length]); return '0x' + Buffer.from(bytes).toString('hex'); } // The numeric code toc2_signon wants (recalled from the spec; the server may ignore it). function signonCode(user, pass) { const sn = user.toLowerCase().charCodeAt(0) - 96; const pw = pass.toLowerCase().charCodeAt(0) - 96; const a = sn * 7696 + 738816; return pw * a - a + sn * 746512 + 71665152; } // Quote an argument: wrap in double quotes, backslash-escape special characters. const q = (s) => '"' + s.replace(/([\\"$\[\]{}()])/g, '\\$1') + '"'; // ---- FLAP framing ---- let seq = Math.floor(Math.random() * 0xffff); // we pick the starting sequence number function frame(type, body) { const head = Buffer.alloc(6); head.write('*', 0); // byte 0: always '*' head.writeUInt8(type, 1); // byte 1: 1 = sign-on, 2 = data head.writeUInt16BE(seq, 2); // bytes 2-3: sequence number seq = (seq + 1) & 0xffff; // wraps at 16 bits head.writeUInt16BE(body.length, 4); // bytes 4-5: body length return Buffer.concat([head, body]); } // Send one TOC command: text plus a null byte, inside a data frame. const sendCmd = (text) => sock.write(frame(2, Buffer.from(text + '\0'))); function signonBody(name) { const n = Buffer.from(name); const b = Buffer.alloc(8 + n.length); b.writeUInt32BE(1, 0); // FLAP version 1 b.writeUInt16BE(1, 4); // TLV tag 1 = screen name b.writeUInt16BE(n.length, 6); // TLV length n.copy(b, 8); return b; } // ---- Connection ---- const sock = net.connect(TOC_PORT, TOC_HOST, () => { console.log('connected'); sock.write('FLAPON\r\n\r\n'); // announce ourselves as a TOC client }); let buf = Buffer.alloc(0); // TCP delivers arbitrary chunks, so we buffer sock.on('data', (chunk) => { buf = Buffer.concat([buf, chunk]); while (buf.length >= 6) { // need a full header const len = buf.readUInt16BE(4); if (buf.length < 6 + len) break; // frame incomplete: wait for more data const type = buf[1]; const body = buf.subarray(6, 6 + len); buf = buf.subarray(6 + len); // drop this frame from the buffer onFrame(type, body); } }); function onFrame(type, body) { if (type === 1) { // server sign-on frame: reply, then log in sock.write(frame(1, signonBody(TOC_USER))); sendCmd(`toc2_signon localhost 5190 ${TOC_USER} ${roast(TOC_PASS)} english ` + `${q('web-oscar-chat')} 160 ${signonCode(TOC_USER, TOC_PASS)}`); return; } const text = body.toString('latin1').replace(/\0$/, ''); console.log('<<', text); if (text.startsWith('SIGN_ON:')) sendCmd('toc_init_done'); // start receiving events } sock.on('error', (e) => console.error('socket error:', e.message)); sock.on('close', () => console.log('closed')); ``` To try it, run it, then message the account from Pidgin and watch IM_IN2 appear. Once that works, add sendCmd('toc_chat_join 4 "testroom"') after toc_init_done, and log what comes back. Then invite the account from Pidgin and look for CHAT_INVITE.