/*
goircd -- minimalistic simple Internet Relay Chat (IRC) server
-Copyright (C) 2014 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2014-2020 Sergey Matveev <stargrave@stargrave.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
package main
import (
"io/ioutil"
"log"
"net"
- "os"
- "os/signal"
"path"
"path/filepath"
"strings"
- "syscall"
)
var (
logdir = flag.String("logdir", "", "Absolute path to directory for logs")
statedir = flag.String("statedir", "", "Absolute path to directory for states")
passwords = flag.String("passwords", "", "Optional path to passwords file")
-
- tlsBind = flag.String("tlsbind", "", "TLS address to bind to")
- tlsPEM = flag.String("tlspem", "", "Path to TLS certificat+key PEM file")
-
- verbose = flag.Bool("v", false, "Enable verbose logging.")
+ tlsBind = flag.String("tlsbind", "", "TLS address to bind to")
+ tlsPEM = flag.String("tlspem", "", "Path to TLS certificat+key PEM file")
+ verbose = flag.Bool("v", false, "Enable verbose logging.")
)
-func listenerLoop(sock net.Listener, events chan<- ClientEvent) {
+func listenerLoop(sock net.Listener, events chan ClientEvent) {
for {
conn, err := sock.Accept()
if err != nil {
log.Println("Error during accepting connection", err)
continue
}
- client := NewClient(*hostname, conn)
+ client := NewClient(conn)
go client.Processor(events)
}
}
events := make(chan ClientEvent)
log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)
- logSink := make(chan LogEvent)
if *logdir == "" {
// Dummy logger
go func() {
} else {
if !path.IsAbs(*logdir) {
log.Fatalln("Need absolute path for logdir")
- return
}
go Logger(*logdir, logSink)
log.Println(*logdir, "logger initialized")
}
- stateSink := make(chan StateEvent)
- daemon := NewDaemon(version, *hostname, *motd, logSink, stateSink)
- daemon.Verbose = *verbose
- log.Println("goircd "+daemon.version+" is starting")
+ log.Println("goircd " + version + " is starting")
if *statedir == "" {
// Dummy statekeeper
go func() {
if err != nil {
log.Fatalf("Can not read state %s: %v", state, err)
}
- room, _ := daemon.RoomRegister(path.Base(state))
+ room, _ := RoomRegister(path.Base(state))
contents := strings.Split(string(buf), "\n")
if len(contents) < 2 {
- log.Printf("State corrupted for %s: %q", room.name, contents)
+ log.Printf("State corrupted for %s: %q", *room.name, contents)
} else {
- room.topic = contents[0]
- room.key = contents[1]
- log.Println("Loaded state for room", room.name)
+ room.topic = &contents[0]
+ room.key = &contents[1]
+ log.Println("Loaded state for room", *room.name)
}
}
go StateKeeper(*statedir, stateSink)
log.Println(*statedir, "statekeeper initialized")
}
- if *passwords != "" {
- daemon.PasswordsRefresh()
- hups := make(chan os.Signal)
- signal.Notify(hups, syscall.SIGHUP)
- go func() {
- for {
- <-hups
- daemon.PasswordsRefresh()
- }
- }()
- }
-
-
if *bind != "" {
listener, err := net.Listen("tcp", *bind)
if err != nil {
log.Println("TLS listening on", *tlsBind)
go listenerLoop(listenerTLS, events)
}
-
- daemon.Processor(events)
+ Processor(events, make(chan struct{}))
}
func main() {