From 7634d0b170df6bfda41f32e8c66bb75f6144bf69 Mon Sep 17 00:00:00 2001 From: Ken Piper Date: Mon, 15 Dec 2014 01:21:40 -0500 Subject: [PATCH 1/3] Make highlighting optional for broadcasts ...And beeping on broadcasts, too --- client.go | 10 +++++----- server.go | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/client.go b/client.go index 1168893..acc7cdf 100644 --- a/client.go +++ b/client.go @@ -233,7 +233,7 @@ func (c *Client) handleShell(channel ssh.Channel) { if c.IsSilenced() || len(msg) > 1000 { c.SysMsg("Message rejected.") } else { - c.Server.Broadcast(msg, nil) + c.Server.Broadcast(msg, nil, false) } case "/nick": if len(parts) == 2 { @@ -280,7 +280,7 @@ func (c *Client) handleShell(channel ssh.Channel) { client.SysMsg("Banned by %s.", c.ColoredName()) c.Server.Ban(fingerprint, nil) client.Conn.Close() - c.Server.Broadcast(fmt.Sprintf("* %s was banned by %s", parts[1], c.ColoredName()), nil) + c.Server.Broadcast(fmt.Sprintf("* %s was banned by %s", parts[1], c.ColoredName()), nil, true) } } case "/op": @@ -310,7 +310,7 @@ func (c *Client) handleShell(channel ssh.Channel) { } else { client.SysMsg("Kicked by %s.", c.ColoredName()) client.Conn.Close() - c.Server.Broadcast(fmt.Sprintf("* %s was kicked by %s", parts[1], c.ColoredName()), nil) + c.Server.Broadcast(fmt.Sprintf("* %s was kicked by %s", parts[1], c.ColoredName()), nil, true) } } case "/silence": @@ -347,7 +347,7 @@ func (c *Client) handleShell(channel ssh.Channel) { } // Shutdown after 5 seconds go func() { - c.Server.Broadcast(ColorString("31", msg), nil) + c.Server.Broadcast(ColorString("31", msg), nil, true) time.Sleep(time.Second * 5) c.Server.Stop() }() @@ -422,7 +422,7 @@ func (c *Client) handleShell(channel ssh.Channel) { c.SysMsg("Message rejected.") continue } - c.Server.Broadcast(msg, c) + c.Server.Broadcast(msg, c, true) c.lastTX = time.Now() } diff --git a/server.go b/server.go index ef2cb82..b629688 100644 --- a/server.go +++ b/server.go @@ -91,11 +91,11 @@ func (s *Server) Len() int { // SysMsg broadcasts the given message to everyone func (s *Server) SysMsg(msg string, args ...interface{}) { - s.Broadcast(ContinuousFormat(systemMessageFormat, " * "+fmt.Sprintf(msg, args...)), nil) + s.Broadcast(ContinuousFormat(systemMessageFormat, " * "+fmt.Sprintf(msg, args...)), nil, false) } // Broadcast broadcasts the given message to everyone except for the given client -func (s *Server) Broadcast(msg string, except *Client) { +func (s *Server) Broadcast(msg string, except *Client, canHighlight bool) { logger.Debugf("Broadcast to %d: %s", s.Len(), msg) s.history.Add(msg) @@ -104,7 +104,7 @@ func (s *Server) Broadcast(msg string, except *Client) { continue } - if strings.Contains(msg, client.Name) { + if strings.Contains(msg, client.Name) && canHighlight { // Turn message red if client's name is mentioned, and send BEL if they have enabled beeping tmpMsg := strings.Split(msg, Reset) if client.beepMe { @@ -150,8 +150,8 @@ func (s *Server) MotdBroadcast(client *Client) { if s.motd == "" { return } - s.Broadcast(ContinuousFormat(systemMessageFormat, fmt.Sprintf(" * New MOTD set by %s.", client.ColoredName())), client) - s.Broadcast(s.motd, client) + s.Broadcast(ContinuousFormat(systemMessageFormat, fmt.Sprintf(" * New MOTD set by %s.", client.ColoredName())), client, false) + s.Broadcast(s.motd, client, false) } // Add adds the client to the list of clients @@ -174,7 +174,7 @@ func (s *Server) Add(client *Client) { num := len(s.clients) s.Unlock() - s.Broadcast(ContinuousFormat(systemMessageFormat, fmt.Sprintf(" * %s joined. (Total connected: %d)", client.ColoredName(), num)), client) + s.Broadcast(ContinuousFormat(systemMessageFormat, fmt.Sprintf(" * %s joined. (Total connected: %d)", client.ColoredName(), num)), client, false) } // Remove removes the given client from the list of clients From 64e0dbc5c47a0924628c2dfd2e9861b26c89c455 Mon Sep 17 00:00:00 2001 From: Ken Piper Date: Mon, 15 Dec 2014 20:25:10 -0500 Subject: [PATCH 2/3] Revert 7634d0b170df6bfda41f32e8c66bb75f6144bf69 --- client.go | 8 ++++---- server.go | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/client.go b/client.go index 438b151..f3d886b 100644 --- a/client.go +++ b/client.go @@ -293,7 +293,7 @@ func (c *Client) handleShell(channel ssh.Channel) { client.SysMsg("Banned by %s.", c.ColoredName()) c.Server.Ban(fingerprint, nil) client.Conn.Close() - c.Server.Broadcast(fmt.Sprintf("* %s was banned by %s", parts[1], c.ColoredName()), nil, true) + c.Server.Broadcast(fmt.Sprintf("* %s was banned by %s", parts[1], c.ColoredName()), nil) } } case "/op": @@ -323,7 +323,7 @@ func (c *Client) handleShell(channel ssh.Channel) { } else { client.SysMsg("Kicked by %s.", c.ColoredName()) client.Conn.Close() - c.Server.Broadcast(fmt.Sprintf("* %s was kicked by %s", parts[1], c.ColoredName()), nil, true) + c.Server.Broadcast(fmt.Sprintf("* %s was kicked by %s", parts[1], c.ColoredName()), nil) } } case "/silence": @@ -360,7 +360,7 @@ func (c *Client) handleShell(channel ssh.Channel) { } // Shutdown after 5 seconds go func() { - c.Server.Broadcast(ColorString("31", msg), nil, true) + c.Server.Broadcast(ColorString("31", msg), nil) time.Sleep(time.Second * 5) c.Server.Stop() }() @@ -435,7 +435,7 @@ func (c *Client) handleShell(channel ssh.Channel) { c.SysMsg("Message rejected.") continue } - c.Server.Broadcast(msg, c, true) + c.Server.Broadcast(msg, c) c.lastTX = time.Now() } diff --git a/server.go b/server.go index 2f39941..bd4230e 100644 --- a/server.go +++ b/server.go @@ -92,11 +92,11 @@ func (s *Server) Len() int { // SysMsg broadcasts the given message to everyone func (s *Server) SysMsg(msg string, args ...interface{}) { - s.Broadcast(ContinuousFormat(systemMessageFormat, " * "+fmt.Sprintf(msg, args...)), nil, false) + s.Broadcast(ContinuousFormat(systemMessageFormat, " * "+fmt.Sprintf(msg, args...)), nil) } // Broadcast broadcasts the given message to everyone except for the given client -func (s *Server) Broadcast(msg string, except *Client, canHighlight bool) { +func (s *Server) Broadcast(msg string, except *Client) { logger.Debugf("Broadcast to %d: %s", s.Len(), msg) s.history.Add(msg) @@ -105,7 +105,7 @@ func (s *Server) Broadcast(msg string, except *Client, canHighlight bool) { continue } - if strings.Contains(msg, client.Name) && canHighlight { + if strings.Contains(msg, client.Name) { // Turn message red if client's name is mentioned, and send BEL if they have enabled beeping personalMsg := strings.Replace(msg, client.Name, highlightFormat+client.Name+Reset, -1) if client.beepMe { @@ -151,8 +151,8 @@ func (s *Server) MotdBroadcast(client *Client) { if s.motd == "" { return } - s.Broadcast(ContinuousFormat(systemMessageFormat, fmt.Sprintf(" * New MOTD set by %s.", client.ColoredName())), client, false) - s.Broadcast(s.motd, client, false) + s.Broadcast(ContinuousFormat(systemMessageFormat, fmt.Sprintf(" * New MOTD set by %s.", client.ColoredName())), client) + s.Broadcast(s.motd, client) } // Add adds the client to the list of clients From 1afe84925de95b4d3668dc78fd689e17f88b4ac0 Mon Sep 17 00:00:00 2001 From: Ken Piper Date: Mon, 15 Dec 2014 20:31:13 -0500 Subject: [PATCH 3/3] Make /whois ignore any trailing spaces/text --- client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client.go b/client.go index f3d886b..1a6a795 100644 --- a/client.go +++ b/client.go @@ -255,7 +255,7 @@ func (c *Client) handleShell(channel ssh.Channel) { c.SysMsg("Missing $NAME from: /nick $NAME") } case "/whois": - if len(parts) == 2 { + if len(parts) >= 2 { client := c.Server.Who(parts[1]) if client != nil { version := reStripText.ReplaceAllString(string(client.Conn.ClientVersion()), "")