strip authfile, simplify motd, rename arguments and make the servername argument mandatory

--HG--
branch : nmdc-ircfrontend
This commit is contained in:
. 2016-05-02 18:51:53 +12:00
parent 468b9fe126
commit f0cbe04d88
2 changed files with 13 additions and 54 deletions

60
main.go
View File

@ -3,15 +3,13 @@ package main
import ( import (
"flag" "flag"
"log" "log"
"os" "net"
"strings"
) )
var ( var (
ircAddress = flag.String("irc-address", ":6697", "The address:port to bind to and listen for clients on") ircAddress = flag.String("bind", ":6697", "The address:port to bind to and listen for clients on")
serverName = flag.String("irc-servername", "rosella", "Server name displayed to clients") dcAddress = flag.String("upstream", "127.0.0.1:411", "Upstream NMDC server")
authFile = flag.String("irc-authfile", "", "File containing usernames and passwords of operators.") serverName = flag.String("servername", "nmdc-ircfrontend", "Server name displayed to clients")
motdFile = flag.String("irc-motdfile", "", "File container motd to display to clients.")
) )
func main() { func main() {
@ -20,53 +18,14 @@ func main() {
log.Println("Starting server...") log.Println("Starting server...")
//Init rosella itself
server := NewServer() server := NewServer()
server.name = *serverName server.name = *serverName
if *authFile != "" { if len(server.name) == 0 {
log.Printf("Loading auth file: %q", *authFile) log.Println("Please specify the -servername parameter.")
return
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])
} }
server.motd = "Connected to " + *serverName
listener, err := net.Listen("tcp", *ircAddress) listener, err := net.Listen("tcp", *ircAddress)
if err != nil { if err != nil {
@ -81,8 +40,7 @@ func main() {
for { for {
conn, err := listener.Accept() conn, err := listener.Accept()
if err != nil { if err != nil {
log.Printf("Error accepting connection.") log.Printf("Error accepting connection (%s)", err.Error())
log.Printf(err.Error())
continue continue
} }

View File

@ -2,11 +2,12 @@ package main
import ( import (
"fmt" "fmt"
"golang.org/x/crypto/bcrypt"
"log" "log"
"net" "net"
"regexp" "regexp"
"strings" "strings"
"golang.org/x/crypto/bcrypt"
) )
var ( var (
@ -16,11 +17,11 @@ var (
func NewServer() *Server { func NewServer() *Server {
return &Server{eventChan: make(chan Event), return &Server{eventChan: make(chan Event),
name: "rosella", name: "",
clientMap: make(map[string]*Client), clientMap: make(map[string]*Client),
channelMap: make(map[string]*Channel), channelMap: make(map[string]*Channel),
operatorMap: make(map[string][]byte), operatorMap: make(map[string][]byte),
motd: "This server is running " + APP_DESCRIPTION, motd: "",
} }
} }