Esempio n. 1
0
        private void RemoveContext(GameServerContext context, IGameServerPeer peer = null)
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Removing context. context={0},p:{1}", context, peer);
            }

            if (this.gameServerContexts.TryGetValue(context.Key, out ContextKeeper keeper))
            {
                if (keeper.Context == context)
                {
                    this.gameServerContexts.Remove(context.Key);

                    if (log.IsInfoEnabled)
                    {
                        log.InfoFormat("Context was removed. context={0}, p:{1}", context, peer);
                    }
                    return;
                }

                if (log.IsInfoEnabled)
                {
                    log.InfoFormat("Context removal skiped. context found but it belongs " +
                                   "to different server. context4remove={0}, context in index:{1}", context, keeper.Context);
                }
            }
            else
            {
                log.WarnFormat("Removing of context failed. context={0},p:{1}", context, peer);
            }
        }
Esempio n. 2
0
        private void ScheduleContextRemoval(GameServerContext context, IGameServerPeer peer)
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Scheduling context for context removal. context={0},p:{1}", context, peer);
            }

            if (!this.gameServerContexts.TryGetValue(context.Key, out ContextKeeper keeper))
            {
                log.WarnFormat("Scheduling removal failed to find context. key:'{0}', id:'{1}',p:{2}", context.Key, context.ServerId, peer);
                return;
            }

            if (keeper.Context == context)
            {
                keeper.DisposeTimer = this.fiber.Schedule(() => ScheduledDestroyContext(keeper), this.contextTTL);
                if (log.IsInfoEnabled)
                {
                    log.InfoFormat("Context was scheduled for removal. context={0}, p:{1}", context, peer);
                }
                return;
            }

            if (log.IsInfoEnabled)
            {
                log.InfoFormat("Removal scheduling skiped. context found but it belongs " +
                               "to different server. context4remove={0}, context in index:{1}", context, keeper.Context);
            }
        }
Esempio n. 3
0
        private void RegisterGameServer(IRegisterGameServer request, IGameServerPeer peer, bool registerByRequet)
        {
            var key = GameServerContext.GetKey(request);

            if (log.IsInfoEnabled)
            {
                if (registerByRequet)
                {
                    log.Info($"Registering GS by request. key:'{key}', id:'{request.ServerId}', p:{peer}");
                }
                else
                {
                    log.Info($"Registering GS by InitRequest. key:'{key}', id:'{request.ServerId}', p:{peer}");
                }
            }

            lock (this.gameServerContexts)
            {
                ContextKeeper keeper;
                if (this.gameServerContexts.TryGetValue(key, out keeper))
                {
                    keeper.KillDisposeTimer();
                    if (keeper.Context.ServerId == request.ServerId)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.InfoFormat("Context for GS found and reused. key:'{0}', id:'{1}',p:{2}", key, request.ServerId, peer);
                        }

                        keeper.Context.AttachPeerAndHandleRegisterRequest(peer, request, true);
                        return;
                    }

                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Context for GS found but belongs to other server." +
                                        " key:'{0}', old_id:'{1}',new_id:{2}", key, keeper.Context.ServerId, request.ServerId);
                    }

                    this.RemoveContext(keeper.Context);
                    keeper.Context.DetachPeerAndClose();
                }

                keeper = new ContextKeeper
                {
                    Context = this.CreateContext(request),
                };

                keeper.Context.AttachPeerAndHandleRegisterRequest(peer, request, false);

                this.gameServerContexts.Add(key, keeper);

                if (log.IsInfoEnabled)
                {
                    log.InfoFormat("GS is added. key:'{0}', id:'{1}',p:{2}", key, request.ServerId, peer);
                }
                return;
            }
        }
Esempio n. 4
0
        public void OnGameServerLeft(GameServerContext context, IGameServerPeer peer)
        {
            lock (this.gameServerContexts)
            {
                context.DetachPeerAndClose();

                this.RemoveContext(context, peer);
            }
        }
 public ReplicationAssistant(GameServerContext gameServerContext, GameApplication app)
     : base(gameServerContext)
 {
     this.application = app;
     if (log.IsInfoEnabled)
     {
         log.InfoFormat("Replication started for context:{0}", gameServerContext);
     }
     this.application.OnBeginReplication(this.gameServerContext);
 }
Esempio n. 6
0
 public void OnGameServerDisconnect(GameServerContext context, IGameServerPeer peer)
 {
     lock (this.gameServerContexts)
     {
         if (context.DetachPeer(peer))
         {
             this.ScheduleContextRemoval(context, peer);
         }
     }
 }
        void IGameServerPeer.AttachToContext(GameServerContext context)
        {
            this.Context = context;

            if (this.Context != null)
            {
                this.ServerId = this.Context.ServerId;
            }

            if (log.IsDebugEnabled)
            {
                log.Debug($"Context attached to peer. context:{context}, p:{this}");
            }

            this.OnContextAttached();
        }
Esempio n. 8
0
 protected ReplicationAssistantBase(GameServerContext context)
 {
     this.gameServerContext = context;
 }