Add title config option

Closes: https://todo.sr.ht/~emersion/soju/146
This commit is contained in:
Simon Ser 2021-11-02 22:38:07 +01:00
parent 832d8b89a2
commit 07c962018d
6 changed files with 25 additions and 7 deletions

View File

@ -97,8 +97,8 @@ func main() {
}
srv := soju.NewServer(db)
// TODO: load from config/DB
srv.Hostname = cfg.Hostname
srv.Title = cfg.Title
srv.LogPath = cfg.LogPath
srv.HTTPOrigins = cfg.HTTPOrigins
srv.AcceptProxyIPs = cfg.AcceptProxyIPs

View File

@ -38,8 +38,9 @@ type TLS struct {
type Server struct {
Listen []string
Hostname string
TLS *TLS
Hostname string
Title string
MOTDPath string
SQLDriver string
@ -87,6 +88,14 @@ func parse(cfg scfg.Block) (*Server, error) {
if err := d.ParseParams(&srv.Hostname); err != nil {
return nil, err
}
case "title":
if err := d.ParseParams(&srv.Title); err != nil {
return nil, err
}
case "motd":
if err := d.ParseParams(&srv.MOTDPath); err != nil {
return nil, err
}
case "tls":
tls := &TLS{}
if err := d.ParseParams(&tls.CertPath, &tls.KeyPath); err != nil {
@ -129,10 +138,6 @@ func parse(cfg scfg.Block) (*Server, error) {
if srv.MaxUserNetworks, err = strconv.Atoi(max); err != nil {
return nil, fmt.Errorf("directive %q: %v", d.Name, err)
}
case "motd":
if err := d.ParseParams(&srv.MOTDPath); err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("unknown directive %q", d.Name)
}

View File

@ -104,6 +104,10 @@ The following directives are supported:
*hostname* <name>
Server hostname (default: system hostname).
*title* <title>
Server title. This will be sent as the _ISUPPORT NETWORK_ value when clients
don't select a specific network.
*tls* <cert> <key>
Enable TLS support. The certificate and the key files must be PEM-encoded.

View File

@ -1157,7 +1157,9 @@ func (dc *downstreamConn) welcome() error {
if dc.network != nil {
isupport = append(isupport, fmt.Sprintf("BOUNCER_NETID=%v", dc.network.ID))
}
if dc.network == nil && dc.srv.Title != "" {
isupport = append(isupport, "NETWORK="+encodeISUPPORT(dc.srv.Title))
}
if dc.network == nil && dc.caps["soju.im/bouncer-networks"] {
isupport = append(isupport, "WHOX")
}

6
irc.go
View File

@ -761,3 +761,9 @@ func generateWHOXReply(prefix *irc.Prefix, nick, fields string, info *whoxInfo)
Params: append([]string{nick}, params...),
}
}
var isupportEncoder = strings.NewReplacer(" ", "\\x20", "\\", "\\x5C")
func encodeISUPPORT(s string) string {
return isupportEncoder.Replace(s)
}

View File

@ -50,6 +50,7 @@ func (l *prefixLogger) Printf(format string, v ...interface{}) {
type Server struct {
Hostname string
Title string
Logger Logger
HistoryLimit int
LogPath string