private void onReceivedResponsePack(byte[] body, int seq, int cmd, string cmdUri) { Log.i("Network", string.Concat(new object[] { "receive a packet , cmd = ", (CmdConst)cmd, ",seq = ", seq, " , len = ", body.Length })); SessionPack sessionPack = SessionPackMgr.getSessionPackBySeq(seq); if (sessionPack == null) { //FlowControl.onReceive(cmd, "", (uint) body.Length); this.onReceivedNotify(seq, cmd, body); } else { sessionPack.timeInRecvEnd = Util.getNowMilliseconds(); sessionPack.cancelTimeoutPoint(); sessionPack.mSendStatus = 4; if (sessionPack.mCmdID == 6) { sessionPack.mSendStatus = 5; } else if (sessionPack.mCmdID == 0x19) { sessionPack.mSendStatus = 5; sessionPack.mResponseBuffer = body; OnCallback.onSuccess(sessionPack); } else { if (sessionPack.mCmdID == 1 || sessionPack.mCmdID == 0xb2) { SessionPackMgr.setAuthStatus(0); } if (sessionPack.mCanceled) { Log.i("Network", "receive a packet been cancelled."); } else { byte[] key = sessionPack.getSessionKey(false); if (key == null) { Log.e("Network", "recv a packet without valid key, resend later."); sessionPack.mCacheBodyBuffer = null; sessionPack.mSendStatus = 0; } else { byte[] serverId = null; byte[] decryptedData = null; int ret = 0; if (!MMPack.DecodePack(ref decryptedData, body, key, ref serverId, ref ret)) { Log.e("Network", string.Concat(new object[] { "unpack error! cmd=", (CmdConst)cmd, " seq=", seq })); Connector.close(); if (ret == -13) { Log.e("Network", "session timeout"); SessionPackMgr.setSessionKey(null); } if (sessionPack.mRetryLeft > 0) { sessionPack.mCacheBodyBuffer = null; sessionPack.cancelTimeoutPoint(); sessionPack.mSendStatus = 0; } else { sessionPack.mSendStatus = 6; OnCallback.onError(sessionPack, PackResult.UNPACK_ERROR); } } else { sessionPack.mSendStatus = 5; sessionPack.mResponseBuffer = decryptedData; // string a = Util.byteToHexStr(decryptedData); object responseObject = null; if (!AuthPack.preProcessAuthPack(sessionPack, ref responseObject)) { sessionPack.mSendStatus = 6; OnCallback.onAllError(PackResult.AUTH_ERROR); Connector.onSendFailed(false, 3); } else { this.updateCookie(sessionPack.mCmdID, ret, serverId); if (responseObject != null) { sessionPack.mResponseObject = responseObject; } else { try { sessionPack.mResponseObject = sessionPack.onResponseParser(); } catch (Exception exception) { Log.e("Network", "onResponseParser failed," + exception.ToString()); OnCallback.onError(sessionPack, PackResult.PARSER_ERROR); return; } if (sessionPack.mResponseObject == null) { Log.e("Network", "onResponseParser failed"); OnCallback.onError(sessionPack, PackResult.PARSER_ERROR); return; } } OnCallback.onSuccess(sessionPack); } } } } } } }
private void packMapData() { MMPack packer = new MMPack(); packer.CountSims(this.mapsources, this.minX, this.maxX, this.minY, this.maxY); }
private bool preProcessPack(SessionPack sessionPack) { if (sessionPack.mRetryLeft <= 0) { Log.e("Network", "sender: retryLeft =0,cmd =:" + ((CmdConst)sessionPack.mCmdID)); sessionPack.mSendStatus = 6; OnCallback.onError(sessionPack, PackResult.RETRY_LIMIT); return(false); } if (sessionPack.mCanceled) { Log.e("Network", "not send packet been cancelled.)"); return(false); } if ((sessionPack.mCmdID != 6) && (sessionPack.mRetryLeft != 3)) { int newSeq = SessionPack.getSeqID(); Log.d("Network", string.Concat(new object[] { "resend pack, change seq ", sessionPack.mSeqID, " to new seq ", newSeq })); SessionPackMgr.changeSessionPackSeq(sessionPack.mSeqID, newSeq); sessionPack.mSeqID = newSeq; } sessionPack.mRetryLeft--; sessionPack.mSendStatus = 1; if (sessionPack.mCacheBodyBuffer == null) { // if ((sessionPack.mCmdID == 8) || (sessionPack.mCmdID == 0x19) || (sessionPack.mCmdID == 232 || (sessionPack.mCmdID == 233))) // { //sessionPack.mCacheBodyBuffer = sessionPack.requestToByteArray(); ////Log.e("Network", "mCacheBodyBuffer:"+); //if (sessionPack.mCacheBodyBuffer == null) //{ // Log.e("Network", "newsync check got bytearray failed."); // sessionPack.mSendStatus = 6; // OnCallback.onError(sessionPack, PackResult.PACK_ERROR); // return false; //} //if (sessionPack.mCmdID == 232 || sessionPack.mCmdID == 233) //{ // if (!MMPack.EncodePackMini(sessionPack)) // //if (!MMPack.EncodePack(sessionPack)) // { // Log.e("Network", "sender.encodePack failed,cmd= " + ((CmdConst)sessionPack.mCmdID)); // sessionPack.mCacheBodyBuffer = null; // sessionPack.mSendStatus = 6; // OnCallback.onError(sessionPack, PackResult.PACK_ERROR); // return false; // } //} //return true; // } if (!MMPack.EncodePackMini(sessionPack)) // if (!MMPack.EncodePack(sessionPack)) { Log.e("Network", "sender.encodePack failed,cmd= " + ((CmdConst)sessionPack.mCmdID)); sessionPack.mCacheBodyBuffer = null; sessionPack.mSendStatus = 6; OnCallback.onError(sessionPack, PackResult.PACK_ERROR); return(false); } } return(true); }