3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

generalize server name/listen.

This commit is contained in:
Jeremy Latt 2012-04-17 22:11:35 -07:00
parent 96cb8240e6
commit 4cee1ef909
5 changed files with 16 additions and 6 deletions

View File

@ -1,10 +1,13 @@
package main package main
import ( import (
"flag"
"irc" "irc"
) )
func main() { func main() {
server := irc.NewServer() name := flag.String("name", "localhost", "A name for the server")
server.Listen(":6667") listen := flag.String("listen", ":6667", "interface to listen on")
flag.Parse()
irc.NewServer(*name).Listen(*listen)
} }

View File

@ -2,4 +2,4 @@
set -ex set -ex
export GOPATH="$(pwd)" export GOPATH="$(pwd)"
go install irc go install irc
go run ergonomadic.go go run ergonomadic.go "$@"

View File

@ -1,6 +1,7 @@
package irc package irc
import ( import (
"fmt"
"net" "net"
"strings" "strings"
) )
@ -64,3 +65,7 @@ func (c *Client) Hostname() string {
} }
return addr return addr
} }
func (c *Client) UserHost() string {
return fmt.Sprintf("%s!%s@%s", c.nick, c.username, c.Hostname())
}

View File

@ -64,8 +64,8 @@ func tryRegister(s *Server, c *Client) {
if (!c.registered && c.HasNick() && c.HasUser()) { if (!c.registered && c.HasNick() && c.HasUser()) {
c.registered = true c.registered = true
c.send <- ReplyWelcome(c) 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 <- ReplyCreated(c.Nick(), "2012/04/07")
c.send <- ReplyMyInfo(c.Nick(), "irc.jlatt.com") c.send <- ReplyMyInfo(c.Nick(), s.name)
} }
} }

View File

@ -6,6 +6,7 @@ import (
) )
type Server struct { type Server struct {
name string
ch chan *ClientMessage ch chan *ClientMessage
nicks map[string]*Client nicks map[string]*Client
} }
@ -15,8 +16,9 @@ type ClientMessage struct {
message Message message Message
} }
func NewServer() *Server { func NewServer(name string) *Server {
server := new(Server) server := new(Server)
server.name = name
server.ch = make(chan *ClientMessage) server.ch = make(chan *ClientMessage)
server.nicks = make(map[string]*Client) server.nicks = make(map[string]*Client)
go server.Receive() go server.Receive()