From d392cd379d38a7ca4c9cd5ac8d4e4141ca445e54 Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 26 Nov 2017 17:53:14 +1300 Subject: [PATCH] adc: handle user parts --HG-- branch : adc --- AdcProtocol.go | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/AdcProtocol.go b/AdcProtocol.go index 56b42aa..e079df9 100644 --- a/AdcProtocol.go +++ b/AdcProtocol.go @@ -229,14 +229,36 @@ func (this *AdcProtocol) ProcessCommand(msg string) { case "IQUI": // Error message from the hub // IQUI V3M6 DI1 MSNick\staken,\splease\spick\sanother\sone TL-1 - flags, err := this.parts2flags(parts[1:]) + if len(parts) < 2 { + this.malformed(parts) + return + } + + sid := parts[1] + + flags, err := this.parts2flags(parts[2:]) if err != nil { return } - if msg, ok := flags["MS"]; ok { - this.hc.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_HUB, Message: "The hub is closing our connection because: " + this.unescape(msg)}) + + if sid == this.sid { + if msg, ok := flags["MS"]; ok { + this.hc.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_HUB, Message: "The hub is closing our connection because: " + this.unescape(msg)}) + } else { + this.hc.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_HUB, Message: "The hub is closing our connection"}) + } } else { - this.hc.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_HUB, Message: "The hub is closing our connection"}) + this.hc.usersMut.Lock() + defer this.hc.usersMut.Unlock() + otherSidNick, ok := this.hc.userSIDs[sid] + if ok { + delete(this.hc.userSIDs, sid) + delete(this.hc.users, otherSidNick) + this.hc.processEvent(HubEvent{EventType: EVENT_USER_PART, Nick: otherSidNick}) + } else { + // ?? + this.logError(fmt.Errorf("An unknown user quit the hub (SID=%s)", sid)) + } } case "BMSG":