Merge forward changes

This commit is contained in:
zontreck 2023-12-06 09:56:05 -07:00
parent 4680fffbb8
commit 121075336f
9 changed files with 118 additions and 61 deletions

View file

@ -42,6 +42,7 @@ dependencies {
provided ("org.lwjgl.lwjgl:lwjgl:2.9.3")
provided ("org.lwjgl.lwjgl:lwjgl_util:2.9.3")
provided ("org.lwjgl.lwjgl:lwjgl-platform:2.9.3")
provided ("dev.zontreck:LibAC:1.4.15")
}
// Apply a specific Java toolchain to ease working on different environments.

View file

@ -275,13 +275,13 @@ public final class SocketConnection {
}
public final void sendPacket(Packet var1, Object... var2) {
public final void sendPacket(Packet packetType, Object... args) {
if(this.connected) {
this.writeBuffer.put(var1.id);
this.writeBuffer.put(packetType.id);
for(int var3 = 0; var3 < var2.length; ++var3) {
Class var10001 = var1.fields[var3];
Object var6 = var2[var3];
for(int i = 0; i < args.length; ++i) {
Class var10001 = packetType.fields[i];
Object var6 = args[i];
Class var5 = var10001;
SocketConnection var4 = this;
if(this.connected) {

View file

@ -15,6 +15,7 @@ import com.mojang.minecraft.level.levelgen.LevelGen;
import com.mojang.minecraft.level.liquid.Liquid;
import com.mojang.minecraft.level.tile.Tile;
import com.mojang.minecraft.net.ConnectionManager;
import com.mojang.minecraft.net.NetworkPlayer;
import com.mojang.minecraft.net.Packet;
import com.mojang.minecraft.particle.Particle;
import com.mojang.minecraft.particle.ParticleEngine;
@ -39,12 +40,19 @@ import java.awt.Robot;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.net.MalformedURLException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.Iterator;
import java.util.TreeSet;
import java.time.Instant;
import java.util.*;
import javax.swing.JOptionPane;
import dev.zontreck.ariaslib.args.*;
import dev.zontreck.ariaslib.http.HTTPMethod;
import dev.zontreck.ariaslib.http.HTTPRequestBuilder;
import dev.zontreck.ariaslib.http.HTTPResponse;
import dev.zontreck.ariaslib.util.EnvironmentUtils;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
@ -1165,16 +1173,46 @@ public final class Minecraft implements Runnable {
{
Minecraft minecraft = new Minecraft((Canvas)null, 800, 600, false);
if(args.length>0){
Random rng = new Random();
rng.setSeed(Instant.now().getEpochSecond());
// Hack: Add back multiplayer support!
String username = args[0];
minecraft.user = new User(username, args[1]);
Arguments defaults = ArgumentsBuilder.builder().withArgument(new StringArgument("username", "Player" + String.valueOf(rng.nextInt()).substring(5)))
.build();
if(args.length>2){
minecraft.server = args[2];
minecraft.port = Integer.parseInt(args[3]);
Arguments parser = ArgumentsParser.parseArguments(args, defaults);
StringArgument unArg = (StringArgument) parser.getArg("username");
if(parser.hasArg("username")) minecraft.user = new User(unArg.getValue(), System.getProperty("minecraft.auth_token"));
if(parser.hasArg("server"))
{
IntegerArgument serverArg = (IntegerArgument) parser.getArg("server");
// Acquire the server ip and port from Aria's Creations
HTTPResponse response = null;
try {
response = HTTPRequestBuilder.builder()
.withURL("https://api.zontreck.dev/zni/yggdrasil/legacy/server.php")
.withContentType("application/x-www-form-urlencoded")
.withMethod(HTTPMethod.POST)
.withBody("id=" + serverArg.getValue() +
"&username=" + minecraft.user.name)
.build();
} catch (MalformedURLException e) {
System.out.println("An error occured: " + e.getMessage());
throw new RuntimeException(e);
}
if(response.getResponseCode()==200)
{
System.out.println("Response is valid, server found at: " + response.getResponseBody());
String[] lReply = response.getResponseBody().split(";");
minecraft.server = lReply[0];
minecraft.port = Integer.parseInt(lReply[1]);
minecraft.user.mpPass = lReply[2];
}else {
System.out.println("Server could not be found!\nID: " + serverArg.getValue()+ "\nHTTP Response: " + response.getResponseBody());
return;
}
}

View file

@ -198,7 +198,7 @@ public class NetworkPlayer extends Entity {
var2 = 0.05F;
GL11.glScalef(var2, -var2, var2);
GL11.glTranslatef((float)(-var10.width(this.name)) / 2.0F, 0.0F, 0.0F);
if(this.name.equalsIgnoreCase("Notch")) {
if(this.name.equalsIgnoreCase("zontreck")) {
var10.draw(this.name, 0, 0, 16776960);
} else {
var10.draw(this.name, 0, 0, 16777215);

View file

@ -15,7 +15,7 @@ final class NetworkSkinDownloadThread extends Thread {
HttpURLConnection var1 = null;
try {
URL var2 = new URL("http://www.minecraft.net/skin/" + this.player.name + ".png");
URL var2 = new URL("https://api.zontreck.dev/zni/yggdrasil/skin/" + this.player.name + ".png");
var1 = (HttpURLConnection)var2.openConnection();
var1.setDoInput(true);
var1.setDoOutput(false);

View file

@ -37,6 +37,8 @@ repositories {
}
dependencies {
provided ("dev.zontreck:LibAC:1.4.15")
}
// Apply a specific Java toolchain to ease working on different environments.

View file

@ -24,9 +24,9 @@ final class ConsoleInput extends Thread {
return;
}
List var3 = MinecraftServer.a(this.minecraft);
List var3 = MinecraftServer.getPlayerList(this.minecraft);
synchronized(var3) {
MinecraftServer.a(this.minecraft).add(var2);
MinecraftServer.getPlayerList(this.minecraft).add(var2);
}
}
} catch (IOException var5) {

View file

@ -21,7 +21,7 @@ final class HeartbeatThread extends Thread {
HttpURLConnection var1 = null;
try {
URL var2 = new URL("http://www.minecraft.net/heartbeat.jsp");
URL var2 = new URL("https://api.zontreck.dev/zni/yggdrasil/legacy/heartbeat_2.php");
var1 = (HttpURLConnection)var2.openConnection();
var1.setRequestMethod("POST");
var1.setDoOutput(true);
@ -38,13 +38,13 @@ final class HeartbeatThread extends Thread {
var9.close();
BufferedReader var10 = new BufferedReader(new InputStreamReader(var1.getInputStream()));
String var3 = var10.readLine();
if(!MinecraftServer.b(this.minecraft).equals(var3)) {
if(!MinecraftServer.getServerURL(this.minecraft).equals(var3)) {
MinecraftServer.logger.info("To connect directly to this server, surf to: " + var3);
PrintWriter var4 = new PrintWriter(new FileWriter("externalurl.txt"));
var4.println(var3);
var4.close();
MinecraftServer.logger.info("(This is also in externalurl.txt)");
MinecraftServer.a(this.minecraft, var3);
MinecraftServer.setServerURL(this.minecraft, var3);
}
var10.close();

View file

@ -16,6 +16,7 @@ import java.net.URLEncoder;
import java.nio.channels.SocketChannel;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@ -52,6 +53,7 @@ public class MinecraftServer implements Runnable {
public MPPassCalculator mpPassCalculator = new MPPassCalculator(this.salt);
public boolean verifyNames = false;
private int maxConnectCount;
private String id;
public MinecraftServer() throws IOException {
try {
@ -61,12 +63,24 @@ public class MinecraftServer implements Runnable {
}
try {
Random rng = new Random();
rng.setSeed(Instant.now().getEpochSecond());
int id = 0;
while(id <= 0)
{
id = rng.nextInt();
if(("" + id).length() > 5)
id = Integer.parseInt(("" + id).substring(0,5));
}
this.id = "" + id;
this.serverName = this.properties.getProperty("server-name", "Minecraft Server");
this.motd = this.properties.getProperty("motd", "Welcome to my Minecraft Server!");
this.port = Integer.parseInt(this.properties.getProperty("port", "25565"));
this.maxPlayers = Integer.parseInt(this.properties.getProperty("max-players", "16"));
this.isPublic = Boolean.parseBoolean(this.properties.getProperty("public", "true"));
this.verifyNames = Boolean.parseBoolean(this.properties.getProperty("verify-names", "false"));
this.verifyNames = Boolean.parseBoolean(this.properties.getProperty("verify-names", "true"));
if(this.maxPlayers < 1) {
this.maxPlayers = 1;
}
@ -178,20 +192,23 @@ public class MinecraftServer implements Runnable {
}
logger.info("Level saved! Load: " + this.playerList.size() + "/" + this.maxPlayers);
logger.info("Server ID is : " + this.id);
}
/*
if(var7 % 900 == 0) {
HashMap var9 = new HashMap();
var9.put("name", this.serverName);
var9.put("users", Integer.valueOf(this.playerList.size()));
var9.put("max", Integer.valueOf(this.maxPlayers));
var9.put("public", Boolean.valueOf(this.isPublic));
var9.put("port", Integer.valueOf(this.port));
var9.put("salt", this.salt);
var9.put("version", Byte.valueOf((byte)5));
String var12 = assembleHeartbeat(var9);
(new HeartbeatThread(this, var12)).start();
}*/
HashMap map = new HashMap();
map.put("name", this.serverName);
map.put("users", Integer.valueOf(this.playerList.size()));
map.put("max", Integer.valueOf(this.maxPlayers));
map.put("public", Boolean.valueOf(this.isPublic));
map.put("port", Integer.valueOf(this.port));
map.put("salt", this.salt);
map.put("version", Byte.valueOf((byte)5));
map.put("id", this.id);
String heartbeat = assembleHeartbeat(map);
(new HeartbeatThread(this, heartbeat)).start();
}
}
while(System.nanoTime() - var3 > (long)var2) {
@ -207,19 +224,19 @@ public class MinecraftServer implements Runnable {
}
}
private static String assembleHeartbeat(Map var0) {
private static String assembleHeartbeat(Map parameters) {
try {
String var1 = "";
String ret = "";
String var3;
for(Iterator var2 = var0.keySet().iterator(); var2.hasNext(); var1 = var1 + var3 + "=" + URLEncoder.encode(var0.get(var3).toString(), "UTF-8")) {
var3 = (String)var2.next();
if(var1 != "") {
var1 = var1 + "&";
String temp;
for(Iterator it = parameters.keySet().iterator(); it.hasNext(); ret = ret + temp + "=" + URLEncoder.encode(parameters.get(temp).toString(), "UTF-8")) {
temp = (String)it.next();
if(ret != "") {
ret = ret + "&";
}
}
return var1;
return ret;
} catch (Exception var4) {
var4.printStackTrace();
throw new RuntimeException("Failed to assemble heartbeat! This is pretty fatal");
@ -415,9 +432,9 @@ public class MinecraftServer implements Runnable {
}
}
public final void parseCommand(PlayerInstance var1, String var2) {
logger.info((var1 == null ? "[console]" : var1.name) + " admins: " + var2);
String[] var3 = var2.split(" ");
public final void parseCommand(PlayerInstance player, String command) {
logger.info((player == null ? "[console]" : player.name) + " admins: " + command);
String[] var3 = command.split(" ");
if(var3[0].toLowerCase().equals("ban") && var3.length > 1) {
this.ban(var3[1]);
} else if(var3[0].toLowerCase().equals("kick") && var3.length > 1) {
@ -432,31 +449,31 @@ public class MinecraftServer implements Runnable {
} else if(var3[0].toLowerCase().equals("deop") && var3.length > 1) {
this.deop(var3[1]);
} else if(var3[0].toLowerCase().equals("setspawn")) {
if(var1 != null) {
this.level.setSpawnPos(var1.x / 32, var1.y / 32, var1.z / 32, (float)(var1.yaw * 320 / 256));
if(player != null) {
this.level.setSpawnPos(player.x / 32, player.y / 32, player.z / 32, (float)(player.yaw * 320 / 256));
} else {
logger.info("Can\'t set spawn from console!");
}
} else if(var3[0].toLowerCase().equals("broadcast") && var3.length > 1) {
this.sendPacket(Packet.CHAT_MESSAGE, new Object[]{Integer.valueOf(-1), var2.substring("broadcast ".length()).trim()});
this.sendPacket(Packet.CHAT_MESSAGE, new Object[]{Integer.valueOf(-1), command.substring("broadcast ".length()).trim()});
} else if(var3[0].toLowerCase().equals("say") && var3.length > 1) {
this.sendPacket(Packet.CHAT_MESSAGE, new Object[]{Integer.valueOf(-1), var2.substring("say ".length()).trim()});
this.sendPacket(Packet.CHAT_MESSAGE, new Object[]{Integer.valueOf(-1), command.substring("say ".length()).trim()});
} else {
if(var3[0].toLowerCase().equals("teleport") && var3.length > 1) {
if(var1 == null) {
if(player == null) {
logger.info("Can\'t teleport from console!");
return;
}
PlayerInstance var4 = this.getPlayerByName(var3[1]);
if(var4 == null) {
var1.sendPacket(Packet.CHAT_MESSAGE, new Object[]{Integer.valueOf(-1), "No such player"});
player.sendPacket(Packet.CHAT_MESSAGE, new Object[]{Integer.valueOf(-1), "No such player"});
return;
}
var1.connection.sendPacket(Packet.PLAYER_TELEPORT, new Object[]{Integer.valueOf(-1), Integer.valueOf(var4.x), Integer.valueOf(var4.y), Integer.valueOf(var4.z), Integer.valueOf(var4.yaw), Integer.valueOf(var4.pitch)});
} else if(var1 != null) {
var1.sendPacket(Packet.CHAT_MESSAGE, new Object[]{Integer.valueOf(-1), "Unknown command!"});
player.connection.sendPacket(Packet.PLAYER_TELEPORT, new Object[]{Integer.valueOf(-1), Integer.valueOf(var4.x), Integer.valueOf(var4.y), Integer.valueOf(var4.z), Integer.valueOf(var4.yaw), Integer.valueOf(var4.pitch)});
} else if(player != null) {
player.sendPacket(Packet.CHAT_MESSAGE, new Object[]{Integer.valueOf(-1), "Unknown command!"});
}
}
@ -600,7 +617,7 @@ public class MinecraftServer implements Runnable {
return var2;
}
public static void main(String[] var0) {
public static void main(String[] args) {
try {
MinecraftServer var6 = new MinecraftServer();
MinecraftServer var1 = var6;
@ -636,16 +653,15 @@ public class MinecraftServer implements Runnable {
}
}
static List a(MinecraftServer var0) {
static List getPlayerList(MinecraftServer var0) {
return var0.playerList2;
}
static String b(MinecraftServer var0) {
return var0.serverURL;
static String getServerURL(MinecraftServer server) {
return server.serverURL;
}
static String a(MinecraftServer var0, String var1) {
return var0.serverURL = var1;
static String setServerURL(MinecraftServer server, String ip) {
return server.serverURL = ip;
}
static {