Fix some more multiplayer stuff
This commit is contained in:
parent
68470f7efd
commit
fcd22e7304
|
@ -1,40 +1,49 @@
|
||||||
package net.PeytonPlayz585.network;
|
package net.PeytonPlayz585.network;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import net.PeytonPlayz585.opengl.GL11;
|
import net.PeytonPlayz585.opengl.GL11;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public class Socket {
|
public class Socket {
|
||||||
|
|
||||||
public Socket(String ip) throws IOException {
|
public Socket(String hostName, int port) throws IOException {
|
||||||
if(!GL11.EaglerAdapterImpl2.startConnection(ip)) {
|
if(!GL11.EaglerAdapterImpl2.startConnection(hostName + ":" + port)) {
|
||||||
throw new IOException("Failed to connect to '" + ip + "'!");
|
IOException e = new IOException("Connection failed: " + hostName + ":" + port);
|
||||||
|
e.printStackTrace();
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public Socket(String hostName) throws IOException {
|
||||||
if(!GL11.EaglerAdapterImpl2.connectionOpen()) {
|
if(!GL11.EaglerAdapterImpl2.startConnection(hostName)) {
|
||||||
return;
|
IOException e = new IOException("Connection failed: " + hostName);
|
||||||
|
e.printStackTrace();
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
GL11.EaglerAdapterImpl2.endConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean open() {
|
|
||||||
return GL11.EaglerAdapterImpl2.connectionOpen();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(byte[] data) {
|
public void write(byte[] data) {
|
||||||
if(open()) {
|
if(socketOpen()) {
|
||||||
GL11.EaglerAdapterImpl2.writePacket(data);
|
GL11.EaglerAdapterImpl2.writePacket(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] read() {
|
public byte[] read() {
|
||||||
if(open()) {
|
if(socketOpen()) {
|
||||||
return GL11.EaglerAdapterImpl2.readPacket();
|
return GL11.EaglerAdapterImpl2.readPacket();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
if(socketOpen()) {
|
||||||
|
GL11.EaglerAdapterImpl2.endConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean socketOpen() {
|
||||||
|
return GL11.EaglerAdapterImpl2.connectionOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -293,7 +293,7 @@ public class Minecraft implements Runnable {
|
||||||
this.sndManager.func_338_a(this.thePlayer, this.timer.renderPartialTicks);
|
this.sndManager.func_338_a(this.thePlayer, this.timer.renderPartialTicks);
|
||||||
this.checkGLError("Pre render");
|
this.checkGLError("Pre render");
|
||||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||||
if(this.theWorld != null && !this.theWorld.multiplayerWorld) {
|
if(this.theWorld != null && !this.theWorld.multiplayerWorld) {
|
||||||
while(this.theWorld.func_6465_g()) {
|
while(this.theWorld.func_6465_g()) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,7 +287,7 @@ public class EntityRenderer {
|
||||||
this.func_917_f(var1);
|
this.func_917_f(var1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.mc.gameSettings.thirdPersonView && !(Keyboard.getEventKey() == 33 && Keyboard.isKeyDown(2))) {
|
if(!this.mc.gameSettings.thirdPersonView && !Keyboard.isFunctionKeyDown(this.mc.gameSettings.keyBindFunction.keyCode, 2)) {
|
||||||
this.field_1395_a.renderItemInFirstPerson(var1);
|
this.field_1395_a.renderItemInFirstPerson(var1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,33 @@ public class GuiConnecting extends GuiScreen {
|
||||||
private NetClientHandler clientHandler;
|
private NetClientHandler clientHandler;
|
||||||
private boolean cancelled = false;
|
private boolean cancelled = false;
|
||||||
|
|
||||||
|
private Minecraft minecraft;
|
||||||
|
private String uri;
|
||||||
|
private int timer = 0;
|
||||||
|
|
||||||
public GuiConnecting(Minecraft var1, String var2) {
|
public GuiConnecting(Minecraft var1, String var2) {
|
||||||
|
System.out.println("Connecting to " + var2);
|
||||||
var1.func_6261_a((World)null);
|
var1.func_6261_a((World)null);
|
||||||
(new ThreadConnectToServer(this, var1, var2)).start();
|
|
||||||
|
this.minecraft = var1;
|
||||||
|
this.uri = var2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateScreen() {
|
public void updateScreen() {
|
||||||
|
/*
|
||||||
|
* Connects AFTER drawing screen, this fixes two issues
|
||||||
|
* 1. A blank background while the connection is being initialized
|
||||||
|
* 2. The connection failed screen not showing due to the connecting screen being rendered AFTER the connection failed
|
||||||
|
*/
|
||||||
|
if (timer > 2 && this.clientHandler == null) {
|
||||||
|
(new ThreadConnectToServer(this, this.minecraft, this.uri)).start();
|
||||||
|
}
|
||||||
if(this.clientHandler != null) {
|
if(this.clientHandler != null) {
|
||||||
this.clientHandler.processReadPackets();
|
this.clientHandler.processReadPackets();
|
||||||
}
|
}
|
||||||
|
if(timer >= 1) {
|
||||||
|
++timer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void keyTyped(char var1, int var2) {
|
protected void keyTyped(char var1, int var2) {
|
||||||
|
@ -39,6 +56,10 @@ public class GuiConnecting extends GuiScreen {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawScreen(int var1, int var2, float var3) {
|
public void drawScreen(int var1, int var2, float var3) {
|
||||||
|
if(timer == 0) {
|
||||||
|
timer = 1;
|
||||||
|
}
|
||||||
|
|
||||||
this.drawDefaultBackground();
|
this.drawDefaultBackground();
|
||||||
if(this.clientHandler == null) {
|
if(this.clientHandler == null) {
|
||||||
this.drawCenteredString(this.fontRenderer, "Connecting to the server...", this.width / 2, this.height / 2 - 50, 16777215);
|
this.drawCenteredString(this.fontRenderer, "Connecting to the server...", this.width / 2, this.height / 2 - 50, 16777215);
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package net.minecraft.src;
|
package net.minecraft.src;
|
||||||
|
|
||||||
public class MathHelper {
|
public class MathHelper {
|
||||||
private static float[] SIN_TABLE = new float[65536];
|
private static float[] SIN_TABLE = new float[4096];
|
||||||
|
|
||||||
public static final float sin(float var0) {
|
public static final float sin(float var0) {
|
||||||
return SIN_TABLE[(int)(var0 * 10430.378F) & '\uffff'];
|
return SIN_TABLE[(int)(var0 * 651.8986F) & 4095];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final float cos(float var0) {
|
public static final float cos(float var0) {
|
||||||
return SIN_TABLE[(int)(var0 * 10430.378F + 16384.0F) & '\uffff'];
|
return SIN_TABLE[(int)((var0 + ((float)Math.PI / 2F)) * 651.8986F) & 4095];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final float sqrt_float(float var0) {
|
public static final float sqrt_float(float var0) {
|
||||||
|
@ -50,8 +50,12 @@ public class MathHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for(int var0 = 0; var0 < 65536; ++var0) {
|
for (int j = 0; j < 4096; ++j) {
|
||||||
SIN_TABLE[var0] = (float)Math.sin((double)var0 * Math.PI * 2.0D / 65536.0D);
|
SIN_TABLE[j] = (float)Math.sin((double)(((float)j + 0.5F) / 4096.0F * ((float)Math.PI * 2F)));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int l = 0; l < 360; l += 90) {
|
||||||
|
SIN_TABLE[(int)((float)l * 11.377778F) & 4095] = (float)Math.sin((double)((float)l * 0.017453292F));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package net.minecraft.src;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import net.PeytonPlayz585.EaglercraftRandom;
|
import net.PeytonPlayz585.EaglercraftRandom;
|
||||||
|
import net.PeytonPlayz585.network.Socket;
|
||||||
|
import net.PeytonPlayz585.opengl.GL11;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
|
||||||
public class NetClientHandler extends NetHandler {
|
public class NetClientHandler extends NetHandler {
|
||||||
|
@ -16,13 +18,31 @@ public class NetClientHandler extends NetHandler {
|
||||||
|
|
||||||
public NetClientHandler(Minecraft var1, String var2) throws IOException, UnknownHostException {
|
public NetClientHandler(Minecraft var1, String var2) throws IOException, UnknownHostException {
|
||||||
this.mc = var1;
|
this.mc = var1;
|
||||||
this.netManager = new NetworkManager(var2, 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.EaglerAdapterImpl2.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() {
|
public void processReadPackets() {
|
||||||
if(!this.disconnected) {
|
if(!this.disconnected) {
|
||||||
this.netManager.readPacket();
|
this.netManager.readPacket();
|
||||||
this.netManager.processReadPackets();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,6 +336,10 @@ public class NetClientHandler extends NetHandler {
|
||||||
this.addToSendQueue(new Packet1Login(this.mc.session.username, "Password", 6));
|
this.addToSendQueue(new Packet1Login(this.mc.session.username, "Password", 6));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handleHandshake() {
|
||||||
|
this.addToSendQueue(new Packet1Login(this.mc.session.username, "Password", 6));
|
||||||
|
}
|
||||||
|
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
this.disconnected = true;
|
this.disconnected = true;
|
||||||
this.netManager.networkShutdown("Closed");
|
this.netManager.networkShutdown("Closed");
|
||||||
|
|
|
@ -29,23 +29,9 @@ public class NetworkManager {
|
||||||
private int sendQueueByteLength = 0;
|
private int sendQueueByteLength = 0;
|
||||||
private int chunkDataSendCounter = 0;
|
private int chunkDataSendCounter = 0;
|
||||||
|
|
||||||
public NetworkManager(String var4, NetHandler var3) throws IOException {
|
public NetworkManager(Socket var1, String var2, NetHandler var3) throws IOException {
|
||||||
|
|
||||||
this.netHandler = var3;
|
this.netHandler = var3;
|
||||||
String uri = null;
|
this.field_12258_e = var1;
|
||||||
System.out.println(uri);
|
|
||||||
if(var4.startsWith("ws://")) {
|
|
||||||
uri = var4.substring(5);
|
|
||||||
}else if(var4.startsWith("wss://")){
|
|
||||||
uri = var4.substring(6);
|
|
||||||
}else if(!var4.contains("://")){
|
|
||||||
uri = var4;
|
|
||||||
var4 = "ws://" + var4;
|
|
||||||
}else {
|
|
||||||
throw new IOException("Invalid URI Protocol!");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.field_12258_e = new Socket(var4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addToSendQueue(Packet var1) {
|
public void addToSendQueue(Packet var1) {
|
||||||
|
@ -58,6 +44,7 @@ public class NetworkManager {
|
||||||
} else {
|
} else {
|
||||||
this.dataPackets.add(var1);
|
this.dataPackets.add(var1);
|
||||||
}
|
}
|
||||||
|
sendPacket();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,7 +116,7 @@ public class NetworkManager {
|
||||||
readChunks.add(oldChunkBuffer);
|
readChunks.add(oldChunkBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.field_12258_e.open()) {
|
if(this.field_12258_e.socketOpen()) {
|
||||||
byte[] packet;
|
byte[] packet;
|
||||||
while((packet = this.field_12258_e.read()) != null) {
|
while((packet = this.field_12258_e.read()) != null) {
|
||||||
readChunks.add(ByteBuffer.wrap(packet));
|
readChunks.add(ByteBuffer.wrap(packet));
|
||||||
|
@ -159,13 +146,12 @@ public class NetworkManager {
|
||||||
} else {
|
} else {
|
||||||
this.networkShutdown("End of stream");
|
this.networkShutdown("End of stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processReadPackets();
|
||||||
} catch(EOFException e) {
|
} catch(EOFException e) {
|
||||||
stream.reset();
|
stream.reset();
|
||||||
break;
|
break;
|
||||||
} catch(Exception e) {
|
|
||||||
continue;
|
|
||||||
} catch(Throwable t) {
|
} catch(Throwable t) {
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,14 +20,14 @@ class ThreadConnectToServer {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiConnecting.getNetClientHandler(this.connectingGui).addToSendQueue(new Packet2Handshake(this.mc.session.username));
|
GuiConnecting.getNetClientHandler(this.connectingGui).handleHandshake();
|
||||||
} catch (Exception var4) {
|
} catch (Throwable var4) {
|
||||||
if(GuiConnecting.isCancelled(this.connectingGui)) {
|
if(GuiConnecting.isCancelled(this.connectingGui)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var4.printStackTrace();
|
|
||||||
this.mc.displayGuiScreen(new GuiConnectFailed("Failed to connect to the server", var4.toString()));
|
this.mc.displayGuiScreen(new GuiConnectFailed("Failed to connect to the server", var4.toString()));
|
||||||
|
var4.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1587,10 +1587,10 @@ public class World implements IBlockAccess {
|
||||||
} else {
|
} else {
|
||||||
++this.field_4204_J;
|
++this.field_4204_J;
|
||||||
|
|
||||||
|
boolean var2;
|
||||||
try {
|
try {
|
||||||
int var1 = 5000;
|
int var1 = 5000;
|
||||||
|
|
||||||
boolean var2;
|
|
||||||
while(this.field_1051_z.size() > 0) {
|
while(this.field_1051_z.size() > 0) {
|
||||||
--var1;
|
--var1;
|
||||||
if(var1 <= 0) {
|
if(var1 <= 0) {
|
||||||
|
@ -1602,10 +1602,11 @@ public class World implements IBlockAccess {
|
||||||
}
|
}
|
||||||
|
|
||||||
var2 = false;
|
var2 = false;
|
||||||
return var2;
|
|
||||||
} finally {
|
} finally {
|
||||||
--this.field_4204_J;
|
--this.field_4204_J;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return var2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user