Exemple #1
0
        /// <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);
        }
    /// <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 mainId = buffer.ReadShort();

        NetworkManager.AddEvent(mainId, buffer);
    }
 static int ReadShort(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject <LuaFramework.ByteBuffer>(L, 1);
         ushort o = obj.ReadShort();
         LuaDLL.lua_pushnumber(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }