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-30 06:35:30 +01:00
|
|
|
import org.bukkit.craftbukkit.CraftPlayer;
|
2010-12-28 20:52:24 +01:00
|
|
|
|
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;
|
2010-12-26 03:20:29 +01:00
|
|
|
|
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-02 07:36:27 +01:00
|
|
|
public List<EntityPlayerMP> b;
|
2010-12-26 03:20:29 +01:00
|
|
|
private MinecraftServer c;
|
|
|
|
private PlayerManager d;
|
|
|
|
private int e;
|
2011-01-02 07:36:27 +01:00
|
|
|
private Set<String> f;
|
|
|
|
private Set<String> g;
|
|
|
|
private Set<String> 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) {
|
2011-01-03 20:41:23 +01:00
|
|
|
minecraftserver.server = new CraftServer(minecraftserver, this); // CraftBukkit
|
2010-12-28 20:52:24 +01:00
|
|
|
server = minecraftserver.server; // Craftbukkit
|
|
|
|
|
2011-01-02 07:36:27 +01:00
|
|
|
b = new ArrayList<EntityPlayerMP>();
|
|
|
|
f = new HashSet<String>();
|
|
|
|
g = new HashSet<String>();
|
|
|
|
h = new HashSet<String>();
|
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);
|
|
|
|
l.b(entityplayermp);
|
|
|
|
c.e.A.d((int) entityplayermp.p >> 4, (int) entityplayermp.r >> 4);
|
|
|
|
for (; c.e.a(entityplayermp, entityplayermp.z).size() != 0; entityplayermp.a(entityplayermp.p, entityplayermp.q + 1.0D, entityplayermp.r)) {
|
|
|
|
;
|
2010-12-26 03:20:29 +01:00
|
|
|
}
|
2010-12-28 20:52:24 +01:00
|
|
|
c.e.a(entityplayermp);
|
|
|
|
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(entityplayermp);
|
|
|
|
b.remove(entityplayermp);
|
|
|
|
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) {
|
2010-12-28 23:22:26 +01:00
|
|
|
// Craftbukkit note: this entire method needs to be changed
|
|
|
|
// 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, c.e, s, new ItemInWorldManager(c.e));
|
2010-12-30 06:35:30 +01:00
|
|
|
PlayerLoginEvent event = new PlayerLoginEvent(Type.PLAYER_LOGIN, new CraftPlayer(server, entity));
|
2010-12-28 20:52:24 +01:00
|
|
|
|
2010-12-28 23:22:26 +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
|
|
|
|
|
|
|
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
|
|
|
}
|
2011-01-01 14:06:04 +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 23:22:26 +01:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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(entityplayermp);
|
|
|
|
d.b(entityplayermp);
|
|
|
|
b.remove(entityplayermp);
|
|
|
|
c.e.e(entityplayermp);
|
|
|
|
EntityPlayerMP entityplayermp1 = new EntityPlayerMP(c, c.e, entityplayermp.aw, new ItemInWorldManager(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(entityplayermp1, entityplayermp1.z).size() != 0; entityplayermp1.a(entityplayermp1.p, entityplayermp1.q + 1.0D, entityplayermp1.r)) {
|
|
|
|
;
|
2010-12-26 03:20:29 +01:00
|
|
|
}
|
2010-12-28 20:52:24 +01:00
|
|
|
entityplayermp1.a.b(new Packet9());
|
|
|
|
entityplayermp1.a.a(entityplayermp1.p, entityplayermp1.q, entityplayermp1.r, entityplayermp1.v, entityplayermp1.w);
|
|
|
|
d.a(entityplayermp1);
|
|
|
|
c.e.a(entityplayermp1);
|
|
|
|
b.add(entityplayermp1);
|
|
|
|
entityplayermp1.k();
|
|
|
|
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
|
|
|
}
|
2010-12-28 20:52:24 +01:00
|
|
|
|
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(new FileReader(i));
|
|
|
|
|
|
|
|
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 {
|
2010-12-28 20:52:24 +01:00
|
|
|
PrintWriter printwriter = new PrintWriter(new FileWriter(i, false));
|
|
|
|
String s;
|
|
|
|
|
2011-01-02 07:36:27 +01:00
|
|
|
for (Iterator<String> 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(new FileReader(j));
|
|
|
|
|
|
|
|
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 {
|
2010-12-28 20:52:24 +01:00
|
|
|
PrintWriter printwriter = new PrintWriter(new FileWriter(j, false));
|
|
|
|
String s;
|
|
|
|
|
2011-01-02 07:36:27 +01:00
|
|
|
for (Iterator<String> 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(new FileReader(k));
|
|
|
|
|
|
|
|
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 {
|
2010-12-28 20:52:24 +01:00
|
|
|
PrintWriter printwriter = new PrintWriter(new FileWriter(k, false));
|
|
|
|
String s;
|
|
|
|
|
2011-01-02 07:36:27 +01:00
|
|
|
for (Iterator<String> 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(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
|
|
|
|
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(packet3chat);
|
2010-12-26 03:20:29 +01:00
|
|
|
}
|
|
|
|
}
|
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 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
|
|
|
}
|