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); } }
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); } }