support UserIP2 extension

This commit is contained in:
mappu 2017-02-09 19:28:37 +13:00
parent 0adc13ddfa
commit 4415109174
2 changed files with 30 additions and 1 deletions

View File

@ -245,7 +245,35 @@ func (this *HubConnection) processProtocolMessage(message string) {
} }
case "$UserIP": 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": case "$ForceMove":
this.Hco.Address = HubAddress(commandParts[1]) this.Hco.Address = HubAddress(commandParts[1])

View File

@ -24,6 +24,7 @@ type UserInfo struct {
HubsRegistered uint64 HubsRegistered uint64
HubsOperator uint64 HubsOperator uint64
IsOperator bool IsOperator bool
IPAddress string
} }
var rx_myinfo *regexp.Regexp var rx_myinfo *regexp.Regexp