From 5f201e0f203bbb91596be7e1379bbe094353acab Mon Sep 17 00:00:00 2001 From: Pavel Zaitsev Date: Tue, 7 Jul 2020 23:24:25 -0400 Subject: [PATCH 1/2] now if both are ops it will be reflected in output of whois command --- host.go | 3 +-- identity.go | 11 ++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/host.go b/host.go index 8973229..16595c3 100644 --- a/host.go +++ b/host.go @@ -407,12 +407,11 @@ func (h *Host) InitCommands(c *chat.Commands) { if !ok { return errors.New("user not found") } - id := target.Identifier.(*Identity) var whois string switch room.IsOp(msg.From()) { case true: - whois = id.WhoisAdmin() + whois = id.WhoisAdmin(room, h) case false: whois = id.Whois() } diff --git a/identity.go b/identity.go index 0817792..ed74d62 100644 --- a/identity.go +++ b/identity.go @@ -4,6 +4,7 @@ import ( "net" "time" + "github.com/shazow/ssh-chat/chat" "github.com/shazow/ssh-chat/chat/message" "github.com/shazow/ssh-chat/internal/humantime" "github.com/shazow/ssh-chat/internal/sanitize" @@ -59,13 +60,21 @@ func (i Identity) Whois() string { } // WhoisAdmin returns a whois description for admin users. -func (i Identity) WhoisAdmin() string { +func (i Identity) WhoisAdmin(room *chat.Room, host *Host) string { ip, _, _ := net.SplitHostPort(i.RemoteAddr().String()) fingerprint := "(no public key)" if i.PublicKey() != nil { fingerprint = sshd.Fingerprint(i.PublicKey()) } + + isOp := "" + user, ok := host.GetUser(i.id) + if ok && room.IsOp(user) { + isOp = " > Op" + message.Newline + } + return "name: " + i.Name() + message.Newline + + isOp + " > ip: " + ip + message.Newline + " > fingerprint: " + fingerprint + message.Newline + " > client: " + sanitize.Data(string(i.ClientVersion()), 64) + message.Newline + From b6a8763f3be65e436c394e58ef9e1cbbc2954179 Mon Sep 17 00:00:00 2001 From: Pavel Zaitsev Date: Wed, 15 Jul 2020 00:32:53 -0400 Subject: [PATCH 2/2] updated in line with comments in PR * reduce change footprint to parameter list * moved Op flag display to last line as to not break bots --- host.go | 2 +- identity.go | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/host.go b/host.go index 16595c3..1c615c0 100644 --- a/host.go +++ b/host.go @@ -411,7 +411,7 @@ func (h *Host) InitCommands(c *chat.Commands) { var whois string switch room.IsOp(msg.From()) { case true: - whois = id.WhoisAdmin(room, h) + whois = id.WhoisAdmin(room) case false: whois = id.Whois() } diff --git a/identity.go b/identity.go index ed74d62..93df4e5 100644 --- a/identity.go +++ b/identity.go @@ -60,7 +60,7 @@ func (i Identity) Whois() string { } // WhoisAdmin returns a whois description for admin users. -func (i Identity) WhoisAdmin(room *chat.Room, host *Host) string { +func (i Identity) WhoisAdmin(room *chat.Room) string { ip, _, _ := net.SplitHostPort(i.RemoteAddr().String()) fingerprint := "(no public key)" if i.PublicKey() != nil { @@ -68,15 +68,14 @@ func (i Identity) WhoisAdmin(room *chat.Room, host *Host) string { } isOp := "" - user, ok := host.GetUser(i.id) - if ok && room.IsOp(user) { - isOp = " > Op" + message.Newline + if member, ok := room.MemberByID(i.ID()); ok && room.IsOp(member.User) { + isOp = message.Newline + " > op: true" } return "name: " + i.Name() + message.Newline + - isOp + " > ip: " + ip + message.Newline + " > fingerprint: " + fingerprint + message.Newline + " > client: " + sanitize.Data(string(i.ClientVersion()), 64) + message.Newline + - " > joined: " + humantime.Since(i.created) + " ago" + " > joined: " + humantime.Since(i.created) + " ago" + + isOp }