public static void UF_Update(LuaFunction luafunction) { if (luafunction == null) { return; } //接收 ProtocalDatas NetworkSystem.UF_GetInstance().UF_ReceiveProtocalDatas(m_ProtocalDatas); //解析 ProtocalDatas if (m_ProtocalDatas.Count > 0) { for (int k = 0; k < m_ProtocalDatas.Count; k++) { uint bufferID = m_TableCBytesBuffer.UF_Add(m_ProtocalDatas[k].BodyBuffer); try{ //协议解析必须完整解析,不能在解析的时候使用C#协程 luafunction.BeginPCall(); luafunction.Push(m_ProtocalDatas [k].id); luafunction.Push(m_ProtocalDatas [k].retCode); luafunction.Push(m_ProtocalDatas [k].corCode); luafunction.Push(bufferID); luafunction.PCall(); luafunction.EndPCall(); }catch (System.Exception e) { Debugger.UF_Exception(e); luafunction.EndPCall(); } m_TableCBytesBuffer.UF_Remove(bufferID); m_ProtocalDatas[k].UF_Release(); } m_ProtocalDatas.Clear(); } }
static int UF_addConnection(IntPtr L) { #if UNITY_EDITOR if (LuaDLL.lua_isstring(L, 1) == 0) { LuaDLL.luaL_typerror(L, 1, "string"); } if (LuaDLL.lua_isnumber(L, 2) == 0) { LuaDLL.luaL_typerror(L, 2, "number"); } if (LuaDLL.lua_isnumber(L, 3) == 0) { LuaDLL.luaL_typerror(L, 3, "number"); } if (LuaDLL.lua_isnumber(L, 4) == 0) { LuaDLL.luaL_typerror(L, 4, "number"); } #endif string host = LuaDLL.lua_tostring(L, 1); int port = (int)LuaDLL.lua_tonumber(L, 2); int timeout = (int)LuaDLL.lua_tonumber(L, 3); int ctype = (int)LuaDLL.lua_tonumber(L, 4); bool ret = NetworkSystem.UF_GetInstance().UF_AddConnection(host, port, timeout, ctype == 0 ? ConnectType.TCP : ConnectType.UDP); LuaDLL.lua_pushboolean(L, ret); return(1); }
static int UF_httpGet(IntPtr L) { #if UNITY_EDITOR if (LuaDLL.lua_isstring(L, 1) == 0) { LuaDLL.luaL_typerror(L, 1, "string"); } if (LuaDLL.lua_isstring(L, 2) == 0) { LuaDLL.luaL_typerror(L, 2, "string"); } if (LuaDLL.lua_isnumber(L, 3) == 0) { LuaDLL.luaL_typerror(L, 3, "number"); } #endif string url = LuaDLL.lua_tostring(L, 1); string headinfo = LuaDLL.lua_tostring(L, 2); int timeout = (int)LuaDLL.lua_tonumber(L, 3); DelegateResponse callback = null; if (LuaDLL.lua_isfunction(L, 4)) { LuaFunction luafunction = ToLua.ToLuaFunction(L, 4); callback = delegate(int retcode, object param) { UF_OnHttpResponse(luafunction, retcode, param); }; } NetworkSystem.UF_GetInstance().UF_HttpGetRequest(url, headinfo, timeout, callback); return(0); }
static int UF_closeConnection(IntPtr L) { #if UNITY_EDITOR if (LuaDLL.lua_isstring(L, 1) == 0) { LuaDLL.luaL_typerror(L, 1, "string"); } if (LuaDLL.lua_isnumber(L, 2) == 0) { LuaDLL.luaL_typerror(L, 2, "number"); } if (!LuaDLL.lua_isboolean(L, 3)) { LuaDLL.luaL_typerror(L, 3, "boolean"); } #endif string host = LuaDLL.lua_tostring(L, 1); int port = (int)LuaDLL.lua_tonumber(L, 2); bool notifyState = LuaDLL.lua_toboolean(L, 3); NetworkSystem.UF_GetInstance().UF_CloseConnection(host, port, notifyState); return(0); }
static int UF_closeAllConnection(IntPtr L) { #if UNITY_EDITOR if (!LuaDLL.lua_isboolean(L, 1)) { LuaDLL.luaL_typerror(L, 1, "boolean"); } #endif bool notifyState = LuaDLL.lua_toboolean(L, 1); NetworkSystem.UF_GetInstance().UF_CloseAllConnection(notifyState); return(0); }
internal void SendPoint(int pointId, string deviceChunk, string userChunk) { string param = string.Format("&reason={0}{1}{2}", pointId, deviceChunk, userChunk); string url = urlCheckPoint + param; Debugger.UF_Log("Check Point:" + url); //FrameHandle.UF_AddCoroutine(SendRequest(url)); NetworkSystem.UF_GetInstance().UF_HttpGetRequest(url, "", 5000, null); //for (int k = 0; k < 100; k++) { // NetworkSystem.UF_GetInstance().HttpGetRequest(url, "", 5000, (a,e)=> { idx++; Debug.Log(e.ToString() + "| " + idx); }); //} }
static int UF_httpDownload(IntPtr L) { #if UNITY_EDITOR if (LuaDLL.lua_isstring(L, 1) == 0) { LuaDLL.luaL_typerror(L, 1, "string"); } if (LuaDLL.lua_isstring(L, 2) == 0) { LuaDLL.luaL_typerror(L, 2, "string"); } if (LuaDLL.lua_isnumber(L, 3) == 0) { LuaDLL.luaL_typerror(L, 3, "number"); } #endif string url = LuaDLL.lua_tostring(L, 1); string headinfo = LuaDLL.lua_tostring(L, 2); int timeout = (int)LuaDLL.lua_tonumber(L, 3); DelegateResponse callback = null; if (LuaDLL.lua_isfunction(L, 4)) { LuaFunction luafunction = ToLua.ToLuaFunction(L, 4); callback = delegate(int retcode, object param) { // string msg = string.Empty; byte[] data = param as byte[]; LuaFunction func = luafunction; func.BeginPCall(); func.Push(retcode); if (data != null) { uint uniCode = m_TableBytes.UF_Add(data); func.Push(uniCode); } func.PCall(); func.EndPCall(); }; } NetworkSystem.UF_GetInstance().UF_HttpGetRequest(url, headinfo, timeout, callback); return(0); }
static int UF_sendTo(IntPtr L) { #if UNITY_EDITOR if (LuaDLL.lua_isstring(L, 1) == 0) { LuaDLL.luaL_typerror(L, 1, "string"); } if (LuaDLL.lua_isnumber(L, 2) == 0) { LuaDLL.luaL_typerror(L, 2, "number"); } if (LuaDLL.lua_isnumber(L, 3) == 0) { LuaDLL.luaL_typerror(L, 3, "number"); } if (LuaDLL.lua_isnumber(L, 4) == 0) { LuaDLL.luaL_typerror(L, 4, "number"); } if (LuaDLL.lua_isnumber(L, 5) == 0) { LuaDLL.luaL_typerror(L, 5, "number"); } #endif string host = LuaDLL.lua_tostring(L, 1); int port = (int)LuaDLL.lua_tonumber(L, 2); int protocol = (int)LuaDLL.lua_tonumber(L, 3); int corcode = (int)LuaDLL.lua_tonumber(L, 4); uint bufferid = (uint)LuaDLL.lua_tonumber(L, 5); CBytesBuffer buffer = m_TableCBytesBuffer[bufferid]; UF_ASSERT_BYTESBUFFER(buffer); // buffer.pack (); NetworkSystem.UF_GetInstance().UF_SendMessage(host, port, protocol, corcode, buffer.Buffer, buffer.DataSize); return(0); }
static int UF_checkConnected(IntPtr L) { #if UNITY_EDITOR if (LuaDLL.lua_isstring(L, 1) == 0) { LuaDLL.luaL_typerror(L, 1, "string"); } if (LuaDLL.lua_isnumber(L, 2) == 0) { LuaDLL.luaL_typerror(L, 2, "number"); } #endif string host = LuaDLL.lua_tostring(L, 1); int port = (int)LuaDLL.lua_tonumber(L, 2); bool ret = NetworkSystem.UF_GetInstance().UF_CheckNetConnected(host, port); LuaDLL.lua_pushboolean(L, ret); return(1); }
public void UF_DrawDetail(Rect rect) { if (GUILayout.Button("Info", GUILayout.Height(40))) { m_CurrentTag = TAG_INFO; } if (GUILayout.Button("Protocal", GUILayout.Height(40))) { m_CurrentTag = TAG_PROTOCAL; } if (GUILayout.Button("Hack", GUILayout.Height(40))) { m_CurrentTag = TAG_HACK; } GUILayout.Space(40); GUI.color = Color.red; if (GUILayout.Button("BreakAll", GUILayout.Height(40))) { //测试断开所有链接 NetworkSystem.UF_GetInstance().UF_CloseAllConnection(true); } GUI.color = Color.white; }
static int UF_httpDownloadTo(IntPtr L) { #if UNITY_EDITOR if (LuaDLL.lua_isstring(L, 1) == 0) { LuaDLL.luaL_typerror(L, 1, "string"); } if (LuaDLL.lua_isstring(L, 2) == 0) { LuaDLL.luaL_typerror(L, 2, "string"); } if (LuaDLL.lua_isnumber(L, 3) == 0) { LuaDLL.luaL_typerror(L, 3, "number"); } if (LuaDLL.lua_isstring(L, 4) == 0) { LuaDLL.luaL_typerror(L, 4, "string"); } #endif string url = LuaDLL.lua_tostring(L, 1); string headinfo = LuaDLL.lua_tostring(L, 2); int timeout = (int)LuaDLL.lua_tonumber(L, 3); string localPath = LuaDLL.lua_tostring(L, 4); if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(localPath))) { System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(localPath)); } DelegateResponse callback = null; if (LuaDLL.lua_isfunction(L, 5)) { LuaFunction luafunction = ToLua.ToLuaFunction(L, 5); callback = delegate(int retcode, object param) { // string msg = string.Empty; byte[] data = param as byte[]; //save to local try{ if (System.IO.File.Exists(localPath)) { System.IO.File.Delete(localPath); } System.IO.FileInfo fi = new System.IO.FileInfo(localPath); System.IO.FileStream fs = fi.Open(System.IO.FileMode.CreateNew); fs.Write(data, 0, data.Length); fs.Close(); }catch (System.Exception e) { Debugger.UF_Exception(e); } LuaFunction func = luafunction; func.BeginPCall(); func.Push(retcode); func.PCall(); func.EndPCall(); }; } NetworkSystem.UF_GetInstance().UF_HttpGetRequest(url, headinfo, timeout, callback); return(0); }
//网络信息,链接,网速等 private void UF_DrawTagInfo() { GUILayout.Space(4); GUILayout.Box(NetworkSystem.UF_GetInstance().ToString()); GUILayout.Space(4); }
public void UF_OnAwake() { hostAddress = NetworkSystem.UF_GetInstance().UF_GetHostIP(); }
internal void UF_SendUrl(string urlChunk) { Debugger.UF_Log("Check Url:" + urlChunk); //FrameHandle.UF_AddCoroutine(SendRequest(urlChunk)); NetworkSystem.UF_GetInstance().UF_HttpGetRequest(urlChunk, "", 5000, null); }