Пример #1
0
    static int TestBytes(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 4);
        CGameSession obj  = (CGameSession)LuaScriptMgr.GetNetObjectSelf(L, 1, "CGameSession");
        CS2CPrtcData arg0 = (CS2CPrtcData)LuaScriptMgr.GetNetObject(L, 2, typeof(CS2CPrtcData));
        bool         arg1 = LuaScriptMgr.GetBoolean(L, 3);
        bool         arg2 = LuaScriptMgr.GetBoolean(L, 4);

        obj.TestBytes(arg0, arg1, arg2);
        return(0);
    }
Пример #2
0
    private int AddNewProtocol(CS2CPrtcData prct)
    {
        //if (prct.Type == S2CTypePing)
        {
            // 记录上次ping时间
            _LastRecvAliveTime = DateTime.Now.Ticks;
        }

        int iSize = 0;

        lock (_CsSession)
        {
            _NewPrtcList.Add(prct);
            iSize = _NewPrtcList.Count;
        }

        return(iSize);
    }
Пример #3
0
    private void ProcessProtocol(CS2CPrtcData p, bool isSimple)
    {
        if (p != null && p.Type > 0)
        {
#if false
            // test 1
            BytesDecodeTest(p);
            // test 2
            TestBytes(p, false, false);
#endif

            var isSpecial = _ProcessBeginTicks > 0 && p.TimeStamp < _ProcessBeginTicks;

            IntPtr L = LuaScriptMgr.Instance.GetL();
            if (L != IntPtr.Zero)
            {
                int oldTop = LuaDLL.lua_gettop(L);
                LuaDLL.lua_getglobal(L, "ProcessProtocol");
                if (!LuaDLL.lua_isnil(L, -1))
                {
                    LuaDLL.lua_pushinteger(L, p.Type);
                    if (p.Buffer != null)
                    {
                        LuaDLL.lua_pushlstring(L, p.Buffer, p.Buffer.Length);
                    }
                    else
                    {
                        LuaDLL.lua_pushstring(L, String.Empty);
                    }
                    LuaDLL.lua_pushboolean(L, isSpecial);
                    LuaDLL.lua_pushboolean(L, isSimple);

                    if (LuaDLL.lua_pcall(L, 4, 0, 0) != 0)
                    {
                        HobaDebuger.LogLuaError(LuaDLL.lua_tostring(L, -1));
                    }
                }
                LuaDLL.lua_settop(L, oldTop);
            }
        }
    }
Пример #4
0
    // 真实服务器模式下 接收协议处理
    private static void OnReceiveSocketPrtc(ExSocket exSocket, byte[] data)
    {
        if (data == null || data.Length < sizeof(int))
        {
            HobaDebuger.LogWarning("Protocol Data Length is too short");
            return;
        }

        int id = System.BitConverter.ToInt32(data, 0);

        byte[] pbs = null;
        if (data.Length > sizeof(int))
        {
            int len = data.Length - sizeof(int);
            pbs = new byte[len];
            System.Buffer.BlockCopy(data, 4, pbs, 0, len);
        }

        CS2CPrtcData prtc = _PrtcDataPool.GetObject();

        prtc.Set(id, pbs);
        Instance().AddNewProtocol(prtc);
    }
Пример #5
0
    private void BytesDecodeTest(CS2CPrtcData p)
    {
        if (p == null || p.Type != 10531)
        {
            return;
        }

        const int count     = 10000;
        Single    totalTime = 0;

        IntPtr L = LuaScriptMgr.Instance.GetL();

        if (L != IntPtr.Zero)
        {
            var startTime = DateTime.Now;
            for (int i = 0; i < count; i++)
            {
                int oldTop = LuaDLL.lua_gettop(L);
                LuaDLL.lua_getglobal(L, "ProcessMoveProtocol2");
                if (!LuaDLL.lua_isnil(L, -1))
                {
                    LuaDLL.lua_pushinteger(L, p.Type);
                    LuaDLL.lua_pushlstring(L, p.Buffer, p.Buffer.Length);
                    LuaDLL.lua_pushboolean(L, false);
                    LuaDLL.lua_pushboolean(L, false);

                    if (LuaDLL.lua_pcall(L, 4, 0, 0) != 0)
                    {
                        HobaDebuger.LogLuaError(LuaDLL.lua_tostring(L, -1));
                    }
                }
                LuaDLL.lua_settop(L, oldTop);
            }
            totalTime = (DateTime.Now - startTime).Ticks;
        }

        UnityEngine.Debug.LogErrorFormat("ProcessMovePBProtocol * {0} = {1} ticks", count, totalTime);

        byte[] inputBytes         = new byte[100];
        System.IO.MemoryStream ms = new System.IO.MemoryStream(inputBytes);
        System.IO.BinaryWriter bw = new System.IO.BinaryWriter(ms);

        {
            //entityid
            bw.Write(2);
            //CurrentPosition
            bw.Write(1.0f);
            bw.Write(2.0f);
            bw.Write(3.0f);
            //CurrentOrientation
            bw.Write(4.0f);
            bw.Write(5.0f);
            bw.Write(6.0f);
            //MoveType
            bw.Write(3);
            //MoveDirection
            bw.Write(7.0f);
            bw.Write(8.0f);
            bw.Write(9.0f);
            //MoveSpeed
            bw.Write(10.0f);
            //TimeInterval
            bw.Write(4);
            //DstPosition
            bw.Write(11.0f);
            bw.Write(12.0f);
            bw.Write(33.0f);
            //IsDestPosition
            bw.Write(false);


            ms.Seek(0, System.IO.SeekOrigin.Begin);
        }


        System.IO.BinaryReader br = new System.IO.BinaryReader(ms);

        {
            var startTime = DateTime.Now;
            for (int i = 0; i < count; i++)
            {
                br.BaseStream.Position = 0;
                var EntityId        = br.ReadInt32();
                var vecX            = br.ReadSingle();
                var vecY            = br.ReadSingle();
                var vecZ            = br.ReadSingle();
                var CurrentPosition = new UnityEngine.Vector3(vecX, vecY, vecZ);
                vecX = br.ReadSingle();
                vecY = br.ReadSingle();
                vecZ = br.ReadSingle();
                var CurrentOrientation = new UnityEngine.Vector3(vecX, vecY, vecZ);
                var MoveType           = br.ReadInt32();
                vecX = br.ReadSingle();
                vecY = br.ReadSingle();
                vecZ = br.ReadSingle();
                var MoveDirection = new UnityEngine.Vector3(vecX, vecY, vecZ);
                var MoveSpeed     = br.ReadSingle();
                var TimeInterval  = br.ReadInt32();
                vecX = br.ReadSingle();
                vecY = br.ReadSingle();
                vecZ = br.ReadSingle();
                var DstPosition    = new UnityEngine.Vector3(vecX, vecY, vecZ);
                var IsDestPosition = br.ReadBoolean();

                if (L != IntPtr.Zero)
                {
                    int oldTop = LuaDLL.lua_gettop(L);
                    LuaDLL.lua_getglobal(L, "ProcessMoveProtocol1");
                    if (!LuaDLL.lua_isnil(L, -1))
                    {
                        LuaScriptMgr.Push(L, EntityId);
                        LuaScriptMgr.Push(L, CurrentPosition);
                        LuaScriptMgr.Push(L, CurrentOrientation);
                        LuaScriptMgr.Push(L, MoveType);
                        LuaScriptMgr.Push(L, MoveDirection);
                        LuaScriptMgr.Push(L, MoveSpeed);
                        LuaScriptMgr.Push(L, TimeInterval);
                        LuaScriptMgr.Push(L, DstPosition);
                        LuaScriptMgr.Push(L, IsDestPosition);

                        if (LuaDLL.lua_pcall(L, 9, 0, 0) != 0)
                        {
                            HobaDebuger.LogLuaError(LuaDLL.lua_tostring(L, -1));
                        }
                    }
                    LuaDLL.lua_settop(L, oldTop);
                }
            }

            totalTime = (DateTime.Now - startTime).Ticks;
        }
        bw.Close();
        br.Close();
        ms.Close();
        ms.Dispose();

        UnityEngine.Debug.LogErrorFormat("ProcessMoveProtocol * {0} = {1} ticks", count, totalTime);
    }
Пример #6
0
    public void TestBytes(CS2CPrtcData p, bool isSpecial, bool isSimple)
    {
        if (p == null || p.Type != 10531)
        {
            return;
        }

        int  count      = 10000;
        long totalTicks = 0;

        if (p != null && p.Type > 0)
        {
            //UnityEngine.Profiling.Profiler.BeginSample("Start PB ");
            var time = DateTime.Now.Ticks;
            totalTicks = 0;

            for (int i = 0; i < count; i++)
            {
                time = DateTime.Now.Ticks;
                IntPtr L = LuaScriptMgr.Instance.GetL();
                if (L != IntPtr.Zero)
                {
                    int oldTop = LuaDLL.lua_gettop(L);
                    LuaDLL.lua_getglobal(L, "ProcessProtocol");
                    if (!LuaDLL.lua_isnil(L, -1))
                    {
                        LuaDLL.lua_pushinteger(L, p.Type);
                        if (p.Buffer != null)
                        {
                            LuaDLL.lua_pushlstring(L, p.Buffer, p.Buffer.Length);
                        }
                        else
                        {
                            LuaDLL.lua_pushstring(L, String.Empty);
                        }
                        LuaDLL.lua_pushboolean(L, isSpecial);
                        LuaDLL.lua_pushboolean(L, isSimple);

                        if (LuaDLL.lua_pcall(L, 4, 0, 0) != 0)
                        {
                            HobaDebuger.LogLuaError(LuaDLL.lua_tostring(L, -1));
                        }
                    }

                    LuaDLL.lua_settop(L, oldTop);
                }
                totalTicks += DateTime.Now.Ticks - time;
            }
            UnityEngine.Debug.LogError("PB总耗费时间为" + (totalTicks).ToString());

            using (FileStream sr = new FileStream(UnityEngine.Application.dataPath + "/tmpBuffer",
                                                  FileMode.OpenOrCreate))
            {
                BinaryWriter bw = new BinaryWriter(sr);
                //type
                bw.Write(1);
                //entityid
                bw.Write(2);
                //CurrentPosition
                bw.Write(1.0f);
                bw.Write(2.0f);
                bw.Write(3.0f);
                //CurrentOrientation
                bw.Write(4.0f);
                bw.Write(5.0f);
                bw.Write(6.0f);
                //MoveType
                bw.Write(3);
                //MoveDirection
                bw.Write(7.0f);
                bw.Write(8.0f);
                bw.Write(9.0f);
                //MoveSpeed
                bw.Write(10.0f);
                //TimeInterval
                bw.Write(4);
                //DstPosition
                bw.Write(11.0f);
                bw.Write(12.0f);
                bw.Write(33.0f);
                //IsDestPosition
                bw.Write(false);
                bw.Flush();
            }

            //UnityEngine.Profiling.Profiler.BeginSample("Start BF ");
            totalTicks = 0;
            for (int i = 0; i < count; i++)
            {
                FileStream   sr2 = new FileStream(UnityEngine.Application.dataPath + "/tmpBuffer", FileMode.Open);
                BinaryReader br  = new BinaryReader(sr2);

                time = DateTime.Now.Ticks;

                var type            = br.ReadInt32();
                var EntityId        = br.ReadInt32();
                var vecX            = br.ReadSingle();
                var vecY            = br.ReadSingle();
                var vecZ            = br.ReadSingle();
                var CurrentPosition = new Vector3(vecX, vecY, vecZ);
                vecX = br.ReadSingle();
                vecY = br.ReadSingle();
                vecZ = br.ReadSingle();
                var CurrentOrientation = new Vector3(vecX, vecY, vecZ);
                var MoveType           = br.ReadInt32();
                vecX = br.ReadSingle();
                vecY = br.ReadSingle();
                vecZ = br.ReadSingle();
                var MoveDirection = new Vector3(vecX, vecY, vecZ);
                var MoveSpeed     = br.ReadSingle();
                var TimeInterval  = br.ReadInt32();
                vecX = br.ReadSingle();
                vecY = br.ReadSingle();
                vecZ = br.ReadSingle();
                var DstPosition    = new Vector3(vecX, vecY, vecZ);
                var IsDestPosition = br.ReadBoolean();
                LuaScriptMgr.Instance.CallLuaOnWeatherEventFunc2(type, EntityId, CurrentPosition, CurrentOrientation
                                                                 , MoveType, MoveDirection, MoveSpeed, TimeInterval, DstPosition, IsDestPosition);
                totalTicks += DateTime.Now.Ticks - time;
                br.Close();
            }
            UnityEngine.Debug.LogError("二进制总耗费时间为" + (totalTicks).ToString());
            //UnityEngine.Profiling.Profiler.EndSample();
        }
    }