16 Companion server.js (8/13)

    const name = m.objectName(o).trim();
    if (!name || name.length > 30 || skip.test(name) || /[^\x20-\x7e -?]/.test(name)) continue;
    result.objects.push(name.toLowerCase());
    if (result.objects.length >= MAX_OBJECTS) break;
  }
  state.exits = result;
  return result;
}

// ------------------------------------------------------------------ rows

const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));

function excerpt(text) {
  const flat = text.replace(/\s+/g, ' ').trim();
  return flat.length > EXCERPT ? flat.slice(0, EXCERPT - 1).replace(/\s+\S*$/, '') + ' ...' : flat;
}

function rowsFor(sid, game, state) {
  const last = state.history[state.history.length - 1];
  const base = `/s/${sid}`;
  const g = encodeURIComponent(game.id);
  const rows = [{
    title: last.place || last.status || game.title,
    sub: excerpt(last.output) || '(no text)',
    id: `out-${last.turn}`,
    details: `${base}/out?g=${g}&t=${last.turn}`,
    fmt: 'html',
  }];
  const cmdRow = (label, cmd) => rows.push({
    title: label,
    id: `do-${state.turn}-${cmd}`,
    details: `${base}/do?g=${g}&t=${state.turn}&c=${encodeURIComponent(cmd)}`,
    fmt: 'html',
  });
‹ PreviousReader file (.txt)Next ›