adc: support incremental user updates

--HG--
branch : adc
This commit is contained in:
mappu 2017-11-26 18:38:03 +13:00
parent f0e5270458
commit 882f60f157
2 changed files with 48 additions and 38 deletions

View File

@ -175,21 +175,56 @@ func (this *AdcProtocol) ProcessCommand(msg string) {
return
}
uinfo, err := this.handleUserInfo(flags)
if err != nil {
this.logError(err)
return
}
// Log this user in, and associate this SID with this user
this.hc.usersMut.Lock()
defer this.hc.usersMut.Unlock()
newNick := uinfo.Nick
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
this.hc.userSIDs[sid] = uinfo.Nick
@ -206,28 +241,10 @@ func (this *AdcProtocol) ProcessCommand(msg string) {
}
// Notifications
this.hc.users[newNick] = *uinfo
this.hc.users[newNick] = uinfo
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":
// General message from the hub
if len(parts) < 2 {
@ -450,14 +467,15 @@ func (this *AdcProtocol) handleHubInfo(flags map[string]string) error {
return nil
}
func (this *AdcProtocol) handleUserInfo(flags map[string]string) (*UserInfo, error) {
func (this *AdcProtocol) updateUserInfo(u *UserInfo, flags map[string]string) {
// 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 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
u := UserInfo{}
for prop, val := range flags {
switch prop {
case "ID":
@ -511,12 +529,6 @@ func (this *AdcProtocol) handleUserInfo(flags map[string]string) (*UserInfo, err
} else if !hasAP && hasVE {
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) {

View File

@ -2,7 +2,5 @@ NMDC:
- Implement ZPipe ($ZOn)
ADC:
- Test that user info updates work
- they're incremental: BINF Z3BA HO1
- Usercommands
- ???