//방 퇴장 public void ExitRoom(DataPacket packet) { Console.WriteLine(packet.client.RemoteEndPoint.ToString() + "방 퇴장"); ExitRoomPacket exitRoomPacket = new ExitRoomPacket(packet.msg); ExitRoomData exitRoomData = exitRoomPacket.GetData(); string id = loginUser[packet.client]; int characterId = userState[id].characterId; Result result = Result.Fail; int roomNum = -1; bool empty = false; Console.WriteLine(userState[id].state); try { empty = roomManager.ExitRoom(userState[id].state, packet.client); roomNum = userState[id].state; userState[id].state = -1; result = Result.Success; } catch { Console.WriteLine("DataHandler::ExitRoom.DeletePlayer 에러"); result = Result.Fail; return; } ResultData resultData = new ResultData((byte)result); ResultPacket resultDataPacket = new ResultPacket(resultData); resultDataPacket.SetPacketId((int)ServerPacketId.ExitRoomNumber); byte[] msg = CreatePacket(resultDataPacket); packet = new DataPacket(msg, packet.client); lock (sendLock) { sendMsgs.Enqueue(packet); } Console.WriteLine(roomNum); if (roomNum != -1 && !empty) { for (int playerIndex = 0; playerIndex < RoomManager.maxPlayerNum; playerIndex++) { if (roomManager.Room[exitRoomData.RoomNum].Socket[playerIndex] != null) { packet = new DataPacket(new byte[0], roomManager.Room[exitRoomData.RoomNum].Socket[playerIndex]); RequestRoomUserData(packet); } } } }
//방 퇴장 -> Server public void ExitRoom(int roomNum) { Debug.Log("방 퇴장"); ExitRoomData exitRoomData = new ExitRoomData(roomNum); ExitRoomPacket exitRoomPacket = new ExitRoomPacket(exitRoomData); exitRoomPacket.SetPacketId((int)ClientPacketId.ExitRoom); DataPacket packet = new DataPacket(CreatePacket(exitRoomPacket), null); sendMsgs.Enqueue(packet); }