diff --git a/main.go b/main.go index 0f7e142..ff4d22b 100644 --- a/main.go +++ b/main.go @@ -3,15 +3,13 @@ package main import ( "flag" "log" - "os" - "strings" + "net" ) var ( - ircAddress = flag.String("irc-address", ":6697", "The address:port to bind to and listen for clients on") - serverName = flag.String("irc-servername", "rosella", "Server name displayed to clients") - authFile = flag.String("irc-authfile", "", "File containing usernames and passwords of operators.") - motdFile = flag.String("irc-motdfile", "", "File container motd to display to clients.") + ircAddress = flag.String("bind", ":6697", "The address:port to bind to and listen for clients on") + dcAddress = flag.String("upstream", "127.0.0.1:411", "Upstream NMDC server") + serverName = flag.String("servername", "nmdc-ircfrontend", "Server name displayed to clients") ) func main() { @@ -20,53 +18,14 @@ func main() { log.Println("Starting server...") - //Init rosella itself server := NewServer() server.name = *serverName - if *authFile != "" { - log.Printf("Loading auth file: %q", *authFile) - - f, err := os.Open(*authFile) - if err != nil { - log.Fatal(err) - } - data := make([]byte, 1024) - size, err := f.Read(data) - if err != nil { - log.Fatal(err) - } - f.Close() - - lines := strings.Split(string(data[:size]), "\n") - for _, line := range lines { - if i := strings.IndexRune(line, '#'); i > -1 { - line = line[:i] - } - fields := strings.Fields(line) - - if len(fields) == 2 { - server.operatorMap[fields[0]] = []byte(fields[1]) - } - } - } - - if *motdFile != "" { - log.Printf("Loading motd file: %q", *motdFile) - - f, err := os.Open(*motdFile) - if err != nil { - log.Fatal(err) - } - data := make([]byte, 1024) - size, err := f.Read(data) - if err != nil { - log.Fatal(err) - } - f.Close() - - server.motd = string(data[:size]) + if len(server.name) == 0 { + log.Println("Please specify the -servername parameter.") + return } + server.motd = "Connected to " + *serverName listener, err := net.Listen("tcp", *ircAddress) if err != nil { @@ -81,8 +40,7 @@ func main() { for { conn, err := listener.Accept() if err != nil { - log.Printf("Error accepting connection.") - log.Printf(err.Error()) + log.Printf("Error accepting connection (%s)", err.Error()) continue } diff --git a/server.go b/server.go index 57388da..b4ce0bd 100644 --- a/server.go +++ b/server.go @@ -2,11 +2,12 @@ package main import ( "fmt" - "golang.org/x/crypto/bcrypt" "log" "net" "regexp" "strings" + + "golang.org/x/crypto/bcrypt" ) var ( @@ -16,11 +17,11 @@ var ( func NewServer() *Server { return &Server{eventChan: make(chan Event), - name: "rosella", + name: "", clientMap: make(map[string]*Client), channelMap: make(map[string]*Channel), operatorMap: make(map[string][]byte), - motd: "This server is running " + APP_DESCRIPTION, + motd: "", } }