3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-13 07:29:30 +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
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 File

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

View File

@ -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 File

@ -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 File

@ -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()