adc: support incremental user updates
--HG-- branch : adc
This commit is contained in:
parent
f0e5270458
commit
882f60f157
@ -175,21 +175,56 @@ func (this *AdcProtocol) ProcessCommand(msg string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uinfo, err := this.handleUserInfo(flags)
|
|
||||||
if err != nil {
|
|
||||||
this.logError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log this user in, and associate this SID with this user
|
// Log this user in, and associate this SID with this user
|
||||||
this.hc.usersMut.Lock()
|
this.hc.usersMut.Lock()
|
||||||
defer this.hc.usersMut.Unlock()
|
defer this.hc.usersMut.Unlock()
|
||||||
|
|
||||||
newNick := uinfo.Nick
|
|
||||||
|
|
||||||
oldNick, sidExists := this.hc.userSIDs[sid]
|
oldNick, sidExists := this.hc.userSIDs[sid]
|
||||||
|
|
||||||
handleNewUser := func() {
|
uinfo := UserInfo{}
|
||||||
|
if sidExists {
|
||||||
|
uinfo_lookup, ok := this.hc.users[oldNick]
|
||||||
|
if !ok {
|
||||||
|
// Shouldn't happen
|
||||||
|
this.hc.processEvent(HubEvent{
|
||||||
|
EventType: EVENT_SYSTEM_MESSAGE_FROM_CONN,
|
||||||
|
Message: fmt.Sprintf("Hub connection corrupted (missing info for SID='%s' nick='%s'), disconnecting", sid, oldNick),
|
||||||
|
})
|
||||||
|
this.hc.Disconnect()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uinfo = uinfo_lookup
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateUserInfo(&uinfo, flags)
|
||||||
|
newNick := uinfo.Nick
|
||||||
|
if len(newNick) == 0 {
|
||||||
|
this.logError(fmt.Errorf("Zero-length nick for user (SID='%s')", sid))
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldHandleNewUser := false
|
||||||
|
if sidExists && oldNick != newNick {
|
||||||
|
// Nick change = delete all trace of this user first, treat as new
|
||||||
|
|
||||||
|
delete(this.hc.users, oldNick)
|
||||||
|
delete(this.hc.userSIDs, sid)
|
||||||
|
this.hc.processEvent(HubEvent{EventType: EVENT_USER_PART, Nick: oldNick})
|
||||||
|
shouldHandleNewUser = true
|
||||||
|
|
||||||
|
} else if sidExists && oldNick == newNick {
|
||||||
|
// Updating existing user
|
||||||
|
this.hc.users[newNick] = uinfo
|
||||||
|
this.hc.processEvent(HubEvent{EventType: EVENT_USER_UPDATED_INFO, Nick: newNick})
|
||||||
|
|
||||||
|
} else if !sidExists {
|
||||||
|
// User joined
|
||||||
|
shouldHandleNewUser = true
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
if shouldHandleNewUser {
|
||||||
// Install this SID as pointing to this nick
|
// Install this SID as pointing to this nick
|
||||||
this.hc.userSIDs[sid] = uinfo.Nick
|
this.hc.userSIDs[sid] = uinfo.Nick
|
||||||
|
|
||||||
@ -206,28 +241,10 @@ func (this *AdcProtocol) ProcessCommand(msg string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Notifications
|
// Notifications
|
||||||
this.hc.users[newNick] = *uinfo
|
this.hc.users[newNick] = uinfo
|
||||||
this.hc.processEvent(HubEvent{EventType: EVENT_USER_JOINED, Nick: newNick})
|
this.hc.processEvent(HubEvent{EventType: EVENT_USER_JOINED, Nick: newNick})
|
||||||
}
|
}
|
||||||
|
|
||||||
if sidExists && oldNick != newNick {
|
|
||||||
// Nick change = delete all trace of this user first, treat as new
|
|
||||||
|
|
||||||
delete(this.hc.users, oldNick)
|
|
||||||
delete(this.hc.userSIDs, sid)
|
|
||||||
this.hc.processEvent(HubEvent{EventType: EVENT_USER_PART, Nick: oldNick})
|
|
||||||
handleNewUser()
|
|
||||||
|
|
||||||
} else if sidExists && oldNick == newNick {
|
|
||||||
// Updating existing user
|
|
||||||
this.hc.users[newNick] = *uinfo
|
|
||||||
this.hc.processEvent(HubEvent{EventType: EVENT_USER_UPDATED_INFO, Nick: newNick})
|
|
||||||
|
|
||||||
} else if !sidExists {
|
|
||||||
// User joined
|
|
||||||
handleNewUser()
|
|
||||||
}
|
|
||||||
|
|
||||||
case "IMSG":
|
case "IMSG":
|
||||||
// General message from the hub
|
// General message from the hub
|
||||||
if len(parts) < 2 {
|
if len(parts) < 2 {
|
||||||
@ -450,14 +467,15 @@ func (this *AdcProtocol) handleHubInfo(flags map[string]string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *AdcProtocol) handleUserInfo(flags map[string]string) (*UserInfo, error) {
|
func (this *AdcProtocol) updateUserInfo(u *UserInfo, flags map[string]string) {
|
||||||
|
|
||||||
// User MyINFO
|
// User MyINFO
|
||||||
// BINF GUPR IDFEARIFD33NTGC4YBEZ3UFQS5R4ZXXTFL2QN2GRY PDZMIFLG5EKZG3BDRRMIJPG7ARNA6KW3JVIH3DF7Q NIivysaur5 SL3 FS3 SS0 SF0 HN1 HR0 HO0 VEEiskaltDC++\s2.2.9 US2621440 KPSHA256/3UPRORG4BLJ4CG6TO6R3G75A67LXOGD437NALQALRWJF6XBOECTA I40.0.0.0 U418301
|
// BINF GUPR IDFEARIFD33NTGC4YBEZ3UFQS5R4ZXXTFL2QN2GRY PDZMIFLG5EKZG3BDRRMIJPG7ARNA6KW3JVIH3DF7Q NIivysaur5 SL3 FS3 SS0 SF0 HN1 HR0 HO0 VEEiskaltDC++\s2.2.9 US2621440 KPSHA256/3UPRORG4BLJ4CG6TO6R3G75A67LXOGD437NALQALRWJF6XBOECTA I40.0.0.0 U418301
|
||||||
// BINF GUPR I4172.17.0.1 U418301 IDFEARIFD33NTGC4YBEZ3UFQS5R4ZXXTFL2QN2GRY VEEiskaltDC++\s2.2.9 SF0 NIivysaur5 SL3 HN1 HO0 KPSHA256/3UPRORG4BLJ4CG6TO6R3G75A67LXOGD437NALQALRWJF6XBOECTA HR0 FS3 SS0 US2621440 SUSEGA,ADC0,TCP4,UDP4
|
// BINF GUPR I4172.17.0.1 U418301 IDFEARIFD33NTGC4YBEZ3UFQS5R4ZXXTFL2QN2GRY VEEiskaltDC++\s2.2.9 SF0 NIivysaur5 SL3 HN1 HO0 KPSHA256/3UPRORG4BLJ4CG6TO6R3G75A67LXOGD437NALQALRWJF6XBOECTA HR0 FS3 SS0 US2621440 SUSEGA,ADC0,TCP4,UDP4
|
||||||
|
// Or maybe only incremental:
|
||||||
|
// BINF Z3BA HO1
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
u := UserInfo{}
|
|
||||||
for prop, val := range flags {
|
for prop, val := range flags {
|
||||||
switch prop {
|
switch prop {
|
||||||
case "ID":
|
case "ID":
|
||||||
@ -511,12 +529,6 @@ func (this *AdcProtocol) handleUserInfo(flags map[string]string) (*UserInfo, err
|
|||||||
} else if !hasAP && hasVE {
|
} else if !hasAP && hasVE {
|
||||||
u.ClientTag, u.ClientVersion = this.getAPVEFromSingle(VE)
|
u.ClientTag, u.ClientVersion = this.getAPVEFromSingle(VE)
|
||||||
}
|
}
|
||||||
|
|
||||||
if u.Nick == "" {
|
|
||||||
return nil, fmt.Errorf("Malformed user missing nick")
|
|
||||||
}
|
|
||||||
|
|
||||||
return &u, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *AdcProtocol) getAPVEFromSingle(term string) (string, string) {
|
func (this *AdcProtocol) getAPVEFromSingle(term string) (string, string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user