3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-29 07:29:31 +01:00

load motd directly into the config object

This commit is contained in:
Shivaram Lingamneni 2019-05-10 00:07:22 -04:00
parent fbc6c84a01
commit 61d666a25b
2 changed files with 10 additions and 19 deletions

View File

@ -280,6 +280,7 @@ type Config struct {
STS STSConfig STS STSConfig
CheckIdent bool `yaml:"check-ident"` CheckIdent bool `yaml:"check-ident"`
MOTD string MOTD string
motdLines []string
MOTDFormatting bool `yaml:"motd-formatting"` MOTDFormatting bool `yaml:"motd-formatting"`
ProxyAllowedFrom []string `yaml:"proxy-allowed-from"` ProxyAllowedFrom []string `yaml:"proxy-allowed-from"`
proxyAllowedFromNets []net.IPNet proxyAllowedFromNets []net.IPNet
@ -710,6 +711,8 @@ func LoadConfig(filename string) (config *Config, err error) {
config.Server.Compatibility.forceTrailing = true config.Server.Compatibility.forceTrailing = true
} }
config.loadMOTD()
// in the current implementation, we disable history by creating a history buffer // in the current implementation, we disable history by creating a history buffer
// with zero capacity. but the `enabled` config option MUST be respected regardless // with zero capacity. but the `enabled` config option MUST be respected regardless
// of this detail // of this detail

View File

@ -468,9 +468,7 @@ func (client *Client) t(originalString string) string {
// MOTD serves the Message of the Day. // MOTD serves the Message of the Day.
func (server *Server) MOTD(client *Client, rb *ResponseBuffer) { func (server *Server) MOTD(client *Client, rb *ResponseBuffer) {
server.configurableStateMutex.RLock() motdLines := server.Config().Server.motdLines
motdLines := server.motdLines
server.configurableStateMutex.RUnlock()
if len(motdLines) < 1 { if len(motdLines) < 1 {
rb.Add(nil, server.name, ERR_NOMOTD, client.nick, client.t("MOTD File is missing")) rb.Add(nil, server.name, ERR_NOMOTD, client.nick, client.t("MOTD File is missing"))
@ -774,8 +772,6 @@ func (server *Server) applyConfig(config *Config, initial bool) (err error) {
} }
} }
server.loadMOTD(config.Server.MOTD, config.Server.MOTDFormatting)
// save a pointer to the new config // save a pointer to the new config
server.SetConfig(config) server.SetConfig(config)
@ -851,11 +847,9 @@ func (server *Server) setupPprofListener(config *Config) {
} }
} }
func (server *Server) loadMOTD(motdPath string, useFormatting bool) error { func (config *Config) loadMOTD() (err error) {
server.logger.Info("server", "Using MOTD", motdPath) if config.Server.MOTD != "" {
motdLines := make([]string, 0) file, err := os.Open(config.Server.MOTD)
if motdPath != "" {
file, err := os.Open(motdPath)
if err == nil { if err == nil {
defer file.Close() defer file.Close()
@ -867,7 +861,7 @@ func (server *Server) loadMOTD(motdPath string, useFormatting bool) error {
} }
line = strings.TrimRight(line, "\r\n") line = strings.TrimRight(line, "\r\n")
if useFormatting { if config.Server.MOTDFormatting {
line = ircfmt.Unescape(line) line = ircfmt.Unescape(line)
} }
@ -875,17 +869,11 @@ func (server *Server) loadMOTD(motdPath string, useFormatting bool) error {
// bursting it out to clients easier // bursting it out to clients easier
line = fmt.Sprintf("- %s", line) line = fmt.Sprintf("- %s", line)
motdLines = append(motdLines, line) config.Server.motdLines = append(config.Server.motdLines, line)
}
} else {
return err
} }
} }
}
server.configurableStateMutex.Lock() return
server.motdLines = motdLines
server.configurableStateMutex.Unlock()
return nil
} }
func (server *Server) loadDatastore(config *Config) error { func (server *Server) loadDatastore(config *Config) error {