From 4415109174924333e23c5f8abcfe4ece4ed8d4c5 Mon Sep 17 00:00:00 2001 From: mappu Date: Thu, 9 Feb 2017 19:28:37 +1300 Subject: [PATCH] support UserIP2 extension --- HubConnection.go | 30 +++++++++++++++++++++++++++++- UserInfo.go | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/HubConnection.go b/HubConnection.go index 7d12d93..754509d 100644 --- a/HubConnection.go +++ b/HubConnection.go @@ -245,7 +245,35 @@ func (this *HubConnection) processProtocolMessage(message string) { } case "$UserIP": - // TODO + this.userLock.Lock() + + pairs := strings.Split(commandParts[1], "$$") + notifyOfUpdate := make([]string, 0, len(pairs)) + + nextIPPair: + for _, pair := range pairs { + parts := strings.SplitN(pair, " ", 2) + ip2nick := parts[0] + ip2addr := parts[1] + + uinfo, ok := this.users[ip2nick] + if !ok { + this.processEvent(HubEvent{EventType: EVENT_DEBUG_MESSAGE, Message: "Recieved IP '" + ip2addr + "' for unknown user '" + ip2nick + "'"}) + continue nextIPPair + } + + if uinfo.IPAddress != ip2addr { + uinfo.IPAddress = ip2addr + notifyOfUpdate = append(notifyOfUpdate, ip2nick) + this.users[ip2nick] = uinfo + } + } + + this.userLock.Unlock() + + for _, nick := range notifyOfUpdate { + this.processEvent(HubEvent{EventType: EVENT_USER_UPDATED_INFO, Nick: nick}) + } case "$ForceMove": this.Hco.Address = HubAddress(commandParts[1]) diff --git a/UserInfo.go b/UserInfo.go index 453a000..15e3e66 100644 --- a/UserInfo.go +++ b/UserInfo.go @@ -24,6 +24,7 @@ type UserInfo struct { HubsRegistered uint64 HubsOperator uint64 IsOperator bool + IPAddress string } var rx_myinfo *regexp.Regexp