Ejemplo n.º 1
0
        public void ServerDisconnected(SocketClient b)
        {
            foreach (var scene in ((SceneServerUserData)b.UserData).Scenes)
            {
                scene.Status = SceneStatus.Crashed;

                // 这里应该把数据清理干净,目前这样也能工作,每个人上线后,会把自己的数据刷新
                foreach (var characterId in scene.CharacterIds)
                {
                    CharacterInfo character;
                    ulong         cid;
                    if (mCharacterInfoManager.TryRemove(characterId, out character))
                    {
                        var clientId = character.ClientId;
                        mFromClientId2CharacterId.TryRemove(clientId, out cid);
                    }
                }

                SceneInfo sceneInfo;
                ConcurrentDictionary <ulong, SceneInfo> scenes;
                mFromSceneGuid2Server.TryRemove(scene.SceneGuid, out sceneInfo);
                if (sceneInfo != null && mFromServerIdAndSceneId2Guid.TryGetValue(
                        SceneManagerBroker.CalcServerSceneId(sceneInfo.ServerId, sceneInfo.SceneId),
                        out scenes))
                {
                    scenes.TryRemove(scene.SceneGuid, out sceneInfo);
                    //scenes.RemoveAll(item => item.SceneGuid == scene.SceneGuid);
                }

                scene.CharacterIds.Clear();
            }
        }
Ejemplo n.º 2
0
        public override void Start(int id, int nPort, string type, dynamic[] serverList)
        {
            mSceneManager = new SceneManagerBroker(this, type);
            mUniqueId     = (long)(DateTime.Now - DateTime.Parse("2015-01-01")).TotalMilliseconds;
            mTimeDispatcher.Start();

            base.Start(id, nPort, type, serverList);

            mTimeDispatcher.RegisterTimedEvent(TimeSpan.FromMinutes(1), MergeScene);


            //起线程监测事件队列
            WorkingThread = new Thread(() =>
            {
                mWaitingEvents.GetConsumingEnumerable().ToObservable().Subscribe(act =>
                {
                    if (act != null)
                    {
                        try
                        {
                            act();
                        }
                        catch (Exception exception)
                        {
                            Logger.Error(exception, "Process {0} error.", act.Method.Name);
                        }
                    }
                });
            });

            WorkingThread.Start();
        }