public static async Task Main() { try { Console.WriteLine("Gt server testing"); ManagedENet.Startup(); await UpdateItemsDat(); IPEndPoint address = new IPEndPoint(IPAddress.Any, 17091); Server = new ENetHost(address, 1024, 10); Server.ChecksumWithCRC32(); Server.CompressWithRangeCoder(); await SetItemsDataDB(); await SetItemsDB(); await DbContext.OpenConnection(); Console.WriteLine("Success at opening MySql connection!"); Server.OnConnect += Server_OnConnect; Server.StartServiceThread(); Thread.Sleep(-1); } catch (Exception e) { Console.WriteLine("Critical error occured ! Message : " + e.Message); } }
static void Main(string[] args) { // You should call this at start of your application or before any usage of ENet Console.WriteLine("Starting ENet..."); ManagedENet.Startup(); // The IP endpoint which we are going to listen on var listenEndPoint = new IPEndPoint(IPAddress.Loopback, 27015); // By creating ENetHost we bind the endpoint Console.WriteLine("Creating host..."); var host = new ENetHost(listenEndPoint, MaximumPeers, MaximumChannels); Console.WriteLine($"Servicing on {listenEndPoint}"); while (true) { var Event = host.Service(TimeSpan.FromSeconds(60)); switch (Event.Type) { case ENetEventType.None: continue; case ENetEventType.Connect: Console.WriteLine($"Peer connected from {Event.Peer.GetRemoteEndPoint()}"); continue; case ENetEventType.Disconnect: Console.WriteLine($"Peer disconnected from {Event.Peer.GetRemoteEndPoint()}"); continue; case ENetEventType.Receive: // Decode packet data bytes to ASCII string var dataString = Encoding.ASCII.GetString(Event.Packet.Data); // Here we prefix the dataString with peer's remote endpoint dataString = $"{Event.Peer.GetRemoteEndPoint()}: {dataString}"; Console.WriteLine($"Peer {Event.Peer.GetRemoteEndPoint()}: {dataString}"); // this will broadcast the packet to all connected peers // including the peer that sent this packet host.Broadcast(Event.ChannelId, Event.Packet.Data, ENetPacketFlags.Reliable); // We are done with the packet that the peer sent so we destroy it // if you miss this you will end up with memory leaks Event.Packet.Destroy(); continue; default: throw new NotImplementedException(); } } }
public static void loadproxy() { ManagedENet.Startup(); globalUserData.macc = GenerateMACAddress(); if (!Directory.Exists("stored")) { Directory.CreateDirectory("stored"); } itemDB.SetupItemDefs(); }
public static void Build() { ManagedENet.Startup(); Port = 17091; Address = new IPEndPoint(IPAddress.Any, Port); Host = new ENetHost(Address, 1024, 1); Host.ChecksumWithCRC32(); Host.CompressWithRangeCoder(); Console.WriteLine("Server core has been built.\n" + $" [-] Port : {Port}\n"); }
private static void Main(string[] args) { ManagedENet.Startup(); Console.WriteLine("Setting up Local Server"); LocalServer = new ENetHost(new IPEndPoint(IPAddress.Any, 17091), 1024, 10, 0, 0); LocalServer.ChecksumWithCRC32(); LocalServer.CompressWithRangeCoder(); LocalServer.OnConnect += (sender, eventArgs) => { LogClient("Connected!"); RemotePeer = RemoteServer.Connect(RemoteEndpoint, 1, 0); RemotePeer.OnReceive += (o, packet) => { SendToClient(packet); }; eventArgs.Peer.OnReceive += (o, packet) => { SendToRemote(packet); }; eventArgs.Peer.OnDisconnect += (o, u) => { RemotePeer.DisconnectNow(0); LogClient("Disconnected!"); }; }; LocalServer.StartServiceThread(); Console.WriteLine("Setting up Remote Server"); RemoteServer = new ENetHost(1, 10); RemoteServer.ChecksumWithCRC32(); RemoteServer.CompressWithRangeCoder(); RemoteServer.OnConnect += (sender, eventArgs) => LogServer("Connected!"); RemoteServer.StartServiceThread(); while (true) { Thread.Sleep(5); } }
private void animaButton5_Click(object sender, EventArgs e) { animaTextBox4.Enabled = false; animaTextBox3.Enabled = false; animaButton6.Enabled = false; animaButton5.Enabled = false; ManagedENet.Startup(); eNet = new ENetHost(1, 2); eNet.OnConnect += Client_OnConnect; eNet.CompressWithRangeCoder(); eNet.ChecksumWithCRC32(); eNet.StartServiceThread(); eNetP = eNet.Connect(new System.Net.IPEndPoint(IPAddress.Parse(Growtopia_Master_IP), Growtopia_Master_Port), 2, 0); updatestatus("Connected!", 2); }
public ENetServer(string hostname, ushort port = 17091) { ManagedENet.Startup(); var address = new IPEndPoint(IPAddress.Any, port); if (hostname != "0.0.0.0") { var addresses = Dns.GetHostAddresses(hostname); if (addresses.Length == 0) { throw new ArgumentException("Unable to retrieve address from specified host name.", nameof(hostname)); } address = new IPEndPoint(addresses[0], port); } _host = new ENetHost(address, 1024, 10); _host.ChecksumWithCRC32(); _host.CompressWithRangeCoder(); InstanceId = Guid.NewGuid(); OnConnect += (sender, args) => { Console.WriteLine("A new Peer tries to connect!"); lock (Peers) Peers.Add(args.Peer); var player = new Player(args.Peer); player.OnConnect(); args.Peer.OnDisconnect += (o, u) => { lock (Peers) Peers.Remove(o as ENetPeer); player.OnDisconnect(); }; }; _host.OnConnect += OnConnect; }
public ChatForm(IPEndPoint endPoint, bool connect) : this() { ManagedENet.Startup(); IsClient = connect; nameBox.Text = string.Format("Test{0}", new Random().Next(1, 10)); if (IsClient) { chatBox.Enabled = false; } m_Host = IsClient ? new ENetHost(1, 1) : new ENetHost(endPoint, ENetHost.MaximumPeers, 1); m_Host.OnConnect += Host_OnConnect; if (IsClient) { m_Host.Connect(endPoint, 1, 0); } m_Host.StartServiceThread(); }
private void MainForm_Load(object sender, EventArgs e) { macc = GenerateMACAddress(); DialogResult dr = MessageBox.Show("Proceeding will connect you to the Growbrew Network!\nGROWBREW MAY USE ANY OF YOUR HARDWARE IDENTIFIERS AND YOUR IP WHICH ARE USED TO SECURE THE PRODUCT E.G FOR BANS AND ANTI-CRACK SOLUTIONS! \nRead more in 'Growbrew Policies'\nContinue?", "Growbrew Proxy", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr == DialogResult.No) { Environment.Exit(-1); } //tClient.BeginConnect(IPAddress.Parse("89.47.163.53"), 6770, new AsyncCallback(ConnectCallback), tClient.Client); // hackernetwork is discontinued / servers shutdown, it was good to have it when the proxy was paid, now its abusive and just a big bug mess. playerLogicUpdate.Start(); itemDB.SetupItemDefs(); ManagedENet.Startup(); }
public static async Task Main() { try { SendDateTime(); Console.WriteLine("GT SERVER IN C#"); ManagedENet.Startup(); await UpdateItemsDat(); // To check the log. recommend not to lol //UseLog = true; IPEndPoint address = new IPEndPoint(IPAddress.Any, 17091); Server = new ENetHost(address, 1024, 10); Server.ChecksumWithCRC32(); Server.CompressWithRangeCoder(); await SetItemsDataDB(); await SetItemsDB(); await DbContext.OpenConnection(); SendDateTime(); Console.WriteLine("Success at opening MySql connection!"); SendDateTime(); Console.WriteLine("Server created."); Server.OnConnect += Server_OnConnect; Server.StartServiceThread(); Thread.Sleep(-1); } catch (Exception e) { SendDateTime(); Console.WriteLine("Critical error occured ! Message : " + e.Message); } }
static void Main(string[] args) { // You should call this at start of your application or before any usage of ENet library Console.WriteLine("Starting ENet..."); ManagedENet.Startup(); // By passing null as endpoint the system will pick up a random open endpoint to listen on // since we are the client we choose a random endpoint IPEndPoint listenEndPoint = null; var host = new ENetHost(listenEndPoint, MaximumPeers, MaximumChannels); // This is the endpoint that the server is listening on // IPAddress.Loopback equals to 127.0.0.1 on most systems IPEndPoint connectEndPoint = new IPEndPoint(IPAddress.Loopback, 27015); // Here we connect to the server by creating a peer and sending the connect packet // Connect Data is a number which we can supply with our packet // this number can be ignored by server uint connectData = 0; // Send connect request Console.WriteLine("Requesting connection..."); var peer = host.Connect(connectEndPoint, MaximumChannels, connectData); while (true) { var Event = host.Service(TimeSpan.FromMilliseconds(250)); switch (Event.Type) { case ENetEventType.None: // Check if user is about to write something to input if (Console.KeyAvailable) { // Read user input var line = Console.ReadLine(); // If user wanted to disconnect if (line == "/disconnect") { // Request disconnect peer.Disconnect(data: 0); // Go for next event continue; } // Encode the input into ASCII bytes var data = Encoding.ASCII.GetBytes(line); // Send packet through channel 0 with the reliable packet flag set peer.Send(channelId: 0, data, ENetPacketFlags.Reliable); } continue; case ENetEventType.Connect: Console.WriteLine("Connected, write /disconnect to disconnect from server"); continue; case ENetEventType.Disconnect: Console.WriteLine("Disconnected"); goto shutdown; case ENetEventType.Receive: // Decode packet data into ASCII string var dataString = Encoding.ASCII.GetString(Event.Packet.Data); // We are done with this packet so we destroy it Event.Packet.Destroy(); Console.WriteLine(dataString); continue; default: throw new NotImplementedException(); } } shutdown: host.Dispose(); Console.WriteLine("Shutdown ENet..."); ManagedENet.Shutdown(); Console.WriteLine("Client stopped, press any key to close the app"); Console.ReadKey(); }