Added /uptime command support

This commit is contained in:
aquilax 2014-12-13 11:14:53 +01:00
parent 857dcd0a14
commit e62755322d
2 changed files with 9 additions and 1 deletions

View File

@ -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 == "" {

View File

@ -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