Skip to content

Instantly share code, notes, and snippets.

@thvortex
Created August 9, 2012 07:45
Show Gist options
  • Save thvortex/3302081 to your computer and use it in GitHub Desktop.
Save thvortex/3302081 to your computer and use it in GitHub Desktop.
Prototype LANBans Minecraft mod (1.3.2)
diff --git a/src/minecraft/net/minecraft/src/CommandServerBan.java b/src/minecraft/net/minecraft/src/CommandServerBan.java
index d151938..f36d545 100644
--- a/src/minecraft/net/minecraft/src/CommandServerBan.java
+++ b/src/minecraft/net/minecraft/src/CommandServerBan.java
@@ -31,6 +31,12 @@ public class CommandServerBan extends CommandBase
BanEntry var4 = new BanEntry(par2ArrayOfStr[0]);
var4.setBannedBy(par1ICommandSender.getCommandSenderName());
+ MinecraftServer server = MinecraftServer.getServer();
+ if (server.isSinglePlayer() && server.getServerOwner().equalsIgnoreCase(par2ArrayOfStr[0]))
+ {
+ throw new WrongUsageException("Cannot ban the server owner", new Object[0]);
+ }
+
if (par2ArrayOfStr.length >= 2)
{
var4.setBanReason(joinString(par2ArrayOfStr, 1));
diff --git a/src/minecraft/net/minecraft/src/CommandServerBanIp.java b/src/minecraft/net/minecraft/src/CommandServerBanIp.java
index 50342ea..30a5605 100644
--- a/src/minecraft/net/minecraft/src/CommandServerBanIp.java
+++ b/src/minecraft/net/minecraft/src/CommandServerBanIp.java
@@ -85,11 +85,14 @@ public class CommandServerBanIp extends CommandBase
String[] var6 = new String[var5.size()];
int var7 = 0;
EntityPlayerMP var9;
-
+ MinecraftServer server = MinecraftServer.getServer();
for (Iterator var8 = var5.iterator(); var8.hasNext(); var6[var7++] = var9.getEntityName())
{
var9 = (EntityPlayerMP)var8.next();
- var9.serverForThisPlayer.kickPlayerFromServer("You have been IP banned.");
+ if (!server.isSinglePlayer() || !server.getServerOwner().equalsIgnoreCase(var9.username))
+ {
+ var9.serverForThisPlayer.kickPlayerFromServer("You have been IP banned.");
+ }
}
if (var5.isEmpty())
diff --git a/src/minecraft/net/minecraft/src/CommandServerKick.java b/src/minecraft/net/minecraft/src/CommandServerKick.java
index 411ed6b..93d8200 100644
--- a/src/minecraft/net/minecraft/src/CommandServerKick.java
+++ b/src/minecraft/net/minecraft/src/CommandServerKick.java
@@ -23,6 +23,12 @@ public class CommandServerKick extends CommandBase
String var4 = "Kicked by an operator.";
boolean var5 = false;
+ MinecraftServer server = MinecraftServer.getServer();
+ if (server.isSinglePlayer() && server.getServerOwner().equalsIgnoreCase(par2ArrayOfStr[0]))
+ {
+ throw new WrongUsageException("Cannot kick the server owner", new Object[0]);
+ }
+
if (var3 == null)
{
throw new PlayerNotFoundException();
diff --git a/src/minecraft/net/minecraft/src/DedicatedPlayerList.java b/src/minecraft/net/minecraft/src/DedicatedPlayerList.java
index dded324..165d669 100644
--- a/src/minecraft/net/minecraft/src/DedicatedPlayerList.java
+++ b/src/minecraft/net/minecraft/src/DedicatedPlayerList.java
@@ -13,36 +13,23 @@ public class DedicatedPlayerList extends ServerConfigurationManager
private File opsList;
private File whiteList;
- public DedicatedPlayerList(DedicatedServer par1DedicatedServer)
+ public DedicatedPlayerList(MinecraftServer par1DedicatedServer)
{
super(par1DedicatedServer);
- this.opsList = par1DedicatedServer.getFile("ops.txt");
- this.whiteList = par1DedicatedServer.getFile("white-list.txt");
- this.viewDistance = par1DedicatedServer.getOrSetIntProperty("view-distance", 10);
- this.maxPlayers = par1DedicatedServer.getOrSetIntProperty("max-players", 20);
- this.setWhiteListEnabled(par1DedicatedServer.getOrSetBoolProperty("white-list", false));
+ viewDistance = 10;
- if (!par1DedicatedServer.isSinglePlayer())
- {
- this.getBannedPlayers().setListActive(true);
- this.getBannedIPs().setListActive(true);
- }
+ getBannedPlayers().setListActive(true);
+ getBannedIPs().setListActive(true);
this.getBannedPlayers().loadBanList();
this.getBannedPlayers().saveToFileWithHeader();
this.getBannedIPs().loadBanList();
this.getBannedIPs().saveToFileWithHeader();
- this.loadOpsList();
- this.readWhiteList();
- this.saveOpsList();
- this.saveWhiteList();
}
public void setWhiteListEnabled(boolean par1)
{
super.setWhiteListEnabled(par1);
- this.getDedicatedServerInstance().setArbitraryProperty("white-list", Boolean.valueOf(par1));
- this.getDedicatedServerInstance().saveSettingsToFile();
}
/**
@@ -51,7 +38,6 @@ public class DedicatedPlayerList extends ServerConfigurationManager
public void addOp(String par1Str)
{
super.addOp(par1Str);
- this.saveOpsList();
}
/**
@@ -60,7 +46,6 @@ public class DedicatedPlayerList extends ServerConfigurationManager
public void removeOp(String par1Str)
{
super.removeOp(par1Str);
- this.saveOpsList();
}
/**
@@ -69,7 +54,6 @@ public class DedicatedPlayerList extends ServerConfigurationManager
public void removeFromWhitelist(String par1Str)
{
super.removeFromWhitelist(par1Str);
- this.saveWhiteList();
}
/**
@@ -78,7 +62,6 @@ public class DedicatedPlayerList extends ServerConfigurationManager
public void addToWhiteList(String par1Str)
{
super.addToWhiteList(par1Str);
- this.saveWhiteList();
}
/**
diff --git a/src/minecraft/net/minecraft/src/IntegratedServer.java b/src/minecraft/net/minecraft/src/IntegratedServer.java
index 04d7a37..0c043cf 100644
--- a/src/minecraft/net/minecraft/src/IntegratedServer.java
+++ b/src/minecraft/net/minecraft/src/IntegratedServer.java
@@ -24,9 +24,10 @@ public class IntegratedServer extends MinecraftServer
this.setDemo(par1Minecraft.isDemo());
this.canCreateBonusChest(par4WorldSettings.isBonusChestEnabled());
this.setBuildLimit(256);
- this.setConfigurationManager(new IntegratedPlayerList(this));
this.mc = par1Minecraft;
this.field_71350_m = par4WorldSettings;
+ this.setConfigurationManager(new DedicatedPlayerList(this));
+
try
{
@@ -155,7 +156,7 @@ public class IntegratedServer extends MinecraftServer
public boolean isDedicatedServer()
{
- return false;
+ return true;
}
public IntegratedServerListenThread func_71343_a()
diff --git a/src/minecraft/net/minecraft/src/ServerConfigurationManager.java b/src/minecraft/net/minecraft/src/ServerConfigurationManager.java
index f454b42..28b1bd5 100644
--- a/src/minecraft/net/minecraft/src/ServerConfigurationManager.java
+++ b/src/minecraft/net/minecraft/src/ServerConfigurationManager.java
@@ -174,6 +174,9 @@ public abstract class ServerConfigurationManager
var2.getPlayerManager().func_72695_c(par1EntityPlayerMP);
this.playerEntityList.remove(par1EntityPlayerMP);
this.sendPacketToAllPlayers(new Packet201PlayerInfo(par1EntityPlayerMP.username, false, 9999));
+
+ this.removeOp(par1EntityPlayerMP.username);
+ this.removeFromWhitelist(par1EntityPlayerMP.username);
}
/**
@@ -217,6 +220,10 @@ public abstract class ServerConfigurationManager
}
else
{
+ for (EntityPlayerMP otherPlayer : (List<EntityPlayerMP>) this.playerEntityList)
+ if (otherPlayer.username.equalsIgnoreCase(par2Str))
+ return "Your player name is already in use!";
+
return this.playerEntityList.size() >= this.maxPlayers ? "The server is full!" : null;
}
}
@@ -514,7 +521,12 @@ public abstract class ServerConfigurationManager
public boolean areCommandsAllowed(String par1Str)
{
- return this.ops.contains(par1Str.trim().toLowerCase()) || this.mcServer.isSinglePlayer() && this.mcServer.theWorldServer[0].getWorldInfo().areCommandsAllowed() && this.mcServer.getServerOwner().equalsIgnoreCase(par1Str) || this.commandsAllowedForAll;
+ boolean isOp = this.ops.contains(par1Str.trim().toLowerCase());
+ boolean isOwner = this.mcServer.isSinglePlayer() && this.mcServer.getServerOwner().equalsIgnoreCase(par1Str);
+ boolean isPublic = (this.mcServer instanceof IntegratedServer) && ((IntegratedServer)this.mcServer).func_71344_c();
+ boolean areCommandsAllowed = this.mcServer.theWorldServer[0].getWorldInfo().areCommandsAllowed();
+
+ return isOp || isOwner && (isPublic || areCommandsAllowed) || this.commandsAllowedForAll;
}
public EntityPlayerMP getPlayerForUsername(String par1Str)
@@ -586,7 +598,7 @@ public abstract class ServerConfigurationManager
*/
public void addToWhiteList(String par1Str)
{
- this.whiteListIPs.add(par1Str);
+ this.whiteListIPs.add(par1Str.toLowerCase());
}
/**
@@ -594,7 +606,7 @@ public abstract class ServerConfigurationManager
*/
public void removeFromWhitelist(String par1Str)
{
- this.whiteListIPs.remove(par1Str);
+ this.whiteListIPs.remove(par1Str.toLowerCase());
}
public Set getIPWhiteList()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment