Exemple #1
0
        private void UpdateLoginTimer()
        {
            if (_hasHallServer && _loginStates.Count > 0)
            {
                var time = Time.time;
                foreach (var state in _loginStates)
                {
                    if (IsRoomGameExit() || state.Value.IsLoginTimeOut(time))
                    {
                        _loginTimeOutList.Add(state.Key);

                        var e = RoomEvent.AllocEvent <MandatoryLogOutEvent>();
                        e.LogOutReason = IsRoomGameExit()
                            ? MandatoryLogOutEvent.Reason.GameExit
                            : MandatoryLogOutEvent.Reason.TimeOut;
                        e.PlayerId   = state.Value.PlayerId;
                        e.HallRoomId = _hallRoomId;
                        e.RoomId     = _roomId;
                        e.Token      = state.Key;

                        _logger.InfoFormat("Mandatory Loginout  Player Token {0} Reason {1}", state.Key, e.LogOutReason);

                        _dispatcher.AddEvent(e);
                    }
                }

                foreach (var key in _loginTimeOutList)
                {
                    _loginStates.Remove(key);
                }

                _loginTimeOutList.Clear();
            }
        }
Exemple #2
0
        public void PlayerLeaveRoom(long playerId)
        {
            _logger.InfoFormat("player leave room {0}", playerId);
            GameOverPlayer gameOverPlayer = null;
            var            evt            = RoomEvent.AllocEvent <LeaveRoomEvent>();

            if (_dictPlayers.ContainsKey(playerId))
            {
                IPlayerInfo player = _dictPlayers[playerId];
                gameOverPlayer = GameOverPlayer.Allocate();
                SetGameOverPlayerValue(gameOverPlayer, player);
                //_gameStatisticData.SetStatisticData(gameOverPlayer, playerInfo, _contexts.session.commonSession.FreeArgs);

                if (player.Token != TestUtility.TestToken)
                {
                    evt.Token = player.Token;
                }

                RemovePlayer(playerId);
                _logger.InfoFormat("player {0} leave room, set statistics complete", playerId);
            }

            evt.PlayerId = playerId;
            evt.Player   = gameOverPlayer;
            _dispatcher.AddEvent(evt);
        }
        private void CreateRoom(CreateRoomEvent e)
        {
            bool success = false;

            if (_room == null && (e.IsDummy || e.Message != null))
            {
                try
                {
                    _room = _roomFactory.Create(e.Message);
                    FinishRoomCreate(e.Message);
                    success = true;
                }
                catch (Exception exception)
                {
                    _logger.Error("Create Room Failed: ", exception);
                }
            }

            if (!success)
            {
                var evt = RoomEvent.AllocEvent <CreateRoomResponseEvent>();
                evt.Success = false;
                evt.ErrCode = _room != null ? ErrorCode.CreateRoom_ServerRoom_Exist : ErrorCode.CreateRoom_Message_Error;
                _dispatcher.AddEvent(evt);
            }
        }
Exemple #4
0
        public override void GameOver(bool forceOver)
        {
            var evt = RoomEvent.AllocEvent <GameOverEvent>();

            evt.HallRoomId = HallRoomId;
            evt.Message    = null;
            _dispatcher.AddEvent(evt);
        }
Exemple #5
0
        public override void DoAction(IEventArgs args)
        {
            var re = RoomEvent.AllocEvent <SetRoomStatusEvent>();

            re.GameStatus  = (ERoomGameStatus)args.GetInt(gameStatus);
            re.EnterStatus = (ERoomEnterStatus)args.GetInt(enterStatus);
            args.GameContext.session.serverSessionObjects.RoomEventDispatchter.AddEvent(re);
        }
Exemple #6
0
        public void Handle(INetworkChannel networkChannel, object messagName, ResponseRegisterBattleServerMessage msg)
        {
            var e = RoomEvent.AllocEvent <HallServerConnectEvent>();

            _dispatcher.AddEvent(e);

            _logger.InfoFormat("Receive Response Register Battle Server Message, Has Hall Server");
        }
