Split rplMOTD into rplMOTDStart, rplMOTD and rplEndOfMOTD

This commit is contained in:
ed 2016-03-13 01:51:10 -05:00
parent f240730e9a
commit d7bbc2b475
3 changed files with 16 additions and 11 deletions

View File

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

View File

@ -126,7 +126,9 @@ const (
rplKick
rplInfo
rplVersion
rplMOTDStart
rplMOTD
rplEndOfMOTD
rplPong
errMoreArgs
errNoNick

View File

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