mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-28 17:38:04 -08:00
CompuServe CB Simulator on the BBS's chat rooms
GO CB asks a handle (not another member's name) and a channel; channel n is the chat room cb-n, shared with the BBS's other chat callers. The 1982 /HELP's commands: /TUN, /MON, /UNM, /STA, /TIM, /UST (the 1986 table, with s for scrambled and Tlk), /WHO, /HAN, /SCR, /SMC, /XCL, /UNS, /SQU, /JOB, /EXI, plus /TALK, /ROLL and /OFF. Lines show as (Handle) text, or (ch,Handle) from a monitored channel. Chat events carry the sender's handle (bbs.Node.SetHandle) beside their name, so other front ends still show the name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRRPWCkk1Ro91AuzXFM
This commit is contained in:
8 files changed
+788
-14
No files matched your search
@@ -688,6 +688,8 @@ In that format, `s` means scrambled and `Tlk` means in a `/TALK`.
|
||||
- a 1985 magazine quotes CB as `(Old Man) Does anyone know what time it is?`;
|
||||
- **the CB format is unresolved** — choose `(ch,Handle)` for consistency with forums [I].
|
||||
|
||||
**As built** [I]: `(Handle) text` for the tuned channel (the 1985 quote), `(ch,Handle) text` for a monitored one, `** Handle tuned in to channel n **` and `** Handle left channel n **` for comings and goings, `(Talk job,Handle) text` in a `/TALK`. The entry asks `What's your handle?` and `What channel (1-36)?`; `/TUN` answers `(Tuned to channel n, k others here)`.
|
||||
|
||||
---
|
||||
|
||||
## 7. Billing (for display only)
|
||||
|
||||
+31
-1
@@ -179,6 +179,35 @@ Subj: Testing
|
||||
Hello from Mail.
|
||||
```
|
||||
|
||||
## CB Simulator
|
||||
|
||||
`GO CB` enters the CB Simulator. Its channels are the BBS's chat rooms
|
||||
`cb-1` to `cb-36`, so callers in the BBS's own chat, or on IRC, can join a
|
||||
channel too. A CB caller picks a handle, which can't be another member's
|
||||
name, and a channel. After that, whatever they type is said on that
|
||||
channel. A line from the tuned channel shows as `(Handle) text`, and a
|
||||
line from a monitored channel shows as `(17,Handle) text`. Others see
|
||||
the handle, and the BBS's other chat programs see the caller's name.
|
||||
|
||||
| Command | Does |
|
||||
|---|---|
|
||||
| `/TUN n` | tune to channel n (1-36) |
|
||||
| `/MON 1,4`, `/UNM 1,4` | listen to other channels too, or stop |
|
||||
| `/STA` | how many are on each channel |
|
||||
| `/UST [n]` | who is on CB: job, User ID, channel (`17s` scrambled, `Tlk` talking), node, handle |
|
||||
| `/WHO` | the User ID of the last talker |
|
||||
| `/HAN name` | change your handle |
|
||||
| `/SCR key`, `/SMC key`, `/XCL key`, `/UNS` | scramble what you send and unscramble what you get, one of the two, or neither |
|
||||
| `/SQU handle` | squelch a handle (again to unsquelch) |
|
||||
| `/TALK job` | talk with one caller alone (`/EXIT` back to the channel) |
|
||||
| `/ROLL [3D6]` | roll dice for the channel |
|
||||
| `/TIM`, `/JOB`, `/HELP` | the time, your job number (the BBS node), the commands |
|
||||
| `/EXI`, `/OFF` | leave CB, or log off |
|
||||
|
||||
Scrambling works the way CompuServe's did. Everything you send goes out
|
||||
permuted by the key, and everything you receive is unpermuted with it,
|
||||
so only callers using the same key read each other.
|
||||
|
||||
## What is there and what is coming
|
||||
|
||||
| Done | Coming, in order |
|
||||
@@ -188,7 +217,8 @@ Hello from Mail.
|
||||
| The CompuServe B, Quick B and B Plus protocols (`internal/xfer/cisb.go`) | B Plus resume (Tr) and file information (TI) |
|
||||
| Libraries on the file areas, with B+ downloads and uploads | |
|
||||
| CompuServe Mail on the BBS's private mail | A kept address book, binary mail |
|
||||
| | The CB Simulator, then CIM's HMI service |
|
||||
| The CB Simulator on the chat rooms | Forum conferences (CO) |
|
||||
| | CIM's HMI service |
|
||||
|
||||
The research behind all this, with sources, is in
|
||||
[docs/cis](https://github.com/D-Modem/bbs/tree/main/docs/cis).
|
||||
+30
-8
@@ -35,6 +35,9 @@ type Event struct {
|
||||
Node int
|
||||
Text string
|
||||
Time time.Time
|
||||
// the CB handle the sender goes by ("": none; From is still the
|
||||
// user's name, for those that do not show handles)
|
||||
Handle string
|
||||
}
|
||||
|
||||
// String is the event as a line for the caller.
|
||||
@@ -86,6 +89,7 @@ type chatState struct {
|
||||
also map[string]bool // rooms an IRC client is in besides (JoinAlso)
|
||||
busy bool // a sysop not to be paged
|
||||
sent []time.Time
|
||||
handle string // a CompuServe CB handle ("": none)
|
||||
paging string // why this caller pages the sysop ("": not)
|
||||
pagedAt time.Time // when
|
||||
}
|
||||
@@ -173,6 +177,23 @@ func (n *Node) Room() string {
|
||||
return cs.room
|
||||
}
|
||||
|
||||
// SetHandle sets the handle the node goes by in chat (a CompuServe CB
|
||||
// handle; "": none). Events still carry the user's name.
|
||||
func (n *Node) SetHandle(h string) {
|
||||
cs := n.chat()
|
||||
cs.mu.Lock()
|
||||
cs.handle = h
|
||||
cs.mu.Unlock()
|
||||
}
|
||||
|
||||
// Handle is the node's chat handle ("": none).
|
||||
func (n *Node) Handle() string {
|
||||
cs := n.chat()
|
||||
cs.mu.Lock()
|
||||
defer cs.mu.Unlock()
|
||||
return cs.handle
|
||||
}
|
||||
|
||||
// name is the node's user's name, or "node N" before a login.
|
||||
func (n *Node) name() string {
|
||||
if u := n.User(); u != nil {
|
||||
@@ -287,7 +308,7 @@ func (b *BBS) RoomMembers(name string) []RoomMember {
|
||||
b.mu.Lock()
|
||||
via := m.Caller.Via
|
||||
b.mu.Unlock()
|
||||
out = append(out, RoomMember{Name: m.name(), Node: m.Num, Via: via})
|
||||
out = append(out, RoomMember{Name: m.name(), Node: m.Num, Via: via, Handle: m.Handle()})
|
||||
}
|
||||
sort.Slice(out, func(i, j int) bool { return out[i].Node < out[j].Node })
|
||||
return out
|
||||
@@ -295,9 +316,10 @@ func (b *BBS) RoomMembers(name string) []RoomMember {
|
||||
|
||||
// RoomMember is one in a room.
|
||||
type RoomMember struct {
|
||||
Name string
|
||||
Node int
|
||||
Via string
|
||||
Name string
|
||||
Node int
|
||||
Via string
|
||||
Handle string // a CB handle ("": none)
|
||||
}
|
||||
|
||||
// enter puts the node in a room's members, tells the others, and gives
|
||||
@@ -318,7 +340,7 @@ func (n *Node) enter(name string) []Event {
|
||||
}
|
||||
hist = append(hist, r.history...)
|
||||
h.mu.Unlock()
|
||||
e := Event{Kind: Joined, Room: name, From: n.name(), Node: n.Num, Time: time.Now()}
|
||||
e := Event{Kind: Joined, Room: name, From: n.name(), Node: n.Num, Time: time.Now(), Handle: n.Handle()}
|
||||
for _, o := range others {
|
||||
o.deliver(e)
|
||||
}
|
||||
@@ -363,7 +385,7 @@ func (n *Node) exit(name string) {
|
||||
}
|
||||
}
|
||||
h.mu.Unlock()
|
||||
e := Event{Kind: Left, Room: name, From: n.name(), Node: n.Num, Time: time.Now()}
|
||||
e := Event{Kind: Left, Room: name, From: n.name(), Node: n.Num, Time: time.Now(), Handle: n.Handle()}
|
||||
for _, o := range others {
|
||||
o.deliver(e)
|
||||
}
|
||||
@@ -425,7 +447,7 @@ func (n *Node) SayIn(name, text string, emote bool) error {
|
||||
if n.flood() {
|
||||
return ErrFlood
|
||||
}
|
||||
e := Event{Kind: Said, Room: name, From: n.name(), Node: n.Num, Text: text, Time: time.Now()}
|
||||
e := Event{Kind: Said, Room: name, From: n.name(), Node: n.Num, Text: text, Time: time.Now(), Handle: n.Handle()}
|
||||
if emote {
|
||||
e.Kind = Emoted
|
||||
}
|
||||
@@ -505,7 +527,7 @@ func (n *Node) Message(to int, text string) error {
|
||||
if n.flood() {
|
||||
return ErrFlood
|
||||
}
|
||||
o.deliver(Event{Kind: Private, From: n.name(), Node: n.Num, Text: text, Time: time.Now()})
|
||||
o.deliver(Event{Kind: Private, From: n.name(), Node: n.Num, Text: text, Time: time.Now(), Handle: n.Handle()})
|
||||
n.b.Log.Printf("node %d: %s sent a message to node %d", n.Num, n.name(), to)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func (s *session) ascii() error {
|
||||
switch p := s.pages.Get(s.firstGo); {
|
||||
case s.firstGo == "" || !s.known(s.firstGo):
|
||||
s.show(top)
|
||||
case p != nil && p.ID != "MAIL":
|
||||
case p != nil && p.ID != "MAIL" && p.ID != "CB":
|
||||
s.show(p)
|
||||
default:
|
||||
// /GO:word to a forum or Mail: in it first, TOP when it is left
|
||||
@@ -166,6 +166,9 @@ func (s *session) goWord(word string) error {
|
||||
if p != nil && p.ID == "MAIL" {
|
||||
return s.enterMail()
|
||||
}
|
||||
if p != nil && p.ID == "CB" {
|
||||
return s.enterCB()
|
||||
}
|
||||
s.goTo(p)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,617 @@
|
||||
package cis
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"math/rand/v2"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/D-Modem/bbs/internal/bbs"
|
||||
)
|
||||
|
||||
// The CB Simulator on the BBS's chat rooms: channel n is the room "cb-n",
|
||||
// so the BBS's own chat callers can tune in too. The commands are the
|
||||
// 1982 /HELP's; the line format, "(Handle) text" on the tuned channel and
|
||||
// "(ch,Handle) text" on one monitored, follows a 1985 quote and the forum
|
||||
// conferences' "(room,name)" [I].
|
||||
|
||||
const cbChannels = 36
|
||||
|
||||
func cbRoom(ch int) string { return "cb-" + strconv.Itoa(ch) }
|
||||
|
||||
// cbChannel is the channel of a room, or 0.
|
||||
func cbChannel(room string) int {
|
||||
n, err := strconv.Atoi(strings.TrimPrefix(room, "cb-"))
|
||||
if !strings.HasPrefix(room, "cb-") || err != nil || n < 1 || n > cbChannels {
|
||||
return 0
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// cbState is a caller's time in CB.
|
||||
type cbState struct {
|
||||
tuned int
|
||||
monitor map[int]bool
|
||||
xmitKey string // /SCR, /SMC: what is sent is scrambled
|
||||
rcvKey string // /SCR, /XCL: what comes is unscrambled
|
||||
squelch map[string]bool
|
||||
talk int // /TALK: the job talked to (0: none)
|
||||
lastFrom string // the last talker on the tuned channel, for /WHO
|
||||
}
|
||||
|
||||
// cbFlags are the CB callers' scrambling and talking, for /UST.
|
||||
var cbFlags = struct {
|
||||
sync.Mutex
|
||||
m map[int]string // by node: "s" scrambled, "Tlk" talking
|
||||
}{m: map[int]string{}}
|
||||
|
||||
func setCBFlag(node int, f string) {
|
||||
cbFlags.Lock()
|
||||
defer cbFlags.Unlock()
|
||||
if f == "" {
|
||||
delete(cbFlags.m, node)
|
||||
} else {
|
||||
cbFlags.m[node] = f
|
||||
}
|
||||
}
|
||||
|
||||
func cbFlag(node int) string {
|
||||
cbFlags.Lock()
|
||||
defer cbFlags.Unlock()
|
||||
return cbFlags.m[node]
|
||||
}
|
||||
|
||||
// errLeaveCB is /EXI: the CB Simulator left.
|
||||
var errLeaveCB = errors.New("cis: leaving CB")
|
||||
|
||||
// enterCB is GO CB: a handle, a channel, then talk until /EXI.
|
||||
func (s *session) enterCB() error {
|
||||
if !s.b.LevelOf(s.user).Chat {
|
||||
s.out("\nYour access does not include the CB Simulator.\n")
|
||||
return nil
|
||||
}
|
||||
s.node.Doing("CompuServe: CB")
|
||||
s.out("\nCompuServe CB Simulator\n\n")
|
||||
st := &cbState{monitor: map[int]bool{}, squelch: map[string]bool{}}
|
||||
if s.node.Handle() == "" {
|
||||
for {
|
||||
h, err := s.prompt("What's your handle? ")
|
||||
if err != nil {
|
||||
return s.abortOK0(err)
|
||||
}
|
||||
if err := s.setHandle(h); err != nil {
|
||||
s.out(err.Error() + "\n")
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
for st.tuned == 0 {
|
||||
c, err := s.prompt("What channel (1-36)? ")
|
||||
if err != nil {
|
||||
return s.abortOK0(err)
|
||||
}
|
||||
if strings.TrimSpace(c) == "" {
|
||||
c = "1"
|
||||
}
|
||||
if err := s.tune(st, c); err != nil {
|
||||
s.out(err.Error() + "\n")
|
||||
}
|
||||
}
|
||||
defer func() {
|
||||
s.node.LeaveRoom()
|
||||
for ch := range st.monitor {
|
||||
s.node.Part(cbRoom(ch))
|
||||
}
|
||||
setCBFlag(s.node.Num, "")
|
||||
}()
|
||||
err := s.cbLoop(st)
|
||||
if errors.Is(err, errLeaveCB) {
|
||||
s.out("\nThank you for using CB.\n")
|
||||
s.show(s.page)
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// setHandle checks and sets the caller's handle: not another member's
|
||||
// name ("" is the caller's own).
|
||||
func (s *session) setHandle(h string) error {
|
||||
h = bbs.Clean(h, 24)
|
||||
if h == "" {
|
||||
h = s.user.Name
|
||||
}
|
||||
if u, err := s.b.Store.UserByName(h); err == nil && u.ID != s.user.ID {
|
||||
return errors.New("That handle is another member's name.")
|
||||
}
|
||||
s.node.SetHandle(h)
|
||||
return nil
|
||||
}
|
||||
|
||||
// tune is /TUN n.
|
||||
func (s *session) tune(st *cbState, arg string) error {
|
||||
ch, err := strconv.Atoi(strings.TrimSpace(arg))
|
||||
if err != nil || ch < 1 || ch > cbChannels {
|
||||
return errors.New("Channels are 1 to 36.")
|
||||
}
|
||||
was := st.monitor[ch]
|
||||
if was {
|
||||
s.node.Part(cbRoom(ch))
|
||||
delete(st.monitor, ch)
|
||||
}
|
||||
hist, err := s.node.JoinRoom(cbRoom(ch))
|
||||
if err != nil {
|
||||
return fmt.Errorf("You cannot tune to channel %d: %v.", ch, err)
|
||||
}
|
||||
st.tuned = ch
|
||||
st.lastFrom = ""
|
||||
n := len(s.b.RoomMembers(cbRoom(ch))) - 1
|
||||
s.outf("(Tuned to channel %d, %d other%s here)\n", ch, n, plural(n))
|
||||
for _, e := range hist {
|
||||
if !was && (e.Kind == bbs.Said || e.Kind == bbs.Emoted) {
|
||||
s.cbShow(st, e)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// cbLoop reads lines, showing what is said meanwhile.
|
||||
func (s *session) cbLoop(st *cbState) error {
|
||||
var buf []byte
|
||||
last := time.Now()
|
||||
idle := s.b.Conf().IdleTimeout
|
||||
for {
|
||||
if evs := s.node.Pending(); len(evs) > 0 {
|
||||
if len(buf) > 0 {
|
||||
s.out("\n")
|
||||
}
|
||||
for _, e := range evs {
|
||||
s.cbShow(st, e)
|
||||
}
|
||||
if len(buf) > 0 {
|
||||
s.line.Write(buf)
|
||||
}
|
||||
}
|
||||
c, err := s.getc(250 * time.Millisecond)
|
||||
if errors.Is(err, errIdle) {
|
||||
if idle > 0 && time.Since(last) > idle {
|
||||
s.out("\n\nYou have been idle too long.\n")
|
||||
s.logoff()
|
||||
return errHangup
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
last = time.Now()
|
||||
if s.cr && (c == '\n' || c == 0) {
|
||||
s.cr = false
|
||||
continue
|
||||
}
|
||||
s.cr = false
|
||||
switch c {
|
||||
case '\r', '\n':
|
||||
s.cr = c == '\r'
|
||||
s.out("\n")
|
||||
line := string(buf)
|
||||
buf = buf[:0]
|
||||
if err := s.cbLine(st, line); err != nil {
|
||||
return err
|
||||
}
|
||||
case 8, 0x7F:
|
||||
if len(buf) > 0 {
|
||||
buf = buf[:len(buf)-1]
|
||||
s.out("\b \b")
|
||||
}
|
||||
case 0x15:
|
||||
if len(buf) > 0 {
|
||||
s.out("^U\n")
|
||||
}
|
||||
buf = buf[:0]
|
||||
case 0x16:
|
||||
s.out("\n" + string(buf))
|
||||
case 3, 0x10:
|
||||
s.out("^C\n")
|
||||
buf = buf[:0]
|
||||
default:
|
||||
if c < 0x20 || len(buf) >= bbs.MaxChatLine {
|
||||
continue
|
||||
}
|
||||
buf = append(buf, c)
|
||||
s.line.Write([]byte{c})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cbName is who an event is from: the handle, or the name.
|
||||
func cbName(e bbs.Event) string {
|
||||
if e.Handle != "" {
|
||||
return e.Handle
|
||||
}
|
||||
return e.From
|
||||
}
|
||||
|
||||
// cbShow shows an event as CB does.
|
||||
func (s *session) cbShow(st *cbState, e bbs.Event) {
|
||||
name := cbName(e)
|
||||
if st.squelch[strings.ToUpper(name)] {
|
||||
return
|
||||
}
|
||||
ch := cbChannel(e.Room)
|
||||
tag := "(" + name + ")"
|
||||
if ch != st.tuned {
|
||||
tag = fmt.Sprintf("(%d,%s)", ch, name)
|
||||
}
|
||||
switch e.Kind {
|
||||
case bbs.Said, bbs.Emoted:
|
||||
if e.Node == s.node.Num {
|
||||
return // typed, so already seen
|
||||
}
|
||||
if ch == st.tuned {
|
||||
st.lastFrom = e.From
|
||||
}
|
||||
text := e.Text
|
||||
if st.rcvKey != "" {
|
||||
text = unscramble(st.rcvKey, text)
|
||||
}
|
||||
if e.Kind == bbs.Emoted {
|
||||
s.outf("%s *%s*\n", tag, text)
|
||||
} else {
|
||||
s.outf("%s %s\n", tag, text)
|
||||
}
|
||||
case bbs.Joined:
|
||||
if e.Node != s.node.Num {
|
||||
s.outf("** %s tuned in to channel %d **\n", name, ch)
|
||||
}
|
||||
case bbs.Left:
|
||||
if e.Node != s.node.Num {
|
||||
s.outf("** %s left channel %d **\n", name, ch)
|
||||
}
|
||||
case bbs.Private:
|
||||
s.outf("(Talk %d,%s) %s\n", e.Node, name, e.Text)
|
||||
case bbs.Topic:
|
||||
default:
|
||||
s.out(e.String() + "\n")
|
||||
}
|
||||
}
|
||||
|
||||
// cbLine does a line typed in CB: a /command, or something to say.
|
||||
func (s *session) cbLine(st *cbState, line string) error {
|
||||
if strings.TrimSpace(line) == "" {
|
||||
return nil
|
||||
}
|
||||
if !strings.HasPrefix(line, "/") {
|
||||
if st.talk != 0 {
|
||||
if err := s.node.Message(st.talk, line); err != nil {
|
||||
s.outf("?%v\n", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if st.xmitKey != "" {
|
||||
line = scramble(st.xmitKey, line)
|
||||
}
|
||||
if err := s.node.Say(line, false); err != nil {
|
||||
s.outf("?%v\n", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
verb, arg, _ := strings.Cut(line[1:], " ")
|
||||
verb, arg = strings.ToUpper(verb), strings.TrimSpace(arg)
|
||||
switch {
|
||||
case is(verb, "TUNE", 3):
|
||||
if err := s.tune(st, arg); err != nil {
|
||||
s.out(err.Error() + "\n")
|
||||
}
|
||||
case is(verb, "MONITOR", 3):
|
||||
for _, ch := range channels(arg) {
|
||||
if ch == st.tuned || st.monitor[ch] {
|
||||
continue
|
||||
}
|
||||
if _, err := s.node.JoinAlso(cbRoom(ch)); err != nil {
|
||||
s.outf("?Channel %d: %v\n", ch, err)
|
||||
continue
|
||||
}
|
||||
st.monitor[ch] = true
|
||||
}
|
||||
s.monitoring(st)
|
||||
case is(verb, "UNMONITOR", 3):
|
||||
for _, ch := range channels(arg) {
|
||||
if st.monitor[ch] {
|
||||
s.node.Part(cbRoom(ch))
|
||||
delete(st.monitor, ch)
|
||||
}
|
||||
}
|
||||
s.monitoring(st)
|
||||
case is(verb, "STATUS", 3):
|
||||
s.cbStatus()
|
||||
case is(verb, "TIME", 3):
|
||||
s.out(s.now().Format("3:04:05 PM MST Monday, January 2, 2006") + "\n")
|
||||
case is(verb, "USTATUS", 3):
|
||||
s.ust(arg)
|
||||
case is(verb, "EXIT", 3) || is(verb, "OFF", 3) || is(verb, "QUIT", 4):
|
||||
if st.talk != 0 && is(verb, "EXIT", 3) {
|
||||
s.endTalk(st)
|
||||
return nil
|
||||
}
|
||||
if is(verb, "OFF", 3) {
|
||||
s.logoff()
|
||||
return errHangup
|
||||
}
|
||||
return errLeaveCB
|
||||
case is(verb, "WHO", 3):
|
||||
if st.lastFrom == "" {
|
||||
s.out("No one has talked yet.\n")
|
||||
} else if u, err := s.b.Store.UserByName(st.lastFrom); err == nil {
|
||||
s.out(PPN(u.ID) + "\n")
|
||||
} else {
|
||||
s.out(st.lastFrom + "\n")
|
||||
}
|
||||
case is(verb, "HANDLE", 3):
|
||||
if arg == "" {
|
||||
var err error
|
||||
if arg, err = s.prompt("New handle: "); err != nil {
|
||||
return s.abortOK0(err)
|
||||
}
|
||||
}
|
||||
if err := s.setHandle(arg); err != nil {
|
||||
s.out(err.Error() + "\n")
|
||||
} else {
|
||||
s.outf("Your handle is %s\n", s.node.Handle())
|
||||
}
|
||||
case verb == "SCR" || verb == "SCRAMBLE":
|
||||
st.xmitKey, st.rcvKey = arg, arg
|
||||
s.scrambled(st)
|
||||
case verb == "SMC":
|
||||
st.xmitKey, st.rcvKey = arg, ""
|
||||
s.scrambled(st)
|
||||
case verb == "XCL":
|
||||
st.xmitKey, st.rcvKey = "", arg
|
||||
s.scrambled(st)
|
||||
case is(verb, "UNSCRAMBLE", 3):
|
||||
st.xmitKey, st.rcvKey = "", ""
|
||||
s.scrambled(st)
|
||||
case is(verb, "SQUELCH", 3):
|
||||
if arg == "" {
|
||||
s.out("Squelch whose handle?\n")
|
||||
} else if k := strings.ToUpper(arg); st.squelch[k] {
|
||||
delete(st.squelch, k)
|
||||
s.outf("%s is no longer squelched\n", arg)
|
||||
} else {
|
||||
st.squelch[k] = true
|
||||
s.outf("%s is squelched\n", arg)
|
||||
}
|
||||
case is(verb, "JOB", 3):
|
||||
s.outf("Your job number is %d\n", s.node.Num)
|
||||
case is(verb, "TALK", 3):
|
||||
return s.startTalk(st, arg)
|
||||
case is(verb, "ROLL", 3):
|
||||
n, sides := 2, 6
|
||||
if a, b, ok := strings.Cut(strings.ToUpper(arg), "D"); ok {
|
||||
n, _ = strconv.Atoi(a)
|
||||
sides, _ = strconv.Atoi(b)
|
||||
}
|
||||
n, sides = min(max(n, 1), 10), min(max(sides, 2), 100)
|
||||
var rolls []string
|
||||
for range n {
|
||||
rolls = append(rolls, strconv.Itoa(1+rand.IntN(sides)))
|
||||
}
|
||||
text := "rolls " + strings.Join(rolls, ",")
|
||||
s.outf("You roll %s\n", strings.Join(rolls, ","))
|
||||
if err := s.node.Say(text, true); err != nil {
|
||||
s.outf("?%v\n", err)
|
||||
}
|
||||
case is(verb, "GAG", 3):
|
||||
s.out("/GAG is for CompuServe's staff.\n")
|
||||
case is(verb, "HELP", 1) || verb == "?":
|
||||
s.cbHelp()
|
||||
default:
|
||||
s.outf("?Unknown command /%s; /HELP for a list\n", verb)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// channels reads "1,4" or "1 4".
|
||||
func channels(arg string) []int {
|
||||
var out []int
|
||||
for _, f := range strings.FieldsFunc(arg, func(r rune) bool { return r == ',' || r == ' ' }) {
|
||||
if n, err := strconv.Atoi(f); err == nil && n >= 1 && n <= cbChannels {
|
||||
out = append(out, n)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *session) monitoring(st *cbState) {
|
||||
if len(st.monitor) == 0 {
|
||||
s.out("Monitoring no other channels\n")
|
||||
return
|
||||
}
|
||||
var chs []int
|
||||
for ch := range st.monitor {
|
||||
chs = append(chs, ch)
|
||||
}
|
||||
sort.Ints(chs)
|
||||
var ss []string
|
||||
for _, ch := range chs {
|
||||
ss = append(ss, strconv.Itoa(ch))
|
||||
}
|
||||
s.out("Monitoring channels " + strings.Join(ss, ",") + "\n")
|
||||
}
|
||||
|
||||
func (s *session) scrambled(st *cbState) {
|
||||
switch {
|
||||
case st.xmitKey != "" && st.rcvKey != "":
|
||||
s.out("Scrambled\n")
|
||||
case st.xmitKey != "":
|
||||
s.out("Transmitting scrambled, receiving clear\n")
|
||||
case st.rcvKey != "":
|
||||
s.out("Transmitting clear, unscrambling what you receive\n")
|
||||
default:
|
||||
s.out("Clear\n")
|
||||
}
|
||||
if st.talk == 0 {
|
||||
f := ""
|
||||
if st.xmitKey != "" {
|
||||
f = "s"
|
||||
}
|
||||
setCBFlag(s.node.Num, f)
|
||||
}
|
||||
}
|
||||
|
||||
// cbStatus is /STA: how many are on each channel in use.
|
||||
func (s *session) cbStatus() {
|
||||
s.out("Ch Users\n-- -----\n")
|
||||
any := false
|
||||
for ch := 1; ch <= cbChannels; ch++ {
|
||||
if n := len(s.b.RoomMembers(cbRoom(ch))); n > 0 {
|
||||
s.outf("%2d %5d\n", ch, n)
|
||||
any = true
|
||||
}
|
||||
}
|
||||
if !any {
|
||||
s.out("No one is on CB.\n")
|
||||
}
|
||||
}
|
||||
|
||||
// ust is /UST [ch]: who is on CB, the 1986 way.
|
||||
func (s *session) ust(arg string) {
|
||||
only := channels(arg)
|
||||
s.out(" Job User Id Ch. Node Handle\n --- ---------- --- ---- ------\n")
|
||||
i := 0
|
||||
for ch := 1; ch <= cbChannels; ch++ {
|
||||
if len(only) > 0 && only[0] != ch {
|
||||
continue
|
||||
}
|
||||
for _, m := range s.b.RoomMembers(cbRoom(ch)) {
|
||||
id := ""
|
||||
if u, err := s.b.Store.UserByName(m.Name); err == nil {
|
||||
id = PPN(u.ID)
|
||||
}
|
||||
c := strconv.Itoa(ch)
|
||||
switch f := cbFlag(m.Node); f {
|
||||
case "Tlk":
|
||||
c = f
|
||||
case "s":
|
||||
c += f
|
||||
}
|
||||
node := strings.ToUpper(m.Via)
|
||||
if len(node) > 3 {
|
||||
node = node[:3]
|
||||
}
|
||||
h := m.Handle
|
||||
if h == "" {
|
||||
h = m.Name
|
||||
}
|
||||
i++
|
||||
s.outf("%d) %3d %-10s %3s %-4s %s\n", i, m.Node, id, c, node, h)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// startTalk is /TALK job: what is typed goes to that caller alone.
|
||||
func (s *session) startTalk(st *cbState, arg string) error {
|
||||
if arg == "" && st.talk != 0 {
|
||||
s.endTalk(st)
|
||||
return nil
|
||||
}
|
||||
job, err := strconv.Atoi(arg)
|
||||
if err != nil {
|
||||
for _, ch := range append([]int{st.tuned}, keys(st.monitor)...) {
|
||||
for _, m := range s.b.RoomMembers(cbRoom(ch)) {
|
||||
if strings.EqualFold(m.Handle, arg) || strings.EqualFold(m.Name, arg) {
|
||||
job = m.Node
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if job == 0 || job == s.node.Num {
|
||||
s.out("Talk to which job? /UST shows them.\n")
|
||||
return nil
|
||||
}
|
||||
if err := s.node.Message(job, fmt.Sprintf("wants to /TALK with you: /TALK %d", s.node.Num)); err != nil {
|
||||
s.outf("?%v\n", err)
|
||||
return nil
|
||||
}
|
||||
st.talk = job
|
||||
setCBFlag(s.node.Num, "Tlk")
|
||||
s.outf("Talking with job %d; /EXIT to return to channel %d\n", job, st.tuned)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *session) endTalk(st *cbState) {
|
||||
st.talk = 0
|
||||
s.scrambled(st)
|
||||
s.outf("Back on channel %d\n", st.tuned)
|
||||
}
|
||||
|
||||
func keys(m map[int]bool) []int {
|
||||
var out []int
|
||||
for k := range m {
|
||||
out = append(out, k)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *session) cbHelp() {
|
||||
s.out(` /TUN # - Tunes channel # (1-36)
|
||||
/MON 1,4 - Listen to extra chnls
|
||||
/UNM 7,3 - Unmonitor channels
|
||||
/STA - Type channel status
|
||||
/TIM - Type time, day, and date
|
||||
/UST - User STatus typeout
|
||||
/EXI - Exit CB Simulator
|
||||
/WHO - Type PPN of last talker
|
||||
/HAN - Change handle
|
||||
/SCR xyz - Scramble on key "xyz"
|
||||
/SMC xyz - Scr & Monitor Clear
|
||||
/XCL xyz - Xmt CLear; unscr rcvr
|
||||
/UNS - Unscramble (both clear)
|
||||
/SQU abc - Squelch handle "abc"
|
||||
/JOB - your job #
|
||||
/TALK # - talk with job # alone
|
||||
/ROLL - roll dice (/ROLL 3D6)
|
||||
/HELP - Type this message
|
||||
`)
|
||||
}
|
||||
|
||||
// The scramble: the printable characters but space, permuted by the key.
|
||||
func scrambleTable(key string) (fwd, back [128]byte) {
|
||||
h := fnv.New64a()
|
||||
h.Write([]byte(strings.ToUpper(key)))
|
||||
r := rand.New(rand.NewPCG(h.Sum64(), 0x43425349)) // "CBSI"
|
||||
perm := r.Perm(94)
|
||||
for i := range fwd {
|
||||
fwd[i], back[i] = byte(i), byte(i)
|
||||
}
|
||||
for i, p := range perm {
|
||||
fwd[0x21+i] = byte(0x21 + p)
|
||||
back[0x21+p] = byte(0x21 + i)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func mapText(t [128]byte, text string) string {
|
||||
b := []byte(text)
|
||||
for i, c := range b {
|
||||
if c < 128 {
|
||||
b[i] = t[c]
|
||||
}
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func scramble(key, text string) string {
|
||||
f, _ := scrambleTable(key)
|
||||
return mapText(f, text)
|
||||
}
|
||||
|
||||
func unscramble(key, text string) string {
|
||||
_, b := scrambleTable(key)
|
||||
return mapText(b, text)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cis
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestScramble(t *testing.T) {
|
||||
text := "Hello, CB! 123"
|
||||
s := scramble("xyz", text)
|
||||
if s == text || len(s) != len(text) || s[5] != ',' && s[6] != ' ' {
|
||||
t.Errorf("scrambled %q", s)
|
||||
}
|
||||
if s[6] != ' ' {
|
||||
t.Errorf("spaces are kept: %q", s)
|
||||
}
|
||||
if u := unscramble("XYZ", s); u != text {
|
||||
t.Errorf("unscrambled %q", u)
|
||||
}
|
||||
if u := unscramble("abc", s); u == text {
|
||||
t.Error("another key unscrambled it")
|
||||
}
|
||||
}
|
||||
@@ -64,8 +64,11 @@
|
||||
prompt or command mode (SET), with downloads and uploads of mail by
|
||||
the B protocols. Send to a name, a User ID, or a FidoNet address.
|
||||
|
||||
On their way, in this order: the CB Simulator, and the CompuServe
|
||||
Information Manager (CIM) graphical service.
|
||||
The CB Simulator (GO CB) is on the BBS's chat rooms: channel 1 is
|
||||
the room cb-1, and so on to 36. /HELP there lists its commands.
|
||||
|
||||
On its way: the CompuServe Information Manager (CIM) graphical
|
||||
service.
|
||||
|
||||
:RATES CHARGES BILLING NEWBIL
|
||||
=CompuServe
|
||||
@@ -143,9 +146,9 @@
|
||||
=CompuServe
|
||||
(This menu is made from the BBS's message areas when shown.)
|
||||
|
||||
:CB CB-1 CHAT
|
||||
:CB CB-1 CHAT CBS
|
||||
=CB Simulator
|
||||
The CB Simulator is on its way, on the BBS's chat rooms.
|
||||
(Going here enters the CB Simulator, on the BBS's chat rooms.)
|
||||
|
||||
:DIRECTORY
|
||||
=CompuServe
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/D-Modem/bbs/internal/ui3270"
|
||||
)
|
||||
|
||||
// TestCompuServeCB: two callers on the CB Simulator: handles, a channel,
|
||||
// /UST, a monitored channel, scrambling and /EXI.
|
||||
func TestCompuServeCB(t *testing.T) {
|
||||
e := startFull(t, ui3270.Graphics{}, nil, nil, cisListener())
|
||||
|
||||
a := cisLogin(e, "72000,1", "alicepass1")
|
||||
a.send("GO CB\r")
|
||||
a.expect("CompuServe CB Simulator")
|
||||
a.expect("What's your handle? ")
|
||||
a.send("sysop\r")
|
||||
a.expect("That handle is another member's name.")
|
||||
a.expect("What's your handle? ")
|
||||
a.send("Red Leather\r")
|
||||
a.expect("What channel (1-36)? ")
|
||||
a.send("17\r")
|
||||
a.expect("(Tuned to channel 17, 0 others here)\r\n")
|
||||
|
||||
b := cisLogin(e, "72000,2", "sysoppass1")
|
||||
b.send("GO CB\r")
|
||||
b.expect("What's your handle? ")
|
||||
b.send("Old Man\r")
|
||||
b.expect("What channel (1-36)? ")
|
||||
b.send("\r")
|
||||
b.expect("(Tuned to channel 1, 0 others here)\r\n")
|
||||
b.send("/MON 17\r")
|
||||
b.expect("Monitoring channels 17\r\n")
|
||||
|
||||
a.send("Does anyone know what time it is?\r")
|
||||
b.expect("(17,Red Leather) Does anyone know what time it is?\r\n")
|
||||
b.send("/TUN 17\r")
|
||||
b.expect("(Tuned to channel 17, 1 other here)\r\n")
|
||||
a.expect("** Old Man tuned in to channel 17 **\r\n")
|
||||
b.send("Time for CB.\r")
|
||||
a.expect("(Old Man) Time for CB.\r\n")
|
||||
a.send("/WHO\r")
|
||||
a.expect("72000,2\r\n")
|
||||
a.send("/UST\r")
|
||||
a.expect(" Job User Id Ch. Node Handle\r\n --- ---------- --- ---- ------\r\n")
|
||||
a.expect(" 72000,1 17 ")
|
||||
a.expect("Red Leather\r\n")
|
||||
a.expect(" 72000,2 17 ")
|
||||
a.expect("Old Man\r\n")
|
||||
|
||||
// scrambled: clear to the same key, garbage to the rest
|
||||
a.send("/SCR secret\r")
|
||||
a.expect("Scrambled\r\n")
|
||||
a.send("meet at noon\r")
|
||||
b.expect("(Red Leather) ")
|
||||
b.expect("\r\n")
|
||||
if got := string(b.before); strings.Contains(got, "meet") {
|
||||
t.Errorf("unscrambled without the key: %q", got)
|
||||
}
|
||||
b.send("/SCR secret\r")
|
||||
b.expect("Scrambled\r\n")
|
||||
a.send("meet at noon\r")
|
||||
b.expect("(Red Leather) meet at noon\r\n")
|
||||
a.send("/UST 17\r")
|
||||
a.expect(" 17s ")
|
||||
|
||||
b.send("/EXI\r")
|
||||
b.expect("Thank you for using CB.")
|
||||
b.expect("Enter choice !")
|
||||
a.expect("** Old Man left channel 17 **")
|
||||
a.send("/OFF\r")
|
||||
a.expect("Thank you for using CompuServe!")
|
||||
b.send("OFF\r")
|
||||
b.expect("Thank you for using CompuServe!")
|
||||
}
|
||||
Reference in new issue
Block a user