2013-08-23 01:03:37 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
2013-08-23 22:59:33 +00:00
|
|
|
"os"
|
|
|
|
"strings"
|
2013-08-23 01:03:37 +00:00
|
|
|
)
|
|
|
|
|
2013-08-24 07:36:57 +00:00
|
|
|
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.")
|
2013-09-08 21:56:43 +00:00
|
|
|
motdFile = flag.String("irc-motdfile", "", "File container motd to display to clients.")
|
2013-08-24 07:36:57 +00:00
|
|
|
)
|
2013-08-23 01:03:37 +00:00
|
|
|
|
2013-08-24 07:36:57 +00:00
|
|
|
func main() {
|
2013-08-23 22:59:33 +00:00
|
|
|
|
2013-08-23 01:03:37 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
2016-05-02 06:45:13 +00:00
|
|
|
log.Println("Starting server...")
|
2013-08-23 01:03:37 +00:00
|
|
|
|
|
|
|
//Init rosella itself
|
2013-08-23 14:23:27 +00:00
|
|
|
server := NewServer()
|
2013-08-23 01:03:37 +00:00
|
|
|
server.name = *serverName
|
2013-08-23 22:59:33 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2016-03-07 06:09:10 +00:00
|
|
|
f.Close()
|
2013-08-23 22:59:33 +00:00
|
|
|
|
|
|
|
lines := strings.Split(string(data[:size]), "\n")
|
|
|
|
for _, line := range lines {
|
2016-03-16 03:52:44 +00:00
|
|
|
if i := strings.IndexRune(line, '#'); i > -1 {
|
|
|
|
line = line[:i]
|
2013-08-23 22:59:33 +00:00
|
|
|
}
|
|
|
|
fields := strings.Fields(line)
|
|
|
|
|
|
|
|
if len(fields) == 2 {
|
2016-03-07 05:28:47 +00:00
|
|
|
server.operatorMap[fields[0]] = []byte(fields[1])
|
2013-08-23 22:59:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-24 07:36:57 +00:00
|
|
|
|
2013-09-08 21:56:43 +00:00
|
|
|
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)
|
|
|
|
}
|
2016-03-07 06:09:10 +00:00
|
|
|
f.Close()
|
2013-09-08 21:56:43 +00:00
|
|
|
|
|
|
|
server.motd = string(data[:size])
|
|
|
|
}
|
|
|
|
|
2016-05-02 06:45:51 +00:00
|
|
|
listener, err := net.Listen("tcp", *ircAddress)
|
2013-08-23 01:03:37 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Printf(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-03-07 06:23:53 +00:00
|
|
|
go server.Run()
|
|
|
|
|
2013-08-23 01:03:37 +00:00
|
|
|
log.Printf("Listening on %s", *ircAddress)
|
|
|
|
|
|
|
|
for {
|
2016-05-02 06:45:51 +00:00
|
|
|
conn, err := listener.Accept()
|
2013-08-23 01:03:37 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("Error accepting connection.")
|
|
|
|
log.Printf(err.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
server.HandleConnection(conn)
|
|
|
|
}
|
|
|
|
}
|