Permalink
Browse files

generalize server name/listen.

  • Loading branch information...
1 parent 96cb824 commit 4cee1ef909ce236a40535b89ddceb492b7074801 @jlatt committed Apr 18, 2012
Showing with 16 additions and 6 deletions.
  1. +5 −2 ergonomadic.go
  2. +1 −1 ergonomadic.sh
  3. +5 −0 src/irc/client.go
  4. +2 −2 src/irc/commands.go
  5. +3 −1 src/irc/server.go
View
@@ -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)
}
View
@@ -2,4 +2,4 @@
set -ex
export GOPATH="$(pwd)"
go install irc
-go run ergonomadic.go
+go run ergonomadic.go "$@"
View
@@ -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())
+}
View
@@ -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)
}
}
View
@@ -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()

0 comments on commit 4cee1ef

Please sign in to comment.