Пример #1
0
    public static void SendRequest <T>(object o, int msgType, MessegeCallBack msgCallBack = null, bool showlock = true)
    {
        if (showlock)
        {
            mNetmaskCtr.ShowLoading(true);
        }
        Action act = () =>
        {
            MessageData msg = new MessageData(o, msgType);
            msg.Write <T>(o, msgType);
            ResonponseCallDic[msgType] = msgCallBack;
            if (msgCallBack != null)
            {
                SetLockScreen(msgType, showlock);
            }
            ConnectionManager.Instance.CurrentConnection.SendMessage(msg.msgData);
        };

        if (mConnectionManager.CurrentConnection != null && mConnectionManager.CurrentConnection.Connected)
        {
            act();
        }
        else
        {
            //Connect(false, (result, sessionId) =>
            //{
            //    if (result)
            //    {
            //        act();
            //    }
            //});
        }
    }
Пример #2
0
    /// <summary>
    /// 提供给LUA过来调用的接口
    /// </summary>
    /// <param name="o"></param>
    /// <param name="msgType"></param>
    /// <param name="msgCallBack"></param>
    /// <param name="showlock"></param>
    public static void SendRequestLuaMsg(byte[] o, int msgType, MessegeCallBack msgCallBack = null, bool showlock = true)
    {
        Action act = () =>
        {
            MessageData msg = new MessageData(o, msgType);
            msg.WriteLua(o, msgType);
            ResonponseCallDic[msgType] = msgCallBack;
            if (msgCallBack != null)
            {
                SetLockScreen(msgType, showlock);
            }
            ConnectionManager.Instance.CurrentConnection.SendMessage(msg.msgData);
        };

        if (mConnectionManager.CurrentConnection.Connected)
        {
            act();
        }
        else
        {
            Connect(GameManager.Instance.Ip, GameManager.Instance.port, (result, sessionId) =>
            {
                if (result)
                {
                    act();
                }
            });
        }
    }
Пример #3
0
    /// <summary>
    /// Registers the response call back.
    /// </summary>
    /// <param name="msgType">Message type.</param>
    /// <param name="msgCallBack">Message call back.</param>
    /// <param name="gameType">Game type.  不为0的则为游戏内协议 </param>
    public static void RegisterResponseCallBack(int msgType, MessegeCallBack msgCallBack, int gameType = 0)
    {
        ResonponseCallDic[msgType] = msgCallBack;

        if (gameType == 0)
        {
            mHallTypeList.Add(msgType);
        }
        else
        {
            mGameTypeList.Add(msgType);
        }
    }
Пример #4
0
    bool OnExecReceive(Connection connection, int key, byte[] msgData)
    {
        if (key != 1500)
        {
            SQDebug.Log("收到消息ID为:" + key.ToString());
        }
        if (LockResponseId.Contains(key))
        {
            LockResponseId.Remove(key);
            if (LockResponseId.Count == 0)
            {
                //CommonUI.Instance.HideLockScreen();
            }
        }
        if (key != 1500)
        {
            mNetmaskCtr.ShowLoading(false);
        }
        if (msgData == null)
        {
            return(false);
        }

        MessageData msg = new MessageData(msgData);

        string jsonString = Encoding.UTF8.GetString(msgData, 0, msgData.Length);

        //if (key != 1102)
        //{
        //    SQDebug.PrintToScreen("Json=" + jsonString);
        //    SQDebug.Log("Json=" + jsonString);
        //}

        if (!ResonponseCallDic.ContainsKey(key))
        {
            SQDebug.Log("Client Don`t wanna handle this messege ,msgType : " + key);
            return(false);
        }
        MessegeCallBack callBack = ResonponseCallDic[key];

        if (callBack == null)
        {
            SQDebug.Log("callBack Is Null ,msgType : " + key);
            return(false);
        }
        else
        {
            //Global.It.mCommonBoxCtr.ShowLoading(false);
            //CommonUI.It.HideLoad();
        }

        if (!callBack.Method.IsStatic && callBack.Target.ToString() == "null")
        {
            SQDebug.LogWarning("对象已经被销毁了,而消息还想被处理");

            if (NetConnectStateCall != null)
            {
                //连接已释放
                NetConnectStateCall(NETSTATE.NETREALEASE, connection.SessionID);
            }
            return(false);
        }

        callBack(msg);
        return(true);
    }