mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-11-14 19:34:58 -05:00
Formatting
This commit is contained in:
parent
6b3768fe57
commit
4b6cd21d98
92 changed files with 910 additions and 902 deletions
|
@ -5,27 +5,27 @@ import ch.spacebase.mcprotocol.packet.Packet;
|
|||
public class PacketRecieveEvent extends ProtocolEvent {
|
||||
|
||||
private Packet packet;
|
||||
|
||||
|
||||
public PacketRecieveEvent(Packet packet) {
|
||||
this.packet = packet;
|
||||
}
|
||||
|
||||
|
||||
public Packet getPacket() {
|
||||
return this.packet;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Packet> T getPacket(Class<T> clazz) {
|
||||
try {
|
||||
return (T) this.packet;
|
||||
} catch(ClassCastException e) {
|
||||
} catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public void call(ProtocolListener listener) {
|
||||
listener.onPacketRecieve(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package ch.spacebase.mcprotocol.event;
|
||||
|
||||
public abstract class ProtocolListener {
|
||||
|
||||
|
||||
public abstract void onPacketRecieve(PacketRecieveEvent event);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,11 +3,11 @@ package ch.spacebase.mcprotocol.exception;
|
|||
public class ConnectException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
public ConnectException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
public ConnectException(String message, Exception e) {
|
||||
super(message, e);
|
||||
}
|
||||
|
|
|
@ -3,11 +3,11 @@ package ch.spacebase.mcprotocol.exception;
|
|||
public class LoginException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
public LoginException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
public LoginException(String message, Exception e) {
|
||||
super(message, e);
|
||||
}
|
||||
|
|
|
@ -10,55 +10,57 @@ import ch.spacebase.mcprotocol.exception.OutdatedLibraryException;
|
|||
import ch.spacebase.mcprotocol.util.Util;
|
||||
|
||||
public class Client extends Connection {
|
||||
|
||||
|
||||
private String username;
|
||||
private String sessionId;
|
||||
|
||||
|
||||
public Client(Protocol prot, String host, int port) {
|
||||
super(prot, host, port);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Assigns username without logging into minecraft.net. Use this login method
|
||||
* together with online-mode=false in server.properties.
|
||||
* @param username The username to assign.
|
||||
* Assigns username without logging into minecraft.net. Use this login
|
||||
* method together with online-mode=false in server.properties.
|
||||
*
|
||||
* @param username
|
||||
* The username to assign.
|
||||
*/
|
||||
public void setUser(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
|
||||
public void setSessionId(String id) {
|
||||
this.sessionId = id;
|
||||
}
|
||||
|
||||
|
||||
public boolean setUser(String username, String password) throws LoginException, OutdatedLibraryException {
|
||||
return this.getProtocol().login(this, username, password);
|
||||
}
|
||||
|
||||
|
||||
public Client connect() throws ConnectException {
|
||||
Util.logger().info("Connecting to \"" + this.host + ":" + this.port + "\"...");
|
||||
|
||||
|
||||
try {
|
||||
Socket sock = new Socket(InetAddress.getByName(this.host), this.port);
|
||||
sock.setSoTimeout(30000);
|
||||
sock.setTrafficClass(24);
|
||||
super.connect(sock);
|
||||
} catch(UnknownHostException e) {
|
||||
} catch (UnknownHostException e) {
|
||||
throw new ConnectException("Unknown host: " + this.host);
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
throw new ConnectException("Failed to open stream: " + this.host, e);
|
||||
}
|
||||
|
||||
|
||||
this.protocol.connect(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
|
||||
public String getSessionId() {
|
||||
return this.sessionId;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -24,47 +24,47 @@ public abstract class Connection {
|
|||
protected Protocol protocol;
|
||||
protected String host;
|
||||
protected int port;
|
||||
|
||||
|
||||
private DataInputStream input;
|
||||
private DataOutputStream output;
|
||||
|
||||
|
||||
private Queue<Packet> packets = new ConcurrentLinkedQueue<Packet>();
|
||||
private boolean connected;
|
||||
|
||||
|
||||
private List<ProtocolListener> listeners = new ArrayList<ProtocolListener>();
|
||||
|
||||
|
||||
public Connection(Protocol prot, String host, int port) {
|
||||
this.protocol = prot;
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public Protocol getProtocol() {
|
||||
return this.protocol;
|
||||
}
|
||||
|
||||
|
||||
public String getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
|
||||
public int getPort() {
|
||||
return this.port;
|
||||
}
|
||||
|
||||
|
||||
public void listen(ProtocolListener listener) {
|
||||
this.listeners.add(listener);
|
||||
}
|
||||
|
||||
|
||||
public <T extends ProtocolEvent> T call(T event) {
|
||||
for(ProtocolListener listener : this.listeners) {
|
||||
event.call(listener);
|
||||
}
|
||||
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
|
||||
public abstract Connection connect() throws ConnectException;
|
||||
|
||||
|
||||
protected void connect(Socket sock) throws ConnectException {
|
||||
try {
|
||||
this.input = new DataInputStream(sock.getInputStream());
|
||||
|
@ -72,25 +72,25 @@ public abstract class Connection {
|
|||
this.connected = true;
|
||||
new ListenThread().start();
|
||||
new WriteThread().start();
|
||||
} catch(UnknownHostException e) {
|
||||
} catch (UnknownHostException e) {
|
||||
throw new ConnectException("Unknown host: " + this.host);
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
throw new ConnectException("Failed to open stream: " + this.host, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DataInputStream getIn() {
|
||||
return this.input;
|
||||
}
|
||||
|
||||
|
||||
public DataOutputStream getOut() {
|
||||
return this.output;
|
||||
}
|
||||
|
||||
|
||||
public void setIn(InputStream in) {
|
||||
this.input = new DataInputStream(in);
|
||||
}
|
||||
|
||||
|
||||
public void setOut(OutputStream out) {
|
||||
this.output = new DataOutputStream(out);
|
||||
}
|
||||
|
@ -98,21 +98,21 @@ public abstract class Connection {
|
|||
public void send(Packet packet) {
|
||||
this.packets.add(packet);
|
||||
}
|
||||
|
||||
|
||||
public void disconnect(String reason) {
|
||||
this.disconnect(reason, true);
|
||||
}
|
||||
|
||||
|
||||
public void disconnect(String reason, boolean packet) {
|
||||
this.getProtocol().disconnected(this, reason, packet);
|
||||
this.packets.clear();
|
||||
this.connected = false;
|
||||
}
|
||||
|
||||
|
||||
public boolean isConnected() {
|
||||
return this.connected;
|
||||
}
|
||||
|
||||
|
||||
private class ListenThread extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -122,13 +122,13 @@ public abstract class Connection {
|
|||
if(opcode < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if(protocol.getType().getPacket(opcode) == null) {
|
||||
Util.logger().severe("Bad packet ID: " + opcode);
|
||||
disconnect("Bad packet ID: " + opcode);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Packet packet = protocol.getType().getPacket(opcode).newInstance();
|
||||
packet.read(input);
|
||||
if(Connection.this instanceof Client) {
|
||||
|
@ -136,9 +136,9 @@ public abstract class Connection {
|
|||
} else {
|
||||
packet.handleServer((ServerConnection) Connection.this);
|
||||
}
|
||||
|
||||
|
||||
call(new PacketRecieveEvent(packet));
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
Util.logger().severe("Error while listening to connection!");
|
||||
e.printStackTrace();
|
||||
disconnect("Error while listening to connection!");
|
||||
|
@ -146,19 +146,19 @@ public abstract class Connection {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class WriteThread extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
while(isConnected()) {
|
||||
if(packets.size() > 0) {
|
||||
Packet packet = packets.poll();
|
||||
|
||||
|
||||
try {
|
||||
output.write(packet.getId());
|
||||
packet.write(output);
|
||||
output.flush();
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
Util.logger().severe("Error while writing packet \"" + packet.getId() + "\"!");
|
||||
e.printStackTrace();
|
||||
disconnect("Error while writing packet.");
|
||||
|
@ -167,5 +167,5 @@ public abstract class Connection {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -82,127 +82,125 @@ import ch.spacebase.mcprotocol.standard.packet.PacketWindowProperty;
|
|||
public abstract class Protocol {
|
||||
|
||||
private Type type;
|
||||
|
||||
|
||||
public Protocol(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
public Type getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
|
||||
public abstract void connect(Client c);
|
||||
|
||||
|
||||
public abstract boolean login(Client c, String username, String password) throws LoginException, OutdatedLibraryException;
|
||||
|
||||
|
||||
public abstract void disconnected(Connection conn, String reason, boolean packet);
|
||||
|
||||
|
||||
public abstract void keepAlive(ServerConnection c);
|
||||
|
||||
|
||||
public enum Type {
|
||||
STANDARD,
|
||||
CLASSIC,
|
||||
POCKET;
|
||||
|
||||
STANDARD, CLASSIC, POCKET;
|
||||
|
||||
static {
|
||||
// standard protocol
|
||||
STANDARD.registerPacket(0, PacketKeepAlive.class);
|
||||
STANDARD.registerPacket(1, PacketLogin.class);
|
||||
STANDARD.registerPacket(2, PacketHandshake.class);
|
||||
STANDARD.registerPacket(3, PacketChat.class);
|
||||
STANDARD.registerPacket(4, PacketTimeUpdate.class);
|
||||
STANDARD.registerPacket(5, PacketEntityEquipment.class);
|
||||
STANDARD.registerPacket(6, PacketSpawnPosition.class);
|
||||
STANDARD.registerPacket(7, PacketUseEntity.class);
|
||||
STANDARD.registerPacket(8, PacketHealthUpdate.class);
|
||||
STANDARD.registerPacket(9, PacketRespawn.class);
|
||||
STANDARD.registerPacket(10, PacketPlayer.class);
|
||||
STANDARD.registerPacket(11, PacketPlayerPosition.class);
|
||||
STANDARD.registerPacket(12, PacketPlayerLook.class);
|
||||
STANDARD.registerPacket(13, PacketPlayerPositionLook.class);
|
||||
STANDARD.registerPacket(14, PacketPlayerDigging.class);
|
||||
STANDARD.registerPacket(15, PacketPlayerBlockPlace.class);
|
||||
STANDARD.registerPacket(16, PacketHeldItemChange.class);
|
||||
STANDARD.registerPacket(17, PacketUseBed.class);
|
||||
STANDARD.registerPacket(18, PacketAnimation.class);
|
||||
STANDARD.registerPacket(19, PacketEntityAction.class);
|
||||
STANDARD.registerPacket(20, PacketSpawnNamedEntity.class);
|
||||
STANDARD.registerPacket(21, PacketSpawnDroppedItem.class);
|
||||
STANDARD.registerPacket(22, PacketCollectItem.class);
|
||||
STANDARD.registerPacket(23, PacketSpawnVehicle.class);
|
||||
STANDARD.registerPacket(24, PacketSpawnMob.class);
|
||||
STANDARD.registerPacket(25, PacketSpawnPainting.class);
|
||||
STANDARD.registerPacket(26, PacketSpawnExpOrb.class);
|
||||
STANDARD.registerPacket(28, PacketEntityVelocity.class);
|
||||
STANDARD.registerPacket(29, PacketDestroyEntity.class);
|
||||
STANDARD.registerPacket(30, PacketEntity.class);
|
||||
STANDARD.registerPacket(31, PacketEntityRelativeMove.class);
|
||||
STANDARD.registerPacket(32, PacketEntityLook.class);
|
||||
STANDARD.registerPacket(33, PacketEntityLookRelativeMove.class);
|
||||
STANDARD.registerPacket(34, PacketEntityTeleport.class);
|
||||
STANDARD.registerPacket(35, PacketEntityHeadYaw.class);
|
||||
STANDARD.registerPacket(38, PacketEntityStatus.class);
|
||||
STANDARD.registerPacket(39, PacketAttachEntity.class);
|
||||
STANDARD.registerPacket(40, PacketEntityMetadata.class);
|
||||
STANDARD.registerPacket(41, PacketEntityEffect.class);
|
||||
STANDARD.registerPacket(42, PacketRemoveEntityEffect.class);
|
||||
STANDARD.registerPacket(43, PacketSetExperience.class);
|
||||
STANDARD.registerPacket(51, PacketMapChunk.class);
|
||||
STANDARD.registerPacket(52, PacketMultiBlockChange.class);
|
||||
STANDARD.registerPacket(53, PacketBlockChange.class);
|
||||
STANDARD.registerPacket(54, PacketBlockAction.class);
|
||||
STANDARD.registerPacket(55, PacketBlockBreakAnimation.class);
|
||||
STANDARD.registerPacket(56, PacketMapChunkBulk.class);
|
||||
STANDARD.registerPacket(60, PacketExplosion.class);
|
||||
STANDARD.registerPacket(61, PacketEffect.class);
|
||||
STANDARD.registerPacket(62, PacketNamedSound.class);
|
||||
STANDARD.registerPacket(70, PacketGameState.class);
|
||||
STANDARD.registerPacket(71, PacketLightning.class);
|
||||
STANDARD.registerPacket(100, PacketOpenWindow.class);
|
||||
STANDARD.registerPacket(101, PacketCloseWindow.class);
|
||||
STANDARD.registerPacket(102, PacketWindowClick.class);
|
||||
STANDARD.registerPacket(103, PacketSetSlot.class);
|
||||
STANDARD.registerPacket(104, PacketWindowItems.class);
|
||||
STANDARD.registerPacket(105, PacketWindowProperty.class);
|
||||
STANDARD.registerPacket(106, PacketConfirmTransaction.class);
|
||||
STANDARD.registerPacket(107, PacketCreativeSlot.class);
|
||||
STANDARD.registerPacket(108, PacketEnchantItem.class);
|
||||
STANDARD.registerPacket(130, PacketUpdateSign.class);
|
||||
STANDARD.registerPacket(131, PacketItemData.class);
|
||||
STANDARD.registerPacket(132, PacketUpdateTileEntity.class);
|
||||
STANDARD.registerPacket(200, PacketIncrementStatistic.class);
|
||||
STANDARD.registerPacket(201, PacketPlayerListItem.class);
|
||||
STANDARD.registerPacket(202, PacketPlayerAbilities.class);
|
||||
STANDARD.registerPacket(203, PacketTabComplete.class);
|
||||
STANDARD.registerPacket(204, PacketClientInfo.class);
|
||||
STANDARD.registerPacket(4, PacketTimeUpdate.class);
|
||||
STANDARD.registerPacket(5, PacketEntityEquipment.class);
|
||||
STANDARD.registerPacket(6, PacketSpawnPosition.class);
|
||||
STANDARD.registerPacket(7, PacketUseEntity.class);
|
||||
STANDARD.registerPacket(8, PacketHealthUpdate.class);
|
||||
STANDARD.registerPacket(9, PacketRespawn.class);
|
||||
STANDARD.registerPacket(10, PacketPlayer.class);
|
||||
STANDARD.registerPacket(11, PacketPlayerPosition.class);
|
||||
STANDARD.registerPacket(12, PacketPlayerLook.class);
|
||||
STANDARD.registerPacket(13, PacketPlayerPositionLook.class);
|
||||
STANDARD.registerPacket(14, PacketPlayerDigging.class);
|
||||
STANDARD.registerPacket(15, PacketPlayerBlockPlace.class);
|
||||
STANDARD.registerPacket(16, PacketHeldItemChange.class);
|
||||
STANDARD.registerPacket(17, PacketUseBed.class);
|
||||
STANDARD.registerPacket(18, PacketAnimation.class);
|
||||
STANDARD.registerPacket(19, PacketEntityAction.class);
|
||||
STANDARD.registerPacket(20, PacketSpawnNamedEntity.class);
|
||||
STANDARD.registerPacket(21, PacketSpawnDroppedItem.class);
|
||||
STANDARD.registerPacket(22, PacketCollectItem.class);
|
||||
STANDARD.registerPacket(23, PacketSpawnVehicle.class);
|
||||
STANDARD.registerPacket(24, PacketSpawnMob.class);
|
||||
STANDARD.registerPacket(25, PacketSpawnPainting.class);
|
||||
STANDARD.registerPacket(26, PacketSpawnExpOrb.class);
|
||||
STANDARD.registerPacket(28, PacketEntityVelocity.class);
|
||||
STANDARD.registerPacket(29, PacketDestroyEntity.class);
|
||||
STANDARD.registerPacket(30, PacketEntity.class);
|
||||
STANDARD.registerPacket(31, PacketEntityRelativeMove.class);
|
||||
STANDARD.registerPacket(32, PacketEntityLook.class);
|
||||
STANDARD.registerPacket(33, PacketEntityLookRelativeMove.class);
|
||||
STANDARD.registerPacket(34, PacketEntityTeleport.class);
|
||||
STANDARD.registerPacket(35, PacketEntityHeadYaw.class);
|
||||
STANDARD.registerPacket(38, PacketEntityStatus.class);
|
||||
STANDARD.registerPacket(39, PacketAttachEntity.class);
|
||||
STANDARD.registerPacket(40, PacketEntityMetadata.class);
|
||||
STANDARD.registerPacket(41, PacketEntityEffect.class);
|
||||
STANDARD.registerPacket(42, PacketRemoveEntityEffect.class);
|
||||
STANDARD.registerPacket(43, PacketSetExperience.class);
|
||||
STANDARD.registerPacket(51, PacketMapChunk.class);
|
||||
STANDARD.registerPacket(52, PacketMultiBlockChange.class);
|
||||
STANDARD.registerPacket(53, PacketBlockChange.class);
|
||||
STANDARD.registerPacket(54, PacketBlockAction.class);
|
||||
STANDARD.registerPacket(55, PacketBlockBreakAnimation.class);
|
||||
STANDARD.registerPacket(56, PacketMapChunkBulk.class);
|
||||
STANDARD.registerPacket(60, PacketExplosion.class);
|
||||
STANDARD.registerPacket(61, PacketEffect.class);
|
||||
STANDARD.registerPacket(62, PacketNamedSound.class);
|
||||
STANDARD.registerPacket(70, PacketGameState.class);
|
||||
STANDARD.registerPacket(71, PacketLightning.class);
|
||||
STANDARD.registerPacket(100, PacketOpenWindow.class);
|
||||
STANDARD.registerPacket(101, PacketCloseWindow.class);
|
||||
STANDARD.registerPacket(102, PacketWindowClick.class);
|
||||
STANDARD.registerPacket(103, PacketSetSlot.class);
|
||||
STANDARD.registerPacket(104, PacketWindowItems.class);
|
||||
STANDARD.registerPacket(105, PacketWindowProperty.class);
|
||||
STANDARD.registerPacket(106, PacketConfirmTransaction.class);
|
||||
STANDARD.registerPacket(107, PacketCreativeSlot.class);
|
||||
STANDARD.registerPacket(108, PacketEnchantItem.class);
|
||||
STANDARD.registerPacket(130, PacketUpdateSign.class);
|
||||
STANDARD.registerPacket(131, PacketItemData.class);
|
||||
STANDARD.registerPacket(132, PacketUpdateTileEntity.class);
|
||||
STANDARD.registerPacket(200, PacketIncrementStatistic.class);
|
||||
STANDARD.registerPacket(201, PacketPlayerListItem.class);
|
||||
STANDARD.registerPacket(202, PacketPlayerAbilities.class);
|
||||
STANDARD.registerPacket(203, PacketTabComplete.class);
|
||||
STANDARD.registerPacket(204, PacketClientInfo.class);
|
||||
STANDARD.registerPacket(205, PacketClientStatus.class);
|
||||
STANDARD.registerPacket(250, PacketPluginMessage.class);
|
||||
STANDARD.registerPacket(252, PacketKeyResponse.class);
|
||||
STANDARD.registerPacket(253, PacketKeyRequest.class);
|
||||
STANDARD.registerPacket(254, PacketServerPing.class);
|
||||
STANDARD.registerPacket(255, PacketDisconnect.class);
|
||||
|
||||
|
||||
// classic protocol
|
||||
// TODO
|
||||
|
||||
|
||||
// pocket protocol
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private final Class<? extends Packet> packets[] = new Class[256];
|
||||
|
||||
|
||||
public void registerPacket(int id, Class<? extends Packet> packet) {
|
||||
this.packets[id] = packet;
|
||||
}
|
||||
|
||||
|
||||
public Class<? extends Packet> getPacket(int id) {
|
||||
try {
|
||||
return this.packets[id];
|
||||
} catch(ArrayIndexOutOfBoundsException e) {
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,17 +16,17 @@ public class Server {
|
|||
|
||||
private int port;
|
||||
private boolean online;
|
||||
|
||||
|
||||
private List<ServerConnection> connections = new CopyOnWriteArrayList<ServerConnection>();
|
||||
private KeyPair keys;
|
||||
private boolean verify;
|
||||
private Class<? extends Protocol> protocol;
|
||||
|
||||
|
||||
public Server(Class<? extends Protocol> prot, int port, boolean verifyUsers) {
|
||||
this.port = port;
|
||||
this.verify = verifyUsers;
|
||||
this.protocol = prot;
|
||||
|
||||
|
||||
try {
|
||||
KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
|
||||
gen.initialize(1024);
|
||||
|
@ -35,7 +35,7 @@ public class Server {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void bind() {
|
||||
try {
|
||||
ServerSocket sock = new ServerSocket(this.port);
|
||||
|
@ -45,30 +45,30 @@ public class Server {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void shutdown() {
|
||||
for(ServerConnection conn : this.connections) {
|
||||
conn.disconnect("The server is shutting down!");
|
||||
}
|
||||
|
||||
|
||||
this.online = false;
|
||||
}
|
||||
|
||||
|
||||
public KeyPair getKeys() {
|
||||
return this.keys;
|
||||
}
|
||||
|
||||
|
||||
public boolean verifyUsers() {
|
||||
return this.verify;
|
||||
}
|
||||
|
||||
|
||||
private class ServerConnectionThread extends Thread {
|
||||
private ServerSocket sock;
|
||||
|
||||
|
||||
public ServerConnectionThread(ServerSocket sock) {
|
||||
this.sock = sock;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(online) {
|
||||
|
@ -80,7 +80,7 @@ public class Server {
|
|||
Util.logger().severe("Failed to create server connection!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
Util.logger().severe("Failed to accept connection from client!");
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
|
@ -92,5 +92,5 @@ public class Server {
|
|||
public List<ServerConnection> getConnections() {
|
||||
return new ArrayList<ServerConnection>(this.connections);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,38 +5,38 @@ import java.net.Socket;
|
|||
import ch.spacebase.mcprotocol.exception.ConnectException;
|
||||
|
||||
public class ServerConnection extends Connection {
|
||||
|
||||
|
||||
private String username;
|
||||
|
||||
|
||||
private Socket sock;
|
||||
private Server server;
|
||||
|
||||
|
||||
private long aliveTime = System.currentTimeMillis();
|
||||
|
||||
|
||||
public ServerConnection(Protocol prot, Server server, Socket sock) {
|
||||
super(prot, sock.getInetAddress().getHostName(), ((InetSocketAddress) sock.getRemoteSocketAddress()).getPort());
|
||||
this.server = server;
|
||||
this.sock = sock;
|
||||
}
|
||||
|
||||
|
||||
public ServerConnection connect() throws ConnectException {
|
||||
super.connect(this.sock);
|
||||
new KeepAliveThread().start();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
|
||||
public Server getServer() {
|
||||
return this.server;
|
||||
}
|
||||
|
||||
|
||||
private class KeepAliveThread extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -48,5 +48,5 @@ public class ServerConnection extends Connection {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,18 +7,18 @@ import ch.spacebase.mcprotocol.net.Client;
|
|||
import ch.spacebase.mcprotocol.net.ServerConnection;
|
||||
|
||||
public abstract class Packet {
|
||||
|
||||
|
||||
public Packet() {
|
||||
}
|
||||
|
||||
|
||||
public abstract void read(DataInputStream in) throws IOException;
|
||||
|
||||
|
||||
public abstract void write(DataOutputStream out) throws IOException;
|
||||
|
||||
|
||||
public abstract void handleClient(Client conn);
|
||||
|
||||
|
||||
public abstract void handleServer(ServerConnection conn);
|
||||
|
||||
|
||||
public abstract int getId();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -37,18 +37,18 @@ import ch.spacebase.mcprotocol.util.Util;
|
|||
public class StandardProtocol extends Protocol {
|
||||
|
||||
private final Random rand = new Random();
|
||||
|
||||
|
||||
private boolean session;
|
||||
private String serverId;
|
||||
private SecretKey key;
|
||||
private int aliveId;
|
||||
private int aliveId;
|
||||
private String loginKey;
|
||||
private byte token[];
|
||||
|
||||
|
||||
public StandardProtocol() {
|
||||
super(Type.STANDARD);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void connect(Client c) {
|
||||
c.send(new PacketHandshake(c.getUsername(), c.getHost(), c.getPort()));
|
||||
|
@ -57,119 +57,119 @@ public class StandardProtocol extends Protocol {
|
|||
@Override
|
||||
public boolean login(Client c, String username, String password) throws LoginException, OutdatedLibraryException {
|
||||
URL url = null;
|
||||
|
||||
|
||||
try {
|
||||
url = new URL("https://login.minecraft.net/");
|
||||
} catch(MalformedURLException e) {
|
||||
} catch (MalformedURLException e) {
|
||||
throw new LoginException("Login URL is malformed?", e);
|
||||
}
|
||||
|
||||
|
||||
String params = "";
|
||||
|
||||
|
||||
try {
|
||||
params = "user=" + URLEncoder.encode(username, "UTF-8") + "&password=" + URLEncoder.encode(password, "UTF-8") + "&version=" + Constants.LAUNCHER_VERSION;
|
||||
} catch(UnsupportedEncodingException e) {
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new LoginException("UTF-8 unsupported", e);
|
||||
}
|
||||
|
||||
|
||||
HttpURLConnection conn = null;
|
||||
|
||||
|
||||
try {
|
||||
Util.logger().info("Sending info to login.minecraft.net...");
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
conn.setRequestProperty("Content-Length", Integer.toString(params.getBytes().length));
|
||||
conn.setRequestProperty("Content-Language", "en-US");
|
||||
conn.setUseCaches(false);
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
conn.setReadTimeout(1000 * 60 * 10);
|
||||
|
||||
conn.connect();
|
||||
|
||||
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
|
||||
out.writeBytes(params);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
if (conn.getResponseCode() != 200) {
|
||||
throw new LoginException("Login returned response " + conn.getResponseCode() + ": " + conn.getResponseMessage());
|
||||
}
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
|
||||
StringBuilder build = new StringBuilder();
|
||||
|
||||
char[] buffer = new char[1024];
|
||||
int length = 0;
|
||||
while((length = reader.read(buffer)) != -1) {
|
||||
build.append(buffer, 0, length);
|
||||
}
|
||||
|
||||
String result = build.toString();
|
||||
if (result.contains(":")) {
|
||||
String[] values = result.split(":");
|
||||
|
||||
try {
|
||||
c.setUser(values[2].trim());
|
||||
c.setSessionId(values[3].trim());
|
||||
this.session = true;
|
||||
|
||||
new Thread(new KeepAliveTask()).start();
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
throw new LoginException("Response contained incorrect amount of parameters: " + result);
|
||||
}
|
||||
|
||||
Util.logger().info("Finished logging in to minecraft.net");
|
||||
return true;
|
||||
} else {
|
||||
if (result.trim().equals("Bad login")) {
|
||||
return false;
|
||||
} else if (result.trim().equals("Old version")) {
|
||||
throw new OutdatedLibraryException();
|
||||
} else {
|
||||
throw new LoginException(result.trim());
|
||||
}
|
||||
}
|
||||
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
conn.setRequestProperty("Content-Length", Integer.toString(params.getBytes().length));
|
||||
conn.setRequestProperty("Content-Language", "en-US");
|
||||
conn.setUseCaches(false);
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
conn.setReadTimeout(1000 * 60 * 10);
|
||||
|
||||
conn.connect();
|
||||
|
||||
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
|
||||
out.writeBytes(params);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
if(conn.getResponseCode() != 200) {
|
||||
throw new LoginException("Login returned response " + conn.getResponseCode() + ": " + conn.getResponseMessage());
|
||||
}
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
|
||||
StringBuilder build = new StringBuilder();
|
||||
|
||||
char[] buffer = new char[1024];
|
||||
int length = 0;
|
||||
while((length = reader.read(buffer)) != -1) {
|
||||
build.append(buffer, 0, length);
|
||||
}
|
||||
|
||||
String result = build.toString();
|
||||
if(result.contains(":")) {
|
||||
String[] values = result.split(":");
|
||||
|
||||
try {
|
||||
c.setUser(values[2].trim());
|
||||
c.setSessionId(values[3].trim());
|
||||
this.session = true;
|
||||
|
||||
new Thread(new KeepAliveTask()).start();
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
throw new LoginException("Response contained incorrect amount of parameters: " + result);
|
||||
}
|
||||
|
||||
Util.logger().info("Finished logging in to minecraft.net");
|
||||
return true;
|
||||
} else {
|
||||
if(result.trim().equals("Bad login")) {
|
||||
return false;
|
||||
} else if(result.trim().equals("Old version")) {
|
||||
throw new OutdatedLibraryException();
|
||||
} else {
|
||||
throw new LoginException(result.trim());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new LoginException("Failed to login", e);
|
||||
} finally {
|
||||
if (conn != null) conn.disconnect();
|
||||
if(conn != null) conn.disconnect();
|
||||
conn = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class KeepAliveTask implements Runnable {
|
||||
private URL url;
|
||||
private long last;
|
||||
|
||||
|
||||
public KeepAliveTask() throws LoginException {
|
||||
try {
|
||||
this.url = new URL("https://login.minecraft.net/");
|
||||
} catch(MalformedURLException e) {
|
||||
} catch (MalformedURLException e) {
|
||||
throw new LoginException("Failed to create keep alive URL!", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
this.last = System.currentTimeMillis();
|
||||
while(session) {
|
||||
if(System.currentTimeMillis() - this.last >= 300000) {
|
||||
HttpURLConnection conn = null;
|
||||
|
||||
|
||||
try {
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setUseCaches(false);
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
conn.setReadTimeout(1000 * 60 * 10);
|
||||
conn.connect();
|
||||
conn.setUseCaches(false);
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
conn.setReadTimeout(1000 * 60 * 10);
|
||||
conn.connect();
|
||||
} catch (IOException e) {
|
||||
Util.logger().severe("Failed to send keep alive to login.minecraft.net!");
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (conn != null) conn.disconnect();
|
||||
if(conn != null) conn.disconnect();
|
||||
conn = null;
|
||||
}
|
||||
}
|
||||
|
@ -182,53 +182,53 @@ public class StandardProtocol extends Protocol {
|
|||
if(packet) conn.send(new PacketDisconnect(reason));
|
||||
this.session = false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void keepAlive(ServerConnection c) {
|
||||
aliveId = rand.nextInt();
|
||||
c.send(new PacketKeepAlive(aliveId));
|
||||
}
|
||||
|
||||
|
||||
public String getLoginKey() {
|
||||
return this.loginKey;
|
||||
}
|
||||
|
||||
|
||||
public void setLoginKey(String key) {
|
||||
this.loginKey = key;
|
||||
}
|
||||
|
||||
|
||||
public byte[] getToken() {
|
||||
return this.token;
|
||||
}
|
||||
|
||||
|
||||
public void setToken(byte token[]) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
|
||||
public String getServerId() {
|
||||
return this.serverId;
|
||||
}
|
||||
|
||||
|
||||
public void setServerId(String id) {
|
||||
this.serverId = id;
|
||||
}
|
||||
|
||||
|
||||
public void setAES(Connection conn) {
|
||||
BufferedBlockCipher in = new BufferedBlockCipher(new CFBBlockCipher(new AESFastEngine(), 8));
|
||||
in.init(false, new ParametersWithIV(new KeyParameter(this.key.getEncoded()), this.key.getEncoded(), 0, 16));
|
||||
BufferedBlockCipher out = new BufferedBlockCipher(new CFBBlockCipher(new AESFastEngine(), 8));
|
||||
out.init(true, new ParametersWithIV(new KeyParameter(this.key.getEncoded()), this.key.getEncoded(), 0, 16));
|
||||
|
||||
|
||||
conn.setIn(new DataInputStream(new CipherInputStream(conn.getIn(), in)));
|
||||
conn.setOut(new DataOutputStream(new CipherOutputStream(conn.getOut(), out)));
|
||||
}
|
||||
|
||||
|
||||
public SecretKey getSecretKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
|
||||
public void setSecretKey(SecretKey key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -11,17 +11,17 @@ public class Coordinates {
|
|||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
|
||||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -10,61 +10,61 @@ public class ItemStack {
|
|||
private byte stackSize;
|
||||
private short damage;
|
||||
private byte nbt[];
|
||||
|
||||
|
||||
public ItemStack() {
|
||||
}
|
||||
|
||||
|
||||
public ItemStack(short item) {
|
||||
this(item, (byte) 1);
|
||||
}
|
||||
|
||||
|
||||
public ItemStack(short item, byte stackSize) {
|
||||
this(item, stackSize, (short) 0);
|
||||
}
|
||||
|
||||
|
||||
public ItemStack(short item, byte stackSize, short damage) {
|
||||
this(item, stackSize, damage, null);
|
||||
}
|
||||
|
||||
|
||||
public ItemStack(short item, byte stackSize, short damage, byte nbt[]) {
|
||||
this.item = item;
|
||||
this.stackSize = stackSize;
|
||||
this.damage = damage;
|
||||
this.nbt = nbt;
|
||||
}
|
||||
|
||||
|
||||
public short getItem() {
|
||||
return this.item;
|
||||
}
|
||||
|
||||
|
||||
public void setItem(short item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
|
||||
public byte getStackSize() {
|
||||
return this.stackSize;
|
||||
}
|
||||
|
||||
|
||||
public void setStackSize(byte stackSize) {
|
||||
this.stackSize = stackSize;
|
||||
}
|
||||
|
||||
|
||||
public short getDamage() {
|
||||
return this.damage;
|
||||
}
|
||||
|
||||
|
||||
public void setDamage(short damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
|
||||
public byte[] getNBT() {
|
||||
return this.nbt;
|
||||
}
|
||||
|
||||
|
||||
public void setNBT(byte nbt[]) {
|
||||
this.nbt = nbt;
|
||||
}
|
||||
|
||||
|
||||
public void read(DataInputStream in) throws IOException {
|
||||
this.item = in.readShort();
|
||||
if(this.item > -1) {
|
||||
|
@ -77,7 +77,7 @@ public class ItemStack {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void write(DataOutputStream out) throws IOException {
|
||||
out.writeShort(this.item);
|
||||
if(this.item != -1) {
|
||||
|
@ -89,5 +89,5 @@ public class ItemStack {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,21 +5,21 @@ public class WatchableObject {
|
|||
private int type;
|
||||
private int id;
|
||||
private Object value;
|
||||
|
||||
|
||||
public WatchableObject(int type, int id, Object value) {
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
public int getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
|
|
@ -12,12 +12,13 @@ import ch.spacebase.mcprotocol.standard.packet.PacketChat;
|
|||
import ch.spacebase.mcprotocol.standard.packet.PacketPlayerPositionLook;
|
||||
|
||||
/**
|
||||
* A simple bot that prints "Hello, this is Heisenberg at coordinate <coordinate>".
|
||||
* Be sure to use the Bukkit server setting online-mode=false in server.properties.
|
||||
* Otherwise supply a valid minecraft.net username and password.
|
||||
* A simple bot that prints
|
||||
* "Hello, this is Heisenberg at coordinate <coordinate>". Be sure to use the
|
||||
* Bukkit server setting online-mode=false in server.properties. Otherwise
|
||||
* supply a valid minecraft.net username and password.
|
||||
*/
|
||||
public class ChatBot {
|
||||
|
||||
|
||||
private Client client;
|
||||
private Listener listener;
|
||||
|
||||
|
@ -47,12 +48,12 @@ public class ChatBot {
|
|||
public static void main(String[] args) {
|
||||
ChatBot bot = new ChatBot("127.0.0.1", 25565);
|
||||
System.out.println("Logging in...");
|
||||
bot.login("Heisenberg");
|
||||
bot.login("Heisenberg");
|
||||
}
|
||||
|
||||
private class Listener extends ProtocolListener {
|
||||
@Override
|
||||
public void onPacketRecieve(PacketRecieveEvent event) {
|
||||
public void onPacketRecieve(PacketRecieveEvent event) {
|
||||
Packet packet = event.getPacket();
|
||||
|
||||
switch(event.getPacket().getId()) {
|
||||
|
@ -66,10 +67,8 @@ public class ChatBot {
|
|||
client.send(packet);
|
||||
DecimalFormat format = new DecimalFormat("#.00");
|
||||
|
||||
ChatBot.this.say("Hello, this is Heisenberg at coordinate (" +
|
||||
format.format(packet.x) + ", " + format.format(packet.y) + ", " + format.format(packet.z) +
|
||||
")");
|
||||
ChatBot.this.say("Hello, this is Heisenberg at coordinate (" + format.format(packet.x) + ", " + format.format(packet.y) + ", " + format.format(packet.z) + ")");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ public class PacketAnimation extends Packet {
|
|||
|
||||
public int entityId;
|
||||
public byte animation;
|
||||
|
||||
|
||||
public PacketAnimation() {
|
||||
}
|
||||
|
||||
|
||||
public PacketAnimation(int entityId, byte animation) {
|
||||
this.entityId = entityId;
|
||||
this.animation = animation;
|
||||
|
@ -36,14 +36,14 @@ public class PacketAnimation extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 18;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ public class PacketAttachEntity extends Packet {
|
|||
|
||||
public int entityId;
|
||||
public int vehicleId;
|
||||
|
||||
|
||||
public PacketAttachEntity() {
|
||||
}
|
||||
|
||||
|
||||
public PacketAttachEntity(int entityId, int vehicleId) {
|
||||
this.entityId = entityId;
|
||||
this.vehicleId = vehicleId;
|
||||
|
@ -36,14 +36,14 @@ public class PacketAttachEntity extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 39;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@ public class PacketBlockAction extends Packet {
|
|||
public byte b1;
|
||||
public byte b2;
|
||||
public int block;
|
||||
|
||||
|
||||
public PacketBlockAction() {
|
||||
}
|
||||
|
||||
|
||||
public PacketBlockAction(int x, int y, int z, byte b1, byte b2, short block) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
@ -52,14 +52,14 @@ public class PacketBlockAction extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 54;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@ public class PacketBlockBreakAnimation extends Packet {
|
|||
public int y;
|
||||
public int z;
|
||||
public byte stage;
|
||||
|
||||
|
||||
public PacketBlockBreakAnimation() {
|
||||
}
|
||||
|
||||
|
||||
public PacketBlockBreakAnimation(int entityId, int x, int y, int z, byte stage) {
|
||||
this.entityId = entityId;
|
||||
this.x = x;
|
||||
|
@ -48,14 +48,14 @@ public class PacketBlockBreakAnimation extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 55;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@ public class PacketBlockChange extends Packet {
|
|||
public int z;
|
||||
public short block;
|
||||
public byte data;
|
||||
|
||||
|
||||
public PacketBlockChange() {
|
||||
}
|
||||
|
||||
|
||||
public PacketBlockChange(int x, int y, int z, short block, byte data) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
@ -48,14 +48,14 @@ public class PacketBlockChange extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 53;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,14 +12,14 @@ import ch.spacebase.mcprotocol.util.IOUtils;
|
|||
public class PacketChat extends Packet {
|
||||
|
||||
public String message;
|
||||
|
||||
|
||||
public PacketChat() {
|
||||
}
|
||||
|
||||
|
||||
public PacketChat(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class PacketChat extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@ public class PacketClientInfo extends Packet {
|
|||
public byte chatFlags;
|
||||
public byte difficulty;
|
||||
public boolean cape;
|
||||
|
||||
|
||||
public PacketClientInfo() {
|
||||
}
|
||||
|
||||
|
||||
public PacketClientInfo(String locale, byte viewDistance, byte chatFlags, byte difficulty, boolean cape) {
|
||||
this.locale = locale;
|
||||
this.viewDistance = viewDistance;
|
||||
|
@ -49,14 +49,14 @@ public class PacketClientInfo extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 204;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,14 +18,14 @@ import ch.spacebase.mcprotocol.util.Util;
|
|||
public class PacketClientStatus extends Packet {
|
||||
|
||||
public byte status;
|
||||
|
||||
|
||||
public PacketClientStatus() {
|
||||
}
|
||||
|
||||
|
||||
public PacketClientStatus(byte status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
|
||||
public byte getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
@ -43,28 +43,28 @@ public class PacketClientStatus extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
if(this.status == 0 && conn.getServer().verifyUsers()) {
|
||||
String encrypted = new BigInteger(Util.encrypt(((StandardProtocol) conn.getProtocol()).getLoginKey(), conn.getServer().getKeys().getPublic(), ((StandardProtocol) conn.getProtocol()).getSecretKey())).toString(16);
|
||||
String response = null;
|
||||
|
||||
|
||||
try {
|
||||
URL url = new URL("http://session.minecraft.net/game/checkserver.jsp?user=" + URLEncoder.encode(conn.getUsername(), "UTF-8") + "&serverId=" + URLEncoder.encode(encrypted, "UTF-8"));
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
response = reader.readLine();
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
response = e.toString();
|
||||
}
|
||||
|
||||
URL url = new URL("http://session.minecraft.net/game/checkserver.jsp?user=" + URLEncoder.encode(conn.getUsername(), "UTF-8") + "&serverId=" + URLEncoder.encode(encrypted, "UTF-8"));
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
response = reader.readLine();
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
response = e.toString();
|
||||
}
|
||||
|
||||
if(!response.equals("YES")) {
|
||||
conn.disconnect("Failed to verify username!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(ServerConnection c : conn.getServer().getConnections()) {
|
||||
if(c.getUsername().equals(conn.getUsername())) {
|
||||
c.disconnect("You logged in from another location!");
|
||||
|
@ -77,5 +77,5 @@ public class PacketClientStatus extends Packet {
|
|||
public int getId() {
|
||||
return 205;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@ import ch.spacebase.mcprotocol.packet.Packet;
|
|||
public class PacketCloseWindow extends Packet {
|
||||
|
||||
public byte id;
|
||||
|
||||
|
||||
public PacketCloseWindow() {
|
||||
}
|
||||
|
||||
|
||||
public PacketCloseWindow(byte id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
@ -32,14 +32,14 @@ public class PacketCloseWindow extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 101;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ public class PacketCollectItem extends Packet {
|
|||
|
||||
public int collected;
|
||||
public int collector;
|
||||
|
||||
|
||||
public PacketCollectItem() {
|
||||
}
|
||||
|
||||
|
||||
public PacketCollectItem(int collected, int collector) {
|
||||
this.collected = collected;
|
||||
this.collector = collector;
|
||||
|
@ -36,14 +36,14 @@ public class PacketCollectItem extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 22;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ public class PacketConfirmTransaction extends Packet {
|
|||
public byte id;
|
||||
public short action;
|
||||
public boolean confirm;
|
||||
|
||||
|
||||
public PacketConfirmTransaction() {
|
||||
}
|
||||
|
||||
|
||||
public PacketConfirmTransaction(byte id, short action, boolean confirm) {
|
||||
this.id = id;
|
||||
this.action = action;
|
||||
|
@ -40,14 +40,14 @@ public class PacketConfirmTransaction extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 106;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ public class PacketCreativeSlot extends Packet {
|
|||
|
||||
public short slot;
|
||||
public ItemStack clicked;
|
||||
|
||||
|
||||
public PacketCreativeSlot() {
|
||||
}
|
||||
|
||||
|
||||
public PacketCreativeSlot(short slot, ItemStack clicked) {
|
||||
this.slot = slot;
|
||||
this.clicked = clicked;
|
||||
|
@ -40,14 +40,14 @@ public class PacketCreativeSlot extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 107;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@ import ch.spacebase.mcprotocol.packet.Packet;
|
|||
public class PacketDestroyEntity extends Packet {
|
||||
|
||||
public int entityIds[];
|
||||
|
||||
|
||||
public PacketDestroyEntity() {
|
||||
}
|
||||
|
||||
|
||||
public PacketDestroyEntity(int... entityIds) {
|
||||
this.entityIds = entityIds;
|
||||
}
|
||||
|
@ -38,14 +38,14 @@ public class PacketDestroyEntity extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 29;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,14 +12,14 @@ import ch.spacebase.mcprotocol.util.IOUtils;
|
|||
public class PacketDisconnect extends Packet {
|
||||
|
||||
public String reason;
|
||||
|
||||
|
||||
public PacketDisconnect() {
|
||||
}
|
||||
|
||||
|
||||
public PacketDisconnect(String reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
|
||||
public String getReason() {
|
||||
return this.reason;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class PacketDisconnect extends Packet {
|
|||
public void handleClient(Client conn) {
|
||||
conn.disconnect("", false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@ public class PacketEffect extends Packet {
|
|||
public int z;
|
||||
public int data;
|
||||
public boolean ignoreVolume;
|
||||
|
||||
|
||||
public PacketEffect() {
|
||||
}
|
||||
|
||||
|
||||
public PacketEffect(int effectId, int x, byte y, int z, int data, boolean ignoreVolume) {
|
||||
this.effectId = effectId;
|
||||
this.x = x;
|
||||
|
@ -52,14 +52,14 @@ public class PacketEffect extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 61;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ public class PacketEnchantItem extends Packet {
|
|||
|
||||
public byte id;
|
||||
public byte enchantment;
|
||||
|
||||
|
||||
public PacketEnchantItem() {
|
||||
}
|
||||
|
||||
|
||||
public PacketEnchantItem(byte id, byte enchantment) {
|
||||
this.id = id;
|
||||
this.enchantment = enchantment;
|
||||
|
@ -36,14 +36,14 @@ public class PacketEnchantItem extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 108;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@ import ch.spacebase.mcprotocol.packet.Packet;
|
|||
public class PacketEntity extends Packet {
|
||||
|
||||
public int entityId;
|
||||
|
||||
|
||||
public PacketEntity() {
|
||||
}
|
||||
|
||||
|
||||
public PacketEntity(int entityId) {
|
||||
this.entityId = entityId;
|
||||
}
|
||||
|
@ -32,14 +32,14 @@ public class PacketEntity extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 30;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ public class PacketEntityAction extends Packet {
|
|||
|
||||
public int entityId;
|
||||
public byte action;
|
||||
|
||||
|
||||
public PacketEntityAction() {
|
||||
}
|
||||
|
||||
|
||||
public PacketEntityAction(int entityId, byte action) {
|
||||
this.entityId = entityId;
|
||||
this.action = action;
|
||||
|
@ -36,14 +36,14 @@ public class PacketEntityAction extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 19;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@ public class PacketEntityEffect extends Packet {
|
|||
public byte effect;
|
||||
public byte amplifier;
|
||||
public short duration;
|
||||
|
||||
|
||||
public PacketEntityEffect() {
|
||||
}
|
||||
|
||||
|
||||
public PacketEntityEffect(int entityId, byte effect, byte amplifier, short duration) {
|
||||
this.entityId = entityId;
|
||||
this.effect = effect;
|
||||
|
@ -44,14 +44,14 @@ public class PacketEntityEffect extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 41;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -14,24 +14,24 @@ public class PacketEntityEquipment extends Packet {
|
|||
public int entityId;
|
||||
public short slot;
|
||||
public ItemStack item;
|
||||
|
||||
|
||||
public PacketEntityEquipment() {
|
||||
}
|
||||
|
||||
|
||||
public PacketEntityEquipment(int entityId, short slot, ItemStack item) {
|
||||
this.entityId = entityId;
|
||||
this.slot = slot;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
|
||||
public int getEntityId() {
|
||||
return this.entityId;
|
||||
}
|
||||
|
||||
|
||||
public short getSlot() {
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
|
||||
public ItemStack getItem() {
|
||||
return this.item;
|
||||
}
|
||||
|
@ -54,14 +54,14 @@ public class PacketEntityEquipment extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ public class PacketEntityHeadYaw extends Packet {
|
|||
|
||||
public int entityId;
|
||||
public byte headYaw;
|
||||
|
||||
|
||||
public PacketEntityHeadYaw() {
|
||||
}
|
||||
|
||||
|
||||
public PacketEntityHeadYaw(int entityId, byte headYaw) {
|
||||
this.entityId = entityId;
|
||||
this.headYaw = headYaw;
|
||||
|
@ -36,14 +36,14 @@ public class PacketEntityHeadYaw extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 35;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ public class PacketEntityLook extends Packet {
|
|||
public int entityId;
|
||||
public byte yaw;
|
||||
public byte pitch;
|
||||
|
||||
|
||||
public PacketEntityLook() {
|
||||
}
|
||||
|
||||
|
||||
public PacketEntityLook(int entityId, byte yaw, byte pitch) {
|
||||
this.entityId = entityId;
|
||||
this.yaw = yaw;
|
||||
|
@ -40,14 +40,14 @@ public class PacketEntityLook extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 32;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@ public class PacketEntityLookRelativeMove extends Packet {
|
|||
public byte dZ;
|
||||
public byte yaw;
|
||||
public byte pitch;
|
||||
|
||||
|
||||
public PacketEntityLookRelativeMove() {
|
||||
}
|
||||
|
||||
|
||||
public PacketEntityLookRelativeMove(int entityId, byte dX, byte dY, byte dZ, byte yaw, byte pitch) {
|
||||
this.entityId = entityId;
|
||||
this.dX = dX;
|
||||
|
@ -52,14 +52,14 @@ public class PacketEntityLookRelativeMove extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 33;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@ public class PacketEntityMetadata extends Packet {
|
|||
|
||||
public int entityId;
|
||||
public WatchableObject metadata[];
|
||||
|
||||
|
||||
public PacketEntityMetadata() {
|
||||
}
|
||||
|
||||
|
||||
public PacketEntityMetadata(int entityId, WatchableObject metadata[]) {
|
||||
this.entityId = entityId;
|
||||
this.metadata = metadata;
|
||||
|
@ -38,14 +38,14 @@ public class PacketEntityMetadata extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 40;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@ public class PacketEntityRelativeMove extends Packet {
|
|||
public byte dX;
|
||||
public byte dY;
|
||||
public byte dZ;
|
||||
|
||||
|
||||
public PacketEntityRelativeMove() {
|
||||
}
|
||||
|
||||
|
||||
public PacketEntityRelativeMove(int entityId, byte dX, byte dY, byte dZ) {
|
||||
this.entityId = entityId;
|
||||
this.dX = dX;
|
||||
|
@ -44,14 +44,14 @@ public class PacketEntityRelativeMove extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 31;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ public class PacketEntityStatus extends Packet {
|
|||
|
||||
public int entityId;
|
||||
public byte status;
|
||||
|
||||
|
||||
public PacketEntityStatus() {
|
||||
}
|
||||
|
||||
|
||||
public PacketEntityStatus(int entityId, byte status) {
|
||||
this.entityId = entityId;
|
||||
this.status = status;
|
||||
|
@ -36,14 +36,14 @@ public class PacketEntityStatus extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 38;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@ public class PacketEntityTeleport extends Packet {
|
|||
public int z;
|
||||
public byte yaw;
|
||||
public byte pitch;
|
||||
|
||||
|
||||
public PacketEntityTeleport() {
|
||||
}
|
||||
|
||||
|
||||
public PacketEntityTeleport(int entityId, int x, int y, int z, byte yaw, byte pitch) {
|
||||
this.entityId = entityId;
|
||||
this.x = x;
|
||||
|
@ -52,14 +52,14 @@ public class PacketEntityTeleport extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 34;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@ public class PacketEntityVelocity extends Packet {
|
|||
public short velX;
|
||||
public short velY;
|
||||
public short velZ;
|
||||
|
||||
|
||||
public PacketEntityVelocity() {
|
||||
}
|
||||
|
||||
|
||||
public PacketEntityVelocity(int entityId, short velX, short velY, short velZ) {
|
||||
this.entityId = entityId;
|
||||
this.velX = velX;
|
||||
|
@ -44,14 +44,14 @@ public class PacketEntityVelocity extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 28;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,10 +18,10 @@ public class PacketExplosion extends Packet {
|
|||
public float unk1;
|
||||
public float unk2;
|
||||
public float unk3;
|
||||
|
||||
|
||||
public PacketExplosion() {
|
||||
}
|
||||
|
||||
|
||||
public PacketExplosion(double x, double y, double z, float radius, byte blocks[], float unk1, float unk2, float unk3) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
@ -62,14 +62,14 @@ public class PacketExplosion extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ public class PacketGameState extends Packet {
|
|||
|
||||
public byte reason;
|
||||
public byte gamemode;
|
||||
|
||||
|
||||
public PacketGameState() {
|
||||
}
|
||||
|
||||
|
||||
public PacketGameState(byte reason, byte gamemode) {
|
||||
this.reason = reason;
|
||||
this.gamemode = gamemode;
|
||||
|
@ -36,14 +36,14 @@ public class PacketGameState extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 70;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -19,10 +19,10 @@ public class PacketHandshake extends Packet {
|
|||
public String user;
|
||||
public String host;
|
||||
public int port;
|
||||
|
||||
|
||||
public PacketHandshake() {
|
||||
}
|
||||
|
||||
|
||||
public PacketHandshake(String user, String host, int port) {
|
||||
this.protocol = Constants.STANDARD_PROTOCOL_VERSION;
|
||||
this.user = user;
|
||||
|
@ -49,7 +49,7 @@ public class PacketHandshake extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
if(!Util.stripColor(this.user).equals(this.user)) {
|
||||
|
@ -63,14 +63,14 @@ public class PacketHandshake extends Packet {
|
|||
} else {
|
||||
PublicKey key = conn.getServer().getKeys().getPublic();
|
||||
((StandardProtocol) conn.getProtocol()).setLoginKey(conn.getServer().verifyUsers() ? Long.toString(Util.random().nextLong(), 16) : "-");
|
||||
byte token[] = new byte[4];
|
||||
Util.random().nextBytes(token);
|
||||
((StandardProtocol) conn.getProtocol()).setToken(token);
|
||||
|
||||
conn.send(new PacketKeyRequest(((StandardProtocol) conn.getProtocol()).getLoginKey(), key.getEncoded(), token));
|
||||
byte token[] = new byte[4];
|
||||
Util.random().nextBytes(token);
|
||||
((StandardProtocol) conn.getProtocol()).setToken(token);
|
||||
|
||||
conn.send(new PacketKeyRequest(((StandardProtocol) conn.getProtocol()).getLoginKey(), key.getEncoded(), token));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 2;
|
||||
|
|
|
@ -13,10 +13,10 @@ public class PacketHealthUpdate extends Packet {
|
|||
public short health;
|
||||
public short food;
|
||||
public float saturation;
|
||||
|
||||
|
||||
public PacketHealthUpdate() {
|
||||
}
|
||||
|
||||
|
||||
public PacketHealthUpdate(short health, short food, float saturation) {
|
||||
this.health = health;
|
||||
this.food = food;
|
||||
|
@ -40,14 +40,14 @@ public class PacketHealthUpdate extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 8;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@ import ch.spacebase.mcprotocol.packet.Packet;
|
|||
public class PacketHeldItemChange extends Packet {
|
||||
|
||||
public short slot;
|
||||
|
||||
|
||||
public PacketHeldItemChange() {
|
||||
}
|
||||
|
||||
|
||||
public PacketHeldItemChange(short slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
|
@ -32,14 +32,14 @@ public class PacketHeldItemChange extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ public class PacketIncrementStatistic extends Packet {
|
|||
|
||||
public int statistic;
|
||||
public byte amount;
|
||||
|
||||
|
||||
public PacketIncrementStatistic() {
|
||||
}
|
||||
|
||||
|
||||
public PacketIncrementStatistic(int statistic, byte amount) {
|
||||
this.statistic = statistic;
|
||||
this.amount = amount;
|
||||
|
@ -36,14 +36,14 @@ public class PacketIncrementStatistic extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 200;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ public class PacketItemData extends Packet {
|
|||
public short item;
|
||||
public short damage;
|
||||
public byte data[];
|
||||
|
||||
|
||||
public PacketItemData() {
|
||||
}
|
||||
|
||||
|
||||
public PacketItemData(short item, short damage, byte data[]) {
|
||||
this.item = item;
|
||||
this.damage = damage;
|
||||
|
@ -42,14 +42,14 @@ public class PacketItemData extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 131;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@ import ch.spacebase.mcprotocol.packet.Packet;
|
|||
public class PacketKeepAlive extends Packet {
|
||||
|
||||
public int id;
|
||||
|
||||
|
||||
public PacketKeepAlive() {
|
||||
}
|
||||
|
||||
|
||||
public PacketKeepAlive(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
@ -33,14 +33,14 @@ public class PacketKeepAlive extends Packet {
|
|||
public void handleClient(Client conn) {
|
||||
conn.send(new PacketKeepAlive(this.id));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -38,23 +38,23 @@ public class PacketKeyRequest extends Packet {
|
|||
public String serverId;
|
||||
public byte[] pubKey;
|
||||
public byte[] verifyToken;
|
||||
|
||||
|
||||
public PacketKeyRequest() {
|
||||
}
|
||||
|
||||
|
||||
public PacketKeyRequest(String serverId, byte[] pubKey, byte[] verifyToken) {
|
||||
this.pubKey = pubKey;
|
||||
this.verifyToken = verifyToken;
|
||||
}
|
||||
|
||||
|
||||
public String getServerId() {
|
||||
return this.serverId;
|
||||
}
|
||||
|
||||
|
||||
public byte[] getPublicKey() {
|
||||
return this.pubKey;
|
||||
}
|
||||
|
||||
|
||||
public byte[] getVerifyToken() {
|
||||
return this.verifyToken;
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public class PacketKeyRequest extends Packet {
|
|||
byte pubKey[] = new byte[in.readShort()];
|
||||
in.readFully(pubKey);
|
||||
this.pubKey = pubKey;
|
||||
|
||||
|
||||
byte verifyToken[] = new byte[in.readShort()];
|
||||
in.readFully(verifyToken);
|
||||
this.verifyToken = verifyToken;
|
||||
|
@ -93,20 +93,20 @@ public class PacketKeyRequest extends Packet {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
conn.send(new PacketKeyResponse(encryptBytes(key, secret.getEncoded()), encryptBytes(key, this.verifyToken)));
|
||||
((StandardProtocol) conn.getProtocol()).setSecretKey(secret);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 253;
|
||||
}
|
||||
|
||||
|
||||
private static byte[] encryptBytes(PublicKey key, byte[] bytes) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance(key.getAlgorithm());
|
||||
|
@ -123,16 +123,16 @@ public class PacketKeyRequest extends Packet {
|
|||
} catch (BadPaddingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static SecretKey generateKey() {
|
||||
CipherKeyGenerator gen = new CipherKeyGenerator();
|
||||
gen.init(new KeyGenerationParameters(new SecureRandom(), 128));
|
||||
return new SecretKeySpec(gen.generateKey(), "AES");
|
||||
CipherKeyGenerator gen = new CipherKeyGenerator();
|
||||
gen.init(new KeyGenerationParameters(new SecureRandom(), 128));
|
||||
return new SecretKeySpec(gen.generateKey(), "AES");
|
||||
}
|
||||
|
||||
|
||||
private static PublicKey toKey(byte[] key) {
|
||||
try {
|
||||
X509EncodedKeySpec spec = new X509EncodedKeySpec(key);
|
||||
|
@ -148,17 +148,17 @@ public class PacketKeyRequest extends Packet {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static String joinServer(String user, String session, String key) {
|
||||
try {
|
||||
URL url = new URL("http://session.minecraft.net/game/joinserver.jsp?user=" + URLEncoder.encode(user, "UTF-8") + "&sessionId=" + URLEncoder.encode(session, "UTF-8") + "&serverId=" + URLEncoder.encode(key, "UTF-8"));
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
String response = reader.readLine();
|
||||
reader.close();
|
||||
return response;
|
||||
} catch (IOException e) {
|
||||
return e.toString();
|
||||
}
|
||||
try {
|
||||
URL url = new URL("http://session.minecraft.net/game/joinserver.jsp?user=" + URLEncoder.encode(user, "UTF-8") + "&sessionId=" + URLEncoder.encode(session, "UTF-8") + "&serverId=" + URLEncoder.encode(key, "UTF-8"));
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
String response = reader.readLine();
|
||||
reader.close();
|
||||
return response;
|
||||
} catch (IOException e) {
|
||||
return e.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -23,19 +23,19 @@ public class PacketKeyResponse extends Packet {
|
|||
|
||||
public byte[] sharedKey;
|
||||
public byte[] verifyToken;
|
||||
|
||||
|
||||
public PacketKeyResponse() {
|
||||
}
|
||||
|
||||
|
||||
public PacketKeyResponse(byte[] sharedKey, byte[] verifyToken) {
|
||||
this.sharedKey = sharedKey;
|
||||
this.verifyToken = verifyToken;
|
||||
}
|
||||
|
||||
|
||||
public byte[] getSharedKey() {
|
||||
return this.sharedKey;
|
||||
}
|
||||
|
||||
|
||||
public byte[] getVerifyToken() {
|
||||
return this.verifyToken;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public class PacketKeyResponse extends Packet {
|
|||
byte sharedKey[] = new byte[in.readShort()];
|
||||
in.readFully(sharedKey);
|
||||
this.sharedKey = sharedKey;
|
||||
|
||||
|
||||
byte verifyToken[] = new byte[in.readShort()];
|
||||
in.readFully(verifyToken);
|
||||
this.verifyToken = verifyToken;
|
||||
|
@ -62,27 +62,27 @@ public class PacketKeyResponse extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
((StandardProtocol) conn.getProtocol()).setAES(conn);
|
||||
conn.send(new PacketClientStatus((byte) 0));
|
||||
conn.send(new PacketClientStatus((byte) 0));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
PrivateKey priv = conn.getServer().getKeys().getPrivate();
|
||||
PrivateKey priv = conn.getServer().getKeys().getPrivate();
|
||||
|
||||
((StandardProtocol) conn.getProtocol()).setSecretKey(new SecretKeySpec(encryptBytes(priv, this.sharedKey), "AES"));
|
||||
if (!Arrays.equals(((StandardProtocol) conn.getProtocol()).getToken(), encryptBytes(priv, this.verifyToken))) {
|
||||
conn.disconnect("Invalid client reply");
|
||||
return;
|
||||
}
|
||||
|
||||
conn.send(new PacketKeyResponse(new byte[0], new byte[0]));
|
||||
((StandardProtocol) conn.getProtocol()).setSecretKey(new SecretKeySpec(encryptBytes(priv, this.sharedKey), "AES"));
|
||||
if(!Arrays.equals(((StandardProtocol) conn.getProtocol()).getToken(), encryptBytes(priv, this.verifyToken))) {
|
||||
conn.disconnect("Invalid client reply");
|
||||
return;
|
||||
}
|
||||
|
||||
conn.send(new PacketKeyResponse(new byte[0], new byte[0]));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 252;
|
||||
}
|
||||
|
||||
|
||||
private static byte[] encryptBytes(PrivateKey key, byte[] bytes) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance(key.getAlgorithm());
|
||||
|
@ -99,8 +99,8 @@ public class PacketKeyResponse extends Packet {
|
|||
} catch (BadPaddingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@ public class PacketLightning extends Packet {
|
|||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
|
||||
|
||||
public PacketLightning() {
|
||||
}
|
||||
|
||||
|
||||
public PacketLightning(int entityId, boolean unk, int x, int y, int z) {
|
||||
this.entityId = entityId;
|
||||
this.unk = unk;
|
||||
|
@ -48,14 +48,14 @@ public class PacketLightning extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 71;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,10 +18,10 @@ public class PacketLogin extends Packet {
|
|||
public byte difficulty;
|
||||
public byte unused;
|
||||
public byte maxPlayers;
|
||||
|
||||
|
||||
public PacketLogin() {
|
||||
}
|
||||
|
||||
|
||||
public PacketLogin(int entityId, String levelType, byte gameMode, byte dimension, byte difficulty, byte unused, byte maxPlayers) {
|
||||
this.entityId = entityId;
|
||||
this.levelType = levelType;
|
||||
|
@ -57,14 +57,14 @@ public class PacketLogin extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -20,29 +20,29 @@ public class PacketMapChunk extends Packet {
|
|||
public int endY;
|
||||
public byte data[];
|
||||
public int length;
|
||||
|
||||
|
||||
public PacketMapChunk() {
|
||||
}
|
||||
|
||||
|
||||
public PacketMapChunk(int x, int z, boolean groundUp, int startY, int endY, byte data[]) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.groundUp = groundUp;
|
||||
this.startY = startY;
|
||||
this.startY = startY;
|
||||
this.endY = endY;
|
||||
|
||||
Deflater deflater = new Deflater(-1);
|
||||
|
||||
try {
|
||||
deflater.setInput(data, 0, data.length);
|
||||
deflater.finish();
|
||||
this.data = new byte[data.length];
|
||||
this.length = deflater.deflate(this.data);
|
||||
} finally {
|
||||
deflater.end();
|
||||
}
|
||||
Deflater deflater = new Deflater(-1);
|
||||
|
||||
try {
|
||||
deflater.setInput(data, 0, data.length);
|
||||
deflater.finish();
|
||||
this.data = new byte[data.length];
|
||||
this.length = deflater.deflate(this.data);
|
||||
} finally {
|
||||
deflater.end();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream in) throws IOException {
|
||||
this.x = in.readInt();
|
||||
|
@ -51,17 +51,17 @@ public class PacketMapChunk extends Packet {
|
|||
this.startY = in.readShort();
|
||||
this.endY = in.readShort();
|
||||
this.length = in.readInt();
|
||||
|
||||
|
||||
byte[] compressed = new byte[this.length];
|
||||
in.readFully(compressed, 0, this.length);
|
||||
|
||||
|
||||
int off = 0;
|
||||
for (int count = 0; count < 16; count++) {
|
||||
for(int count = 0; count < 16; count++) {
|
||||
off += this.startY >> count & 1;
|
||||
}
|
||||
|
||||
int size = 12288 * off;
|
||||
if (this.groundUp) {
|
||||
if(this.groundUp) {
|
||||
size += 256;
|
||||
}
|
||||
|
||||
|
@ -92,14 +92,14 @@ public class PacketMapChunk extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 51;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -14,17 +14,17 @@ public class PacketMultiBlockChange extends Packet {
|
|||
public int z;
|
||||
public int records;
|
||||
public byte data[];
|
||||
|
||||
|
||||
public PacketMultiBlockChange() {
|
||||
}
|
||||
|
||||
|
||||
public PacketMultiBlockChange(int x, int z, int records, byte data[]) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.records = records;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream in) throws IOException {
|
||||
this.x = in.readInt();
|
||||
|
@ -53,14 +53,14 @@ public class PacketMultiBlockChange extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 52;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -17,10 +17,10 @@ public class PacketNamedSound extends Packet {
|
|||
public int z;
|
||||
public float volume;
|
||||
public int pitch;
|
||||
|
||||
|
||||
public PacketNamedSound() {
|
||||
}
|
||||
|
||||
|
||||
public PacketNamedSound(String sound, int x, byte y, int z, float volume, int pitch) {
|
||||
this.sound = sound;
|
||||
this.x = x;
|
||||
|
@ -53,14 +53,14 @@ public class PacketNamedSound extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 62;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@ public class PacketOpenWindow extends Packet {
|
|||
public byte type;
|
||||
public String name;
|
||||
public byte slots;
|
||||
|
||||
|
||||
public PacketOpenWindow() {
|
||||
}
|
||||
|
||||
|
||||
public PacketOpenWindow(byte id, byte type, String name, byte slots) {
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
|
@ -45,14 +45,14 @@ public class PacketOpenWindow extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@ import ch.spacebase.mcprotocol.packet.Packet;
|
|||
public class PacketPlayer extends Packet {
|
||||
|
||||
public boolean grounded;
|
||||
|
||||
|
||||
public PacketPlayer() {
|
||||
}
|
||||
|
||||
|
||||
public PacketPlayer(boolean grounded) {
|
||||
this.grounded = grounded;
|
||||
}
|
||||
|
@ -32,14 +32,14 @@ public class PacketPlayer extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ public class PacketPlayerAbilities extends Packet {
|
|||
public byte flags;
|
||||
public byte flySpeed;
|
||||
public byte walkSpeed;
|
||||
|
||||
|
||||
public PacketPlayerAbilities() {
|
||||
}
|
||||
|
||||
|
||||
public PacketPlayerAbilities(byte flags, byte flySpeed, byte walkSpeed) {
|
||||
this.flags = flags;
|
||||
this.flySpeed = flySpeed;
|
||||
|
@ -40,14 +40,14 @@ public class PacketPlayerAbilities extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 202;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import ch.spacebase.mcprotocol.packet.Packet;
|
|||
import ch.spacebase.mcprotocol.standard.data.ItemStack;
|
||||
|
||||
public class PacketPlayerBlockPlace extends Packet {
|
||||
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
|
@ -22,10 +22,10 @@ public class PacketPlayerBlockPlace extends Packet {
|
|||
public byte cursorX;
|
||||
public byte cursorY;
|
||||
public byte cursorZ;
|
||||
|
||||
|
||||
public PacketPlayerBlockPlace() {
|
||||
}
|
||||
|
||||
|
||||
public PacketPlayerBlockPlace(int x, int y, int z, byte direction, ItemStack item, byte cursorX, byte cursorY, byte cursorZ) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
@ -65,14 +65,14 @@ public class PacketPlayerBlockPlace extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 15;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@ public class PacketPlayerDigging extends Packet {
|
|||
public byte y;
|
||||
public int z;
|
||||
public byte face;
|
||||
|
||||
|
||||
public PacketPlayerDigging() {
|
||||
}
|
||||
|
||||
|
||||
public PacketPlayerDigging(byte status, int x, byte y, int z, byte face) {
|
||||
this.status = status;
|
||||
this.x = x;
|
||||
|
@ -48,14 +48,14 @@ public class PacketPlayerDigging extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 14;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@ public class PacketPlayerListItem extends Packet {
|
|||
public String name;
|
||||
public boolean online;
|
||||
public short ping;
|
||||
|
||||
|
||||
public PacketPlayerListItem() {
|
||||
}
|
||||
|
||||
|
||||
public PacketPlayerListItem(String name, boolean online, short ping) {
|
||||
this.name = name;
|
||||
this.online = online;
|
||||
|
@ -41,14 +41,14 @@ public class PacketPlayerListItem extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 201;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ public class PacketPlayerLook extends Packet {
|
|||
public float yaw;
|
||||
public float pitch;
|
||||
public boolean grounded;
|
||||
|
||||
|
||||
public PacketPlayerLook() {
|
||||
}
|
||||
|
||||
|
||||
public PacketPlayerLook(float yaw, float pitch, boolean grounded) {
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
|
@ -40,14 +40,14 @@ public class PacketPlayerLook extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 12;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@ public class PacketPlayerPosition extends Packet {
|
|||
public double stance;
|
||||
public double z;
|
||||
public boolean grounded;
|
||||
|
||||
|
||||
public PacketPlayerPosition() {
|
||||
}
|
||||
|
||||
|
||||
public PacketPlayerPosition(double x, double y, double stance, double z, boolean grounded) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
@ -48,14 +48,14 @@ public class PacketPlayerPosition extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 11;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -17,10 +17,10 @@ public class PacketPlayerPositionLook extends Packet {
|
|||
public float yaw;
|
||||
public float pitch;
|
||||
public boolean grounded;
|
||||
|
||||
|
||||
public PacketPlayerPositionLook() {
|
||||
}
|
||||
|
||||
|
||||
public PacketPlayerPositionLook(double x, double y, double stance, double z, float yaw, float pitch, boolean grounded) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
@ -56,14 +56,14 @@ public class PacketPlayerPositionLook extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 13;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ public class PacketPluginMessage extends Packet {
|
|||
|
||||
public String channel;
|
||||
public byte data[];
|
||||
|
||||
|
||||
public PacketPluginMessage() {
|
||||
}
|
||||
|
||||
|
||||
public PacketPluginMessage(String channel, byte data[]) {
|
||||
this.channel = channel;
|
||||
this.data = data;
|
||||
|
@ -39,14 +39,14 @@ public class PacketPluginMessage extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 250;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ public class PacketRemoveEntityEffect extends Packet {
|
|||
|
||||
public int entityId;
|
||||
public byte effect;
|
||||
|
||||
|
||||
public PacketRemoveEntityEffect() {
|
||||
}
|
||||
|
||||
|
||||
public PacketRemoveEntityEffect(int entityId, byte effect) {
|
||||
this.entityId = entityId;
|
||||
this.effect = effect;
|
||||
|
@ -36,14 +36,14 @@ public class PacketRemoveEntityEffect extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@ public class PacketRespawn extends Packet {
|
|||
public byte gameMode;
|
||||
public byte worldHeight;
|
||||
public String levelType;
|
||||
|
||||
|
||||
public PacketRespawn() {
|
||||
}
|
||||
|
||||
|
||||
public PacketRespawn(byte dimension, byte difficulty, byte gameMode, byte worldHeight, String levelType) {
|
||||
this.dimension = dimension;
|
||||
this.difficulty = difficulty;
|
||||
|
@ -49,14 +49,14 @@ public class PacketRespawn extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ import ch.spacebase.mcprotocol.net.ServerConnection;
|
|||
import ch.spacebase.mcprotocol.packet.Packet;
|
||||
|
||||
public class PacketServerPing extends Packet {
|
||||
|
||||
|
||||
private static final byte MAGIC = 1;
|
||||
|
||||
|
||||
public PacketServerPing() {
|
||||
}
|
||||
|
||||
|
@ -28,14 +28,14 @@ public class PacketServerPing extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 254;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ public class PacketSetExperience extends Packet {
|
|||
public float experienceBar;
|
||||
public short level;
|
||||
public short experience;
|
||||
|
||||
|
||||
public PacketSetExperience() {
|
||||
}
|
||||
|
||||
|
||||
public PacketSetExperience(float experienceBar, short level, short experience) {
|
||||
this.experienceBar = experienceBar;
|
||||
this.level = level;
|
||||
|
@ -40,14 +40,14 @@ public class PacketSetExperience extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 43;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@ public class PacketSetSlot extends Packet {
|
|||
public byte id;
|
||||
public short slot;
|
||||
public ItemStack item;
|
||||
|
||||
|
||||
public PacketSetSlot() {
|
||||
}
|
||||
|
||||
|
||||
public PacketSetSlot(byte id, short slot, ItemStack item) {
|
||||
this.id = id;
|
||||
this.slot = slot;
|
||||
|
@ -44,14 +44,14 @@ public class PacketSetSlot extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 103;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -19,10 +19,10 @@ public class PacketSpawnDroppedItem extends Packet {
|
|||
public byte yaw;
|
||||
public byte pitch;
|
||||
public byte roll;
|
||||
|
||||
|
||||
public PacketSpawnDroppedItem() {
|
||||
}
|
||||
|
||||
|
||||
public PacketSpawnDroppedItem(int entityId, ItemStack item, int x, int y, int z, byte yaw, byte pitch, byte roll) {
|
||||
this.entityId = entityId;
|
||||
this.item = item;
|
||||
|
@ -62,14 +62,14 @@ public class PacketSpawnDroppedItem extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 21;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@ public class PacketSpawnExpOrb extends Packet {
|
|||
public int y;
|
||||
public int z;
|
||||
public short count;
|
||||
|
||||
|
||||
public PacketSpawnExpOrb() {
|
||||
}
|
||||
|
||||
|
||||
public PacketSpawnExpOrb(int entityId, int x, int y, int z, short count) {
|
||||
this.entityId = entityId;
|
||||
this.x = x;
|
||||
|
@ -48,14 +48,14 @@ public class PacketSpawnExpOrb extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 26;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@ public class PacketSpawnMob extends Packet {
|
|||
public short velY;
|
||||
public short velZ;
|
||||
public WatchableObject metadata[];
|
||||
|
||||
|
||||
public PacketSpawnMob() {
|
||||
}
|
||||
|
||||
|
||||
public PacketSpawnMob(int entityId, byte type, int x, int y, int z, byte yaw, byte pitch, byte headYaw, short velX, short velY, short velZ, WatchableObject metadata[]) {
|
||||
this.entityId = entityId;
|
||||
this.type = type;
|
||||
|
@ -78,14 +78,14 @@ public class PacketSpawnMob extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 24;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -21,10 +21,10 @@ public class PacketSpawnNamedEntity extends Packet {
|
|||
public byte pitch;
|
||||
public short item;
|
||||
public WatchableObject metadata[];
|
||||
|
||||
|
||||
public PacketSpawnNamedEntity() {
|
||||
}
|
||||
|
||||
|
||||
public PacketSpawnNamedEntity(int entityId, String name, int x, int y, int z, byte yaw, byte pitch, short item, WatchableObject metadata[]) {
|
||||
this.entityId = entityId;
|
||||
this.name = name;
|
||||
|
@ -66,14 +66,14 @@ public class PacketSpawnNamedEntity extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -17,10 +17,10 @@ public class PacketSpawnPainting extends Packet {
|
|||
public int y;
|
||||
public int z;
|
||||
public int direction;
|
||||
|
||||
|
||||
public PacketSpawnPainting() {
|
||||
}
|
||||
|
||||
|
||||
public PacketSpawnPainting(int entityId, String title, int x, int y, int z, int direction) {
|
||||
this.entityId = entityId;
|
||||
this.title = title;
|
||||
|
@ -53,14 +53,14 @@ public class PacketSpawnPainting extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 25;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ public class PacketSpawnPosition extends Packet {
|
|||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
|
||||
|
||||
public PacketSpawnPosition() {
|
||||
}
|
||||
|
||||
|
||||
public PacketSpawnPosition(int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
@ -40,14 +40,14 @@ public class PacketSpawnPosition extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -19,10 +19,10 @@ public class PacketSpawnVehicle extends Packet {
|
|||
public short speedX;
|
||||
public short speedY;
|
||||
public short speedZ;
|
||||
|
||||
|
||||
public PacketSpawnVehicle() {
|
||||
}
|
||||
|
||||
|
||||
public PacketSpawnVehicle(int entityId, byte type, int x, int y, int z, int data, short speedX, short speedY, short speedZ) {
|
||||
this.entityId = entityId;
|
||||
this.type = type;
|
||||
|
@ -68,14 +68,14 @@ public class PacketSpawnVehicle extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 23;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ import ch.spacebase.mcprotocol.util.IOUtils;
|
|||
public class PacketTabComplete extends Packet {
|
||||
|
||||
public String text;
|
||||
|
||||
|
||||
public PacketTabComplete() {
|
||||
}
|
||||
|
||||
|
||||
public PacketTabComplete(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
@ -33,14 +33,14 @@ public class PacketTabComplete extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 203;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ public class PacketTimeUpdate extends Packet {
|
|||
|
||||
public long age;
|
||||
public long time;
|
||||
|
||||
|
||||
public PacketTimeUpdate() {
|
||||
}
|
||||
|
||||
|
||||
public PacketTimeUpdate(long age, long time) {
|
||||
this.age = age;
|
||||
this.time = time;
|
||||
|
@ -36,14 +36,14 @@ public class PacketTimeUpdate extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@ public class PacketUpdateSign extends Packet {
|
|||
public short y;
|
||||
public int z;
|
||||
public String lines[];
|
||||
|
||||
|
||||
public PacketUpdateSign() {
|
||||
}
|
||||
|
||||
|
||||
public PacketUpdateSign(int x, short y, int z, String lines[]) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
@ -53,14 +53,14 @@ public class PacketUpdateSign extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 130;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@ public class PacketUpdateTileEntity extends Packet {
|
|||
public int z;
|
||||
public byte action;
|
||||
public byte nbt[];
|
||||
|
||||
|
||||
public PacketUpdateTileEntity() {
|
||||
}
|
||||
|
||||
|
||||
public PacketUpdateTileEntity(int x, short y, int z, byte action, byte nbt[]) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
@ -52,14 +52,14 @@ public class PacketUpdateTileEntity extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 132;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@ public class PacketUseBed extends Packet {
|
|||
public int x;
|
||||
public byte y;
|
||||
public int z;
|
||||
|
||||
|
||||
public PacketUseBed() {
|
||||
}
|
||||
|
||||
|
||||
public PacketUseBed(int entityId, byte unknown, int x, byte y, int z) {
|
||||
this.entityId = entityId;
|
||||
this.unknown = unknown;
|
||||
|
@ -48,14 +48,14 @@ public class PacketUseBed extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 17;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ public class PacketUseEntity extends Packet {
|
|||
public int user;
|
||||
public int target;
|
||||
public boolean leftclick;
|
||||
|
||||
|
||||
public PacketUseEntity() {
|
||||
}
|
||||
|
||||
|
||||
public PacketUseEntity(int user, int target, boolean leftclick) {
|
||||
this.user = user;
|
||||
this.target = target;
|
||||
|
@ -40,14 +40,14 @@ public class PacketUseEntity extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 7;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -17,10 +17,10 @@ public class PacketWindowClick extends Packet {
|
|||
public short action;
|
||||
public boolean shift;
|
||||
public ItemStack clicked;
|
||||
|
||||
|
||||
public PacketWindowClick() {
|
||||
}
|
||||
|
||||
|
||||
public PacketWindowClick(byte id, short slot, byte mousebutton, short action, boolean shift, ItemStack clicked) {
|
||||
this.id = id;
|
||||
this.slot = slot;
|
||||
|
@ -56,14 +56,14 @@ public class PacketWindowClick extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 102;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ public class PacketWindowItems extends Packet {
|
|||
|
||||
public byte id;
|
||||
public ItemStack items[];
|
||||
|
||||
|
||||
public PacketWindowItems() {
|
||||
}
|
||||
|
||||
|
||||
public PacketWindowItems(byte id, ItemStack items[]) {
|
||||
this.id = id;
|
||||
this.items = items;
|
||||
|
@ -44,14 +44,14 @@ public class PacketWindowItems extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 104;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ public class PacketWindowProperty extends Packet {
|
|||
public byte id;
|
||||
public short prop;
|
||||
public short value;
|
||||
|
||||
|
||||
public PacketWindowProperty() {
|
||||
}
|
||||
|
||||
|
||||
public PacketWindowProperty(byte id, short prop, short value) {
|
||||
this.id = id;
|
||||
this.prop = prop;
|
||||
|
@ -40,14 +40,14 @@ public class PacketWindowProperty extends Packet {
|
|||
@Override
|
||||
public void handleClient(Client conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleServer(ServerConnection conn) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 105;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,5 +6,5 @@ public class Constants {
|
|||
public static final byte STANDARD_PROTOCOL_VERSION = 49;
|
||||
public static final byte CLASSIC_PROTOCOL_VERSION = 7;
|
||||
public static final byte[] POCKET_MAGIC = new byte[] { 0, -1, -1, 0, -2, -2, -2, -2, -3, -3, -3, -3, 18, 52, 86, 120 };
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,175 +16,184 @@ import ch.spacebase.mcprotocol.standard.data.WatchableObject;
|
|||
*/
|
||||
public final class IOUtils {
|
||||
|
||||
/**
|
||||
* The UTF-8 character set.
|
||||
*/
|
||||
private static final Charset CHARSET_UTF8 = Charset.forName("UTF-8");
|
||||
/**
|
||||
* The UTF-8 character set.
|
||||
*/
|
||||
private static final Charset CHARSET_UTF8 = Charset.forName("UTF-8");
|
||||
|
||||
/**
|
||||
* Writes a string to the buffer.
|
||||
* @param buf The buffer.
|
||||
* @param str The string.
|
||||
* @throws IllegalArgumentException if the string is too long
|
||||
* <em>after</em> it is encoded.
|
||||
*/
|
||||
public static void writeString(DataOutputStream out, String str) throws IOException {
|
||||
int len = str.length();
|
||||
if (len >= 65536) {
|
||||
throw new IllegalArgumentException("String too long.");
|
||||
}
|
||||
/**
|
||||
* Writes a string to the buffer.
|
||||
*
|
||||
* @param buf
|
||||
* The buffer.
|
||||
* @param str
|
||||
* The string.
|
||||
* @throws IllegalArgumentException
|
||||
* if the string is too long <em>after</em> it is encoded.
|
||||
*/
|
||||
public static void writeString(DataOutputStream out, String str) throws IOException {
|
||||
int len = str.length();
|
||||
if(len >= 65536) {
|
||||
throw new IllegalArgumentException("String too long.");
|
||||
}
|
||||
|
||||
out.writeShort(len);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
out.writeChar(str.charAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a UTF-8 string to the buffer.
|
||||
* @param buf The buffer.
|
||||
* @param str The string.
|
||||
* @throws IllegalArgumentException if the string is too long
|
||||
* <em>after</em> it is encoded.
|
||||
*/
|
||||
public static void writeUtf8String(DataOutputStream out, String str) throws IOException {
|
||||
byte[] bytes = str.getBytes(CHARSET_UTF8);
|
||||
if (bytes.length >= 65536) {
|
||||
throw new IllegalArgumentException("Encoded UTF-8 string too long.");
|
||||
}
|
||||
|
||||
out.writeShort(bytes.length);
|
||||
out.write(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a string from the buffer.
|
||||
* @param buf The buffer.
|
||||
* @return The string.
|
||||
*/
|
||||
public static String readString(DataInputStream in) throws IOException {
|
||||
int len = in.readUnsignedShort();
|
||||
|
||||
char[] characters = new char[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
characters[i] = in.readChar();
|
||||
}
|
||||
|
||||
return new String(characters);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads a UTF-8 encoded string from the buffer.
|
||||
* @param buf The buffer.
|
||||
* @return The string.
|
||||
*/
|
||||
public static String readUtf8String(DataInputStream in) throws IOException {
|
||||
int len = in.readUnsignedShort();
|
||||
|
||||
byte[] bytes = new byte[len];
|
||||
in.readFully(bytes);
|
||||
|
||||
return new String(bytes, CHARSET_UTF8);
|
||||
}
|
||||
|
||||
public static WatchableObject[] readMetadata(DataInputStream in) throws IOException {
|
||||
List<WatchableObject> objects = new ArrayList<WatchableObject>();
|
||||
|
||||
byte b;
|
||||
while((b = in.readByte()) != 127) {
|
||||
int type = (b & 0xe0) >> 5;
|
||||
int id = b & 0x1f;
|
||||
WatchableObject obj = null;
|
||||
|
||||
switch (type) {
|
||||
case 0:
|
||||
obj = new WatchableObject(type, id, Byte.valueOf(in.readByte()));
|
||||
break;
|
||||
case 1:
|
||||
obj = new WatchableObject(type, id, Short.valueOf(in.readShort()));
|
||||
break;
|
||||
case 2:
|
||||
obj = new WatchableObject(type, id, Integer.valueOf(in.readInt()));
|
||||
break;
|
||||
case 3:
|
||||
obj = new WatchableObject(type, id, Float.valueOf(in.readFloat()));
|
||||
break;
|
||||
case 4:
|
||||
obj = new WatchableObject(type, id, readString(in));
|
||||
break;
|
||||
case 5:
|
||||
short item = in.readShort();
|
||||
byte stackSize = 0;
|
||||
short damage = 0;
|
||||
if(item >= 0) {
|
||||
stackSize = in.readByte();
|
||||
damage = in.readShort();
|
||||
}
|
||||
|
||||
obj = new WatchableObject(type, id, new ItemStack(item, stackSize, damage));
|
||||
break;
|
||||
case 6:
|
||||
int x = in.readInt();
|
||||
int y = in.readInt();
|
||||
int z = in.readInt();
|
||||
obj = new WatchableObject(type, id, new Coordinates(x, y, z));
|
||||
break;
|
||||
}
|
||||
|
||||
objects.add(obj);
|
||||
}
|
||||
|
||||
return objects.toArray(new WatchableObject[objects.size()]);
|
||||
out.writeShort(len);
|
||||
for(int i = 0; i < len; ++i) {
|
||||
out.writeChar(str.charAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes a UTF-8 string to the buffer.
|
||||
*
|
||||
* @param buf
|
||||
* The buffer.
|
||||
* @param str
|
||||
* The string.
|
||||
* @throws IllegalArgumentException
|
||||
* if the string is too long <em>after</em> it is encoded.
|
||||
*/
|
||||
public static void writeUtf8String(DataOutputStream out, String str) throws IOException {
|
||||
byte[] bytes = str.getBytes(CHARSET_UTF8);
|
||||
if(bytes.length >= 65536) {
|
||||
throw new IllegalArgumentException("Encoded UTF-8 string too long.");
|
||||
}
|
||||
|
||||
out.writeShort(bytes.length);
|
||||
out.write(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a string from the buffer.
|
||||
*
|
||||
* @param buf
|
||||
* The buffer.
|
||||
* @return The string.
|
||||
*/
|
||||
public static String readString(DataInputStream in) throws IOException {
|
||||
int len = in.readUnsignedShort();
|
||||
|
||||
char[] characters = new char[len];
|
||||
for(int i = 0; i < len; i++) {
|
||||
characters[i] = in.readChar();
|
||||
}
|
||||
|
||||
return new String(characters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a UTF-8 encoded string from the buffer.
|
||||
*
|
||||
* @param buf
|
||||
* The buffer.
|
||||
* @return The string.
|
||||
*/
|
||||
public static String readUtf8String(DataInputStream in) throws IOException {
|
||||
int len = in.readUnsignedShort();
|
||||
|
||||
byte[] bytes = new byte[len];
|
||||
in.readFully(bytes);
|
||||
|
||||
return new String(bytes, CHARSET_UTF8);
|
||||
}
|
||||
|
||||
public static WatchableObject[] readMetadata(DataInputStream in) throws IOException {
|
||||
List<WatchableObject> objects = new ArrayList<WatchableObject>();
|
||||
|
||||
byte b;
|
||||
while((b = in.readByte()) != 127) {
|
||||
int type = (b & 0xe0) >> 5;
|
||||
int id = b & 0x1f;
|
||||
WatchableObject obj = null;
|
||||
|
||||
switch(type) {
|
||||
case 0:
|
||||
obj = new WatchableObject(type, id, Byte.valueOf(in.readByte()));
|
||||
break;
|
||||
case 1:
|
||||
obj = new WatchableObject(type, id, Short.valueOf(in.readShort()));
|
||||
break;
|
||||
case 2:
|
||||
obj = new WatchableObject(type, id, Integer.valueOf(in.readInt()));
|
||||
break;
|
||||
case 3:
|
||||
obj = new WatchableObject(type, id, Float.valueOf(in.readFloat()));
|
||||
break;
|
||||
case 4:
|
||||
obj = new WatchableObject(type, id, readString(in));
|
||||
break;
|
||||
case 5:
|
||||
short item = in.readShort();
|
||||
byte stackSize = 0;
|
||||
short damage = 0;
|
||||
if(item >= 0) {
|
||||
stackSize = in.readByte();
|
||||
damage = in.readShort();
|
||||
}
|
||||
|
||||
obj = new WatchableObject(type, id, new ItemStack(item, stackSize, damage));
|
||||
break;
|
||||
case 6:
|
||||
int x = in.readInt();
|
||||
int y = in.readInt();
|
||||
int z = in.readInt();
|
||||
obj = new WatchableObject(type, id, new Coordinates(x, y, z));
|
||||
break;
|
||||
}
|
||||
|
||||
objects.add(obj);
|
||||
}
|
||||
|
||||
return objects.toArray(new WatchableObject[objects.size()]);
|
||||
}
|
||||
|
||||
public static void writeMetadata(DataOutputStream out, WatchableObject data[]) throws IOException {
|
||||
for(WatchableObject obj : data) {
|
||||
int header = (obj.getType() << 5 | obj.getType() & 0x1f) & 0xff;
|
||||
out.writeByte(header);
|
||||
|
||||
switch (obj.getType()) {
|
||||
case 0:
|
||||
out.writeByte((Byte) obj.getValue());
|
||||
break;
|
||||
case 1:
|
||||
out.writeShort((Short) obj.getValue());
|
||||
break;
|
||||
case 2:
|
||||
out.writeInt((Integer) obj.getValue());
|
||||
break;
|
||||
case 3:
|
||||
out.writeFloat((Float) obj.getValue());
|
||||
break;
|
||||
case 4:
|
||||
writeString(out, (String) obj.getValue());
|
||||
break;
|
||||
case 5:
|
||||
ItemStack itemstack = (ItemStack) obj.getValue();
|
||||
out.writeShort(itemstack.getItem());
|
||||
if(itemstack.getItem() >= 0) {
|
||||
out.writeByte(itemstack.getStackSize());
|
||||
out.writeShort(itemstack.getDamage());
|
||||
}
|
||||
|
||||
break;
|
||||
case 6:
|
||||
Coordinates chunkcoordinates = (Coordinates) obj.getValue();
|
||||
out.writeInt(chunkcoordinates.getX());
|
||||
out.writeInt(chunkcoordinates.getY());
|
||||
out.writeInt(chunkcoordinates.getZ());
|
||||
break;
|
||||
}
|
||||
int header = (obj.getType() << 5 | obj.getType() & 0x1f) & 0xff;
|
||||
out.writeByte(header);
|
||||
|
||||
switch(obj.getType()) {
|
||||
case 0:
|
||||
out.writeByte((Byte) obj.getValue());
|
||||
break;
|
||||
case 1:
|
||||
out.writeShort((Short) obj.getValue());
|
||||
break;
|
||||
case 2:
|
||||
out.writeInt((Integer) obj.getValue());
|
||||
break;
|
||||
case 3:
|
||||
out.writeFloat((Float) obj.getValue());
|
||||
break;
|
||||
case 4:
|
||||
writeString(out, (String) obj.getValue());
|
||||
break;
|
||||
case 5:
|
||||
ItemStack itemstack = (ItemStack) obj.getValue();
|
||||
out.writeShort(itemstack.getItem());
|
||||
if(itemstack.getItem() >= 0) {
|
||||
out.writeByte(itemstack.getStackSize());
|
||||
out.writeShort(itemstack.getDamage());
|
||||
}
|
||||
|
||||
break;
|
||||
case 6:
|
||||
Coordinates chunkcoordinates = (Coordinates) obj.getValue();
|
||||
out.writeInt(chunkcoordinates.getX());
|
||||
out.writeInt(chunkcoordinates.getY());
|
||||
out.writeInt(chunkcoordinates.getZ());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
out.writeByte(127);
|
||||
|
||||
out.writeByte(127);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default private constructor to prevent instantiation.
|
||||
*/
|
||||
private IOUtils() {
|
||||
/**
|
||||
* Default private constructor to prevent instantiation.
|
||||
*/
|
||||
private IOUtils() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -13,15 +13,15 @@ public class Util {
|
|||
|
||||
private static final Logger logger = Logger.getLogger("mc-protocol-lib");
|
||||
private static final Random rand = new Random();
|
||||
|
||||
|
||||
public static Logger logger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
|
||||
public static Random random() {
|
||||
return rand;
|
||||
}
|
||||
|
||||
|
||||
public static String stripColor(String str) {
|
||||
StringBuilder build = new StringBuilder();
|
||||
for(int index = 0; index < str.length(); index++) {
|
||||
|
@ -29,13 +29,13 @@ public class Util {
|
|||
index++;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
build.append(str.charAt(index));
|
||||
}
|
||||
|
||||
|
||||
return build.toString();
|
||||
}
|
||||
|
||||
|
||||
public static byte[] encrypt(String serverId, PublicKey key, SecretKey secret) {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
||||
|
@ -51,5 +51,5 @@ public class Util {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue