2017-06-08 01:53:08 +00:00
|
|
|
// AnonIRCd - Anonymous IRC daemon
|
2023-03-24 03:38:25 +00:00
|
|
|
// https://code.rocketnine.space/tslocum/anonircd
|
2016-09-02 05:54:54 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-08-26 05:50:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-12-02 07:50:51 +00:00
|
|
|
"fmt"
|
2017-06-08 07:39:01 +00:00
|
|
|
"log"
|
2016-09-16 01:25:52 +00:00
|
|
|
"math/rand"
|
2017-12-02 07:50:51 +00:00
|
|
|
"net/http"
|
2017-06-08 07:39:01 +00:00
|
|
|
_ "net/http/pprof"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2016-08-26 05:50:24 +00:00
|
|
|
"time"
|
2016-09-01 06:35:27 +00:00
|
|
|
|
2017-12-02 07:50:51 +00:00
|
|
|
"github.com/jessevdk/go-flags"
|
2017-12-11 11:01:24 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"gopkg.in/sorcix/irc.v2"
|
2016-09-02 05:54:54 +00:00
|
|
|
)
|
2016-08-26 05:50:24 +00:00
|
|
|
|
2017-12-02 07:50:51 +00:00
|
|
|
var prefixAnonIRC = irc.Prefix{Name: "AnonIRC"}
|
2017-12-15 01:39:18 +00:00
|
|
|
var prefixAnonymous = irc.Prefix{Name: "Anonymous", User: "Anon", Host: "IRC"}
|
2016-08-31 08:44:40 +00:00
|
|
|
|
2021-06-25 06:00:33 +00:00
|
|
|
const defaultMOTD = `
|
2016-08-31 08:44:40 +00:00
|
|
|
_|_| _|_|_| _|_|_| _|_|_|
|
|
|
|
_| _| _|_|_| _|_| _|_|_| _| _| _| _|
|
|
|
|
_|_|_|_| _| _| _| _| _| _| _| _|_|_| _|
|
|
|
|
_| _| _| _| _| _| _| _| _| _| _| _|
|
|
|
|
_| _| _| _| _|_| _| _| _|_|_| _| _| _|_|_|
|
|
|
|
`
|
2016-09-02 05:54:54 +00:00
|
|
|
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
2017-04-29 21:36:33 +00:00
|
|
|
const writebuffersize = 10
|
2016-08-26 05:50:24 +00:00
|
|
|
|
2017-12-02 07:50:51 +00:00
|
|
|
const (
|
2021-06-25 06:00:33 +00:00
|
|
|
channelLobby = "#"
|
|
|
|
channelServer = "&"
|
2017-12-02 07:50:51 +00:00
|
|
|
)
|
2016-09-07 00:38:11 +00:00
|
|
|
|
2017-12-02 07:50:51 +00:00
|
|
|
var debugMode = false
|
|
|
|
var verbose = false
|
2016-09-07 00:38:11 +00:00
|
|
|
|
2017-12-02 07:50:51 +00:00
|
|
|
func main() {
|
|
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
2016-09-07 00:38:11 +00:00
|
|
|
|
2017-12-02 07:50:51 +00:00
|
|
|
var opts struct {
|
|
|
|
ConfigFile string `short:"c" long:"config" description:"Configuration file"`
|
|
|
|
Debug int `short:"d" long:"debug" description:"Serve pprof data on specified port"`
|
|
|
|
BareLog bool `short:"b" long:"bare-log" description:"Don't add current date/time to log entries"`
|
|
|
|
Verbose bool `short:"v" long:"verbose" description:"Log verbosely"`
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := flags.Parse(&opts)
|
|
|
|
if err != nil {
|
2017-12-11 11:01:24 +00:00
|
|
|
log.Panicf("%+v", errors.Wrap(err, "failed to parse flags"))
|
2016-09-07 00:38:11 +00:00
|
|
|
}
|
|
|
|
|
2017-12-02 07:50:51 +00:00
|
|
|
if opts.Debug > 0 {
|
|
|
|
debugMode = true
|
|
|
|
log.Printf("WARNING: Running in debug mode. pprof data is available at http://localhost:%d/debug/pprof/", opts.Debug)
|
|
|
|
go http.ListenAndServe(fmt.Sprintf("localhost:%d", opts.Debug), nil)
|
2016-08-26 05:50:24 +00:00
|
|
|
}
|
|
|
|
|
2017-12-02 07:50:51 +00:00
|
|
|
if opts.BareLog {
|
|
|
|
log.SetFlags(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
verbose = opts.Verbose
|
2016-08-31 08:44:40 +00:00
|
|
|
|
2017-12-02 07:50:51 +00:00
|
|
|
s := NewServer(opts.ConfigFile)
|
|
|
|
err = s.loadConfig()
|
|
|
|
if err != nil {
|
2017-12-11 11:01:24 +00:00
|
|
|
log.Panicf("%+v", errors.Wrap(err, "failed to load configuration file"))
|
2017-12-02 07:50:51 +00:00
|
|
|
}
|
|
|
|
s.connectDatabase()
|
|
|
|
defer s.closeDatabase()
|
2016-09-16 06:12:25 +00:00
|
|
|
|
|
|
|
sighup := make(chan os.Signal, 1)
|
2019-07-10 07:53:57 +00:00
|
|
|
signal.Notify(sighup, syscall.SIGHUP)
|
2016-09-16 06:12:25 +00:00
|
|
|
go func() {
|
2019-07-10 07:53:57 +00:00
|
|
|
for {
|
|
|
|
<-sighup
|
|
|
|
err := s.reload()
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
2017-12-02 07:50:51 +00:00
|
|
|
}
|
2016-09-16 06:12:25 +00:00
|
|
|
}()
|
2016-09-02 07:49:36 +00:00
|
|
|
|
2017-12-02 07:50:51 +00:00
|
|
|
s.listen()
|
2016-09-01 06:35:27 +00:00
|
|
|
}
|