mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-28 17:38:04 -08:00
Merge main into time sync (beside the AOL host)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRUSPBZTX8wShmaLrrg
This commit is contained in:
24 files changed
+1747
-18
No files matched your search
@@ -4,8 +4,8 @@ Ideas not yet started, with what is known of them.
|
||||
|
||||
## An AOL front end
|
||||
|
||||
*Status: started; the FDO91 layer (`internal/aol/fdo`) and P3
|
||||
(`internal/aol/p3`) are done.*
|
||||
*Status: started; FDO91 (`internal/aol/fdo`), P3 (`internal/aol/p3`) and
|
||||
the host's sign-on (`internal/aol`, `[aol]`) are done.*
|
||||
|
||||
For AOL 3.0 and 4.0 for Windows, the real clients, over TCP (port 5190, the
|
||||
client's `AmericaOnline.aol.com`) and by modem.
|
||||
@@ -19,12 +19,14 @@ client's `AmericaOnline.aol.com`) and by modem.
|
||||
end of a link: INIT acknowledged, DATA in order in and within a window
|
||||
of 16 out, ACKs every 8 or soon after, NAKs and go-back-N resends,
|
||||
heartbeats after 12 seconds, 10 of them and the link is down.
|
||||
- **Listener**, next: OSCAR's port 5190 already hands a connection that
|
||||
starts with P3's sync byte to `oscar.Server.P3`; serve it there with
|
||||
`p3.Serve`, and sniff a P3 INIT (`p3.Sniff`) on the telnet port too.
|
||||
- **Tokens**: `Dd` sign-on (the form's two `de_data`) to the BBS's login,
|
||||
then chat (`Aa`), IMs (`iS`), mail (`m4`, MIP), keywords (`k1`/`f1`) to
|
||||
areas, `pE` sign-off; each answered with forms compiled from source.
|
||||
- **Host** (started): `[aol]`, sharing 5190 with `[oscar]` through its P3
|
||||
hook; `Dd` signs on with a BBS account (a node, as any caller), then
|
||||
`async_online`, the client's main window (32-296) and the BBS's own
|
||||
Welcome; `pE` answered with `XS`; other tokens with `uni_wait_off`.
|
||||
Streams go as `aT`, or `at` pieces when long; the client's long ones
|
||||
are put together. Not yet tried with a real client.
|
||||
- **Tokens**, next: chat (`Aa`), IMs (`iS`), mail (`m4`, MIP), keywords
|
||||
(`k1`/`f1`) to areas; each answered with forms compiled from source.
|
||||
- **Modem callers**: the client's CCL script expects a network's prompts
|
||||
(SprintNet, Tymnet) before P3; emulate one, or ship a CCL that dials
|
||||
straight in.
|
||||
|
||||
@@ -670,6 +670,16 @@ address = 127.0.0.1:2513
|
||||
; the screen name the BBS's notices come from
|
||||
;system = OnlineHost
|
||||
|
||||
; AOL: a host for AOL's own clients (3.0, 4.0 and on, over TCP). Users sign
|
||||
; on with their BBS names and passwords and get the BBS's Welcome window.
|
||||
; The client's port is 5190: with [oscar] there too, the two share it. The
|
||||
; client finds its host as AmericaOnline.aol.com (point that name here in
|
||||
; its machine's hosts file, or edit its TCP.CCL).
|
||||
;[aol]
|
||||
;address = :5190
|
||||
;max_clients = 256
|
||||
;max_per_ip = 4
|
||||
|
||||
; MSN Messenger: the chat for MSN Messenger 1.0 to 4.7 and Windows
|
||||
; Messenger 4.x (MSNP2 to 7), beside IRC and AIM. Users sign in as
|
||||
; name@domain with their BBS passwords; contacts are their friends list;
|
||||
|
||||
@@ -48,6 +48,7 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"log/syslog"
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
@@ -58,6 +59,7 @@ import (
|
||||
|
||||
"golang.org/x/term"
|
||||
|
||||
"github.com/D-Modem/bbs/internal/aol"
|
||||
"github.com/D-Modem/bbs/internal/api"
|
||||
"github.com/D-Modem/bbs/internal/bbs"
|
||||
"github.com/D-Modem/bbs/internal/events"
|
||||
@@ -272,6 +274,9 @@ func main() {
|
||||
if o := cfg.OSCAR; o != nil {
|
||||
fmt.Printf("oscar: %q, reconnect at %q, ICQ numbers from %d\n", o.Address, o.Host, o.UINBase)
|
||||
}
|
||||
if a := cfg.AOL; a != nil {
|
||||
fmt.Printf("aol: %q\n", a.Address)
|
||||
}
|
||||
if m := cfg.MSN; m != nil {
|
||||
fmt.Printf("msn: %q, conversations at %q, handles @%s\n", m.Address, m.Host, m.Domain)
|
||||
}
|
||||
@@ -473,12 +478,23 @@ func serve(cfg *server.Config, path string) int {
|
||||
}
|
||||
}()
|
||||
}
|
||||
var asrv *aol.Server
|
||||
if cfg.AOL != nil {
|
||||
if asrv, err = aol.New(b, *cfg.AOL); err != nil {
|
||||
lg.Printf("%v", err)
|
||||
return 1
|
||||
}
|
||||
}
|
||||
if cfg.OSCAR != nil {
|
||||
osrv, err := oscar.New(b, *cfg.OSCAR)
|
||||
if err != nil {
|
||||
lg.Printf("%v", err)
|
||||
return 1
|
||||
}
|
||||
if asrv != nil && sameAddress(cfg.OSCAR.Address, cfg.AOL.Address) {
|
||||
osrv.P3 = asrv.Handle // AOL's clients come to OSCAR's port
|
||||
asrv = nil
|
||||
}
|
||||
go func() {
|
||||
if err := osrv.Run(ctx); err != nil {
|
||||
lg.Printf("%v", err)
|
||||
@@ -486,6 +502,14 @@ func serve(cfg *server.Config, path string) int {
|
||||
}
|
||||
}()
|
||||
}
|
||||
if asrv != nil {
|
||||
go func() {
|
||||
if err := asrv.Run(ctx); err != nil {
|
||||
lg.Printf("%v", err)
|
||||
stop()
|
||||
}
|
||||
}()
|
||||
}
|
||||
if cfg.MSN != nil {
|
||||
msrv, err := msn.New(b, *cfg.MSN)
|
||||
if err != nil {
|
||||
@@ -1695,3 +1719,15 @@ func dbCmd(cfg *server.Config, args []string) {
|
||||
}
|
||||
fmt.Println("done: set database = in the configuration to the new one")
|
||||
}
|
||||
|
||||
// sameAddress is whether two listening addresses are one port: the same
|
||||
// port, on the same host or on every one.
|
||||
func sameAddress(a, b string) bool {
|
||||
ah, ap, err1 := net.SplitHostPort(a)
|
||||
bh, bp, err2 := net.SplitHostPort(b)
|
||||
if err1 != nil || err2 != nil || ap != bp {
|
||||
return false
|
||||
}
|
||||
any := func(h string) bool { return h == "" || h == "0.0.0.0" || h == "::" }
|
||||
return ah == bh || any(ah) || any(bh)
|
||||
}
|
||||
@@ -265,6 +265,14 @@ PERMANENT SETTINGS
|
||||
|
||||
Each change ends with a confirm screen: `CHANGE PERMANENT SETTINGS 1 Confirm 2 Cancel`.
|
||||
|
||||
**As built** (`internal/cis/profile.go`, test `TestCompuServeDefault`, which replays PARAMS.SCR's sends and waits):
|
||||
- The menus, their order, the bracketed values (right-aligned at column 40) and the setting screens are PARAMS.SCR's.
|
||||
- Screens the script never shows are ours: Instructions, the two Explanations, Show session vs. permanent, Change current session settings, CLEAR/BLANK/LF, FEEDS/TABS, the GIF/NAPLPS/RLE screens, and the number prompts (which end in `:`, as the script waits for).
|
||||
- `<CR>` goes up a level. A command typed at any prompt leaves DEFAULT with the changes unsaved, then runs the command.
|
||||
- After Confirm or Cancel the host shows `GO PROFILE`, as in the script.
|
||||
- Choosing a terminal type sets WIDTH 80, LINES 24, PARITY EVEN and ERASE NO, as the transcript shows.
|
||||
- Values are kept as prefs: `cis-paged`, `cis-width` and so on.
|
||||
|
||||
Other notes:
|
||||
- "Micro inquiry sequence at logon" is the setting that sends `ESC I` at login (doc 03 §5).
|
||||
- **Compatibility minimum** [V, S10]: TAPCIS requires PAGED=NO and COMMAND mode in forums and Mail ("COMMAND mode is essential. TAPCIS will not work in any other"). Navigator for the Mac needs "TOP goes to MAIN".
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
The BBS can be an AOL host for AOL's own Windows clients (3.0, 4.0 and
|
||||
later) over TCP. A caller signs on in the client with their BBS name and
|
||||
password, and the BBS draws its Welcome window. This is early work: sign-on
|
||||
and sign-off work, and chat, IMs, mail and keywords are still to come.
|
||||
|
||||
```ini
|
||||
[aol]
|
||||
address = :5190
|
||||
```
|
||||
|
||||
| Setting | Default | What it sets |
|
||||
|---|---|---|
|
||||
| `address` | `:5190` | where to listen |
|
||||
| `max_clients` | `256` | clients at once |
|
||||
| `max_per_ip` | `4` | from one address |
|
||||
|
||||
Port 5190 is also the [AIM and ICQ](AIM-and-ICQ) server's. With `[oscar]`
|
||||
on the same address, the two share it: a connection that begins as an AOL
|
||||
client's goes to the AOL host, and everything else stays with OSCAR.
|
||||
|
||||
## Pointing the client at the BBS
|
||||
|
||||
The client's TCP connection (`TCP.CCL` in its folder) dials
|
||||
`AmericaOnline.aol.com` on port 5190. Either point that name at the BBS in
|
||||
the hosts file of the client's machine
|
||||
(`C:\Windows\hosts` on Windows 95 and 98), or change the name in `TCP.CCL`.
|
||||
Then pick "TCP/IP" as the connection in the client's Setup.
|
||||
|
||||
## Signing on
|
||||
|
||||
The screen name and password on the client's Welcome window are a BBS
|
||||
account's. "New User" does not make an account; callers join by telnet or
|
||||
the web first. A failed sign-on is shown in the client, and counts against
|
||||
the address as failed logins do everywhere else. The deny list and bans in
|
||||
`[security]` apply.
|
||||
|
||||
A signed-on client is a node, as any caller is, and appears in Who's On
|
||||
as `AOL`. Sign Off in the client signs off and hangs up.
|
||||
|
||||
## How it is built
|
||||
|
||||
- `internal/aol/p3`: P3, the client's link layer (packets, checksums,
|
||||
acknowledgements, resends).
|
||||
- `internal/aol/fdo`: FDO91, the forms language the client draws windows
|
||||
from. It has a compiler from FDO91 source, so the host's windows are
|
||||
written as source.
|
||||
- `internal/aol`: the host, which handles each token the client sends.
|
||||
+25
-1
@@ -109,6 +109,30 @@ testing.
|
||||
|
||||
Commands chain with `;`, as in `SET BRI ON;GO RATES`.
|
||||
|
||||
## Terminal settings (GO DEFAULT)
|
||||
|
||||
`SET` changes the session's settings. `GO DEFAULT` (or `TERMINAL`, or
|
||||
choice 1 of `GO PROFILE`) keeps them with your User ID, through
|
||||
CompuServe's own menus: TERMINAL SETTINGS/SERVICE OPTIONS, then
|
||||
PERMANENT SETTINGS with its Logon/Service, Display, Terminal and
|
||||
Transfer protocol groups. When you leave, you confirm the changes. The
|
||||
screens follow TAPCIS's ALT-P script (PARAMS.SCR, 1991), which sets a new
|
||||
member up through them.
|
||||
|
||||
What the kept settings do:
|
||||
|
||||
- PAGED, BRIEF, WIDTH and LINES take effect at each logon.
|
||||
- **Mail waiting: Go to MAIL** goes straight into Mail when letters wait.
|
||||
- **Online editor** sets Mail's line numbering when Mail has no setting
|
||||
of its own.
|
||||
- **Protocol preference** (B, Quick B, XMODEM or Kermit) skips the
|
||||
protocol menu.
|
||||
|
||||
The rest are kept and shown, as scripts expect, but do nothing here:
|
||||
terminal type, parity, delays, first service, TOP goes to, forum mode and
|
||||
graphics support. Forums are always in command mode. Add `;TTY` to the
|
||||
User ID (`72000,1;TTY`) to log on with the defaults for once.
|
||||
|
||||
## Forums
|
||||
|
||||
`GO FORUMS` lists the forums. Each forum is a group of the BBS's message
|
||||
@@ -254,7 +278,7 @@ so only callers using the same key read each other.
|
||||
|
||||
| Done | Coming, in order |
|
||||
|---|---|
|
||||
| The logon, `ESC I`, the menus and articles (`internal/cis/pages.txt`), GO, FIND, SET | Forum JOIN and member options |
|
||||
| The logon, `ESC I`, the menus and articles (`internal/cis/pages.txt`), GO, FIND, SET, permanent settings (GO DEFAULT) | Forum JOIN and member options |
|
||||
| Forums on the message areas, with the forum command language | |
|
||||
| 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 | |
|
||||
|
||||
@@ -32,6 +32,7 @@ the file is laid out.
|
||||
| [`[door NAME]`](#door-name) | A door: a program callers play, or another system's doors. |
|
||||
| [`[irc]`](#irc) | IRC: the chat rooms as channels (#main ...), for IRC clients. |
|
||||
| [`[oscar]`](#oscar) | AIM and ICQ: the chat for AIM and ICQ clients (OSCAR), beside IRC. |
|
||||
| [`[aol]`](#aol) | AOL: a host for AOL's own clients (3.0, 4.0 and on, over TCP). |
|
||||
| [`[msn]`](#msn) | MSN Messenger: the chat for MSN Messenger 1.0 to 4.7 and Windows Messenger 4.x (MSNP2 to 7), beside IRC and AIM. |
|
||||
| [`[mrc]`](#mrc) | Multi Relay Chat: the BBSes' chat network. |
|
||||
| [`[finger]`](#finger) | finger: who is on ("finger @host"), and who a user is ("finger name@host"). |
|
||||
@@ -454,6 +455,17 @@ AIM and ICQ: the chat for AIM and ICQ clients (OSCAR), beside IRC. Users sign o
|
||||
| `system` | | | the screen name the BBS's notices come from. Examples: `OnlineHost`. |
|
||||
|
||||
|
||||
## `[aol]`
|
||||
|
||||
AOL: a host for AOL's own clients (3.0, 4.0 and on, over TCP). Users sign on with their BBS names and passwords and get the BBS's Welcome window. The client's port is 5190: with [oscar] there too, the two share it. The client finds its host as AmericaOnline.aol.com (point that name here in its machine's hosts file, or edit its TCP.CCL).
|
||||
|
||||
| key | default | live | what it does |
|
||||
|---|---|---|---|
|
||||
| `address` | | | See the section above. Examples: `:5190`. |
|
||||
| `max_clients` | | | See the section above. Examples: `256`. |
|
||||
| `max_per_ip` | | | See the section above. Examples: `4`. |
|
||||
|
||||
|
||||
## `[msn]`
|
||||
|
||||
MSN Messenger: the chat for MSN Messenger 1.0 to 4.7 and Windows Messenger 4.x (MSNP2 to 7), beside IRC and AIM. Users sign in as name@domain with their BBS passwords; contacts are their friends list; an IM is a private message (a PRIVMSG on IRC), kept for one away. The clients must be pointed at this host (see the wiki page). See docs/wiki/MSN-Messenger.md.
|
||||
|
||||
@@ -137,6 +137,7 @@ which is generated from `bbs.conf.sample`.
|
||||
| [Chat and paging](Chat-and-Paging) | chat rooms, node messages, paging the sysop |
|
||||
| [IRC](IRC) | the IRC server, with the chat rooms as channels |
|
||||
| [AIM and ICQ](AIM-and-ICQ) | the OSCAR server: AIM and ICQ clients, buddies, IMs and chat rooms |
|
||||
| [AOL clients](AOL) | a host for AOL's own clients (3.0, 4.0): sign-on with BBS accounts |
|
||||
| [MSN Messenger](MSN-Messenger) | the MSN server: MSN Messenger 1.0 to 4.7, contacts and IMs |
|
||||
| [MRC](MRC) | Multi Relay Chat: chat rooms shared with other BBSes |
|
||||
| [Finger and gopher](Finger-and-Gopher) | who is on, and the BBS in gopherspace |
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
- [Chat and paging](Chat-and-Paging)
|
||||
- [IRC](IRC)
|
||||
- [AIM and ICQ](AIM-and-ICQ)
|
||||
- [AOL clients](AOL)
|
||||
- [MSN Messenger](MSN-Messenger)
|
||||
- [MRC](MRC)
|
||||
- [Finger and gopher](Finger-and-Gopher)
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
// Package aol is the BBS as an AOL host, for AOL's own clients (3.0, 4.0
|
||||
// and on) over TCP: P3 (package p3) carries tokens, a two-letter name and
|
||||
// what follows it, each way; the client's forms send their fields as FDO91
|
||||
// atom streams (package fdo), and the host answers with streams of its
|
||||
// own that draw windows and run actions.
|
||||
//
|
||||
// The client signs on with a BBS account (the Welcome form's screen name
|
||||
// and password, token Dd), and signs off with pE. The client's own
|
||||
// database has most of its windows; the host draws its own Welcome.
|
||||
//
|
||||
// Sources for what the client expects: Dialtone (MIT) and other hosts
|
||||
// serving live clients, and notes on the 3.0 client's code.
|
||||
package aol
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/D-Modem/bbs/internal/aol/p3"
|
||||
"github.com/D-Modem/bbs/internal/bbs"
|
||||
"github.com/D-Modem/bbs/internal/sockets"
|
||||
"github.com/D-Modem/bbs/internal/tcpserv"
|
||||
)
|
||||
|
||||
// Settings are the [aol] section's.
|
||||
type Settings struct {
|
||||
// Address is where to listen: the client's port is 5190, which the
|
||||
// OSCAR server (AIM, ICQ) shares when it listens there too.
|
||||
Address string
|
||||
MaxClients int
|
||||
MaxPerIP int
|
||||
}
|
||||
|
||||
// Server serves AOL clients.
|
||||
type Server struct {
|
||||
B *bbs.BBS
|
||||
S Settings
|
||||
|
||||
// Trace, if set, is told of every packet (for the sysop's debugging).
|
||||
Trace func(remote string, in bool, p p3.Packet)
|
||||
|
||||
mu sync.Mutex
|
||||
sessions map[*session]bool
|
||||
}
|
||||
|
||||
// New checks the settings and makes the server.
|
||||
func New(b *bbs.BBS, s Settings) (*Server, error) {
|
||||
if s.Address != "" {
|
||||
if _, _, err := net.SplitHostPort(s.Address); err != nil {
|
||||
return nil, fmt.Errorf("aol: address: %w", err)
|
||||
}
|
||||
}
|
||||
if s.MaxClients == 0 {
|
||||
s.MaxClients = 256
|
||||
}
|
||||
return &Server{B: b, S: s, sessions: map[*session]bool{}}, nil
|
||||
}
|
||||
|
||||
// Run listens on the settings' address until ctx is done.
|
||||
func (s *Server) Run(ctx context.Context) error {
|
||||
if s.S.Address == "" {
|
||||
return errors.New("aol: no address to listen on")
|
||||
}
|
||||
ln, err := sockets.Listen("tcp", s.S.Address)
|
||||
if err != nil {
|
||||
return fmt.Errorf("aol: %w", err)
|
||||
}
|
||||
return s.Serve(ctx, ln)
|
||||
}
|
||||
|
||||
// Serve answers on ln until ctx is done.
|
||||
func (s *Server) Serve(ctx context.Context, ln net.Listener) error {
|
||||
ts := &tcpserv.Server{Name: "aol", MaxClients: s.S.MaxClients, MaxPerIP: s.S.MaxPerIP, Log: s.B.Log,
|
||||
Handle: s.Handle,
|
||||
Refuse: func(c net.Conn) bool { return s.B.Refuse("aol", c.RemoteAddr()) }}
|
||||
return ts.Serve(ctx, ln)
|
||||
}
|
||||
|
||||
// Clients is how many clients are connected.
|
||||
func (s *Server) Clients() int {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return len(s.sessions)
|
||||
}
|
||||
|
||||
// Handle serves one client's connection, from its first P3 packet (the
|
||||
// OSCAR server hands over those that begin as P3).
|
||||
func (s *Server) Handle(c net.Conn) {
|
||||
host, _, _ := net.SplitHostPort(c.RemoteAddr().String())
|
||||
opt := p3.Options{Logf: func(f string, a ...any) { s.B.Log.Printf("aol: %s: "+f, append([]any{host}, a...)...) }}
|
||||
if s.Trace != nil {
|
||||
opt.Trace = func(in bool, p p3.Packet) { s.Trace(host, in, p) }
|
||||
}
|
||||
l, err := p3.Serve(c, opt)
|
||||
if err != nil {
|
||||
s.B.Log.Printf("aol: %s: %v", host, err)
|
||||
return
|
||||
}
|
||||
ss := &session{s: s, l: l, host: host, init: l.Init(), parts: map[partKey][]byte{}}
|
||||
s.mu.Lock()
|
||||
s.sessions[ss] = true
|
||||
s.mu.Unlock()
|
||||
defer func() {
|
||||
s.mu.Lock()
|
||||
delete(s.sessions, ss)
|
||||
s.mu.Unlock()
|
||||
}()
|
||||
s.B.Log.Printf("aol: %s: %s", host, ss.init)
|
||||
ss.serve()
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
package aol
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"log"
|
||||
"net"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/D-Modem/bbs/internal/aol/fdo"
|
||||
"github.com/D-Modem/bbs/internal/aol/p3"
|
||||
"github.com/D-Modem/bbs/internal/bbs"
|
||||
"github.com/D-Modem/bbs/internal/oscar"
|
||||
"github.com/D-Modem/bbs/internal/store"
|
||||
)
|
||||
|
||||
type syncBuf struct {
|
||||
mu sync.Mutex
|
||||
b bytes.Buffer
|
||||
}
|
||||
|
||||
func (s *syncBuf) Write(p []byte) (int, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return s.b.Write(p)
|
||||
}
|
||||
|
||||
func (s *syncBuf) String() string {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return s.b.String()
|
||||
}
|
||||
|
||||
// newServer is a BBS (alice, password1) with an AOL host.
|
||||
func newServer(t *testing.T) (*Server, *syncBuf) {
|
||||
t.Helper()
|
||||
store.BcryptCost = 4
|
||||
st, err := store.Open(filepath.Join(t.TempDir(), "bbs.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { st.Close() })
|
||||
if _, err := st.CreateUser("alice", "password1", "Here", false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := bbs.Defaults()
|
||||
s.Name, s.FailDelay = "Test BBS", 0
|
||||
logs := &syncBuf{}
|
||||
b := bbs.New(s, st, log.New(logs, "", 0))
|
||||
srv, err := New(b, Settings{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if t.Failed() {
|
||||
t.Log("log:\n" + logs.String())
|
||||
}
|
||||
})
|
||||
return srv, logs
|
||||
}
|
||||
|
||||
// client is a scripted AOL client: P3 by hand, tokens in DATA.
|
||||
type client struct {
|
||||
t *testing.T
|
||||
c net.Conn
|
||||
tx, rx uint8
|
||||
pkts chan p3.Packet
|
||||
}
|
||||
|
||||
func connect(t *testing.T, srv *Server) *client {
|
||||
t.Helper()
|
||||
a, b := net.Pipe()
|
||||
go srv.Handle(b)
|
||||
return attach(t, a)
|
||||
}
|
||||
|
||||
// attach begins P3 on a, a connection to the host.
|
||||
func attach(t *testing.T, a net.Conn) *client {
|
||||
t.Helper()
|
||||
c := &client{t: t, c: a, tx: p3.SeqInit, rx: p3.SeqInit, pkts: make(chan p3.Packet, 256)}
|
||||
go func() {
|
||||
r := p3.NewReader(a)
|
||||
for {
|
||||
p, err := r.Read()
|
||||
if err != nil {
|
||||
close(c.pkts)
|
||||
return
|
||||
}
|
||||
c.pkts <- p
|
||||
}
|
||||
}()
|
||||
t.Cleanup(func() { a.Close() })
|
||||
init := make([]byte, 0x34)
|
||||
init[0], init[1] = p3.PlatformWindows, 3
|
||||
c.write(p3.Packet{TX: p3.SeqInit, RX: p3.SeqInit, Type: p3.INIT, Data: init})
|
||||
if p := c.next(); p.Type != p3.ACK {
|
||||
t.Fatalf("INIT answered with %v", p)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *client) write(p p3.Packet) {
|
||||
p.Type |= p3.FromClient
|
||||
if _, err := c.c.Write(p3.Append(nil, p)); err != nil {
|
||||
c.t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// send sends a token in a DATA packet.
|
||||
func (c *client) send(token string, data []byte) {
|
||||
c.tx = next(c.tx)
|
||||
c.write(p3.Packet{TX: c.tx, RX: c.rx, Type: p3.DATA, Data: append([]byte(token), data...)})
|
||||
}
|
||||
|
||||
func next(s uint8) uint8 {
|
||||
if s >= p3.SeqMax {
|
||||
return p3.SeqMin
|
||||
}
|
||||
return s + 1
|
||||
}
|
||||
|
||||
func (c *client) next() p3.Packet {
|
||||
c.t.Helper()
|
||||
select {
|
||||
case p, ok := <-c.pkts:
|
||||
if !ok {
|
||||
c.t.Fatal("hung up")
|
||||
}
|
||||
return p
|
||||
case <-time.After(3 * time.Second):
|
||||
c.t.Fatal("nothing from the host")
|
||||
}
|
||||
return p3.Packet{}
|
||||
}
|
||||
|
||||
// token is the next token the host sends (acknowledging it), and its
|
||||
// data; the host's ACKs are passed over.
|
||||
func (c *client) token() (string, []byte) {
|
||||
c.t.Helper()
|
||||
for {
|
||||
p := c.next()
|
||||
if p.Kind() != p3.DATA {
|
||||
continue
|
||||
}
|
||||
c.rx = p.TX
|
||||
c.write(p3.Packet{TX: c.tx, RX: c.rx, Type: p3.ACK})
|
||||
tok, rest := p3.Token(p.Data)
|
||||
return tok, rest
|
||||
}
|
||||
}
|
||||
|
||||
// stream is the next atom stream the host sends (aT, or at in pieces),
|
||||
// decompiled.
|
||||
func (c *client) stream() string {
|
||||
c.t.Helper()
|
||||
var held []byte
|
||||
for {
|
||||
tok, d := c.token()
|
||||
switch tok {
|
||||
case "aT":
|
||||
src, err := fdo.Decompile(d)
|
||||
if err != nil {
|
||||
c.t.Fatal(err)
|
||||
}
|
||||
return src
|
||||
case "at":
|
||||
held = append(held, d[4:]...)
|
||||
if src, err := fdo.Decompile(held); err == nil && strings.Contains(src, "uni_end_stream") {
|
||||
return src
|
||||
}
|
||||
default:
|
||||
c.t.Fatalf("token %q, wanted a stream", tok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// signOnForm is the Welcome form's Dd, as the 3.0 client sends it: its
|
||||
// stream id, then the screen name and password as de_data.
|
||||
func signOnForm(name, pw string) []byte {
|
||||
src := `uni_start_stream
|
||||
man_set_context_relative <00x, 00x, 00x, 01x>
|
||||
man_set_context_index <00x, 00x, 00x, 01x>
|
||||
de_data <` + fdo.Quote(name) + `>
|
||||
man_end_context
|
||||
man_end_context
|
||||
man_set_context_relative <00x, 00x, 00x, 02x>
|
||||
de_data <` + fdo.Quote(pw) + `>
|
||||
man_end_context
|
||||
uni_end_stream
|
||||
`
|
||||
return append([]byte{0x00, 0x15}, fdo.MustCompile(src)...)
|
||||
}
|
||||
|
||||
func TestSignOn(t *testing.T) {
|
||||
srv, logs := newServer(t)
|
||||
c := connect(t, srv)
|
||||
c.send("Dd", signOnForm("alice ", "password1"))
|
||||
if s := c.stream(); !strings.Contains(s, "async_online") || !strings.Contains(s, "uni_invoke_local <32-296>") {
|
||||
t.Errorf("online:\n%s", s)
|
||||
}
|
||||
if s := c.stream(); !strings.Contains(s, `man_start_object <ind_group, "Welcome, alice!">`) ||
|
||||
!strings.Contains(s, "Welcome to Test BBS, alice!") {
|
||||
t.Errorf("welcome:\n%s", s)
|
||||
}
|
||||
nodes := srv.B.Nodes()
|
||||
if len(nodes) != 1 || nodes[0].User != "alice" {
|
||||
t.Errorf("nodes %+v", nodes)
|
||||
}
|
||||
|
||||
// a token not served yet is answered, so the client doesn't wait
|
||||
c.send("k1", []byte{0, 1})
|
||||
if s := c.stream(); !strings.Contains(s, "uni_wait_off") {
|
||||
t.Errorf("k1:\n%s", s)
|
||||
}
|
||||
|
||||
// Sign Off
|
||||
c.send("pE", []byte{0, 1})
|
||||
if tok, d := c.token(); tok != "XS" || !bytes.Equal(d, []byte{0}) {
|
||||
t.Errorf("pE answered %q % x", tok, d)
|
||||
}
|
||||
c.c.Close()
|
||||
for i := 0; len(srv.B.Nodes()) > 0; i++ {
|
||||
if i > 100 {
|
||||
t.Fatal("node not given back")
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
if !strings.Contains(logs.String(), "alice on AOL") {
|
||||
t.Error("not logged")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSignOnRefused(t *testing.T) {
|
||||
srv, _ := newServer(t)
|
||||
for _, c := range []struct{ name, pw, want string }{
|
||||
{"alice", "wrong", "Incorrect screen name or password"},
|
||||
{"New User", "", "call it by telnet or the web first"},
|
||||
} {
|
||||
cl := connect(t, srv)
|
||||
cl.send("Dd", signOnForm(c.name, c.pw))
|
||||
if s := cl.stream(); !strings.Contains(s, "async_alert <info, ") || !strings.Contains(s, c.want) {
|
||||
t.Errorf("%s: alert:\n%s", c.name, s)
|
||||
}
|
||||
if s := cl.stream(); !strings.Contains(s, "async_force_off") {
|
||||
t.Errorf("%s: then:\n%s", c.name, s)
|
||||
}
|
||||
// nothing else until it signs on
|
||||
cl.send("k1", []byte{0, 1})
|
||||
select {
|
||||
case p := <-cl.pkts:
|
||||
if p.Kind() == p3.DATA {
|
||||
t.Errorf("%s: answered %v", c.name, p)
|
||||
}
|
||||
case <-time.After(300 * time.Millisecond):
|
||||
}
|
||||
}
|
||||
if n := len(srv.B.Nodes()); n != 0 {
|
||||
t.Errorf("%d nodes", n)
|
||||
}
|
||||
}
|
||||
|
||||
// TestLongStreams: a stream too big for a packet goes as at pieces; one
|
||||
// the client spreads over packets is put together.
|
||||
func TestLongStreams(t *testing.T) {
|
||||
srv, _ := newServer(t)
|
||||
c := connect(t, srv)
|
||||
// the 4.0 client's long Dd, in two packets of one stream id
|
||||
d := signOnForm("alice", "password1")
|
||||
c.send("Dd", d[:9])
|
||||
c.send("Dd", append([]byte{0x00, 0x15}, d[9:]...))
|
||||
c.stream()
|
||||
c.stream()
|
||||
|
||||
ss := func() *session {
|
||||
srv.mu.Lock()
|
||||
defer srv.mu.Unlock()
|
||||
for ss := range srv.sessions {
|
||||
return ss
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
long := alertForm(strings.Repeat("All work and no play. ", 100))
|
||||
if err := ss.send(long); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s := c.stream(); !strings.Contains(s, "All work and no play. All work") {
|
||||
t.Errorf("long:\n%.200s", s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestForms(t *testing.T) {
|
||||
for _, src := range []string{onlineForm, alertForm(`"Quotes" and \ and é`), welcomeForm("BBS", "Zoë", 3)} {
|
||||
if _, err := fdo.Compile(src); err != nil {
|
||||
t.Errorf("%v:\n%s", err, src)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestOSCARPort: on OSCAR's port, an AOL client is handed over and signs
|
||||
// on, while AIM clients go on as before.
|
||||
func TestOSCARPort(t *testing.T) {
|
||||
srv, _ := newServer(t)
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
osrv, err := oscar.New(srv.B, oscar.Settings{Address: ln.Addr().String()})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
osrv.P3 = srv.Handle
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
done := make(chan struct{})
|
||||
go func() { osrv.Serve(ctx, ln); close(done) }()
|
||||
t.Cleanup(func() { cancel(); <-done })
|
||||
|
||||
conn, err := net.Dial("tcp", ln.Addr().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c := attach(t, conn)
|
||||
c.send("Dd", signOnForm("alice", "password1"))
|
||||
if s := c.stream(); !strings.Contains(s, "async_online") {
|
||||
t.Errorf("online:\n%s", s)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package aol
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/D-Modem/bbs/internal/aol/fdo"
|
||||
)
|
||||
|
||||
// The host's forms, as FDO91 source.
|
||||
|
||||
// onlineForm takes the client online after it signs on, and opens its
|
||||
// main window (32-296).
|
||||
const onlineForm = `uni_start_stream
|
||||
async_online
|
||||
uni_invoke_local <32-296>
|
||||
uni_end_stream
|
||||
`
|
||||
|
||||
// alertForm is a message box.
|
||||
func alertForm(text string) string {
|
||||
return fmt.Sprintf("uni_start_stream\n async_alert <info, %s>\nuni_end_stream\n", fdo.Quote(text))
|
||||
}
|
||||
|
||||
// welcomeForm is the BBS's Welcome window.
|
||||
func welcomeForm(bbsName, user string, online int) string {
|
||||
others := "You are the only one here."
|
||||
switch {
|
||||
case online == 2:
|
||||
others = "One other caller is here."
|
||||
case online > 2:
|
||||
others = fmt.Sprintf("%d other callers are here.", online-1)
|
||||
}
|
||||
text := strings.Join([]string{
|
||||
fmt.Sprintf("Welcome to %s, %s!", bbsName, user),
|
||||
"",
|
||||
"You are signed on with your BBS account. " + others,
|
||||
}, "\r\n") // the client drops what follows a bare CR
|
||||
return fmt.Sprintf(`uni_start_stream
|
||||
man_start_object <ind_group, %s>
|
||||
mat_orientation <vcf>
|
||||
mat_position <center_center>
|
||||
man_start_object <view, "">
|
||||
mat_size <40, 6>
|
||||
man_append_data <%s>
|
||||
man_end_data
|
||||
man_end_object
|
||||
man_update_display
|
||||
uni_wait_off
|
||||
uni_end_stream
|
||||
`, fdo.Quote("Welcome, "+user+"!"), fdo.Quote(text))
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
package aol
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/D-Modem/bbs/internal/aol/fdo"
|
||||
"github.com/D-Modem/bbs/internal/aol/p3"
|
||||
"github.com/D-Modem/bbs/internal/bbs"
|
||||
"github.com/D-Modem/bbs/internal/store"
|
||||
)
|
||||
|
||||
// streamChunk is the most of an atom stream the host puts in one packet.
|
||||
const streamChunk = 900
|
||||
|
||||
// session is one client's.
|
||||
type session struct {
|
||||
s *Server
|
||||
l *p3.Link
|
||||
host string
|
||||
init p3.Init
|
||||
|
||||
mu sync.Mutex
|
||||
u *store.User // signed on as
|
||||
n *bbs.Node
|
||||
|
||||
parts map[partKey][]byte // streams the client has sent part of
|
||||
}
|
||||
|
||||
type partKey struct {
|
||||
token string
|
||||
sid string
|
||||
}
|
||||
|
||||
func (ss *session) logf(format string, args ...any) {
|
||||
ss.s.B.Log.Printf("aol: %s: "+format, append([]any{ss.host}, args...)...)
|
||||
}
|
||||
|
||||
// serve reads the client's tokens until the link is down.
|
||||
func (ss *session) serve() {
|
||||
defer func() {
|
||||
ss.l.Close()
|
||||
ss.mu.Lock()
|
||||
n, u := ss.n, ss.u
|
||||
ss.mu.Unlock()
|
||||
if n != nil {
|
||||
n.Leave()
|
||||
ss.s.B.Log.Printf("node %d: gone (aol)", n.Num)
|
||||
} else if u == nil {
|
||||
ss.logf("gone before signing on")
|
||||
}
|
||||
}()
|
||||
for {
|
||||
d, err := ss.l.Read()
|
||||
if err != nil {
|
||||
if !errors.Is(err, p3.ErrClosed) {
|
||||
ss.logf("%v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
tok, body := p3.Token(d)
|
||||
if tok == "" {
|
||||
continue
|
||||
}
|
||||
ss.token(tok, body)
|
||||
}
|
||||
}
|
||||
|
||||
// signedOn is whether the client has signed on.
|
||||
func (ss *session) signedOn() bool {
|
||||
ss.mu.Lock()
|
||||
defer ss.mu.Unlock()
|
||||
return ss.u != nil
|
||||
}
|
||||
|
||||
// token handles one token from the client.
|
||||
func (ss *session) token(tok string, body []byte) {
|
||||
sid, atoms := splitStream(tok, body)
|
||||
if atoms = ss.whole(tok, sid, atoms); atoms == nil {
|
||||
return // more to come
|
||||
}
|
||||
switch {
|
||||
case tok == "Dd":
|
||||
ss.signOn(atoms)
|
||||
case !ss.signedOn():
|
||||
ss.logf("token %q before signing on", tok)
|
||||
case tok == "pE":
|
||||
ss.signOff()
|
||||
default:
|
||||
ss.logf("token %q (not served yet)", tok)
|
||||
// never leave the client waiting on an answer that won't come
|
||||
ss.send("uni_start_stream\n uni_wait_off\nuni_end_stream\n")
|
||||
}
|
||||
}
|
||||
|
||||
// splitStream splits a token's data into its stream id and the atoms
|
||||
// after it. The id is two bytes, but for the a/A t/T family: "aT" none,
|
||||
// "At" three, "at" four.
|
||||
func splitStream(tok string, body []byte) (sid, atoms []byte) {
|
||||
n := 2
|
||||
switch tok {
|
||||
case "aT":
|
||||
n = 0
|
||||
case "At":
|
||||
n = 3
|
||||
case "at":
|
||||
n = 4
|
||||
}
|
||||
if len(body) < n {
|
||||
return body, nil
|
||||
}
|
||||
return body[:n], body[n:]
|
||||
}
|
||||
|
||||
// whole is a stream the client sent, once all of it has come: AOL 4.0
|
||||
// spreads a long one (a mail, an IM) over packets of the same token and
|
||||
// stream id, from uni_start_stream to uni_end_stream. nil: more to come.
|
||||
func (ss *session) whole(tok string, sid, atoms []byte) []byte {
|
||||
k := partKey{tok, string(sid)}
|
||||
if held, ok := ss.parts[k]; ok {
|
||||
atoms = append(held, atoms...)
|
||||
delete(ss.parts, k)
|
||||
}
|
||||
frames, err := fdo.Decode(atoms)
|
||||
if len(sid) > 0 && (err != nil || len(frames) > 0 && frames[0].Name() == "uni_start_stream" && !hasEnd(frames)) {
|
||||
if len(atoms) > 64<<10 {
|
||||
ss.logf("token %q: a stream of more than 64K; dropped", tok)
|
||||
return nil
|
||||
}
|
||||
ss.parts[k] = append([]byte(nil), atoms...)
|
||||
return nil
|
||||
}
|
||||
if atoms == nil {
|
||||
atoms = []byte{}
|
||||
}
|
||||
return atoms
|
||||
}
|
||||
|
||||
func hasEnd(frames []fdo.Frame) bool {
|
||||
_, ok := fdo.Find(frames, "uni_end_stream")
|
||||
return ok
|
||||
}
|
||||
|
||||
// send compiles FDO91 source and sends it to the client to run. A
|
||||
// source of more than one stream goes as one stream at a time.
|
||||
func (ss *session) send(src string) error {
|
||||
b, err := fdo.Compile(src)
|
||||
if err != nil {
|
||||
ss.logf("a form that doesn't compile: %v", err)
|
||||
return err
|
||||
}
|
||||
return ss.sendAtoms(b)
|
||||
}
|
||||
|
||||
// sendAtoms sends an atom stream: in one packet as token aT, or, too big
|
||||
// for one, in pieces as token at, each with the same four-byte id.
|
||||
func (ss *session) sendAtoms(b []byte) error {
|
||||
frames, err := fdo.Decode(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, st := range topStreams(frames) {
|
||||
enc := fdo.Encode(st)
|
||||
if len(enc) <= streamChunk {
|
||||
if err := ss.l.WriteToken("aT", enc); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
var id [4]byte
|
||||
rand.Read(id[:])
|
||||
for _, piece := range fdo.Packets(st, streamChunk) {
|
||||
if err := ss.l.WriteToken("at", append(id[:], piece...)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// topStreams splits frames into its streams at the top level, each from
|
||||
// uni_start_stream to its uni_end_stream.
|
||||
func topStreams(frames []fdo.Frame) [][]fdo.Frame {
|
||||
var out [][]fdo.Frame
|
||||
depth, start := 0, 0
|
||||
for i, f := range frames {
|
||||
switch f.Name() {
|
||||
case "uni_start_stream":
|
||||
if depth == 0 {
|
||||
start = i
|
||||
}
|
||||
depth++
|
||||
case "uni_end_stream":
|
||||
depth--
|
||||
if depth == 0 {
|
||||
out = append(out, frames[start:i+1])
|
||||
start = i + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
if start < len(frames) {
|
||||
out = append(out, frames[start:])
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// signOn is Dd: the Welcome form's screen name and password, its two
|
||||
// de_data, checked as a BBS login.
|
||||
func (ss *session) signOn(atoms []byte) {
|
||||
if ss.signedOn() {
|
||||
return
|
||||
}
|
||||
frames, err := fdo.Decode(atoms)
|
||||
if err != nil {
|
||||
ss.logf("Dd: %v", err)
|
||||
}
|
||||
de := fdo.FindAll(frames, "de_data")
|
||||
if len(de) < 2 {
|
||||
ss.logf("Dd without a name and password: % x", atoms)
|
||||
ss.refuse("Please type your screen name and password.")
|
||||
return
|
||||
}
|
||||
name := strings.TrimSpace(fdo.FromLatin1(de[0].Data))
|
||||
pw := strings.TrimSpace(fdo.FromLatin1(bytes.TrimRight(de[1].Data, "\x00")))
|
||||
b := ss.s.B
|
||||
if strings.EqualFold(name, "New User") {
|
||||
ss.refuse(fmt.Sprintf("To join %s, call it by telnet or the web first; then sign on here with "+
|
||||
"your name and password.", b.Conf().Name))
|
||||
return
|
||||
}
|
||||
u, err := b.Authenticate("aol", "ip:"+ss.host, name, pw)
|
||||
if err != nil {
|
||||
ss.logf("%s: %v", name, err)
|
||||
msg := "Incorrect screen name or password. Please check them and try again."
|
||||
switch {
|
||||
case errors.Is(err, bbs.ErrLocked):
|
||||
msg = "This account is locked."
|
||||
case errors.Is(err, bbs.ErrThrottled):
|
||||
msg = "Too many failed sign-ons. Please try again later."
|
||||
}
|
||||
ss.refuse(msg)
|
||||
return
|
||||
}
|
||||
n, err := b.Enter(&bbs.Caller{Via: "aol", Listener: "aol", Remote: ss.host, Source: "ip:" + ss.host,
|
||||
Terminal: ss.init.String()}, func() { ss.l.Close() })
|
||||
if err != nil {
|
||||
ss.refuse("All lines are busy. Please try again later.")
|
||||
return
|
||||
}
|
||||
n.SetUser(u)
|
||||
n.Doing("AOL")
|
||||
ss.mu.Lock()
|
||||
ss.u, ss.n = u, n
|
||||
ss.mu.Unlock()
|
||||
b.Log.Printf("node %d: %s on AOL (%s, %s)", n.Num, u.Name, ss.host, ss.init)
|
||||
ss.send(onlineForm)
|
||||
ss.send(welcomeForm(b.Conf().Name, u.Name, len(b.Nodes())))
|
||||
}
|
||||
|
||||
// refuse tells the client why it can't sign on, and has it hang up.
|
||||
func (ss *session) refuse(why string) {
|
||||
ss.send(alertForm(why) + "uni_start_stream\n async_force_off\nuni_end_stream\n")
|
||||
}
|
||||
|
||||
// signOff is pE, the Sign Off menu: XS has the client sign off as if the
|
||||
// host had (its offline broadcast, the Goodbye window), and hang up.
|
||||
func (ss *session) signOff() {
|
||||
ss.mu.Lock()
|
||||
u := ss.u
|
||||
ss.mu.Unlock()
|
||||
if u != nil {
|
||||
ss.logf("%s signs off", u.Name)
|
||||
}
|
||||
ss.l.WriteToken("XS", []byte{0})
|
||||
}
|
||||
+24
-1
@@ -29,18 +29,41 @@ var prefValues = map[string][]string{
|
||||
"cis-mailpage": {"on", "off"},
|
||||
}
|
||||
|
||||
// prefChecks are settings registered by a front end (RegisterPref), each
|
||||
// with what its values may be.
|
||||
var prefChecks = map[string]func(string) bool{}
|
||||
|
||||
// RegisterPref adds a setting whose values ok accepts: a front end's own
|
||||
// (CompuServe's terminal settings). It is for package init: settings
|
||||
// are read without a lock.
|
||||
func RegisterPref(key string, ok func(string) bool) {
|
||||
if _, dup := prefValues[key]; dup {
|
||||
panic("bbs: setting " + key + " twice")
|
||||
}
|
||||
prefChecks[key] = ok
|
||||
}
|
||||
|
||||
// PrefKeys are the settings' names, sorted.
|
||||
func PrefKeys() []string {
|
||||
var out []string
|
||||
for k := range prefValues {
|
||||
out = append(out, k)
|
||||
}
|
||||
for k := range prefChecks {
|
||||
out = append(out, k)
|
||||
}
|
||||
sort.Strings(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// CheckPref says what is wrong with a setting, or nil.
|
||||
func CheckPref(key, value string) error {
|
||||
if ok := prefChecks[key]; ok != nil {
|
||||
if !ok(value) || strings.ContainsAny(value, " =") || value == "" {
|
||||
return fmt.Errorf("%q is not a value of %s", value, key)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
vs, ok := prefValues[key]
|
||||
if !ok {
|
||||
return fmt.Errorf("there is no setting %q", key)
|
||||
@@ -89,7 +112,7 @@ func ChangePrefs(kept string, changes map[string]string) (string, error) {
|
||||
p := ParsePrefs(kept)
|
||||
for k, v := range changes {
|
||||
if v == "" {
|
||||
if _, ok := prefValues[k]; !ok {
|
||||
if _, ok := prefValues[k]; !ok && prefChecks[k] == nil {
|
||||
return "", fmt.Errorf("there is no setting %q", k)
|
||||
}
|
||||
delete(p, k)
|
||||
|
||||
+10
-1
@@ -12,11 +12,17 @@ var errRelog = errors.New("cis: LOG")
|
||||
// ascii is the terminal service, from the banner to the logoff.
|
||||
func (s *session) ascii() error {
|
||||
s.banner()
|
||||
if s.firstGo == "" && s.keptSetting(setMailWait) == "mail" {
|
||||
// Mail waiting: GO MAIL
|
||||
if n, err := s.b.Store.UnreadMail(s.user.ID); err == nil && n > 0 {
|
||||
s.firstGo = "MAIL"
|
||||
}
|
||||
}
|
||||
top := s.pages.Get("TOP")
|
||||
switch p := s.pages.Get(s.firstGo); {
|
||||
case s.firstGo == "" || !s.known(s.firstGo):
|
||||
s.show(top)
|
||||
case p != nil && p.ID != "MAIL" && p.ID != "CB":
|
||||
case p != nil && p.ID != "MAIL" && p.ID != "CB" && p.ID != "DEFAULT":
|
||||
s.show(p)
|
||||
default:
|
||||
// /GO:word to a forum or Mail: in it first, TOP when it is left
|
||||
@@ -169,6 +175,9 @@ func (s *session) goWord(word string) error {
|
||||
if p != nil && p.ID == "CB" {
|
||||
return s.enterCB()
|
||||
}
|
||||
if p != nil && p.ID == "DEFAULT" {
|
||||
return s.terminalSettings()
|
||||
}
|
||||
s.goTo(p)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ type session struct {
|
||||
menus []*Page // menus gone through, for M
|
||||
more []string
|
||||
firstGo string // /GO:word at the User ID
|
||||
tty bool // ;TTY at the User ID: not the kept terminal settings
|
||||
byName bool // logged on with a BBS name, not a User ID
|
||||
fpage *Page // the FORUMS menu, as last made
|
||||
mail *mailState
|
||||
@@ -99,6 +100,7 @@ func (s *session) run() error {
|
||||
return err
|
||||
}
|
||||
s.user = u
|
||||
s.loadSettings(s.tty)
|
||||
if err := s.identify(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -417,6 +417,12 @@ func (s *session) chooseProtocol(given string) (string, error) {
|
||||
case "CAP", "CAPTURE", "ASCII", "DC2":
|
||||
return "CAPTURE", nil
|
||||
}
|
||||
if given == "" {
|
||||
// the permanent protocol preference, if it is one of these
|
||||
if k, ok := map[string]string{"b": "B", "qb": "QB", "xmodem": "XMODEM", "kermit": "KERMIT"}[s.keptSetting(setProtocol)]; ok {
|
||||
return k, nil
|
||||
}
|
||||
}
|
||||
for {
|
||||
for _, p := range protocols {
|
||||
s.outf(" %s %s\n", p.num, p.name)
|
||||
|
||||
@@ -178,6 +178,7 @@ func (s *session) login() (*store.User, error) {
|
||||
if id.Go != "" {
|
||||
s.firstGo = id.Go
|
||||
}
|
||||
s.tty = id.TTY
|
||||
return u, nil
|
||||
case errors.Is(err, bbs.ErrBadLogin) && id.Secure:
|
||||
s.out("No.\n") // CIM's script says "Incorrect User ID or password"
|
||||
|
||||
@@ -61,6 +61,10 @@ func (s *session) mailSettings() *mailState {
|
||||
m.mode = p[prefMailMode]
|
||||
}
|
||||
m.lineEdit = p[prefMailEdit] == "line"
|
||||
if p[prefMailEdit] == "" {
|
||||
// none of Mail's own: the permanent online editor
|
||||
m.lineEdit = s.keptSetting(setEditor) == "linedit"
|
||||
}
|
||||
m.paged = p[prefMailPage] == "on"
|
||||
s.mail = m
|
||||
return m
|
||||
|
||||
+27
-6
@@ -80,19 +80,40 @@
|
||||
|
||||
There is no membership support fee.
|
||||
|
||||
:DEFAULT TERMINAL PROFILE
|
||||
:DEFAULT TERMINAL
|
||||
=TERMINAL SETTINGS
|
||||
Your settings for this session are set with the SET command:
|
||||
TERMINAL SETTINGS/SERVICE OPTIONS
|
||||
|
||||
GO DEFAULT from a terminal changes your terminal type and parameters
|
||||
and your service options, for this session or permanently: PAGED,
|
||||
BRIEF, WIDTH, LINES, Mail waiting, the online editor and the transfer
|
||||
protocol. SET changes the session's:
|
||||
|
||||
SET BRIEF ON brief "!" prompts (expert mode)
|
||||
SET BRIEF OFF full prompts ("Enter choice !")
|
||||
SET PAGED ON stop at each screen ("Press <CR> for more !")
|
||||
SET PAGED OFF no stops (for offline readers)
|
||||
SET WIDTH n the screen's width (40 to 132)
|
||||
SET LINES n lines per screen, when paged
|
||||
|
||||
Permanent settings are not kept yet: each logon starts with BRIEF
|
||||
OFF, PAGED OFF and WIDTH 80.
|
||||
Append ;TTY to your User ID at logon to override the permanent ones.
|
||||
|
||||
:PROFILE
|
||||
=CompuServe
|
||||
CHANGE YOUR USER PROFILE
|
||||
|
||||
1 Terminal Settings > DEFAULT
|
||||
2 Change Your Password > LGN-1
|
||||
3 Password Security Guidelines > PWSECURITY
|
||||
4 Change Your Billing Options > RATES
|
||||
5 Change Your Billing Address > RATES
|
||||
|
||||
:PWSECURITY
|
||||
=CompuServe
|
||||
PASSWORD SECURITY GUIDELINES
|
||||
|
||||
Never tell anyone your password, not even someone who says they are
|
||||
from CompuServe or the BBS. Choose a password that is not a word,
|
||||
and change it now and then. CIM's Secure Login never sends your
|
||||
password over the line.
|
||||
|
||||
:LGN-1 SIGNUP JOIN PASSWORD
|
||||
=CompuServe
|
||||
|
||||
@@ -0,0 +1,622 @@
|
||||
package cis
|
||||
|
||||
// GO DEFAULT (TERMINAL, PROFILE's first choice): the terminal settings and
|
||||
// service options, session and permanent, as CompuServe's menus had them
|
||||
// in 1991. TAPCIS's PARAMS.SCR (ALT-P) walks these screens to set a new
|
||||
// member up, so the menus, their order, the bracketed values and the
|
||||
// prompts follow its transcript. The settings are kept as the user's
|
||||
// prefs (cis-paged, cis-width...). What they do here: PAGED, BRIEF, WIDTH
|
||||
// and LINES (the session's, from the logon), Mail waiting (GO MAIL at the
|
||||
// logon), the online editor (Mail's, when Mail has none of its own), and
|
||||
// the protocol preference (no protocol menu). The rest are kept and
|
||||
// shown, as a script expects, and change nothing.
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/D-Modem/bbs/internal/bbs"
|
||||
)
|
||||
|
||||
// tchoice is one of a setting's values.
|
||||
type tchoice struct {
|
||||
value string // as kept
|
||||
label string // its menu line
|
||||
help []string // the lines under it
|
||||
shown string // in the brackets ("" for its label's first word, in capitals)
|
||||
}
|
||||
|
||||
// tsetting is a permanent setting.
|
||||
type tsetting struct {
|
||||
key string // its pref, without "cis-"
|
||||
label string // its line in its group's menu
|
||||
under []string // lines under that line
|
||||
before string // a heading before that line
|
||||
title string // its screen's heading
|
||||
text []string // before "Permanent setting ="
|
||||
after []string // after it
|
||||
choices []tchoice
|
||||
lo, hi int // a number from lo to hi, when hi > 0
|
||||
prompt string
|
||||
def string
|
||||
none []string // not a setting: a screen with this, and back
|
||||
}
|
||||
|
||||
// tgroup is one of PERMANENT SETTINGS' menus.
|
||||
type tgroup struct {
|
||||
label, title string
|
||||
items []*tsetting
|
||||
extra []string
|
||||
}
|
||||
|
||||
var yesNoChoices = []tchoice{{value: "yes", label: "YES"}, {value: "no", label: "NO"}}
|
||||
|
||||
func yesNoHelp(yes, no []string) []tchoice {
|
||||
return []tchoice{{value: "yes", label: "YES", help: yes}, {value: "no", label: "NO", help: no}}
|
||||
}
|
||||
|
||||
var (
|
||||
setPaged = &tsetting{key: "paged", label: "PAGED display", title: "PAGED DISPLAY", def: "no",
|
||||
choices: yesNoHelp(
|
||||
[]string{" (Output is presented in pages;", " you are asked to enter <CR> after", " each page.)", ""},
|
||||
[]string{" (Output is scrolled continuously", " to end of article.)"})}
|
||||
setBrief = &tsetting{key: "brief", label: "BRIEF prompts", title: "BRIEF PROMPTS", def: "no",
|
||||
choices: []tchoice{
|
||||
{value: "yes", label: "YES - expert mode", help: []string{" (You will receive abbreviated", " prompts such as ! or More!.)"}},
|
||||
{value: "no", label: "NO - novice/intermediate mode", help: []string{" (You will receive full prompts", " such as Enter choice! or Enter", " <CR> for more!.)"}},
|
||||
}}
|
||||
setWidth = &tsetting{key: "width", label: "Screen WIDTH", title: "SCREEN WIDTH", def: "80",
|
||||
after: []string{"", "This determines the number of characters", "per line."},
|
||||
lo: 40, hi: 132, prompt: "Enter characters per line, 40 to 132, or <CR> for no change:"}
|
||||
setLines = &tsetting{key: "lines", label: "LINES per page", title: "LINES PER PAGE", def: "0",
|
||||
lo: 0, hi: 200, prompt: "Enter lines per page, 0 to 200, or <CR> for no change:"}
|
||||
setTerm = &tsetting{key: "term", label: "TERMINAL type", title: "TERMINAL TYPE", def: "other",
|
||||
choices: []tchoice{
|
||||
{value: "vidtex", label: "VIDTEX (Professional Connection)"},
|
||||
{value: "ansi", label: "ANSI"},
|
||||
{value: "vt100", label: "VT100"},
|
||||
{value: "vt52", label: "VT52"},
|
||||
{value: "heath", label: "Heath (Zenith)"},
|
||||
{value: "adm", label: "ADM"},
|
||||
{value: "crt", label: "CRT"},
|
||||
{value: "other", label: "Other"},
|
||||
}}
|
||||
setProtocol = &tsetting{key: "protocol", label: "PROTOCOL preference", before: "FILE TRANSFER PROTOCOL",
|
||||
title: "PROTOCOL PREFERENCE", def: "menu",
|
||||
choices: []tchoice{
|
||||
{value: "b", label: "B Protocol", shown: "B PROTOCOL"},
|
||||
{value: "qb", label: "Quick B protocol", shown: "QUICK B"},
|
||||
{value: "xmodem", label: "XMODEM"},
|
||||
{value: "kermit", label: "KERMIT"},
|
||||
{value: "a", label: "A Protocol", shown: "A PROTOCOL"},
|
||||
{value: "menu", label: "SHOW MENU", shown: "SHOW MENU", help: []string{" (if this choice is selected, you", " will be presented a menu of", " protocols when you request a file", " transfer.)"}},
|
||||
}}
|
||||
setMailWait = &tsetting{key: "mailwait", label: "Mail Waiting", title: "MAIL WAITING", def: "notify",
|
||||
choices: []tchoice{
|
||||
{value: "mail", label: "Go to MAIL", shown: "GO TO MAIL", help: []string{" (Will take you to Mail when you", " have messages waiting)"}},
|
||||
{value: "notify", label: "Notify only", shown: "NOTIFY ONLY", help: []string{" (Will notify you that you have", " messages waiting - then take you to", " your first service)", ""}},
|
||||
}}
|
||||
setEditor = &tsetting{key: "editor", label: "Online editor", title: "ONLINE EDITOR PREFERENCE", def: "edit",
|
||||
text: []string{"This setting determines the editor you", "will normally use. You may change this", "for a specific forum via the forum", "options or for Mail via the", "Mail options."},
|
||||
choices: []tchoice{
|
||||
{value: "edit", label: "EDIT", help: []string{" (does not use line numbers)"}},
|
||||
{value: "linedit", label: "LINEDIT", help: []string{" (uses line numbers)"}},
|
||||
{value: "default", label: "DEFAULT", help: []string{" (no preference)", ""}},
|
||||
}}
|
||||
)
|
||||
|
||||
// first and top: where the logon and TOP go
|
||||
func serviceChoices(what string) []tchoice {
|
||||
return []tchoice{
|
||||
{value: "main", label: "MAIN menu", help: []string{" (Normal setting)"}},
|
||||
{value: "go", label: "Designated " + what, shown: "DESIGNATED", help: []string{" (You specify which one.)"}},
|
||||
{value: "menu", label: "Personal MENU", shown: "MENU", help: []string{" (A menu you have constructed)"}},
|
||||
{value: "command", label: "COMMAND mode in the personal", help: []string{" file area", ""}},
|
||||
}
|
||||
}
|
||||
|
||||
var termGroups = []*tgroup{
|
||||
{label: "Logon/Service options", title: "LOGON/SERVICE OPTIONS", items: []*tsetting{
|
||||
{key: "first", label: "First service at logon", title: "FIRST SERVICE", def: "main", choices: serviceChoices("first service")},
|
||||
setMailWait,
|
||||
{label: "Personal menu established", under: []string{" (Select this to create or", " change a personal menu.)"},
|
||||
title: "PERSONAL MENU", def: "NO", none: []string{"Personal menus are not available on this service."}},
|
||||
{key: "top", label: "TOP goes to", title: "TOP GOES TO", def: "main",
|
||||
after: []string{" As alternative, use 2 and choose INDEX or create a personal menu"},
|
||||
choices: serviceChoices("top page")},
|
||||
setEditor,
|
||||
{key: "forummode", label: "Forum presentation mode", title: "FORUM PRESENTATION MODE", def: "command",
|
||||
text: []string{"This setting determines the type of", "presentation you will normally receive", "in each forum you visit. You may change", "this for a specific forum via the forum", "options."},
|
||||
choices: []tchoice{
|
||||
{value: "menu", label: "MENU mode - novice/intermediate", help: []string{" (menu of choices)"}},
|
||||
{value: "command", label: "COMMAND mode - expert", help: []string{" (one word prompts)"}},
|
||||
{value: "default", label: "DEFAULT", help: []string{" (no preference)", ""}},
|
||||
}},
|
||||
}},
|
||||
{label: "Display options", title: "PERMANENT DISPLAY OPTIONS", items: []*tsetting{
|
||||
setPaged, setBrief,
|
||||
{key: "clear", label: "CLEAR screen between pages", title: "CLEAR SCREEN", def: "yes", choices: yesNoChoices},
|
||||
{key: "blank", label: "BLANK lines sent", title: "BLANK LINES", def: "yes", choices: yesNoChoices},
|
||||
{key: "lf", label: "Line feeds sent", title: "LINE FEEDS", def: "yes", choices: yesNoChoices},
|
||||
}},
|
||||
{label: "Terminal type/parameters", title: "TERMINAL TYPE/PARAMETERS", items: []*tsetting{
|
||||
setTerm, setWidth, setLines,
|
||||
{key: "feeds", label: "Form FEEDS", title: "FORM FEEDS", def: "simulated", choices: []tchoice{{value: "simulated", label: "SIMULATED"}, {value: "real", label: "REAL"}}},
|
||||
{key: "tabs", label: "Horizontal TABS", title: "HORIZONTAL TABS", def: "simulated", choices: []tchoice{{value: "simulated", label: "SIMULATED"}, {value: "real", label: "REAL"}}},
|
||||
{key: "case", label: "Chars. received (CASE)", title: "CHARACTERS RECEIVED (CAPS)", def: "ul", choices: []tchoice{
|
||||
{value: "ul", label: "U/L - normal mode", shown: "U/L", help: []string{" (Output to you will be in upper or", " lower case as available on the", " host computer.)"}},
|
||||
{value: "upper", label: "UPPER only", help: []string{" (You will receive only upper case", " output.)"}},
|
||||
{value: "lower", label: "LOWER only", help: []string{" (You will receive only lower case", " output.)", ""}},
|
||||
}},
|
||||
{key: "caps", label: "Chars. sent in CAPS", title: "CHARACTERS SENT IN CAPS", def: "no", choices: []tchoice{
|
||||
{value: "no", label: "NO - normal mode", help: []string{" (Whatever you input will be in the", " case you send it.)"}},
|
||||
{value: "yes", label: "YES", help: []string{" (Whatever you input will always be", " in CAPS regardless of how you send", " it.)", ""}},
|
||||
}},
|
||||
{key: "parity", label: "PARITY", title: "PARITY", def: "zero", choices: []tchoice{
|
||||
{value: "even", label: "EVEN"}, {value: "odd", label: "ODD"}, {value: "zero", label: "ZERO"}, {value: "one", label: "ONE"}}},
|
||||
{key: "delays", label: "Output DELAYS", title: "OUTPUT DELAYS", def: "0", lo: 0, hi: 9,
|
||||
prompt: "Enter delay, 0 to 9, or <CR> for no change:"},
|
||||
{key: "erase", label: "ERASE when backspacing", title: "BACKSPACE ERASE", def: "yes", choices: yesNoHelp(
|
||||
[]string{" (When a backspace is received,", " the host sends a space and another", " backspace which has the effect of", " erasing the last character typed.)"},
|
||||
[]string{" (no special processing when a", " backspace is received)", ""})},
|
||||
{key: "inquiry", label: "Micro inquiry sequence at logon", title: "SEND MICRO INQUIRY SEQUENCE AT LOGON", def: "no",
|
||||
choices: []tchoice{{value: "yes", label: "YES", help: []string{" (Use this only if your software", " supports an inquiry sequence.)"}}, {value: "no", label: "NO", help: []string{""}}}},
|
||||
}},
|
||||
{label: "Transfer protocol/graphic support", title: "TRANSFER PROTOCOLS/GRAPHICS SUPPORT", items: []*tsetting{
|
||||
setProtocol,
|
||||
{key: "gif", label: "GIF SUPPORT", before: "GRAPHICS SUPPORT", title: "GIF SUPPORT", def: "no", choices: yesNoChoices},
|
||||
{key: "naplps", label: "NAPLPS SUPPORT", title: "NAPLPS SUPPORT", def: "no", choices: yesNoChoices},
|
||||
{key: "rle", label: "RLE SUPPORT", title: "RLE SUPPORT", def: "no", choices: yesNoChoices},
|
||||
}, extra: []string{"(Note: Please consult your software and hardware documentation for graphics", "support before changing these settings.)"}},
|
||||
}
|
||||
|
||||
// the session's own settings, for 4 and 5
|
||||
var sessionSettings = []*tsetting{setPaged, setBrief, setWidth, setLines}
|
||||
|
||||
func init() {
|
||||
for _, g := range termGroups {
|
||||
for _, t := range g.items {
|
||||
if t.key == "" {
|
||||
continue
|
||||
}
|
||||
t := t
|
||||
bbs.RegisterPref("cis-"+t.key, func(v string) bool { return t.valid(v) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// valid is whether v is one of t's values.
|
||||
func (t *tsetting) valid(v string) bool {
|
||||
if t.hi > 0 {
|
||||
n, err := strconv.Atoi(v)
|
||||
return err == nil && n >= t.lo && n <= t.hi && strconv.Itoa(n) == v
|
||||
}
|
||||
for _, c := range t.choices {
|
||||
if c.value == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// show is v as the brackets show it.
|
||||
func (t *tsetting) show(v string) string {
|
||||
for _, c := range t.choices {
|
||||
if c.value == v {
|
||||
if c.shown != "" {
|
||||
return c.shown
|
||||
}
|
||||
return strings.ToUpper(strings.Fields(c.label)[0])
|
||||
}
|
||||
}
|
||||
return strings.ToUpper(v)
|
||||
}
|
||||
|
||||
// bracketed is text with [v] at its right, 40 wide.
|
||||
func bracketed(text, v string) string {
|
||||
b := "[" + v + "]"
|
||||
return text + strings.Repeat(" ", max(40-len(text)-len(b), 1)) + b
|
||||
}
|
||||
|
||||
// profile is GO DEFAULT's state: the settings kept, and the changes to be
|
||||
// kept when the caller confirms them.
|
||||
type profile struct {
|
||||
kept bbs.Prefs
|
||||
pending map[string]string
|
||||
}
|
||||
|
||||
// get is a permanent setting: as changed, as kept, or its default.
|
||||
func (p *profile) get(t *tsetting) string {
|
||||
if v, ok := p.pending[t.key]; ok {
|
||||
return v
|
||||
}
|
||||
if v, ok := p.kept["cis-"+t.key]; ok && t.valid(v) {
|
||||
return v
|
||||
}
|
||||
return t.def
|
||||
}
|
||||
|
||||
// sessionValue is a session setting as the menus show it.
|
||||
func (s *session) sessionValue(t *tsetting) string {
|
||||
switch t {
|
||||
case setPaged:
|
||||
return map[bool]string{true: "yes", false: "no"}[s.paged]
|
||||
case setBrief:
|
||||
return map[bool]string{true: "yes", false: "no"}[s.brief]
|
||||
case setWidth:
|
||||
return strconv.Itoa(s.width)
|
||||
case setLines:
|
||||
return strconv.Itoa(s.lines)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// applySetting makes a setting the session's (the four the session has).
|
||||
func (s *session) applySetting(t *tsetting, v string) {
|
||||
n, _ := strconv.Atoi(v)
|
||||
switch t {
|
||||
case setPaged:
|
||||
s.paged = v == "yes"
|
||||
if s.paged && s.lines == 0 {
|
||||
s.lines = 24
|
||||
}
|
||||
case setBrief:
|
||||
s.brief = v == "yes"
|
||||
case setWidth:
|
||||
s.width = n
|
||||
case setLines:
|
||||
s.lines = n
|
||||
}
|
||||
}
|
||||
|
||||
// loadSettings sets the session from the kept settings at the logon,
|
||||
// unless the caller asked for the defaults (;TTY).
|
||||
func (s *session) loadSettings(tty bool) {
|
||||
if tty {
|
||||
return
|
||||
}
|
||||
p := &profile{kept: s.node.Prefs()}
|
||||
for _, t := range []*tsetting{setWidth, setLines, setBrief, setPaged} {
|
||||
if _, ok := p.kept["cis-"+t.key]; ok {
|
||||
s.applySetting(t, p.get(t))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// keptSetting is a permanent setting, outside GO DEFAULT.
|
||||
func (s *session) keptSetting(t *tsetting) string {
|
||||
return (&profile{kept: s.node.Prefs()}).get(t)
|
||||
}
|
||||
|
||||
// leaveFor is a command typed at one of the settings' prompts: GO DEFAULT
|
||||
// is left, and it is done.
|
||||
type leaveFor struct{ cmd string }
|
||||
|
||||
func (l leaveFor) Error() string { return "cis: leaving the settings for " + l.cmd }
|
||||
|
||||
// settingsChoice reads a choice: "" for <CR> (or ^C), a number, or a
|
||||
// command to leave for.
|
||||
func (s *session) settingsChoice(p string) (string, error) {
|
||||
c, err := s.prompt(s.choicePrompt(p))
|
||||
if errors.Is(err, errAbort) {
|
||||
return "", nil
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
c = strings.TrimSpace(c)
|
||||
if c == "" || isNumber(c) {
|
||||
return c, nil
|
||||
}
|
||||
return "", leaveFor{c}
|
||||
}
|
||||
|
||||
// terminalSettings is GO DEFAULT.
|
||||
func (s *session) terminalSettings() error {
|
||||
s.node.Doing("CompuServe: terminal settings")
|
||||
p := &profile{kept: s.node.Prefs(), pending: map[string]string{}}
|
||||
err := s.settingsTop(p)
|
||||
var l leaveFor
|
||||
if errors.As(err, &l) {
|
||||
if len(p.pending) > 0 {
|
||||
s.out("Your permanent settings have not been changed.\n")
|
||||
}
|
||||
return s.commands(l.cmd)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *session) settingsTop(p *profile) error {
|
||||
for {
|
||||
s.out("\nTERMINAL SETTINGS/SERVICE OPTIONS\n" +
|
||||
"Use this area to change your terminal type/parameters and/or service options.\n\n" +
|
||||
" 1 Instructions\n 2 Change permanent settings\n\n" +
|
||||
" 3 Explanation of session vs. permanent\n 4 Show session vs. permanent\n" +
|
||||
" 5 Change current session settings\n")
|
||||
c, err := s.settingsChoice("Enter choice !")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch c {
|
||||
case "":
|
||||
return s.leaveSettings(p)
|
||||
case "1":
|
||||
err = s.settingsText("INSTRUCTIONS", []string{
|
||||
"Choose 2 to change the settings kept for every logon, or 5 to",
|
||||
"change them for this session only. In each menu, enter a",
|
||||
"number to change that setting, or <CR> to go back. When you",
|
||||
"leave, you are asked to confirm the permanent changes.",
|
||||
})
|
||||
case "2":
|
||||
err = s.permanentSettings(p)
|
||||
case "3":
|
||||
err = s.settingsText("SESSION VS. PERMANENT", []string{
|
||||
"Session settings last until you log off; the SET command",
|
||||
"changes them too. Permanent settings are kept with your User",
|
||||
"ID and are in effect each time you log on. Changing a",
|
||||
"permanent setting changes it for this session as well.",
|
||||
"Append ;TTY to your User ID at logon to override them.",
|
||||
})
|
||||
case "4":
|
||||
err = s.showSettings(p)
|
||||
case "5":
|
||||
err = s.settingsMenu(p, "CURRENT SESSION SETTINGS", sessionSettings, nil, true)
|
||||
default:
|
||||
s.out(c + " is not a choice !\n")
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// settingsText is a screen of text, and <CR> back.
|
||||
func (s *session) settingsText(title string, lines []string) error {
|
||||
s.out("\n" + title + "\n\n")
|
||||
for _, l := range lines {
|
||||
s.out(l + "\n")
|
||||
}
|
||||
_, err := s.settingsChoice("Last page !")
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *session) showSettings(p *profile) error {
|
||||
s.out("\nSESSION VS. PERMANENT SETTINGS\n\n")
|
||||
s.outf("%-34s %-10s %s\n", "", "Session", "Permanent")
|
||||
for _, g := range termGroups {
|
||||
for _, t := range g.items {
|
||||
if t.key == "" {
|
||||
continue
|
||||
}
|
||||
sess := s.sessionValue(t)
|
||||
if sess == "" {
|
||||
sess = p.get(t)
|
||||
}
|
||||
s.outf(" %-33s %-10s %s\n", t.label, t.show(sess), t.show(p.get(t)))
|
||||
}
|
||||
}
|
||||
_, err := s.settingsChoice("Last page !")
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *session) permanentSettings(p *profile) error {
|
||||
for {
|
||||
s.out("\nPERMANENT SETTINGS\n\n 1 Explanation\n")
|
||||
for i, g := range termGroups {
|
||||
s.outf(" %d %s\n", i+2, g.label)
|
||||
}
|
||||
s.outf(" %d Make session settings permanent\n", len(termGroups)+2)
|
||||
c, err := s.settingsChoice("Enter choice !")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n, _ := strconv.Atoi(c)
|
||||
switch {
|
||||
case c == "":
|
||||
return nil
|
||||
case n == 1:
|
||||
err = s.settingsText("PERMANENT SETTINGS", []string{
|
||||
"These settings are kept with your User ID and are in effect",
|
||||
"each time you log on. When you leave TERMINAL SETTINGS you",
|
||||
"are asked to confirm them.",
|
||||
})
|
||||
case n >= 2 && n < len(termGroups)+2:
|
||||
g := termGroups[n-2]
|
||||
err = s.settingsMenu(p, g.title, g.items, g.extra, false)
|
||||
case n == len(termGroups)+2:
|
||||
for _, t := range sessionSettings {
|
||||
p.pending[t.key] = s.sessionValue(t)
|
||||
}
|
||||
err = s.settingsText("MAKE SESSION SETTINGS PERMANENT", []string{
|
||||
"Your session settings (PAGED, BRIEF, WIDTH and LINES) will be",
|
||||
"made permanent when you confirm your changes.",
|
||||
})
|
||||
default:
|
||||
s.out(c + " is not a choice !\n")
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// settingsMenu is a group's menu: each setting and its value.
|
||||
func (s *session) settingsMenu(p *profile, title string, items []*tsetting, extra []string, session bool) error {
|
||||
for {
|
||||
s.out("\n" + title + "\n\n")
|
||||
for i, t := range items {
|
||||
if t.before != "" {
|
||||
s.out(t.before + "\n")
|
||||
}
|
||||
v := t.def
|
||||
switch {
|
||||
case t.key == "":
|
||||
case session:
|
||||
v = s.sessionValue(t)
|
||||
default:
|
||||
v = p.get(t)
|
||||
}
|
||||
if t.key != "" {
|
||||
v = t.show(v)
|
||||
}
|
||||
s.out(bracketed(fmt.Sprintf("%2d %s", i+1, t.label), v) + "\n")
|
||||
for _, l := range t.under {
|
||||
s.out(l + "\n")
|
||||
}
|
||||
}
|
||||
for _, l := range extra {
|
||||
s.out(l + "\n")
|
||||
}
|
||||
c, err := s.settingsChoice("Enter choice !")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n, _ := strconv.Atoi(c)
|
||||
switch {
|
||||
case c == "":
|
||||
return nil
|
||||
case n >= 1 && n <= len(items):
|
||||
err = s.changeSetting(p, items[n-1], session)
|
||||
default:
|
||||
s.out(c + " is not a choice !\n")
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// changeSetting is a setting's screen: its value, its choices, the new one.
|
||||
func (s *session) changeSetting(p *profile, t *tsetting, session bool) error {
|
||||
s.out("\n" + t.title + "\n\n")
|
||||
if t.none != nil {
|
||||
for _, l := range t.none {
|
||||
s.out(l + "\n")
|
||||
}
|
||||
_, err := s.settingsChoice("Press <CR> !")
|
||||
return err
|
||||
}
|
||||
for _, l := range t.text {
|
||||
s.out(l + "\n")
|
||||
}
|
||||
if len(t.text) > 0 {
|
||||
s.out("\n")
|
||||
}
|
||||
label, v := "Permanent setting =", p.get(t)
|
||||
if session {
|
||||
label, v = "Session setting =", s.sessionValue(t)
|
||||
}
|
||||
s.out(bracketed(label, t.show(v)) + "\n")
|
||||
for _, l := range t.after {
|
||||
s.out(l + "\n")
|
||||
}
|
||||
var nv string
|
||||
if t.hi > 0 {
|
||||
for {
|
||||
c, err := s.prompt(t.prompt)
|
||||
if errors.Is(err, errAbort) {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c = strings.TrimSpace(c)
|
||||
if c == "" {
|
||||
return nil
|
||||
}
|
||||
if n, err := strconv.Atoi(c); err == nil && t.valid(strconv.Itoa(n)) {
|
||||
nv = strconv.Itoa(n)
|
||||
break
|
||||
}
|
||||
s.outf("Please enter a number from %d to %d.\n", t.lo, t.hi)
|
||||
}
|
||||
} else {
|
||||
s.out("\n")
|
||||
for i, c := range t.choices {
|
||||
s.outf("%2d %s\n", i+1, c.label)
|
||||
for _, l := range c.help {
|
||||
s.out(l + "\n")
|
||||
}
|
||||
}
|
||||
for {
|
||||
c, err := s.settingsChoice("Enter choice !")
|
||||
if err != nil || c == "" {
|
||||
return err
|
||||
}
|
||||
if n, _ := strconv.Atoi(c); n >= 1 && n <= len(t.choices) {
|
||||
nv = t.choices[n-1].value
|
||||
break
|
||||
}
|
||||
s.out(c + " is not a choice !\n")
|
||||
}
|
||||
}
|
||||
if !session {
|
||||
p.pending[t.key] = nv
|
||||
}
|
||||
s.applySetting(t, nv)
|
||||
switch {
|
||||
case t == setBrief && nv == "yes":
|
||||
s.out("\nFULL/BRIEF PROMPTS\n\n" +
|
||||
"Please note: Now that you will be receiving Short prompts, some CompuServe\n" +
|
||||
"services may not warn you about SURCHARGED usage of the service.\n")
|
||||
_, err := s.settingsChoice("Press <CR> !")
|
||||
return err
|
||||
case t == setTerm && !session:
|
||||
// a terminal type brings its parameters
|
||||
for k, v := range map[*tsetting]string{setWidth: "80", setLines: "24"} {
|
||||
p.pending[k.key] = v
|
||||
s.applySetting(k, v)
|
||||
}
|
||||
p.pending["parity"], p.pending["erase"] = "even", "no"
|
||||
s.out("\nTERMINAL TYPE\n\n")
|
||||
s.out("Your terminal type is now [" + t.show(nv) + "]\n" +
|
||||
"and your terminal parameters have been adjusted accordingly. If you wish to\n" +
|
||||
"override these parameters, you can append ;TTY to your User ID when logging on.\n")
|
||||
_, err := s.settingsChoice("Press <CR> !")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// leaveSettings is <CR> at the top: changes to keep are confirmed first,
|
||||
// then PROFILE.
|
||||
func (s *session) leaveSettings(p *profile) error {
|
||||
if len(p.pending) == 0 {
|
||||
s.show(s.page)
|
||||
return nil
|
||||
}
|
||||
for {
|
||||
s.out("\nCHANGE PERMANENT SETTINGS\n\n" +
|
||||
" 1 Confirm\n" +
|
||||
" (Select this choice if you wish to\n" +
|
||||
" update your User Profile with the\n" +
|
||||
" permanent changes you have made.)\n" +
|
||||
" 2 Cancel\n" +
|
||||
" (Select this choice if you do not\n" +
|
||||
" wish to save the changes you have\n" +
|
||||
" made to your permanent settings.\n" +
|
||||
" This will not \"undo\" the changes\n" +
|
||||
" for this session, but they will not\n" +
|
||||
" be in effect the next time you log\n" +
|
||||
" onto CompuServe.)\n")
|
||||
c, err := s.settingsChoice("Enter choice !")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if c == "1" {
|
||||
for k, v := range p.pending {
|
||||
if err := s.node.SetPref("cis-"+k, v); err != nil {
|
||||
s.b.Log.Printf("node %d: CompuServe: keeping cis-%s: %v", s.node.Num, k, err)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
if c == "2" {
|
||||
break
|
||||
}
|
||||
}
|
||||
s.goTo(s.pages.Get("PROFILE"))
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/D-Modem/bbs/internal/aol"
|
||||
"github.com/D-Modem/bbs/internal/config"
|
||||
)
|
||||
|
||||
// aolSection reads [aol]: the host for AOL's own clients.
|
||||
func (c *Config) aolSection(cf *config.File) error {
|
||||
s := cf.Get("aol", "")
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
err := func() error {
|
||||
a := &aol.Settings{Address: s.String("address", ":5190")}
|
||||
if _, _, err := net.SplitHostPort(a.Address); err != nil {
|
||||
return fmt.Errorf("address: %v", err)
|
||||
}
|
||||
var err error
|
||||
if a.MaxClients, err = s.Int("max_clients", 256, 1, 100000); err != nil {
|
||||
return err
|
||||
}
|
||||
if a.MaxPerIP, err = s.Int("max_per_ip", 4, 0, 1000); err != nil {
|
||||
return err
|
||||
}
|
||||
c.AOL = a
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
return fmt.Errorf("[aol] %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/D-Modem/bbs/internal/bbs"
|
||||
)
|
||||
|
||||
// TestCompuServeDefault: TAPCIS's ALT-P (PARAMS.SCR, 1991), its sends and
|
||||
// waits in order, through GO DEFAULT's permanent settings; then the
|
||||
// settings at the next logon, and ;TTY.
|
||||
func TestCompuServeDefault(t *testing.T) {
|
||||
e := start(t, nil, cisListener())
|
||||
d := cisLogin(e, "72000,1", "alicepass1")
|
||||
steps := []struct{ send, wait string }{
|
||||
{"G DEFAULT", "TERM"}, {"-", "!"},
|
||||
{"2", "!"}, {"3", "!"}, {"1", "!"}, {"2", "!"}, {"", "!"},
|
||||
{"2", "!"}, {"1", "!"}, {"4", "!"}, {"2", "!"}, {"2", "!"},
|
||||
{"4", "!"}, {"1", "!"}, {"5", "!"}, {"1", "!"}, {"6", "!"}, {"2", "!"}, {"", "!"},
|
||||
{"3", "!"}, {"1", "!"}, {"2", "!"},
|
||||
{"2", "<CR>"}, {"-", "."}, {"-", "!"},
|
||||
{"1", "!"}, {"", "!"}, {"", "!"},
|
||||
{"4", "!"}, {"1", "!"}, {"8", "!"}, {"", "!"},
|
||||
{"2", ":"}, {"79", "!"}, {"3", ":"}, {"0", "!"},
|
||||
{"6", "!"}, {"1", "!"}, {"7", "!"}, {"1", "!"},
|
||||
{"8", "!"}, {"3", "!"}, {"9", ":"}, {"0", "!"},
|
||||
{"10", "!"}, {"1", "!"}, {"11", "!"}, {"2", "!"}, {"", "!"},
|
||||
{"5", "!"}, {"1", "!"}, {"1", "!"}, {"", "!"},
|
||||
{"", "!"}, {"", "!"},
|
||||
{"", "CHANGE PERMANENT SETTINGS"}, {"-", "!"},
|
||||
{"1", "CHANGE YOUR USER PROFILE"}, {"-", "!"},
|
||||
}
|
||||
// "-": no send, a second wait on the same screen
|
||||
for _, st := range steps {
|
||||
if st.send != "-" {
|
||||
d.send(st.send + "\r")
|
||||
}
|
||||
d.expect(st.wait)
|
||||
}
|
||||
d.send("OFF\r")
|
||||
d.expect("Thank you for using CompuServe!")
|
||||
|
||||
u, err := e.b.Store.UserByName("alice")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p := bbs.ParsePrefs(u.Prefs)
|
||||
for k, v := range map[string]string{
|
||||
"cis-paged": "no", "cis-brief": "yes", "cis-width": "79", "cis-lines": "0",
|
||||
"cis-first": "command", "cis-mailwait": "notify", "cis-top": "main", "cis-editor": "edit",
|
||||
"cis-forummode": "command", "cis-term": "other", "cis-parity": "zero", "cis-delays": "0",
|
||||
"cis-erase": "yes", "cis-inquiry": "no", "cis-protocol": "b", "cis-case": "ul", "cis-caps": "no",
|
||||
} {
|
||||
if p[k] != v {
|
||||
t.Errorf("%s = %q, want %q (%s)", k, p[k], v, u.Prefs)
|
||||
}
|
||||
}
|
||||
|
||||
// the next logon is brief; with ;TTY it is not
|
||||
d = e.dial("cis.sock")
|
||||
d.expect("Host Name: ")
|
||||
d.send("CIS\r")
|
||||
d.expect("User ID: ")
|
||||
d.send("72000,1\r")
|
||||
d.expect("Password: ")
|
||||
d.send("alicepass1\r")
|
||||
d.expect("12 Business/Other Interests\r\n!")
|
||||
d.send("OFF\r")
|
||||
d.expect("Thank you for using CompuServe!")
|
||||
d = cisLogin(e, "72000,1;TTY", "alicepass1")
|
||||
if strings.Contains(string(d.before), "\n!") {
|
||||
t.Errorf("brief with ;TTY: %q", d.before)
|
||||
}
|
||||
d.send("GO TERMINAL\r")
|
||||
d.expect("TERMINAL SETTINGS/SERVICE OPTIONS")
|
||||
d.expect("Enter choice !")
|
||||
d.send("4\r")
|
||||
d.expect(" BRIEF prompts NO YES\r\n")
|
||||
d.expect(" Screen WIDTH 80 79\r\n")
|
||||
d.send("\r")
|
||||
d.expect("Enter choice !")
|
||||
d.send("OFF\r")
|
||||
d.expect("Thank you for using CompuServe!")
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/D-Modem/bbs/internal/aol"
|
||||
"github.com/D-Modem/bbs/internal/api"
|
||||
"net"
|
||||
"os"
|
||||
@@ -62,6 +63,7 @@ type Config struct {
|
||||
Finger *finger.Settings // nil: no finger server
|
||||
IRC *ircd.Settings // nil: no IRC server
|
||||
OSCAR *oscar.Settings // nil: no AIM/ICQ server
|
||||
AOL *aol.Settings // nil: no host for AOL clients
|
||||
MSN *msn.Settings // nil: no MSN Messenger server
|
||||
MRC *mrc.Settings // nil: not on Multi Relay Chat
|
||||
Screens *screens.Set // nil: no screens of the sysop's
|
||||
@@ -142,6 +144,9 @@ func load(cf *config.File) (*Config, error) {
|
||||
if err := c.oscarSection(cf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := c.aolSection(cf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := c.msnSection(cf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -217,7 +222,7 @@ func load(cf *config.File) (*Config, error) {
|
||||
}
|
||||
for _, s := range cf.Sections {
|
||||
switch s.Kind {
|
||||
case "general", "security", "backup", "modemmenu", "event", "listen", "ftp", "news", "nntp", "peer", "qwknet", "fido", "binkp", "link", "door", "finger", "gopher", "time", "ntp", "nts", "ptp", "irc", "oscar", "msn", "mrc", "menu", "strings", "http", "level", "chan":
|
||||
case "general", "security", "backup", "modemmenu", "event", "listen", "ftp", "news", "nntp", "peer", "qwknet", "fido", "binkp", "link", "door", "finger", "gopher", "time", "ntp", "nts", "ptp", "irc", "oscar", "aol", "msn", "mrc", "menu", "strings", "http", "level", "chan":
|
||||
default:
|
||||
return nil, fmt.Errorf("line %d: unknown section [%s]", s.Line, s.Kind)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user