diff --git a/client.go b/client.go index 1de35b1..f49db57 100644 --- a/client.go +++ b/client.go @@ -16,6 +16,7 @@ const HELP_TEXT string = `-> Available commands: /exit /help /list + /uptime /nick $NAME /whois $NAME ` @@ -133,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 71b221a..b053bd5 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