PaperMC/src/main/java/net/minecraft/server/ServerConfigurationManager.java

372 lines
12 KiB
Java
Raw Normal View History

2010-12-26 03:20:29 +01:00
package net.minecraft.server;
2010-12-28 20:52:24 +01:00
import java.io.*;
import java.util.*;
2010-12-26 03:20:29 +01:00
import java.util.logging.Logger;
2010-12-28 20:52:24 +01:00
// CraftBukkit start
import org.bukkit.craftbukkit.entity.CraftPlayer;
2010-12-26 03:20:29 +01:00
import org.bukkit.craftbukkit.CraftServer;
2010-12-28 23:22:26 +01:00
import org.bukkit.event.Event.Type;
2010-12-26 03:20:29 +01:00
import org.bukkit.event.player.PlayerEvent;
2010-12-28 23:22:26 +01:00
import org.bukkit.event.player.PlayerLoginEvent;
// CraftBukkit end
2010-12-28 20:52:24 +01:00
2010-12-26 03:20:29 +01:00
public class ServerConfigurationManager {
public static Logger a = Logger.getLogger("Minecraft");
public List b;
2010-12-26 03:20:29 +01:00
private MinecraftServer c;
private PlayerManager d;
private int e;
private Set f;
private Set g;
private Set h;
2010-12-26 03:20:29 +01:00
private File i;
private File j;
private File k;
private PlayerNBTManager l;
private CraftServer server; // CraftBukkit
2010-12-28 20:52:24 +01:00
public ServerConfigurationManager(MinecraftServer minecraftserver) {
// CraftBukkit 2 lines!
minecraftserver.server = new CraftServer(minecraftserver, this);
server = minecraftserver.server;
b = ((List) (new ArrayList()));
f = ((Set) (new HashSet()));
g = ((Set) (new HashSet()));
h = ((Set) (new HashSet()));
2010-12-28 20:52:24 +01:00
c = minecraftserver;
i = minecraftserver.a("banned-players.txt");
j = minecraftserver.a("banned-ips.txt");
k = minecraftserver.a("ops.txt");
d = new PlayerManager(minecraftserver);
e = minecraftserver.d.a("max-players", 20);
2010-12-26 03:20:29 +01:00
e();
g();
i();
f();
h();
j();
}
2010-12-28 20:52:24 +01:00
public void a(WorldServer worldserver) {
l = new PlayerNBTManager(new File(worldserver.t, "players"));
2010-12-26 03:20:29 +01:00
}
public int a() {
2010-12-28 20:52:24 +01:00
return d.b();
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
public void a(EntityPlayerMP entityplayermp) {
b.add(((entityplayermp)));
2010-12-28 20:52:24 +01:00
l.b(entityplayermp);
c.e.A.d((int) entityplayermp.p >> 4, (int) entityplayermp.r >> 4);
for (; c.e.a(((Entity) (entityplayermp)), entityplayermp.z).size() != 0; entityplayermp.a(entityplayermp.p, entityplayermp.q + 1.0D, entityplayermp.r)) {
2010-12-28 20:52:24 +01:00
;
2010-12-26 03:20:29 +01:00
}
c.e.a(((Entity) (entityplayermp)));
2010-12-28 20:52:24 +01:00
d.a(entityplayermp);
2010-12-26 03:20:29 +01:00
// CraftBukkit
2010-12-28 20:52:24 +01:00
server.getPluginManager().callEvent(new PlayerEvent(PlayerEvent.Type.PLAYER_JOIN, server.getPlayer(entityplayermp)));
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
public void b(EntityPlayerMP entityplayermp) {
d.c(entityplayermp);
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
public void c(EntityPlayerMP entityplayermp) {
l.a(entityplayermp);
c.e.d(((Entity) (entityplayermp)));
b.remove(((entityplayermp)));
2010-12-28 20:52:24 +01:00
d.b(entityplayermp);
2010-12-26 03:20:29 +01:00
// CraftBukkit
2010-12-28 20:52:24 +01:00
server.getPluginManager().callEvent(new PlayerEvent(PlayerEvent.Type.PLAYER_QUIT, server.getPlayer(entityplayermp)));
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
public EntityPlayerMP a(NetLoginHandler netloginhandler, String s, String s1) {
// CraftBukkit start - note: this entire method needs to be changed
2010-12-28 23:22:26 +01:00
// Instead of kicking then returning, we need to store the kick reason
// in the event, check with plugins to see if it's ok, and THEN kick
// depending on the outcome.
EntityPlayerMP entity = new EntityPlayerMP(c, ((World) (c.e)), s, new ItemInWorldManager(((World) (c.e))));
PlayerLoginEvent event = new PlayerLoginEvent(Type.PLAYER_LOGIN, new CraftPlayer(server, entity));
// CraftBukkit end
String s2 = ((netloginhandler.b.b())).toString();
2010-12-28 20:52:24 +01:00
s2 = s2.substring(s2.indexOf("/") + 1);
s2 = s2.substring(0, s2.indexOf(":"));
2010-12-28 23:22:26 +01:00
// CraftBukkit start
2010-12-28 23:22:26 +01:00
if (f.contains(s.trim().toLowerCase())) {
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, "You are banned from this server!");
} else if (g.contains(s2)) {
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, "Your IP address is banned from this server!");
} else if (b.size() >= e) {
event.disallow(PlayerLoginEvent.Result.KICK_FULL, "The server is full!");
2010-12-26 03:20:29 +01:00
}
2010-12-28 23:22:26 +01:00
server.getPluginManager().callEvent(event);
if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
netloginhandler.a(event.getKickMessage());
2010-12-26 03:20:29 +01:00
return null;
}
// CraftBukkit end
2010-12-28 20:52:24 +01:00
for (int i1 = 0; i1 < b.size(); i1++) {
EntityPlayerMP entityplayermp = (EntityPlayerMP) b.get(i1);
if (entityplayermp.aw.equalsIgnoreCase(s)) {
entityplayermp.a.a("You logged in from another location");
2010-12-26 03:20:29 +01:00
}
}
// CraftBukkit
2010-12-28 23:22:26 +01:00
return entity;
2010-12-28 20:52:24 +01:00
}
2010-12-26 03:20:29 +01:00
2010-12-28 20:52:24 +01:00
public EntityPlayerMP d(EntityPlayerMP entityplayermp) {
c.k.a(entityplayermp);
c.k.b(((Entity) (entityplayermp)));
2010-12-28 20:52:24 +01:00
d.b(entityplayermp);
b.remove(((entityplayermp)));
c.e.e(((Entity) (entityplayermp)));
EntityPlayerMP entityplayermp1 = new EntityPlayerMP(c, ((World) (c.e)), entityplayermp.aw, new ItemInWorldManager(((World) (c.e))));
2010-12-26 03:20:29 +01:00
2010-12-28 20:52:24 +01:00
entityplayermp1.g = entityplayermp.g;
entityplayermp1.a = entityplayermp.a;
c.e.A.d((int) entityplayermp1.p >> 4, (int) entityplayermp1.r >> 4);
for (; c.e.a(((Entity) (entityplayermp1)), entityplayermp1.z).size() != 0; entityplayermp1.a(entityplayermp1.p, entityplayermp1.q + 1.0D, entityplayermp1.r)) {
2010-12-28 20:52:24 +01:00
;
2010-12-26 03:20:29 +01:00
}
entityplayermp1.a.b(((Packet) (new Packet9())));
2010-12-28 20:52:24 +01:00
entityplayermp1.a.a(entityplayermp1.p, entityplayermp1.q, entityplayermp1.r, entityplayermp1.v, entityplayermp1.w);
d.a(entityplayermp1);
c.e.a(((Entity) (entityplayermp1)));
b.add(((entityplayermp1)));
2011-01-14 14:31:10 +01:00
entityplayermp1.l();
2010-12-28 20:52:24 +01:00
return entityplayermp1;
2010-12-26 03:20:29 +01:00
}
public void b() {
2010-12-28 20:52:24 +01:00
d.a();
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
public void a(int i1, int j1, int k1) {
d.a(i1, j1, k1);
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
public void a(Packet packet) {
for (int i1 = 0; i1 < b.size(); i1++) {
EntityPlayerMP entityplayermp = (EntityPlayerMP) b.get(i1);
entityplayermp.a.b(packet);
2010-12-26 03:20:29 +01:00
}
}
public String c() {
2010-12-28 20:52:24 +01:00
String s = "";
for (int i1 = 0; i1 < b.size(); i1++) {
if (i1 > 0) {
s = (new StringBuilder()).append(s).append(", ").toString();
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
s = (new StringBuilder()).append(s).append(((EntityPlayerMP) b.get(i1)).aw).toString();
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
return s;
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
public void a(String s) {
f.add(((s.toLowerCase())));
2010-12-26 03:20:29 +01:00
f();
}
2010-12-28 20:52:24 +01:00
public void b(String s) {
f.remove(((s.toLowerCase())));
2010-12-26 03:20:29 +01:00
f();
}
private void e() {
try {
2010-12-28 20:52:24 +01:00
f.clear();
BufferedReader bufferedreader = new BufferedReader(((java.io.Reader) (new FileReader(i))));
2010-12-28 20:52:24 +01:00
for (String s = ""; (s = bufferedreader.readLine()) != null;) {
f.add(((s.trim().toLowerCase())));
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
bufferedreader.close();
} catch (Exception exception) {
a.warning((new StringBuilder()).append("Failed to load ban list: ").append(((exception))).toString());
2010-12-26 03:20:29 +01:00
}
}
private void f() {
try {
PrintWriter printwriter = new PrintWriter(((java.io.Writer) (new FileWriter(i, false))));
2010-12-28 20:52:24 +01:00
String s;
for (Iterator iterator = f.iterator(); iterator.hasNext(); printwriter.println(s)) {
2010-12-28 20:52:24 +01:00
s = (String) iterator.next();
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
printwriter.close();
} catch (Exception exception) {
a.warning((new StringBuilder()).append("Failed to save ban list: ").append(((exception))).toString());
2010-12-26 03:20:29 +01:00
}
}
2010-12-28 20:52:24 +01:00
public void c(String s) {
g.add(((s.toLowerCase())));
2010-12-26 03:20:29 +01:00
h();
}
2010-12-28 20:52:24 +01:00
public void d(String s) {
g.remove(((s.toLowerCase())));
2010-12-26 03:20:29 +01:00
h();
}
private void g() {
try {
2010-12-28 20:52:24 +01:00
g.clear();
BufferedReader bufferedreader = new BufferedReader(((java.io.Reader) (new FileReader(j))));
2010-12-28 20:52:24 +01:00
for (String s = ""; (s = bufferedreader.readLine()) != null;) {
g.add(((s.trim().toLowerCase())));
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
bufferedreader.close();
} catch (Exception exception) {
a.warning((new StringBuilder()).append("Failed to load ip ban list: ").append(((exception))).toString());
2010-12-26 03:20:29 +01:00
}
}
private void h() {
try {
PrintWriter printwriter = new PrintWriter(((java.io.Writer) (new FileWriter(j, false))));
2010-12-28 20:52:24 +01:00
String s;
for (Iterator iterator = g.iterator(); iterator.hasNext(); printwriter.println(s)) {
2010-12-28 20:52:24 +01:00
s = (String) iterator.next();
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
printwriter.close();
} catch (Exception exception) {
a.warning((new StringBuilder()).append("Failed to save ip ban list: ").append(((exception))).toString());
2010-12-26 03:20:29 +01:00
}
}
2010-12-28 20:52:24 +01:00
public void e(String s) {
h.add(((s.toLowerCase())));
2010-12-26 03:20:29 +01:00
j();
}
2010-12-28 20:52:24 +01:00
public void f(String s) {
h.remove(((s.toLowerCase())));
2010-12-26 03:20:29 +01:00
j();
}
private void i() {
try {
2010-12-28 20:52:24 +01:00
h.clear();
BufferedReader bufferedreader = new BufferedReader(((java.io.Reader) (new FileReader(k))));
2010-12-28 20:52:24 +01:00
for (String s = ""; (s = bufferedreader.readLine()) != null;) {
h.add(((s.trim().toLowerCase())));
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
bufferedreader.close();
} catch (Exception exception) {
a.warning((new StringBuilder()).append("Failed to load ip ban list: ").append(((exception))).toString());
2010-12-26 03:20:29 +01:00
}
}
private void j() {
try {
PrintWriter printwriter = new PrintWriter(((java.io.Writer) (new FileWriter(k, false))));
2010-12-28 20:52:24 +01:00
String s;
for (Iterator iterator = h.iterator(); iterator.hasNext(); printwriter.println(s)) {
2010-12-28 20:52:24 +01:00
s = (String) iterator.next();
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
printwriter.close();
} catch (Exception exception) {
a.warning((new StringBuilder()).append("Failed to save ip ban list: ").append(((exception))).toString());
2010-12-26 03:20:29 +01:00
}
}
2010-12-28 20:52:24 +01:00
public boolean g(String s) {
return h.contains(((s.trim().toLowerCase())));
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
public EntityPlayerMP h(String s) {
for (int i1 = 0; i1 < b.size(); i1++) {
EntityPlayerMP entityplayermp = (EntityPlayerMP) b.get(i1);
if (entityplayermp.aw.equalsIgnoreCase(s)) {
return entityplayermp;
2010-12-26 03:20:29 +01:00
}
}
2010-12-28 20:52:24 +01:00
2010-12-26 03:20:29 +01:00
return null;
}
2010-12-28 20:52:24 +01:00
public void a(String s, String s1) {
EntityPlayerMP entityplayermp = h(s);
if (entityplayermp != null) {
entityplayermp.a.b(((Packet) (new Packet3Chat(s1))));
2010-12-26 03:20:29 +01:00
}
}
2010-12-28 20:52:24 +01:00
public void a(double d1, double d2, double d3, double d4, Packet packet) {
for (int i1 = 0; i1 < b.size(); i1++) {
EntityPlayerMP entityplayermp = (EntityPlayerMP) b.get(i1);
double d5 = d1 - entityplayermp.p;
double d6 = d2 - entityplayermp.q;
double d7 = d3 - entityplayermp.r;
if (d5 * d5 + d6 * d6 + d7 * d7 < d4 * d4) {
entityplayermp.a.b(packet);
2010-12-26 03:20:29 +01:00
}
}
}
2010-12-28 20:52:24 +01:00
public void i(String s) {
Packet3Chat packet3chat = new Packet3Chat(s);
for (int i1 = 0; i1 < b.size(); i1++) {
EntityPlayerMP entityplayermp = (EntityPlayerMP) b.get(i1);
if (g(entityplayermp.aw)) {
entityplayermp.a.b(((Packet) (packet3chat)));
2010-12-26 03:20:29 +01:00
}
}
}
2010-12-28 20:52:24 +01:00
public boolean a(String s, Packet packet) {
EntityPlayerMP entityplayermp = h(s);
if (entityplayermp != null) {
entityplayermp.a.b(packet);
2010-12-26 03:20:29 +01:00
return true;
2010-12-28 20:52:24 +01:00
} else {
return false;
2010-12-26 03:20:29 +01:00
}
}
public void d() {
2010-12-28 20:52:24 +01:00
for (int i1 = 0; i1 < b.size(); i1++) {
l.a((EntityPlayerMP) b.get(i1));
2010-12-26 03:20:29 +01:00
}
}
2010-12-28 20:52:24 +01:00
public void a(int i1, int j1, int k1, TileEntity tileentity) {}
2010-12-26 03:20:29 +01:00
}