2013-08-23 01:03:37 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2016-05-03 06:25:27 +00:00
|
|
|
"libnmdc"
|
2013-08-23 01:03:37 +00:00
|
|
|
"log"
|
2016-05-02 06:51:53 +00:00
|
|
|
"net"
|
2013-08-23 01:03:37 +00:00
|
|
|
)
|
|
|
|
|
2013-08-24 07:36:57 +00:00
|
|
|
var (
|
2016-05-02 06:51:53 +00:00
|
|
|
ircAddress = flag.String("bind", ":6697", "The address:port to bind to and listen for clients on")
|
|
|
|
dcAddress = flag.String("upstream", "127.0.0.1:411", "Upstream NMDC server")
|
|
|
|
serverName = flag.String("servername", "nmdc-ircfrontend", "Server name displayed 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-03 06:25:27 +00:00
|
|
|
if len(*serverName) == 0 {
|
2016-05-02 06:51:53 +00:00
|
|
|
log.Println("Please specify the -servername parameter.")
|
|
|
|
return
|
2013-09-08 21:56:43 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
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-03 06:25:27 +00:00
|
|
|
// Spin up an IRC server for the new user.
|
|
|
|
// The upstream connection doesn't get launched until we hear a nick
|
|
|
|
// from the irc client
|
|
|
|
|
|
|
|
server := NewServer(*serverName, libnmdc.HubAddress(*dcAddress))
|
|
|
|
go server.Run()
|
2013-08-23 01:03:37 +00:00
|
|
|
server.HandleConnection(conn)
|
|
|
|
}
|
|
|
|
}
|