Changeset 636 in code
- Timestamp:
- Oct 13, 2021, 8:58:34 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cmd/soju/main.go
r620 r636 6 6 "flag" 7 7 "fmt" 8 "io/ioutil" 8 9 "log" 9 10 "net" … … 37 38 } 38 39 40 func loadMOTD(srv *soju.Server, filename string) error { 41 if filename == "" { 42 return nil 43 } 44 45 b, err := ioutil.ReadFile(filename) 46 if err != nil { 47 return err 48 } 49 srv.SetMOTD(strings.TrimSpace(string(b))) 50 return nil 51 } 52 39 53 func main() { 40 54 var listen []string … … 92 106 srv.Debug = debug 93 107 108 if err := loadMOTD(srv, cfg.MOTDPath); err != nil { 109 log.Fatalf("failed to load MOTD: %v", err) 110 } 111 94 112 for _, listen := range cfg.Listen { 95 113 listenURI := listen … … 225 243 switch sig { 226 244 case syscall.SIGHUP: 245 log.Print("reloading TLS certificate and MOTD") 227 246 if cfg.TLS != nil { 228 log.Print("reloading TLS certificate")229 247 cert, err := tls.LoadX509KeyPair(cfg.TLS.CertPath, cfg.TLS.KeyPath) 230 248 if err != nil { … … 233 251 } 234 252 tlsCert.Store(&cert) 253 } 254 if err := loadMOTD(srv, cfg.MOTDPath); err != nil { 255 log.Printf("failed to reload MOTD: %v", err) 235 256 } 236 257 case syscall.SIGINT, syscall.SIGTERM: -
trunk/config/config.go
r612 r636 41 41 Hostname string 42 42 TLS *TLS 43 MOTDPath string 43 44 44 45 SQLDriver string … … 129 130 return nil, fmt.Errorf("directive %q: %v", d.Name, err) 130 131 } 132 case "motd": 133 if err := d.ParseParams(&srv.MOTDPath); err != nil { 134 return nil, err 135 } 131 136 default: 132 137 return nil, fmt.Errorf("unknown directive %q", d.Name) -
trunk/doc/soju.1.scd
r632 r636 45 45 be done by adding a "@<client>" suffix to the username. 46 46 47 soju will reload the TLS certificate and key when it receives the HUP signal. 47 soju will reload the TLS certificate/key and the MOTD file when it receives the 48 HUP signal. 48 49 49 50 Administrators can broadcast a message to all bouncer users via _/notice … … 143 144 Maximum number of networks per user. By default, there is no limit. 144 145 146 *motd* <path> 147 Path to the MOTD file. The bouncer MOTD is sent to clients which aren't 148 bound to a specific network. By default, no MOTD is sent. 149 145 150 # IRC SERVICE 146 151 -
trunk/downstream.go
r629 r636 1120 1120 dc.SendMessage(msg) 1121 1121 } 1122 motdHint := "No MOTD"1123 1122 if uc := dc.upstream(); uc != nil { 1124 motdHint = "Use /motd to read the message of the day"1125 1123 dc.SendMessage(&irc.Message{ 1126 1124 Prefix: dc.srv.prefix(), … … 1129 1127 }) 1130 1128 } 1131 dc.SendMessage(&irc.Message{ 1132 Prefix: dc.srv.prefix(), 1133 Command: irc.ERR_NOMOTD, 1134 Params: []string{dc.nick, motdHint}, 1135 }) 1129 1130 if motd := dc.user.srv.MOTD(); motd != "" && dc.network == nil { 1131 for _, msg := range generateMOTD(dc.srv.prefix(), dc.nick, motd) { 1132 dc.SendMessage(msg) 1133 } 1134 } else { 1135 motdHint := "No MOTD" 1136 if dc.network != nil { 1137 motdHint = "Use /motd to read the message of the day" 1138 } 1139 dc.SendMessage(&irc.Message{ 1140 Prefix: dc.srv.prefix(), 1141 Command: irc.ERR_NOMOTD, 1142 Params: []string{dc.nick, motdHint}, 1143 }) 1144 } 1136 1145 1137 1146 dc.updateNick() -
trunk/irc.go
r516 r636 380 380 } 381 381 382 func generateMOTD(prefix *irc.Prefix, nick string, motd string) []*irc.Message { 383 var msgs []*irc.Message 384 msgs = append(msgs, &irc.Message{ 385 Prefix: prefix, 386 Command: irc.RPL_MOTDSTART, 387 Params: []string{nick, fmt.Sprintf("- Message of the Day -")}, 388 }) 389 390 for _, l := range strings.Split(motd, "\n") { 391 msgs = append(msgs, &irc.Message{ 392 Prefix: prefix, 393 Command: irc.RPL_MOTD, 394 Params: []string{nick, l}, 395 }) 396 } 397 398 msgs = append(msgs, &irc.Message{ 399 Prefix: prefix, 400 Command: irc.RPL_ENDOFMOTD, 401 Params: []string{nick, "End of /MOTD command."}, 402 }) 403 404 return msgs 405 } 406 382 407 type joinSorter struct { 383 408 channels []string -
trunk/server.go
r612 r636 64 64 listeners map[net.Listener]struct{} 65 65 users map[string]*user 66 67 motd atomic.Value // string 66 68 } 67 69 68 70 func NewServer(db Database) *Server { 69 return&Server{71 srv := &Server{ 70 72 Logger: log.New(log.Writer(), "", log.LstdFlags), 71 73 HistoryLimit: 1000, … … 75 77 users: make(map[string]*user), 76 78 } 79 srv.motd.Store("") 80 return srv 77 81 } 78 82 … … 269 273 return &stats 270 274 } 275 276 func (s *Server) SetMOTD(motd string) { 277 s.motd.Store(motd) 278 } 279 280 func (s *Server) MOTD() string { 281 return s.motd.Load().(string) 282 }
Note:
See TracChangeset
for help on using the changeset viewer.