コード例 #1
0
    //消息分发
    public void DispatchMsgEvent(NetMsgBase msg)
    {
        // Debug.Log("接收协议" + msg.MsgType.ToString());

        if (msg.MsgType == eNetMsgType.FRAME)
        {
            NetFrameMsg realMSg = (NetFrameMsg)msg;
            if (realMSg == null)
            {
                Debug.Log("协议 error");
                return;
            }
            GameMain.GetInstance().logicManager.AddNewFrame(realMSg.frame);
        }
        else if (msg.MsgType == eNetMsgType.SYS)
        {
            Debug.Log("sys init");
            NetSysMsg realMSg = (NetSysMsg)msg;
            GameMain.GetInstance().logicManager.Init(realMSg.localPid);
        }
        //string name = protocol.GetName();
        //Debug.Log("分发处理消息 " + name);
        //if (eventDict.ContainsKey(name))
        //{
        //    eventDict[name](protocol);
        //}
        //if (onceDict.ContainsKey(name))
        //{
        //    onceDict[name](protocol);
        //    onceDict[name] = null;
        //    onceDict.Remove(name);
        //}
    }
コード例 #2
0
    //消息处理
    private void ProcessData()
    {
        if (buffCount < sizeof(Int32))
        {
            return;
        }



        Array.Copy(readBuff, lenBytes, sizeof(Int32));
        msgLength = BitConverter.ToInt32(lenBytes, 0);
        if (buffCount < msgLength + sizeof(Int32))
        {
            return;
        }

        ByteBuffer buffer = new ByteBuffer(readBuff, sizeof(Int32), msgLength);

        NetMsgBase msg = ReadAndDecode(buffer);

        msgDist.msgList.Enqueue(msg);

        int count = buffCount - msgLength - sizeof(Int32);

        //使用循环队列避免无意义的复制开销
        Array.Copy(readBuff, sizeof(Int32) + msgLength, readBuff, 0, count);
        buffCount = count;
        if (buffCount > 0)
        {
            ProcessData();
        }
    }
コード例 #3
0
    static int _CreateTCPSocketMsg(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                TCPSocketMsg obj = new TCPSocketMsg();
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (count == 2 && TypeChecker.CheckTypes <ushort, NetMsgBase>(L, 1))
            {
                ushort       arg0 = (ushort)LuaDLL.lua_tonumber(L, 1);
                NetMsgBase   arg1 = (NetMsgBase)ToLua.ToObject(L, 2);
                TCPSocketMsg obj  = new TCPSocketMsg(arg0, arg1);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: TCPSocketMsg.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
コード例 #4
0
 public void PushSendMsg(NetMsgBase msg)
 {
     lock (sendQueue)
     {
         sendQueue.Enqueue(msg);
     }
 }
コード例 #5
0
    public override void ProcessEvent(MsgBase msg)
    {
        if (callBack != null)
        {
            //网络数据
            if (msg.GetState() != 127)
            {
                NetMsgBase tmpBase = (NetMsgBase)msg;


                byte[] proto = tmpBase.GetProtoBuffer();

                if (proto != null && proto.Length > 0)
                {
                    LuaByteBuffer buffer = new LuaByteBuffer(proto);

                    callBack.Call(true, tmpBase.msgId, tmpBase.GetState(), buffer);
                }
                else
                {
                    callBack.Call(true, tmpBase.msgId, tmpBase.GetState());
                }
            }
            else
            {
                // 其它消息

                //Debug.Log("122222222222221tmpBase.GetState()==" + msg.GetState());
                callBack.Call(false, msg);
            }
        }
    }
コード例 #6
0
 public void PutSendMsgToPool(NetMsgBase msg)
 {
     lock (sendMsgPool)
     {
         sendMsgPool.Enqueue(msg);
     }
 }
コード例 #7
0
 public void PushRecvMsg(NetMsgBase msg)
 {
     lock (recvQueue)
     {
         recvQueue.Enqueue(msg);
     }
 }
コード例 #8
0
    public override void ProcessEvent(MsgBase msg)
    {
        if (callback == null)
        {
            return;
        }

        // 从网络来的msg 和从框架其他模块来的数据不一样
        if (msg.GetState() != 127)                  // 从网络来的
        {
            NetMsgBase netMsg = (NetMsgBase)msg;

            byte[] proto = netMsg.GetProtoBuffer();

            // 转成lua能识别的字符串
            LuaByteBuffer buffer = new LuaByteBuffer(proto);

            // 第一个参数代表是否是网络来的
            callback.Call(true, netMsg.msgID, netMsg.GetState(), buffer);
        }
        else                                        // 从框架来的
        {
            callback.Call(false, msg);
        }
    }
コード例 #9
0
    private void TcpLoginMsgButtonClick()
    {
        Login login = new Login();

        login.UserName = "******";
        login.PassWord = "******";

        byte[] bodys = login.ToByteArray();

        string strs = "";

        for (int i = 0; i < bodys.Length; i++)
        {
            strs = strs + " " + bodys[i];
        }
        int bodycount = bodys.Length;

        byte[] bodycountbytes   = BitConverter.GetBytes(bodycount);
        byte[] headbackMsgbytes = BitConverter.GetBytes((ushort)TCPEvent.TcpBackLoginMsg);

        NetMsgBase ba  = new NetMsgBase(FrameTools.CombomBinaryArray(bodycountbytes, FrameTools.CombomBinaryArray(headbackMsgbytes, bodys)));
        TCPMsg     msg = new TCPMsg((ushort)TCPEvent.TcpSendLoginMsg, ba);

        SendMsg(msg);
    }
コード例 #10
0
    /// <summary>
    /// 接收消息
    /// </summary>
    public void RecvUpdate()
    {
        while (recvMsgPool.Count > 0)
        {
            NetMsgBase tmpMsg = recvMsgPool.Dequeue();

            AnalyseData(tmpMsg);
        }
    }
コード例 #11
0
 public void Update()
 {
     if (recvMsgPool != null)
     {
         while (recvMsgPool.Count > 0)
         {
             NetMsgBase tmpBase = recvMsgPool.Dequeue();
             AnalyseData(tmpBase);
         }
     }
 }
コード例 #12
0
 private void ReceiveCallBack(bool isSuccess, SocketError errorType, string exception, byte[] msgBytes, string str)
 {
     if (isSuccess)
     {
         NetMsgBase msg = new NetMsgBase(msgBytes);
         PushRecvMsg(msg);
     }
     else
     {//处理接收消息发生错误
     }
 }
コード例 #13
0
 public void Update()
 {
     if (recvQueue != null)
     {
         if (recvQueue.Count > 0)
         {
             NetMsgBase msg = recvQueue.Dequeue();
             AnalysisMsg(msg);
         }
     }
 }
コード例 #14
0
ファイル: NetWorkToSever.cs プロジェクト: yutongzhu/UtoVR
 public void Update()
 {
     if (recvMsgPool != null)
     {
         while (recvMsgPool.Count > 0)
         {
             NetMsgBase tmp = recvMsgPool.Dequeue();
             MsgCenter.instance.SendToMsg(tmp);
         }
     }
 }
コード例 #15
0
ファイル: NetWorkToSever.cs プロジェクト: yutongzhu/UtoVR
 void AsysnRecvCallBack(bool sucess, ErrorSocket error, string exception, byte[] byteMessage, string strMsg)
 {
     if (sucess)
     {
         NetMsgBase tmp = new NetMsgBase(byteMessage);
     }
     else
     {
         //处理错误信息
     }
 }
コード例 #16
0
 public void Update()
 {
     if (recvMsgPool != null)
     {
         while (recvMsgPool.Count > 0)
         {
             NetMsgBase tmp = recvMsgPool.Dequeue();
             AnalyseData(tmp);
         }
     }
     //clientSocket.Recive();
 }
コード例 #17
0
    private void TcpSendMsgButtonClick()
    {
        string body = "body content = asdfasdf";

        byte[] data      = Encoding.Default.GetBytes(body);
        int    bodycount = body.Length;

        byte[] bodycountbytes   = BitConverter.GetBytes(bodycount);
        byte[] headbackMsgbytes = BitConverter.GetBytes((ushort)TCPEvent.TcpSendMsgBack);

        NetMsgBase ba  = new NetMsgBase(FrameTools.CombomBinaryArray(bodycountbytes, FrameTools.CombomBinaryArray(headbackMsgbytes, data)));
        TCPMsg     msg = new TCPMsg((ushort)TCPEvent.TcpSendMsg, ba);

        SendMsg(msg);
    }
コード例 #18
0
 /// <summary>
 /// 不断发送消息给服务端
 /// </summary>
 private void LoodSendMsg()
 {
     while (clientSocket != null && clientSocket.IsConnect())
     {
         lock (sendMsgPool)
         {
             while (sendMsgPool.Count > 0)
             {
                 NetMsgBase body = sendMsgPool.Dequeue();
                 clientSocket.AsyncSend(body.GetNetBytes(), CallBackSend);
             }
         }
         Thread.Sleep(100);
     }
 }
コード例 #19
0
 void LoopSendMsg()
 {
     while (clientSocket != null && clientSocket.isConnected())
     {
         lock (sendMsgPool)
         {
             while (sendMsgPool.Count > 0)
             {
                 NetMsgBase tmpBody = sendMsgPool.Dequeue();
                 clientSocket.AsynSend(tmpBody.GetNetBytes(), CallBackSend);
             }
         }
         Thread.Sleep(100);
     }
 }
コード例 #20
0
 void LoopSendMsg()
 {
     while (clientSocket.isConnect())
     {
         lock (sendQueue)
         {
             while (sendQueue.Count > 0)
             {
                 NetMsgBase msg = sendQueue.Dequeue();
                 clientSocket.SendAsyn(msg.GetNetBytes(), SendCallBack);
             }
         }
         Thread.Sleep(100);
     }
 }
コード例 #21
0
    private void LoopSendMsg()
    {
        while (clientSocket != null && clientSocket.IsConnect)
        {
            lock (sendMsgPool) {
                while (sendMsgPool.Count > 0)
                {
                    NetMsgBase tmpSendMsg = sendMsgPool.Dequeue();

                    clientSocket.AsyncSend(tmpSendMsg.GetNetBytes(), OnSendCallback);
                }
            }

            Thread.Sleep(100);
        }
    }
コード例 #22
0
 static int ChangerMsg(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         TCPSocketMsg obj  = (TCPSocketMsg)ToLua.CheckObject <TCPSocketMsg>(L, 1);
         ushort       arg0 = (ushort)LuaDLL.luaL_checknumber(L, 2);
         NetMsgBase   arg1 = (NetMsgBase)ToLua.CheckObject <NetMsgBase>(L, 3);
         obj.ChangerMsg(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
コード例 #23
0
    static int get_netMsg(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            TCPSocketMsg obj = (TCPSocketMsg)o;
            NetMsgBase   ret = obj.netMsg;
            ToLua.PushObject(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index netMsg on a nil value" : e.Message));
        }
    }
コード例 #24
0
    static int set_netMsg(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            TCPSocketMsg obj  = (TCPSocketMsg)o;
            NetMsgBase   arg0 = (NetMsgBase)ToLua.CheckObject <NetMsgBase>(L, 2);
            obj.netMsg = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index netMsg on a nil value" : e.Message));
        }
    }
コード例 #25
0
 public override void ProcessEvent(MsgBase tmpMsg)
 {
     if (callBack != null)
     {
         //从网络来
         if (tmpMsg.GetState() != 127)
         {
             NetMsgBase    tmpBase = (NetMsgBase)tmpMsg;
             byte[]        proto   = tmpBase.GetProtoBuffer();
             LuaByteBuffer buffer  = new LuaByteBuffer(proto);
             callBack.Call(true, tmpBase.msgId, tmpBase.GetState(), buffer);
         }
         else  //从框架其他模块来的
         {
             callBack.Call(false, tmpMsg);
         }
     }
 }
コード例 #26
0
    public override void ProcessEvent(MsgBase tmpMsg)
    {
        switch (tmpMsg.msgId)
        {
        case (ushort)TCPEvent.TcpSendMsgBack:
            Debug.Log("TcpSendMsgBack");
            break;

        case (ushort)TCPEvent.TcpBackLoginMsg:

            NetMsgBase tCPMsg  = (NetMsgBase)tmpMsg;
            IMessage   IMLogin = new Login();
            Login      login   = new Login();
            login = (Login)IMLogin.Descriptor.Parser.ParseFrom(tCPMsg.GetBodyBytes());
            Debug.Log("login.UserName = "******"login.PassWord = " + login.PassWord);
            break;
        }
    }
コード例 #27
0
 public override void ProcessEvent(MsgBase msg)
 {
     //从网络来的msg和从框架来的数据不一样
     if (luaFunctionCallBack != null)
     {
         //从网络来的msg
         if (msg.GetState() != 127)
         {
             NetMsgBase    netMsgBase = msg as NetMsgBase;
             byte[]        proto      = netMsgBase.GetProtoBuffer();
             LuaByteBuffer buffer     = new LuaByteBuffer(proto);
             luaFunctionCallBack.Call(true, netMsgBase.msgId, netMsgBase.GetState(), buffer);
         }
         else
         {
             luaFunctionCallBack.Call(false, msg);
         }
     }
 }
コード例 #28
0
 public TCPMsg(ushort tmpId, NetMsgBase tmpBase)
 {
     this.msgId  = tmpId;
     this.netMsg = tmpBase;
 }
コード例 #29
0
    void PutRecvMsgToPool(byte[] recvMsg)
    {
        NetMsgBase tmp = new NetMsgBase(recvMsg);

        recvMsgPool.Enqueue(tmp);
    }
コード例 #30
0
 void AnalysisMsg(NetMsgBase msg)
 {
     MsgCenter.Instance.HandleMsg(msg);
 }