From 0a8a7a62ce28a8de945c2145673c3dd73719f797 Mon Sep 17 00:00:00 2001 From: mappu Date: Sat, 24 Mar 2018 13:21:49 +1300 Subject: [PATCH] re-add SayInfo() support, for changing tag/share-size on an active connection --- AdcProtocol.go | 6 +++++- AutodetectProtocol.go | 10 ++++++++++ HubConnection.go | 4 ++++ NmdcProtocol.go | 6 +++--- Protocol.go | 2 ++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/AdcProtocol.go b/AdcProtocol.go index fe4bdfa..d423ee8 100644 --- a/AdcProtocol.go +++ b/AdcProtocol.go @@ -135,7 +135,7 @@ func (this *AdcProtocol) ProcessCommand(msg string) { this.sid = parts[1] // State transition IDENTIFY --> VERIFY and send our own info - this.hc.SayRaw("BINF " + this.escape(this.sid) + " " + this.ourINFO(true) + "\n") + this.SayInfo() this.state = adcStateVerify case "IINF": @@ -468,6 +468,10 @@ func (this *AdcProtocol) ourINFO(includePid bool) string { return ret[1:] } +func (this *AdcProtocol) SayInfo() { + this.hc.SayRaw("BINF " + this.escape(this.sid) + " " + this.ourINFO(true) + "\n") +} + func (this *AdcProtocol) parts2flags(parts []string) (map[string]string, error) { flags := make(map[string]string, len(parts)) for _, flag := range parts { diff --git a/AutodetectProtocol.go b/AutodetectProtocol.go index 8ab97da..3c188f6 100644 --- a/AutodetectProtocol.go +++ b/AutodetectProtocol.go @@ -69,6 +69,16 @@ func (this *AutodetectProtocol) SayPrivate(user, message string) { this.realProto.SayPrivate(user, message) } +func (this *AutodetectProtocol) SayInfo() { + this.realProtoMut.Lock() + defer this.realProtoMut.Unlock() + + if this.realProto == nil { + this.realProto = NewNmdcProtocol(this.hc) + } + this.realProto.SayInfo() +} + func (this *AutodetectProtocol) ProtoMessageSeparator() string { this.realProtoMut.Lock() defer this.realProtoMut.Unlock() diff --git a/HubConnection.go b/HubConnection.go index 5780cdc..e1dd29a 100644 --- a/HubConnection.go +++ b/HubConnection.go @@ -49,6 +49,10 @@ func (this *HubConnection) SayPrivate(recipient string, message string) { this.proto.SayPrivate(recipient, message) } +func (this *HubConnection) SayInfo() { + this.proto.SayInfo() +} + func (this *HubConnection) UserExists(nick string) bool { this.usersMut.RLock() defer this.usersMut.RUnlock() diff --git a/NmdcProtocol.go b/NmdcProtocol.go index 42dce25..1e708cb 100644 --- a/NmdcProtocol.go +++ b/NmdcProtocol.go @@ -81,7 +81,7 @@ func (this *NmdcProtocol) ProcessCommand(message string) { if commandParts[1] == this.hc.Hco.Self.Nick && !this.sentOurHello { this.hc.SayRaw("$Version 1,0091|") this.hc.SayRaw("$GetNickList|") - this.sayInfo() + this.SayInfo() this.sentOurHello = true } else { @@ -253,7 +253,7 @@ func (this *NmdcProtocol) ProcessCommand(message string) { // Need to log in. // If the hub supports QuickList, we can skip one network roundtrip if _, ok := this.supports["QuickList"]; ok { - this.sayInfo() + this.SayInfo() this.hc.SayRaw("$GetNickList|") } else { this.hc.SayRaw("$ValidateNick " + this.escape(this.hc.Hco.Self.Nick) + "|") @@ -300,7 +300,7 @@ func (this *NmdcProtocol) SayPrivate(recipient, message string) { this.hc.SayRaw("$To: " + recipient + " From: " + this.hc.Hco.Self.Nick + " $<" + this.hc.Hco.Self.Nick + "> " + this.escape(message) + "|") } -func (this *NmdcProtocol) sayInfo() { +func (this *NmdcProtocol) SayInfo() { this.hc.SayRaw(this.getUserMyINFO(this.hc.Hco.Self) + "|") } diff --git a/Protocol.go b/Protocol.go index e587a11..416c398 100644 --- a/Protocol.go +++ b/Protocol.go @@ -7,6 +7,8 @@ type Protocol interface { SayPrivate(user, message string) + SayInfo() + ProtoMessageSeparator() string }