sessions.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package sessions
  2. import (
  3. "sync/atomic"
  4. cproto "github.com/cherry-game/cherry/net/proto"
  5. )
  6. func GetSession(playerID int64) (*cproto.Session, bool) {
  7. value, found := actor.GetCacheSession(playerID)
  8. if found {
  9. return value, true
  10. }
  11. if !actor.isSync {
  12. return actor.GetRedisSession(playerID)
  13. }
  14. return nil, false
  15. }
  16. func UIDCount() int64 {
  17. return atomic.LoadInt64(&actor.count)
  18. }
  19. func GetAgentPathWithPlayerIDS(playerIDList []int64) map[string][]int64 {
  20. sessionMaps, missPlayerIDS := actor.GetCacheSessions(playerIDList)
  21. // 未命中的playerID从redis再查一次
  22. if !actor.isSync && len(missPlayerIDS) > 0 {
  23. sessionMap := actor.GetRedisSessions(missPlayerIDS)
  24. for playerID, session := range sessionMap {
  25. sessionMaps[playerID] = session
  26. }
  27. }
  28. agentPathUIDMaps := map[string][]int64{}
  29. for _, session := range sessionMaps {
  30. if len(session.AgentPath) > 0 && session.Uid > 0 {
  31. agentPathUIDMaps[session.AgentPath] = append(agentPathUIDMaps[session.AgentPath], session.Uid)
  32. }
  33. }
  34. return agentPathUIDMaps
  35. }