Sanity 435 Posted September 28, 2017 Report Share Posted September 28, 2017 Wrote this very quickly cause I had to test some core updates I made to my Elvarg base. Keep in mind 90% of the code was taken from the client. Difficulty: 1/10, just copy paste What you're adding: Let's start, create a new package called "flood" or something, add these in it: package com.elvarg.util.flood; import java.io.IOException; import java.net.InetAddress; import java.net.Socket; import com.elvarg.Server; import com.elvarg.game.GameConstants; import com.elvarg.net.NetworkConstants; import com.elvarg.net.login.LoginResponses; import com.elvarg.net.security.IsaacRandom; /** * Represents a client which will attempt * to connect to the server. * * This can be used to stresstest the server. * * Note: Code was copy+pasted from client. * I've barely touched it. * * @author Professor Oak */ public class Client { public Client(String username, String password) { this.username = username; this.password = password; } private final String username; private final String password; private Buffer incoming, login; private ByteBuffer outgoing; private BufferedConnection socketStream; private long serverSeed; private IsaacRandom encryption; public boolean loggedIn; public void attemptLogin() throws Exception { login = Buffer.create(); incoming = Buffer.create(); outgoing = ByteBuffer.create(5000, false, null); socketStream = new BufferedConnection(openSocket(NetworkConstants.GAME_PORT)); outgoing.putByte(14); //REQUEST socketStream.queueBytes(1, outgoing.getBuffer()); int response = socketStream.read(); //Our encryption for outgoing messages for this player's session IsaacRandom cipher = null; if (response == 0) { socketStream.flushInputStream(incoming.payload, 8); incoming.currentPosition = 0; serverSeed = incoming.readLong(); // aka server session key int seed[] = new int[4]; seed[0] = (int) (Math.random() * 99999999D); seed[1] = (int) (Math.random() * 99999999D); seed[2] = (int) (serverSeed >> 32); seed[3] = (int) serverSeed; outgoing.resetPosition(); outgoing.putByte(10); outgoing.putInt(seed[0]); outgoing.putInt(seed[1]); outgoing.putInt(seed[2]); outgoing.putInt(seed[3]); outgoing.putInt(4 >> 1); outgoing.putString(username); outgoing.putString(password); outgoing.encryptRSAContent(); login.currentPosition = 0; login.writeByte(16); //18 if reconnecting, we aren't though login.writeByte(outgoing.getPosition() + 1 + 1 + 2); // size of the // login block login.writeByte(255); login.writeShort(GameConstants.GAME_VERSION); //Client version login.writeByte(0); // low mem login.writeBytes(outgoing.getBuffer(), outgoing.getPosition(), 0); cipher = new IsaacRandom(seed); for (int index = 0; index < 4; index++) seed[index] += 50; encryption = new IsaacRandom(seed); socketStream.queueBytes(login.currentPosition, login.payload); response = socketStream.read(); } if (response == LoginResponses.LOGIN_SUCCESSFUL) { Server.getFlooder().clients.put(username, this); int rights = socketStream.read(); loggedIn = true; outgoing = ByteBuffer.create(5000, true, cipher); incoming.currentPosition = 0; } } int pingCounter = 0; public void process() throws Exception { if(loggedIn) { /*for(int i = 0; i < 5; i++) { if(!readPacket()) break; }*/ if(pingCounter++ >= 25) { outgoing.resetPosition(); //Basic packet ping to keep connection alive outgoing.putOpcode(0); if (socketStream != null) { socketStream.queueBytes(outgoing.bufferLength(), outgoing.getBuffer()); } pingCounter = 0; } } } private boolean readPacket() throws Exception { if (socketStream == null) { return false; } int available = socketStream.available(); if (available < 2) { return false; } int opcode = -1; int packetSize = -1; //First we read opcode... if(opcode == -1) { socketStream.flushInputStream(incoming.payload, 1); opcode = incoming.payload[0] & 0xff; if (encryption != null) { opcode = opcode - encryption.nextInt() & 0xff; } //Now attempt to read packet size.. socketStream.flushInputStream(incoming.payload, 2); packetSize = ((incoming.payload[0] & 0xff) << 8) + (incoming.payload[1] & 0xff); } if(!(opcode >= 0 && opcode < 256)) { opcode = -1; return false; } incoming.currentPosition = 0; socketStream.flushInputStream(incoming.payload, packetSize); switch(opcode) { } return false; } private Socket openSocket(int port) throws IOException { return new Socket(InetAddress.getByName("localhost"), port); } } package com.elvarg.util.flood; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import com.elvarg.util.Misc; /** * An implementation of {@link Runnable} which creates * new clients and tries to connect them with the server. * * @author Professor Oak */ public class Flooder implements Runnable { /** * The clients that are currently active. * We can use this map to distinguish fake-clients * from real ones. */ public final Map<String, Client> clients = new HashMap<String, Client>(); /** * Is this flooder currently running? */ private boolean running; /** * Starts this flooder if it hasn't * been started already. */ public void start() { if(!running) { running = true; new Thread(this).start(); } } /** * Stops this flooder. * * Any logged in clients will eventually be disconnected * from the server automatically for being idle. */ public void stop() { running = false; } /** * Attempts to login the amount of given clients. * @param amount */ public void login(int amount) { //Make sure we have started before logging in clients. start(); //Attempt to login the amount of bots.. synchronized(clients) { for(int i = 0; i < amount; i++) { try { String username = "bot" + Integer.toString(clients.size()); String password = "bot"; new Client(Misc.formatText(username), password).attemptLogin(); } catch(Exception e) { e.printStackTrace(); } } } } @Override public void run() { while(running) { try { Iterator<Entry<String, Client>> i = clients.entrySet().iterator(); while(i.hasNext()) { Entry<String, Client> entry = i.next(); try { entry.getValue().process(); } catch(Exception e) { e.printStackTrace(); i.remove(); } } Thread.sleep(300); } catch(Exception e) { e.printStackTrace(); } } } } Buffers, don't ask why there are two of them lmao package com.elvarg.util.flood; import java.math.BigInteger; import com.elvarg.net.security.IsaacRandom; public final class ByteBuffer { private int bitPosition; private byte[] buffer; private IsaacRandom cipher; private int position; private static final int pkt_opcode_slot = 0; private static final int pkt_size_slot = 1; private static final int pkt_content_start = 2; private boolean reserve_packet_slots; private int size; private ByteBuffer() { } public static ByteBuffer create(int size, boolean reserve_packet_slots, IsaacRandom cipher) { ByteBuffer stream_1 = new ByteBuffer(); stream_1.buffer = new byte[size]; stream_1.reserve_packet_slots = reserve_packet_slots; stream_1.size = size; stream_1.position = reserve_packet_slots ? pkt_content_start : pkt_opcode_slot; stream_1.cipher = cipher; return stream_1; } public void reset(boolean reserve_packet_slots) { this.buffer = new byte[size]; this.reserve_packet_slots = reserve_packet_slots; this.position = reserve_packet_slots ? pkt_content_start : pkt_opcode_slot; } public void encryptRSAContent() { /* Cache the current position for future use */ int currentPosition = position; /* Reset the position */ position = reserve_packet_slots ? pkt_content_start : pkt_opcode_slot; /* An empty byte array with a capacity of {@code #currentPosition} bytes */ byte[] decodeBuffer = new byte[currentPosition]; /* * Gets bytes up to the current position from the buffer and populates * the {@code #decodeBuffer} */ getBytes(currentPosition, 0, decodeBuffer); /* * The decoded big integer which translates the {@code #decodeBuffer} * into a {@link BigInteger} */ BigInteger decodedBigInteger = new BigInteger(decodeBuffer); /* * This is going to be a mouthful... the encoded {@link BigInteger} is * responsible of returning a value which is the value of {@code * #decodedBigInteger}^{@link #RSA_EXPONENT} mod (Modular arithmetic can * be handled mathematically by introducing a congruence relation on the * integers that is compatible with the operations of the ring of * integers: addition, subtraction, and multiplication. For a positive * integer n, two integers a and b are said to be congruent modulo n) * {@link #RSA_MODULES} */ BigInteger encodedBigInteger = decodedBigInteger.modPow(RSA_EXPONENT, RSA_MODULUS); /* * Returns the value of the {@code #encodedBigInteger} translated to a * byte array in big-endian byte-order */ byte[] encodedBuffer = encodedBigInteger.toByteArray(); /* Reset the position so we can write fresh to the buffer */ position = reserve_packet_slots ? pkt_content_start : pkt_opcode_slot; /* * We put the length of the {@code #encodedBuffer} to the buffer as a * standard byte. (Ignore the naming, that really writes a byte...) */ putByte(encodedBuffer.length); /* Put the bytes of the {@code #encodedBuffer} into the buffer. */ putBytes(encodedBuffer, encodedBuffer.length, 0); } public void finishBitAccess() { position = (bitPosition + 7) / 8; } public int getBits(int bitLength) { int k = bitPosition >> 3; int l = 8 - (bitPosition & 7); int i1 = 0; bitPosition += bitLength; for (; bitLength > l; l = 8) { i1 += (buffer[k++] & BIT_CONSTANTS[l]) << bitLength - l; bitLength -= l; } if (bitLength == l) { i1 += buffer[k] & BIT_CONSTANTS[l]; } else { i1 += buffer[k] >> l - bitLength & BIT_CONSTANTS[bitLength]; } return i1; } public byte getByte() { return buffer[position++]; } public void getByte(int value) { buffer[position++] = (byte) value; } public byte[] getBytes() { int pos = position; while (buffer[position++] != 10) { ; } byte[] buf = new byte[position - pos - 1]; System.arraycopy(buffer, pos, buf, pos - pos, position - 1 - pos); return buf; } public void getBytes(int len, int off, byte[] dest) { for (int i = off; i < off + len; i++) { dest[i] = buffer[position++]; } } public int getInt() { position += 4; return ((buffer[position - 4] & 0xFF) << 24) + ((buffer[position - 3] & 0xFF) << 16) + ((buffer[position - 2] & 0xFF) << 8) + (buffer[position - 1] & 0xFF); } public int getIntLittleEndian() { position += 4; return ((buffer[position - 4] & 0xFF) << 24) + ((buffer[position - 3] & 0xFF) << 16) + ((buffer[position - 2] & 0xFF) << 8) + (buffer[position - 1] & 0xFF); } public long getLong() { long msw = getIntLittleEndian() & 0xFFFFFFFFL; long lsw = getIntLittleEndian() & 0xFFFFFFFFL; return msw << 32 | lsw; } public int getShort() { position += 2; return ((buffer[position - 2] & 0xFF) << 8) + (buffer[position - 1] & 0xFF); } public int getShort2() { position += 2; int i = ((buffer[position - 2] & 0xFF) << 8) + (buffer[position - 1] & 0xFF); if (i > 60000) { i = -65535 + i; } return i; } public int getShortBigEndian() { position += 2; return ((buffer[position - 1] & 0xFF) << 8) + (buffer[position - 2] & 0xFF); } public int getShortBigEndianA() { position += 2; return ((buffer[position - 1] & 0xFF) << 8) + (buffer[position - 2] - 128 & 0xFF); } public byte getSignedByte() { return buffer[position++]; } public int getSignedShort() { position += 2; int value = ((buffer[position - 2] & 0xFF) << 8) + (buffer[position - 1] & 0xFF); if (value > 32767) { value -= 0x10000; } return value; } public int getSmart() { try { // checks current without modifying position if (position >= buffer.length) { return buffer[buffer.length - 1] & 0xFF; } int value = buffer[position] & 0xFF; if (value < 128) { return getUnsignedByte(); } else { return getUnsignedShort() - 32768; } } catch (Exception e) { e.printStackTrace(); return getUnsignedShort() - 32768; } } public String getString() { int i = position; while (buffer[position++] != 10) { } return new String(buffer, i, position - i - 1); } public int getTribyte() { position += 3; return ((buffer[position - 3] & 0xFF) << 16) + ((buffer[position - 2] & 0xFF) << 8) + (buffer[position - 1] & 0xFF); } public final int getTribyte(int value) { position += 3; return (0xFF & buffer[position - 3] << 16) + (0xFF & buffer[position - 2] << 8) + (0xFF & buffer[position - 1]); } public int getUnsignedByte() { if (position + 1 > buffer.length) { position = buffer.length - 2; } return buffer[position++] & 0xFF; } public int getUnsignedShort() { if (position + 2 > buffer.length) { return buffer[buffer.length - 1]; } position += 2; return ((buffer[position - 2] & 0xFF) << 8) + (buffer[position - 1] & 0xFF); } public int getUSmart2() { int baseVal = 0; int lastVal = 0; while ((lastVal = getSmart()) == 32767) { baseVal += 32767; } return baseVal + lastVal; } public void initBitAccess() { bitPosition = position << 3; } void method400(int value) { buffer[position++] = (byte) value; buffer[position++] = (byte) (value >> 8); } void method403(int value) { buffer[position++] = (byte) value; buffer[position++] = (byte) (value >> 8); buffer[position++] = (byte) (value >> 16); buffer[position++] = (byte) (value >> 24); } public int method421() { int i = buffer[position] & 0xFF; if (i < 128) { return getUnsignedByte() - 64; } else { return getUnsignedShort() - 49152; } } public void method424(int i) { buffer[position++] = (byte) -i; } public void method425(int j) { buffer[position++] = (byte) (128 - j); } public int method426() { return buffer[position++] - 128 & 0xFF; } public int method427() { return -buffer[position++] & 0xFF; } public int getByteA() { position += 2; return ((buffer[position - 2] & 0xff) << 8) + (buffer[position - 1] - 128 & 0xff); } public int method428() { return 128 - buffer[position++] & 0xFF; } public byte method429() { return (byte) -buffer[position++]; } public byte method430() { return (byte) (128 - buffer[position++]); } public void writeUnsignedWordBigEndian(int i) { buffer[position++] = (byte) i; buffer[position++] = (byte) (i >> 8); } public void writeUnsignedWordA(int j) { buffer[position++] = (byte) (j >> 8); buffer[position++] = (byte) (j + 128); } public void writeSignedBigEndian(int j) { buffer[position++] = (byte) (j + 128); buffer[position++] = (byte) (j >> 8); } public int method435() { position += 2; return ((buffer[position - 2] & 0xFF) << 8) + (buffer[position - 1] - 128 & 0xFF); } public int method437() { position += 2; int j = ((buffer[position - 1] & 0xFF) << 8) + (buffer[position - 2] & 0xFF); if (j > 32767) { j -= 0x10000; } return j; } public int method438() { position += 2; int j = ((buffer[position - 1] & 0xFF) << 8) + (buffer[position - 2] - 128 & 0xFF); if (j > 32767) { j -= 0x10000; } return j; } public int method439() { position += 4; return ((buffer[position - 2] & 0xFF) << 24) + ((buffer[position - 1] & 0xFF) << 16) + ((buffer[position - 4] & 0xFF) << 8) + (buffer[position - 3] & 0xFF); } public int method440() { position += 4; return ((buffer[position - 3] & 0xFF) << 24) + ((buffer[position - 4] & 0xFF) << 16) + ((buffer[position - 1] & 0xFF) << 8) + (buffer[position - 2] & 0xFF); } public void method441(int i, byte abyte0[], int j) { for (int k = i + j - 1; k >= i; k--) { buffer[position++] = (byte) (abyte0[k] + 128); } } public void method442(int i, int j, byte abyte0[]) { for (int k = j + i - 1; k >= j; k--) { abyte0[k] = buffer[position++]; } } public void putBytes(byte[] tmp, int len, int off) { for (int i = off; i < off + len; i++) { buffer[position++] = tmp[i]; } } public void putDWordBigEndian(int value) { buffer[position++] = (byte) (value >> 16); buffer[position++] = (byte) (value >> 8); buffer[position++] = (byte) value; } public void putInt(int i) { buffer[position++] = (byte) (i >> 24); buffer[position++] = (byte) (i >> 16); buffer[position++] = (byte) (i >> 8); buffer[position++] = (byte) i; } public void putLong(long value) { try { buffer[position++] = (byte) (value >> 56); buffer[position++] = (byte) (value >> 48); buffer[position++] = (byte) (value >> 40); buffer[position++] = (byte) (value >> 32); buffer[position++] = (byte) (value >> 24); buffer[position++] = (byte) (value >> 16); buffer[position++] = (byte) (value >> 8); buffer[position++] = (byte) value; } catch (RuntimeException runtimeexception) { throw new RuntimeException(); } } public void putOpcode(int i) { buffer[reserve_packet_slots ? pkt_opcode_slot : position++] = (byte) (i + cipher.nextInt()); } public void putShort(int value) { buffer[position++] = (byte) (value >> 8); buffer[position++] = (byte) value; } public void putString(String s) { System.arraycopy(s.getBytes(), 0, buffer, position, s.length()); position += s.length(); buffer[position++] = 10; } public void putVariableSizeByte(int size) { buffer[position - size - 1] = (byte) size; } public void putByte(int i) { buffer[position++] = (byte) i; } public int getBitPosition() { return bitPosition; } public IsaacRandom getCipher() { return cipher; } public void setCipher(IsaacRandom cipher) { this.cipher = cipher; } public byte[] getBuffer() { return buffer; } public int bufferLength() { int size = position; if(reserve_packet_slots) { /* Update the pkt_size slot and encrypt it */ buffer[pkt_size_slot] = (byte) (size + cipher.nextInt()); } return size; } public void resetPosition() { this.position = reserve_packet_slots ? pkt_content_start : pkt_opcode_slot; } public int getPosition() { return position; } public ByteBuffer(byte[] buffer) { this.buffer = buffer; } private static final int[] BIT_CONSTANTS = { 0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 0x1ffff, 0x3ffff, 0x7ffff, 0xFFfff, 0x1fffff, 0x3fffff, 0x7fffff, 0xFFffff, 0x1ffffff, 0x3ffffff, 0x7ffffff, 0xFFfffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, -1 }; public static final BigInteger RSA_MODULUS = new BigInteger("104491769878744214552327916539299463496996457081116392641740420337580247359457531212713234798435269852381858199895582444770363103378419890508986198319599243102737368616946490728678876018327788000439596635223141886089230154991381365099178986572201859664528128354742213167942196819984139030533812106754541601427"); public static final BigInteger RSA_EXPONENT = new BigInteger("65537"); } package com.elvarg.util.flood; import java.math.BigInteger; import com.elvarg.net.security.IsaacRandom; public final class Buffer { public byte payload[]; public int currentPosition; public int bitPosition; private static final int[] BIT_MASKS = { 0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 0x1ffff, 0x3ffff, 0x7ffff, 0xfffff, 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff, 0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, -1 }; public IsaacRandom encryption; public static Buffer create() { Buffer buffer = new Buffer(); buffer.currentPosition = 0; buffer.payload = new byte[5000]; return buffer; } public final int readUTriByte() { currentPosition += 3; return (0xff & payload[currentPosition - 3] << 16) + (0xff & payload[currentPosition - 2] << 8) + (0xff & payload[currentPosition - 1]); } public final int readUTriByte(int i) { currentPosition += 3; return (0xff & payload[currentPosition - 3] << 16) + (0xff & payload[currentPosition - 2] << 8) + (0xff & payload[currentPosition - 1]); } private Buffer() {} public Buffer(byte[] payload) { this.payload = payload; currentPosition = 0; } public int readUSmart2() { int baseVal = 0; int lastVal = 0; while ((lastVal = readUSmart()) == 32767) { baseVal += 32767; } return baseVal + lastVal; } public String readNewString() { int i = currentPosition; while (payload[currentPosition++] != 0) ; return new String(payload, i, currentPosition - i - 1); } public void writeOpcode(int opcode) { payload[currentPosition++] = (byte) (opcode + encryption.nextInt()); } public void writeByte(int value) { payload[currentPosition++] = (byte) value; } public void writeShort(int value) { payload[currentPosition++] = (byte) (value >> 8); payload[currentPosition++] = (byte) value; } public void writeTriByte(int value) { payload[currentPosition++] = (byte) (value >> 16); payload[currentPosition++] = (byte) (value >> 8); payload[currentPosition++] = (byte) value; } public void writeInt(int value) { payload[currentPosition++] = (byte) (value >> 24); payload[currentPosition++] = (byte) (value >> 16); payload[currentPosition++] = (byte) (value >> 8); payload[currentPosition++] = (byte) value; } public void writeLEInt(int value) { payload[currentPosition++] = (byte) value; payload[currentPosition++] = (byte) (value >> 8); payload[currentPosition++] = (byte) (value >> 16); payload[currentPosition++] = (byte) (value >> 24); } public void writeLong(long value) { try { payload[currentPosition++] = (byte) (int) (value >> 56); payload[currentPosition++] = (byte) (int) (value >> 48); payload[currentPosition++] = (byte) (int) (value >> 40); payload[currentPosition++] = (byte) (int) (value >> 32); payload[currentPosition++] = (byte) (int) (value >> 24); payload[currentPosition++] = (byte) (int) (value >> 16); payload[currentPosition++] = (byte) (int) (value >> 8); payload[currentPosition++] = (byte) (int) value; } catch (RuntimeException runtimeexception) { System.err.println("14395, " + 5 + ", " + value + ", " + runtimeexception.toString()); throw new RuntimeException(); } } public void writeString(String text) { System.arraycopy(text.getBytes(), 0, payload, currentPosition, text.length()); currentPosition += text.length(); payload[currentPosition++] = 10; } public void writeBytes(byte data[], int offset, int length) { for (int index = length; index < length + offset; index++) payload[currentPosition++] = data[index]; } public void writeBytes(int value) { payload[currentPosition - value - 1] = (byte) value; } public int method440() { currentPosition += 4; return ((payload[currentPosition - 3] & 0xFF) << 24) + ((payload[currentPosition - 4] & 0xFF) << 16) + ((payload[currentPosition - 1] & 0xFF) << 8) + (payload[ - 2] & 0xFF); } public int readUnsignedByte() { return payload[currentPosition++] & 0xff; } public int readShort2() { currentPosition += 2; int i = ((payload[currentPosition - 2] & 0xff) << 8) + (payload[currentPosition - 1] & 0xff); if(i > 32767) i -= 65537; return i; } public byte readSignedByte() { return payload[currentPosition++]; } public int readUShort() { currentPosition += 2; return ((payload[currentPosition - 2] & 0xff) << 8) + (payload[currentPosition - 1] & 0xff); } public int readShort() { currentPosition += 2; int value = ((payload[currentPosition - 2] & 0xff) << 8) + (payload[currentPosition - 1] & 0xff); if (value > 32767) { value -= 0x10000; } return value; } public int readTriByte() { currentPosition += 3; return ((payload[currentPosition - 3] & 0xff) << 16) + ((payload[currentPosition - 2] & 0xff) << 8) + (payload[currentPosition - 1] & 0xff); } public int readInt() { currentPosition += 4; return ((payload[currentPosition - 4] & 0xff) << 24) + ((payload[currentPosition - 3] & 0xff) << 16) + ((payload[currentPosition - 2] & 0xff) << 8) + (payload[currentPosition - 1] & 0xff); } public long readLong() { long msi = (long) readInt() & 0xffffffffL; long lsi = (long) readInt() & 0xffffffffL; return (msi << 32) + lsi; } public String readString() { int index = currentPosition; while (payload[currentPosition++] != 10) ; return new String(payload, index, currentPosition - index - 1); } public byte[] readBytes() { int index = currentPosition; while (payload[currentPosition++] != 10) ; byte data[] = new byte[currentPosition - index - 1]; System.arraycopy(payload, index, data, index - index, currentPosition - 1 - index); return data; } public void readBytes(int offset, int length, byte data[]) { for (int index = length; index < length + offset; index++) data[index] = payload[currentPosition++]; } public void initBitAccess() { bitPosition = currentPosition * 8; } public int readBits(int amount) { int byteOffset = bitPosition >> 3; int bitOffset = 8 - (bitPosition & 7); int value = 0; bitPosition += amount; for (; amount > bitOffset; bitOffset = 8) { value += (payload[byteOffset++] & BIT_MASKS[bitOffset]) << amount - bitOffset; amount -= bitOffset; } if (amount == bitOffset) value += payload[byteOffset] & BIT_MASKS[bitOffset]; else value += payload[byteOffset] >> bitOffset - amount & BIT_MASKS[amount]; return value; } public void disableBitAccess() { currentPosition = (bitPosition + 7) / 8; } public int readSmart() { int value = payload[currentPosition] & 0xff; if (value < 128) return readUnsignedByte() - 64; else return readUShort() - 49152; } public int getSmart() { try { // checks current without modifying position if (currentPosition >= payload.length) { return payload[payload.length - 1] & 0xFF; } int value = payload[currentPosition] & 0xFF; if (value < 128) { return readUnsignedByte(); } else { return readUShort() - 32768; } } catch (Exception e) { e.printStackTrace(); return readUShort() - 32768; } } public int readUSmart() { int value = payload[currentPosition] & 0xff; if (value < 128) return readUnsignedByte(); else return readUShort() - 32768; } public void encodeRSA(BigInteger exponent, BigInteger modulus) { int length = currentPosition; currentPosition = 0; byte buffer[] = new byte[length]; readBytes(length, 0, buffer); byte rsa[] = buffer; //if (Configuration.ENABLE_RSA) { rsa = new BigInteger(buffer).modPow(exponent, modulus) .toByteArray(); //} currentPosition = 0; writeByte(rsa.length); writeBytes(rsa, rsa.length, 0); } public void writeNegatedByte(int value) { payload[currentPosition++] = (byte) (-value); } public void writeByteS(int value) { payload[currentPosition++] = (byte) (128 - value); } public int readUByteA() { return payload[currentPosition++] - 128 & 0xff; } public int readNegUByte() { return -payload[currentPosition++] & 0xff; } public int readUByteS() { return 128 - payload[currentPosition++] & 0xff; } public byte readNegByte() { return (byte) -payload[currentPosition++]; } public byte readByteS() { return (byte) (128 - payload[currentPosition++]); } public void writeLEShort(int value) { payload[currentPosition++] = (byte) value; payload[currentPosition++] = (byte) (value >> 8); } public void writeShortA(int value) { payload[currentPosition++] = (byte) (value >> 8); payload[currentPosition++] = (byte) (value + 128); } public void writeLEShortA(int value) { payload[currentPosition++] = (byte) (value + 128); payload[currentPosition++] = (byte) (value >> 8); } public int readLEUShort() { currentPosition += 2; return ((payload[currentPosition - 1] & 0xff) << 8) + (payload[currentPosition - 2] & 0xff); } public int readUShortA() { currentPosition += 2; return ((payload[currentPosition - 2] & 0xff) << 8) + (payload[currentPosition - 1] - 128 & 0xff); } public int readLEUShortA() { currentPosition += 2; return ((payload[currentPosition - 1] & 0xff) << 8) + (payload[currentPosition - 2] - 128 & 0xff); } public int readLEShort() { currentPosition += 2; int value = ((payload[currentPosition - 1] & 0xff) << 8) + (payload[currentPosition - 2] & 0xff); if (value > 32767) { value -= 0x10000; } return value; } public int readLEShortA() { currentPosition += 2; int value = ((payload[currentPosition - 1] & 0xff) << 8) + (payload[currentPosition - 2] - 128 & 0xff); if (value > 32767) value -= 0x10000; return value; } public int getIntLittleEndian() { currentPosition += 4; return ((payload[currentPosition - 4] & 0xFF) << 24) + ((payload[currentPosition - 3] & 0xFF) << 16) + ((payload[currentPosition - 2] & 0xFF) << 8) + (payload[currentPosition - 1] & 0xFF); } public int readMEInt() { // V1 currentPosition += 4; return ((payload[currentPosition - 2] & 0xff) << 24) + ((payload[currentPosition - 1] & 0xff) << 16) + ((payload[currentPosition - 4] & 0xff) << 8) + (payload[currentPosition - 3] & 0xff); } public int readIMEInt() { // V2 currentPosition += 4; return ((payload[currentPosition - 3] & 0xff) << 24) + ((payload[currentPosition - 4] & 0xff) << 16) + ((payload[currentPosition - 1] & 0xff) << 8) + (payload[currentPosition - 2] & 0xff); } public void writeReverseDataA(byte data[], int length, int offset) { for (int index = (length + offset) - 1; index >= length; index--) { payload[currentPosition++] = (byte) (data[index] + 128); } } public void readReverseData(byte data[], int offset, int length) { for (int index = (length + offset) - 1; index >= length; index--) { data[index] = payload[currentPosition++]; } } } Socket package com.elvarg.util.flood; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; public final class BufferedConnection implements Runnable { public BufferedConnection(Socket socket1) throws IOException { closed = false; isWriter = false; hasIOError = false; socket = socket1; socket.setSoTimeout(30000); socket.setTcpNoDelay(true); inputStream = socket.getInputStream(); outputStream = socket.getOutputStream(); } public void close() { closed = true; try { if (inputStream != null) inputStream.close(); if (outputStream != null) outputStream.close(); if (socket != null) socket.close(); } catch (IOException _ex) { //System.out.println("Error closing stream"); } isWriter = false; synchronized (this) { notify(); } buffer = null; } public int read() throws IOException { if (closed) return 0; else return inputStream.read(); } public int available() throws IOException { if (closed) return 0; else return inputStream.available(); } public void flushInputStream(byte abyte0[], int j) throws IOException { int i = 0;// was parameter if (closed) return; int k; for (; j > 0; j -= k) { k = inputStream.read(abyte0, i, j); if (k <= 0) throw new IOException("EOF"); i += k; } } public void queueBytes(int i, byte abyte0[]) throws IOException { if (closed) { System.out.println("Closed"); return; } if (hasIOError) { hasIOError = false; //throw new IOException("Error in writer thread"); } if (buffer == null) buffer = new byte[5000]; synchronized (this) { for (int l = 0; l < i; l++) { buffer[buffIndex] = abyte0[l]; buffIndex = (buffIndex + 1) % 5000; if (buffIndex == (writeIndex + 4900) % 5000) throw new IOException("buffer overflow"); } if (!isWriter) { isWriter = true; Thread t = new Thread(this); t.setPriority(3); t.start(); } notify(); } } public void run() { while (isWriter) { int i; int j; synchronized (this) { if (buffIndex == writeIndex) try { wait(); } catch (InterruptedException _ex) { } if (!isWriter) return; j = writeIndex; if (buffIndex >= writeIndex) i = buffIndex - writeIndex; else i = 5000 - writeIndex; } if (i > 0) { try { outputStream.write(buffer, j, i); } catch (IOException _ex) { hasIOError = true; } writeIndex = (writeIndex + i) % 5000; try { if (buffIndex == writeIndex) outputStream.flush(); } catch (IOException _ex) { hasIOError = true; } } } } public void printDebug() { System.out.println("dummy:" + closed); System.out.println("tcycl:" + writeIndex); System.out.println("tnum:" + buffIndex); System.out.println("writer:" + isWriter); System.out.println("ioerror:" + hasIOError); try { System.out.println("available:" + available()); } catch (IOException _ex) { } } private InputStream inputStream; private OutputStream outputStream; private final Socket socket; private boolean closed; private byte[] buffer; private int writeIndex; private int buffIndex; private boolean isWriter; private boolean hasIOError; } Elvarg.java, put: /** * The flooder used to stress-test the server. */ private static Flooder flooder = new Flooder(); public static Flooder getFlooder() { return flooder; } Command for creating logins: if(parts[0].startsWith("flood")) { int amt = Integer.parseInt(parts[1]); Server.getFlooder().login(amt); } Player.java, replace: @Override public boolean equals(Object o) { if (!(o instanceof Player)) { return false; } Player p = (Player) o; return p.getUsername().equals(username); } Disclaimer: Please don't use this to target online servers which haven't changed their rsa keys/login decoder blocks ^ If you're using osrs pk/elvarg, consider updating rsa keys/login decoder blocks You can prob build on this to make pk bots and shit happen Usernames are currently Bot(and bot list size), example: bot23, can be changed easily. Look at the flooder class. Client sends opcode 0 every 25 client ticks. 1 client tick is currently set to 300 ms. Feel free to change that. Keep in mind that if you don't send a packet within a specific timeframe, session will go idle and close. I added the readPacket boolean but commented out the call cause I didn't find any use for it yet, feel free to use it edit: guess this can be used for any base. Just change the login in client class to match yours Note: You can distinguish real clients from bots by checking if their username exists in the clients map in Flooder class. This way you can make the fake clients do actions to actually stress test your server. Having them stand in a spot doing nothing barely does anything. Link to comment Share on other sites More sharing options...
Ary3x 0 Posted February 14, 2022 Report Share Posted February 14, 2022 Will be using thanks Link to comment Share on other sites More sharing options...
 nordvpn123 1 Posted October 13, 2022 Report Share Posted October 13, 2022 Thanks bro this is quite useful 😆 Link to comment Share on other sites More sharing options...
WalkToPoland 0 Posted October 16, 2022 Report Share Posted October 16, 2022 Thanks I'll use this stress/lag testing on my local base Link to comment Share on other sites More sharing options...
nick491 0 Posted July 7, 2023 Report Share Posted July 7, 2023 huge!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now