2 goircd -- minimalistic simple Internet Relay Chat (IRC) server
3 Copyright (C) 2014 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
32 hostname = flag.String("hostname", "localhost", "Hostname")
33 bind = flag.String("bind", ":6667", "Address to bind to")
34 motd = flag.String("motd", "", "Path to MOTD file")
35 logdir = flag.String("logdir", "", "Absolute path to directory for logs")
36 statedir = flag.String("statedir", "", "Absolute path to directory for states")
41 events := make(chan ClientEvent)
42 log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)
44 log_sink := make(chan LogEvent)
53 if !path.IsAbs(*logdir) {
54 log.Fatalln("Need absolute path for logdir")
57 go Logger(*logdir, log_sink)
58 log.Println(*logdir, "logger initialized")
61 state_sink := make(chan StateEvent)
62 daemon := NewDaemon(*hostname, *motd, log_sink, state_sink)
71 if !path.IsAbs(*statedir) {
72 log.Fatalln("Need absolute path for statedir")
74 states, err := filepath.Glob(*statedir + "/#*")
76 log.Fatalln("Can not read statedir", err)
78 for _, state := range states {
79 fd, err := os.Open(state)
81 log.Fatalln("Can not open state", state, err)
83 buf := make([]byte, 1024)
87 log.Fatalln("Can not read state", state, err)
89 room, _ := daemon.RoomRegister(path.Base(state))
90 buf = bytes.TrimRight(buf, "\x00")
91 contents := strings.Split(string(buf), "\n")
92 room.topic = contents[0]
93 room.key = contents[1]
94 log.Println("Loaded state for room", room.name)
96 go StateKeeper(*statedir, state_sink)
97 log.Println(*statedir, "statekeeper initialized")
100 listener, err := net.Listen("tcp", *bind)
102 log.Fatalln("Can not listen on ", *bind)
104 log.Println("Listening on", *bind)
106 go daemon.Processor(events)
108 conn, err := listener.Accept()
110 log.Println("Error during accepting connection", err)
113 client = NewClient(*hostname, conn)
114 go client.Processor(events)