From 69d56919f82d74adcf412db654b1ae5a3bce5e34 Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Fri, 12 Dec 2014 14:53:19 -0800 Subject: [PATCH] Share the op. --- client.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/client.go b/client.go index a82e1a3..c5ffe55 100644 --- a/client.go +++ b/client.go @@ -117,6 +117,7 @@ func (c *Client) handleShell(channel ssh.Channel) { isCmd := strings.HasPrefix(parts[0], "/") if isCmd { + // TODO: Factor this out. switch parts[0] { case "/exit": channel.Close() @@ -161,6 +162,21 @@ func (c *Client) handleShell(channel ssh.Channel) { c.Server.Broadcast(fmt.Sprintf("* %s was banned by %s", parts[1], c.Name), nil) } } + case "/op": + if !c.Server.IsOp(c) { + c.Msg <- fmt.Sprintf("-> You're not an admin.") + } else if len(parts) != 2 { + c.Msg <- fmt.Sprintf("-> Missing $NAME from: /op $NAME") + } else { + client := c.Server.Who(parts[1]) + if client == nil { + c.Msg <- fmt.Sprintf("-> No such name: %s", parts[1]) + } else { + fingerprint := client.Fingerprint() + client.Write(fmt.Sprintf("-> Made op by %s.", c.Name)) + c.Server.Op(fingerprint) + } + } default: c.Msg <- fmt.Sprintf("-> Invalid command: %s", line) }