Exemple #7
0
        public void UpdatePlayerStatus(long playerId, EPlayerGameStatus status)
        {
            var e = RoomEvent.AllocEvent <UpdatePlayerStatusEvent>();

            e.PlayerId = playerId;
            e.Status   = (int)status;

            _dispatcher.AddEvent(e);
        }
Exemple #8
0
        private void GameExit()
        {
            SetGameOverStatus(true);

            SendGameOverMessageToAllPlayers();
            var evt = RoomEvent.AllocEvent <GameExitEvent>();

            _eventDispatcher.AddEvent(evt);
        }
        private void JoinRoom(JoinRoomEvent e)
        {
            var evt = RoomEvent.AllocEvent <JoinRoomResponseEvent>();

            evt.HallRoomId           = e.HallRoomId;
            evt.RetCode              = 0;
            evt.JoinRoomResponseInfo = JoinRoom(e.HallRoomId, e.RoomPlayer);

            _dispatcher.AddEvent(evt);
        }
 //In the absence of connection to Hall Server, we use a dummy CreateRoomEvent to create  a  new room.
 //Usually, it means the game is running in Edit Mode.
 public void CreateRoomIfNotExist()
 {
     if (_room == null && !_hasHallServer)
     {
         var e = RoomEvent.AllocEvent <CreateRoomEvent>();
         e.IsDummy = true;
         e.Message = null;
         CreateRoom(e);
         RoomEvent.FreeEvent(e);
     }
 }
        private void DisposeClientConnect()
        {
            DisposeChannel(_clientChannel);
            _clientChannel = null;

            var evt = RoomEvent.AllocEvent <HallServerDisconnectEvent>();

            _dispatcher.AddEvent(evt);

            _logger.ErrorFormat("Disconnect From Allocation Server.");
        }
Exemple #12
0
        public void Handle(INetworkChannel networkChannel, object messagName, LongData roomId, RoomPlayer player)
        {
            var e = RoomEvent.AllocEvent <JoinRoomEvent>();

            e.HallRoomId = roomId.Value;
            e.RoomPlayer = player;

            _dispatcher.AddEvent(e);

            _logger.InfoFormat("Receive Join Room Message Hall Room Id {0} Map Id {1}", roomId, player.Id);
        }
Exemple #13
0
        private void GameExit(RoomState state)
        {
            SetGameOverStatus(true);

            if (!isGameExit)
            {
                SendGameOverMessageToAllPlayers();
                var evt = RoomEvent.AllocEvent <GameExitEvent>();
                eventDispatcher.AddEvent(evt);
                isGameExit = true;
            }
        }
Exemple #14
0
        public void UpdateRoomGameStatus(ERoomGameStatus status, ERoomEnterStatus enter)
        {
            _logger.InfoFormat("Update Room Status {0}=>{1}", GameStatus, status);
            GameStatus = status;

            var e = RoomEvent.AllocEvent <UpdateRoomGameStatusEvent>();

            e.HallRoomId = HallRoomId;
            e.Status     = (int)status;
            e.CanEnter   = (int)enter;

            _dispatcher.AddEvent(e);
        }
