diff --git a/ergonomadic.go b/ergonomadic.go index 698865c3..3567ea20 100644 --- a/ergonomadic.go +++ b/ergonomadic.go @@ -1,10 +1,13 @@ package main import ( + "flag" "irc" ) func main() { - server := irc.NewServer() - server.Listen(":6667") + name := flag.String("name", "localhost", "A name for the server") + listen := flag.String("listen", ":6667", "interface to listen on") + flag.Parse() + irc.NewServer(*name).Listen(*listen) } diff --git a/ergonomadic.sh b/ergonomadic.sh index 0303549d..93b8db6a 100755 --- a/ergonomadic.sh +++ b/ergonomadic.sh @@ -2,4 +2,4 @@ set -ex export GOPATH="$(pwd)" go install irc -go run ergonomadic.go +go run ergonomadic.go "$@" diff --git a/src/irc/client.go b/src/irc/client.go index d7246b03..85ad6284 100644 --- a/src/irc/client.go +++ b/src/irc/client.go @@ -1,6 +1,7 @@ package irc import ( + "fmt" "net" "strings" ) @@ -64,3 +65,7 @@ func (c *Client) Hostname() string { } return addr } + +func (c *Client) UserHost() string { + return fmt.Sprintf("%s!%s@%s", c.nick, c.username, c.Hostname()) +} diff --git a/src/irc/commands.go b/src/irc/commands.go index 57d72e2a..2a993711 100644 --- a/src/irc/commands.go +++ b/src/irc/commands.go @@ -64,8 +64,8 @@ func tryRegister(s *Server, c *Client) { if (!c.registered && c.HasNick() && c.HasUser()) { c.registered = true c.send <- ReplyWelcome(c) - c.send <- ReplyYourHost(c.Nick(), "irc.jlatt.com") + c.send <- ReplyYourHost(c.Nick(), s.name) c.send <- ReplyCreated(c.Nick(), "2012/04/07") - c.send <- ReplyMyInfo(c.Nick(), "irc.jlatt.com") + c.send <- ReplyMyInfo(c.Nick(), s.name) } } diff --git a/src/irc/server.go b/src/irc/server.go index 6188ce0d..991d9b43 100644 --- a/src/irc/server.go +++ b/src/irc/server.go @@ -6,6 +6,7 @@ import ( ) type Server struct { + name string ch chan *ClientMessage nicks map[string]*Client } @@ -15,8 +16,9 @@ type ClientMessage struct { message Message } -func NewServer() *Server { +func NewServer(name string) *Server { server := new(Server) + server.name = name server.ch = make(chan *ClientMessage) server.nicks = make(map[string]*Client) go server.Receive()