3 Commits

Author SHA1 Message Date
Will Storey
0cad70c364 Allow setting SID by command line argument 2019-07-01 17:55:59 -07:00
Will Storey
1afbd99bc7 Log server name when starting up 2019-07-01 14:59:19 -07:00
Will Storey
c2182d5a74 Allow specifying server-name via command line argument 2019-07-01 14:49:57 -07:00
4 changed files with 51 additions and 10 deletions

View File

@@ -1,7 +1,10 @@
# 1.11.1 # 1.12.0
* Send messages during connect immediately rather than only after we've * Send messages during connect immediately rather than only after we've
performed our reverse DNS lookup. performed our reverse DNS lookup.
* Allow setting server name via command line argument.
* Log server name when starting up.
* Allow setting SID via command line argument.
# 1.11.0 (2019-01-01) # 1.11.0 (2019-01-01)

21
args.go
View File

@@ -11,12 +11,27 @@ import (
type Args struct { type Args struct {
ConfigFile string ConfigFile string
ListenFD int ListenFD int
ServerName string
SID string
} }
func getArgs() *Args { func getArgs() *Args {
configFile := flag.String("conf", "", "Configuration file.") configFile := flag.String("conf", "", "Configuration file.")
fd := flag.Int("listen-fd", -1, fd := flag.Int(
"File descriptor with listening port to use (optional).") "listen-fd",
-1,
"File descriptor with listening port to use (optional).",
)
serverName := flag.String(
"server-name",
"",
"Server name. Overrides server-name from config.",
)
sid := flag.String(
"sid",
"",
"SID. Overrides ts6-sid from config.",
)
flag.Parse() flag.Parse()
@@ -35,6 +50,8 @@ func getArgs() *Args {
return &Args{ return &Args{
ConfigFile: configPath, ConfigFile: configPath,
ListenFD: *fd, ListenFD: *fd,
ServerName: *serverName,
SID: *sid,
} }
} }

View File

@@ -78,7 +78,11 @@ type UserConfig struct {
// We parse some values into alternate representations. // We parse some values into alternate representations.
// //
// This function populates both the server.Config and server.Opers fields. // This function populates both the server.Config and server.Opers fields.
func checkAndParseConfig(file string) (*Config, error) { func checkAndParseConfig(
file,
serverName,
sid string,
) (*Config, error) {
m, err := config.ReadStringMap(file) m, err := config.ReadStringMap(file)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -113,6 +117,9 @@ func checkAndParseConfig(file string) (*Config, error) {
if m["server-name"] != "" { if m["server-name"] != "" {
c.ServerName = m["server-name"] c.ServerName = m["server-name"]
} }
if serverName != "" {
c.ServerName = serverName
}
c.ServerInfo = "IRC" c.ServerInfo = "IRC"
if m["server-info"] != "" { if m["server-info"] != "" {
@@ -216,6 +223,9 @@ func checkAndParseConfig(file string) (*Config, error) {
} }
c.TS6SID = TS6SID(m["ts6-sid"]) c.TS6SID = TS6SID(m["ts6-sid"])
} }
if sid != "" {
c.TS6SID = TS6SID(sid)
}
c.AdminEmail = m["admin-email"] c.AdminEmail = m["admin-email"]

23
main.go
View File

@@ -22,6 +22,8 @@ import (
// I put everything global to a server in an instance of struct rather than // I put everything global to a server in an instance of struct rather than
// have global variables. // have global variables.
type Catbox struct { type Catbox struct {
Args *Args
// ConfigFile is the path to the config file. // ConfigFile is the path to the config file.
ConfigFile string ConfigFile string
@@ -212,7 +214,7 @@ func main() {
os.Args[0], err) os.Args[0], err)
} }
cb, err := newCatbox(args.ConfigFile) cb, err := newCatbox(args)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -242,9 +244,10 @@ func main() {
log.Printf("Server shutdown cleanly.") log.Printf("Server shutdown cleanly.")
} }
func newCatbox(configFile string) (*Catbox, error) { func newCatbox(args *Args) (*Catbox, error) {
cb := Catbox{ cb := Catbox{
ConfigFile: configFile, Args: args,
ConfigFile: args.ConfigFile,
LocalClients: make(map[uint64]*LocalClient), LocalClients: make(map[uint64]*LocalClient),
LocalUsers: make(map[uint64]*LocalUser), LocalUsers: make(map[uint64]*LocalUser),
LocalServers: make(map[uint64]*LocalServer), LocalServers: make(map[uint64]*LocalServer),
@@ -262,7 +265,11 @@ func newCatbox(configFile string) (*Catbox, error) {
ToServerChan: make(chan Event), ToServerChan: make(chan Event),
} }
cfg, err := checkAndParseConfig(configFile) cfg, err := checkAndParseConfig(
args.ConfigFile,
args.ServerName,
args.SID,
)
if err != nil { if err != nil {
return nil, fmt.Errorf("configuration problem: %s", err) return nil, fmt.Errorf("configuration problem: %s", err)
} }
@@ -413,7 +420,7 @@ func (cb *Catbox) start(listenFD int) error {
} }
}() }()
log.Printf("catbox started") log.Printf("catbox started (%s)", cb.Config.ServerName)
cb.eventLoop() cb.eventLoop()
// We don't need to drain any channels. None close that will have any // We don't need to drain any channels. None close that will have any
@@ -1485,7 +1492,11 @@ func (cb *Catbox) quitRemoteUser(u *User, message string) {
// //
// We could close listeners and open new ones. But nah. // We could close listeners and open new ones. But nah.
func (cb *Catbox) rehash(byUser *User) { func (cb *Catbox) rehash(byUser *User) {
cfg, err := checkAndParseConfig(cb.ConfigFile) cfg, err := checkAndParseConfig(
cb.ConfigFile,
cb.Args.ServerName,
cb.Args.SID,
)
if err != nil { if err != nil {
cb.noticeOpers(fmt.Sprintf("Rehash: Configuration problem: %s", err)) cb.noticeOpers(fmt.Sprintf("Rehash: Configuration problem: %s", err))
return return