Exemple #15
0
        public virtual void GameOver(bool forceOver)
        {
            var msg = GameOverMessage.Allocate();

            msg.HallRoomId = this.HallRoomId;
            if (!forceOver)
            {
                try
                {
                    foreach (var player in _dictPlayers.Values)
                    {
                        var gameOverPlayer = GameOverPlayer.Allocate();
                        SetGameOverPlayerValue(gameOverPlayer, player);
                        //_gameStatisticData.SetStatisticData(gameOverPlayer, playerInfo, _contexts.session.commonSession.FreeArgs);
                        msg.Players.Add(gameOverPlayer);
                    }

                    if (_dictGoPlayers.Count > 0)
                    {
                        foreach (var gameOverPlayer in _dictGoPlayers.Values)
                        {
                            msg.Players.Add(gameOverPlayer);
                        }
                    }

                    msg.TotalPlayer = _dictPlayers.Count + _dictGoPlayers.Count;
                }
                catch (Exception e)
                {
                    _logger.ErrorFormat("GameOver ... Error:{0}", e.StackTrace);
                }
            }
            else
            {
                Dispose();
            }

            IFreeRule rule = _contexts.session.commonSession.FreeArgs.Rule;

            msg.BattleStartTime = rule.StartTime + rule.GameStartTime;
            msg.BattleEndTime   = rule.StartTime + rule.GameEndTime;


            var evt = RoomEvent.AllocEvent <GameOverEvent>();

            evt.HallRoomId = HallRoomId;
            evt.Message    = msg;
            _dispatcher.AddEvent(evt);
        }
        private void JoinRoomList(JoinRoomListEvent e)
        {
            if (e.RoomPlayerList != null)
            {
                var evt = RoomEvent.AllocEvent <JoinRoomListResponseEvent>();
                evt.HallRoomId = e.HallRoomId;
                evt.RetCode    = 0;
                foreach (var roomPlayer in e.RoomPlayerList)
                {
                    evt.JoinRoomResponseInfoList.Add(JoinRoom(e.HallRoomId, roomPlayer));
                }

                _dispatcher.AddEvent(evt);
            }
        }
 private void CreateRoom(CreateRoomEvent e)
 {
     if (_room != null || (!e.IsDummy && e.Message == null))
     {
         var evt = RoomEvent.AllocEvent <CreateRoomResponseEvent>();
         evt.Success = false;
         evt.ErrCode = _room != null ? ErrorCode.CreateRoom_ServerRoom_Exist : ErrorCode.CreateRoom_Message_Error;
         _dispatcher.AddEvent(evt);
     }
     else
     {
         _room = _roomFactory.Create(e.Message);
         FinishRoomCreate(e.Message);
     }
 }
        public void Handle(INetworkChannel networkChannel, object messagName, RequestCreateRoomMessage messageData)
        {
            var e = RoomEvent.AllocEvent <CreateRoomEvent>();

            e.Message = messageData as RequestCreateRoomMessage;
            _dispatcher.AddEvent(e);

            if (e.Message != null)
            {
                _logger.InfoFormat("Receive Create Room Message Hall Room Id {0} Map Id {1}", e.Message.HallRoomId, e.Message.MapId);
            }
            else
            {
                _logger.ErrorFormat("Receive Create Room Message is Null");
            }
        }
Exemple #19
0
        public void CheckStateOnReceivePlayerMessage()
        {
            if (_hasHallServer)
            {
                if (IsRoomGameExit())
                {
                    var e = RoomEvent.AllocEvent <MandatoryLogOutEvent>();
                    e.LogOutReason = MandatoryLogOutEvent.Reason.GameExit;
                    e.PlayerId     = 0;
                    e.HallRoomId   = _hallRoomId;
                    e.RoomId       = _roomId;

                    _dispatcher.AddEvent(e);
                    _logger.Info("The room game has exited!");
                }
            }
        }
        public bool RequestPlayerInfo(string messageToken, INetworkChannel channel)
        {
            var playerInfo = GetPlayerInfo(messageToken, false);

            if (playerInfo != null)
            {
                bool sucess = _room.LoginPlayer(playerInfo, channel);
                if (!_hasHallServer && sucess)
                {
                    var evt = RoomEvent.AllocEvent <PlayerLoginEvent>();
                    evt.PlayerInfo = playerInfo;
                    _dispatcher.AddEvent(evt);
                }
                return(sucess);
            }

            return(false);
        }
Exemple #21
0
        public void Handle(INetworkChannel networkChannel, object messagName, RequestJoinRoomListMessage message)
        {
            var e = RoomEvent.AllocEvent <JoinRoomListEvent>();

            e.HallRoomId = message.HallRoomId;
            int count          = message.Players.Count;
            var roomPlayerList = new RoomPlayer[count];

            for (int i = 0; i < count; ++i)
            {
                roomPlayerList[i] = message.Players[i];
            }
            e.RoomPlayerList = roomPlayerList;

            _dispatcher.AddEvent(e);

            _logger.InfoFormat("Receive Join Room List Message Hall Room Id {0} Count {1}", e.HallRoomId, count);
        }
        private void SendCreateRoomResponse(RequestCreateRoomMessage message)
        {
            if (message == null)
            {
                return;
            }

            var resMsg = ResponseCreateRoomMessage.Allocate();

            resMsg.RetCode    = 0; //Success
            resMsg.HallRoomId = message.HallRoomId;

            var evt = RoomEvent.AllocEvent <CreateRoomResponseEvent>();

            evt.Success = true;
            evt.Message = resMsg;
            evt.RoomId  = _room.RoomId.Id;

            _dispatcher.AddEvent(evt);
        }
