Example #1
0
    /// <summary>
    /// 发送登录消息
    /// </summary>
    /// <param name="loginMsg"></param>
    public void SendCSLoginMsg(ref DGPKG loginMsg, CSMsgDelegate callback, bool bLockScreen = false)
    {
        if (mGameServerHandler != null && mGameServerHandler.IsConnected())
        {
            if (bLockScreen)
            {
                //UI3System.lockScreen(902/*" 正在连接..."*/, 10.0f, () => {
                //        UISystemTip.ShowTip(901/*"网络已断开,点击重新连接"*/, ReConnect);
                //    });
            }

            MsgInfo msginfo = SetMsgInfo(loginMsg, callback);
            Send(ref loginMsg);
            mCSMsgAlreadySentList.Add(msginfo);
        }
        else if (LoginMgr.Instance.m_bNeedRecon)
        {
            // Modified by [email protected]
            // 目前在已上线版本中发现一个偶现但多次出现的bug:
            // CS.ReconnectReq有一定机率会被扔到集合m_lstBeforeReconnNotSendMsg当中,原因不明。
            // 所以,为避免这个情况再发生,这里作一下过滤
            if (loginMsg.header.msg_full_name != "CS.ReconnectReq")
            {
                MsgInfo msg = new MsgInfo(loginMsg, callback);
                m_lstBeforeReconnNotSendMsg.Add(msg);
            }

            //UISystemTip.ShowTip(901/*"网络已断开,点击重新连接"*/, ReConnect);
        }
    }
Example #2
0
 public void Set(DGPKG msg, CSMsgDelegate callback)
 {
     mMsg      = msg;
     mCallBack = callback;
     mValid    = true;
     mSentTime = UnityEngine.Time.realtimeSinceStartup;
 }
Example #3
0
    void ReConnRsp(CSMsgResult result, DGPKG msg)
    {
        //role login 成功
        if (result == CSMsgResult.NoError)
        {
            // 开启加密解密开关
            LoginMgr.Instance.ToggleGameServerMsgFilter(true);

            ReconnectRsp rsp = msg.body as ReconnectRsp;
            if (rsp == null)
            {
                return;
            }
            Debuger.LogError("reconnec rsp : " + rsp.result);
            if (rsp.result == 0)
            {
                Network.Instance.ReSendBeforeReconNotSendMsg();
                //重连成功
                return;
            }
            else
            {
                Debug.LogWarning("ReConnRsp, rsp.result: " + rsp.result);
            }
        }

        //SceneSys.Instance.GotoLoginScene();
        m_bNeedPing = false;
    }
Example #4
0
        public void HandleMsg(DGPKG msg)
        {
            CSMsgDelegate handle = null;

            if (m_dicHandle.TryGetValue(msg.header.msg_full_name, out handle))
            {
                handle(CSMsgResult.NoError, msg);
            }
        }
Example #5
0
 private void OnNotifyGiftBagItem(CSMsgResult result, DGPKG msg)
 {
     if (result != CSMsgResult.NoError || msg == null)
     {
         return;
     }
     CS.NotifyGiftBagItem rsp = (CS.NotifyGiftBagItem)msg.body;
     //PlayerDataMgrSys.Instance.AddGiftBagItem(rsp.gift_bag_item);
 }
Example #6
0
        private void OnNotifyRetryRoleLogin(CSMsgResult result, DGPKG msg)
        {
            LoginMgr.Instance.m_bNeedRecon = false;
            Network.Instance.Reset();

            // 先解除锁屏(如果有的话)
            //UI3System.unlockScreen();

            //UISystemTip.ShowTip(903/*"已退出登录,点击重新登录"*/, OnNotifyRetryRoleLoginCallback);
        }
Example #7
0
    public void ProcessMsg(DGPKG msg)
    {
//		Debug.Log("Start ProcessMsg");
        // 通过模块注册消息响应函数处理
        if (msg == null)
        {
            return;
        }

//		Debug.Log("ProcessMsg : " + (msg != null));
        if (msg.header.seq == 0)
        {
            NotifyMsgHandleMgr.Instance.HandleMsg(msg);
        }
        else
        {
            MsgInfo info = GetMsgInfo((int)msg.header.seq);
            if (info == null) // 最大的可能是,seq对应的响应来了多次(因为在目前的消息重发机制下,客户端可能会将具有同一seq的请求重发多次)
            {
                RemoveAlreadySentMsgBySeq(msg.header.seq);
            }
            else
            {
                RemoveAlreadySentMsg(info);

                //ssGame.NetDelay = Time.realtimeSinceStartup*1000 - msg.stHead.dwClientTime;
                if (info.Callback != null)
                {
                    if (msg.header != null && msg.body != null)
                    {
//                        Debug.Log("ProcessMsg : " + msg.header.msg_full_name);
                        //Debug.Log("ProcessMsg here GetType: " + msg.body.GetType());
                        //Debug.Log("ProcessMsg rsper: " + info.Callback.Target);
                        string fullName = msg.header.msg_full_name;
                        string typeName = msg.body.GetType().FullName;
                        if (fullName == typeName)
                        {
                            info.Callback(CSMsgResult.NoError, msg);
                        }
                        else
                        {
                            Debug.LogError(string.Format("{0} != {1}", fullName, typeName));
                        }
                        info.Reset();
                    }
                }
            }

            // 只要还有尚未被响应的请求,这里就不主动解锁
            if (!IsAnyRequestNotResponded())
            {
                UnlockScreen();
            }
        }
    }
Example #8
0
    /// <summary>
    /// 处理发送的消息对列
    /// </summary>
    private void HandleMsgSendQueue()
    {
//		Debug.LogError("Network HandleMsgSendQueue");
        LoginMgr login = LoginMgr.Instance;

        //如果网络断了,会在下一次发送数据的时候做重连处理。
        if (mCSMsgWaitSendList.Count > 0)
        {
//			Debug.LogError("Network HandleMsgSendQueue mCSMsgWaitSendList.Count > 0 " + mCSMsgWaitSendList.Count);
            //如果这个时候Socket已经挂了,自动重连服务器
            //if (mGameServerHandler.IsShutDown() && login.IsAccountLogin )
            //{
            //login.IsRoleLogin = false;
            //ConnectGameServer(login.OnReConnectSuccess);
            //}
            if (mGameServerHandler.IsConnected())
            {
//				Debug.LogError("Network HandleMsgSendQueue mGameServerHandler.IsConnected()");
                //Socket在连接状态才发送网络数据,其他状态不做处理,等待socekt连接成功和rolelogin成功
                //if ( login.IsRoleLogin )
                {
                    //foreach (MsgInfo msginfo in mCSMsgWaitSendList)
                    for (int i = 0; i < mCSMsgWaitSendList.Count; i++)
                    {
                        MsgInfo msginfo = mCSMsgWaitSendList[i];
                        if (msginfo != null)
                        {
                            DGPKG msg = msginfo.Msg;
                            Send(ref msg);
                            mCSMsgAlreadySentList.Add(msginfo);
//							Debug.LogError("Network HandleMsgSendQueue msginfo != null mCSMsgAlreadySentList.Add(msginfo)");
                        }
                    }
                    mCSMsgWaitSendList.Clear();
                }
//                 else
//                 {//只处理登陆协议
//                     foreach (MsgInfo msginfo in mCSMsgWaitSendList)
//                     {
//                         string msg_full_name = msginfo.Msg.header.msg_full_name;
//                         if ( msg_full_name == typeof(CS.RoleLoginReq).FullName )
//                         {
//                             DGPKG msg = msginfo.Msg;
//                             Send(ref msg);
//                             mCSMsgAlreadySentList.AddLast(msginfo);
//                             mCSMsgWaitSendList.Remove(msginfo);
//                             break;
//                         }
//                     }
//                }//end else //只处理登陆协议
            }//end else if
        }
    }
Example #9
0
 private void OnNotifyGmRsp(CSMsgResult result, DGPKG msg)
 {
     CS.GmRsp rsp = (CS.GmRsp)msg.body;
     if (result != CSMsgResult.NoError || msg == null)
     {
         return;
     }
     if (rsp.result == 0)
     {
         //GmMgr.Instance.DisplayMsg(rsp.msg);
     }
 }
Example #10
0
    /// <summary>
    /// 发送重连请求
    /// </summary>
    void ReConnReq(CSMsgDelegate callback)
    {
        // 保证加密解密开关是关闭的
        LoginMgr.Instance.ToggleGameServerMsgFilter(false);

        var Req = new ReconnectReq();

        Req.uid   = s_uid;
        Req.gcode = gcode;
        DGPKG msg = ProtocolDGlUtility.BuildDGMsg(Req);

        Network.Instance.SendCSLoginMsg(ref msg, callback);
    }
Example #11
0
    private MsgInfo SetMsgInfo(DGPKG msg, CSMsgDelegate callback)
    {
        int i = (int)msg.header.seq % kCSMsgCallArrayLength;

        if (mMsgInfoArray[i] == null)
        {
            mMsgInfoArray[i] = new MsgInfo(msg, callback);
        }
        else
        {
            mMsgInfoArray[i].Set(msg, callback);
        }
        return(mMsgInfoArray[i]);
    }
Example #12
0
 private void OnMineStateInfoNotify(CSMsgResult result, DGPKG msg)
 {
     Debug.LogError("OnMineStateInfoNotify " + result);
     if (result == CSMsgResult.NoError && msg != null && msg.header.msg_full_name == typeof(CS.MineStateInfoNotify).FullName)
     {
         Debug.LogError("OnMineStateInfoNotify " + msg.header.msg_full_name);
         var Rsp = (CS.MineStateInfoNotify)msg.body;
         if (Rsp == null)
         {
             Debug.LogError("OnMineStateInfoNotify Rsp == null");
             return;
         }
         // 发送充值成功消息
         //#if !UNITY_IPHONE
         //LuaManager.Instance.SendMsg(LuaMessage.MineStateInfoNotify,Rsp);
         //#endif
     }
 }
Example #13
0
    /// <summary>
    /// 处理收到的字节
    /// </summary>
    private void HandleRecvBytes()
    {
//		Debug.Log("HandleRecvBytes");
        for (int i = 0; i < MaxPkgPerFrame; i++)
        {
            if (mGameServerHandler != null)
            {
//				Debug.Log("ProcessMsg" + (mGameServerHandler != null));
                DGPKG msg = mGameServerHandler.ParseProtocolData(ref unpackDelegate) as DGPKG;
                if (msg == null)
                {
//					Debug.Log("ProcessMsg : " + (msg == null));
                    return;
                }
                ProcessMsg(msg);
            }
        }
    }
Example #14
0
    /// <summary>
    /// 在内部调用的一个发送CS数据报接口
    /// 由于被调用处已经做了Socket合法性检查, 所以这个私有函数内部就不做检查了
    /// 今后扩展前记得在外面做这个处理
    /// </summary>
    /// <param name="msg"></param>
    private void Send(ref DGPKG msg)
    {
        byte[] sendData    = msg.doSerialize();
        int    sendDataLen = sendData.Length;

        //Debug.Log("Send Msg [ID:]" + msg.header.msg_full_name + " [Len:]" + sendDataLen);

        // 过滤
        byte[] finalSentData = LoginMgr.Instance.FilterSentBytes(sendData);

        // 发送
        mGameServerHandler.Send(finalSentData, finalSentData.Length);

        if (msg.header.msg_full_name != "CS.P")
        {
            LoginMgr.Instance.SetLastPingTime();
        }
    }
Example #15
0
    public void ReSendBeforeReconNotSendMsg()
    {
        List <MsgInfo> copyCSMsgAlreadySentList = new List <MsgInfo>(mCSMsgAlreadySentList);

        mCSMsgAlreadySentList.Clear();
        for (int i = 0; i < copyCSMsgAlreadySentList.Count; ++i)
        {
            MsgInfo msginfo = copyCSMsgAlreadySentList[i];
            DGPKG   msg     = msginfo.Msg;
            if (msg.header.msg_full_name != "CS.ReconnectReq")
            {
                SendCSLoginMsg(ref msg, msginfo.Callback);
            }
        }
        copyCSMsgAlreadySentList.Clear();

        for (int i = 0; i < m_lstBeforeReconnNotSendMsg.Count; ++i)
        {
            DGPKG msg = m_lstBeforeReconnNotSendMsg[i].Msg;
            SendCSLoginMsg(ref msg, m_lstBeforeReconnNotSendMsg[i].Callback);
        }
        m_lstBeforeReconnNotSendMsg.Clear();
    }
