Login: math bot check + configurable server host/ports; update docs
This commit is contained in:
parent
d4dfdd0326
commit
11c946de33
11 changed files with 182 additions and 95 deletions
10
HANDOFF.md
10
HANDOFF.md
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
## Status
|
||||
|
||||
**Phase:** M1/M2 in progress - TOC transport added for IM/chat/invites; Web API kept for buddy/presence where available. TOC auth fixed (roast prefix bug); remote `steve:please` signs on to TOC successfully. Group chat/invite flow should now be testable on web UI.
|
||||
**Phase:** M1/M2 in progress - TOC transport added for IM/chat/invites; Web API kept for buddy/presence where available. Public-hardening pass applied (SQLite sessions, corrupt DB recovery, SSE per-IP limit, input validation, session cleanup).
|
||||
|
||||
**Date:** 2026-12-02 (updated)
|
||||
**Date:** 2026-12-03 (updated)
|
||||
|
||||
## What was done
|
||||
|
||||
|
|
@ -49,6 +49,8 @@ Against local open-oscar-server 0.25.0 with `DISABLE_AUTH=true`, TOC listener 98
|
|||
|
||||
- **TOC 980 root cause (fixed 2026-12-02):** `src/toc.js` `roastPassword` incorrectly prepended `00 02` before XORing. open-oscar-server `wire.RoastTOCPassword` XORs the full payload with `Tic/Toc` and does not strip a prefix, so the extra bytes corrupted the cleartext and caused 980 on real-auth servers. Fixed by removing the prefix. Verified: local auth-enabled oscar-server and remote `oscar.claytonia.net:9898` both sign on with `steve/please` (`SIGN_ON:TOC2.0`).
|
||||
- **UI overhaul (initial, 2026-12-02):** dark theme, sidebar sections as cards, conversations moved to tabs above chat window, message style toggle (Bubbles/Classic AIM-IRC) persisted in localStorage. Local static assets only, no build step.
|
||||
- **Recent UI/fix pass (2026-12-03):** CSP `upgrade-insecure-requests` disabled for HTTP deployments; TOC status label shows Connected/Disconnected; TOC-sent IMs broadcast into SSE buffer for replay on refresh; frontend `addMessage()` dedupes by msgId/recent same-sender text to prevent duplicate display; message input is textarea with Enter-to-send/Shift+Enter newline; buddy list shows per-person outlined rows with green/red/yellow status dots and handles `presence` updates.
|
||||
- **Login hardening/UX (2026-12-03):** login page includes a simple server-side math bot check (`GET /api/auth/challenge`, validated on login) and configurable server host + Web API/TOC ports (defaults prefilled from env, Claytonia-friendly). Backend auth supports per-login Web API base/TOC host+port.
|
||||
- **Web API chat unavailable on 0.25.0:** do not rely on `/chat/*` Web API endpoints on this server. TOC is the working transport for chat/invites.
|
||||
- **TOC is HTTP-mixed on 9898:** normal HTTP clients get 404; TOC clients must send `FLAPON\r\n\r\n` first. Any proxy in front of 9898 must pass raw TCP.
|
||||
- **No reliable all-users list:** Management API not exposed; `memberDir/search` returned empty. UI has direct "Start IM by screen name" flow.
|
||||
|
|
@ -96,11 +98,11 @@ Against local open-oscar-server 0.25.0 with `DISABLE_AUTH=true`, TOC listener 98
|
|||
|
||||
## Needs to be done next
|
||||
|
||||
1. **Complete public-hardening pass** and verify login/IM/chat/SSE still work.
|
||||
1. **Deploy publicly behind HTTPS nginx:** `LISTEN_HOST=127.0.0.1`, `TRUST_PROXY=1`, `COOKIE_SECURE=true`, strong `SESSION_SECRET`, `.env` chmod `0600`, non-root systemd service, firewall block app port, nginx SSE buffering off for `/api/events`.
|
||||
2. **UI polish follow-up:** tab close buttons, unread indicators, chat room membership/leave/invite-send UI, better mobile layout.
|
||||
3. **Harden TOC client:** handle reconnect/backoff, keepalive timeout, parse CONFIG2 buddy list properly, handle TOC1/TOC2 variants, handle chat errors/room not found.
|
||||
4. **Chat UX:** show chat room membership, leave button, invite-send UI, better system messages, error states.
|
||||
5. **M5:** systemd service, env file permissions, nginx/certbot review.
|
||||
5. **Security follow-up:** configurable login host/ports enable arbitrary server targets; consider SSRF/egress restrictions or allowlist if exposed publicly.
|
||||
|
||||
## Files of interest
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@ A small browser chat client for [Open OSCAR Server](https://github.com/mk6i/open
|
|||
## Features
|
||||
|
||||
- Sign in with an existing OSCAR screen name/password
|
||||
- Simple math bot check on login
|
||||
- Configurable server host/Web API port/TOC port on login (defaults prefilled)
|
||||
- 1:1 instant messages
|
||||
- Buddy list/presence (when provided by server/Web API)
|
||||
- Buddy list with online/away/offline status dots (presence updates when provided)
|
||||
- Add buddy
|
||||
- Group chat join/send/leave via TOC
|
||||
- Chat invites (Join/Ignore) via TOC
|
||||
|
|
|
|||
|
|
@ -275,16 +275,38 @@ stream.on('*', (event) => {
|
|||
|
||||
// --- UI wiring ---
|
||||
|
||||
async function loadChallenge() {
|
||||
try {
|
||||
const c = await api.challenge();
|
||||
document.getElementById('captchaQuestion').textContent = `${c.a} + ${c.b} =`;
|
||||
document.getElementById('captchaAnswer').value = '';
|
||||
const d = c.defaults || {};
|
||||
const host = document.getElementById('serverHost');
|
||||
const wp = document.getElementById('webapiPort');
|
||||
const tp = document.getElementById('tocPort');
|
||||
if (host && !host.value) host.value = d.host || 'oscar.claytonia.net';
|
||||
if (wp && !wp.value) wp.value = String(d.webapiPort || 8081);
|
||||
if (tp && !tp.value) tp.value = String(d.tocPort || 9898);
|
||||
} catch (err) {
|
||||
console.warn('[challenge] load failed', err);
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('loginForm').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
ui.setLoginError('');
|
||||
const screenName = document.getElementById('screenName').value.trim();
|
||||
const password = document.getElementById('password').value;
|
||||
const host = document.getElementById('serverHost').value.trim();
|
||||
const webapiPort = Number(document.getElementById('webapiPort').value);
|
||||
const tocPort = Number(document.getElementById('tocPort').value);
|
||||
const captchaAnswer = Number(document.getElementById('captchaAnswer').value);
|
||||
try {
|
||||
await api.login(screenName, password);
|
||||
await api.login({ screenName, password, host, webapiPort, tocPort, captchaAnswer });
|
||||
await afterLogin(screenName);
|
||||
} catch (err) {
|
||||
ui.setLoginError(err.message);
|
||||
loadChallenge().catch(() => {});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -295,6 +317,7 @@ document.getElementById('logoutBtn').addEventListener('click', async () => {
|
|||
state.active = null;
|
||||
state.conversations = {};
|
||||
ui.showLogin();
|
||||
loadChallenge().catch(() => {});
|
||||
});
|
||||
|
||||
const styleToggleBtn = document.getElementById('styleToggleBtn');
|
||||
|
|
@ -434,6 +457,7 @@ async function boot() {
|
|||
// fall through to login
|
||||
}
|
||||
ui.showLogin();
|
||||
loadChallenge().catch(() => {});
|
||||
}
|
||||
|
||||
boot();
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Web OSCAR Chat</title>
|
||||
<link rel="stylesheet" href="/style.css?v=26">
|
||||
<link rel="stylesheet" href="/style.css?v=27">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
|
|
@ -22,11 +22,23 @@
|
|||
<main>
|
||||
<section id="loginView" class="panel login-panel">
|
||||
<h1>Sign in</h1>
|
||||
<p class="muted">Use your existing OSCAR screen name and password.</p>
|
||||
<p class="muted login-hint">Sign in with your OSCAR screen name. Server defaults to Claytonia; change host/ports to connect elsewhere.</p>
|
||||
<form id="loginForm">
|
||||
<div class="login-grid">
|
||||
<label>Screen name <input id="screenName" name="screenName" autocomplete="username" required></label>
|
||||
<label>Password <input id="password" name="password" type="password" autocomplete="current-password" required></label>
|
||||
<button type="submit">Sign in</button>
|
||||
</div>
|
||||
<div class="login-grid login-grid-server">
|
||||
<label class="field-host">Server host <input id="serverHost" name="host" autocomplete="off" spellcheck="false" value="oscar.claytonia.net" required></label>
|
||||
<label>Web API <input id="webapiPort" name="webapiPort" type="number" min="1" max="65535" value="8081" required></label>
|
||||
<label>TOC <input id="tocPort" name="tocPort" type="number" min="1" max="65535" value="9898" required></label>
|
||||
</div>
|
||||
<div class="login-grid login-grid-captcha">
|
||||
<label class="captcha-label">Bot check <span id="captchaQuestion" class="captcha-q">...</span>
|
||||
<input id="captchaAnswer" name="captchaAnswer" type="number" inputmode="numeric" autocomplete="off" required placeholder="Answer">
|
||||
</label>
|
||||
<button type="submit" class="login-submit">Sign in</button>
|
||||
</div>
|
||||
<p id="loginError" class="error" aria-live="polite"></p>
|
||||
</form>
|
||||
</section>
|
||||
|
|
@ -86,6 +98,6 @@
|
|||
</main>
|
||||
</div>
|
||||
|
||||
<script type="module" src="/app.js?v=26"></script>
|
||||
<script type="module" src="/app.js?v=27"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -16,9 +16,10 @@ async function request(path, options = {}) {
|
|||
|
||||
export const api = {
|
||||
me: () => request('/api/me'),
|
||||
login: (screenName, password) => request('/api/login', {
|
||||
challenge: () => request('/api/challenge'),
|
||||
login: (payload) => request('/api/login', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ screenName, password }),
|
||||
body: JSON.stringify(payload),
|
||||
}),
|
||||
logout: () => request('/api/logout', { method: 'POST', body: '{}' }),
|
||||
sendIM: (to, text) => request('/api/im', {
|
||||
|
|
|
|||
|
|
@ -87,10 +87,21 @@ main { padding: 1rem; max-width: 1600px; margin: 0 auto; }
|
|||
box-shadow: 0 2px 10px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.login-panel { max-width: 440px; margin: 4rem auto; padding: 1.25rem; }
|
||||
.login-panel { max-width: 620px; margin: 3rem auto; padding: 1.25rem; }
|
||||
.login-panel form { display: grid; gap: 0.75rem; }
|
||||
.login-panel label { display: grid; gap: 0.3rem; font-size: 0.95rem; color: var(--muted); }
|
||||
.login-panel h1 { margin-top: 0; margin-bottom: 0.25rem; }
|
||||
.login-panel label { display: grid; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
|
||||
.login-panel h1 { margin: 0 0 0.2rem 0; font-size: 1.4rem; }
|
||||
.login-hint { margin: 0 0 1rem 0; font-size: 0.9rem; }
|
||||
.login-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
|
||||
.login-grid-server { grid-template-columns: minmax(0, 1fr) 110px 90px; }
|
||||
.login-grid-captcha { grid-template-columns: 1fr auto; align-items: end; }
|
||||
.captcha-label { min-width: 0; }
|
||||
.captcha-q { color: var(--text); font-weight: 600; margin-left: 0.35rem; font-family: var(--mono); font-size: 0.9rem; }
|
||||
.login-submit { min-width: 120px; height: 2.5rem; }
|
||||
@media (max-width: 560px) {
|
||||
.login-grid, .login-grid-server, .login-grid-captcha { grid-template-columns: 1fr; }
|
||||
.login-submit { width: 100%; }
|
||||
}
|
||||
|
||||
.chat-layout {
|
||||
display: grid;
|
||||
|
|
|
|||
47
src/oscar.js
47
src/oscar.js
|
|
@ -71,7 +71,7 @@ async function call(path, params = {}, { base = WEBAPI_BASE, method = 'GET', for
|
|||
|
||||
// --- Auth / session ---
|
||||
|
||||
export async function clientLogin(screenName, password) {
|
||||
export async function clientLogin(screenName, password, { base } = {}) {
|
||||
// M0 partial: POST /auth/clientLogin accepts form-encoded username/password.
|
||||
// TODO(M0): confirm whether k/devId is required and its param name.
|
||||
const params = {};
|
||||
|
|
@ -80,70 +80,71 @@ export async function clientLogin(screenName, password) {
|
|||
return call('/auth/clientLogin', params, {
|
||||
method: 'POST',
|
||||
formBody: { username: screenName, password },
|
||||
...(base ? { base } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
export async function startSession(token, { events = [] } = {}) {
|
||||
export async function startSession(token, { events = [], base } = {}) {
|
||||
// TODO(M0): confirm param names and how event subscriptions are requested.
|
||||
const params = { a: token };
|
||||
if (events.length) params.events = events.join(',');
|
||||
return call('/aim/startSession', params);
|
||||
return call('/aim/startSession', params, base ? { base } : {});
|
||||
}
|
||||
|
||||
export async function fetchEvents(aimsid, seqNum, { timeout = 25000 } = {}) {
|
||||
export async function fetchEvents(aimsid, seqNum, { timeout = 25000, base } = {}) {
|
||||
// TODO(M0): confirm timeout units/param name and seqNum semantics.
|
||||
return call('/aim/fetchEvents', {
|
||||
aimsid,
|
||||
seqNum,
|
||||
timeout,
|
||||
}, { timeoutMs: timeout + 10000 });
|
||||
}, { timeoutMs: timeout + 10000, ...(base ? { base } : {}) });
|
||||
}
|
||||
|
||||
export async function endSession(aimsid) {
|
||||
return call('/aim/endSession', { aimsid });
|
||||
export async function endSession(aimsid, { base } = {}) {
|
||||
return call('/aim/endSession', { aimsid }, base ? { base } : {});
|
||||
}
|
||||
|
||||
// --- IM ---
|
||||
|
||||
export async function sendIM(aimsid, to, message) {
|
||||
export async function sendIM(aimsid, to, message, { base } = {}) {
|
||||
// TODO(M0): confirm param names (t/target, message/msg).
|
||||
return call('/im/sendIM', { aimsid, t: to, message });
|
||||
return call('/im/sendIM', { aimsid, t: to, message }, base ? { base } : {});
|
||||
}
|
||||
|
||||
export async function setTyping(aimsid, to, typingStatus = 'typing') {
|
||||
export async function setTyping(aimsid, to, typingStatus = 'typing', { base } = {}) {
|
||||
// TODO(M0): confirm typingStatus values.
|
||||
return call('/im/setTyping', { aimsid, t: to, typingStatus });
|
||||
return call('/im/setTyping', { aimsid, t: to, typingStatus }, base ? { base } : {});
|
||||
}
|
||||
|
||||
// --- Chat ---
|
||||
|
||||
export async function createAndJoinChat(aimsid, room) {
|
||||
export async function createAndJoinChat(aimsid, room, { base } = {}) {
|
||||
// TODO(M0): confirm param name for room/exchange.
|
||||
return call('/chat/createAndJoinChat', { aimsid, room });
|
||||
return call('/chat/createAndJoinChat', { aimsid, room }, base ? { base } : {});
|
||||
}
|
||||
|
||||
export async function sendChatMessage(aimsid, chatId, message) {
|
||||
export async function sendChatMessage(aimsid, chatId, message, { base } = {}) {
|
||||
// TODO(M0): confirm chat id param name.
|
||||
return call('/chat/sendMessage', { aimsid, c: chatId, message });
|
||||
return call('/chat/sendMessage', { aimsid, c: chatId, message }, base ? { base } : {});
|
||||
}
|
||||
|
||||
export async function leaveChat(aimsid, chatId) {
|
||||
return call('/chat/leaveChat', { aimsid, c: chatId });
|
||||
export async function leaveChat(aimsid, chatId, { base } = {}) {
|
||||
return call('/chat/leaveChat', { aimsid, c: chatId }, base ? { base } : {});
|
||||
}
|
||||
|
||||
export async function setChatTyping(aimsid, chatId, typingStatus = 'typing') {
|
||||
return call('/chat/setTyping', { aimsid, c: chatId, typingStatus });
|
||||
export async function setChatTyping(aimsid, chatId, typingStatus = 'typing', { base } = {}) {
|
||||
return call('/chat/setTyping', { aimsid, c: chatId, typingStatus }, base ? { base } : {});
|
||||
}
|
||||
|
||||
// --- Presence / buddy list ---
|
||||
|
||||
export async function getPresence(aimsid) {
|
||||
return call('/presence/get', { aimsid });
|
||||
export async function getPresence(aimsid, { base } = {}) {
|
||||
return call('/presence/get', { aimsid }, base ? { base } : {});
|
||||
}
|
||||
|
||||
export async function addBuddy(aimsid, screenName, { group = 'Buddies' } = {}) {
|
||||
export async function addBuddy(aimsid, screenName, { group = 'Buddies', base } = {}) {
|
||||
// TODO(M0): confirm param names and group behavior.
|
||||
return call('/buddylist/addBuddy', { aimsid, buddy: screenName, group });
|
||||
return call('/buddylist/addBuddy', { aimsid, buddy: screenName, group }, base ? { base } : {});
|
||||
}
|
||||
|
||||
// --- Management API (localhost only, unauthenticated) ---
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ export async function runPoller(rec) {
|
|||
|
||||
while (rec.polling) {
|
||||
try {
|
||||
const data = await oscar.fetchEvents(rec.aimsid, rec.seqNum);
|
||||
const data = await oscar.fetchEvents(rec.aimsid, rec.seqNum, { base: rec.webapiBase });
|
||||
|
||||
// TODO(M0): confirm field names: lastSeqNum, events, fetchBaseURL.
|
||||
if (typeof data?.lastSeqNum === 'number') {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ async function endOscarSession(rec, sessionId) {
|
|||
sessions.deleteSession(sessionId);
|
||||
if (rec.aimsid) {
|
||||
try {
|
||||
await oscar.endSession(rec.aimsid);
|
||||
await oscar.endSession(rec.aimsid, { base: rec.webapiBase });
|
||||
} catch (err) {
|
||||
console.warn(`[logout] endSession failed for ${rec.screenName}:`, err.message);
|
||||
}
|
||||
|
|
@ -47,14 +47,52 @@ export async function cleanupSessionById(sessionId, sessionStore) {
|
|||
}
|
||||
}
|
||||
|
||||
function cleanHost(v) {
|
||||
const s = String(v || '').trim().slice(0, 255);
|
||||
if (!s) return '';
|
||||
if (!/^[a-zA-Z0-9._:-]+$/.test(s)) return '';
|
||||
return s;
|
||||
}
|
||||
function cleanPort(v, fallback) {
|
||||
const n = Number(v);
|
||||
if (!Number.isInteger(n) || n < 1 || n > 65535) return fallback;
|
||||
return n;
|
||||
}
|
||||
|
||||
authRouter.get('/challenge', (req, res) => {
|
||||
const a = Math.floor(Math.random() * 10) + 1;
|
||||
const b = Math.floor(Math.random() * 10) + 1;
|
||||
req.session.captchaAnswer = a + b;
|
||||
res.json({
|
||||
a,
|
||||
b,
|
||||
defaults: {
|
||||
host: process.env.WEBAPI_HOST || process.env.TOC_HOST || 'oscar.claytonia.net',
|
||||
webapiPort: cleanPort(process.env.WEBAPI_PORT, 8081),
|
||||
tocPort: cleanPort(process.env.TOC_PORT, 9898),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
authRouter.post('/login', async (req, res) => {
|
||||
const screenName = cleanScreenName(req.body?.screenName);
|
||||
const password = String(req.body?.password || '').replace(/[\u0000-\u001f\u007f]/g, '').slice(0, 256);
|
||||
const captchaAnswer = Number(req.body?.captchaAnswer);
|
||||
const expectedCaptcha = Number(req.session?.captchaAnswer);
|
||||
req.session.captchaAnswer = null;
|
||||
|
||||
if (!Number.isFinite(expectedCaptcha) || !Number.isFinite(captchaAnswer) || captchaAnswer !== expectedCaptcha) {
|
||||
return res.status(400).json({ error: 'Bot check failed. Please solve the math problem.' });
|
||||
}
|
||||
if (!screenName || !password) {
|
||||
return res.status(400).json({ error: 'screenName and password are required' });
|
||||
}
|
||||
|
||||
const host = cleanHost(req.body?.host) || process.env.WEBAPI_HOST || process.env.TOC_HOST || 'oscar.claytonia.net';
|
||||
const webapiPort = cleanPort(req.body?.webapiPort, cleanPort(process.env.WEBAPI_PORT, 8081));
|
||||
const tocPort = cleanPort(req.body?.tocPort, cleanPort(process.env.TOC_PORT, 9898));
|
||||
const webapiBase = `http://${host}:${webapiPort}`;
|
||||
|
||||
// If this browser session already has an OSCAR session, clean it up first.
|
||||
const existing = sessions.getSession(req.session.id);
|
||||
if (existing) await endOscarSession(existing, req.session.id);
|
||||
|
|
@ -67,20 +105,17 @@ authRouter.post('/login', async (req, res) => {
|
|||
req.session.regenerate((err) => (err ? reject(err) : resolve()));
|
||||
});
|
||||
|
||||
const tocHost = process.env.TOC_HOST;
|
||||
const tocPort = Number(process.env.TOC_PORT || 9898);
|
||||
let webErr = null;
|
||||
let tocErr = null;
|
||||
let rec = null;
|
||||
|
||||
// Try Web API login (buddy list/presence/profile) when configured.
|
||||
if (process.env.WEBAPI_HOST) {
|
||||
// Try Web API login (buddy list/presence/profile).
|
||||
try {
|
||||
const loginData = await oscar.clientLogin(screenName, password);
|
||||
const loginData = await oscar.clientLogin(screenName, password, { base: webapiBase });
|
||||
let token = loginData?.token || loginData?.a || loginData?.loginCookie;
|
||||
if (token && typeof token === 'object') token = token.a || token.token || token.loginCookie;
|
||||
if (typeof token !== 'string' || !token) throw new Error('no token in login response');
|
||||
const startData = await oscar.startSession(token);
|
||||
const startData = await oscar.startSession(token, { base: webapiBase });
|
||||
const aimsid = startData?.aimsid;
|
||||
if (!aimsid) throw new Error('startSession returned no aimsid');
|
||||
rec = {
|
||||
|
|
@ -88,6 +123,7 @@ authRouter.post('/login', async (req, res) => {
|
|||
screenName,
|
||||
token,
|
||||
aimsid,
|
||||
webapiBase,
|
||||
seqNum: typeof startData?.lastSeqNum === 'number' ? startData.lastSeqNum : -1,
|
||||
sseClients: new Set(),
|
||||
polling: false,
|
||||
|
|
@ -98,10 +134,8 @@ authRouter.post('/login', async (req, res) => {
|
|||
webErr = err;
|
||||
console.warn('[login] webapi failed:', err.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Try TOC login for IM/chat/invites (works where Web API chat is unavailable).
|
||||
if (tocHost) {
|
||||
try {
|
||||
if (!rec) {
|
||||
rec = {
|
||||
|
|
@ -109,24 +143,24 @@ authRouter.post('/login', async (req, res) => {
|
|||
screenName,
|
||||
token: null,
|
||||
aimsid: null,
|
||||
webapiBase,
|
||||
seqNum: -1,
|
||||
sseClients: new Set(),
|
||||
polling: false,
|
||||
eventBuffer: [],
|
||||
};
|
||||
}
|
||||
await startTOCSession(rec, { host: tocHost, port: tocPort, password });
|
||||
await startTOCSession(rec, { host, port: tocPort, password });
|
||||
} catch (err) {
|
||||
tocErr = err;
|
||||
console.warn('[login] toc failed:', err.message);
|
||||
if (!rec?.aimsid) rec = null; // no usable session
|
||||
}
|
||||
}
|
||||
|
||||
if (!rec) {
|
||||
console.error('[login] failed:', webErr?.message || tocErr?.message);
|
||||
const status = (webErr?.statusCode === 401 || webErr?.statusCode === 403) ? 401 : 502;
|
||||
return res.status(status).json({ error: 'Login failed. Check screen name/password and server status.' });
|
||||
return res.status(status).json({ error: 'Login failed. Check screen name/password, bot check, and server settings.' });
|
||||
}
|
||||
|
||||
sessions.setSession(req.session.id, rec);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ buddiesRouter.get('/buddies', requireLogin, async (req, res) => {
|
|||
return res.json({ ok: true, data: buf[i].data || {}, source: 'buddylist-event' });
|
||||
}
|
||||
}
|
||||
const data = await oscar.getPresence(req.oscar.aimsid);
|
||||
const data = await oscar.getPresence(req.oscar.aimsid, { base: req.oscar.webapiBase });
|
||||
res.json({ ok: true, data, source: 'presence' });
|
||||
} catch (err) {
|
||||
console.error('[buddies] list failed:', err.message);
|
||||
|
|
@ -29,7 +29,7 @@ buddiesRouter.post('/buddies', requireLogin, async (req, res) => {
|
|||
if (!screenName) return res.status(400).json({ error: 'screenName is required' });
|
||||
|
||||
try {
|
||||
const data = await oscar.addBuddy(req.oscar.aimsid, screenName);
|
||||
const data = await oscar.addBuddy(req.oscar.aimsid, screenName, { base: req.oscar.webapiBase });
|
||||
res.json({ ok: true, data });
|
||||
} catch (err) {
|
||||
console.error('[buddies] add failed:', err.message);
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ messagesRouter.post('/im', requireLogin, async (req, res) => {
|
|||
});
|
||||
return res.json({ ok: true, transport: 'toc', data: { msgId } });
|
||||
}
|
||||
const data = await oscar.sendIM(req.oscar.aimsid, to, message);
|
||||
const data = await oscar.sendIM(req.oscar.aimsid, to, message, { base: req.oscar.webapiBase });
|
||||
res.json({ ok: true, data, transport: 'webapi' });
|
||||
} catch (err) {
|
||||
console.error('[im] send failed:', err.message);
|
||||
|
|
@ -47,7 +47,7 @@ messagesRouter.post('/chat/join', requireLogin, async (req, res) => {
|
|||
req.oscar.toc.chatJoin(exchange, room);
|
||||
return res.json({ ok: true, transport: 'toc', note: 'CHAT_JOIN event will arrive via SSE' });
|
||||
}
|
||||
const data = await oscar.createAndJoinChat(req.oscar.aimsid, room);
|
||||
const data = await oscar.createAndJoinChat(req.oscar.aimsid, room, { base: req.oscar.webapiBase });
|
||||
res.json({ ok: true, data, transport: 'webapi' });
|
||||
} catch (err) {
|
||||
console.error('[chat] join failed:', err.message);
|
||||
|
|
@ -80,7 +80,7 @@ messagesRouter.post('/chat/send', requireLogin, async (req, res) => {
|
|||
req.oscar.toc.chatSend(room, message);
|
||||
return res.json({ ok: true, transport: 'toc' });
|
||||
}
|
||||
const data = await oscar.sendChatMessage(req.oscar.aimsid, room, message);
|
||||
const data = await oscar.sendChatMessage(req.oscar.aimsid, room, message, { base: req.oscar.webapiBase });
|
||||
res.json({ ok: true, data, transport: 'webapi' });
|
||||
} catch (err) {
|
||||
console.error('[chat] send failed:', err.message);
|
||||
|
|
@ -97,7 +97,7 @@ messagesRouter.post('/chat/leave', requireLogin, async (req, res) => {
|
|||
req.oscar.toc.chatLeave(room);
|
||||
return res.json({ ok: true, transport: 'toc' });
|
||||
}
|
||||
await oscar.leaveChat(req.oscar.aimsid, room);
|
||||
await oscar.leaveChat(req.oscar.aimsid, room, { base: req.oscar.webapiBase });
|
||||
res.json({ ok: true, transport: 'webapi' });
|
||||
} catch (err) {
|
||||
console.error('[chat] leave failed:', err.message);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue