Esempio n. 1
0
 public bool checkTryAutoAuth()
 {
     if (!SessionPackMgr.getAccount().isValid())
     {
         Log.e("Network", "cannot auto-auth without valid account.");
         this.closeSender();
         return(false);
     }
     if (mRetryAuthLeft <= 0)
     {
         if (mRetryAuthLeft == 0)
         {
             Log.e("Network", " autoAuth no retry left");
             mRetryAuthLeft = -1;
         }
         return(false);
     }
     SessionPackMgr.getPackEx(delegate(SessionPack pack)
     {
         if (pack.mCacheBodyBuffer != null)
         {
             Log.i("Network", "clearn cache body before autoauth, cmdUri = " + pack.mCmdUri);
             pack.mCacheBodyBuffer = null;
         }
         return(true);
     });
     Log.i("Network", "CMD need autoauth, autoAuthLeft:" + mRetryAuthLeft);
     mRetryAuthLeft--;
     SessionPackMgr.putToHead(AuthPack.makeAutoAuthPack(2));
     return(true);
 }
Esempio n. 2
0
        private bool checkSessionKey(ref SessionPack sessionPack)
        {
            if (sessionPack.mCmdID == 1 || sessionPack.mCmdID == 0xb2)
            {
                AuthPack.updateAccountInfoFromAuth(sessionPack.mRequestObject);

                return(true);
            }

            if (sessionPack.mCmdID == 0x20)
            {
                AuthPack.updateAccountInfoFromNewReg(sessionPack.mRequestObject);
                return(true);
            }
            if (sessionPack.mCmdID == 0x1f)
            {
                AuthPack.updateAccountInfoFromReg(sessionPack.mRequestObject);
                return(true);
            }
            if (sessionPack.mCmdID == 232 || sessionPack.mCmdID == 233)
            {
                return(true);
            }
            if (!this.needSessionKey(sessionPack))
            {
                return(true);
            }
            if (SessionPackMgr.isValidSessionKey())
            {
                return(true);
            }
            this.checkTryAutoAuth();
            return(false);
        }
Esempio n. 3
0
        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);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public bool sendAutoAuthPack()
        {
            SessionPack sessionPack = AuthPack.makeAutoAuthPack(2);

            return(this.sendPack(sessionPack));
        }