2013-08-23 01:03:37 +00:00
|
|
|
package main
|
|
|
|
|
2016-05-05 07:20:36 +00:00
|
|
|
/*
|
2017-05-28 01:45:05 +00:00
|
|
|
Copyright (C) 2016-2017 The `nmdc-ircfrontend' author(s)
|
2016-05-05 07:20:36 +00:00
|
|
|
Copyright (C) 2013 Harry Jeffery
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-08-23 01:03:37 +00:00
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
2016-05-02 06:51:53 +00:00
|
|
|
"net"
|
2016-11-29 06:55:50 +00:00
|
|
|
|
|
|
|
"code.ivysaur.me/libnmdc"
|
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
|
|
|
|
2016-05-08 02:33:21 +00:00
|
|
|
ircAddress := flag.String("bind", ":6667", "The address:port to bind to and listen for clients on")
|
2016-05-07 01:55:29 +00:00
|
|
|
dcAddress := flag.String("upstream", "127.0.0.1:411", "Upstream NMDC server")
|
2016-08-27 00:38:21 +00:00
|
|
|
serverName := flag.String("servername", APP_NAME, "Server name displayed to clients")
|
2016-05-09 06:48:07 +00:00
|
|
|
hubsec := flag.String("hubsecurity", "Hub-Security", "Nick used for administrative events")
|
2016-05-07 01:55:29 +00:00
|
|
|
verbose := flag.Bool("verbose", false, "Display debugging information")
|
2016-05-07 05:07:16 +00:00
|
|
|
autojoin := flag.Bool("autojoin", true, "Automatically join clients to the channel")
|
2016-08-27 02:20:27 +00:00
|
|
|
version := flag.Bool("version", false, "Display version and exit")
|
2016-05-09 06:48:07 +00:00
|
|
|
|
2013-08-23 01:03:37 +00:00
|
|
|
flag.Parse()
|
2013-09-08 21:56:43 +00:00
|
|
|
|
2016-08-27 02:20:27 +00:00
|
|
|
if *version {
|
|
|
|
log.Printf("%s version %s\n", APP_NAME, APP_VERSION)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-05-05 07:11:40 +00:00
|
|
|
log.Printf("Listening on '%s'...", *ircAddress)
|
2016-05-07 05:07:16 +00:00
|
|
|
if *autojoin {
|
|
|
|
log.Printf("Clients will be automatically joined to the channel.")
|
|
|
|
}
|
2016-05-05 07:11:40 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
2016-05-02 06:45:51 +00:00
|
|
|
conn, err := listener.Accept()
|
2013-08-23 01:03:37 +00:00
|
|
|
if err != nil {
|
2016-05-02 06:51:53 +00:00
|
|
|
log.Printf("Error accepting connection (%s)", err.Error())
|
2013-08-23 01:03:37 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2016-05-05 07:45:59 +00:00
|
|
|
// Spin up a worker for the new user.
|
2016-05-05 07:11:40 +00:00
|
|
|
server := NewServer(*serverName, libnmdc.HubAddress(*dcAddress), conn)
|
2016-05-07 01:55:29 +00:00
|
|
|
server.verbose = *verbose
|
2016-05-07 05:07:16 +00:00
|
|
|
server.autojoin = *autojoin
|
2016-05-09 06:48:07 +00:00
|
|
|
server.hubSecNick = *hubsec
|
2016-05-05 07:11:40 +00:00
|
|
|
go server.RunWorker()
|
2013-08-23 01:03:37 +00:00
|
|
|
}
|
|
|
|
}
|