private void StartClient(string user, string uuid, string sessionID, int protocolversion, string server_ip, ushort port, ForgeInfo forgeInfo)
        {
            this.sessionid = sessionID;
            this.host      = server_ip;
            this.port      = port;
            player         = new Player(world, user, uuid);

            try
            {
                packetClient = new PacketClient();
                if (!packetClient.Connect(new ServerConnectionInfo(server_ip, port), player, protocolversion, forgeInfo, this))
                {
                    return;
                }

                handler = packetClient.communicationHandler;
                player.SetHandler(handler);

                Console.WriteLine("Server was successfully joined.\nType '" + Settings.internalCmdChar + "quit' to leave the server.");
            }
            catch (SocketException e)
            {
                ConsoleIO.WriteLineFormatted("§8" + e.Message);
                Console.WriteLine("Failed to connect to this IP.");
            }
        }
示例#2
0
        private static void MirrorRateTesting()
        {
            var server = new PacketServer(26657);

            server.StartListening();

            var client = new PacketClient("127.0.0.1", 26657);
            var sw     = Stopwatch.StartNew();
            var pc     = 0;

            server.PacketReceived += (s, e) => mirror(e);
            client.PacketReceived += (s, e) => mirror(e);

            if (client.Connect())
            {
                client.Communicator.Send(new PingPacket());
            }
            else
            {
                throw new Exception("How?");
            }

            while (true)
            {
                Thread.Sleep(-1);
            }

            void mirror(PacketReceivedEventArgs e)
            {
                if (e.Packet is PingPacket pingPacket)
                {
                    e.Connection.Communicator.Send(new PongPacket()
                    {
                        Value = pingPacket.Value + 1
                    });
                }
                else if (e.Packet is PongPacket pongPacket)
                {
                    e.Connection.Communicator.Send(new PingPacket()
                    {
                        Value = pongPacket.Value + 1
                    });
                }

                if (e.Connection is PacketClient)
                {
                    pc++;

                    if (sw.ElapsedMilliseconds > 1000)
                    {
                        Console.WriteLine($"Mirrored {pc} packets.");
                        pc = 0;
                        sw.Restart();
                    }
                }
            }
        }