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
8 changed files with 63 additions and 28 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,2 @@
catbox
*.swp *.swp
/catbox
/test-net

View File

@@ -1,14 +1,10 @@
# 1.13.0 (2019-07-08) # 1.12.0
* Include Go version in version string.
# 1.12.0 (2019-07-06)
* Update dependencies.
* 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.
* Stop logging client reads/writes. * 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"]

View File

@@ -176,6 +176,8 @@ func (c *LocalClient) readLoop() {
break break
} }
log.Printf("Client %s: Read: %s", c, strings.TrimSuffix(buf, "\r\n"))
message, err := irc.ParseMessage(buf) message, err := irc.ParseMessage(buf)
if err != nil { if err != nil {
c.Catbox.noticeOpers(fmt.Sprintf("Invalid message from client %s: %s", c, c.Catbox.noticeOpers(fmt.Sprintf("Invalid message from client %s: %s", c,
@@ -247,6 +249,8 @@ Loop:
c.Catbox.newEvent(Event{Type: DeadClientEvent, Client: c, Error: err}) c.Catbox.newEvent(Event{Type: DeadClientEvent, Client: c, Error: err})
break Loop break Loop
} }
log.Printf("Client %s: Sent: %s", c, strings.TrimSuffix(buf, "\r\n"))
case <-c.Catbox.ShutdownChan: case <-c.Catbox.ShutdownChan:
break Loop break Loop
} }
@@ -379,8 +383,7 @@ func (c *LocalClient) registerUser() {
lu.messageFromServer("002", []string{ lu.messageFromServer("002", []string{
fmt.Sprintf("Your host is %s, running version %s", fmt.Sprintf("Your host is %s, running version %s",
lu.Catbox.Config.ServerName, lu.Catbox.Config.ServerName,
lu.Catbox.version(), Version),
),
}) })
// 003 RPL_CREATED // 003 RPL_CREATED
@@ -393,7 +396,7 @@ func (c *LocalClient) registerUser() {
lu.messageFromServer("004", []string{ lu.messageFromServer("004", []string{
// It seems ambiguous if these are to be separate parameters. // It seems ambiguous if these are to be separate parameters.
lu.Catbox.Config.ServerName, lu.Catbox.Config.ServerName,
lu.Catbox.version(), Version,
// User modes we support. // User modes we support.
"ioC", "ioC",
// Channel modes we support. // Channel modes we support.

View File

@@ -2094,6 +2094,8 @@ func (u *LocalUser) versionCommand(m irc.Message) {
// Comments are free form. But I use similar to what ratbox does. See its doc // Comments are free form. But I use similar to what ratbox does. See its doc
// server-version-info. // server-version-info.
version := fmt.Sprintf("%s.", Version)
// H HUB, M IDLE_FROM_MSG, TS supports TS, 6 TS6, o TS only // H HUB, M IDLE_FROM_MSG, TS supports TS, 6 TS6, o TS only
comments := fmt.Sprintf("HM TS6o %s", string(u.Catbox.Config.TS6SID)) comments := fmt.Sprintf("HM TS6o %s", string(u.Catbox.Config.TS6SID))
@@ -2102,7 +2104,7 @@ func (u *LocalUser) versionCommand(m irc.Message) {
Command: "351", Command: "351",
Params: []string{ Params: []string{
u.User.DisplayNick, u.User.DisplayNick,
u.Catbox.version(), version,
u.Catbox.Config.ServerName, u.Catbox.Config.ServerName,
comments, comments,
}, },

26
main.go
View File

@@ -9,7 +9,6 @@ import (
"os" "os"
"os/signal" "os/signal"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
"sync" "sync"
"syscall" "syscall"
@@ -23,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
@@ -213,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)
} }
@@ -243,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),
@@ -263,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)
} }
@@ -414,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
@@ -1486,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
@@ -1706,5 +1716,3 @@ func sendMessages(messages []Message) {
m.Target.maybeQueueMessage(m.Message) m.Target.maybeQueueMessage(m.Message)
} }
} }
func (cb *Catbox) version() string { return Version + "-" + runtime.Version() }

View File

@@ -2,7 +2,7 @@ package main
// CreatedDate is the date we're built. This would be nice to generate // CreatedDate is the date we're built. This would be nice to generate
// dynamically, but I don't want to complicate the build. // dynamically, but I don't want to complicate the build.
const CreatedDate = "2019-07-08" const CreatedDate = "2019-01-01"
// Version is our version. // Version is our version.
const Version = "catbox-1.13.0" const Version = "catbox-1.11.0"