From e62755322d9a276f61f392abb5806d451fade20e Mon Sep 17 00:00:00 2001 From: aquilax Date: Sat, 13 Dec 2014 11:14:53 +0100 Subject: [PATCH] Added /uptime command support --- client.go | 4 +++- server.go | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 33bd4f7..b730ce5 100644 --- a/client.go +++ b/client.go @@ -56,7 +56,7 @@ func NewClient(server *Server, conn *ssh.ServerConn) *Client { } func (c *Client) ColoredName() string { - return ColorString(c.Color, c.Name) + return ColorString(c.Color, c.Name) } func (c *Client) Write(msg string) { @@ -134,6 +134,8 @@ func (c *Client) handleShell(channel ssh.Channel) { c.WriteLines(strings.Split(HELP_TEXT, "\n")) case "/about": c.WriteLines(strings.Split(ABOUT_TEXT, "\n")) + case "/uptime": + c.Write(c.Server.Uptime()) case "/me": me := strings.TrimLeft(line, "/me") if me == "" { diff --git a/server.go b/server.go index abdd61e..b0cf29f 100644 --- a/server.go +++ b/server.go @@ -30,6 +30,7 @@ type Server struct { admins map[string]struct{} // fingerprint lookup bannedPk map[string]*time.Time // fingerprint lookup bannedIp map[net.Addr]*time.Time + started time.Time } func NewServer(privateKey []byte) (*Server, error) { @@ -46,6 +47,7 @@ func NewServer(privateKey []byte) (*Server, error) { admins: map[string]struct{}{}, bannedPk: map[string]*time.Time{}, bannedIp: map[net.Addr]*time.Time{}, + started: time.Now(), } config := ssh.ServerConfig{ @@ -182,6 +184,10 @@ func (s *Server) Op(fingerprint string) { s.lock.Unlock() } +func (s *Server) Uptime() string { + return time.Now().Sub(s.started).String() +} + func (s *Server) IsOp(client *Client) bool { _, r := s.admins[client.Fingerprint()] return r