From d1542af8b95df428334b6810da3ab8a710475f3c Mon Sep 17 00:00:00 2001 From: PeytonPlayz595 <106421860+PeytonPlayz595@users.noreply.github.com> Date: Tue, 19 Dec 2023 11:10:46 -0500 Subject: [PATCH] Cleanup some code --- .../minecraft/server/MinecraftServer.java | 57 ++----------------- .../minecraft/server/NetworkManager.java | 6 +- .../minecraft/server/SaltGenerator.java | 26 --------- 3 files changed, 6 insertions(+), 83 deletions(-) delete mode 100644 src/com/mojang/minecraft/server/SaltGenerator.java diff --git a/src/com/mojang/minecraft/server/MinecraftServer.java b/src/com/mojang/minecraft/server/MinecraftServer.java index 2642c16..4d63369 100644 --- a/src/com/mojang/minecraft/server/MinecraftServer.java +++ b/src/com/mojang/minecraft/server/MinecraftServer.java @@ -3,14 +3,6 @@ package com.mojang.minecraft.server; import com.mojang.minecraft.level.LevelIO; import com.mojang.minecraft.level.generator.LevelGenerator; import com.mojang.minecraft.net.PacketType; -import com.mojang.minecraft.server.ConsoleInput; -import com.mojang.minecraft.server.HeartbeatManager; -import com.mojang.minecraft.server.LogFormatter; -import com.mojang.minecraft.server.LogHandler; -import com.mojang.minecraft.server.NetworkManager; -import com.mojang.minecraft.server.PlayerManager; -import com.mojang.minecraft.server.SaltGenerator; -import com.mojang.minecraft.server.UNKNOWN0; import com.mojang.net.BindTo; import com.mojang.net.NetworkHandler; import java.io.File; @@ -42,10 +34,8 @@ public class MinecraftServer implements Runnable { private Map m = new HashMap(); private List n = new ArrayList(); private List o = new ArrayList(); - private int maxPlayers; private Properties properties = new Properties(); public com.mojang.minecraft.level.Level mainLevel; - private boolean public_ = false; public String serverName; public String MOTD; public boolean adminSlot; @@ -57,15 +47,9 @@ public class MinecraftServer implements Runnable { private List v = new ArrayList(); private String salt = "" + (new Random()).nextLong(); private String x = ""; - public SaltGenerator saltGenerator; - public boolean verifyNames; private boolean growTrees; - private int maxConnections; - public MinecraftServer() { - this.saltGenerator = new SaltGenerator(this.salt); - this.verifyNames = false; this.growTrees = false; try { @@ -77,25 +61,11 @@ public class MinecraftServer implements Runnable { try { this.serverName = this.properties.getProperty("server-name", "Minecraft Server"); this.MOTD = this.properties.getProperty("motd", "Welcome to my Minecraft Server!"); - this.maxPlayers = Integer.parseInt(this.properties.getProperty("max-players", "16")); - this.public_ = Boolean.parseBoolean(this.properties.getProperty("public", "true")); - this.verifyNames = Boolean.parseBoolean(this.properties.getProperty("verify-names", "true")); this.growTrees = Boolean.parseBoolean(this.properties.getProperty("grow-trees", "false")); this.adminSlot = Boolean.parseBoolean(this.properties.getProperty("admin-slot", "false")); - if(this.maxPlayers < 1) { - this.maxPlayers = 1; - } - if(this.maxPlayers > 32) { - this.maxPlayers = 32; - } - - this.maxConnections = Integer.parseInt(this.properties.getProperty("max-connections", "3")); this.properties.setProperty("server-name", this.serverName); this.properties.setProperty("motd", this.MOTD); - this.properties.setProperty("max-players", "" + this.maxPlayers); - this.properties.setProperty("public", "" + this.public_); - this.properties.setProperty("verify-names", "" + this.verifyNames); this.properties.setProperty("max-connections", "3"); this.properties.setProperty("grow-trees", "" + this.growTrees); this.properties.setProperty("admin-slot", "" + this.adminSlot); @@ -105,29 +75,13 @@ public class MinecraftServer implements Runnable { System.exit(0); } - if(!this.verifyNames) { - logger.warning("######################### WARNING #########################"); - logger.warning("verify-names is set to false! This means that anyone who"); - logger.warning("connects to this server can choose any username he or she"); - logger.warning("wants! This includes impersonating an OP!"); - if(this.public_) { - logger.warning(""); - logger.warning("AND SINCE THIS IS A PUBLIC SERVER, IT WILL HAPPEN TO YOU!"); - logger.warning(""); - } - - logger.warning("If you wish to fix this, edit server.properties, and change"); - logger.warning("verify-names to true."); - logger.warning("###########################################################"); - } - try { this.properties.store(new FileWriter("server.properties"), "Minecraft server properties"); } catch (Exception var2) { logger.warning("Failed to save server.properties!"); } - this.networkManager = new NetworkManager[this.maxPlayers]; + this.networkManager = new NetworkManager[32]; this.bindTo = new BindTo(this); (new ConsoleInput(this)).start(); } @@ -210,15 +164,14 @@ public class MinecraftServer implements Runnable { logger.severe("Failed to save the level! " + var11); } - logger.info("Level saved! Load: " + this.n.size() + "/" + this.maxPlayers); + logger.info("Level saved! Load: " + this.n.size() + "/" + 32); } if(var7 % 900 == 0) { HashMap var9; (var9 = new HashMap()).put("name", this.serverName); var9.put("users", Integer.valueOf(this.n.size())); - var9.put("max", Integer.valueOf(this.maxPlayers - (this.adminSlot?1:0))); - var9.put("public", Boolean.valueOf(this.public_)); + var9.put("max", Integer.valueOf(32 - (this.adminSlot?1:0))); var9.put("salt", this.salt); var9.put("admin-slot", Boolean.valueOf(this.adminSlot)); var9.put("version", Byte.valueOf((byte)7)); @@ -467,7 +420,7 @@ public class MinecraftServer implements Runnable { public final int a() { int var1 = 0; - for(int var2 = 0; var2 < this.maxPlayers; ++var2) { + for(int var2 = 0; var2 < 32; ++var2) { if(this.networkManager[var2] == null) { ++var1; } @@ -477,7 +430,7 @@ public class MinecraftServer implements Runnable { } private int e() { - for(int var1 = 0; var1 < this.maxPlayers; ++var1) { + for(int var1 = 0; var1 < 32; ++var1) { if(this.networkManager[var1] == null) { return var1; } diff --git a/src/com/mojang/minecraft/server/NetworkManager.java b/src/com/mojang/minecraft/server/NetworkManager.java index 7646031..229180b 100644 --- a/src/com/mojang/minecraft/server/NetworkManager.java +++ b/src/com/mojang/minecraft/server/NetworkManager.java @@ -4,8 +4,6 @@ import com.mojang.minecraft.AvailableBlockType; import com.mojang.minecraft.level.Level; import com.mojang.minecraft.level.tile.a; import com.mojang.minecraft.net.PacketType; -import com.mojang.minecraft.server.LevelSaver; -import com.mojang.minecraft.server.MinecraftServer; import com.mojang.net.NetworkHandler; import com.mojang.util.MathHelper; import java.io.IOException; @@ -105,9 +103,7 @@ public final class NetworkManager { this.a("Illegal name."); } - if(this.server.verifyNames && !var8.equals(this.server.saltGenerator.generate(var3))) { - this.a("The name wasn\'t verified by minecraft.net!"); - } else if(var6 != 7) { + if(var6 != 7) { this.a("Wrong protocol version."); } else if(this.server.playerManager2.containsPlayer(var3)) { this.a("You\'re banned!"); diff --git a/src/com/mojang/minecraft/server/SaltGenerator.java b/src/com/mojang/minecraft/server/SaltGenerator.java deleted file mode 100644 index d0f2dbe..0000000 --- a/src/com/mojang/minecraft/server/SaltGenerator.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.mojang.minecraft.server; - -import java.math.BigInteger; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -public final class SaltGenerator { - - private String salt; - - - public SaltGenerator(String var1) { - this.salt = var1; - } - - public final String generate(String var1) { - try { - String var3 = this.salt + var1; - MessageDigest var4; - (var4 = MessageDigest.getInstance("MD5")).update(var3.getBytes(), 0, var3.length()); - return (new BigInteger(1, var4.digest())).toString(16); - } catch (NoSuchAlgorithmException var2) { - throw new RuntimeException(var2); - } - } -}