From fb5c2152cb50c1a111504e7692ba6fbf05047d9c Mon Sep 17 00:00:00 2001 From: Ken Piper Date: Sat, 13 Dec 2014 17:42:43 -0500 Subject: [PATCH 1/3] Make highlights stand out Also re-fixed empty message check No longer re-seeding the RNG on each call for colors --- client.go | 2 +- cmd.go | 3 +++ colors.go | 8 +++++--- server.go | 13 +++++++++---- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/client.go b/client.go index 27cba79..e6749de 100644 --- a/client.go +++ b/client.go @@ -324,7 +324,7 @@ func (c *Client) handleShell(channel ssh.Channel) { c.Msg <- fmt.Sprintf("-> Rate limiting in effect.") continue } - if c.IsSilenced() || len(msg) > 1000 || len(msg) == 0 { + if c.IsSilenced() || len(msg) > 1000 || len(line) < 1 { c.SysMsg("Message rejected.") continue } diff --git a/cmd.go b/cmd.go index 628f471..29c5563 100644 --- a/cmd.go +++ b/cmd.go @@ -36,6 +36,9 @@ func main() { return } + // Initialize seed for random colors + RandomColorInit() + // Figure out the log level numVerbose := len(options.Verbose) if numVerbose > len(logLevels) { diff --git a/colors.go b/colors.go index c5e83df..1e85441 100644 --- a/colors.go +++ b/colors.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" "math/rand" - "time" + "time" ) const RESET string = "\033[0m" @@ -18,12 +18,10 @@ const INVERT string = "\033[7m" var colors = []string { "31", "32", "33", "34", "35", "36", "37", "91", "92", "93", "94", "95", "96", "97" } func RandomColor256() string { - rand.Seed(time.Now().UTC().UnixNano()) return fmt.Sprintf("38;05;%d", rand.Intn(256)) } func RandomColor() string { - rand.Seed(time.Now().UTC().UnixNano()) return colors[rand.Intn(len(colors))] } @@ -31,6 +29,10 @@ func ColorString(color string, msg string) string { return BOLD + "\033[" + color + "m" + msg + RESET } +func RandomColorInit() { + rand.Seed(time.Now().UTC().UnixNano()) +} + // Horrible hack to "continue" the previous string color and format // after a RESET has been encountered. // This is not HTML where you can just do a to resume your previous formatting! diff --git a/server.go b/server.go index 0d1ec71..a542212 100644 --- a/server.go +++ b/server.go @@ -89,10 +89,15 @@ func (s *Server) Broadcast(msg string, except *Client) { continue } - client.Send(msg) - if client.beepMe && strings.Contains(msg, client.Name) { - /* Add an ascii BEL to ding clients when they're mentioned */ - client.Send(BEEP) + if strings.Contains(msg, client.Name) { + // 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 { + tmpMsg[0] += BEEP + } + client.Send(strings.Join(tmpMsg, RESET + BOLD + "\033[31m") + RESET) + } else { + client.Send(msg) } } } From f57de43d73dcfe9b62a49330c7b64f94a0f5f4f1 Mon Sep 17 00:00:00 2001 From: Ken Piper Date: Sat, 13 Dec 2014 18:08:40 -0500 Subject: [PATCH 2/3] Allow escaping for messages beginning with / --- client.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client.go b/client.go index e6749de..639b5e4 100644 --- a/client.go +++ b/client.go @@ -164,6 +164,14 @@ func (c *Client) handleShell(channel ssh.Channel) { parts := strings.SplitN(line, " ", 3) isCmd := strings.HasPrefix(parts[0], "/") + // Allow for messages starting with / that aren't commands to be escaped + if len(line) > 2 { + if line[:3] == "/ /" { + line = line[2:] + isCmd = false + } + } + if isCmd { // TODO: Factor this out. switch parts[0] { From 13043e9a6093115aba7f1c295bf577e58e4ba873 Mon Sep 17 00:00:00 2001 From: Ken Piper Date: Sat, 13 Dec 2014 18:36:41 -0500 Subject: [PATCH 3/3] Removed escaped messages --- client.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/client.go b/client.go index 5063736..775b2fb 100644 --- a/client.go +++ b/client.go @@ -166,14 +166,6 @@ func (c *Client) handleShell(channel ssh.Channel) { parts := strings.SplitN(line, " ", 3) isCmd := strings.HasPrefix(parts[0], "/") - // Allow for messages starting with / that aren't commands to be escaped - if len(line) > 2 { - if line[:3] == "/ /" { - line = line[2:] - isCmd = false - } - } - if isCmd { // TODO: Factor this out. switch parts[0] {