mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-28 17:38:04 -08:00
screens_dir holds display files by name: NAME.ans (ANSI art in CP437,
SAUCE dropped; UTF-8 to UTF-8 terminals, CP437 bytes to the rest),
NAME.asc/.txt (text, paged) and NAME.3270 (text with {color} tags).
logon, newuser, welcome and goodbye are shown by themselves, on text
terminals and 3270s; others by menus. @-codes (@USER@, @NEWMAIL@,
@NODE@, @ONLINE@ ... with @CODE:20@ widths, @CLS@, @PAUSE@) are filled
in, their values cleaned.
[menu NAME] sections: KEY = ACTION Label, actions the built-in parts or
door:, menu:, screen:, area:; [menu main] replaces the built-in main menu
on both kinds of terminal, with an optional screen in place of its list.
[strings]: the login and command prompts, the pause, the logoff question
and the welcome. bbs check refuses menus naming what is not there.
screens.sample: a set of screens to start from. Tested: the screens
package; menus and strings in the configuration; a text caller through
ANSI art, strings, menus and screens; a 3270 (s3270) through colored
screens and the sysop's main menu. Wiki page Customization.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
112 lines
3.0 KiB
Go
112 lines
3.0 KiB
Go
package server
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"sort"
|
|
"strings"
|
|
|
|
"github.com/Neo-Desktop/bbs-sec/internal/bbs"
|
|
"github.com/Neo-Desktop/bbs-sec/internal/config"
|
|
"github.com/Neo-Desktop/bbs-sec/internal/screens"
|
|
)
|
|
|
|
// customSections reads screens_dir, the [menu NAME]s and [strings].
|
|
func (c *Config) customSections(cf *config.File) error {
|
|
if dir := cf.Get("general", "").String("screens_dir", ""); dir != "" {
|
|
if fi, err := os.Stat(dir); err != nil || !fi.IsDir() {
|
|
c.Warnings = append(c.Warnings, fmt.Sprintf("[general] screens_dir %s is not a directory: no screens", dir))
|
|
}
|
|
c.Screens = &screens.Set{Dir: dir}
|
|
}
|
|
c.Menus = map[string]*bbs.Menu{}
|
|
for _, s := range cf.All("menu") {
|
|
m, err := menu(s)
|
|
if err != nil {
|
|
return fmt.Errorf("[menu %s] %w", s.Name, err)
|
|
}
|
|
if c.Menus[m.Name] != nil {
|
|
return fmt.Errorf("[menu %s] given twice", m.Name)
|
|
}
|
|
c.Menus[m.Name] = m
|
|
}
|
|
// what menus name must be there
|
|
doors := map[string]bool{}
|
|
for _, d := range c.Doors {
|
|
doors[strings.ToLower(d.Name)] = true
|
|
}
|
|
for _, m := range c.Menus {
|
|
for _, it := range m.Items {
|
|
switch it.Action {
|
|
case "menu":
|
|
if c.Menus[strings.ToLower(it.Arg)] == nil {
|
|
return fmt.Errorf("[menu %s] %s: there is no [menu %s]", m.Name, it.Key, it.Arg)
|
|
}
|
|
case "door":
|
|
if !doors[strings.ToLower(it.Arg)] {
|
|
return fmt.Errorf("[menu %s] %s: there is no [door %s]", m.Name, it.Key, it.Arg)
|
|
}
|
|
case "screen":
|
|
if c.Screens == nil {
|
|
return fmt.Errorf("[menu %s] %s: screen:%s, but no screens_dir", m.Name, it.Key, it.Arg)
|
|
}
|
|
}
|
|
}
|
|
if m.Screen != "" && c.Screens == nil {
|
|
return fmt.Errorf("[menu %s] screen = %s, but no screens_dir", m.Name, m.Screen)
|
|
}
|
|
}
|
|
c.Text = map[string]string{}
|
|
if s := cf.Get("strings", ""); s != nil {
|
|
for _, k := range s.Keys() {
|
|
if _, ok := bbs.Strings[k]; !ok {
|
|
return fmt.Errorf("[strings] %s: no such string (%s)", k, strings.Join(stringKeys(), ", "))
|
|
}
|
|
c.Text[k] = s.String(k, "")
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func stringKeys() []string {
|
|
var out []string
|
|
for k := range bbs.Strings {
|
|
out = append(out, k)
|
|
}
|
|
sort.Strings(out)
|
|
return out
|
|
}
|
|
|
|
func menu(s *config.Section) (*bbs.Menu, error) {
|
|
name := strings.ToLower(s.Name)
|
|
if name == "" {
|
|
return nil, errors.New("a menu needs a name: [menu main]")
|
|
}
|
|
m := &bbs.Menu{Name: name, Title: s.String("title", s.Name), Screen: s.String("screen", ""),
|
|
Prompt: s.String("prompt", "")}
|
|
if m.Screen != "" && !screens.ValidName(m.Screen) {
|
|
return nil, errors.New("screen: a screen's name is lower case letters, digits, _ and -")
|
|
}
|
|
seen := map[string]bool{}
|
|
for _, k := range s.Keys() {
|
|
switch k {
|
|
case "title", "screen", "prompt":
|
|
continue
|
|
}
|
|
it, err := bbs.ParseMenuItem(k, s.String(k, ""))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if seen[it.Key] {
|
|
return nil, fmt.Errorf("%s given twice", it.Key)
|
|
}
|
|
seen[it.Key] = true
|
|
m.Items = append(m.Items, it)
|
|
}
|
|
if len(m.Items) == 0 {
|
|
return nil, errors.New("no items: KEY = ACTION Label, e.g. m = areas Message areas")
|
|
}
|
|
return m, nil
|
|
}
|