void ToPacket(DefinedProtocol.eToServer toServer, object str) { DefinedStructure.PacketInfo packet; packet._id = (int)toServer; packet._data = new byte[1024]; byte[] temp = ConvertPacket.StructureToByteArray(str); for (int n = 0; n < temp.Length; n++) { packet._data[n] = temp[n]; } packet._totalSize = temp.Length; _toServerQueue.Enqueue(ConvertPacket.StructureToByteArray(packet)); }
void FromServerQueue() { try { while (true) { if (_fromServerQueue.Count != 0) { FromServerData fData = _fromServerQueue.Dequeue(); DefinedStructure.PacketInfo packet = new DefinedStructure.PacketInfo(); packet = (DefinedStructure.PacketInfo)ConvertPacket.ByteArrayToStructure(fData._data, packet.GetType(), fData._length); switch ((DefinedProtocol.eFromServer)packet._id) { #region LogIn / Character case DefinedProtocol.eFromServer.CheckLogIn: DefinedStructure.P_Check_ID_Pw pCheckLogIn = new DefinedStructure.P_Check_ID_Pw(); pCheckLogIn = (DefinedStructure.P_Check_ID_Pw)ConvertPacket.ByteArrayToStructure(packet._data, pCheckLogIn.GetType(), packet._totalSize); LogIn(pCheckLogIn._id, pCheckLogIn._pw, pCheckLogIn._index); break; case DefinedProtocol.eFromServer.OverlapCheck_ID: DefinedStructure.P_CheckOverlap pCheckOverlap_ID = new DefinedStructure.P_CheckOverlap(); pCheckOverlap_ID = (DefinedStructure.P_CheckOverlap)ConvertPacket.ByteArrayToStructure(packet._data, pCheckOverlap_ID.GetType(), packet._totalSize); OverlapCheck_ID(pCheckOverlap_ID._target, pCheckOverlap_ID._index); break; case DefinedProtocol.eFromServer.OverlapCheck_NickName: DefinedStructure.P_CheckOverlap pCheckOverlap_NickName = new DefinedStructure.P_CheckOverlap(); pCheckOverlap_NickName = (DefinedStructure.P_CheckOverlap)ConvertPacket.ByteArrayToStructure(packet._data, pCheckOverlap_NickName.GetType(), packet._totalSize); OverlapCheck_NickName(pCheckOverlap_NickName._target, pCheckOverlap_NickName._index); break; case DefinedProtocol.eFromServer.CheckEnroll: DefinedStructure.P_Check_ID_Pw pCheckEnroll = new DefinedStructure.P_Check_ID_Pw(); pCheckEnroll = (DefinedStructure.P_Check_ID_Pw)ConvertPacket.ByteArrayToStructure(packet._data, pCheckEnroll.GetType(), packet._totalSize); Enroll(pCheckEnroll._id, pCheckEnroll._pw, pCheckEnroll._index); break; case DefinedProtocol.eFromServer.CheckCharacterInfo: DefinedStructure.P_CheckRequest pCheckCharacInfo = new DefinedStructure.P_CheckRequest(); pCheckCharacInfo = (DefinedStructure.P_CheckRequest)ConvertPacket.ByteArrayToStructure(packet._data, pCheckCharacInfo.GetType(), packet._totalSize); CheckCharacInfo(pCheckCharacInfo._UUID); break; case DefinedProtocol.eFromServer.CreateCharacter: DefinedStructure.P_CreateCharacterInfo pCreateCharac = new DefinedStructure.P_CreateCharacterInfo(); pCreateCharac = (DefinedStructure.P_CreateCharacterInfo)ConvertPacket.ByteArrayToStructure(packet._data, pCreateCharac.GetType(), packet._totalSize); CreateCharacter(pCreateCharac._UUID, pCreateCharac._nickName, pCreateCharac._characterIndex, pCreateCharac._slot, pCreateCharac._startCardList); break; #endregion #region Card case DefinedProtocol.eFromServer.UserMyInfoData: DefinedStructure.P_UserMyInfoData pUserMyInfoData = new DefinedStructure.P_UserMyInfoData(); pUserMyInfoData = (DefinedStructure.P_UserMyInfoData)ConvertPacket.ByteArrayToStructure(packet._data, pUserMyInfoData.GetType(), packet._totalSize); UserMyInfoData(pUserMyInfoData._UUID, pUserMyInfoData._nickName); break; case DefinedProtocol.eFromServer.AddReleaseCard: DefinedStructure.P_ReleaseCard pReleaseCard = new DefinedStructure.P_ReleaseCard(); pReleaseCard = (DefinedStructure.P_ReleaseCard)ConvertPacket.ByteArrayToStructure(packet._data, pReleaseCard.GetType(), packet._totalSize); AddCardRelease(pReleaseCard._nickName, pReleaseCard._cardIndex); break; #endregion #region Battle case DefinedProtocol.eFromServer.GetBattleInfo: DefinedStructure.P_GetBattleInfo pGetBattleInfo = new DefinedStructure.P_GetBattleInfo(); pGetBattleInfo = (DefinedStructure.P_GetBattleInfo)ConvertPacket.ByteArrayToStructure(packet._data, pGetBattleInfo.GetType(), packet._totalSize); GetBattleInfo(pGetBattleInfo._roomNumber, pGetBattleInfo._UUID, pGetBattleInfo._nickName); break; case DefinedProtocol.eFromServer.GetAllCard: DefinedStructure.P_GetAllCard pGetAllCard = new DefinedStructure.P_GetAllCard(); pGetAllCard = (DefinedStructure.P_GetAllCard)ConvertPacket.ByteArrayToStructure(packet._data, pGetAllCard.GetType(), packet._totalSize); GetAllCard(pGetAllCard._roomNumber, pGetAllCard._nickNameArr); break; #endregion #region Shop case DefinedProtocol.eFromServer.GetShopInfo: DefinedStructure.P_GetShopInfo pGetShopInfo = new DefinedStructure.P_GetShopInfo(); pGetShopInfo = (DefinedStructure.P_GetShopInfo)ConvertPacket.ByteArrayToStructure(packet._data, pGetShopInfo.GetType(), packet._totalSize); GetShopInfo(pGetShopInfo._UUID, pGetShopInfo._nickName); break; case DefinedProtocol.eFromServer.TryBuyItem: DefinedStructure.P_TryBuyItem pTryBuyItem = new DefinedStructure.P_TryBuyItem(); pTryBuyItem = (DefinedStructure.P_TryBuyItem)ConvertPacket.ByteArrayToStructure(packet._data, pTryBuyItem.GetType(), packet._totalSize); BuyItem(pTryBuyItem._UUID, pTryBuyItem._nickName, pTryBuyItem._itemIndex, pTryBuyItem._exchangeType, pTryBuyItem._coin, pTryBuyItem._coinKind, pTryBuyItem._exchangeResult); break; #endregion case DefinedProtocol.eFromServer.GetFriendList: DefinedStructure.P_GetFriendList pGetFriendList = new DefinedStructure.P_GetFriendList(); pGetFriendList = (DefinedStructure.P_GetFriendList)ConvertPacket.ByteArrayToStructure(packet._data, pGetFriendList.GetType(), packet._totalSize); GetFriendList(pGetFriendList._UUID, pGetFriendList._nickName); break; } } Thread.Sleep(10); } } catch (ThreadInterruptedException e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } }