sp-server

This commit is contained in:
catfoolyou
2025-02-06 18:02:51 -05:00
parent 353c5d7165
commit f4e3cbe2fe
1030 changed files with 123381 additions and 3 deletions

View File

@@ -1,69 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.IOException;
import java.io.InputStream;
public class IPCInputStream extends InputStream {
private byte[] currentBuffer = null;
private int idx = 0;
private int markIDX = 0;
private String errorName = null;
public void feedBuffer(byte[] b) {
currentBuffer = b;
idx = 0;
errorName = null;
markIDX = 0;
}
public void nameBuffer(String str) {
errorName = str;
}
@Override
public int read() throws IOException {
try {
return ((int)currentBuffer[idx++]) & 0xFF;
}catch(ArrayIndexOutOfBoundsException a) {
throw new IOException("IPCInputStream buffer underflow" + (errorName == null ? "," : (" (while deserializing '" + errorName + "')")) + " no bytes remaining", a);
}
}
@Override
public int read(byte b[], int off, int len) throws IOException {
if(idx + len > currentBuffer.length) {
throw new IOException("IPCInputStream buffer underflow" + (errorName == null ? "," : (" (while deserializing '" + errorName + "')")) + " tried to read " + len + " when there are only " + (currentBuffer.length - idx) + " bytes remaining", new ArrayIndexOutOfBoundsException(idx + len - 1));
}
if(off + len > b.length) {
throw new ArrayIndexOutOfBoundsException(off + len - 1);
}
System.arraycopy(currentBuffer, idx, b, off, len);
idx += len;
return len;
}
public void markIndex() {
markIDX = idx;
}
public void rewindIndex() {
idx = markIDX;
}
public byte[] getLeftover() {
if(currentBuffer.length - idx <= 0) {
return null;
}
byte[] buf = new byte[currentBuffer.length - idx];
System.arraycopy(currentBuffer, idx, buf, 0, currentBuffer.length - idx);
return buf;
}
public int getLeftoverCount() {
return currentBuffer.length - idx;
}
}

View File

@@ -1,54 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.IOException;
import java.io.OutputStream;
public class IPCOutputStream extends OutputStream {
private String className = null;
private byte[] currentBuffer = null;
private int idx = 0;
private int originalSize = 0;
public void feedBuffer(byte[] buf, String clazzName) {
currentBuffer = buf;
idx = 0;
originalSize = buf.length;
className = clazzName;
}
public byte[] returnBuffer() {
if(className != null && currentBuffer.length != originalSize) {
System.err.println("WARNING: Packet '" + className + "' was supposed to be " + originalSize + " bytes but buffer has grown by " + (currentBuffer.length - originalSize) + " to " + currentBuffer.length + " bytes");
}
return currentBuffer;
}
void growBuffer(int i) {
int ii = currentBuffer.length;
int iii = i - ii;
if(iii > 0) {
byte[] n = new byte[i];
System.arraycopy(currentBuffer, 0, n, 0, ii);
currentBuffer = n;
}
}
@Override
public void write(int b) throws IOException {
if(idx >= currentBuffer.length) {
growBuffer(idx + 1);
}
currentBuffer[idx++] = (byte) b;
}
@Override
public void write(byte b[], int off, int len) throws IOException {
if(idx + len > currentBuffer.length) {
growBuffer(idx + len);
}
System.arraycopy(b, off, currentBuffer, idx, len);
idx += len;
}
}

View File

@@ -1,48 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket00StartServer implements IPCPacketBase {
public static final int ID = 0x00;
public String worldName;
public String ownerName;
public int initialDifficulty;
public IPCPacket00StartServer() {
}
public IPCPacket00StartServer(String worldName, String ownerName, int initialDifficulty) {
this.worldName = worldName;
this.ownerName = ownerName;
this.initialDifficulty = initialDifficulty;
}
@Override
public void deserialize(DataInput bin) throws IOException {
worldName = bin.readUTF();
ownerName = bin.readUTF();
initialDifficulty = bin.readByte();
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeUTF(worldName);
bin.writeUTF(ownerName);
bin.writeByte(initialDifficulty);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return IPCPacketBase.strLen(worldName) + IPCPacketBase.strLen(ownerName) + 1;
}
}

