forked from 2009Scape/Server
Added initial version
This commit is contained in:
commit
b452bd670c
13290 changed files with 1178433 additions and 0 deletions
|
|
@ -0,0 +1,54 @@
|
|||
package ms.net.event;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import ms.net.IoReadEvent;
|
||||
import ms.net.IoSession;
|
||||
import ms.world.WorldDatabase;
|
||||
import ms.system.util.ByteBufferUtils;
|
||||
|
||||
/**
|
||||
* Handles handshake read events.
|
||||
* @author Emperor
|
||||
*/
|
||||
public final class HSReadEvent extends IoReadEvent {
|
||||
|
||||
/**
|
||||
* The password used to verify
|
||||
*/
|
||||
private static final String PASSWORD = "0x14ari0SSbh98989910";
|
||||
|
||||
/**
|
||||
* Constructs a new {@code HSReadEvent}.
|
||||
* @param session The session.
|
||||
* @param buffer The buffer.
|
||||
*/
|
||||
public HSReadEvent(IoSession session, ByteBuffer buffer) {
|
||||
super(session, buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(IoSession session, ByteBuffer buffer) {
|
||||
int opcode = buffer.get() & 0xFF;
|
||||
switch (opcode) {
|
||||
case 88:
|
||||
String password = ByteBufferUtils.getString(buffer);
|
||||
if (!password.equals(PASSWORD)) {
|
||||
System.out.println("Password mismatch (attempt=" + password + ")!");
|
||||
session.disconnect();
|
||||
break;
|
||||
}
|
||||
session.write(opcode);
|
||||
break;
|
||||
case 255: // World list
|
||||
int updateStamp = buffer.getInt();
|
||||
WorldDatabase.sendUpdate(session, updateStamp);
|
||||
break;
|
||||
default:
|
||||
System.err.println("Unhandled handshake opcode: " + opcode + ".");
|
||||
session.disconnect();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package ms.net.event;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import ms.net.IoSession;
|
||||
import ms.net.IoWriteEvent;
|
||||
import ms.net.producer.RegistryEventProducer;
|
||||
|
||||
/**
|
||||
* Handles Handshake write events.
|
||||
* @author Emperor
|
||||
*/
|
||||
public final class HSWriteEvent extends IoWriteEvent {
|
||||
|
||||
/**
|
||||
* The login event producer.
|
||||
*/
|
||||
private static final RegistryEventProducer REGISTRY_PRODUCER = new RegistryEventProducer();
|
||||
|
||||
/**
|
||||
* Constructs a new {@code HSWriteEvent} {@code Object}.
|
||||
* @param session The session.
|
||||
* @param context The context.
|
||||
*/
|
||||
public HSWriteEvent(IoSession session, Object context) {
|
||||
super(session, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(IoSession session, Object context) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(9);
|
||||
buffer.put((byte) 14);
|
||||
session.setProducer( REGISTRY_PRODUCER);
|
||||
buffer.flip();
|
||||
session.queue(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
package ms.net.event;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import ms.net.IoReadEvent;
|
||||
import ms.net.IoSession;
|
||||
import ms.net.packet.WorldPacketRepository;
|
||||
|
||||
/**
|
||||
* Handles world packet reading events.
|
||||
* @author Emperor
|
||||
*
|
||||
*/
|
||||
public final class PacketReadEvent extends IoReadEvent {
|
||||
|
||||
/**
|
||||
* The packet sizes.
|
||||
*/
|
||||
private static final int[] PACKET_SIZE = {
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructs a new {@code PacketReadEvent} {@code Object}.
|
||||
* @param session The I/O session.
|
||||
* @param buffer The buffer to read from.
|
||||
*/
|
||||
public PacketReadEvent(IoSession session, ByteBuffer buffer) {
|
||||
super(session, buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(IoSession session, ByteBuffer buffer) {
|
||||
int last = -1;
|
||||
while (buffer.hasRemaining()) {
|
||||
int opcode = buffer.get() & 0xFF;
|
||||
if (opcode >= PACKET_SIZE.length) {
|
||||
break;
|
||||
}
|
||||
int header = PACKET_SIZE[opcode];
|
||||
int size = header;
|
||||
if (header < 0) {
|
||||
size = getPacketSize(buffer, opcode, header, last);
|
||||
}
|
||||
if (size == -1) {
|
||||
break;
|
||||
}
|
||||
if (buffer.remaining() < size) {
|
||||
switch (header) {
|
||||
case -2:
|
||||
queueBuffer(opcode, size >> 8, size);
|
||||
break;
|
||||
case -1:
|
||||
queueBuffer(opcode, size);
|
||||
break;
|
||||
default:
|
||||
queueBuffer(opcode);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
byte[] data = new byte[size];
|
||||
buffer.get(data);
|
||||
last = opcode;
|
||||
try {
|
||||
WorldPacketRepository.handleIncoming(session, opcode, ByteBuffer.wrap(data));
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the packet size for the given opcode.
|
||||
* @param buffer The buffer.
|
||||
* @param opcode The opcode.
|
||||
* @param header The packet header.
|
||||
* @param last The last opcode.
|
||||
* @return The packet size.
|
||||
*/
|
||||
private int getPacketSize(ByteBuffer buffer, int opcode, int header, int last) {
|
||||
if (header == -1) {
|
||||
if (buffer.remaining() < 1) {
|
||||
queueBuffer(opcode);
|
||||
return -1;
|
||||
}
|
||||
return buffer.get() & 0xFF;
|
||||
}
|
||||
if (header == -2) {
|
||||
if (buffer.remaining() < 2) {
|
||||
queueBuffer(opcode);
|
||||
return -1;
|
||||
}
|
||||
return buffer.getShort() & 0xFFFF;
|
||||
}
|
||||
System.err.println("Invalid packet [opcode=" + opcode + ", last=" + last + ", queued=" + usedQueuedBuffer + "]!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package ms.net.event;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import ms.net.IoSession;
|
||||
import ms.net.IoWriteEvent;
|
||||
import ms.net.packet.IoBuffer;
|
||||
|
||||
/**
|
||||
* Handles world packet writing events.
|
||||
* @author Emperor
|
||||
*
|
||||
*/
|
||||
public final class PacketWriteEvent extends IoWriteEvent {
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new {@code PacketWriteEvent} {@code Object}.
|
||||
* @param session The I/O session.
|
||||
* @param context The packet context.
|
||||
*/
|
||||
public PacketWriteEvent(IoSession session, Object context) {
|
||||
super(session, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(IoSession session, Object context) {
|
||||
IoBuffer b = (IoBuffer) context;
|
||||
int size = b.toByteBuffer().position();
|
||||
ByteBuffer buffer = ByteBuffer.allocate(1 + size + b.getHeader().ordinal());
|
||||
buffer.put((byte) b.opcode());
|
||||
switch (b.getHeader()) {
|
||||
case NORMAL:
|
||||
break;
|
||||
case BYTE:
|
||||
buffer.put((byte) size);
|
||||
break;
|
||||
case SHORT:
|
||||
buffer.putShort((short) size);
|
||||
break;
|
||||
}
|
||||
buffer.put((ByteBuffer) b.toByteBuffer().flip());
|
||||
session.queue((ByteBuffer) buffer.flip());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
package ms.net.event;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import ms.ServerConstants;
|
||||
import ms.net.IoReadEvent;
|
||||
import ms.net.IoSession;
|
||||
import ms.world.WorldDatabase;
|
||||
import ms.system.util.ByteBufferUtils;
|
||||
import ms.world.info.CountryFlag;
|
||||
import ms.world.info.WorldInfo;
|
||||
|
||||
/**
|
||||
* Handles world registry read events.
|
||||
* @author Emperor
|
||||
*
|
||||
*/
|
||||
public final class RegistryReadEvent extends IoReadEvent {
|
||||
|
||||
/**
|
||||
* The string check.
|
||||
*/
|
||||
private static final String CHECK = "12x4578f5g45hrdjiofed59898";
|
||||
//kratos = 666x14x88x28shhhwpwwb&h
|
||||
//12x4578f5g45hrdjiofed59898
|
||||
|
||||
/**
|
||||
* Constructs a new {@code RegistryReadEvent} {@code Object}.
|
||||
* @param session The session.
|
||||
* @param buffer The buffer to read.
|
||||
*/
|
||||
public RegistryReadEvent(IoSession session, ByteBuffer buffer) {
|
||||
super(session, buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(IoSession session, ByteBuffer buffer) {
|
||||
int worldId = buffer.get() & 0xFF;
|
||||
if (buffer.remaining() < 2) {
|
||||
queueBuffer(worldId);
|
||||
return;
|
||||
}
|
||||
int revision = buffer.getInt();
|
||||
int country = buffer.get() & 0xFF;
|
||||
boolean members = buffer.get() == 1;
|
||||
boolean pvp = buffer.get() == 1;
|
||||
boolean quickChat = buffer.get() == 1;
|
||||
boolean lootshare = buffer.get() == 1;
|
||||
String activity = ByteBufferUtils.getString(buffer);
|
||||
System.out.println("["+ revision + "], country = " + country + ", members = " + members + ", pvp = " + pvp + ", quickChat = " + quickChat + ", lootShare = " + lootshare + ", activity = " + activity);
|
||||
for (int i = 0; i < CHECK.length(); i++) {
|
||||
if ((char) buffer.get() != CHECK.charAt(i)) {
|
||||
session.write(3);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (worldId >= ServerConstants.WORLD_LIMIT) {
|
||||
session.write(0);
|
||||
return;
|
||||
}
|
||||
if (WorldDatabase.isActive(worldId)) {
|
||||
session.write(2);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
WorldInfo info = new WorldInfo(worldId, session.getAddress(), revision, CountryFlag.values()[country], activity, members, pvp, quickChat, lootshare);
|
||||
WorldDatabase.register(info).configure(session);
|
||||
session.write(1);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
session.write(3);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package ms.net.event;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import ms.net.EventProducer;
|
||||
import ms.net.IoSession;
|
||||
import ms.net.IoWriteEvent;
|
||||
import ms.net.producer.PacketEventProducer;
|
||||
|
||||
/**
|
||||
* Handles game world registry writing events.
|
||||
* @author Emperor
|
||||
*
|
||||
*/
|
||||
public final class RegistryWriteEvent extends IoWriteEvent {
|
||||
|
||||
/**
|
||||
* The event producer.
|
||||
*/
|
||||
public static final EventProducer PRODUCER = new PacketEventProducer();
|
||||
|
||||
/**
|
||||
* Constructs a new {@code RegistryWriteEvent} {@code Object}.
|
||||
* @param session The I/O session.
|
||||
* @param context The writing context.
|
||||
*/
|
||||
public RegistryWriteEvent(IoSession session, Object context) {
|
||||
super(session, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(IoSession session, Object context) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(1);
|
||||
int opcode = (int) context;
|
||||
buffer.put((byte) opcode);
|
||||
buffer.flip();
|
||||
if (opcode == 1) {
|
||||
session.setProducer(PRODUCER);
|
||||
}
|
||||
session.queue(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue