public static IEnumerator Post(string url, CSLinkInfo csLinkInfo, int timeout, Action <string, int, long> OnSucc, Action <WebErrorCode> OnError) { byte[] byteData = ProtoSerAndUnSer.Serialize(csLinkInfo); CSServerReq req = new CSServerReq { Data = ByteString.AttachBytes(byteData), OpCode = OpCodeType.GetConnectServer }; byte[] sendData = ProtoSerAndUnSer.Serialize(req); WWWForm from = new WWWForm(); UnityWebRequest request = new UnityWebRequest(url, UnityWebRequest.kHttpVerbPOST) { uploadHandler = new UploadHandlerRaw(sendData), downloadHandler = new DownloadHandlerBuffer(), timeout = timeout }; request.SetRequestHeader("Content-Type", "multipart/form-data"); yield return(request.SendWebRequest()); //拿到信息 SCServerRes data = ProtoSerAndUnSer.UnSerialize <SCServerRes>(request.downloadHandler.data); if (data == null) { Debug.LogError("网关异常"); OnError?.Invoke(new WebErrorCode()); yield break; } if (data.Data != null && data.Code == (int)WebErrorCode.Success) { SCLinkInfo info = ProtoSerAndUnSer.UnSerialize <SCLinkInfo>(data.Data.ToByteArray()); Debug.Log(info); if (info != null) { string ip = StaticData.IntToIp((long)info.Ip); OnSucc?.Invoke(ip, info.Port, info.Uid); } } else { OnError?.Invoke((WebErrorCode)data.Code); } }
private void ProcessUnSeriMsgs(byte[] data) { var unSeriMsgs = ProtoSerAndUnSer.UnSerialize <SCServerRes>(data); OpCodeType opCode = unSeriMsgs.RtCode; StaticData.DebugGreen($"WebSocket Receive opCode:{opCode.ToString()}"); IMessage msg = ListOPRelation.GetRealMessageByOpCodeType(opCode, unSeriMsgs.Data.ToByteArray()); Debug.Log("ProcessUnSeriMsgs opCode = " + (int)opCode); Debug.Log("unSeriMsgs.Code = " + unSeriMsgs.Code); int code = (int)opCode; if (code >= 50000) { //账号被挤掉了 switch (code) { case 50020: //账户被挤掉 PushSystemAccountWasSqueezed(); break; case 60000: //服务器强制更新 ServerForcedUpdate(); break; default: //服务器推送 RigisterCmdPush.PushMsgHandle(msg, (int)opCode); break; } } else { //判定队列中是否有,如果没有,直接丢弃 if (QueueMsgBuiness.Count > 0) { if (QueueMsgBuiness.Peek().opCode != opCode) { return; } } if (QueueMsgBuiness.Count <= 0) //队列中没有东西,但是收到了返回 { //重置 SetOnceMessageCompelete(); return; } //出队 if (msg != null) { StaticData.DebugGreen($"WebSocket msg:{msg.ToString()} Dequeue"); } else { StaticData.DebugGreen($"==========消息返回:{QueueMsgBuiness.Peek().opCode}为null!"); } var msgItem = QueueMsgBuiness.Dequeue(); SetOnceMessageCompelete(); //正常请求 if (unSeriMsgs.Code != (int)WebErrorCode.Success) { ErrorInfo error = new ErrorInfo() { webErrorCode = (WebErrorCode)unSeriMsgs.Code, ErrorMessage = $"服务器异常{unSeriMsgs.Code}" }; msgItem.onFail(error); } else { msgItem.onSuccess((msg)); } } }
public static IMessage GetRealMessageByOpCodeType(OpCodeType codeType, byte[] data) { if ((int)codeType == 1) { return(ProtoSerAndUnSer.UnSerialize <SCLinkInfo>(data)); } if ((int)codeType == 2) { return(ProtoSerAndUnSer.UnSerialize <SCUserInfo>(data)); } if ((int)codeType == 3) { return(ProtoSerAndUnSer.UnSerialize <SCEmtpySetBasicsInfo>(data)); } if ((int)codeType == 5) { return(ProtoSerAndUnSer.UnSerialize <SCFriendList>(data)); } if ((int)codeType == 6) { return(ProtoSerAndUnSer.UnSerialize <SCApplyList>(data)); } if ((int)codeType == 7) { return(ProtoSerAndUnSer.UnSerialize <SCRecommendList>(data)); } if ((int)codeType == 8) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyApply>(data)); } if ((int)codeType == 9) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyAccept>(data)); } if ((int)codeType == 10) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyRepluse>(data)); } if ((int)codeType == 11) { return(ProtoSerAndUnSer.UnSerialize <SCEmtpyDelFriend>(data)); } if ((int)codeType == 12) { return(ProtoSerAndUnSer.UnSerialize <SCSearch>(data)); } if ((int)codeType == 13) { return(ProtoSerAndUnSer.UnSerialize <SCSearch>(data)); } if ((int)codeType == 14) { return(ProtoSerAndUnSer.UnSerialize <SCDiceResult>(data)); } if ((int)codeType == 15) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyRichManFinish>(data)); } if ((int)codeType == 16) { return(ProtoSerAndUnSer.UnSerialize <SCLucky>(data)); } if ((int)codeType == 17) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyCropSpeed>(data)); } if ((int)codeType == 18) { return(ProtoSerAndUnSer.UnSerialize <SCBuyProp>(data)); } if ((int)codeType == 19) { return(ProtoSerAndUnSer.UnSerialize <SCDrag>(data)); } if ((int)codeType == 20) { return(ProtoSerAndUnSer.UnSerialize <SCManorData>(data)); } if ((int)codeType == 21) { return(ProtoSerAndUnSer.UnSerialize <SCEmptFertilizer>(data)); } if ((int)codeType == 22) { return(ProtoSerAndUnSer.UnSerialize <SCEmptEradicate>(data)); } if ((int)codeType == 23) { return(ProtoSerAndUnSer.UnSerialize <SCPlantResult>(data)); } if ((int)codeType == 24) { return(ProtoSerAndUnSer.UnSerialize <SCHarvestData>(data)); } if ((int)codeType == 25) { return(ProtoSerAndUnSer.UnSerialize <SCStealData>(data)); } if ((int)codeType == 26) { return(ProtoSerAndUnSer.UnSerialize <SCEmptChangeLocationData>(data)); } if ((int)codeType == 27) { return(ProtoSerAndUnSer.UnSerialize <SCGoodSellData>(data)); } if ((int)codeType == 28) { return(ProtoSerAndUnSer.UnSerialize <SCEmptGoodLock>(data)); } if ((int)codeType == 29) { return(ProtoSerAndUnSer.UnSerialize <SCManorFriendData>(data)); } if ((int)codeType == 30) { return(ProtoSerAndUnSer.UnSerialize <SCUnlockArea>(data)); } if ((int)codeType == 31) { return(ProtoSerAndUnSer.UnSerialize <CSRoleSInfo>(data)); } if ((int)codeType == 32) { return(ProtoSerAndUnSer.UnSerialize <SCEmptChoiceRole>(data)); } if ((int)codeType == 33) { return(ProtoSerAndUnSer.UnSerialize <SCBuyProp>(data)); } if ((int)codeType == 34) { return(ProtoSerAndUnSer.UnSerialize <SCPromotionsGoodsInfo>(data)); } if ((int)codeType == 35) { return(ProtoSerAndUnSer.UnSerialize <SCGoldJewelBuy>(data)); } if ((int)codeType == 36) { return(ProtoSerAndUnSer.UnSerialize <SCBuySection>(data)); } if ((int)codeType == 37) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyClearance>(data)); } if ((int)codeType == 38) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyOrnamentalRecycle>(data)); } if ((int)codeType == 39) { return(ProtoSerAndUnSer.UnSerialize <SCTreasureChestResult>(data)); } if ((int)codeType == 40) { return(ProtoSerAndUnSer.UnSerialize <SCGetTreasureChestAwardResult>(data)); } if ((int)codeType == 43) { return(ProtoSerAndUnSer.UnSerialize <SCBuyExtraStory>(data)); } if ((int)codeType == 44) { return(ProtoSerAndUnSer.UnSerialize <SCMailInfo>(data)); } if ((int)codeType == 45) { return(ProtoSerAndUnSer.UnSerialize <SCAccessoryInWarehouse>(data)); } if ((int)codeType == 46) { return(ProtoSerAndUnSer.UnSerialize <SCAccessory>(data)); } if ((int)codeType == 47) { return(ProtoSerAndUnSer.UnSerialize <SCEverydayAward>(data)); } if ((int)codeType == 49) { return(ProtoSerAndUnSer.UnSerialize <SCFriendStealInfo>(data)); } if ((int)codeType == 50) { return(ProtoSerAndUnSer.UnSerialize <SCCurrentExperience>(data)); } if ((int)codeType == 53) { return(ProtoSerAndUnSer.UnSerialize <SCWorkShedSpeedUp>(data)); } if ((int)codeType == 54) { return(ProtoSerAndUnSer.UnSerialize <SCTreasureChestUnlockInfo>(data)); } if ((int)codeType == 55) { return(ProtoSerAndUnSer.UnSerialize <SCTreasureChestSpeed>(data)); } if ((int)codeType == 56) { return(ProtoSerAndUnSer.UnSerialize <SCUseWarehouseGoods>(data)); } if ((int)codeType == 57) { return(ProtoSerAndUnSer.UnSerialize <SCManorLogs>(data)); } if ((int)codeType == 58) { return(ProtoSerAndUnSer.UnSerialize <SCPurchaseRole>(data)); } if ((int)codeType == 59) { return(ProtoSerAndUnSer.UnSerialize <SCEmptySwitchoverRole>(data)); } if ((int)codeType == 60) { return(ProtoSerAndUnSer.UnSerialize <SCEmptySwitchoverCostume>(data)); } if ((int)codeType == 61) { return(ProtoSerAndUnSer.UnSerialize <SCOneselfMarmot>(data)); } if ((int)codeType == 62) { return(ProtoSerAndUnSer.UnSerialize <SCFriendMarmot>(data)); } if ((int)codeType == 63) { return(ProtoSerAndUnSer.UnSerialize <SCEmtpyAdvExtraStory>(data)); } if ((int)codeType == 64) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyWorldChat>(data)); } if ((int)codeType == 65) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyPrivateChat>(data)); } if ((int)codeType == 66) { return(ProtoSerAndUnSer.UnSerialize <SCEntranceRoom>(data)); } if ((int)codeType == 67) { return(ProtoSerAndUnSer.UnSerialize <SCEmtpyGuessing>(data)); } if ((int)codeType == 68) { return(ProtoSerAndUnSer.UnSerialize <SCEmtpyChannelChat>(data)); } if ((int)codeType == 69) { return(ProtoSerAndUnSer.UnSerialize <SCRoomListInfo>(data)); } if ((int)codeType == 70) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyLoginGetFavorable>(data)); } if ((int)codeType == 71) { return(ProtoSerAndUnSer.UnSerialize <SCEmptySendNPCGift>(data)); } if ((int)codeType == 72) { return(ProtoSerAndUnSer.UnSerialize <SCEmtpySectionAddFavorable>(data)); } if ((int)codeType == 74) { return(ProtoSerAndUnSer.UnSerialize <SCFavorableInfo>(data)); } if ((int)codeType == 75) { return(ProtoSerAndUnSer.UnSerialize <SCEmtpyMoveLocation>(data)); } if ((int)codeType == 76) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyDepartureRoom>(data)); } if ((int)codeType == 78) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyMotion>(data)); } if ((int)codeType == 79) { return(ProtoSerAndUnSer.UnSerialize <SCMarmotAwardInfo>(data)); } if ((int)codeType == 80) { return(ProtoSerAndUnSer.UnSerialize <SCEmtpyChangeMailState>(data)); } if ((int)codeType == 81) { return(ProtoSerAndUnSer.UnSerialize <SCBuyProp>(data)); } if ((int)codeType == 82) { return(ProtoSerAndUnSer.UnSerialize <SCEmtpyHeartBeat>(data)); } if ((int)codeType == 83) { return(ProtoSerAndUnSer.UnSerialize <SCEmtpyAccumulateSignIn>(data)); } if ((int)codeType == 84) { return(ProtoSerAndUnSer.UnSerialize <SCEmptySaveGuidance>(data)); } if ((int)codeType == 87) { return(ProtoSerAndUnSer.UnSerialize <SCManorGuidance>(data)); } if ((int)codeType == 88) { return(ProtoSerAndUnSer.UnSerialize <SCStealManorGuidance>(data)); } if ((int)codeType == 91) { return(ProtoSerAndUnSer.UnSerialize <SCGetTaskInfo>(data)); } if ((int)codeType == 92) { return(ProtoSerAndUnSer.UnSerialize <SCGetTaskAward>(data)); } if ((int)codeType == 93) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyLogoutAccount>(data)); } if ((int)codeType == 94) { return(ProtoSerAndUnSer.UnSerialize <SCCdkAward>(data)); } if ((int)codeType == 95) { return(ProtoSerAndUnSer.UnSerialize <SCDealInfo>(data)); } if ((int)codeType == 96) { return(ProtoSerAndUnSer.UnSerialize <SCSubmintDeal>(data)); } if ((int)codeType == 97) { return(ProtoSerAndUnSer.UnSerialize <SCRefreshDeal>(data)); } if ((int)codeType == 98) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyAdvSkipDeal>(data)); } if ((int)codeType == 99) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyEntranceSection>(data)); } if ((int)codeType == 100) { return(ProtoSerAndUnSer.UnSerialize <SCCropMature>(data)); } if ((int)codeType == 101) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyManorDecorateRotate>(data)); } if ((int)codeType == 102) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyLike>(data)); } if ((int)codeType == 103) { return(ProtoSerAndUnSer.UnSerialize <SCFriendCostume>(data)); } if ((int)codeType == 104) { return(ProtoSerAndUnSer.UnSerialize <SCOnceWatering>(data)); } if ((int)codeType == 105) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyDerectUp>(data)); } if ((int)codeType == 50002) { return(ProtoSerAndUnSer.UnSerialize <SCFriendApplyPushMsg>(data)); } if ((int)codeType == 50003) { return(ProtoSerAndUnSer.UnSerialize <SCFriendAcceptPushMsg>(data)); } if ((int)codeType == 50004) { return(ProtoSerAndUnSer.UnSerialize <SCFriendRepulsePushMsg>(data)); } if ((int)codeType == 50005) { return(ProtoSerAndUnSer.UnSerialize <SCFriendDeletePushMsg>(data)); } if ((int)codeType == 50006) { return(ProtoSerAndUnSer.UnSerialize <SCSendMailPushMsg>(data)); } if ((int)codeType == 50009) { return(ProtoSerAndUnSer.UnSerialize <SCNotePushMess>(data)); } if ((int)codeType == 50010) { return(ProtoSerAndUnSer.UnSerialize <SCNotePushMess>(data)); } if ((int)codeType == 50011) { return(ProtoSerAndUnSer.UnSerialize <SCChat>(data)); } if ((int)codeType == 50012) { return(ProtoSerAndUnSer.UnSerialize <SCChat>(data)); } if ((int)codeType == 50013) { return(ProtoSerAndUnSer.UnSerialize <SCChat>(data)); } if ((int)codeType == 50014) { return(ProtoSerAndUnSer.UnSerialize <SCEntranceRoomInfo>(data)); } if ((int)codeType == 50015) { return(ProtoSerAndUnSer.UnSerialize <SCMoveLocation>(data)); } if ((int)codeType == 50016) { return(ProtoSerAndUnSer.UnSerialize <SCpushGuessingInfo>(data)); } if ((int)codeType == 50017) { return(ProtoSerAndUnSer.UnSerialize <SCpushMotion>(data)); } if ((int)codeType == 50018) { return(ProtoSerAndUnSer.UnSerialize <SCDepartureRoom>(data)); } if ((int)codeType == 50019) { return(ProtoSerAndUnSer.UnSerialize <SCActivityFinish>(data)); } if ((int)codeType == 50020) { return(ProtoSerAndUnSer.UnSerialize <SCRepetitionRegister>(data)); } if ((int)codeType == 50021) { return(ProtoSerAndUnSer.UnSerialize <SCEmtpyMailPushMsg>(data)); } if ((int)codeType == 60000) { return(ProtoSerAndUnSer.UnSerialize <SCEmptyCoerceRenewal>(data)); } return(null); }