Ejemplo n.º 1
0
 public void Connect(string addr, int port, lua.LuaFunction onConnected, lua.LuaFunction onRecv)
 {
     client           = new networking.TcpIpClient();
     this.onConnected = onConnected.Retain();
     this.onRecv      = onRecv.Retain();
     client.Connect(addr, port, OnConnected);
 }
Ejemplo n.º 2
0
 public EncryptedChanModule(lua.LuaFunction onInit = null)
 {
     if (onInit != null)
     {
         this.onInit = onInit.Retain();
     }
 }
Ejemplo n.º 3
0
    public void Serve(ushort port, lua.LuaFunction onConnected, lua.LuaFunction onRecv)
    {
        this.onConnected = onConnected.Retain();
        this.onRecv      = onRecv.Retain();
        networking.TcpIpServer.Serve(port, OnConnected);

#if UNITY_EDITOR
        var x      = 100;
        var y      = 60;
        var width  = 200;
        var height = 80;
        Editor_AddGraph_Native(
            "server_send", "kbps", GetSendBandwidth, 10, 0.5f,
            x, y, width, height, Color.red);

        y += height + 5;
        Editor_AddGraph_Native(
            "server_recv", "kbps", GetRecvBandwidth, 10, 0.5f,
            x, y, width, height, Color.blue);

        y += height + 5;
        Editor_AddGraph_Native(
            "proxy_send", "kbps", GetProxySendBandwidth, 10, 0.5f,
            x, y, width, height, Color.red);

        y += height + 5;
        Editor_AddGraph_Native(
            "proxy_recv", "kbps", GetProxyRecvBandwidth, 10, 0.5f,
            x, y, width, height, Color.blue);
#endif
    }
Ejemplo n.º 4
0
 public void ConnectProxy(string addr, int port, lua.LuaFunction onConnected, lua.LuaFunction onRecv)
 {
     proxyClient      = new networking.TcpIpClient();
     onProxyConnected = onConnected.Retain();
     onProxyRecv      = onRecv.Retain();
     proxyClient.Connect(addr, port, OnProxyConnected);
 }
Ejemplo n.º 5
0
    protected override void OnDestroy()
    {
        if (onProxyConnected != null)
        {
            onProxyConnected.Dispose();
            onProxyConnected = null;
        }
        if (onProxyRecv != null)
        {
            onProxyRecv.Dispose();
            onProxyRecv = null;
        }
        if (proxyClient != null)
        {
            proxyClient.Close();
            proxyClient = null;
        }
        if (onConnected != null)
        {
            onConnected.Dispose();
            onConnected = null;
        }
        if (onRecv != null)
        {
            onRecv.Dispose();
            onRecv = null;
        }
        networking.TcpIpServer.Shutdown();

        base.OnDestroy();
    }
Ejemplo n.º 6
0
        public static void Download_Lua(string url, lua.LuaFunction complete)
        {
            var localComplete = complete.Retain();

            WebRequest2.Download(url, (data) =>
            {
                localComplete.Invoke(data);
                localComplete.Dispose();
            });
        }
Ejemplo n.º 7
0
 // main thread
 public void HandleAllPackets(lua.LuaFunction onRecv)
 {
     lock (receivedPackets)
     {
         for (int i = 0; i < receivedPackets.Count; ++i)
         {
             var data = receivedPackets[i];
             onRecv.Invoke(id, data);
             // OPT: pool for received packet
         }
         receivedPackets.Clear();
     }
 }
Ejemplo n.º 8
0
 public void Dispose()
 {
     lock (this)
     {
         if (logPack != null)
         {
             logPack.Dispose();
             logPack = null;
         }
         if (onInit != null)
         {
             onInit.Dispose();
             onInit = null;
         }
     }
 }
Ejemplo n.º 9
0
 protected override void OnDestroy()
 {
     if (onConnected != null)
     {
         onConnected.Dispose();
         onConnected = null;
     }
     if (onRecv != null)
     {
         onRecv.Dispose();
         onRecv = null;
     }
     if (client != null)
     {
         client.Close();
         client = null;
     }
     base.OnDestroy();
 }
Ejemplo n.º 10
0
        public static void Post_Lua(string url, string function, lua.LuaTable parameter, lua.LuaFunction complete, WebRequest2.Context context = null, string parametersStr = "")
        {
            Dictionary <string, object> param = new Dictionary <string, object>();

            if (parameter != null)
            {
                var L = luaVm;
                parameter.Push();
                Api.lua_pushnil(L);
                while (Api.lua_next(L, -2) != 0)
                {
                    var key   = Api.lua_tostring(L, -2);
                    var value = L.ValueAt(-1);
                    param.Add(key, value);
                    Api.lua_pop(L, 1);             // pop value
                }
                Api.lua_pop(L, 1);                 // pop table
            }

            var localComplete = complete.Retain();

            WebRequest2.Post(new System.Uri(url), function, param,
                             (s, resCode, payload, cookies, headers, localContext) =>
            {
                if (s == WebExceptionStatus.Success && resCode == HttpStatusCode.OK)
                {
                    localComplete.Invoke(true, payload);
                }
                else
                {
                    localComplete.Invoke(false);
                }
                localComplete.Dispose();
            }, context, parametersStr);
        }