Here is my effort for this thread.
I have written a Java WarRock private server packet handler and now I'm going to release it here. This are functions to decode incoming packets from the log-in server.
Everything is explained inside the code, I want to encourage you guys to start learning to understand servers instead of requesting help with old and bugged server files. It isn't hard once you understand it. However, don't ask me help if you don't know a program language or how to use sockets because I amuse you do.
If you want to make your own server and you don't have any knowledge, well start by learning a program language, focus then on socket programming an networking. (I started by a simple chat program in Visual Basic 6).
Now let us get back on topic, here are the classes and functions I used.
I used 2 functions to decode and handle the packet, the packet parsing is done by a different class.
void processPackets():
Code:
public boolean processPackets() {
try {
// Check if the player is disconnected.
if (disconnected) { return false; }
// Checking if the inputstream is valid.
if (inStream == null) { return false; }
// Reading input stream and checking if its available.
if (inStream.available() == 0) { return false; }
// Reading packet buffers from the network stream.
int byteLen = inStream.read(this.packetBuffer);
if (byteLen > 1) {
// Seting-up a new temporary buffer for parsing the packet string later.
byte[] packetData = new byte[byteLen];
// Start of the packet decoding with the xOr keys of the client.
// the xOr keys can change, this is made for the login server (Nexon).
// Client -> Server (0xC3)
for (int i = 0; i < byteLen; i++) {
packetData[i] = (byte)(packetBuffer[i] ^ 0xC3);
}
// Convert the bytes array into a string with UTF8 encoding for processing it.
// TODO: Split the packets for stacked packets due the delay of it.
String packet = new String(packetData, "UTF8");
System.out.println("[BYTES RECV] >>" + packet); // Debug print.
// Parse the packet with the decoder.
PacketDecoder decoder = new PacketDecoder(packet);
// Handle the packet and check if it was a valid one.
return handlePacket(decoder);
}else{
// Packet bytes are way to short, disconnecting!
disconnect();
return false;
}
}catch (Exception e) {
// An exception occured, print print an error message and disconnect.
System.out.println("Failed to process the packet(s).");
disconnect();
return false;
}
}
boolean handlePacket():
Code:
private boolean handlePacket(PacketDecoder d) {
try {
// Validate the packet decoder class, if its null just return false,
// we let the loop know there was no packet handeld.
if (d == null) { return false; }
// Check the packet Id we are going to process.
switch (d.getId()) {
case 4352: { // Login request packet
//TODO: Write this function by yourself and handle it :)
break;
}
default: {
// We received a unknown packet.
System.out.println("Received a unknown packet id:" + d.getId());
System.out.println("Packet: " + d.getOriginalPacket());
break;
}
}
return true;
}catch (Exception e) {
// An exception occured while processing a packet, nothing bad happend so just display a message.
System.out.println("An exception occured while processing a packet!");
return false;
}
}
PacketDecoder.java:
Code:
public class PacketDecoder {
private long timeStamp;
private int packetId;
private String[] packetBlocks;
private String packetString;
public PacketDecoder(String packet) {
// We need to remember the original packet.
packetString = packet;
// Split the packet into blocks with their seperator (the space character).
String[] packetArgs = packet.split(" ");
// The first block(0) is the timestamp of the packet, we convert it into a long variable.
timeStamp = Long.parseLong(packetArgs[0]);
// The second block(1) is the packetid, it is a heximal value but for now we are going to use an int.
packetId = Integer.parseInt(packetArgs[1]);
// The rest of the blocks are the packet data.
// We are going to store the blocks in order, we move the blocks from 2 to the first place in the new block array.
// We continue this step until we reach the end of the splitted packet arguments.
packetBlocks = new String[packet.length() - 2];
for (int i = 2; i < packet.length(); i ++) {
packetBlocks[i-2] = packetArgs[i];
}
// The packet has been parsed into the class :)
}
// Return the timestamp.
public long getTimestamp() {
return this.timeStamp;
}
// Return the ID.
public int getId() {
return this.packetId;
}
// Return all datablocks as an array.
public String[] getAllBlocks() {
return this.packetBlocks;
}
// Return the original packet.
public String getOriginalPacket() {
return this.packetString;
}
}
Have fun with this code! I hope to see less people asking for help.