refactor: change FindSessionByCharID to search on channel sessions

This commit is contained in:
Yslan Ramos
2022-08-27 20:05:25 -03:00
parent b33248c370
commit 63a829c913

View File

@@ -11,6 +11,7 @@ import (
"erupe-ce/network/binpacket" "erupe-ce/network/binpacket"
"erupe-ce/network/mhfpacket" "erupe-ce/network/mhfpacket"
"erupe-ce/server/discordbot" "erupe-ce/server/discordbot"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"go.uber.org/zap" "go.uber.org/zap"
) )
@@ -343,19 +344,11 @@ func (s *Server) DiscordChannelSend(charName string, content string) {
func (s *Server) FindSessionByCharID(charID uint32) *Session { func (s *Server) FindSessionByCharID(charID uint32) *Session {
for _, c := range s.Channels { for _, c := range s.Channels {
c.stagesLock.RLock() for _, session := range c.sessions {
for _, stage := range c.stages { if session.charID == charID {
stage.RLock() return session
for client := range stage.clients {
if client.charID == charID {
stage.RUnlock()
c.stagesLock.RUnlock()
return client
} }
} }
stage.RUnlock()
}
c.stagesLock.RUnlock()
} }
return nil return nil
} }