Example #16
0
    /// <summary>
    /// 向游戏服务器发送数据包
    /// </summary>
    /// <param name="msg"></param>
    /// <returns></returns>
    private void SendCSMsg(ref DGPKG msg, CSMsgDelegate callback)
    {
        MsgInfo msginfo = SetMsgInfo(msg, callback);

        mCSMsgWaitSendList.Add(msginfo);
    }
Example #17
0
        private void OnNotifyRechargeResult(CSMsgResult result, DGPKG msg)
        {
            Debug.LogError("OnNotifyRechargeResult " + result);
            if (result == CSMsgResult.NoError && msg != null && msg.header.msg_full_name == typeof(CS.NotifyRechargeResult).FullName)
            {
                Debug.LogError("OnNotifyRechargeResult " + msg.header.msg_full_name);
                var Rsp = (CS.NotifyRechargeResult)msg.body;
                if (Rsp == null)
                {
                    Debug.LogError("OnNotifyRechargeResult Rsp == null");
                    return;
                }
                Debug.LogError("OnNotifyRechargeResult " + Rsp.result);
                if (Rsp.result != 0)
                {
                    //UITextSys.Instance.ShowText(Rsp.result);
                    return;
                }

                /*
                 * int amount = (int)(Rsp.new_diamond_num) - (int)(PlayerDataMgrSys.Instance.Diamond);
                 * Debug.LogError("Rechage Rsp.result == 0 here " + Rsp.new_diamond_num + " " + Rsp.new_vip_exp + " " + Rsp.new_vip_level + " " + amount);
                 * if (amount < 0)
                 *  amount = 0;
                 * Debug.LogError("Rechage Rsp.result == 0 here " + Rsp.new_diamond_num + " " + Rsp.new_vip_exp + " " + Rsp.new_vip_level + " " + amount);
                 * DCCoin.gain("充值", DCCoinType.DIAMOND, Rsp.add_diamond_num, Rsp.new_diamond_num);
                 * DCVirtualCurrency.paymentSuccess(Rsp.order_id,"",Rsp.recharge_money_num, "CNY", "支付宝");
                 * PlayerDataMgrSys.Instance.Diamond = Rsp.new_diamond_num;
                 * PlayerDataMgrSys.Instance.VipExp = Rsp.new_vip_exp;
                 * PlayerDataMgrSys.Instance.VipLevel = Rsp.new_vip_level;
                 *
                 */

                // Debug.LogError("Rechage Rsp.result == 0 here " + PlayerDataMgrSys.Instance.Diamond + " " + PlayerDataMgrSys.Instance.VipExp + " " + PlayerDataMgrSys.Instance.VipLevel);

//                EventDispatcher eventDistpatcher = EventDispatcher.Instance;
//                if (eventDistpatcher != null)
//                {
//                    Debug.LogError("if (eventDistpatcher != null)");
//                    eventDistpatcher.Dispatch(EnmEvn.EVN_PAY_SUCCESSFUL, null);
//                }
//                UIRechargeSuccess recharge = UI3System.createWindow<UIRechargeSuccess>();
//                if (recharge != null)
//                {
//                    Debug.LogError("recharge != null");
//                    recharge.SetValue((int)Rsp.add_diamond_num);
//                    recharge.bringTop();
//                    recharge.showWithScale();
//                    UIVIP uivip = UI3System.findWindow<UIVIP>();
//                    if (uivip != null && uivip.gameObject.activeInHierarchy == true)
//                    {
//                        Debug.LogError("uivip != null && uivip.gameObject.activeInHierarchy == true");
//                        uivip.updateObj();
//                    }
//                }

//                // 发送充值成功消息
//#if !UNITY_IPHONE
//                LuaManager.Instance.SendMsg(LuaMessage.RechargeSucceed);
//#endif
                //UISdkSys.Instance.OnPay(LoginMgr.Instance.Roleid + "",Rsp.order_id,(int)Rsp.recharge_money_num,"CNY");
            }
        }