Fix mp bugs and add multiplayer menu
This commit is contained in:
parent
dde3009a62
commit
1d8402c58b
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
/.gradle/
|
||||
/desktopRuntime/filesystem/
|
||||
/desktopRuntime/eclipseProject/bin/
|
||||
/desktopRuntime/eclipseProject/bin/
|
||||
/build/
|
@ -90,14 +90,14 @@ public final class Minecraft implements Runnable {
|
||||
public MovingObjectPosition selected;
|
||||
public GameSettings settings;
|
||||
String server;
|
||||
int port;
|
||||
volatile boolean running;
|
||||
public volatile boolean running;
|
||||
public String debug;
|
||||
public boolean hasMouse;
|
||||
private int lastClick;
|
||||
public boolean raining;
|
||||
private boolean enableGLErrorChecking = false;
|
||||
private static Minecraft mc;
|
||||
public boolean mpRestart = false;
|
||||
|
||||
|
||||
public Minecraft(int var3, int var4, boolean var5) {
|
||||
@ -109,8 +109,6 @@ public final class Minecraft implements Runnable {
|
||||
this.online = false;
|
||||
new HumanoidModel(0.0F);
|
||||
this.selected = null;
|
||||
this.server = null;
|
||||
this.port = 0;
|
||||
this.running = false;
|
||||
this.debug = "";
|
||||
this.hasMouse = false;
|
||||
@ -283,7 +281,7 @@ public final class Minecraft implements Runnable {
|
||||
this.hud = new HUDScreen(this, this.width, this.height);
|
||||
if(this.server != null && this.session != null) {
|
||||
this.gamemode = new CreativeGameMode(this);
|
||||
this.networkManager = new NetworkManager(this, this.server, this.port, this.session.username, this.session.mppass);
|
||||
this.networkManager = new NetworkManager(this, this.server, this.session.username, this.session.mppass);
|
||||
}
|
||||
|
||||
long var13 = EagRuntime.steadyTimeMillis();
|
||||
@ -1209,7 +1207,7 @@ public final class Minecraft implements Runnable {
|
||||
NetworkManager var20 = this.networkManager;
|
||||
if(this.networkManager.successful) {
|
||||
NetworkHandler var18 = var20.netHandler;
|
||||
if(var20.netHandler.connected) {
|
||||
if(this.networkManager.isConnected()) {
|
||||
try {
|
||||
NetworkHandler var22 = var20.netHandler;
|
||||
var20.netHandler.read(var22.in);
|
||||
@ -1406,7 +1404,7 @@ public final class Minecraft implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
if(!var22.connected) {
|
||||
if(!this.networkManager.isConnected()) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1440,7 +1438,7 @@ public final class Minecraft implements Runnable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(this.currentScreen == null && this.player != null && this.player.health <= 0) {
|
||||
this.setCurrentScreen((GuiScreen)null);
|
||||
}
|
||||
@ -1759,6 +1757,13 @@ public final class Minecraft implements Runnable {
|
||||
System.gc();
|
||||
}
|
||||
|
||||
public void startNetworkManager(String serverIP, SessionData session) {
|
||||
this.gamemode = new CreativeGameMode(this);
|
||||
this.networkManager = new NetworkManager(this, serverIP, session.username, session.mppass);
|
||||
this.server = serverIP;
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public static Minecraft getMinecraft() {
|
||||
return mc;
|
||||
}
|
||||
|
119
src/game/java/com/mojang/minecraft/gui/MultiplayerMenu.java
Normal file
119
src/game/java/com/mojang/minecraft/gui/MultiplayerMenu.java
Normal file
@ -0,0 +1,119 @@
|
||||
package com.mojang.minecraft.gui;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.mojang.minecraft.SessionData;
|
||||
|
||||
import net.lax1dude.eaglercraft.Keyboard;
|
||||
|
||||
public class MultiplayerMenu extends GuiScreen {
|
||||
|
||||
boolean textBox1Active = false;
|
||||
boolean textBox2Active = false;
|
||||
private int counter = 0;
|
||||
String server = "";
|
||||
String username = "";
|
||||
Button connect;
|
||||
|
||||
public final void onOpen() {
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
this.buttons.clear();
|
||||
this.buttons.add(connect = new Button(0, this.width / 2 - 100, this.height / 4 + 96 + 12, "Connect"));
|
||||
this.buttons.add(new Button(1, this.width / 2 - 100, this.height / 4 + 120 + 12, "Cancel"));
|
||||
connect.active = false;
|
||||
}
|
||||
|
||||
public final void tick() {
|
||||
++this.counter;
|
||||
}
|
||||
|
||||
protected final void onButtonClick(Button var1) {
|
||||
if(var1.id == 0 && var1.active) {
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
this.minecraft.setCurrentScreen(new PauseScreen());
|
||||
this.minecraft.setLevel(null);
|
||||
this.minecraft.startNetworkManager(this.server, new SessionData(username, "mcpass"));
|
||||
} else if(var1.id == 1) {
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
minecraft.setCurrentScreen(new PauseScreen());
|
||||
}
|
||||
}
|
||||
|
||||
protected void onMouseClick(int var1, int var2, int var3) {
|
||||
if(var3 == 0) {
|
||||
if(var1 >= this.width / 2 - 100 && var1 < (this.width / 2 - 100) + 200 && var2 >= this.height / 4 - 10 + 50 + 18 && var2 < (this.height / 4 - 10 + 50 + 18) + 20) {
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
textBox1Active = true;
|
||||
textBox2Active = false;
|
||||
} else if(var1 >= this.width / 2 - 100 && var1 < (this.width / 2 - 100) + 200 && var2 >= this.height / 4 - 10 + 50 - 20 && var2 < (this.height / 4 - 10 + 50 - 20) + 20) {
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
textBox2Active = true;
|
||||
textBox1Active = false;
|
||||
} else {
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
textBox1Active = false;
|
||||
textBox2Active = false;
|
||||
}
|
||||
}
|
||||
super.onMouseClick(var1, var2, var3);
|
||||
}
|
||||
|
||||
protected final void onKeyPress(char var1, int var2) {
|
||||
if(textBox1Active) {
|
||||
if(var2 == 14 && this.server.length() > 0) {
|
||||
this.server = this.server.substring(0, this.server.length() - 1);
|
||||
}
|
||||
if("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ,.:-_\'*!\\\"#%/()=+?[]{}<>@|$;".indexOf(var1) >= 0 && this.server.length() < 64) {
|
||||
this.server = this.server + var1;
|
||||
}
|
||||
if(server.length() > 0 && username.length() > 0) {
|
||||
connect.active = true;
|
||||
} else {
|
||||
connect.active = false;
|
||||
}
|
||||
} else if(textBox2Active) {
|
||||
if(var2 == 14 && this.username.length() > 0) {
|
||||
this.username = this.username.substring(0, this.username.length() - 1);
|
||||
}
|
||||
if("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ,.:-_\'*!\\\"#%/()=+?[]{}<>@|$;".indexOf(var1) >= 0 && this.username.length() < 64) {
|
||||
this.username = this.username + var1;
|
||||
}
|
||||
if(server.length() > 0 && username.length() > 0) {
|
||||
connect.active = true;
|
||||
} else {
|
||||
connect.active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void render(int var1, int var2) {
|
||||
//username
|
||||
drawBox((this.width / 2 - 100) - 1, (this.height / 4 - 10 + 50 - 20) - 1, (this.width / 2 - 100) + 200 + 1, (this.height / 4 - 10 + 50 - 20) + 20 + 1, -6250336);
|
||||
drawBox(this.width / 2 - 100, this.height / 4 - 10 + 50 - 20, (this.width / 2 - 100) + 200, (this.height / 4 - 10 + 50 - 20) + 20, -16777216);
|
||||
|
||||
drawString(this.fontRenderer, "Username:", this.width / 2 - 100, this.height / 4 - 10 + 50 - 30, 10526880);
|
||||
|
||||
//server IP
|
||||
drawBox((this.width / 2 - 100) - 1, (this.height / 4 - 10 + 50 + 18) - 1, (this.width / 2 - 100) + 200 + 1, (this.height / 4 - 10 + 50 + 18) + 20 + 1, -6250336);
|
||||
drawBox(this.width / 2 - 100, this.height / 4 - 10 + 50 + 18, (this.width / 2 - 100) + 200, (this.height / 4 - 10 + 50 + 18) + 20, -16777216);
|
||||
|
||||
drawString(this.fontRenderer, "Server address:", this.width / 2 - 100, this.height / 4 - 10 + 50 + 8, 10526880);
|
||||
if(textBox1Active) {
|
||||
boolean e = this.counter / 6 % 2 == 0;
|
||||
drawString(this.fontRenderer, server + (e ? "_" : ""), (this.width / 2 - 100) + 4, (this.height / 4 - 10 + 50 + 18) + (20 - 8) / 2, 14737632);
|
||||
} else {
|
||||
drawString(this.fontRenderer, server, (this.width / 2 - 100) + 4, (this.height / 4 - 10 + 50 + 18) + (20 - 8) / 2, 14737632);
|
||||
}
|
||||
if(textBox2Active) {
|
||||
boolean e = this.counter / 6 % 2 == 0;
|
||||
drawString(this.fontRenderer, username + (e ? "_" : ""), (this.width / 2 - 100) + 4, (this.height / 4 - 10 + 50 - 20) + (20 - 8) / 2, 14737632);
|
||||
} else {
|
||||
drawString(this.fontRenderer, username, (this.width / 2 - 100) + 4, (this.height / 4 - 10 + 50 - 20) + (20 - 8) / 2, 14737632);
|
||||
}
|
||||
|
||||
drawFadingBox(0, 0, this.width, this.height, 1610941696, -1607454624);
|
||||
drawCenteredString(this.fontRenderer, "Multiplayer Menu", this.width / 2, 40, 16777215);
|
||||
super.render(var1, var2);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package com.mojang.minecraft.gui;
|
||||
|
||||
import com.mojang.minecraft.SessionData;
|
||||
|
||||
import net.peyton.eagler.level.LevelUtils;
|
||||
|
||||
public final class PauseScreen extends GuiScreen {
|
||||
@ -8,16 +10,12 @@ public final class PauseScreen extends GuiScreen {
|
||||
this.buttons.clear();
|
||||
this.buttons.add(new Button(0, this.width / 2 - 100, this.height / 4, "Options..."));
|
||||
this.buttons.add(new Button(1, this.width / 2 - 100, this.height / 4 + 24, "Generate new level..."));
|
||||
this.buttons.add(new Button(2, this.width / 2 - 100, this.height / 4 + 48, "Save level.."));
|
||||
this.buttons.add(new Button(3, this.width / 2 - 100, this.height / 4 + 72, "Load level.."));
|
||||
this.buttons.add(new Button(3, this.width / 2 - 100, this.height / 4 + 48, "Multiplayer..."));
|
||||
this.buttons.add(new Button(4, this.width / 2 - 100, this.height / 4 + 120, "Back to game"));
|
||||
((Button)this.buttons.get(2)).active = false;
|
||||
((Button)this.buttons.get(3)).active = false;
|
||||
|
||||
if(this.minecraft.networkManager != null) {
|
||||
((Button)this.buttons.get(1)).active = false;
|
||||
((Button)this.buttons.get(2)).active = false;
|
||||
((Button)this.buttons.get(3)).active = false;
|
||||
}
|
||||
|
||||
LevelUtils.save();
|
||||
@ -31,6 +29,10 @@ public final class PauseScreen extends GuiScreen {
|
||||
if(var1.id == 1) {
|
||||
this.minecraft.setCurrentScreen(new GenerateLevelScreen(this));
|
||||
}
|
||||
|
||||
if(var1.id == 3) {
|
||||
this.minecraft.setCurrentScreen(new MultiplayerMenu());
|
||||
}
|
||||
|
||||
if(var1.id == 4) {
|
||||
LevelUtils.save();
|
||||
|
@ -3,6 +3,10 @@ package com.mojang.minecraft.net;
|
||||
import com.mojang.minecraft.Minecraft;
|
||||
import com.mojang.minecraft.gui.ErrorScreen;
|
||||
import com.mojang.net.NetworkHandler;
|
||||
|
||||
import net.lax1dude.eaglercraft.internal.EnumEaglerConnectionState;
|
||||
import net.lax1dude.eaglercraft.internal.PlatformNetworking;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -11,7 +15,7 @@ import java.util.List;
|
||||
|
||||
public class NetworkManager
|
||||
{
|
||||
public NetworkManager(Minecraft minecraft, String server, int port, String username, String key)
|
||||
public NetworkManager(Minecraft minecraft, String server, String username, String key)
|
||||
{
|
||||
minecraft.online = true;
|
||||
|
||||
@ -19,7 +23,7 @@ public class NetworkManager
|
||||
|
||||
players = new HashMap<Byte, NetworkPlayer>();
|
||||
|
||||
new ServerConnectThread(this, server, port, username, key, minecraft).start();
|
||||
new ServerConnectThread(this, server, username, key, minecraft).start();
|
||||
}
|
||||
|
||||
public ByteArrayOutputStream levelData;
|
||||
@ -30,7 +34,7 @@ public class NetworkManager
|
||||
|
||||
public boolean successful = false;
|
||||
public boolean levelLoaded = false;
|
||||
|
||||
|
||||
public HashMap<Byte, NetworkPlayer> players;
|
||||
|
||||
public void sendBlockChange(int x, int y, int z, int mode, int block)
|
||||
@ -51,7 +55,7 @@ public class NetworkManager
|
||||
|
||||
public boolean isConnected()
|
||||
{
|
||||
return netHandler != null && netHandler.connected;
|
||||
return netHandler != null && PlatformNetworking.playConnectionState() == EnumEaglerConnectionState.CONNECTED;
|
||||
}
|
||||
|
||||
public List getPlayers()
|
||||
|
@ -6,13 +6,12 @@ import com.mojang.net.NetworkHandler;
|
||||
|
||||
public class ServerConnectThread extends Thread
|
||||
{
|
||||
public ServerConnectThread(NetworkManager networkManager, String server, int port, String username, String key, Minecraft minecraft) {
|
||||
public ServerConnectThread(NetworkManager networkManager, String server, String username, String key, Minecraft minecraft) {
|
||||
super();
|
||||
|
||||
netManager = networkManager;
|
||||
|
||||
this.server = server;
|
||||
this.port = port;
|
||||
|
||||
this.username = username;
|
||||
this.key = key;
|
||||
@ -24,7 +23,7 @@ public class ServerConnectThread extends Thread
|
||||
public void run()
|
||||
{
|
||||
try {
|
||||
netManager.netHandler = new NetworkHandler(server, port);
|
||||
netManager.netHandler = new NetworkHandler(server);
|
||||
netManager.netHandler.netManager = netManager;
|
||||
|
||||
netManager.netHandler.send(PacketType.IDENTIFICATION, new Object[]{Byte.valueOf((byte)7), this.username, this.key, Integer.valueOf(0)});
|
||||
@ -42,7 +41,6 @@ public class ServerConnectThread extends Thread
|
||||
}
|
||||
|
||||
private String server;
|
||||
private int port;
|
||||
|
||||
private String username;
|
||||
private String key;
|
||||
|
@ -1,8 +1,10 @@
|
||||
package com.mojang.net;
|
||||
|
||||
import com.mojang.minecraft.Minecraft;
|
||||
import com.mojang.minecraft.net.NetworkManager;
|
||||
import com.mojang.minecraft.net.PacketType;
|
||||
|
||||
import net.lax1dude.eaglercraft.EagRuntime;
|
||||
import net.lax1dude.eaglercraft.internal.EnumEaglerConnectionState;
|
||||
import net.lax1dude.eaglercraft.internal.PlatformNetworking;
|
||||
|
||||
@ -12,19 +14,25 @@ import java.util.List;
|
||||
|
||||
public final class NetworkHandler {
|
||||
|
||||
public volatile boolean connected;
|
||||
public ByteBuffer in = ByteBuffer.allocate(1048576);
|
||||
public ByteBuffer out = ByteBuffer.allocate(1048576);
|
||||
public NetworkManager netManager;
|
||||
private byte[] stringBytes = new byte[64];
|
||||
|
||||
|
||||
public NetworkHandler(String server, int port) {
|
||||
String serveraddress = server.replace("wss://", "").replace("ws://", "").split(":")[0] + ":" + port;
|
||||
public NetworkHandler(String server) {
|
||||
if(server.contains("ws://")) {
|
||||
if(EagRuntime.requireSSL()) {
|
||||
server = server.replace("ws://", "wss://");
|
||||
}
|
||||
} else if(!server.contains("://")) {
|
||||
server = EagRuntime.requireSSL() ? "wss://" + server : "ws://" + server;
|
||||
}
|
||||
|
||||
this.in.clear();
|
||||
this.out.clear();
|
||||
|
||||
PlatformNetworking.startPlayConnection("ws://" + serveraddress);
|
||||
|
||||
PlatformNetworking.startPlayConnection(server);
|
||||
|
||||
boolean connected = false;
|
||||
boolean connectionFailed = false;
|
||||
@ -36,17 +44,33 @@ public final class NetworkHandler {
|
||||
connected = true;
|
||||
}
|
||||
}
|
||||
this.connected = connected;
|
||||
|
||||
if(connectionFailed && server.contains("ws://")) {
|
||||
server = server.replace("ws://", "wss://");
|
||||
}
|
||||
|
||||
connected = false;
|
||||
connectionFailed = false;
|
||||
PlatformNetworking.startPlayConnection(server);
|
||||
|
||||
while(!connected && !connectionFailed) {
|
||||
EnumEaglerConnectionState state = PlatformNetworking.playConnectionState();
|
||||
if(state == EnumEaglerConnectionState.FAILED) {
|
||||
connectionFailed = true;
|
||||
} else if(state == EnumEaglerConnectionState.CONNECTED) {
|
||||
connected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void close() {
|
||||
PlatformNetworking.playDisconnect();
|
||||
|
||||
this.connected = false;
|
||||
this.netManager.isConnected();
|
||||
}
|
||||
|
||||
public final void send(PacketType var1, Object ... var2) {
|
||||
if(this.connected) {
|
||||
if(this.netManager.isConnected()) {
|
||||
this.out.put(var1.opcode);
|
||||
|
||||
for(int var3 = 0; var3 < var2.length; ++var3) {
|
||||
@ -54,7 +78,7 @@ public final class NetworkHandler {
|
||||
Object var4 = var2[var3];
|
||||
Class<?> var5 = var10001;
|
||||
NetworkHandler var6 = this;
|
||||
if(this.connected) {
|
||||
if(this.netManager.isConnected()) {
|
||||
try {
|
||||
if(var5 == Long.TYPE) {
|
||||
var6.out.putLong(((Long)var4).longValue());
|
||||
@ -104,7 +128,7 @@ public final class NetworkHandler {
|
||||
}
|
||||
|
||||
public Object readObject(Class<?> var1) {
|
||||
if(!this.connected) {
|
||||
if(!this.netManager.isConnected()) {
|
||||
return null;
|
||||
} else {
|
||||
try {
|
||||
@ -139,7 +163,6 @@ public final class NetworkHandler {
|
||||
|
||||
public void read(ByteBuffer in2) {
|
||||
if(PlatformNetworking.playConnectionState() != EnumEaglerConnectionState.CONNECTED) {
|
||||
this.connected = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -147,14 +170,13 @@ public final class NetworkHandler {
|
||||
|
||||
if(packets != null) {
|
||||
for(byte[] bytes : packets) {
|
||||
in.put(bytes);
|
||||
in2.put(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void write(ByteBuffer out2) {
|
||||
if(PlatformNetworking.playConnectionState() != EnumEaglerConnectionState.CONNECTED) {
|
||||
this.connected = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user