View File

@@ -1,32 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket01StopServer implements IPCPacketBase {
public static final int ID = 0x01;
public IPCPacket01StopServer() {
}
@Override
public void deserialize(DataInput bin) throws IOException {
}
@Override
public void serialize(DataOutput bin) throws IOException {
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return 0;
}
}

View File

@@ -1,68 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket02InitWorld implements IPCPacketBase {
public static final int ID = 0x02;
public String worldName;
public byte gamemode;
public byte worldType;
public String worldArgs;
public long seed;
public boolean cheats;
public boolean structures;
public boolean bonusChest;
public IPCPacket02InitWorld() {
}
public IPCPacket02InitWorld(String worldName, int gamemode, int worldType, String worldArgs, long seed, boolean cheats, boolean structures, boolean bonusChest) {
this.worldName = worldName;
this.gamemode = (byte)gamemode;
this.worldType = (byte)worldType;
this.worldArgs = worldArgs;
this.seed = seed;
this.cheats = cheats;
this.structures = structures;
this.bonusChest = bonusChest;
}
@Override
public void deserialize(DataInput bin) throws IOException {
worldName = bin.readUTF();
gamemode = bin.readByte();
worldType = bin.readByte();
worldArgs = bin.readUTF();
seed = bin.readLong();
cheats = bin.readBoolean();
structures = bin.readBoolean();
bonusChest = bin.readBoolean();
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeUTF(worldName);
bin.writeByte(gamemode);
bin.writeByte(worldType);
bin.writeUTF(worldArgs);
bin.writeLong(seed);
bin.writeBoolean(cheats);
bin.writeBoolean(structures);
bin.writeBoolean(bonusChest);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return IPCPacketBase.strLen(worldName) + 1 + 1 + IPCPacketBase.strLen(worldArgs) + 8 + 1 + 1 + 1;
}
}

View File

@@ -1,40 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket03DeleteWorld implements IPCPacketBase {
public static final int ID = 0x03;
public String worldName;
public IPCPacket03DeleteWorld() {
}
public IPCPacket03DeleteWorld(String worldName) {
this.worldName = worldName;
}
@Override
public void deserialize(DataInput bin) throws IOException {
worldName = bin.readUTF();
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeUTF(worldName);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return IPCPacketBase.strLen(worldName);
}
}

View File

@@ -1,52 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket04RenameWorld implements IPCPacketBase {
public static final int ID = 0x04;
public String worldOldName;
public String worldNewName;
public String displayName;
public boolean copy;
public IPCPacket04RenameWorld() {
}
public IPCPacket04RenameWorld(String worldOldName, String worldNewName, String displayName, boolean copy) {
this.worldOldName = worldOldName;
this.worldNewName = worldNewName;
this.displayName = displayName;
this.copy = copy;
}
@Override
public void deserialize(DataInput bin) throws IOException {
worldOldName = bin.readUTF();
worldNewName = bin.readUTF();
displayName = bin.readUTF();
copy = bin.readBoolean();
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeUTF(worldOldName);
bin.writeUTF(worldNewName);
bin.writeUTF(displayName);
bin.writeBoolean(copy);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return IPCPacketBase.strLen(worldOldName) + IPCPacketBase.strLen(worldNewName) + IPCPacketBase.strLen(displayName) + 1;
}
}

View File

