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) srv := soju.NewServer(db)
// TODO: load from config/DB
srv.Hostname = cfg.Hostname srv.Hostname = cfg.Hostname
srv.Title = cfg.Title
srv.LogPath = cfg.LogPath srv.LogPath = cfg.LogPath
srv.HTTPOrigins = cfg.HTTPOrigins srv.HTTPOrigins = cfg.HTTPOrigins
srv.AcceptProxyIPs = cfg.AcceptProxyIPs srv.AcceptProxyIPs = cfg.AcceptProxyIPs

View File

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

View File

@ -104,6 +104,10 @@ The following directives are supported:
*hostname* <name> *hostname* <name>
Server hostname (default: system hostname). 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> *tls* <cert> <key>
Enable TLS support. The certificate and the key files must be PEM-encoded. 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 { if dc.network != nil {
isupport = append(isupport, fmt.Sprintf("BOUNCER_NETID=%v", dc.network.ID)) 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"] { if dc.network == nil && dc.caps["soju.im/bouncer-networks"] {
isupport = append(isupport, "WHOX") 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...), 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 { type Server struct {
Hostname string Hostname string
Title string
Logger Logger Logger Logger
HistoryLimit int HistoryLimit int
LogPath string LogPath string