Merge pull request #5 from edjsu/split-rplMOTD

Split rplMOTD into rplMOTDStart, rplMOTD and rplEndOfMOTD
This commit is contained in:
Harry Jeffery 2016-03-14 12:36:43 +00:00
commit 9cbea548a3
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]) c.outputChan <- fmt.Sprintf(":%s 371 %s :%s", c.server.name, c.nick, args[0])
case rplVersion: case rplVersion:
c.outputChan <- fmt.Sprintf(":%s 351 %s %s", c.server.name, c.nick, args[0]) c.outputChan <- fmt.Sprintf(":%s 351 %s %s", c.server.name, c.nick, args[0])
case rplMOTD: case rplMOTDStart:
motd := args[0]
c.outputChan <- fmt.Sprintf(":%s 375 %s :- Message of the day - ", c.server.name, c.nick) 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) { case rplMOTD:
if size <= 80 { c.outputChan <- fmt.Sprintf(":%s 372 %s :- %s", c.server.name, c.nick, args[0])
c.outputChan <- fmt.Sprintf(":%s 372 %s :- %s", c.server.name, c.nick, motd) case rplEndOfMOTD:
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 :End of MOTD Command", c.server.name, c.nick) c.outputChan <- fmt.Sprintf(":%s 376 %s :End of MOTD Command", c.server.name, c.nick)
case rplPong: case rplPong:
c.outputChan <- fmt.Sprintf(":%s PONG %s %s", c.server.name, c.nick, c.server.name) c.outputChan <- fmt.Sprintf(":%s PONG %s %s", c.server.name, c.nick, c.server.name)

View File

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

View File

@ -53,7 +53,16 @@ func (s *Server) handleEvent(e Event) {
switch e.event { switch e.event {
case connected: case connected:
//Client 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: case disconnected:
//Client disconnected //Client disconnected
case command: case command: