コード例 #1
0
    static int ReadBytes(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1)
            {
                LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject <LuaFramework.ByteBuffer>(L, 1);
                byte[] o = obj.ReadBytes();
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 2)
            {
                LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject <LuaFramework.ByteBuffer>(L, 1);
                int    arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                byte[] o    = obj.ReadBytes(arg0);
                ToLua.Push(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: LuaFramework.ByteBuffer.ReadBytes"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
コード例 #2
0
ファイル: KcpClient.cs プロジェクト: snowyyj001/kcploumiao
        /// <summary>
        /// 接收到消息
        /// </summary>
        /// <param name="ms"></param>
        void OnReceivedMessage(MemoryStream ms)
        {
            BinaryReader r = new BinaryReader(ms);

            byte[] message = r.ReadBytes((int)(ms.Length - ms.Position));
            //int msglen = message.Length;
            LuaFramework.ByteBuffer buffer = new LuaFramework.ByteBuffer(message);
            int   uid     = buffer.ReadShort(); //这个字段对客户端无意义
            short nameLen = IPAddress.NetworkToHostOrder((short)buffer.ReadShort());

            string        name = System.Text.Encoding.UTF8.GetString(buffer.ReadBytes(nameLen));
            LuaByteBuffer lb   = buffer.ReadBuffer((int)(ms.Length - 4 - nameLen));

            NetworkManager.AddEvent(name, lb);
        }
コード例 #3
0
 static int ReadBytes(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject <LuaFramework.ByteBuffer>(L, 1);
         byte[] o = obj.ReadBytes();
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
コード例 #4
0
 static int ReadBytes(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject(L, 1, typeof(LuaFramework.ByteBuffer));
         int    arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         byte[] o    = obj.ReadBytes(arg0);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
コード例 #5
0
        /// <summary>
        /// 发送SOCKET消息
        /// </summary>
        public void SendMsg(int uMsgID, ByteBuffer buffer)
        {
            NFMsg.MsgBase xData = new NFMsg.MsgBase();
            xData.player_id = Util.NFToPB(mMainID);
            ByteBuffer newbuffer = new ByteBuffer(buffer.ToBytes());

            xData.msg_data = newbuffer.ReadBytes();
            MemoryStream body = new MemoryStream();

            Serializer.Serialize <NFMsg.MsgBase>(body, xData);
            MsgHead head = new MsgHead();

            head.unMsgID   = (UInt16)uMsgID;
            head.unDataLen = (UInt32)body.Length + (UInt32)ConstDefine.NF_PACKET_HEAD_SIZE;
            byte[] bodyByte  = body.ToArray();
            byte[] headByte  = StructureTransform.StructureToByteArrayEndian(head);
            byte[] sendBytes = new byte[head.unDataLen];
            headByte.CopyTo(sendBytes, 0);
            bodyByte.CopyTo(sendBytes, headByte.Length);
            SocketClient.SendMessage(sendBytes);
            buffer.Close();
            newbuffer.Close();
        }
コード例 #6
0
ファイル: GameManager.cs プロジェクト: vineleven/prj.wumai
        IEnumerator OnExtractResource()
        {
            Util.Log("------> extract start <------");
            string dataPath = Util.DataPath;         //数据目录
            string resPath  = Util.AppContentPath(); //游戏包资源目录

            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }

            yield return(null);



            //md5对比
            //包内
            string aplicationFileMD5 = resPath + AppConst.FinalSingleFileInfoMD5;
            //包外
            string persistentFileMD5 = dataPath + AppConst.FinalSingleFileInfoMD5;

            string aplicationMd5String = null;
            string persistentMd5String = null;

            // 读取文件列表
//            string aplicationFileListName = resPath + AppConst.FinalSingleFileInfo;


            //获取md5?
            //获取包外
            if (File.Exists(persistentFileMD5))
            {
                persistentMd5String = File.ReadAllText(persistentFileMD5);
            }

            //包内
            WWW www = new WWW(aplicationFileMD5);

            yield return(www);

            aplicationMd5String = www.text;
            www.Dispose();

            // md5验证相同,跳过解压
            if (persistentMd5String != null && persistentMd5String.Equals(aplicationMd5String))
            {
                StartCoroutine(OnUpdateResource());
                yield break;
            }



            //md5验证不同或者data目录不存在MD5文件


            //读取整个单文件
            string inFile = resPath + AppConst.FinalSingleFile;

            www = new WWW(inFile);
            yield return(www);


            //解析文件
            ByteBuffer buffer     = new ByteBuffer(www.bytes);
            int        idx        = 0;
            int        curIndex   = 0;
            int        totalCount = buffer.ReadInt();

            byte[] wwwByte = www.bytes;
            NotiConst.MsgProgress msgProgress;

            for (int i = 0; i < totalCount; i++)
            {
                //开始写吧
                string outFile = dataPath + buffer.ReadString();
                string dir     = Path.GetDirectoryName(outFile);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                File.WriteAllBytes(outFile, buffer.ReadBytes());
                curIndex++;
                if (idx++ > 10)     // 限制每帧加载4个文件
                {
                    idx = 0;
                    msgProgress.progress = (float)curIndex / (float)totalCount;
                    msgProgress.notice   = string.Format("正在解压:({0}%)", (int)(msgProgress.progress * 100));
                    facade.SendMessageCommand(NotiConst.LOADING_PROGRESS, msgProgress);
                    yield return(null);
                }
            }
            buffer.Close();

            www.Dispose();
            //facade.SendMessageCommand( NotiConst.UPDATE_EXTRACT, "解压完毕(100%)" );


            //加载完之后 将包内的md5信息写到包外
            File.WriteAllText(persistentFileMD5, aplicationMd5String);


            //Debug.Log("OnExtractResource Done");
            StartCoroutine(OnUpdateResource());
        }
コード例 #7
0
ファイル: Util.cs プロジェクト: zh423328/LuaFramework_UGUI
 public static LuaByteBuffer FilterNoMsgBase(ByteBuffer buffer)
 {
     NFMsg.MsgBase xMsg = new NFMsg.MsgBase();
     xMsg = ProtoBuf.Serializer.Deserialize <NFMsg.MsgBase>(new MemoryStream(buffer.ReadBytes()));
     return(new LuaByteBuffer(xMsg.msg_data));
 }