Files
bbs/internal/server/ircconfig.go
T
Claude 7399e0fa36 Point repository references at the D-Modem organisation
The repositories moved from Neo-Desktop to the D-Modem GitHub
organisation: D-Modem-RE is now D-Modem/D-Modem, pico-serial is
D-Modem/hardware, modemmenu (PBX-Modem) is D-Modem/menu, bbs-sec is
D-Modem/bbs and go3270-sec is D-Modem/go3270.  Update links, module
paths, submodule URLs and source-location strings to match.  Copyright
notices still name Neo-Desktop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRUwD2JJ5d6fgHmpVTw
2026-10-29 09:02:40 +00:00

67 lines
1.9 KiB
Go

package server
import (
"crypto/tls"
"errors"
"fmt"
"net"
"github.com/D-Modem/bbs/internal/config"
"github.com/D-Modem/bbs/internal/ircd"
)
// ircSection reads [irc]: the IRC server for the chat rooms.
func (c *Config) ircSection(cf *config.File) error {
s := cf.Get("irc", "")
if s == nil {
return nil
}
err := func() error {
i := &ircd.Settings{Address: s.String("address", ":6667"), TLSAddress: s.String("tls_address", ""),
CertFile: s.String("tls_cert", ""), KeyFile: s.String("tls_key", ""),
ServerName: s.String("server_name", ""), Network: s.String("network", ""),
Service: s.String("service", "BBSServ")}
if !ircd.ValidNick(i.Service) {
return errors.New("service: the bot's nick, a letter then letters, digits, - and _")
}
if i.Address == "none" { // TLS only
i.Address = ""
}
for _, a := range []struct{ key, v string }{{"address", i.Address}, {"tls_address", i.TLSAddress}} {
if a.v == "" {
continue
}
if _, _, err := net.SplitHostPort(a.v); err != nil {
return fmt.Errorf("%s: %v", a.key, err)
}
}
if i.Address == "" && i.TLSAddress == "" {
return errors.New("address or tls_address: somewhere to listen")
}
if i.TLSAddress != "" {
if i.CertFile == "" || i.KeyFile == "" {
return errors.New("tls_address needs tls_cert and tls_key")
}
if _, err := tls.LoadX509KeyPair(i.CertFile, i.KeyFile); err != nil {
return fmt.Errorf("tls_cert, tls_key: %v", err)
}
}
var err error
if i.MaxClients, err = s.Int("max_clients", 64, 1, 10000); err != nil {
return err
}
if i.MaxPerIP, err = s.Int("max_per_ip", 4, 0, 1000); err != nil {
return err
}
if i.Address != "" && i.TLSAddress == "" {
c.Warnings = append(c.Warnings, "[irc] passwords go in the clear: give it a tls_address too")
}
c.IRC = i
return nil
}()
if err != nil {
return fmt.Errorf("[irc] %w", err)
}
return nil
}