Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/main.go b/main.go
- index 461a4402..c393a2cd 100644
- --- a/main.go
- +++ b/main.go
- @@ -139,11 +139,11 @@ func main() {
- cookie := newOrLoadCookie(config)
- metrics := server.NewLocalMetrics(logger, startupLogger, db, config)
- sessionRegistry := server.NewLocalSessionRegistry(metrics)
- - sessionCache := server.NewLocalSessionCache(config.GetSession().TokenExpirySec)
- - consoleSessionCache := server.NewLocalSessionCache(config.GetConsole().TokenExpirySec)
- - loginAttemptCache := server.NewLocalLoginAttemptCache()
- statusRegistry := server.NewStatusRegistry(logger, config, sessionRegistry, jsonpbMarshaler)
- tracker := server.StartLocalTracker(logger, config, sessionRegistry, statusRegistry, metrics, jsonpbMarshaler)
- + sessionCache := server.NewLocalSessionCache(sessionRegistry, tracker, config.GetSession().TokenExpirySec)
- + consoleSessionCache := server.NewLocalSessionCache(sessionRegistry, tracker, config.GetConsole().TokenExpirySec)
- + loginAttemptCache := server.NewLocalLoginAttemptCache()
- router := server.NewLocalMessageRouter(sessionRegistry, tracker, jsonpbMarshaler)
- leaderboardCache := server.NewLocalLeaderboardCache(logger, startupLogger, db)
- leaderboardRankCache := server.NewLocalLeaderboardRankCache(ctx, startupLogger, db, config.GetLeaderboard(), leaderboardCache)
- diff --git a/server/session_cache.go b/server/session_cache.go
- index e1d40310..660b9463 100644
- --- a/server/session_cache.go
- +++ b/server/session_cache.go
- @@ -20,6 +20,7 @@ import (
- "time"
- "github.com/gofrs/uuid"
- + "github.com/heroiclabs/nakama-common/runtime"
- )
- type SessionCache interface {
- @@ -52,17 +53,21 @@ type LocalSessionCache struct {
- ctx context.Context
- ctxCancelFn context.CancelFunc
- - cache map[uuid.UUID]*sessionCacheUser
- + tracker Tracker
- + sessionRegistry SessionRegistry
- + cache map[uuid.UUID]*sessionCacheUser
- }
- -func NewLocalSessionCache(tokenExpirySec int64) SessionCache {
- +func NewLocalSessionCache(sessionRegistry SessionRegistry, tracker Tracker, tokenExpirySec int64) SessionCache {
- ctx, ctxCancelFn := context.WithCancel(context.Background())
- s := &LocalSessionCache{
- ctx: ctx,
- ctxCancelFn: ctxCancelFn,
- - cache: make(map[uuid.UUID]*sessionCacheUser),
- + tracker: tracker,
- + sessionRegistry: sessionRegistry,
- + cache: make(map[uuid.UUID]*sessionCacheUser),
- }
- go func() {
- @@ -173,6 +178,16 @@ func (s *LocalSessionCache) RemoveAll(userID uuid.UUID) {
- func (s *LocalSessionCache) Ban(userIDs []uuid.UUID) {
- s.Lock()
- for _, userID := range userIDs {
- + if _, ok := s.cache[userID]; !ok {
- + continue
- + }
- +
- + for _, presence := range s.tracker.ListPresenceIDByStream(PresenceStream{Mode: StreamModeNotifications, Subject: userID}) {
- + if activeSession := s.sessionRegistry.Get(presence.SessionID); activeSession != nil {
- + activeSession.Close("you banned", runtime.PresenceReasonDisconnect)
- + }
- + }
- +
- delete(s.cache, userID)
- }
- s.Unlock()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement