Documentation
¶
Overview ¶
Package session holds the state of each connected caller (BbsSession) and the SessionRegistry that indexes the live sessions by node number. The server registers a session when a caller connects and removes it on disconnect; who's online, node paging, chat, the admin views and V3 scripts read the registry to see who else is on.
Index ¶
- type BbsSession
- func (s *BbsSession) AddExpiringPage(msg string, ttl time.Duration)
- func (s *BbsSession) AddPage(msg string)
- func (s *BbsSession) ClearToastAnchor()
- func (s *BbsSession) DrainPages() []string
- func (s *BbsSession) HoldPage()
- func (s *BbsSession) NoteToastAnnounced(id string) bool
- func (s *BbsSession) NoteToastShown(id string)
- func (s *BbsSession) PeekHeldPage() (string, bool)
- func (s *BbsSession) PeekPage() (string, bool)
- func (s *BbsSession) PopHeldPage()
- func (s *BbsSession) PopPage()
- func (s *BbsSession) SetToastAnchor(row, col int)
- func (s *BbsSession) SetToastViewer(accessLevel, screenWidth int)
- func (s *BbsSession) SetToastsReady(ready bool)
- func (s *BbsSession) TermSize() (width, height int)
- func (s *BbsSession) ToastAnchor() (row, col int, ok bool)
- func (s *BbsSession) ToastAnnounced(id string) bool
- func (s *BbsSession) ToastShown(id string) bool
- func (s *BbsSession) ToastViewer() (accessLevel, screenWidth int, ok bool)
- func (s *BbsSession) ToastWake() <-chan struct{}
- func (s *BbsSession) ToastsReady() bool
- func (s *BbsSession) WakeToasts()
- type SessionRegistry
- func (r *SessionRegistry) ActiveCount() int
- func (r *SessionRegistry) Get(nodeID int) *BbsSession
- func (r *SessionRegistry) ListActive() []*BbsSession
- func (r *SessionRegistry) Register(s *BbsSession)
- func (r *SessionRegistry) SendToast(store *toast.Store, userID int, t toast.Toast) error
- func (r *SessionRegistry) Unregister(nodeID int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BbsSession ¶
type BbsSession struct {
ID int // Unique identifier for the session/node
Conn gossh.Conn
Channel gossh.Channel // Store the SSH channel for direct I/O
Term *term.Terminal
User *user.User // Logged-in user, nil if not logged in
Width int
Height int
RemoteAddr net.Addr
CurrentMenu string // Tracks the current ViSiON/2 menu the user is in
Activity string // Descriptive activity text for Who's Online (e.g., "Reading Messages")
NodeID int // Node ID for the session
AssetsPath string // Store required path directly
Mutex sync.RWMutex // For thread-safe access to session state if needed later
Pty *ssh.Pty // Store PTY info
AutoRunLog types.AutoRunTracker // Tracks run-once commands executed (Use types.AutoRunTracker)
LastMenu string // Tracks the previously visited menu
StartTime time.Time // Tracks the session start time
LastActivity time.Time // Tracks last user input for idle calculation
PendingPages []pendingPage // Live-only toasts waiting to be shown; not kept across a restart
Invisible bool // True if user logged in invisibly (SysOp/CoSysOp only)
Tap *snoop.Tap // WFC snoop point for this node; nil in tests
ChatCredit func() time.Duration // Sysop chat time credited to the caller; nil means none
// Size returns the caller's live terminal size. The SSH session handler
// sets it; sessions built without it (tests) report Width and Height.
Size func() (width, height int)
// contains filtered or unexported fields
}
BbsSession represents one caller's connection to the BBS: the SSH channel and terminal it talks through, the logged-in user (nil until login), and the node, menu and activity details shown to other callers. Fields that change while the session runs are guarded by Mutex.
func (*BbsSession) AddExpiringPage ¶ added in v0.9.6
func (s *BbsSession) AddExpiringPage(msg string, ttl time.Duration)
AddExpiringPage is AddPage for news that is worthless after ttl, such as a logon announcement to a caller who is in a door.
func (*BbsSession) AddPage ¶
func (s *BbsSession) AddPage(msg string)
AddPage queues a live-only toast for this session and wakes its key wait.
func (*BbsSession) ClearToastAnchor ¶ added in v0.9.6
func (s *BbsSession) ClearToastAnchor()
ClearToastAnchor returns toasts to the configured position.
func (*BbsSession) DrainPages ¶
func (s *BbsSession) DrainPages() []string
DrainPages returns all pending pages and clears the queue.
func (*BbsSession) HoldPage ¶ added in v0.9.6
func (s *BbsSession) HoldPage()
HoldPage takes the oldest pending page out of the overlay's way: it has been drawn cut short, so the whole of it waits for the next inline delivery.
func (*BbsSession) NoteToastAnnounced ¶ added in v0.9.6
func (s *BbsSession) NoteToastAnnounced(id string) bool
NoteToastAnnounced records that this session has drawn a toast's line but not all of it, the row having cut it short, and reports whether it is the first time.
func (*BbsSession) NoteToastShown ¶ added in v0.9.6
func (s *BbsSession) NoteToastShown(id string)
NoteToastShown records that this session has shown all of a toast but could not remove it from the queue, so it is not shown again while the removal is retried.
func (*BbsSession) PeekHeldPage ¶ added in v0.9.6
func (s *BbsSession) PeekHeldPage() (string, bool)
PeekHeldPage returns the oldest page HoldPage kept, without removing it.
func (*BbsSession) PeekPage ¶ added in v0.9.6
func (s *BbsSession) PeekPage() (string, bool)
PeekPage returns the oldest pending page without removing it.
func (*BbsSession) PopHeldPage ¶ added in v0.9.6
func (s *BbsSession) PopHeldPage()
PopHeldPage removes the oldest page HoldPage kept.
func (*BbsSession) PopPage ¶ added in v0.9.6
func (s *BbsSession) PopPage()
PopPage removes the oldest pending page.
func (*BbsSession) SetToastAnchor ¶ added in v0.9.6
func (s *BbsSession) SetToastAnchor(row, col int)
SetToastAnchor sets where toasts go while the current menu screen is up.
func (*BbsSession) SetToastViewer ¶ added in v0.9.6
func (s *BbsSession) SetToastViewer(accessLevel, screenWidth int)
SetToastViewer publishes the current values of the caller's record for other sessions to read. User stays the record taken at login: the session goroutine works on its own copy, changing it in place, so that copy cannot be shared.
func (*BbsSession) SetToastsReady ¶ added in v0.9.6
func (s *BbsSession) SetToastsReady(ready bool)
SetToastsReady marks whether the session can show toasts on screen. It is false until the login sequence has finished, so none lands on login art.
func (*BbsSession) TermSize ¶ added in v0.9.5
func (s *BbsSession) TermSize() (width, height int)
TermSize returns the caller's current terminal size.
func (*BbsSession) ToastAnchor ¶ added in v0.9.6
func (s *BbsSession) ToastAnchor() (row, col int, ok bool)
ToastAnchor returns what SetToastAnchor set, and whether anything is set.
func (*BbsSession) ToastAnnounced ¶ added in v0.9.6
func (s *BbsSession) ToastAnnounced(id string) bool
ToastAnnounced reports whether NoteToastAnnounced has seen id.
func (*BbsSession) ToastShown ¶ added in v0.9.6
func (s *BbsSession) ToastShown(id string) bool
ToastShown reports whether NoteToastShown has seen id.
func (*BbsSession) ToastViewer ¶ added in v0.9.6
func (s *BbsSession) ToastViewer() (accessLevel, screenWidth int, ok bool)
ToastViewer returns what SetToastViewer last published, or the login record's values until it has run. ok is false when nobody is logged in.
func (*BbsSession) ToastWake ¶ added in v0.9.6
func (s *BbsSession) ToastWake() <-chan struct{}
ToastWake returns the channel that fires when this session may have a toast to show. It is buffered, so a wake is kept until a key wait takes it.
func (*BbsSession) ToastsReady ¶ added in v0.9.6
func (s *BbsSession) ToastsReady() bool
ToastsReady reports what SetToastsReady last set.
func (*BbsSession) WakeToasts ¶ added in v0.9.6
func (s *BbsSession) WakeToasts()
WakeToasts tells the session's key wait to look for toasts.
type SessionRegistry ¶
type SessionRegistry struct {
// contains filtered or unexported fields
}
SessionRegistry tracks all active BBS sessions.
func NewSessionRegistry ¶
func NewSessionRegistry() *SessionRegistry
NewSessionRegistry returns an empty registry, ready for use.
func (*SessionRegistry) ActiveCount ¶
func (r *SessionRegistry) ActiveCount() int
ActiveCount returns the number of currently active sessions.
func (*SessionRegistry) Get ¶
func (r *SessionRegistry) Get(nodeID int) *BbsSession
Get returns the session registered for nodeID, or nil if that node is not in use. The returned session is shared; guard access to its mutable fields with its Mutex.
func (*SessionRegistry) ListActive ¶
func (r *SessionRegistry) ListActive() []*BbsSession
ListActive returns a snapshot of the registered sessions sorted by NodeID. The slice is the caller's to keep, but the sessions it points to are shared and may change or disconnect after it returns.
func (*SessionRegistry) Register ¶
func (r *SessionRegistry) Register(s *BbsSession)
Register adds s to the registry under s.NodeID, replacing any session already registered for that node. Safe for concurrent use.
func (*SessionRegistry) SendToast ¶ added in v0.9.6
SendToast queues a toast for a user account and wakes any session they have. The disk comes first, so a toast cannot be lost with a session that ends before showing it. If the write fails, online sessions still get its line.
func (*SessionRegistry) Unregister ¶
func (r *SessionRegistry) Unregister(nodeID int)
Unregister removes the session for nodeID; it is a no-op if none is registered. Safe for concurrent use.