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

383 lines
11 KiB
Java
Raw Normal View History

2010-12-26 03:20:29 +01:00
package net.minecraft.server;
2011-01-29 22:50:29 +01:00
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
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;
import org.bukkit.entity.Player;
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");
2011-01-29 22:50:29 +01:00
public List b = new ArrayList();
2010-12-26 03:20:29 +01:00
private MinecraftServer c;
private PlayerManager d;
private int e;
2011-01-29 22:50:29 +01:00
private Set f = new HashSet();
private Set g = new HashSet();
private Set h = new HashSet();
2010-12-26 03:20:29 +01:00
private File i;
private File j;
private File k;
private PlayerNBTManager l;
public ServerConfigurationManager(MinecraftServer minecraftserver) {
2011-01-29 22:50:29 +01:00
this.c = minecraftserver;
this.i = minecraftserver.a("banned-players.txt");
this.j = minecraftserver.a("banned-ips.txt");
this.k = minecraftserver.a("ops.txt");
this.d = new PlayerManager(minecraftserver);
this.e = minecraftserver.d.a("max-players", 20);
this.e();
this.g();
this.i();
this.f();
this.h();
this.j();
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
public void a(WorldServer worldserver) {
2011-01-29 22:50:29 +01:00
this.l = new PlayerNBTManager(new File(worldserver.t, "players"));
2010-12-26 03:20:29 +01:00
}
public int a() {
2011-01-29 22:50:29 +01:00
return this.d.b();
2010-12-26 03:20:29 +01:00
}
2011-01-29 22:50:29 +01:00
public void a(EntityPlayer entityplayer) {
this.b.add(entityplayer);
this.l.b(entityplayer);
this.c.e.A.d((int) entityplayer.locX >> 4, (int) entityplayer.locZ >> 4);
while (this.c.e.a(entityplayer, entityplayer.boundingBox).size() != 0) {
entityplayer.a(entityplayer.locX, entityplayer.locY + 1.0D, entityplayer.locZ);
2010-12-26 03:20:29 +01:00
}
2011-01-29 22:50:29 +01:00
this.c.e.a(entityplayer);
this.d.a(entityplayer);
2010-12-26 03:20:29 +01:00
}
2011-01-29 22:50:29 +01:00
public void b(EntityPlayer entityplayer) {
this.d.c(entityplayer);
2010-12-26 03:20:29 +01:00
}
2011-01-29 22:50:29 +01:00
public void c(EntityPlayer entityplayer) {
this.l.a(entityplayer);
this.c.e.d(entityplayer);
this.b.remove(entityplayer);
this.d.b(entityplayer);
2010-12-26 03:20:29 +01:00
2011-01-29 22:50:29 +01:00
// CraftBukkit start
server.getPluginManager().callEvent(new PlayerEvent(PlayerEvent.Type.PLAYER_QUIT, server.getPlayer(entityplayer))); // CraftBukkit
2010-12-26 03:20:29 +01:00
}
2011-01-29 22:50:29 +01:00
private CraftServer server;
// CraftBukkit end
2010-12-26 03:20:29 +01:00
2011-01-29 22:50:29 +01:00
public EntityPlayer 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.
2011-01-29 22:50:29 +01:00
EntityPlayer entity = new EntityPlayer(c, ((World) (c.e)), s, new ItemInWorldManager(((World) (c.e))));
Player player = (entity == null) ? null : (Player) entity.getBukkitEntity();
PlayerLoginEvent event = new PlayerLoginEvent(Type.PLAYER_LOGIN, player);
2011-01-29 22:50:29 +01:00
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
2011-01-29 22:50:29 +01:00
if (this.f.contains(s.trim().toLowerCase())) {
2010-12-28 23:22:26 +01:00
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, "You are banned from this server!");
2011-01-29 22:50:29 +01:00
} else if (this.g.contains(s2)) {
2010-12-28 23:22:26 +01:00
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, "Your IP address is banned from this server!");
2011-01-29 22:50:29 +01:00
} else if (this.b.size() >= this.e) {
2010-12-28 23:22:26 +01:00
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;
}
2010-12-28 20:52:24 +01:00
2011-01-29 22:50:29 +01:00
for (int i = 0; i < this.b.size(); ++i) {
EntityPlayer entityplayer = (EntityPlayer) this.b.get(i);
if (entityplayer.name.equalsIgnoreCase(s)) {
entityplayer.a.a("You logged in from another location");
2010-12-26 03:20:29 +01:00
}
}
2011-01-29 22:50:29 +01:00
return new EntityPlayer(this.c, this.c.e, s, new ItemInWorldManager(this.c.e));
// CraftBukkit end
2010-12-28 20:52:24 +01:00
}
2010-12-26 03:20:29 +01:00
2011-01-29 22:50:29 +01:00
public EntityPlayer d(EntityPlayer entityplayer) {
this.c.k.a(entityplayer);
this.c.k.b(entityplayer);
this.d.b(entityplayer);
this.b.remove(entityplayer);
this.c.e.e(entityplayer);
EntityPlayer entityplayer1 = new EntityPlayer(this.c, this.c.e, entityplayer.name, new ItemInWorldManager(this.c.e));
entityplayer1.id = entityplayer.id;
entityplayer1.a = entityplayer.a;
this.c.e.A.d((int) entityplayer1.locX >> 4, (int) entityplayer1.locZ >> 4);
while (this.c.e.a(entityplayer1, entityplayer1.boundingBox).size() != 0) {
entityplayer1.a(entityplayer1.locX, entityplayer1.locY + 1.0D, entityplayer1.locZ);
2010-12-26 03:20:29 +01:00
}
2011-01-29 22:50:29 +01:00
entityplayer1.a.b((Packet) (new Packet9Respawn()));
entityplayer1.a.a(entityplayer1.locX, entityplayer1.locY, entityplayer1.locZ, entityplayer1.yaw, entityplayer1.pitch);
this.d.a(entityplayer1);
this.c.e.a(entityplayer1);
this.b.add(entityplayer1);
entityplayer1.l();
return entityplayer1;
2010-12-26 03:20:29 +01:00
}
public void b() {
2011-01-29 22:50:29 +01:00
this.d.a();
2010-12-26 03:20:29 +01:00
}
2011-01-29 22:50:29 +01:00
public void a(int i, int j, int k) {
this.d.a(i, j, k);
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
public void a(Packet packet) {
2011-01-29 22:50:29 +01:00
for (int i = 0; i < this.b.size(); ++i) {
EntityPlayer entityplayer = (EntityPlayer) this.b.get(i);
2010-12-28 20:52:24 +01:00
2011-01-29 22:50:29 +01:00
entityplayer.a.b(packet);
2010-12-26 03:20:29 +01:00
}
}
public String c() {
2010-12-28 20:52:24 +01:00
String s = "";
2011-01-29 22:50:29 +01:00
for (int i = 0; i < this.b.size(); ++i) {
if (i > 0) {
s = s + ", ";
2010-12-26 03:20:29 +01:00
}
2011-01-29 22:50:29 +01:00
s = s + ((EntityPlayer) this.b.get(i)).name;
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) {
2011-01-29 22:50:29 +01:00
this.f.add(s.toLowerCase());
this.f();
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
public void b(String s) {
2011-01-29 22:50:29 +01:00
this.f.remove(s.toLowerCase());
this.f();
2010-12-26 03:20:29 +01:00
}
private void e() {
try {
2011-01-29 22:50:29 +01:00
this.f.clear();
BufferedReader bufferedreader = new BufferedReader(new FileReader(this.i));
String s = "";
2010-12-28 20:52:24 +01:00
2011-01-29 22:50:29 +01:00
while ((s = bufferedreader.readLine()) != null) {
this.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) {
2011-01-29 22:50:29 +01:00
a.warning("Failed to load ban list: " + exception);
2010-12-26 03:20:29 +01:00
}
}
private void f() {
try {
2011-01-29 22:50:29 +01:00
PrintWriter printwriter = new PrintWriter(new FileWriter(this.i, false));
Iterator iterator = this.f.iterator();
2010-12-28 20:52:24 +01:00
2011-01-29 22:50:29 +01:00
while (iterator.hasNext()) {
String s = (String) iterator.next();
printwriter.println(s);
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
printwriter.close();
} catch (Exception exception) {
2011-01-29 22:50:29 +01:00
a.warning("Failed to save ban list: " + exception);
2010-12-26 03:20:29 +01:00
}
}
2010-12-28 20:52:24 +01:00
public void c(String s) {
2011-01-29 22:50:29 +01:00
this.g.add(s.toLowerCase());
this.h();
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
public void d(String s) {
2011-01-29 22:50:29 +01:00
this.g.remove(s.toLowerCase());
this.h();
2010-12-26 03:20:29 +01:00
}
private void g() {
try {
2011-01-29 22:50:29 +01:00
this.g.clear();
BufferedReader bufferedreader = new BufferedReader(new FileReader(this.j));
String s = "";
2010-12-28 20:52:24 +01:00
2011-01-29 22:50:29 +01:00
while ((s = bufferedreader.readLine()) != null) {
this.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) {
2011-01-29 22:50:29 +01:00
a.warning("Failed to load ip ban list: " + exception);
2010-12-26 03:20:29 +01:00
}
}
private void h() {
try {
2011-01-29 22:50:29 +01:00
PrintWriter printwriter = new PrintWriter(new FileWriter(this.j, false));
Iterator iterator = this.g.iterator();
while (iterator.hasNext()) {
String s = (String) iterator.next();
2010-12-28 20:52:24 +01:00
2011-01-29 22:50:29 +01:00
printwriter.println(s);
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
printwriter.close();
} catch (Exception exception) {
2011-01-29 22:50:29 +01:00
a.warning("Failed to save ip ban list: " + exception);
2010-12-26 03:20:29 +01:00
}
}
2010-12-28 20:52:24 +01:00
public void e(String s) {
2011-01-29 22:50:29 +01:00
this.h.add(s.toLowerCase());
this.j();
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
public void f(String s) {
2011-01-29 22:50:29 +01:00
this.h.remove(s.toLowerCase());
this.j();
2010-12-26 03:20:29 +01:00
}
private void i() {
try {
2011-01-29 22:50:29 +01:00
this.h.clear();
BufferedReader bufferedreader = new BufferedReader(new FileReader(this.k));
String s = "";
2010-12-28 20:52:24 +01:00
2011-01-29 22:50:29 +01:00
while ((s = bufferedreader.readLine()) != null) {
this.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) {
2011-01-29 22:50:29 +01:00
a.warning("Failed to load ip ban list: " + exception);
2010-12-26 03:20:29 +01:00
}
}
private void j() {
try {
2011-01-29 22:50:29 +01:00
PrintWriter printwriter = new PrintWriter(new FileWriter(this.k, false));
Iterator iterator = this.h.iterator();
while (iterator.hasNext()) {
String s = (String) iterator.next();
2010-12-28 20:52:24 +01:00
2011-01-29 22:50:29 +01:00
printwriter.println(s);
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
printwriter.close();
} catch (Exception exception) {
2011-01-29 22:50:29 +01:00
a.warning("Failed to save ip ban list: " + exception);
2010-12-26 03:20:29 +01:00
}
}
2010-12-28 20:52:24 +01:00
public boolean g(String s) {
2011-01-29 22:50:29 +01:00
return this.h.contains(s.trim().toLowerCase());
2010-12-26 03:20:29 +01:00
}
2011-01-29 22:50:29 +01:00
public EntityPlayer h(String s) {
for (int i = 0; i < this.b.size(); ++i) {
EntityPlayer entityplayer = (EntityPlayer) this.b.get(i);
2010-12-28 20:52:24 +01:00
2011-01-29 22:50:29 +01:00
if (entityplayer.name.equalsIgnoreCase(s)) {
return entityplayer;
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) {
2011-01-29 22:50:29 +01:00
EntityPlayer entityplayer = this.h(s);
2010-12-28 20:52:24 +01:00
2011-01-29 22:50:29 +01:00
if (entityplayer != null) {
entityplayer.a.b((Packet) (new Packet3Chat(s1)));
2010-12-26 03:20:29 +01:00
}
}
2011-01-29 22:50:29 +01:00
public void a(double d0, double d1, double d2, double d3, Packet packet) {
for (int i = 0; i < this.b.size(); ++i) {
EntityPlayer entityplayer = (EntityPlayer) this.b.get(i);
double d4 = d0 - entityplayer.locX;
double d5 = d1 - entityplayer.locY;
double d6 = d2 - entityplayer.locZ;
2010-12-28 20:52:24 +01:00
2011-01-29 22:50:29 +01:00
if (d4 * d4 + d5 * d5 + d6 * d6 < d3 * d3) {
entityplayer.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);
2011-01-29 22:50:29 +01:00
for (int i = 0; i < this.b.size(); ++i) {
EntityPlayer entityplayer = (EntityPlayer) this.b.get(i);
2010-12-28 20:52:24 +01:00
2011-01-29 22:50:29 +01:00
if (this.g(entityplayer.name)) {
entityplayer.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) {
2011-01-29 22:50:29 +01:00
EntityPlayer entityplayer = this.h(s);
2010-12-28 20:52:24 +01:00
2011-01-29 22:50:29 +01:00
if (entityplayer != null) {
entityplayer.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() {
2011-01-29 22:50:29 +01:00
for (int i = 0; i < this.b.size(); ++i) {
this.l.a((EntityPlayer) this.b.get(i));
2010-12-26 03:20:29 +01:00
}
}
2010-12-28 20:52:24 +01:00
2011-01-29 22:50:29 +01:00
public void a(int i, int j, int k, TileEntity tileentity) {}
2010-12-26 03:20:29 +01:00
}