Implement multiplayer, several bug fixes

This commit is contained in:
PeytonPlayz595 2024-06-10 20:31:25 -04:00
parent 9205b4d267
commit b2dd5c5dd9
21 changed files with 509 additions and 192 deletions

View File

@ -4,7 +4,9 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import net.PeytonPlayz585.glemu.FixedFunctionShader;
import net.PeytonPlayz585.glemu.GLObjectMap;
@ -196,6 +198,8 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
private int shaderMode;
private int listLength;
private List<Translate> translate = new ArrayList<Translate>();
private DisplayList(int id) {
this.id = id;
this.glarray = null;
@ -205,6 +209,16 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
}
private static class Translate {
private float f, f1, f2;
private Translate(float f, float f1, float f2) {
this.f = f;
this.f1 = f1;
this.f2 = f2;
}
}
private static final HashMap<Integer, DisplayList> displayLists = new HashMap();
private static final HashMap<Integer, DisplayList> displayListsInitialized = new HashMap();
@ -370,7 +384,8 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
deevis.set(p1, p2, p3);
getMatrix().translate(deevis);
if (isCompilingDisplayList) {
throw new IllegalArgumentException("matrix is not supported while recording display list use tessellator class instead");
compilingDisplayList.translate.add(new Translate(p1, p2, p3));
//throw new IllegalArgumentException("matrix is not supported while recording display list use tessellator class instead");
}
}
@ -706,6 +721,13 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
bindTheShader(d.shaderMode | getShaderModeFlag1());
_wglBindVertexArray0(d.glarray);
_wglDrawQuadArrays(0, d.listLength);
//glTranslate support for display lists
for(Translate t : d.translate) {
deevis.set(t.f, t.f1, t.f2);
getMatrix().translate(deevis);
}
shader.unuseProgram();
vertexDrawn += d.listLength * 6 / 4;
triangleDrawn += d.listLength / 2;
@ -805,7 +827,13 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
public static final void glPolygonOffset(float p1, float p2) {
_wglPolygonOffset(p1, p2);
//if(p1 != 0) {
p1 = -p1;
//}
//if(p2 != 0) {
p2 = -p2;
//}
_wglPolygonOffset(-p1, -p2);
}
public static final void glCallLists(IntBuffer p1) {

View File

@ -0,0 +1,78 @@
package net.PeytonPlayz585.profile;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2;
import net.minecraft.client.Minecraft;
import net.minecraft.src.CompressedStreamTools;
import net.minecraft.src.NBTTagCompound;
public class Profile {
private static String username = "";
public static String getName() {
return username;
}
public static void setName(String str) {
username = str;
Minecraft mc = Minecraft.getMinecraft();
if(mc != null) {
mc.session.username = str;
}
}
public static void read() {
read(EaglerAdapterImpl2.loadLocalStorage("P"));
}
public static void read(byte[] profileStorage) {
if (profileStorage == null) {
return;
}
NBTTagCompound profile;
try {
profile = CompressedStreamTools.func_1138_a(new ByteArrayInputStream(profileStorage));
}catch(IOException ex) {
return;
}
if (profile == null || profile.hasNoTags()) {
return;
}
String loadUsername = profile.getString("username").trim();
if(!loadUsername.isEmpty()) {
username = loadUsername.replaceAll("[^A-Za-z0-9]", "_");
}
}
private static byte[] write() {
NBTTagCompound profile = new NBTTagCompound();
profile.setString("username", username);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
CompressedStreamTools.writeGzippedCompoundToOutputStream(profile, baos);
} catch (IOException e) {
return null;
}
return baos.toByteArray();
}
public static void save() {
byte[] b = write();
if(b != null) {
EaglerAdapterImpl2.saveLocalStorage("P", b);
}
}
static {
read();
}
}

View File

@ -0,0 +1,22 @@
package net.PeytonPlayz585.socket;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
public class ByteBufferDirectInputStream extends InputStream {
private ByteBuffer buf;
public ByteBufferDirectInputStream(ByteBuffer b) {
this.buf = b;
}
@Override
public int read() throws IOException {
return buf.remaining() > 0 ? ((int) buf.get() & 0xFF) : -1;
}
@Override
public int available() {
return buf.remaining();
}
}

View File

