PageRenderTime 1208ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/src/OServerConfigurationManager.java

http://github.com/traitor/Minecraft-Server-Mod
Java | 461 lines | 383 code | 61 blank | 17 comment | 68 complexity | 8efbf63ec2c14190988fd7eaa65a03ef MD5 | raw file
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileReader;
  4. import java.io.FileWriter;
  5. import java.io.PrintWriter;
  6. import java.util.ArrayList;
  7. import java.util.HashSet;
  8. import java.util.List;
  9. import java.util.Set;
  10. import java.util.logging.Logger;
  11. import net.minecraft.server.MinecraftServer;
  12. public class OServerConfigurationManager {
  13. public static Logger a = Logger.getLogger("Minecraft");
  14. // hMod set list to contain <OEntityPlayerMP> objects.
  15. public List<OEntityPlayerMP> b = new ArrayList();
  16. private MinecraftServer c;
  17. private OPlayerManager d;
  18. private int e;
  19. // hMod set these to Set<String> to remove errors and warnings.
  20. private Set<String> f = new HashSet();
  21. private Set<String> g = new HashSet();
  22. private Set<String> h = new HashSet();
  23. private Set<String> i = new HashSet();
  24. private File j;
  25. private File k;
  26. private File l;
  27. private File m;
  28. private OIPlayerFileData n;
  29. private boolean o;
  30. public OServerConfigurationManager(MinecraftServer paramMinecraftServer) {
  31. etc.setServer(paramMinecraftServer);
  32. etc.getInstance().loadData();
  33. a.info("Note: your current classpath is: " + System.getProperty("java.class.path", "*UNKNOWN*"));
  34. if (!etc.getInstance().getTainted())
  35. a.info("Hey0 Server Mod Build " + etc.getInstance().getVersion());
  36. else
  37. a.info("hMod Build Information: " + etc.getInstance().getVersionStr());
  38. c = paramMinecraftServer;
  39. j = paramMinecraftServer.a("banned-players.txt");
  40. k = paramMinecraftServer.a("banned-ips.txt");
  41. l = paramMinecraftServer.a("ops.txt");
  42. m = paramMinecraftServer.a("white-list.txt");
  43. d = new OPlayerManager(paramMinecraftServer);
  44. e = paramMinecraftServer.d.a("max-players", 20);
  45. o = paramMinecraftServer.d.a("white-list", false);
  46. g();
  47. i();
  48. k();
  49. m();
  50. h();
  51. j();
  52. l();
  53. n();
  54. }
  55. public void a(OWorldServer paramOWorldServer) {
  56. n = paramOWorldServer.o().d();
  57. }
  58. public int a() {
  59. return d.b();
  60. }
  61. public void a(OEntityPlayerMP paramOEntityPlayerMP) {
  62. b.add(paramOEntityPlayerMP);
  63. n.b(paramOEntityPlayerMP);
  64. c.e.u.c((int) paramOEntityPlayerMP.aK >> 4, (int) paramOEntityPlayerMP.aM >> 4);
  65. while (c.e.a(paramOEntityPlayerMP, paramOEntityPlayerMP.aU).size() != 0)
  66. paramOEntityPlayerMP.a(paramOEntityPlayerMP.aK, paramOEntityPlayerMP.aL + 1.0D, paramOEntityPlayerMP.aM);
  67. c.e.a(paramOEntityPlayerMP);
  68. d.a(paramOEntityPlayerMP);
  69. // hMod: Handle login (send MOTD and call hook)
  70. String[] motd = etc.getInstance().getMotd();
  71. if (!(motd.length == 1 && motd[0].equals("")))
  72. for (String str : etc.getInstance().getMotd())
  73. paramOEntityPlayerMP.a.b(new OPacket3Chat(str));
  74. etc.getLoader().callHook(PluginLoader.Hook.LOGIN, paramOEntityPlayerMP.getPlayer());
  75. }
  76. public void b(OEntityPlayerMP paramOEntityPlayerMP) {
  77. d.c(paramOEntityPlayerMP);
  78. }
  79. public void c(OEntityPlayerMP paramOEntityPlayerMP) {
  80. n.a(paramOEntityPlayerMP);
  81. c.e.d(paramOEntityPlayerMP);
  82. b.remove(paramOEntityPlayerMP);
  83. d.b(paramOEntityPlayerMP);
  84. }
  85. public OEntityPlayerMP a(ONetLoginHandler paramONetLoginHandler, String paramString1, String paramString2) {
  86. if (!etc.getLoader().isLoaded())
  87. paramONetLoginHandler.a("The server is not finished loading yet!");
  88. if (f.contains(paramString1.trim().toLowerCase())) {
  89. paramONetLoginHandler.a("You are banned from this server!");
  90. return null;
  91. }
  92. // hMod: whole section below is modified to handle whitelists etc
  93. OEntityPlayerMP temp = new OEntityPlayerMP(c, c.e, paramString1, new OItemInWorldManager(c.e));
  94. Player player = temp.getPlayer();
  95. String str = paramONetLoginHandler.b.b().toString();
  96. str = str.substring(str.indexOf("/") + 1);
  97. str = str.substring(0, str.indexOf(":"));
  98. if (g.contains(str)) {
  99. paramONetLoginHandler.a("Your IP address is banned from this server!");
  100. return null;
  101. }
  102. if (!g(paramString1) || (etc.getInstance().isWhitelistEnabled() && !(etc.getDataSource().isUserOnWhitelist(paramString1) || player.isAdmin()))) {
  103. paramONetLoginHandler.a(etc.getInstance().getWhitelistMessage());
  104. return null;
  105. } else if (b.size() >= e && (!etc.getInstance().isReservelistEnabled() || !etc.getDataSource().isUserOnReserveList(paramString1))) {
  106. paramONetLoginHandler.a("The server is full!");
  107. return null;
  108. }
  109. if (!player.getIps()[0].equals("")) {
  110. boolean kick = true;
  111. for (int i = 0; i < player.getIps().length; i++)
  112. if (!player.getIps()[i].equals("") && str.equals(player.getIps()[i]))
  113. kick = false;
  114. if (kick) {
  115. paramONetLoginHandler.a("IP doesn't match specified IP.");
  116. return null;
  117. }
  118. }
  119. for (int i1 = 0; i1 < b.size(); i1++) {
  120. OEntityPlayerMP localOEntityPlayerMP = b.get(i1);
  121. if (localOEntityPlayerMP.r.equalsIgnoreCase(paramString1))
  122. localOEntityPlayerMP.a.a("You logged in from another location");
  123. }
  124. // hMod: user passed basic login check, inform plugins.
  125. Object obj = etc.getLoader().callHook(PluginLoader.Hook.LOGINCHECK, paramString1);
  126. if (obj instanceof String) {
  127. String result = (String) obj;
  128. if (result != null && !result.equals("")) {
  129. paramONetLoginHandler.a(result);
  130. return null;
  131. }
  132. }
  133. return temp;
  134. }
  135. /**
  136. * Returns the list of bans
  137. *
  138. * @return
  139. */
  140. public String getBans() {
  141. StringBuilder builder = new StringBuilder();
  142. int l = 0;
  143. for (Object o : f) {
  144. if (l > 0)
  145. builder.append(", ");
  146. builder.append(o);
  147. l++;
  148. }
  149. return builder.toString();
  150. }
  151. /**
  152. * Returns the list of IP bans
  153. *
  154. * @return
  155. */
  156. public String getIpBans() {
  157. StringBuilder builder = new StringBuilder();
  158. int l = 0;
  159. for (Object o : g) {
  160. if (l > 0)
  161. builder.append(", ");
  162. builder.append(o);
  163. l++;
  164. }
  165. return builder.toString();
  166. }
  167. public OEntityPlayerMP d(OEntityPlayerMP paramOEntityPlayerMP) {
  168. c.k.a(paramOEntityPlayerMP);
  169. c.k.b(paramOEntityPlayerMP);
  170. d.b(paramOEntityPlayerMP);
  171. b.remove(paramOEntityPlayerMP);
  172. c.e.e(paramOEntityPlayerMP);
  173. OChunkCoordinates localOChunkCoordinates1 = paramOEntityPlayerMP.H();
  174. OEntityPlayerMP localOEntityPlayerMP = new OEntityPlayerMP(c, c.e, paramOEntityPlayerMP.r, new OItemInWorldManager(c.e));
  175. localOEntityPlayerMP.aB = paramOEntityPlayerMP.aB;
  176. localOEntityPlayerMP.a = paramOEntityPlayerMP.a;
  177. if (localOChunkCoordinates1 != null) {
  178. OChunkCoordinates localOChunkCoordinates2 = OEntityPlayer.a(c.e, localOChunkCoordinates1);
  179. if (localOChunkCoordinates2 != null) {
  180. localOEntityPlayerMP.c(localOChunkCoordinates2.a + 0.5F, localOChunkCoordinates2.b + 0.1F, localOChunkCoordinates2.c + 0.5F, 0.0F, 0.0F);
  181. localOEntityPlayerMP.a(localOChunkCoordinates1);
  182. } else
  183. localOEntityPlayerMP.a.b(new OPacket70(0));
  184. }
  185. c.e.u.c((int) localOEntityPlayerMP.aK >> 4, (int) localOEntityPlayerMP.aM >> 4);
  186. while (c.e.a(localOEntityPlayerMP, localOEntityPlayerMP.aU).size() != 0)
  187. localOEntityPlayerMP.a(localOEntityPlayerMP.aK, localOEntityPlayerMP.aL + 1.0D, localOEntityPlayerMP.aM);
  188. localOEntityPlayerMP.a.b(new OPacket9());
  189. localOEntityPlayerMP.a.a(localOEntityPlayerMP.aK, localOEntityPlayerMP.aL, localOEntityPlayerMP.aM, localOEntityPlayerMP.aQ, localOEntityPlayerMP.aR);
  190. d.a(localOEntityPlayerMP);
  191. c.e.a(localOEntityPlayerMP);
  192. b.add(localOEntityPlayerMP);
  193. localOEntityPlayerMP.m();
  194. localOEntityPlayerMP.t();
  195. return localOEntityPlayerMP;
  196. }
  197. public void b() {
  198. d.a();
  199. }
  200. public void a(int paramInt1, int paramInt2, int paramInt3) {
  201. d.a(paramInt1, paramInt2, paramInt3);
  202. }
  203. public void a(OPacket paramOPacket) {
  204. for (int i1 = 0; i1 < b.size(); i1++) {
  205. OEntityPlayerMP localOEntityPlayerMP = b.get(i1);
  206. localOEntityPlayerMP.a.b(paramOPacket);
  207. }
  208. }
  209. public String c() {
  210. String str = "";
  211. for (int i1 = 0; i1 < b.size(); i1++) {
  212. if (i1 > 0)
  213. str = str + ", ";
  214. str = str + b.get(i1).r;
  215. }
  216. return str;
  217. }
  218. public void a(String paramString) {
  219. f.add(paramString.toLowerCase());
  220. h();
  221. }
  222. public void b(String paramString) {
  223. f.remove(paramString.toLowerCase());
  224. h();
  225. }
  226. private void g() {
  227. try {
  228. f.clear();
  229. BufferedReader localBufferedReader = new BufferedReader(new FileReader(j));
  230. String str = "";
  231. while ((str = localBufferedReader.readLine()) != null)
  232. f.add(str.trim().toLowerCase());
  233. localBufferedReader.close();
  234. } catch (Exception localException) {
  235. a.warning("Failed to load ban list: " + localException);
  236. }
  237. }
  238. private void h() {
  239. try {
  240. PrintWriter localPrintWriter = new PrintWriter(new FileWriter(j, false));
  241. for (String str : f)
  242. localPrintWriter.println(str);
  243. localPrintWriter.close();
  244. } catch (Exception localException) {
  245. a.warning("Failed to save ban list: " + localException);
  246. }
  247. }
  248. public void c(String paramString) {
  249. g.add(paramString.toLowerCase());
  250. j();
  251. }
  252. public void d(String paramString) {
  253. g.remove(paramString.toLowerCase());
  254. j();
  255. }
  256. private void i() {
  257. try {
  258. g.clear();
  259. BufferedReader localBufferedReader = new BufferedReader(new FileReader(k));
  260. String str = "";
  261. while ((str = localBufferedReader.readLine()) != null)
  262. g.add(str.trim().toLowerCase());
  263. localBufferedReader.close();
  264. } catch (Exception localException) {
  265. a.warning("Failed to load ip ban list: " + localException);
  266. }
  267. }
  268. private void j() {
  269. try {
  270. PrintWriter localPrintWriter = new PrintWriter(new FileWriter(k, false));
  271. for (String str : g)
  272. localPrintWriter.println(str);
  273. localPrintWriter.close();
  274. } catch (Exception localException) {
  275. a.warning("Failed to save ip ban list: " + localException);
  276. }
  277. }
  278. public void e(String paramString) {
  279. h.add(paramString.toLowerCase());
  280. l();
  281. }
  282. public void f(String paramString) {
  283. h.remove(paramString.toLowerCase());
  284. l();
  285. }
  286. private void k() {
  287. try {
  288. h.clear();
  289. BufferedReader localBufferedReader = new BufferedReader(new FileReader(l));
  290. String str = "";
  291. while ((str = localBufferedReader.readLine()) != null)
  292. h.add(str.trim().toLowerCase());
  293. localBufferedReader.close();
  294. } catch (Exception localException) {
  295. a.warning("Failed to load ip ban list: " + localException);
  296. }
  297. }
  298. private void l() {
  299. try {
  300. PrintWriter localPrintWriter = new PrintWriter(new FileWriter(l, false));
  301. for (String str : h)
  302. localPrintWriter.println(str);
  303. localPrintWriter.close();
  304. } catch (Exception localException) {
  305. a.warning("Failed to save ip ban list: " + localException);
  306. }
  307. }
  308. private void m() {
  309. try {
  310. i.clear();
  311. BufferedReader localBufferedReader = new BufferedReader(new FileReader(m));
  312. String str = "";
  313. while ((str = localBufferedReader.readLine()) != null)
  314. i.add(str.trim().toLowerCase());
  315. localBufferedReader.close();
  316. } catch (Exception localException) {
  317. a.warning("Failed to load white-list: " + localException);
  318. }
  319. }
  320. private void n() {
  321. try {
  322. PrintWriter localPrintWriter = new PrintWriter(new FileWriter(m, false));
  323. for (String str : i)
  324. localPrintWriter.println(str);
  325. localPrintWriter.close();
  326. } catch (Exception localException) {
  327. a.warning("Failed to save white-list: " + localException);
  328. }
  329. }
  330. public boolean g(String paramString) {
  331. paramString = paramString.trim().toLowerCase();
  332. return (!o) || (h.contains(paramString)) || (i.contains(paramString));
  333. }
  334. public boolean h(String paramString) {
  335. return h.contains(paramString.trim().toLowerCase());
  336. }
  337. public OEntityPlayerMP i(String paramString) {
  338. for (int i1 = 0; i1 < b.size(); i1++) {
  339. OEntityPlayerMP localOEntityPlayerMP = b.get(i1);
  340. if (localOEntityPlayerMP.r.equalsIgnoreCase(paramString))
  341. return localOEntityPlayerMP;
  342. }
  343. return null;
  344. }
  345. public void a(String paramString1, String paramString2) {
  346. OEntityPlayerMP localOEntityPlayerMP = i(paramString1);
  347. if (localOEntityPlayerMP != null)
  348. localOEntityPlayerMP.a.b(new OPacket3Chat(paramString2));
  349. }
  350. public void a(double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4, OPacket paramOPacket) {
  351. for (int i1 = 0; i1 < b.size(); i1++) {
  352. OEntityPlayerMP localOEntityPlayerMP = b.get(i1);
  353. double d1 = paramDouble1 - localOEntityPlayerMP.aK;
  354. double d2 = paramDouble2 - localOEntityPlayerMP.aL;
  355. double d3 = paramDouble3 - localOEntityPlayerMP.aM;
  356. if (d1 * d1 + d2 * d2 + d3 * d3 < paramDouble4 * paramDouble4)
  357. localOEntityPlayerMP.a.b(paramOPacket);
  358. }
  359. }
  360. public void j(String paramString) {
  361. OPacket3Chat localOPacket3Chat = new OPacket3Chat(paramString);
  362. for (int i1 = 0; i1 < b.size(); i1++) {
  363. OEntityPlayerMP localOEntityPlayerMP = b.get(i1);
  364. if (h(localOEntityPlayerMP.r))
  365. localOEntityPlayerMP.a.b(localOPacket3Chat);
  366. }
  367. }
  368. public boolean a(String paramString, OPacket paramOPacket) {
  369. OEntityPlayerMP localOEntityPlayerMP = i(paramString);
  370. if (localOEntityPlayerMP != null) {
  371. localOEntityPlayerMP.a.b(paramOPacket);
  372. return true;
  373. }
  374. return false;
  375. }
  376. public void d() {
  377. for (int i1 = 0; i1 < b.size(); i1++)
  378. n.a(b.get(i1));
  379. }
  380. public void a(int paramInt1, int paramInt2, int paramInt3, OTileEntity paramOTileEntity) {
  381. // hMod: fix sign updating in beta 1.1_02
  382. // Check if bg (TileEntity) is a Sign
  383. if (paramOTileEntity instanceof OTileEntitySign)
  384. d.sendPacketToChunk(((OTileEntitySign) paramOTileEntity).e(), paramInt1, paramInt2, paramInt3);
  385. }
  386. public void k(String paramString) {
  387. i.add(paramString);
  388. n();
  389. }
  390. public void l(String paramString) {
  391. i.remove(paramString);
  392. n();
  393. }
  394. public Set e() {
  395. return i;
  396. }
  397. public void f() {
  398. m();
  399. }
  400. }