package main import ( "flag" "log" "os" "strings" ) 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.") ) func main() { flag.Parse() 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]) } listener, err := net.Listen("tcp", *ircAddress) if err != nil { log.Printf(err.Error()) return } go server.Run() log.Printf("Listening on %s", *ircAddress) for { conn, err := listener.Accept() if err != nil { log.Printf("Error accepting connection.") log.Printf(err.Error()) continue } server.HandleConnection(conn) } }