Adding a quiet mode to ignore system messages.

This commit is contained in:
Nick Presta 2015-01-02 22:05:16 -05:00
parent 814c373a21
commit d643d61ccc
2 changed files with 28 additions and 10 deletions

View File

@ -29,7 +29,8 @@ const (
/whois $NAME - Display information about another connected user. /whois $NAME - Display information about another connected user.
/msg $NAME $MESSAGE - Sends a private message to a user. /msg $NAME $MESSAGE - Sends a private message to a user.
/motd - Prints the Message of the Day. /motd - Prints the Message of the Day.
/theme [color|mono] - Set client theme.` /theme [color|mono] - Set client theme.
/quiet - Toggles "quiet" mode. Hide join/quit messages.`
// OpHelpText is the additional text returned by /help if the client is an Op // OpHelpText is the additional text returned by /help if the client is an Op
OpHelpText string = `Available operator commands: OpHelpText string = `Available operator commands:
@ -72,6 +73,7 @@ type Client struct {
lastTX time.Time lastTX time.Time
beepMe bool beepMe bool
colorMe bool colorMe bool
quietMode bool
closed bool closed bool
sync.RWMutex sync.RWMutex
} }
@ -87,6 +89,7 @@ func NewClient(server *Server, conn *ssh.ServerConn) *Client {
ready: make(chan struct{}, 1), ready: make(chan struct{}, 1),
lastTX: time.Now(), lastTX: time.Now(),
colorMe: true, colorMe: true,
quietMode: false,
} }
} }
@ -171,6 +174,11 @@ func (c *Client) Rename(name string) {
c.term.SetPrompt(fmt.Sprintf("[%s] ", prompt)) c.term.SetPrompt(fmt.Sprintf("[%s] ", prompt))
} }
// ToggleQuietMode toggles whether or not a client is in quiet mode
func (c *Client) ToggleQuietMode() {
c.quietMode = !c.quietMode
}
// Fingerprint returns the fingerprint // Fingerprint returns the fingerprint
func (c *Client) Fingerprint() string { func (c *Client) Fingerprint() string {
if c.Conn.Permissions == nil { if c.Conn.Permissions == nil {
@ -414,7 +422,13 @@ func (c *Client) handleShell(channel ssh.Channel) {
// Rename to reset prompt // Rename to reset prompt
c.Rename(c.Name) c.Rename(c.Name)
} }
case "/quiet":
c.ToggleQuietMode()
if c.quietMode {
c.SysMsg("Quiet mode toggled ON")
} else {
c.SysMsg("Quiet mode toggled OFF")
}
case "/whitelist": /* whitelist a fingerprint */ case "/whitelist": /* whitelist a fingerprint */
if !c.Server.IsOp(c) { if !c.Server.IsOp(c) {
c.SysMsg("You're not an admin.") c.SysMsg("You're not an admin.")

View File

@ -128,6 +128,10 @@ func (s *Server) Broadcast(msg string, except *Client) {
} }
client.Send(personalMsg) client.Send(personalMsg)
} else { } else {
if client.quietMode && strings.HasPrefix(msg, systemMessageFormat) {
continue
}
client.Send(msg) client.Send(msg)
} }
} }