static int Update(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); NewTCPClient obj = (NewTCPClient)ToLua.CheckObject <NewTCPClient>(L, 1); obj.Update(); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int GetCmd(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); NewTCPClient obj = (NewTCPClient)ToLua.CheckObject <NewTCPClient>(L, 1); TCPRecvData[] o = obj.GetCmd(); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int CreateSocket(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); System.Net.Sockets.AddressFamily arg0 = (System.Net.Sockets.AddressFamily)ToLua.CheckObject(L, 1, typeof(System.Net.Sockets.AddressFamily)); int arg1 = (int)LuaDLL.luaL_checknumber(L, 2); System.Net.Sockets.Socket o = NewTCPClient.CreateSocket(arg0, arg1); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int Send(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); NewTCPClient obj = (NewTCPClient)ToLua.CheckObject <NewTCPClient>(L, 1); byte[] arg0 = ToLua.CheckByteBuffer(L, 2); bool o = obj.Send(arg0); LuaDLL.lua_pushboolean(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int get_IsConnected(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); NewTCPClient obj = (NewTCPClient)o; bool ret = obj.IsConnected; LuaDLL.lua_pushboolean(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index IsConnected on a nil value")); } }
static int get_Status(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); NewTCPClient obj = (NewTCPClient)o; TCPStatusType ret = obj.Status; ToLua.Push(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index Status on a nil value")); } }
static int SendPack(IntPtr L) { try { ToLua.CheckArgsCount(L, 5); NewTCPClient obj = (NewTCPClient)ToLua.CheckObject <NewTCPClient>(L, 1); byte arg0 = (byte)LuaDLL.luaL_checknumber(L, 2); byte arg1 = (byte)LuaDLL.luaL_checknumber(L, 3); uint arg2 = (uint)LuaDLL.luaL_checknumber(L, 4); byte[] arg3 = ToLua.CheckByteBuffer(L, 5); bool o = obj.SendPack(arg0, arg1, arg2, arg3); LuaDLL.lua_pushboolean(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int ConnectCoroutine(IntPtr L) { try { ToLua.CheckArgsCount(L, 8); NewTCPClient obj = (NewTCPClient)ToLua.CheckObject <NewTCPClient>(L, 1); string arg0 = ToLua.CheckString(L, 2); ushort arg1 = (ushort)LuaDLL.luaL_checknumber(L, 3); uint arg2 = (uint)LuaDLL.luaL_checknumber(L, 4); uint arg3 = (uint)LuaDLL.luaL_checknumber(L, 5); int arg4 = (int)LuaDLL.luaL_checknumber(L, 6); uint arg5 = (uint)LuaDLL.luaL_checknumber(L, 7); uint arg6 = (uint)LuaDLL.luaL_checknumber(L, 8); bool o = obj.ConnectCoroutine(arg0, arg1, arg2, arg3, arg4, arg5, arg6); LuaDLL.lua_pushboolean(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int _CreateNewTCPClient(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 0) { NewTCPClient obj = new NewTCPClient(); ToLua.PushObject(L, obj); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: NewTCPClient.New")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private void AcceptConnection() { #region Defining variables TcpClient NewTCPClient; NetworkStream NewTCPStream; string newClientIP; #endregion string guidStr = null; #region Getting connection try { // Here this thread will be waiting till anybody connect to him NewTCPClient = TCPServer.AcceptTcpClient(); newClientIP = ((System.Net.IPEndPoint)(NewTCPClient.Client.RemoteEndPoint)).Address.ToString(); if (!AllowIpList.TryGetValue(newClientIP, out guidStr)) { // Запрет подключения левых IP NewTCPClient.Close(); Console.WriteLine("Refused connection from not allow IP: " + newClientIP); return; } // Getting the network stream NewTCPStream = NewTCPClient.GetStream(); // Отправка уведомления клиенту byte[] HiMessage = new byte[10]; HiMessage = Encoding.GetEncoding(1251).GetBytes("$M$_$ERVER"); NewTCPStream.Write(HiMessage, 0, HiMessage.Length); lock (this) { for (int i = StorekeeperSessions.Count - 1; i >= 0; i--) { DataTerminalSession WorkerSession = StorekeeperSessions[i]; if (WorkerSession.IPAddress == newClientIP) { WorkerSession.CloseChannels(); } } } } catch (Exception exp) { Console.WriteLine("Error during creating TCP client: " + exp.Message); return; } #endregion #region Creating new thread // Here this thread has to create the new thread and give to him new connection DataTerminalSession NewStorekeeperSession = new DataTerminalSession(NewTCPClient, NewTCPStream, DeleteStorekeeperSession, InformAboutUpdateComplete, receiveMessage, new Guid(guidStr)); AddSession(NewStorekeeperSession); //NewStorekeeperSession.Server1CAgent = OneCConnections[newClientIP]; NewStorekeeperSession.IPAddress = newClientIP; NewStorekeeperSession.NeedToUpdate = NeedToUpdateIpList.IndexOf(newClientIP) != -1; NewStorekeeperSession.FullUpdatePath = FullUpdatePath; Thread NewStorekeeperThread = new Thread(NewStorekeeperSession.Start); NewStorekeeperSession.StorekeeperThread = NewStorekeeperThread; NewStorekeeperThread.Name = AllowIpList[newClientIP]; NewStorekeeperThread.IsBackground = true; NewStorekeeperThread.Start(); #endregion }