コード例 #1
0
        public static void ConnectToServer(ref ENetPeer peer, UserData userData = null, bool FirstInitialUseOfBot = false)
        {
            Console.WriteLine("Internal proxy client is attempting a connection to server...");

            string ip   = globalUserData.Growtopia_IP;
            int    port = globalUserData.Growtopia_Port;


            if (peer == null)
            {
                peer = client.Connect(new IPEndPoint(IPAddress.Parse(ip), port), 2, 0);
            }
            else
            {
                if (peer.IsNull)
                {
                    peer = client.Connect(new IPEndPoint(IPAddress.Parse(ip), port), 2, 0);
                }
                else if (peer.State != ENetPeerState.Connected)
                {
                    peer = client.Connect(new IPEndPoint(IPAddress.Parse(ip), port), 2, 0);
                }
                else
                {
                    // peer = client.Connect(new IPEndPoint(IPAddress.Parse(ip), port), 2, 0);
                    globalUserData.awaitingReconnect = true;
                    peer.Disconnect(0);

                    //In this case, we will want the realPeer to be disconnected first

                    // sub server switching, most likely.
                    peer = client.Connect(new IPEndPoint(IPAddress.Parse(ip), port), 2, 0);
                }
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: thequantes/Growtopia-Checker
 private void animaButton2_Click(object sender, EventArgs e)
 {
     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);
 }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: RealGoblins/growbrewproxy
 public static void ConnectToServer()
 {
     if (realPeer == null)
     {
         realPeer = client.Connect(new IPEndPoint(IPAddress.Parse(Growtopia_IP), Growtopia_Port), 2, 0);
     }
     else
     {
         if (realPeer.State != ENetPeerState.Connected)
         {
             realPeer = client.Connect(new IPEndPoint(IPAddress.Parse(Growtopia_IP), Growtopia_Port), 2, 0);
         }
         else
         {
             PacketSending.SendPacket(3, "action|quit", realPeer);
             // sub server switching, most likely.
             realPeer = client.Connect(new IPEndPoint(IPAddress.Parse(Growtopia_IP), Growtopia_Port), 2, 0);
         }
     }
 }
コード例 #4
0
        public static void ConnectCurrent()
        {
            if (g_Client == null)
            {
                return;
            }

            if (g_Client.ServiceThreadStarted)
            {
                if (g_Peer == null)
                {
                    g_Peer = g_Client.Connect(new System.Net.IPEndPoint(IPAddress.Parse(Growtopia_IP), Growtopia_Port), 2, 0);
                }
                else if (g_Peer.State == ENetPeerState.Connected)
                {
                    g_Peer.Reset();

                    g_Peer = g_Client.Connect(new System.Net.IPEndPoint(IPAddress.Parse(Growtopia_IP), Growtopia_Port), 2, 0);
                }
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: OverallGod/GrowingServer
        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);
            }
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: thequantes/Growtopia-Checker
 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);
 }
コード例 #7
0
        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();
        }
コード例 #8
0
        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();
        }