/// <summary> /// 1초마다 클라이언트의 연결상태를 체크해서 현결 해제된 클라이언트는 제거한다. /// </summary> /// <param name="state"></param> private void RemoveDisconnectedClient(Object state) { foreach (var client in _Players.Where(x => !isConnected(x.Value.TcpClient.Client)).ToList()) { //client.Reason이 기본값(1)그대로인데 소켓 연결이 끊어진 경우는 정상 로그아웃이 아니므로 ZS에도 로그아웃 패킷을 보낸다. if (client.Value.Reason == 1) { MSG_ZA2ZS_ACC_LOGOUT pDisconnect = new MSG_ZA2ZS_ACC_LOGOUT(); pDisconnect.MsgHeader.dwPCID = client.Value.Uid; pDisconnect.byReason = client.Value.Reason; ZoneServer.ZS[client.Value.ZoneStatus].Send(pDisconnect.Serialize()); } MSG_ZA2LS_ACC_LOGOUT pLogout = new MSG_ZA2LS_ACC_LOGOUT(); pLogout.MsgHeader.dwPCID = client.Value.Uid; pLogout.byReason = client.Value.Reason; pLogout.szAccount = client.Value.Account; LoginServer.LS.Send(pLogout.Serialize()); //zonelog update _Main.UpdateLogMsg(string.Format("{0} {1} DisconnectedUser.remove", client.Value.Account, client.Value.Uid)); _Players.Remove(client.Key); //player count update _Main.UpdateConnectionCount(_Players.Count, MaxPlayerCount); } }
/// <summary> /// 클라이언트(플레이어)를 리스트에서 제거, zs에 접속중일때는 해당 zs에 dc패킷까지 보냄 /// </summary> /// <param name="uid"></param> internal static void RemoveClient(uint uid, byte reason) { Client client = _Players[uid]; MSG_ZA2ZS_ACC_LOGOUT pLogout = new MSG_ZA2ZS_ACC_LOGOUT(); pLogout.MsgHeader.dwPCID = uid; pLogout.byReason = reason; ZoneServer.ZS[client.ZoneStatus].Send(pLogout.Serialize()); client.Reason = reason; client.TcpClient.Client.Disconnect(false); //소켓 연결만 끊어주면 플레이어 리스트 에서는 체크 타이머에서 자동 제거 된다. }
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e) { if (MessageBox.Show("Are you sure you want to close?", "ZoneAgent", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { if (ZoneAgent.ReqTick_Sender != null) { ZoneAgent.ReqTick_Sender.Change(Timeout.Infinite, Timeout.Infinite); } if (ZoneAgent.dcClient_Checker != null) { ZoneAgent.dcClient_Checker.Change(Timeout.Infinite, Timeout.Infinite); } //종료전 모든 사용를 로그아웃 처리한다. if (ZoneAgent._Players != null) { foreach (var player in ZoneAgent._Players) { MSG_ZA2ZS_ACC_LOGOUT zLogout = new MSG_ZA2ZS_ACC_LOGOUT(); zLogout.MsgHeader.dwPCID = player.Value.Uid; zLogout.byReason = 0x03; ZoneServer.ZS[player.Value.ZoneStatus].Send(zLogout.Serialize()); MSG_ZA2LS_ACC_LOGOUT pLogout = new MSG_ZA2LS_ACC_LOGOUT(); pLogout.MsgHeader.dwPCID = player.Value.Uid; pLogout.byReason = 0x03; pLogout.szAccount = player.Value.Account; LoginServer.LS.Send(pLogout.Serialize()); player.Value.TcpClient.Client.Disconnect(false); } } } else { e.Cancel = true; } }