1
0
mirror of https://github.com/shazow/ssh-chat.git synced 2025-04-23 12:10:30 +03:00

Merge pull request from shazow/master

Merge to latest
This commit is contained in:
Sam Mauldin 2014-12-13 14:37:58 -06:00
commit c28e5b38b1
2 changed files with 26 additions and 1 deletions

@ -20,10 +20,12 @@ const HELP_TEXT string = SYSTEM_MESSAGE_FORMAT + `-> Available commands:
/nick $NAME - Rename yourself to a new name
/whois $NAME - Display information about another connected user
/msg $NAME $MESSAGE
/beep - Enable BEL notifications on mention.
` + RESET
const OP_HELP_TEXT string = SYSTEM_MESSAGE_FORMAT + `-> Available operator commands:
/ban $NAME - Banish a user from the chat
/kick $NAME - Kick em' out.
/op $NAME - Promote a user to server operator
/silence $NAME - Revoke a user's ability to speak
`
@ -54,6 +56,7 @@ type Client struct {
termHeight int
silencedUntil time.Time
lastTX time.Time
beepMe bool
}
func NewClient(server *Server, conn *ssh.ServerConn) *Client {
@ -160,6 +163,13 @@ func (c *Client) handleShell(channel ssh.Channel) {
c.WriteLines(strings.Split(ABOUT_TEXT, "\n"))
case "/uptime":
c.Write(c.Server.Uptime())
case "/beep":
c.beepMe = !c.beepMe
if c.beepMe {
c.SysMsg("I'll beep you good.")
} else {
c.SysMsg("No more beeps. :(")
}
case "/me":
me := strings.TrimLeft(line, "/me")
if me == "" {
@ -227,6 +237,21 @@ func (c *Client) handleShell(channel ssh.Channel) {
c.Server.Op(fingerprint)
}
}
case "/kick":
if !c.Server.IsOp(c) {
c.SysMsg("You're not an admin.")
} else if len(parts) != 2 {
c.SysMsg("Missing $NAME from: /kick $NAME")
} else {
client := c.Server.Who(parts[1])
if client == nil {
c.SysMsg("No such name: %s", parts[1])
} else {
client.SysMsg2("Kicked by %s.", c.ColoredName())
client.Conn.Close()
c.Server.Broadcast(fmt.Sprintf("* %s was kicked by %s", parts[1], c.ColoredName()), nil)
}
}
case "/silence":
if !c.Server.IsOp(c) {
c.SysMsg("You're not an admin.")

@ -94,7 +94,7 @@ func (s *Server) Broadcast(msg string, except *Client) {
continue
}
/* Add an ascii BEL to ding clients when they're mentioned */
if strings.HasPrefix(msg, fmt.Sprintf("%s:", client.Name)) {
if client.beepMe && strings.Contains(msg, client.Name) {
client.Msg <- msg + BEEP
} else {
client.Msg <- msg