threadsafe access to upstream userlist

--HG--
branch : nmdc-ircfrontend
This commit is contained in:
. 2016-05-08 12:39:18 +12:00
parent e2c2953fc5
commit 3cda342302
2 changed files with 23 additions and 18 deletions

View File

@ -4,16 +4,12 @@ PRE-RELEASE
- detect our own /me messages + don't echo back - detect our own /me messages + don't echo back
- threadsafe access to libnmdc hub options
- client descriptions (CTCP USERINFO) - client descriptions (CTCP USERINFO)
- expose upstream op status - expose upstream op status
- remove color code escape sequences - remove color code escape sequences
---- libnmdc no alert on bad nick
WISHLIST WISHLIST
======== ========

View File

@ -302,7 +302,7 @@ func (s *Server) handleRegisteredCommand(command string, args []string) {
if s.upstream == nil { if s.upstream == nil {
s.reply(rplList, fmt.Sprintf("%s %d :%s", BLESSED_CHANNEL, 1, "-")) s.reply(rplList, fmt.Sprintf("%s %d :%s", BLESSED_CHANNEL, 1, "-"))
} else { } else {
s.reply(rplList, fmt.Sprintf("%s %d :%s", BLESSED_CHANNEL, len(s.upstream.Users), s.upstream.HubName)) s.reply(rplList, fmt.Sprintf("%s %d :%s", BLESSED_CHANNEL, s.upstream.UserCount(), s.upstream.HubName))
} }
s.reply(rplListEnd) s.reply(rplListEnd)
@ -392,7 +392,7 @@ func (s *Server) handleJoinedCommand(command string, args []string) {
if strings.ToLower(args[0]) == BLESSED_CHANNEL { if strings.ToLower(args[0]) == BLESSED_CHANNEL {
s.upstream.SayPublic(message) s.upstream.SayPublic(message)
} else if _, clientExists := s.upstream.Users[args[0]]; clientExists { } else if s.upstream.UserExists(args[0]) {
s.upstream.SayPrivate(args[0], message) s.upstream.SayPrivate(args[0], message)
} else { } else {
@ -486,11 +486,14 @@ func (s *Server) DisconnectClient() {
func (s *Server) sendNames() { func (s *Server) sendNames() {
names := s.upstreamLauncher.Self.Nick // always include ourselves names := s.upstreamLauncher.Self.Nick // always include ourselves
if s.upstream != nil { if s.upstream != nil {
for nick, _ := range s.upstream.Users { s.upstream.Users(func(u *map[string]libnmdc.UserInfo) error {
for nick, _ := range *u {
if nick != s.upstreamLauncher.Self.Nick { // but don't repeat ourselves if nick != s.upstreamLauncher.Self.Nick { // but don't repeat ourselves
names += " " + nick names += " " + nick
} }
} }
return nil
})
} }
s.reply(rplNames, BLESSED_CHANNEL, names) s.reply(rplNames, BLESSED_CHANNEL, names)
@ -506,18 +509,24 @@ func (s *Server) sendWho(arg string) {
// always include ourselves // always include ourselves
s.reply(rplWho, s.upstreamLauncher.Self.Nick, arg) s.reply(rplWho, s.upstreamLauncher.Self.Nick, arg)
for nick, _ := range s.upstream.Users { s.upstream.Users(func(u *map[string]libnmdc.UserInfo) error {
for nick, _ := range *u {
if nick != s.upstreamLauncher.Self.Nick { // but don't repeat ourselves if nick != s.upstreamLauncher.Self.Nick { // but don't repeat ourselves
s.reply(rplWho, nick, arg) s.reply(rplWho, nick, arg)
} }
} }
return nil
})
} else { } else {
// argument is a filter // argument is a filter
for nick, _ := range s.upstream.Users { s.upstream.Users(func(u *map[string]libnmdc.UserInfo) error {
for nick, _ := range *u {
if strings.Contains(nick, arg) { if strings.Contains(nick, arg) {
s.reply(rplWho, nick, arg) s.reply(rplWho, nick, arg)
} }
} }
return nil
})
} }
s.reply(rplEndOfWho, arg) s.reply(rplEndOfWho, arg)
} }