Ability to show server's version
This commit is contained in:
parent
a939b027fd
commit
f46c678ce0
4
Makefile
Normal file
4
Makefile
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
LDFLAGS="-X main.version \"$(shell git describe --tags)\""
|
||||||
|
|
||||||
|
goircd:
|
||||||
|
go install -ldflags $(LDFLAGS) $(BUILD_FLAGS)
|
2
README
2
README
@ -40,7 +40,7 @@ SUPPORTED IRC COMMANDS
|
|||||||
* PASS/NICK/USER during registration workflow
|
* PASS/NICK/USER during registration workflow
|
||||||
* PING/PONGs
|
* PING/PONGs
|
||||||
* NOTICE/PRIVMSG
|
* NOTICE/PRIVMSG
|
||||||
* MOTD, LUSERS, WHO, WHOIS, QUIT
|
* MOTD, LUSERS, WHO, WHOIS, VERSION, QUIT
|
||||||
* LIST, JOIN, TOPIC, +k/-k channel MODE
|
* LIST, JOIN, TOPIC, +k/-k channel MODE
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
|
15
daemon.go
15
daemon.go
@ -43,6 +43,7 @@ var passwordsRefreshLock sync.Mutex
|
|||||||
|
|
||||||
type Daemon struct {
|
type Daemon struct {
|
||||||
Verbose bool
|
Verbose bool
|
||||||
|
version string
|
||||||
hostname string
|
hostname string
|
||||||
motd string
|
motd string
|
||||||
clients map[*Client]bool
|
clients map[*Client]bool
|
||||||
@ -55,8 +56,8 @@ type Daemon struct {
|
|||||||
passwords map[string]string
|
passwords map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDaemon(hostname, motd string, logSink chan<- LogEvent, stateSink chan<- StateEvent) *Daemon {
|
func NewDaemon(version, hostname, motd string, logSink chan<- LogEvent, stateSink chan<- StateEvent) *Daemon {
|
||||||
daemon := Daemon{hostname: hostname, motd: motd}
|
daemon := Daemon{version: version, hostname: hostname, motd: motd}
|
||||||
daemon.clients = make(map[*Client]bool)
|
daemon.clients = make(map[*Client]bool)
|
||||||
daemon.clientAliveness = make(map[*Client]*ClientAlivenessState)
|
daemon.clientAliveness = make(map[*Client]*ClientAlivenessState)
|
||||||
daemon.rooms = make(map[string]*Room)
|
daemon.rooms = make(map[string]*Room)
|
||||||
@ -205,7 +206,7 @@ func (daemon *Daemon) ClientRegister(client *Client, command string, cols []stri
|
|||||||
passwordsRefreshLock.Unlock()
|
passwordsRefreshLock.Unlock()
|
||||||
client.registered = true
|
client.registered = true
|
||||||
client.ReplyNicknamed("001", "Hi, welcome to IRC")
|
client.ReplyNicknamed("001", "Hi, welcome to IRC")
|
||||||
client.ReplyNicknamed("002", "Your host is "+daemon.hostname+", running goircd")
|
client.ReplyNicknamed("002", "Your host is "+daemon.hostname+", running goircd "+daemon.version)
|
||||||
client.ReplyNicknamed("003", "This server was created sometime")
|
client.ReplyNicknamed("003", "This server was created sometime")
|
||||||
client.ReplyNicknamed("004", daemon.hostname+" goircd o o")
|
client.ReplyNicknamed("004", daemon.hostname+" goircd o o")
|
||||||
daemon.SendLusers(client)
|
daemon.SendLusers(client)
|
||||||
@ -458,6 +459,14 @@ func (daemon *Daemon) Processor(events <-chan ClientEvent) {
|
|||||||
cols := strings.Split(cols[1], " ")
|
cols := strings.Split(cols[1], " ")
|
||||||
nicknames := strings.Split(cols[len(cols)-1], ",")
|
nicknames := strings.Split(cols[len(cols)-1], ",")
|
||||||
daemon.SendWhois(client, nicknames)
|
daemon.SendWhois(client, nicknames)
|
||||||
|
case "VERSION":
|
||||||
|
var debug string
|
||||||
|
if daemon.Verbose {
|
||||||
|
debug = "debug"
|
||||||
|
} else {
|
||||||
|
debug = ""
|
||||||
|
}
|
||||||
|
client.ReplyNicknamed("351", fmt.Sprintf("%s.%s %s :", daemon.version, debug, daemon.hostname))
|
||||||
default:
|
default:
|
||||||
client.ReplyNicknamed("421", command, "Unknown command")
|
client.ReplyNicknamed("421", command, "Unknown command")
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestRegistrationWorkflow(t *testing.T) {
|
func TestRegistrationWorkflow(t *testing.T) {
|
||||||
daemon := NewDaemon("foohost", "", nil, nil)
|
daemon := NewDaemon("ver1", "foohost", "", nil, nil)
|
||||||
events := make(chan ClientEvent)
|
events := make(chan ClientEvent)
|
||||||
go daemon.Processor(events)
|
go daemon.Processor(events)
|
||||||
conn := NewTestingConn()
|
conn := NewTestingConn()
|
||||||
@ -120,7 +120,7 @@ func TestMotd(t *testing.T) {
|
|||||||
|
|
||||||
conn := NewTestingConn()
|
conn := NewTestingConn()
|
||||||
client := NewClient("foohost", conn)
|
client := NewClient("foohost", conn)
|
||||||
daemon := NewDaemon("foohost", fd.Name(), nil, nil)
|
daemon := NewDaemon("ver1", "foohost", fd.Name(), nil, nil)
|
||||||
|
|
||||||
daemon.SendMotd(client)
|
daemon.SendMotd(client)
|
||||||
if r := <-conn.outbound; !strings.HasPrefix(r, ":foohost 375") {
|
if r := <-conn.outbound; !strings.HasPrefix(r, ":foohost 375") {
|
||||||
|
@ -32,6 +32,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
version string
|
||||||
hostname = flag.String("hostname", "localhost", "Hostname")
|
hostname = flag.String("hostname", "localhost", "Hostname")
|
||||||
bind = flag.String("bind", ":6667", "Address to bind to")
|
bind = flag.String("bind", ":6667", "Address to bind to")
|
||||||
motd = flag.String("motd", "", "Path to MOTD file")
|
motd = flag.String("motd", "", "Path to MOTD file")
|
||||||
@ -67,7 +68,7 @@ func Run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stateSink := make(chan StateEvent)
|
stateSink := make(chan StateEvent)
|
||||||
daemon := NewDaemon(*hostname, *motd, logSink, stateSink)
|
daemon := NewDaemon(version, *hostname, *motd, logSink, stateSink)
|
||||||
daemon.Verbose = *verbose
|
daemon.Verbose = *verbose
|
||||||
if *statedir == "" {
|
if *statedir == "" {
|
||||||
// Dummy statekeeper
|
// Dummy statekeeper
|
||||||
@ -120,7 +121,7 @@ func Run() {
|
|||||||
log.Fatalf("Can not listen on %s: %v", *bind, err)
|
log.Fatalf("Can not listen on %s: %v", *bind, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Println("Listening on", *bind)
|
log.Println("goircd "+daemon.version+" listening on", *bind)
|
||||||
|
|
||||||
if *passwords != "" {
|
if *passwords != "" {
|
||||||
daemon.PasswordsRefresh()
|
daemon.PasswordsRefresh()
|
||||||
|
@ -26,7 +26,7 @@ func notEnoughParams(t *testing.T, c *TestingConn) {
|
|||||||
func TestTwoUsers(t *testing.T) {
|
func TestTwoUsers(t *testing.T) {
|
||||||
logSink := make(chan LogEvent, 8)
|
logSink := make(chan LogEvent, 8)
|
||||||
stateSink := make(chan StateEvent, 8)
|
stateSink := make(chan StateEvent, 8)
|
||||||
daemon := NewDaemon("foohost", "", logSink, stateSink)
|
daemon := NewDaemon("ver1", "foohost", "", logSink, stateSink)
|
||||||
events := make(chan ClientEvent)
|
events := make(chan ClientEvent)
|
||||||
go daemon.Processor(events)
|
go daemon.Processor(events)
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ func TestTwoUsers(t *testing.T) {
|
|||||||
func TestJoin(t *testing.T) {
|
func TestJoin(t *testing.T) {
|
||||||
logSink := make(chan LogEvent, 8)
|
logSink := make(chan LogEvent, 8)
|
||||||
stateSink := make(chan StateEvent, 8)
|
stateSink := make(chan StateEvent, 8)
|
||||||
daemon := NewDaemon("foohost", "", logSink, stateSink)
|
daemon := NewDaemon("ver1", "foohost", "", logSink, stateSink)
|
||||||
events := make(chan ClientEvent)
|
events := make(chan ClientEvent)
|
||||||
go daemon.Processor(events)
|
go daemon.Processor(events)
|
||||||
conn := NewTestingConn()
|
conn := NewTestingConn()
|
||||||
|
Loading…
Reference in New Issue
Block a user