Sometimes we need long strings

This commit is contained in:
md_5 2012-10-13 11:02:34 +11:00
parent a51ce916ce
commit a6dacb3f96
3 changed files with 88 additions and 12 deletions

View File

@ -79,13 +79,13 @@ public class UserConnection extends GenericConnection implements CommandSender {
server = newServer; server = newServer;
downBridge.start(); downBridge.start();
} catch (KickException ex) { } catch (KickException ex) {
destory(ex.getMessage()); destroySelf(ex.getMessage());
} catch (Exception ex) { } catch (Exception ex) {
destory("Could not connect to server"); destroySelf("Could not connect to server");
} }
} }
private void destory(String reason) { private void destroySelf(String reason) {
if (BungeeCord.instance.isRunning) { if (BungeeCord.instance.isRunning) {
BungeeCord.instance.connections.remove(username); BungeeCord.instance.connections.remove(username);
} }
@ -130,9 +130,9 @@ public class UserConnection extends GenericConnection implements CommandSender {
server.out.write(packet); server.out.write(packet);
} }
} catch (IOException ex) { } catch (IOException ex) {
destory("Reached end of stream"); destroySelf("Reached end of stream");
} catch (Exception ex) { } catch (Exception ex) {
destory(Util.exception(ex)); destroySelf(Util.exception(ex));
} }
} }
} }
@ -149,7 +149,6 @@ public class UserConnection extends GenericConnection implements CommandSender {
try { try {
while (!reconnecting) { while (!reconnecting) {
byte[] packet = server.in.readPacket(); byte[] packet = server.in.readPacket();
boolean sendPacket = true;
int id = Util.getId(packet); int id = Util.getId(packet);
if (id == 0xFA) { if (id == 0xFA) {
@ -169,13 +168,10 @@ public class UserConnection extends GenericConnection implements CommandSender {
} }
EntityMap.rewrite(packet, serverEntityId, clientEntityId); EntityMap.rewrite(packet, serverEntityId, clientEntityId);
if (sendPacket) { out.write(packet);
out.write(packet);
}
} }
} catch (IOException ex) {
} catch (Exception ex) { } catch (Exception ex) {
destory(Util.exception(ex)); destroySelf(Util.exception(ex));
} }
} }
} }

View File

@ -71,6 +71,6 @@ public class Util {
* @return a string representing information about the {@link Throwable} * @return a string representing information about the {@link Throwable}
*/ */
public static String exception(Throwable t) { public static String exception(Throwable t) {
return t.getClass().getSimpleName() + " : " + t.getMessage() + " @ " + t.getStackTrace()[0].getFileName() + ":" + t.getStackTrace()[0].getLineNumber(); return t.getClass().getSimpleName() + " : " + t.getMessage() + " @ " + t.getStackTrace()[0].getClassName() + ":" + t.getStackTrace()[0].getLineNumber();
} }
} }

View File

@ -0,0 +1,80 @@
package net.minecraft.server;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public abstract class Packet {
public boolean lowPriority = false;
public static void a(DataOutputStream dataoutputstream, byte[] abyte) throws IOException {
dataoutputstream.writeShort(abyte.length);
dataoutputstream.write(abyte);
}
public static byte[] b(DataInputStream datainputstream) throws IOException {
short short1 = datainputstream.readShort();
if (short1 < 0) {
throw new IOException("Key was smaller than nothing! Weird key!");
} else {
byte[] abyte = new byte[short1];
datainputstream.read(abyte);
return abyte;
}
}
public static String a(DataInputStream datainputstream, int i) throws IOException {
short short1 = datainputstream.readShort();
if (short1 < 0) {
throw new IOException("Received string length is less than zero! Weird string!");
} else {
StringBuilder stringbuilder = new StringBuilder();
for (int j = 0; j < short1; ++j) {
stringbuilder.append(datainputstream.readChar());
}
return stringbuilder.toString();
}
}
public abstract void a(DataInputStream datainputstream);
public abstract void a(DataOutputStream dataoutputstream);
public abstract void handle(NetHandler nethandler);
public abstract int a();
public static ItemStack c(DataInputStream datainputstream) throws IOException {
ItemStack itemstack = null;
short short1 = datainputstream.readShort();
if (short1 >= 0) {
byte b0 = datainputstream.readByte();
short short2 = datainputstream.readShort();
itemstack = new ItemStack(short1, b0, short2);
itemstack.tag = d(datainputstream);
}
return itemstack;
}
public static NBTTagCompound d(DataInputStream datainputstream) throws IOException {
short short1 = datainputstream.readShort();
if (short1 < 0) {
return null;
} else {
byte[] abyte = new byte[short1];
datainputstream.readFully(abyte);
return NBTCompressedStreamTools.a(abyte);
}
}
}