From df0211c67d4e3a02a1cb56d42a076648a5a33172 Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 8 May 2016 12:49:36 +1200 Subject: [PATCH] parse $OpList, set IsOperator bool in UserInfo structs --- HubConnection.go | 29 +++++++++++++++++++++++++++-- UserInfo.go | 1 + 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/HubConnection.go b/HubConnection.go index 7539908..e6c82f8 100644 --- a/HubConnection.go +++ b/HubConnection.go @@ -187,6 +187,33 @@ func (this *HubConnection) processProtocolMessage(message string) { } } + case "$OpList": + oplist := strings.Split(commandParts[1], "$$") + opmap := map[string]struct{}{} + + // Organise/sort the list, and ensure we're not meeting an operator for + // the first time + for _, nick := range oplist { + if len(nick) > 0 { + opmap[nick] = struct{}{} + this.userJoined_NameOnly(nick) // assert existence; noop otherwise + } + } + + // Mark all mentioned nicks as being operators, and all unmentioned nicks + // as being /not/ an operator. (second pass minimises RW mutex use) + func() { + this.userLock.Lock() + defer this.userLock.Unlock() + + for nick, userinfo := range this.users { + _, isop := opmap[nick] + + userinfo.IsOperator = isop + this.users[nick] = userinfo + } + }() + case "$To:": valid := false if rx_incomingTo.MatchString(commandParts[1]) { @@ -216,8 +243,6 @@ func (this *HubConnection) processProtocolMessage(message string) { // IGNORABLE COMMANDS case "$Supports": case "$UserCommand": // TODO $UserCommand 1 1 Group chat\New group chat$<%[mynick]> !groupchat_new|| - case "$UserList": - case "$OpList": case "$HubTopic": case "$Search": case "$ConnectToMe": diff --git a/UserInfo.go b/UserInfo.go index 6df15f4..c6786af 100644 --- a/UserInfo.go +++ b/UserInfo.go @@ -46,6 +46,7 @@ type UserInfo struct { HubsUnregistered uint64 HubsRegistered uint64 HubsOperator uint64 + IsOperator bool } var rx_myinfo *regexp.Regexp