@@ -1,48 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket05RequestData implements IPCPacketBase {
public static final int ID = 0x05;
public static final byte REQUEST_LEVEL_DAT = 0x00;
public static final byte REQUEST_LEVEL_EAG = 0x01;
public static final byte REQUEST_LEVEL_MCA = 0x02;
public String worldName;
public byte request;
public IPCPacket05RequestData() {
}
public IPCPacket05RequestData(String worldName, byte request) {
this.worldName = worldName;
this.request = request;
}
@Override
public void deserialize(DataInput bin) throws IOException {
worldName = bin.readUTF();
request = bin.readByte();
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeUTF(worldName);
bin.writeByte(request);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return IPCPacketBase.strLen(worldName) + 1;
}
}

View File

@@ -1,44 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket06RenameWorldNBT implements IPCPacketBase {
public static final int ID = 0x06;
public String worldName;
public String displayName;
public IPCPacket06RenameWorldNBT() {
}
public IPCPacket06RenameWorldNBT(String worldName, String displayName) {
this.worldName = worldName;
this.displayName = displayName;
}
@Override
public void deserialize(DataInput bin) throws IOException {
this.worldName = bin.readUTF();
this.displayName = bin.readUTF();
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeUTF(worldName);
bin.writeUTF(displayName);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return IPCPacketBase.strLen(worldName) + IPCPacketBase.strLen(displayName);
}
}

View File

@@ -1,53 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket07ImportWorld implements IPCPacketBase {
public static final int ID = 0x07;
public String worldName;
public byte[] worldData;
public byte worldFormat;
public static final byte WORLD_FORMAT_EAG = 0x00;
public static final byte WORLD_FORMAT_MCA = 0x01;
public IPCPacket07ImportWorld() {
}
public IPCPacket07ImportWorld(String worldName, byte[] worldData, byte worldFormat) {
this.worldName = worldName;
this.worldData = worldData;
this.worldFormat = worldFormat;
}
@Override
public void deserialize(DataInput bin) throws IOException {
worldName = bin.readUTF();
worldData = new byte[bin.readInt()];
worldFormat = bin.readByte();
bin.readFully(worldData);
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeUTF(worldName);
bin.writeInt(worldData.length);
bin.writeByte(worldFormat);
bin.write(worldData);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return IPCPacketBase.strLen(worldName) + worldData.length + 5;
}
}

View File

@@ -1,42 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket09RequestResponse implements IPCPacketBase {
public static final int ID = 0x09;
public byte[] response;
public IPCPacket09RequestResponse() {
}
public IPCPacket09RequestResponse(byte[] dat) {
this.response = dat;
}
@Override
public void deserialize(DataInput bin) throws IOException {
response = new byte[bin.readInt()];
bin.readFully(response);
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeInt(response.length);
bin.write(response);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return 4 + response.length;
}
}

View File

@@ -1,40 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket0ASetWorldDifficulty implements IPCPacketBase {
public static final int ID = 0x0A;
public byte difficulty;
public IPCPacket0ASetWorldDifficulty() {
}
public IPCPacket0ASetWorldDifficulty(byte difficulty) {
this.difficulty = difficulty;
}
@Override
public void deserialize(DataInput bin) throws IOException {
difficulty = bin.readByte();
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeByte(difficulty);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return 1;
}
}

View File

@@ -1,40 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket0BPause implements IPCPacketBase {
public static final int ID = 0x0B;
public boolean pause;
public IPCPacket0BPause() {
}
public IPCPacket0BPause(boolean pause) {
this.pause = pause;
}
@Override
public void deserialize(DataInput bin) throws IOException {
pause = bin.readBoolean();
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeBoolean(pause);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return 1;
}
}

View File

@@ -1,44 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket0CPlayerChannel implements IPCPacketBase {
public static final int ID = 0x0C;
public String channel;
public boolean open;
public IPCPacket0CPlayerChannel() {
}
public IPCPacket0CPlayerChannel(String channel, boolean open) {
this.channel = channel;
this.open = open;
}
@Override
public void deserialize(DataInput bin) throws IOException {
channel = bin.readUTF();
open = bin.readBoolean();
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeUTF(channel);
bin.writeBoolean(open);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return IPCPacketBase.strLen(channel) + 1;
}
}

View File

@@ -1,44 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket0DProgressUpdate implements IPCPacketBase {
public static final int ID = 0x0D;
public String updateMessage;
public float updateProgress;
public IPCPacket0DProgressUpdate() {
}
public IPCPacket0DProgressUpdate(String updateMessage, float updateProgress) {
this.updateMessage = updateMessage == null ? "" : updateMessage;
this.updateProgress = updateProgress;
}
@Override
public void deserialize(DataInput bin) throws IOException {
updateMessage = bin.readUTF();
updateProgress = bin.readFloat();
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeUTF(updateMessage);
bin.writeFloat(updateProgress);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return IPCPacketBase.strLen(updateMessage) + 4;
}
}

View File

@@ -1,32 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket0EListWorlds implements IPCPacketBase {
public static final int ID = 0x0E;
public IPCPacket0EListWorlds() {
}
@Override
public void deserialize(DataInput bin) throws IOException {
}
@Override
public void serialize(DataOutput bin) throws IOException {
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return 0;
}
}

View File

@@ -1,40 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket0FListFiles implements IPCPacketBase {
public static final int ID = 0x0F;
public String path;
public IPCPacket0FListFiles() {
}
public IPCPacket0FListFiles(String path) {
this.path = path;
}
@Override
public void deserialize(DataInput bin) throws IOException {
this.path = bin.readUTF();
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeUTF(path);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return IPCPacketBase.strLen(path);
}
}

View File

@@ -1,40 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket10FileRead implements IPCPacketBase {
public static final int ID = 0x10;
public String file;
public IPCPacket10FileRead() {
}
public IPCPacket10FileRead(String file) {
this.file = file;
}
@Override
public void deserialize(DataInput bin) throws IOException {
file = bin.readUTF();
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeUTF(file);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return IPCPacketBase.strLen(file);
}
}

View File

@@ -1,44 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket12FileWrite implements IPCPacketBase {
public static final int ID = 0x12;
public String path;
public byte[] data;
public IPCPacket12FileWrite() {
}
public IPCPacket12FileWrite(String path, byte[] data) {
this.path = path;
this.data = data;
}
@Override
public void deserialize(DataInput bin) throws IOException {
path = bin.readUTF();
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeUTF(path);
bin.writeInt(data.length);
bin.write(data);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return IPCPacketBase.strLen(path) + 4 + data.length;
}
}

View File

@@ -1,48 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket13FileCopyMove implements IPCPacketBase {
public static final int ID = 0x13;
public String fileOldName;
public String fileNewName;
public boolean copy;
public IPCPacket13FileCopyMove() {
}
public IPCPacket13FileCopyMove(String fileOldName, String fileNewName, boolean copy) {
this.fileOldName = fileOldName;
this.fileNewName = fileNewName;
this.copy = copy;
}
@Override
public void deserialize(DataInput bin) throws IOException {
fileOldName = bin.readUTF();
fileNewName = bin.readUTF();
copy = bin.readBoolean();
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeUTF(fileOldName);
bin.writeUTF(fileNewName);
bin.writeBoolean(copy);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return IPCPacketBase.strLen(fileOldName) + IPCPacketBase.strLen(fileNewName) + 1;
}
}

View File

@@ -1,80 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class IPCPacket14StringList implements IPCPacketBase {
public static final int ID = 0x14;
public static final int FILE_LIST = 0x0;
public static final int LOCALE = 0x1;
public static final int STAT_GUID = 0x2;
public static final int SERVER_TPS = 0x3;
public int opCode;
public final List<String> stringList;
public IPCPacket14StringList() {
stringList = new ArrayList<>();
}
public IPCPacket14StringList(int opcode, String[] list) {
stringList = new ArrayList<>();
for(String s : list) {
s = s.trim();
if(s.length() > 0) {
stringList.add(s);
}
}
this.opCode = opcode;
}
public IPCPacket14StringList(int opcode, List<String> list) {
stringList = new ArrayList<>();
for(String s : list) {
s = s.trim();
if(s.length() > 0) {
stringList.add(s);
}
}
this.opCode = opcode;
}
@Override
public void deserialize(DataInput bin) throws IOException {
stringList.clear();
opCode = bin.readByte();
int len = bin.readInt();
for(int i = 0; i < len; ++i) {
stringList.add(bin.readUTF());
}
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeByte(opCode);
bin.writeInt(stringList.size());
for(String str : stringList) {
bin.writeUTF(str);
}
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
int len = 5;
for(String str : stringList) {
len += IPCPacketBase.strLen(str);
}
return len;
}
}

View File

@@ -1,71 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class IPCPacket15ThrowException implements IPCPacketBase {
public static final int ID = 0x15;
public String errorMessage;
public final List<String> stackTrace;
public IPCPacket15ThrowException() {
stackTrace = new ArrayList<>();
}
public IPCPacket15ThrowException(String errorMessage, String[] list) {
stackTrace = new ArrayList<>(Arrays.asList(list));
this.errorMessage = errorMessage;
}
public IPCPacket15ThrowException(String errorMessage, List<String> list) {
stackTrace = list;
this.errorMessage = errorMessage;
}
@Override
public void deserialize(DataInput bin) throws IOException {
stackTrace.clear();
errorMessage = bin.readUTF();
int len = bin.readInt();
for(int i = 0; i < len; ++i) {
stackTrace.add(bin.readUTF());
}
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeUTF(errorMessage);
bin.writeInt(stackTrace.size());
for(String str : stackTrace) {
bin.writeUTF(str);
}
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
int len = 4 + IPCPacketBase.strLen(errorMessage);
for(String str : stackTrace) {
len += IPCPacketBase.strLen(str);
}
return len;
}
public void log() {
System.err.println("Integrated server exception: " + errorMessage);
for(String s : stackTrace) {
System.err.println(" at " + s);
}
}
}

View File

@@ -1,95 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.src.CompressedStreamTools;
import net.minecraft.src.NBTTagCompound;
public class IPCPacket16NBTList implements IPCPacketBase {
public static final int ID = 0x16;
public static final int WORLD_LIST = 0x0;
public int opCode;
public final List<byte[]> tagList;
public final List<NBTTagCompound> nbtTagList;
public IPCPacket16NBTList() {
tagList = new LinkedList<>();
nbtTagList = new LinkedList<>();
}
public IPCPacket16NBTList(int opcode, NBTTagCompound[] list) {
this(opcode, Arrays.asList(list));
}
public IPCPacket16NBTList(int opcode, List<NBTTagCompound> list) {
tagList = new LinkedList<>();
nbtTagList = list;
for(int i = 0, size = list.size(); i < size; ++i) {
NBTTagCompound tag = list.get(i);
try {
ByteArrayOutputStream bao = new ByteArrayOutputStream();
CompressedStreamTools.write(tag, new DataOutputStream(bao));
tagList.add(bao.toByteArray());
}catch(IOException e) {
System.err.println("Failed to write tag '" + tag.getName() + "' (#" + i + ") in IPCPacket16NBTList");
}
}
opCode = opcode;
}
@Override
public void deserialize(DataInput bin) throws IOException {
tagList.clear();
nbtTagList.clear();
opCode = bin.readInt();
int count = bin.readInt();
for(int i = 0; i < count; ++i) {
byte[] toRead = new byte[bin.readInt()];
bin.readFully(toRead);
tagList.add(toRead);
try {
nbtTagList.add(CompressedStreamTools.read(new DataInputStream(new ByteArrayInputStream(toRead))));
}catch(IOException e) {
System.err.println("Failed to read tag #" + i + " in IPCPacket16NBTList");
}
}
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeInt(opCode);
bin.writeInt(tagList.size());
for(byte[] str : tagList) {
bin.writeInt(str.length);
bin.write(str);
}
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
int len = 8;
for(byte[] str : tagList) {
len += 4;
len += str.length;
}
return len;
}
}

View File

@@ -1,63 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class IPCPacket17ConfigureLAN implements IPCPacketBase {
public static final int ID = 0x17;
public int gamemode;
public boolean cheats;
public final List<String> iceServers;
public IPCPacket17ConfigureLAN() {
iceServers = new ArrayList<>();
}
public IPCPacket17ConfigureLAN(int gamemode, boolean cheats, List<String> iceServers) {
this.gamemode = gamemode;
this.cheats = cheats;
this.iceServers = iceServers;
}
@Override
public void deserialize(DataInput bin) throws IOException {
gamemode = bin.readUnsignedByte();
cheats = bin.readBoolean();
iceServers.clear();
int iceCount = bin.readUnsignedByte();
for(int i = 0; i < iceCount; ++i) {
iceServers.add(bin.readUTF());
}
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeByte(gamemode);
bin.writeBoolean(cheats);
bin.writeByte(iceServers.size());
for(int i = 0, l = iceServers.size(); i < l; ++i) {
bin.writeUTF(iceServers.get(i));
}
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
int s = 0;
for(int i = 0, l = iceServers.size(); i < l; ++i) {
s += 2;
s += iceServers.get(i).length();
}
return 2 + 1 + s;
}
}

View File

@@ -1,40 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacket18ClearPlayers implements IPCPacketBase {
public static final int ID = 0x18;
public String worldName = null;
public IPCPacket18ClearPlayers(String worldName) {
this.worldName = worldName;
}
public IPCPacket18ClearPlayers() {
}
@Override
public void deserialize(DataInput bin) throws IOException {
worldName = bin.readUTF();
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeUTF(worldName);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return IPCPacketBase.strLen(worldName);
}
}

View File

@@ -1,33 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public interface IPCPacketBase {
public void deserialize(DataInput bin) throws IOException;
public void serialize(DataOutput bin) throws IOException;
public int id();
public int size();
public static int strLen(String s) {
int strlen = s.length();
int utflen = 2;
int c;
for (int i = 0; i < strlen; ++i) {
c = s.charAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
++utflen;
} else if (c > 0x07FF) {
utflen += 3;
} else {
utflen += 2;
}
}
return utflen;
}
}

View File

@@ -1,43 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IPCPacketFFProcessKeepAlive implements IPCPacketBase {
public static final int ID = 0xFF;
public static final int KEEPALIVE = 0;
public static final int FAILURE = 0xFE;
public int ack;
public IPCPacketFFProcessKeepAlive() {
}
public IPCPacketFFProcessKeepAlive(int ack) {
this.ack = ack;
}
@Override
public void deserialize(DataInput bin) throws IOException {
ack = bin.readUnsignedByte();
}
@Override
public void serialize(DataOutput bin) throws IOException {
bin.writeByte(ack);
}
@Override
public int id() {
return ID;
}
@Override
public int size() {
return 1;
}
}

View File

@@ -1,79 +0,0 @@
package net.lax1dude.eaglercraft.sp.ipc;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.function.Supplier;
public class IPCPacketManager {
public static final HashMap<Integer, Supplier<IPCPacketBase>> mappings = new HashMap<>();
public static final IPCInputStream IPC_INPUT_STREAM = new IPCInputStream();
public static final IPCOutputStream IPC_OUTPUT_STREAM = new IPCOutputStream();
public static final DataInputStream IPC_DATA_INPUT_STREAM = new DataInputStream(IPC_INPUT_STREAM);
public static final DataOutputStream IPC_DATA_OUTPUT_STREAM = new DataOutputStream(IPC_OUTPUT_STREAM);
static {
mappings.put(IPCPacket00StartServer.ID, () -> new IPCPacket00StartServer());
mappings.put(IPCPacket01StopServer.ID, () -> new IPCPacket01StopServer());
mappings.put(IPCPacket02InitWorld.ID, () -> new IPCPacket02InitWorld());
mappings.put(IPCPacket03DeleteWorld.ID, () -> new IPCPacket03DeleteWorld());
mappings.put(IPCPacket04RenameWorld.ID, () -> new IPCPacket04RenameWorld());
mappings.put(IPCPacket05RequestData.ID, () -> new IPCPacket05RequestData());
mappings.put(IPCPacket06RenameWorldNBT.ID, () -> new IPCPacket06RenameWorldNBT());
mappings.put(IPCPacket07ImportWorld.ID, () -> new IPCPacket07ImportWorld());
mappings.put(IPCPacket09RequestResponse.ID, () -> new IPCPacket09RequestResponse());
mappings.put(IPCPacket0ASetWorldDifficulty.ID, () -> new IPCPacket0ASetWorldDifficulty());
mappings.put(IPCPacket0BPause.ID, () -> new IPCPacket0BPause());
mappings.put(IPCPacket0CPlayerChannel.ID, () -> new IPCPacket0CPlayerChannel());
mappings.put(IPCPacket0DProgressUpdate.ID, () -> new IPCPacket0DProgressUpdate());
mappings.put(IPCPacket0EListWorlds.ID, () -> new IPCPacket0EListWorlds());
mappings.put(IPCPacket0FListFiles.ID, () -> new IPCPacket0FListFiles());
mappings.put(IPCPacket10FileRead.ID, () -> new IPCPacket10FileRead());
mappings.put(IPCPacket12FileWrite.ID, () -> new IPCPacket12FileWrite());
mappings.put(IPCPacket13FileCopyMove.ID, () -> new IPCPacket13FileCopyMove());
mappings.put(IPCPacket14StringList.ID, () -> new IPCPacket14StringList());
mappings.put(IPCPacket15ThrowException.ID, () -> new IPCPacket15ThrowException());
mappings.put(IPCPacket16NBTList.ID, () -> new IPCPacket16NBTList());
mappings.put(IPCPacket17ConfigureLAN.ID, () -> new IPCPacket17ConfigureLAN());
mappings.put(IPCPacket18ClearPlayers.ID, () -> new IPCPacket18ClearPlayers());
mappings.put(IPCPacketFFProcessKeepAlive.ID, () -> new IPCPacketFFProcessKeepAlive());
}
public static byte[] IPCSerialize(IPCPacketBase pkt) throws IOException {
IPC_OUTPUT_STREAM.feedBuffer(new byte[pkt.size() + 1], pkt.getClass().getSimpleName());
IPC_OUTPUT_STREAM.write(pkt.id());
pkt.serialize(IPC_DATA_OUTPUT_STREAM);
return IPC_OUTPUT_STREAM.returnBuffer();
}
public static IPCPacketBase IPCDeserialize(byte[] pkt) throws IOException {
IPC_INPUT_STREAM.feedBuffer(pkt);
int i = IPC_INPUT_STREAM.read();
Supplier<IPCPacketBase> pk = mappings.get(Integer.valueOf(i));
if(pk == null) {
throw new IOException("Packet type 0x" + Integer.toHexString(i) + " doesn't exist");
}
IPCPacketBase p = pk.get();
IPC_INPUT_STREAM.nameBuffer(p.getClass().getSimpleName());
p.deserialize(IPC_DATA_INPUT_STREAM);
int lo = IPC_INPUT_STREAM.getLeftoverCount();
if(lo > 0) {
System.err.println("Packet type 0x" + Integer.toHexString(i) + " class '" + p.getClass().getSimpleName() + "' was size " + (pkt.length - 1) + " but only " + (pkt.length - 1 - lo) + " bytes were read");
}
return p;
}
}