/// <summary>
    /// 丢失链接
    /// </summary>
    void OnDisconnected(DisType dis, string msg)
    {
        Close();   //关掉客户端链接
        int protocal = dis == DisType.Exception ?
                       Protocal.Exception : Protocal.Disconnect;

        LuaFramework.ByteBuffer buffer = new LuaFramework.ByteBuffer();
        buffer.WriteShort((ushort)protocal);
        NetworkManager.AddEvent(protocal, buffer);
        Debug.LogError("Connection was closed by the server:>" + msg + " Distype:>" + dis);
    }
    /// <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);
    }
Beispiel #3
0
    protected void SetActionHead(int actionId, LuaFramework.ByteBuffer body)
    {
        //writer.writeInt32("actionId", ActionId);
        byte[]     bodyBuffer = body.ToBytes();
        ByteBuffer headBuffer = new ByteBuffer();

        headBuffer.WriteInt(actionId);
        headBuffer.WriteInt(bodyBuffer.Length);
        headBuffer.WriteInt(NetWriter.MsgId - 1);
        headBuffer.WriteInt(0); //body_check;
        headBuffer.WriteInt(0); //head_check;

        NetWriter.Instance.SetHeadBuffer(headBuffer.ToBytes());
    }
Beispiel #4
0
 static int ReadLong(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject(L, 1, typeof(LuaFramework.ByteBuffer));
         long o = obj.ReadLong();
         LuaDLL.tolua_pushint64(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int getMemoryStream(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject(L, 1, typeof(LuaFramework.ByteBuffer));
         System.IO.MemoryStream  o   = obj.getMemoryStream();
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int SendMessage(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         LuaFramework.NetworkManager obj  = (LuaFramework.NetworkManager)ToLua.CheckObject(L, 1, typeof(LuaFramework.NetworkManager));
         LuaFramework.ByteBuffer     arg0 = (LuaFramework.ByteBuffer)ToLua.CheckObject(L, 2, typeof(LuaFramework.ByteBuffer));
         obj.SendMessage(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #7
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);
        }
Beispiel #8
0
 static int ReadDouble(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject(L, 1, typeof(LuaFramework.ByteBuffer));
         double o = obj.ReadDouble();
         LuaDLL.lua_pushnumber(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #9
0
 static int WriteInt(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);
         obj.WriteInt(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int AddEvent(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         int arg0 = (int)LuaDLL.luaL_checknumber(L, 1);
         LuaFramework.ByteBuffer arg1 = (LuaFramework.ByteBuffer)ToLua.CheckObject(L, 2, typeof(LuaFramework.ByteBuffer));
         LuaFramework.NetworkManager.AddEvent(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int ToBytes(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject <LuaFramework.ByteBuffer>(L, 1);
         byte[] o = obj.ToBytes();
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int WriteDouble(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject <LuaFramework.ByteBuffer>(L, 1);
         double arg0 = (double)LuaDLL.luaL_checknumber(L, 2);
         obj.WriteDouble(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int WriteBuffer(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         LuaFramework.ByteBuffer obj  = (LuaFramework.ByteBuffer)ToLua.CheckObject <LuaFramework.ByteBuffer>(L, 1);
         LuaByteBuffer           arg0 = new LuaByteBuffer(ToLua.CheckByteBuffer(L, 2));
         obj.WriteBuffer(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int WriteStringUnLen(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject <LuaFramework.ByteBuffer>(L, 1);
         string arg0 = ToLua.CheckString(L, 2);
         obj.WriteStringUnLen(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int ReadString(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject <LuaFramework.ByteBuffer>(L, 1);
         string o = obj.ReadString();
         LuaDLL.lua_pushstring(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int ReadBuffer(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         LuaFramework.ByteBuffer    obj = (LuaFramework.ByteBuffer)ToLua.CheckObject <LuaFramework.ByteBuffer>(L, 1);
         LuaInterface.LuaByteBuffer o   = obj.ReadBuffer();
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int FilterNoMsgBase(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         LuaFramework.ByteBuffer    arg0 = (LuaFramework.ByteBuffer)ToLua.CheckObject(L, 1, typeof(LuaFramework.ByteBuffer));
         LuaInterface.LuaByteBuffer o    = LuaFramework.Util.FilterNoMsgBase(arg0);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int WriteLong(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject <LuaFramework.ByteBuffer>(L, 1);
         long arg0 = LuaDLL.tolua_checkint64(L, 2);
         obj.WriteLong(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #19
0
 static int OnSocketData(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         LuaFramework.NetworkManager obj = (LuaFramework.NetworkManager)ToLua.CheckObject(L, 1, typeof(LuaFramework.NetworkManager));
         int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         LuaFramework.ByteBuffer arg1 = (LuaFramework.ByteBuffer)ToLua.CheckObject(L, 3, typeof(LuaFramework.ByteBuffer));
         obj.OnSocketData(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #20
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));
     }
 }
Beispiel #21
0
 static int Seek(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject <LuaFramework.ByteBuffer>(L, 1);
         int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         System.IO.SeekOrigin arg1 = (System.IO.SeekOrigin)ToLua.CheckObject(L, 3, typeof(System.IO.SeekOrigin));
         obj.Seek(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
    static int get_Length(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)o;
            int ret = obj.Length;
            LuaDLL.lua_pushinteger(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index Length on a nil value"));
        }
    }
Beispiel #23
0
    static int get_ByteBuffer(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            SessionData             obj = (SessionData)o;
            LuaFramework.ByteBuffer ret = obj.ByteBuffer;
            ToLua.PushObject(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index ByteBuffer on a nil value" : e.Message));
        }
    }
Beispiel #24
0
    static int set_ByteBuffer(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            SessionData             obj  = (SessionData)o;
            LuaFramework.ByteBuffer arg0 = (LuaFramework.ByteBuffer)ToLua.CheckObject(L, 2, typeof(LuaFramework.ByteBuffer));
            obj.ByteBuffer = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index ByteBuffer on a nil value" : e.Message));
        }
    }
 static int LuaSendMessage(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 4);
         Protocols.NetworkController obj = (Protocols.NetworkController)ToLua.CheckObject <Protocols.NetworkController>(L, 1);
         int    arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         ushort arg1 = (ushort)LuaDLL.luaL_checknumber(L, 3);
         LuaFramework.ByteBuffer arg2 = (LuaFramework.ByteBuffer)ToLua.CheckObject <LuaFramework.ByteBuffer>(L, 4);
         obj.LuaSendMessage(arg0, arg1, arg2);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #26
0
    static int get_ProtocalCode(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)o;
            ushort ret = obj.ProtocalCode;
            LuaDLL.lua_pushnumber(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index ProtocalCode on a nil value"));
        }
    }
Beispiel #27
0
    private void SocketRequest(int actionId, int actionRespId, LuaFramework.ByteBuffer body, LuaInterface.LuaFunction callback, IHeadFormater formater, bool bShowLoading)
    {
        if (mSocket == null)
        {
            string   url = NetWriter.GetUrl();
            string[] arr = url.Split(new char[] { ':' });
            if (arr.Length != 2)
            {
                Debug.LogError("Url is error:" + url);
                return;
            }
            int nPort = int.Parse(arr[1]);
            mSocket = new SocketConnect(arr[0], nPort, formater);
        }

        SocketPackage package = new SocketPackage();

        package.MsgId        = NetWriter.MsgId - 1;
        package.ActionId     = actionId;
        package.ActionRespId = actionRespId;
        package.HasLoading   = bShowLoading;
        package.SendTime     = DateTime.Now;
        package.Callback     = callback;

        NetWriter writer = NetWriter.Instance;

        SetActionHead(actionId, body);
        writer.SetBodyData(body.ToBytes());
        byte[] data = writer.PostData();
        NetWriter.resetData();

        if (bShowLoading)
        {
            RequestDelegate(Status.eStartRequest);
        }
        mSocket.Send(data, package);
    }
    static int _CreateLuaFramework_ByteBuffer(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                LuaFramework.ByteBuffer obj = new LuaFramework.ByteBuffer();
                ToLua.PushObject(L, obj);
                return 1;
            }
            else if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(byte[])))
            {
                byte[] arg0 = ToLua.CheckByteBuffer(L, 1);
                LuaFramework.ByteBuffer obj = new LuaFramework.ByteBuffer(arg0);
                ToLua.PushObject(L, obj);
                return 1;
            }
            else
            {
                return LuaDLL.luaL_throw(L, "invalid arguments to ctor method: LuaFramework.ByteBuffer.New");
            }
        }
        catch(Exception e)
        {
            return LuaDLL.toluaL_exception(L, e);
        }
    }
Beispiel #29
0
 public void Send(int actionId, int actionRespId, LuaInterface.LuaFunction callback, LuaFramework.ByteBuffer param)
 {
     if (NetWriter.IsSocket())
     {
         SocketRequest(actionId, actionRespId, param, callback, HeadFormater, false);
     }
     else
     {
         //HttpRequest(gameAction, actionParam, HeadFormater, bShowLoading);
     }
 }
Beispiel #30
0
 /// <summary>
 /// 发送消息
 /// </summary>
 public void SendMessage(LuaFramework.ByteBuffer buffer)
 {
     SessionSend(buffer.ToBytes());
     buffer.Close();
 }
Beispiel #31
0
    static int Send(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 4 && TypeChecker.CheckTypes <ActionParam>(L, 4))
            {
                Net obj  = (Net)ToLua.CheckObject <Net>(L, 1);
                int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                System.Action <ActionResult> arg1 = (System.Action <ActionResult>)ToLua.CheckDelegate <System.Action <ActionResult> >(L, 3);
                ActionParam arg2 = (ActionParam)ToLua.ToObject(L, 4);
                obj.Send(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 4 && TypeChecker.CheckTypes <Google.Protobuf.IMessage>(L, 4))
            {
                Net obj  = (Net)ToLua.CheckObject <Net>(L, 1);
                int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                System.Action <ActionResult> arg1 = (System.Action <ActionResult>)ToLua.CheckDelegate <System.Action <ActionResult> >(L, 3);
                Google.Protobuf.IMessage     arg2 = (Google.Protobuf.IMessage)ToLua.ToObject(L, 4);
                obj.Send(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 5 && TypeChecker.CheckTypes <int, LuaInterface.LuaFunction, LuaFramework.ByteBuffer>(L, 3))
            {
                Net                     obj  = (Net)ToLua.CheckObject <Net>(L, 1);
                int                     arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                int                     arg1 = (int)LuaDLL.lua_tonumber(L, 3);
                LuaFunction             arg2 = ToLua.ToLuaFunction(L, 4);
                LuaFramework.ByteBuffer arg3 = (LuaFramework.ByteBuffer)ToLua.ToObject(L, 5);
                obj.Send(arg0, arg1, arg2, arg3);
                return(0);
            }
            else if (count == 5 && TypeChecker.CheckTypes <System.Action <ActionResult>, Google.Protobuf.IMessage, bool>(L, 3))
            {
                Net obj  = (Net)ToLua.CheckObject <Net>(L, 1);
                int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                System.Action <ActionResult> arg1 = (System.Action <ActionResult>)ToLua.ToObject(L, 3);
                Google.Protobuf.IMessage     arg2 = (Google.Protobuf.IMessage)ToLua.ToObject(L, 4);
                bool arg3 = LuaDLL.lua_toboolean(L, 5);
                obj.Send(arg0, arg1, arg2, arg3);
                return(0);
            }
            else if (count == 5 && TypeChecker.CheckTypes <System.Action <ActionResult>, ActionParam, bool>(L, 3))
            {
                Net obj  = (Net)ToLua.CheckObject <Net>(L, 1);
                int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                System.Action <ActionResult> arg1 = (System.Action <ActionResult>)ToLua.ToObject(L, 3);
                ActionParam arg2 = (ActionParam)ToLua.ToObject(L, 4);
                bool        arg3 = LuaDLL.lua_toboolean(L, 5);
                obj.Send(arg0, arg1, arg2, arg3);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: Net.Send"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }