Implemented static MOTD message

This commit is contained in:
Harry Jeffery 2013-09-08 20:35:30 +01:00
parent 85cbc020a3
commit 44775cabdd
3 changed files with 14 additions and 4 deletions

View File

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

View File

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

View File

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