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
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)

21
args.go
View File

@@ -11,12 +11,27 @@ import (
type Args struct {
ConfigFile string
ListenFD int
ServerName string
SID string
}
func getArgs() *Args {
configFile := flag.String("conf", "", "Configuration file.")
fd := flag.Int("listen-fd", -1,
"File descriptor with listening port to use (optional).")
fd := flag.Int(
"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()
@@ -35,6 +50,8 @@ func getArgs() *Args {
return &Args{
ConfigFile: configPath,
ListenFD: *fd,
ServerName: *serverName,
SID: *sid,
}
}

View File

@@ -78,7 +78,11 @@ type UserConfig struct {
// We parse some values into alternate representations.
//
// 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)
if err != nil {
return nil, err
@@ -113,6 +117,9 @@ func checkAndParseConfig(file string) (*Config, error) {
if m["server-name"] != "" {
c.ServerName = m["server-name"]
}
if serverName != "" {
c.ServerName = serverName
}
c.ServerInfo = "IRC"
if m["server-info"] != "" {
@@ -216,6 +223,9 @@ func checkAndParseConfig(file string) (*Config, error) {
}
c.TS6SID = TS6SID(m["ts6-sid"])
}
if sid != "" {
c.TS6SID = TS6SID(sid)
}
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
// have global variables.
type Catbox struct {
Args *Args
// ConfigFile is the path to the config file.
ConfigFile string
@@ -212,7 +214,7 @@ func main() {
os.Args[0], err)
}
cb, err := newCatbox(args.ConfigFile)
cb, err := newCatbox(args)
if err != nil {
log.Fatal(err)
}
@@ -242,9 +244,10 @@ func main() {
log.Printf("Server shutdown cleanly.")
}
func newCatbox(configFile string) (*Catbox, error) {
func newCatbox(args *Args) (*Catbox, error) {
cb := Catbox{
ConfigFile: configFile,
Args: args,
ConfigFile: args.ConfigFile,
LocalClients: make(map[uint64]*LocalClient),
LocalUsers: make(map[uint64]*LocalUser),
LocalServers: make(map[uint64]*LocalServer),
@@ -262,7 +265,11 @@ func newCatbox(configFile string) (*Catbox, error) {
ToServerChan: make(chan Event),
}
cfg, err := checkAndParseConfig(configFile)
cfg, err := checkAndParseConfig(
args.ConfigFile,
args.ServerName,
args.SID,
)
if err != nil {
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()
// 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.
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 {
cb.noticeOpers(fmt.Sprintf("Rehash: Configuration problem: %s", err))
return