Exemple #23
0
        public virtual void GameOver(bool forceOver)
        {
            var msg = GameOverMessage.Allocate();

            msg.HallRoomId = this.HallRoomId;
            if (!forceOver)
            {
                try
                {
                    foreach (var player in _dictPlayers.Values)
                    {
                        var gameOverPlayer = GameOverPlayer.Allocate();
                        SetGameOverPlayerValue(gameOverPlayer, player);
                        //_gameStatisticData.SetStatisticData(gameOverPlayer, playerInfo, _contexts.session.commonSession.FreeArgs);
                        msg.Players.Add(gameOverPlayer);
                        _logger.InfoFormat("游戏结束时战报玩家ID {0} 排名 {1}", gameOverPlayer.Id, gameOverPlayer.Statistics[1]);
                    }

                    if (_dictGoPlayers.Count > 0)
                    {
                        foreach (var gameOverPlayer in _dictGoPlayers.Values)
                        {
                            msg.Players.Add(gameOverPlayer);
                        }
                    }
                    _logger.InfoFormat("游戏结束时战报玩家数 {0}", msg.Players.Count);
                }
                catch (Exception e)
                {
                    _logger.ErrorFormat("GameOver ... Error:{0}", e.StackTrace);
                }
            }

            Dispose();

            var evt = RoomEvent.AllocEvent <GameOverEvent>();

            evt.HallRoomId = HallRoomId;
            evt.Message    = msg;
            _dispatcher.AddEvent(evt);
        }
        public void Update()
        {
            if (_room != null)
            {
                if (_room.IsDiposed)
                {
                    _room = null;

                    var evt = RoomEvent.AllocEvent <RoomDisposedEvent>();
                    _dispatcher.AddEvent(evt);
                }
                else
                {
                    float now      = Time.time * 1000;
                    int   interval = _calcFixTimeInterval.Update(now);
                    _room.Update(interval);
                }
            }

            _debugSystem.Update();
        }
Exemple #25
0
        private void JoinRoomList(JoinRoomListEvent e)
        {
            if (e.RoomPlayerList != null)
            {
                var evt = RoomEvent.AllocEvent <JoinRoomListResponseEvent>();
                evt.HallRoomId = e.HallRoomId;
                evt.RetCode    = 0;
                foreach (var roomPlayer in e.RoomPlayerList)
                {
                    evt.JoinRoomResponseInfoList.Add(JoinRoom(e.HallRoomId, roomPlayer));
                }

                _dispatcher.AddEvent(evt);

                var args = _roomFactory.contexts().session.commonSession.FreeArgs as IEventArgs;
                if (args != null)
                {
                    args.Trigger(FreeTriggerConstant.PRELOAD_RESOURCE, new TempUnit("roomInfo", new ObjectUnit(e.RoomPlayerList)));
                }
            }
        }
Exemple #26
0
        private void NetworkChannelOnMessageReceived(INetworkChannel channel, int messageType, object messageBody)
        {
            if (messageType == (int)EClient2ServerMessage.Login)
            {
                LoginMessage message = (LoginMessage)messageBody;
                if (message == null)
                {
                    _logger.InfoFormat("Illegal login message");
                    channel.Disconnect();
                }
                else
                {
                    _logger.InfoFormat("Received Log in Message ... token:{0} {1}", message.Token, message.LoginStage);
                    var e = RoomEvent.AllocEvent <LoginServerEvent>();
                    e.Channel = channel;
                    e.Message = message;
                    _dispatcher.AddEvent(e);
                }
            }

            _networkMonitor.CheckStateOnReceivePlayerMessage();
        }