Example #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);
 }
Example #2
0
 public EncryptedChanModule(lua.LuaFunction onInit = null)
 {
     if (onInit != null)
     {
         this.onInit = onInit.Retain();
     }
 }
Example #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
    }
Example #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);
 }
Example #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();
    }
Example #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();
            });
        }
Example #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();
     }
 }
Example #8
0
 public void Dispose()
 {
     lock (this)
     {
         if (logPack != null)
         {
             logPack.Dispose();
             logPack = null;
         }
         if (onInit != null)
         {
             onInit.Dispose();
             onInit = null;
         }
     }
 }
Example #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();
 }
Example #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);
        }