From d7bbc2b47535f8125b64914ffff29c781f5f3d8a Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 13 Mar 2016 01:51:10 -0500 Subject: [PATCH] Split rplMOTD into rplMOTDStart, rplMOTD and rplEndOfMOTD --- client.go | 14 ++++---------- rosella.go | 2 ++ server.go | 11 ++++++++++- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/client.go b/client.go index 5cc7adb..6dfcd5a 100644 --- a/client.go +++ b/client.go @@ -183,17 +183,11 @@ func (c *Client) reply(code replyCode, args ...string) { c.outputChan <- fmt.Sprintf(":%s 371 %s :%s", c.server.name, c.nick, args[0]) case rplVersion: c.outputChan <- fmt.Sprintf(":%s 351 %s %s", c.server.name, c.nick, args[0]) - case rplMOTD: - motd := args[0] + case rplMOTDStart: c.outputChan <- fmt.Sprintf(":%s 375 %s :- Message of the day - ", c.server.name, c.nick) - 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:] - } + case rplMOTD: + c.outputChan <- fmt.Sprintf(":%s 372 %s :- %s", c.server.name, c.nick, args[0]) + case rplEndOfMOTD: c.outputChan <- fmt.Sprintf(":%s 376 %s :End of MOTD Command", c.server.name, c.nick) case rplPong: c.outputChan <- fmt.Sprintf(":%s PONG %s %s", c.server.name, c.nick, c.server.name) diff --git a/rosella.go b/rosella.go index df3ea5b..38ffb0d 100644 --- a/rosella.go +++ b/rosella.go @@ -126,7 +126,9 @@ const ( rplKick rplInfo rplVersion + rplMOTDStart rplMOTD + rplEndOfMOTD rplPong errMoreArgs errNoNick diff --git a/server.go b/server.go index ec2dc1f..daced2e 100644 --- a/server.go +++ b/server.go @@ -53,7 +53,16 @@ func (s *Server) handleEvent(e Event) { switch e.event { case connected: //Client connected - e.client.reply(rplMOTD, s.motd) + e.client.reply(rplMOTDStart) + motd := s.motd + for len(motd) > 80 { + e.client.reply(rplMOTD, motd[:80]) + motd = motd[80:] + } + if len(motd) > 0 { + e.client.reply(rplMOTD, motd) + } + e.client.reply(rplEndOfMOTD) case disconnected: //Client disconnected case command: