From ebaddea85920ef768623ae01cfbe409ae99291bd Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Tue, 27 Aug 2013 13:44:42 +0100 Subject: [PATCH] Check for redundant join/parts --- client.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index d045b3e..16c2821 100644 --- a/client.go +++ b/client.go @@ -61,7 +61,14 @@ func (c *Client) joinChannel(channelName string) { c.server.channelMap[channelKey] = channel } - channel.clientMap[strings.ToLower(c.nick)] = c + nickKey := strings.ToLower(c.nick) + + if _, inChannel := channel.clientMap[nickKey]; inChannel { + //Client is already in the channel, do nothing + return + } + + channel.clientMap[nickKey] = c c.channelMap[channelKey] = channel for _, client := range channel.clientMap { @@ -89,6 +96,11 @@ func (c *Client) partChannel(channelName string) { return } + if _, inChannel := channel.clientMap[strings.ToLower(c.nick)]; inChannel == false { + //Client isn't in this channel, do nothing + return + } + //Notify clients of the part for _, client := range channel.clientMap { client.reply(rplPart, c.nick, channelName)