/PART now accepts a reason from the client

This commit is contained in:
Harry Jeffery 2013-08-29 21:23:52 +01:00
parent e0073e55fd
commit 4760297287
2 changed files with 8 additions and 6 deletions

View File

@ -103,7 +103,7 @@ func (c *Client) joinChannel(channelName string) {
c.reply(rplNames, channelName, strings.Join(nicks, " ")) c.reply(rplNames, channelName, strings.Join(nicks, " "))
} }
func (c *Client) partChannel(channelName string) { func (c *Client) partChannel(channelName, reason string) {
channelKey := strings.ToLower(channelName) channelKey := strings.ToLower(channelName)
channel, exists := c.server.channelMap[channelKey] channel, exists := c.server.channelMap[channelKey]
if exists == false { if exists == false {
@ -117,7 +117,7 @@ func (c *Client) partChannel(channelName string) {
//Notify clients of the part //Notify clients of the part
for _, client := range channel.clientMap { for _, client := range channel.clientMap {
client.reply(rplPart, c.nick, channelName) client.reply(rplPart, c.nick, channelName, reason)
} }
delete(channel.clientMap, strings.ToLower(c.nick)) delete(channel.clientMap, strings.ToLower(c.nick))
@ -144,7 +144,7 @@ func (c *Client) reply(code replyCode, args ...string) {
case rplJoin: case rplJoin:
c.outputChan <- fmt.Sprintf(":%s JOIN %s", args[0], args[1]) c.outputChan <- fmt.Sprintf(":%s JOIN %s", args[0], args[1])
case rplPart: case rplPart:
c.outputChan <- fmt.Sprintf(":%s PART %s", args[0], args[1]) c.outputChan <- fmt.Sprintf(":%s PART %s %s", args[0], args[1], args[2])
case rplTopic: case rplTopic:
c.outputChan <- fmt.Sprintf(":%s 332 %s %s :%s", c.server.name, c.nick, args[0], args[1]) c.outputChan <- fmt.Sprintf(":%s 332 %s %s :%s", c.server.name, c.nick, args[0], args[1])
case rplNoTopic: case rplNoTopic:
@ -207,7 +207,7 @@ func (c *Client) clientThread() {
defer func() { defer func() {
//Part from all channels //Part from all channels
for channelName := range c.channelMap { for channelName := range c.channelMap {
c.partChannel(channelName) c.partChannel(channelName, "Disconnecting")
} }
delete(c.server.clientMap, strings.ToLower(c.nick)) delete(c.server.clientMap, strings.ToLower(c.nick))

View File

@ -112,7 +112,7 @@ func (s *Server) handleEvent(e Event) {
if args[0] == "0" { if args[0] == "0" {
//Quit all channels //Quit all channels
for channel := range e.client.channelMap { for channel := range e.client.channelMap {
e.client.partChannel(channel) e.client.partChannel(channel, "Disconnecting")
} }
return return
} }
@ -136,11 +136,13 @@ func (s *Server) handleEvent(e Event) {
return return
} }
reason := strings.Join(args[1:], " ")
channels := strings.Split(args[0], ",") channels := strings.Split(args[0], ",")
for _, channel := range channels { for _, channel := range channels {
//Part the channel if it's valid //Part the channel if it's valid
if channelRegexp.Match([]byte(channel)) { if channelRegexp.Match([]byte(channel)) {
e.client.partChannel(channel) e.client.partChannel(channel, reason)
} }
} }