@ -0,0 +1,49 @@
package net.PeytonPlayz585.socket;
import java.io.IOException;
import net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2;
public class Socket {
public Socket(String hostName, int port) throws IOException {
if(!EaglerAdapterImpl2.startConnection(hostName + ":" + port)) {
IOException e = new IOException("Connection failed: " + hostName + ":" + port);
e.printStackTrace();
throw e;
}
}
public Socket(String hostName) throws IOException {
if(!EaglerAdapterImpl2.startConnection(hostName)) {
IOException e = new IOException("Connection failed: " + hostName);
e.printStackTrace();
throw e;
}
}
public void write(byte[] data) {
if(socketOpen()) {
EaglerAdapterImpl2.writePacket(data);
}
}
public byte[] read() {
if(socketOpen()) {
return EaglerAdapterImpl2.readPacket();
} else {
return null;
}
}
public void close() {
if(socketOpen()) {
EaglerAdapterImpl2.endConnection();
}
}
public boolean socketOpen() {
return EaglerAdapterImpl2.connectionOpen();
}
}

View File

@ -0,0 +1,62 @@
/*
* Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package net.PeytonPlayz585.socket;
import java.io.IOException;
/**
* Thrown to indicate that there is an error creating or accessing a Socket.
*
* @author Jonathan Payne
* @since JDK1.0
*/
public
class SocketException extends IOException {
private static final long serialVersionUID = -5935874303556886934L;
/**
* Constructs a new {@code SocketException} with the
* specified detail message.
*
* @param msg the detail message.
*/
public SocketException(String msg) {
super(msg);
}
/**
* Constructs a new {@code SocketException} with no detail message.
*/
public SocketException() {
}
@Override
public String toString() {
String s = "java.net.SocketException";
String message = getLocalizedMessage();
return (message != null) ? (s + ": " + message) : s;
}
}

View File

@ -41,7 +41,7 @@ public class Client {
private static void run0() {
System.out.println(" -------- starting minecraft -------- ");
instance = new Minecraft();
Session session = new Session("Player", "mcpass");
Session session = new Session("Player094", "mcpass");
instance.session = session;
LocalStorageManager.loadStorage();
run1();

View File

@ -72,7 +72,6 @@ import net.minecraft.src.TexturePortalFX;
import net.minecraft.src.TextureWatchFX;
import net.minecraft.src.TextureWaterFX;
import net.minecraft.src.TextureWaterFlowFX;
import net.minecraft.src.ThreadSleepForever;
import net.minecraft.src.Timer;
import net.minecraft.src.UnexpectedThrowable;
import net.minecraft.src.Vec3D;
@ -138,7 +137,6 @@ public class Minecraft implements Runnable {
public Minecraft() {
StatList.func_27360_a();
this.tempDisplayHeight = GL11.getCanvasHeight();
new ThreadSleepForever(this, "Timer hack thread");
this.displayWidth = GL11.getCanvasWidth();
this.displayHeight = GL11.getCanvasHeight();
@ -198,14 +196,9 @@ public class Minecraft implements Runnable {
this.checkGLError("Post startup");
this.ingameGUI = new GuiIngame(this);
if(this.serverName != null) {
this.displayGuiScreen(new GuiConnecting(this, this.serverName, this.serverPort));
} else {
this.displayGuiScreen(new GuiMainMenu());
}
}
private void loadScreen() {
ScaledResolution var1 = new ScaledResolution(this.gameSettings, this.displayWidth, this.displayHeight);
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_COLOR_BUFFER_BIT);

View File

@ -10,6 +10,7 @@ public class FontRenderer {
private int[] charWidth = new int[256];
public int fontTextureName = 0;
private int fontDisplayLists;
private IntBuffer buffer = GLAllocation.createDirectIntBuffer(1024);
public FontRenderer(GameSettings var1, String var2, RenderEngine var3) {
BufferedImage var4;
@ -75,6 +76,7 @@ public class FontRenderer {
var19.addVertexWithUV((double)(0.0F + var20), 0.0D, 0.0D, (double)(((float)var10 + var20) / 128.0F + var21), (double)((float)var11 / 128.0F + var23));
var19.addVertexWithUV(0.0D, 0.0D, 0.0D, (double)((float)var10 / 128.0F + var21), (double)((float)var11 / 128.0F + var23));
var19.draw();
GL11.glTranslatef((float)this.charWidth[var9], 0.0F, 0.0F);
GL11.glEndList();
}
@ -138,6 +140,7 @@ public class FontRenderer {
}
GL11.glColor4f(var10, var7, var8, var9);
this.buffer.clear();
GL11.glPushMatrix();
GL11.glTranslatef((float)var2, (float)var3, 0.0F);
@ -149,19 +152,30 @@ public class FontRenderer {
var11 = 15;
}
GL11.glCallList(fontDisplayLists + 256 + var11 + (var5 ? 16 : 0));
GL11.glTranslatef(charWidth[256 + var11 + (var5 ? 16 : 0)] * 0.5f, 0.0F, 0.0F);
this.buffer.put(this.fontDisplayLists + 256 + var11 + (var5 ? 16 : 0));
if(this.buffer.remaining() == 0) {
this.buffer.flip();
GL11.glCallLists(this.buffer);
this.buffer.clear();
}
}
if(var6 < var1.length()) {
var11 = ChatAllowedCharacters.allowedCharacters.indexOf(var1.charAt(var6));
if(var11 >= 0) {
GL11.glCallList(fontDisplayLists + var11 + 32);
GL11.glTranslatef(charWidth[var11 + 32], 0.0F, 0.0F);
}
this.buffer.put(this.fontDisplayLists + var11 + 32);
}
}
if(this.buffer.remaining() == 0) {
this.buffer.flip();
GL11.glCallLists(this.buffer);
this.buffer.clear();
}
}
this.buffer.flip();
GL11.glCallLists(this.buffer);
GL11.glPopMatrix();
}
}

View File

@ -6,10 +6,10 @@ public class GuiConnecting extends GuiScreen {
private NetClientHandler clientHandler;
private boolean cancelled = false;
public GuiConnecting(Minecraft var1, String var2, int var3) {
System.out.println("Connecting to " + var2 + ", " + var3);
public GuiConnecting(Minecraft var1, String var2) {
System.out.println("Connecting to " + var2);
var1.changeWorld1((World)null);
//(new ThreadConnectToServer(this, var1, var2, var3)).start();
(new ThreadConnectToServer(this, var1, var2)).start();
}
public void updateScreen() {

View File

@ -172,6 +172,7 @@ public abstract class GuiContainer extends GuiScreen {
public void updateScreen() {
super.updateScreen();
this.mc.setIngameNotInFocus();
if(!this.mc.thePlayer.isEntityAlive() || this.mc.thePlayer.isDead) {
this.mc.thePlayer.closeScreen();
}

View File

@ -32,6 +32,12 @@ public class GuiGameOver extends GuiScreen {
}
@Override
public void updateScreen() {
super.updateScreen();
this.mc.setIngameNotInFocus();
}
public void drawScreen(int var1, int var2, float var3) {
this.drawGradientRect(0, 0, this.width, this.height, 1615855616, -1602211792);
GL11.glPushMatrix();

View File

@ -2,15 +2,19 @@ package net.minecraft.src;
import org.lwjgl.input.Keyboard;
import net.PeytonPlayz585.profile.Profile;
public class GuiMultiplayer extends GuiScreen {
private GuiScreen parentScreen;
private GuiTextField field_22111_h;
private GuiTextField username;
public GuiMultiplayer(GuiScreen var1) {
this.parentScreen = var1;
}
public void updateScreen() {
this.username.updateCursorCounter();
this.field_22111_h.updateCursorCounter();
}
@ -21,10 +25,15 @@ public class GuiMultiplayer extends GuiScreen {
this.controlList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12, var1.translateKey("multiplayer.connect")));
this.controlList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + 12, var1.translateKey("gui.cancel")));
String var2 = this.mc.gameSettings.lastServer.replaceAll("_", ":");
((GuiButton)this.controlList.get(0)).enabled = var2.length() > 0;
this.field_22111_h = new GuiTextField(this, this.fontRenderer, this.width / 2 - 100, this.height / 4 - 10 + 50 + 18, 200, 20, var2);
this.field_22111_h.isFocused = true;
String var3 = Profile.getName();
this.username = new GuiTextField(this, this.fontRenderer, this.width / 2 - 100, this.height / 4 - 10 + 25 + 18, 200, 20, var3);
this.field_22111_h = new GuiTextField(this, this.fontRenderer, this.width / 2 - 100, this.height / 4 - 10 + 65 + 18, 200, 20, var2);
this.username.isFocused = true;
this.username.setMaxStringLength(16);
this.field_22111_h.isFocused = false;
this.field_22111_h.setMaxStringLength(128);
((GuiButton)this.controlList.get(0)).enabled = this.field_22111_h.getText().length() > 0 && this.username.getText().length() > 0;
}
public void onGuiClosed() {
@ -37,28 +46,13 @@ public class GuiMultiplayer extends GuiScreen {
this.mc.displayGuiScreen(this.parentScreen);
} else if(var1.id == 0) {
String var2 = this.field_22111_h.getText().trim();
String username1 = this.username.getText().trim();
this.mc.gameSettings.lastServer = var2.replaceAll(":", "_");
Profile.setName(username1);
Profile.save();
this.mc.gameSettings.saveOptions();
String[] var3 = var2.split(":");
if(var2.startsWith("[")) {
int var4 = var2.indexOf("]");
if(var4 > 0) {
String var5 = var2.substring(1, var4);
String var6 = var2.substring(var4 + 1).trim();
if(var6.startsWith(":") && var6.length() > 0) {
var6 = var6.substring(1);
var3 = new String[]{var5, var6};
} else {
var3 = new String[]{var5};
}
}
}
if(var3.length > 2) {
var3 = new String[]{var2};
}
this.mc.displayGuiScreen(new GuiConnecting(this.mc, var3[0], var3.length > 1 ? this.parseIntWithDefault(var3[1], 25565) : 25565));
this.mc.displayGuiScreen(new GuiConnecting(this.mc, var2));
}
}
@ -74,26 +68,31 @@ public class GuiMultiplayer extends GuiScreen {
protected void keyTyped(char var1, int var2) {
this.field_22111_h.textboxKeyTyped(var1, var2);
if(var1 == 13) {
this.actionPerformed((GuiButton)this.controlList.get(0));
}
this.username.textboxKeyTyped(var1, var2);
((GuiButton)this.controlList.get(0)).enabled = this.field_22111_h.getText().length() > 0;
((GuiButton)this.controlList.get(0)).enabled = this.field_22111_h.getText().length() > 0 && this.username.getText().length() > 0;
}
protected void mouseClicked(int var1, int var2, int var3) {
super.mouseClicked(var1, var2, var3);
this.field_22111_h.mouseClicked(var1, var2, var3);
this.username.mouseClicked(var1, var2, var3);
}
public void drawScreen(int var1, int var2, float var3) {
StringTranslate var4 = StringTranslate.getInstance();
this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, var4.translateKey("multiplayer.title"), this.width / 2, this.height / 4 - 60 + 20, 16777215);
this.drawString(this.fontRenderer, var4.translateKey("multiplayer.info1"), this.width / 2 - 140, this.height / 4 - 60 + 60 + 0, 10526880);
this.drawString(this.fontRenderer, var4.translateKey("multiplayer.info2"), this.width / 2 - 140, this.height / 4 - 60 + 60 + 9, 10526880);
this.drawString(this.fontRenderer, var4.translateKey("multiplayer.ipinfo"), this.width / 2 - 140, this.height / 4 - 60 + 60 + 36, 10526880);
this.drawString(this.fontRenderer, var4.translateKey("multiplayer.info1"), this.width / 2 - 140, this.height / 4 - 60 + 50 + 0, 10526880);
this.drawString(this.fontRenderer, var4.translateKey("multiplayer.info2"), this.width / 2 - 140, this.height / 4 - 60 + 50 + 9, 10526880);
this.drawString(this.fontRenderer, var4.translateKey("Username:"), this.width / 2 - 100, this.height / 4 - 100 + 85 + 36, 10526880);
this.drawString(this.fontRenderer, var4.translateKey("Server IP:"), this.width / 2 - 100, this.height / 4 - 60 + 85 + 36, 10526880);
this.field_22111_h.drawTextBox();
this.username.drawTextBox();
super.drawScreen(var1, var2, var3);
}
private boolean containsOnlyAZ09(String input) {
return input.matches("[a-z0-9]+") || input.matches("[A-Z0-9]+") || input.equals(" ");
}
}

View File

@ -135,6 +135,10 @@ public class NBTTagCompound extends NBTBase {
return this.getByte(var1) != 0;
}
public boolean hasNoTags() {
return this.tagMap.isEmpty();
}
public String toString() {
return "" + this.tagMap.size() + " entries";
}

View File

@ -7,6 +7,8 @@ import java.io.IOException;
//import java.net.UnknownHostException;
import java.util.List;
import net.PeytonPlayz585.opengl.GL11;
import net.PeytonPlayz585.socket.Socket;
import net.minecraft.client.Minecraft;
public class NetClientHandler extends NetHandler {
@ -19,14 +21,32 @@ public class NetClientHandler extends NetHandler {
public MapStorage field_28118_b = new MapStorage((ISaveHandler)null);
Random rand = new Random();
public NetClientHandler(Minecraft var1, String var2, int var3) throws IOException {
public NetClientHandler(Minecraft var1, String var2) throws IOException {
this.mc = var1;
//Socket var4 = new Socket(InetAddress.getByName(var2), var3);
//this.netManager = new NetworkManager(var4, "Client", this);
String uri = null;
if(var2.startsWith("ws://")) {
uri = var2.substring(5);
}else if(var2.startsWith("wss://")){
uri = var2.substring(6);
}else if(!var2.contains("://")){
uri = var2;
if(GL11.isSSLPage()) {
var2 = "wss://" + var2;
} else {
var2 = "ws://" + var2;
}
}else {
throw new IOException("Invalid URI Protocol!");
}
Socket var4 = new Socket(var2);
this.netManager = new NetworkManager(var4, "Client", this);
}
public void processReadPackets() {
if(!this.disconnected) {
this.netManager.readPacket();
this.netManager.processReadPackets();
}
@ -380,6 +400,10 @@ public class NetClientHandler extends NetHandler {
this.addToSendQueue(new Packet1Login(this.mc.session.username, 14));
}
public void handleHandshake() {
this.addToSendQueue(new Packet1Login(this.mc.session.username, 14));
}
public void disconnect() {
this.disconnected = true;
this.netManager.wakeThreads();

View File

@ -1,33 +1,32 @@
package net.minecraft.src;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
//import java.net.Socket;
//import java.net.SocketAddress;
//import java.net.SocketException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import net.PeytonPlayz585.socket.ByteBufferDirectInputStream;
import net.PeytonPlayz585.socket.Socket;
import net.PeytonPlayz585.socket.SocketException;
public class NetworkManager {
public static final Object threadSyncObject = new Object();
public static int numReadThreads;
public static int numWriteThreads;
private Object sendQueueLock = new Object();
//private Socket networkSocket;
//private final SocketAddress remoteSocketAddress;
private DataInputStream socketInputStream;
private DataOutputStream socketOutputStream;
private Socket networkSocket;
private boolean isRunning = true;
private List readPackets = Collections.synchronizedList(new ArrayList());
private List dataPackets = Collections.synchronizedList(new ArrayList());
private List chunkDataPackets = Collections.synchronizedList(new ArrayList());
private NetHandler netHandler;
private boolean isServerTerminating = false;
private Thread writeThread;
private Thread readThread;
private boolean isTerminating = false;
private String terminationReason = "";
private Object[] field_20101_t;
@ -38,25 +37,10 @@ public class NetworkManager {
public int chunkDataSendCounter = 0;
private int field_20100_w = 50;
// public NetworkManager(Socket var1, String var2, NetHandler var3) throws IOException {
// this.networkSocket = var1;
// this.remoteSocketAddress = var1.getRemoteSocketAddress();
// this.netHandler = var3;
//
// try {
// var1.setSoTimeout(30000);
// var1.setTrafficClass(24);
// } catch (SocketException var5) {
// System.err.println(var5.getMessage());
// }
//
// this.socketInputStream = new DataInputStream(var1.getInputStream());
// this.socketOutputStream = new DataOutputStream(new BufferedOutputStream(var1.getOutputStream(), 5120));
// this.readThread = new NetworkReaderThread(this, var2 + " read thread");
// this.writeThread = new NetworkWriterThread(this, var2 + " write thread");
// this.readThread.start();
// this.writeThread.start();
// }
public NetworkManager(Socket var1, String var2, NetHandler var3) throws IOException {
this.networkSocket = var1;
this.netHandler = var3;
}
public void addToSendQueue(Packet var1) {
if(!this.isServerTerminating) {
@ -68,6 +52,7 @@ public class NetworkManager {
} else {
this.dataPackets.add(var1);
}
sendPacket();
}
}
@ -88,7 +73,14 @@ public class NetworkManager {
this.sendQueueByteLength -= var2.getPacketSize() + 1;
}
Packet.writePacket(var2, this.socketOutputStream);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream socketOutputStream = new DataOutputStream(baos);
Packet.writePacket(var2, socketOutputStream);
baos.flush();
socketOutputStream.flush();
this.networkSocket.write(baos.toByteArray());
baos.flush();
socketOutputStream.flush();
var10000 = field_28144_e;
var10001 = var2.getPacketId();
var10000[var10001] += var2.getPacketSize() + 1;
@ -102,7 +94,14 @@ public class NetworkManager {
this.sendQueueByteLength -= var2.getPacketSize() + 1;
}
Packet.writePacket(var2, this.socketOutputStream);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream socketOutputStream = new DataOutputStream(baos);
Packet.writePacket(var2, socketOutputStream);
baos.flush();
socketOutputStream.flush();
this.networkSocket.write(baos.toByteArray());
baos.flush();
socketOutputStream.flush();
var10000 = field_28144_e;
var10001 = var2.getPacketId();
var10000[var10001] += var2.getPacketSize() + 1;
@ -121,15 +120,42 @@ public class NetworkManager {
}
public void wakeThreads() {
this.readThread.interrupt();
this.writeThread.interrupt();
// Do nothing
}
private boolean readPacket() {
boolean var1 = false;
private ByteBuffer oldChunkBuffer = null;
private LinkedList<ByteBuffer> readChunks = new LinkedList();
public boolean readPacket() {
boolean var1 = false;
readChunks.clear();
if(oldChunkBuffer != null) {
readChunks.add(oldChunkBuffer);
}
byte[] packet;
while((packet = this.networkSocket.read()) != null) {
readChunks.add(ByteBuffer.wrap(packet));
}
if(!readChunks.isEmpty()) {
int cap = 0;
for(ByteBuffer b : readChunks) {
cap += b.limit();
}
ByteBuffer stream = ByteBuffer.allocate(cap);
for(ByteBuffer b : readChunks) {
stream.put(b);
}
stream.flip();
DataInputStream packetStream = new DataInputStream(new ByteBufferDirectInputStream(stream));
while(stream.hasRemaining()) {
stream.mark();
try {
Packet var2 = Packet.readPacket(this.socketInputStream, this.netHandler.isServerHandler());
Packet var2 = Packet.readPacket(packetStream, this.netHandler.isServerHandler());
if(var2 != null) {
int[] var10000 = field_28145_d;
int var10001 = var2.getPacketId();
@ -139,15 +165,24 @@ public class NetworkManager {
} else {
this.networkShutdown("disconnect.endOfStream", new Object[0]);
}
} catch(EOFException e) {
stream.reset();
break;
} catch(IOException e) {
continue;
} catch(Throwable t) {
t.printStackTrace();
}
}
if(stream.hasRemaining()) {
oldChunkBuffer = stream.slice();
}else {
oldChunkBuffer = null;
}
}
return var1;
} catch (Exception var3) {
if(!this.isTerminating) {
this.onNetworkError(var3);
}
return false;
}
}
private void onNetworkError(Exception var1) {
@ -160,24 +195,11 @@ public class NetworkManager {
this.isTerminating = true;
this.terminationReason = var1;
this.field_20101_t = var2;
//(new NetworkMasterThread(this)).start();
this.isRunning = false;
try {
this.socketInputStream.close();
this.socketInputStream = null;
} catch (Throwable var6) {
}
try {
this.socketOutputStream.close();
this.socketOutputStream = null;
} catch (Throwable var5) {
}
try {
//this.networkSocket.close();
//this.networkSocket = null;
this.networkSocket.close();
this.networkSocket = null;
} catch (Throwable var4) {
}
@ -209,23 +231,22 @@ public class NetworkManager {
this.netHandler.handleErrorMessage(this.terminationReason, this.field_20101_t);
}
if(!this.networkSocket.socketOpen()) {
onNetworkError(new SocketException(new String("Connection reset")));
}
}
public void func_28142_c() {
this.wakeThreads();
this.isServerTerminating = true;
this.readThread.interrupt();
//(new ThreadCloseConnection(this)).start();
(new ThreadCloseConnection(this)).start();
}
static boolean isRunning(NetworkManager var0) {
return var0.isRunning;
}
static boolean isServerTerminating(NetworkManager var0) {
return var0.isServerTerminating;
}
static boolean readNetworkPacket(NetworkManager var0) {
return var0.readPacket();
}
@ -234,23 +255,7 @@ public class NetworkManager {
return var0.sendPacket();
}
static DataOutputStream func_28140_f(NetworkManager var0) {
return var0.socketOutputStream;
}
static boolean func_28138_e(NetworkManager var0) {
return var0.isTerminating;
}
static void func_30005_a(NetworkManager var0, Exception var1) {
var0.onNetworkError(var1);
}
static Thread getReadThread(NetworkManager var0) {
return var0.readThread;
}
static Thread getWriteThread(NetworkManager var0) {
return var0.writeThread;
}
}

View File

@ -53,12 +53,13 @@ public abstract class Packet {
return ((Integer)packetClassToIdMap.get(this.getClass())).intValue();
}
//Ignore EOFExceptions, it will be handled in NetworkManager
public static Packet readPacket(DataInputStream var0, boolean var1) throws IOException {
boolean var2 = false;
Packet var3 = null;
int var6;
try {
var6 = var0.read();
if(var6 == -1) {
return null;
@ -74,10 +75,6 @@ public abstract class Packet {
}
var3.readPacketData(var0);
} catch (EOFException var5) {
System.out.println("Reached end of stream");
return null;
}
PacketCounter var4 = (PacketCounter)packetStats.get(Integer.valueOf(var6));
if(var4 == null) {

View File

@ -956,7 +956,7 @@ public class RenderGlobal implements IWorldAccess {
var8 = this.worldObj.getBlockId(var2.blockX, var2.blockY, var2.blockZ);
Block var9 = var8 > 0 ? Block.blocksList[var8] : null;
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glPolygonOffset(3.0F, 3.0F);
GL11.glPolygonOffset(-3.0F, -3.0F);
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
double var10 = var1.lastTickPosX + (var1.posX - var1.lastTickPosX) * (double)var5;
double var12 = var1.lastTickPosY + (var1.posY - var1.lastTickPosY) * (double)var5;

View File

@ -103,7 +103,11 @@ public class SoundManager {
double var4 = var1.prevPosX + (var1.posX - var1.prevPosX) * (double)var2;
double var6 = var1.prevPosY + (var1.posY - var1.prevPosY) * (double)var2;
double var8 = var1.prevPosZ + (var1.posZ - var1.prevPosZ) * (double)var2;
try {
GL11.setListenerPos((float)var4, (float)var6, (float)var8, (float)var1.motionX, (float)var1.motionY, (float)var1.motionZ, (float)var9, (float)var3);
} catch(Exception e) {
// ???
}
}
}
}

View File

@ -0,0 +1,21 @@
package net.minecraft.src;
class ThreadCloseConnection extends Thread {
final NetworkManager field_28109_a;
ThreadCloseConnection(NetworkManager var1) {
this.field_28109_a = var1;
}
public void run() {
try {
Thread.sleep(2000L);
if(NetworkManager.isRunning(this.field_28109_a)) {
this.field_28109_a.networkShutdown("disconnect.closed", new Object[0]);
}
} catch (Exception var2) {
var2.printStackTrace();
}
}
}

View File

@ -0,0 +1,34 @@
package net.minecraft.src;
import net.minecraft.client.Minecraft;
class ThreadConnectToServer {
final Minecraft mc;
final String hostName;
final GuiConnecting connectingGui;
ThreadConnectToServer(GuiConnecting var1, Minecraft var2, String var3) {
this.connectingGui = var1;
this.mc = var2;
this.hostName = var3;
}
public void start() {
try {
GuiConnecting.setNetClientHandler(this.connectingGui, new NetClientHandler(this.mc, this.hostName));
if(GuiConnecting.isCancelled(this.connectingGui)) {
return;
}
GuiConnecting.getNetClientHandler(this.connectingGui).handleHandshake();
} catch (Exception var4) {
if(GuiConnecting.isCancelled(this.connectingGui)) {
return;
}
var4.printStackTrace();
this.mc.displayGuiScreen(new GuiConnectFailed("connect.failed", "disconnect.genericReason", new Object[]{var4.toString()}));
}
}
}

View File

@ -1,24 +0,0 @@
package net.minecraft.src;
import net.minecraft.client.Minecraft;
public class ThreadSleepForever extends Thread {
final Minecraft mc;
public ThreadSleepForever(Minecraft var1, String var2) {
super(var2);
this.mc = var1;
this.setDaemon(true);
this.start();
}
public void run() {
while(this.mc.running) {
try {
Thread.sleep(2147483647L);
} catch (InterruptedException var2) {
}
}
}
}