示例#1
0
 private void DisposeChannel(INetworkChannel channel)
 {
     if (channel != null)
     {
         channel.Dispose();
     }
     if (channel != null)
     {
         channel.Disconnect();
         channel.Dispose();
     }
 }
示例#2
0
        public void OnDisconnect(INetworkChannel channel, int messageType, object messageBody)
        {
            PlayerEntity player = GetPlayerEntity(channel);

            if (player != null)
            {
                try
                {
                    _logger.InfoFormat("player disconnected id {0}", player.entityKey);
                    if (_hallRoom.AllowReConnect)
                    {
                        player.stage.Value = EPlayerLoginStage.Offline;
                        player.RemoveNetwork();
                        player.RemoveUpdateMessagePool();
                    }
                    else
                    {
                        player.isFlagDestroy = true;

                        if (player.hasFreeData)
                        {
                            if (player.isInitialized)
                            {
                                _rule.PlayerLeave(_contexts, player);
                            }
                        }
                        else
                        {
                            _logger.ErrorFormat("Leave Player {0} Id {1} without Free Data ",
                                                player.playerInfo.PlayerName,
                                                player.playerInfo.PlayerId);
                        }

                        if (_hallRoom != null)
                        {
                            _hallRoom.PlayerLeaveRoom(player.playerInfo.PlayerId);
                        }
                    }
                }
                catch (Exception e)
                {
                    _logger.ErrorFormat("player disconnected error: {0} \n {1}", e.Message, e.StackTrace);
                }

                channel.MessageReceived -= ChannelOnMessageReceived;
                channel.Disconnected    -= ChannelOnDisonnected;
                _channelToPlayer.Remove(channel);
                channel.Dispose();

                if (_channelToPlayer.Count == 0 && !_hallRoom.AllowReConnect)
                {
                    GameOver(true);
                }
            }
            else
            {
                _logger.ErrorFormat("illegal ChannelOnDisonnected event received {0}", channel);
            }
        }
示例#3
0
 public void Dispose()
 {
     if (NetworkChannel != null)
     {
         NetworkChannel.Dispose();
     }
     if (SnapshotPool != null)
     {
         SnapshotPool.Dispose();
     }
     if (OCController != null)
     {
         OCController.Dispose();
     }
 }
 public void Dispose()
 {
     if (NetworkChannel != null)
     {
         NetworkChannel.Dispose();
     }
     if (SnapshotSelctor != null)
     {
         SnapshotSelctor.Dispose();
     }
     if (OCController != null)
     {
         OCController.Dispose();
     }
     if (Record != null)
     {
         Record.Dispose();
     }
     if (Replay != null)
     {
         Replay.Dispose();
     }
 }
示例#5
0
        public LoginClient(
            string serverIp,
            NetworkPortInfo networkPortInfo,
            IClientRoom clientRoom)
        {
            this._clientRoom = clientRoom;

            //INetworkClientFactory clientFactory = new UNetNetworkClientFactory();
            //INetworkClientFactory clientFactory = new ENetNetworkClientFactory();
            INetworkClientFactory clientFactory = new VNetworkClientFactory();

            if (_networkClient != null)
            {
                _networkChannel.Dispose();
            }
            _networkClient = clientFactory.CreateNetworkClient(SharedConfig.IsLittleEndian, SharedConfig.MutilThread,
                                                               "BattleClient");

            _networkClient.ChannelConnected    += NetworkClientOnChannelConnected;
            _networkClient.ChannelDisconnected += NetworkClientOnChannelDisconnected;
            _networkClient.Connect(serverIp, networkPortInfo);
            SingletonManager.Get <DurationHelp>().ServerInfo = string.Format("{0} tcp:{1} udp:{2}", serverIp,
                                                                             networkPortInfo.TcpPort, networkPortInfo.UdpPort);
        }
示例#6
0
        public void OnDisconnect(INetworkChannel channel, int messageType, object messageBody)
        {
            PlayerEntity player = GetPlayerEntity(channel);

            if (player != null)
            {
                try
                {
                    logger.InfoFormat("player disconnected id {0}", player.entityKey);
                    if (hallRoom != null && hallRoom.AllowReConnect)
                    {
                        logger.InfoFormat("player AllowReConnect id {0}", player.entityKey);
                        player.stage.Value = EPlayerLoginStage.Offline;
                        player.RemoveNetwork();
                        player.RemoveUpdateMessagePool();
                    }
                    else
                    {
                        BulletPlayerUtil.DoProcessPlayerHealthDamage(ContextsWrapper.contexts,
                                                                     ContextsWrapper.FreeArgs.Rule as IGameRule, null, player,
                                                                     new PlayerDamageInfo(0, (int)EUIDeadType.NoHelp, 0, 0, false, false, true));

                        player.isFlagDestroy = true;

                        if (player.hasFreeData)
                        {
                            if (player.isInitialized)
                            {
                                logger.InfoFormat("player PlayerLeave id {0}", player.entityKey);
                                rule.PlayerLeave(ContextsWrapper.contexts, player);
                                player.isInitialized = false;
                            }
                        }
                        else
                        {
                            logger.ErrorFormat("Leave Player {0} Id {1} without Free Data ",
                                               player.playerInfo.PlayerName, player.playerInfo.PlayerId);
                        }

                        if (hallRoom != null)
                        {
                            logger.InfoFormat("player PlayerLeaveRoom id {0}", player.entityKey);
                            hallRoom.PlayerLeaveRoom(player.playerInfo.PlayerId);
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.ErrorFormat("player disconnected error: {0} \n {1}", e.Message, e.StackTrace);
                }
                finally
                {
                    int channelToPlayerCount = channelToPlayer.Count;
                    try
                    {
                        channel.MessageReceived -= ChannelOnMessageReceived;
                        channel.Disconnected    -= ChannelOnDisonnected;
                        channelToPlayer.Remove(channel);
                        channel.Dispose();
                    }
                    catch (Exception e)
                    {
                        logger.ErrorFormat("player Remove error: {0} \n {1}", e.Message, e.StackTrace);
                    }
                    finally
                    {
                        channelToPlayerCount--;
                    }

                    if (channelToPlayerCount == 0)
                    {
                        if (hallRoom == null && hallRoom.AllowReConnect)
                        {
                            logger.ErrorFormat("AllowReConnect");
                        }
                        else
                        {
                            GameOver(true, RoomState.RGameOver);
                        }
                    }
                }
            }
            else
            {
                logger.ErrorFormat("illegal ChannelOnDisonnected event received {0}", channel);
            }
        }