static void tick() { if (!sock.Connected) { Console.WriteLine("Connection failed."); thread.Abort(); return; } while (sock.Available > 0) { // receive packets and respond if needed (keep-alive) int length = Util.readVarInt(); int id = Util.readVarInt(); if (id == 0) { // keep-alive Packets.keepalive0x00(); } else if (id == 2) { // chat message Console.WriteLine(Util.readString()); } else { // everything else (this includes chunk updates and all that stuff we don't need in a console) if (length > 0 && length < 32768) { byte[] buff = new byte[length + 1]; sock.Receive(buff, length, SocketFlags.None); } } } }
// TODO test public static void floodPackets(string address, int port, int count) { Program.connect(address, port); for (int i = 0; i < count; i++) { if (Program.sock != null) { if (!Program.sock.Connected) { Program.connect(address, port); } } else { Program.connect(address, port); } int x = r.Next(10); Console.Write(x); if (x == 1) { Packets.handshake0x00(address, port, 1); } else if (x == 2) { Packets.handshake0x00(address, port, 2); } else if (x == 3) { Packets.chatMessage0x01(randomUser(30)); } else if (x == 4) { // might crash us Packets.keepalive0x00(); } else if (x == 5) { Packets.loginStart0x00(randomUser(10)); } else if (x == 6) { Packets.request0x00(); } else { Packets.handshake0x00(address, port, 1); } } }