From 44775cabdd19312753689d13eb43f074bbefc03b Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Sun, 8 Sep 2013 20:35:30 +0100 Subject: [PATCH] Implemented static MOTD message --- client.go | 13 ++++++++++--- rosella.go | 1 + server.go | 4 +++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index 8432fc0..b7bbf69 100644 --- a/client.go +++ b/client.go @@ -176,10 +176,15 @@ func (c *Client) reply(code replyCode, args ...string) { case rplVersion: c.outputChan <- fmt.Sprintf(":%s 351 %s %s", c.server.name, c.nick, args[0]) case rplMOTD: + motd := args[0] c.outputChan <- fmt.Sprintf(":%s 375 %s", c.server.name, c.nick) - for i := 0; i < len(args[0]); i += 80 { - line := args[0][i : i+80] - c.outputChan <- fmt.Sprintf(":%s 372 %s %s", c.server.name, c.nick, line) + for size := len(motd); size > 0; size = len(motd) { + if size <= 80 { + c.outputChan <- fmt.Sprintf(":%s 372 %s :- %s", c.server.name, c.nick, motd) + break + } + c.outputChan <- fmt.Sprintf(":%s 372 %s :- %s", c.server.name, c.nick, motd[:80]) + motd = motd[80:] } c.outputChan <- fmt.Sprintf(":%s 376 %s", c.server.name, c.nick) case errMoreArgs: @@ -212,6 +217,8 @@ func (c *Client) clientThread() { writeSignalChan := make(chan signalCode, 3) writeChan := make(chan string, 100) + c.server.eventChan <- Event{client: c, event: connected} + go c.readThread(readSignalChan) go c.writeThread(writeSignalChan, writeChan) diff --git a/rosella.go b/rosella.go index 356530d..7235053 100644 --- a/rosella.go +++ b/rosella.go @@ -13,6 +13,7 @@ type Server struct { clientMap map[string]*Client //Map of nicks → clients channelMap map[string]*Channel //Map of channel names → channels operatorMap map[string]string //Map of usernames → SHA1 hashed passwords + motd string } type Client struct { diff --git a/server.go b/server.go index 96f5ecd..01d08a3 100644 --- a/server.go +++ b/server.go @@ -20,7 +20,8 @@ func NewServer() *Server { name: "rosella", clientMap: make(map[string]*Client), channelMap: make(map[string]*Channel), - operatorMap: make(map[string]string)} + operatorMap: make(map[string]string), + motd: "Welcome to IRC. Powered by Rosella."} } func (s *Server) Run() { @@ -52,6 +53,7 @@ func (s *Server) handleEvent(e Event) { switch e.event { case connected: //Client connected + e.client.reply(rplMOTD, s.motd) case disconnected: //Client disconnected case command: