Commits
Dinnerbone authored a799b1463b0
1 + | package net.minecraft.server; |
2 + | |
3 + | import java.awt.GraphicsEnvironment; |
4 + | import java.io.File; |
5 + | import java.io.IOException; |
6 + | import java.io.PrintStream; |
7 + | import java.net.InetAddress; |
8 + | import java.net.UnknownHostException; |
9 + | import java.util.ArrayList; |
10 + | import java.util.Collections; |
11 + | import java.util.HashMap; |
12 + | import java.util.List; |
13 + | import java.util.logging.Level; |
14 + | import java.util.logging.Logger; |
15 + | import org.bukkit.craftbukkit.CraftServer; |
16 + | |
17 + | public class MinecraftServer |
18 + | implements fn, Runnable { |
19 + | |
20 + | public static Logger a = Logger.getLogger("Minecraft"); |
21 + | public static HashMap<String, Integer> b = new HashMap<String, Integer>(); |
22 + | public eh c; |
23 + | public dt d; |
24 + | public fm e; |
25 + | public hl f; |
26 + | private boolean o = true; |
27 + | public boolean g = false; |
28 + | int h = 0; |
29 + | public String i; |
30 + | public int j; |
31 + | private List p = new ArrayList(); |
32 + | private List q = Collections.synchronizedList(new ArrayList()); |
33 + | public hp k; |
34 + | public boolean l; |
35 + | public boolean m; |
36 + | public boolean n; |
37 + | public CraftServer server; // CraftBukkit |
38 + | |
39 + | public MinecraftServer() { |
40 + | new cn(this); |
41 + | } |
42 + | |
43 + | private boolean d() { |
44 + | cl localcl = new cl(this); |
45 + | |
46 + | localcl.setDaemon(true); |
47 + | localcl.start(); |
48 + | |
49 + | hb.a(); |
50 + | a.info("Starting minecraft server version Beta 1.1"); |
51 + | |
52 + | if (Runtime.getRuntime().maxMemory() / 1024L / 1024L < 512L) { |
53 + | a.warning("**** NOT ENOUGH RAM!"); |
54 + | a.warning("To start the server with more ram, launch it as \"java -Xmx1024M -Xms1024M -jar minecraft_server.jar\""); |
55 + | } |
56 + | |
57 + | a.info("Loading properties"); |
58 + | this.d = new dt(new File("server.properties")); |
59 + | String str1 = this.d.a("server-ip", ""); |
60 + | |
61 + | this.l = this.d.a("online-mode", true); |
62 + | this.m = this.d.a("spawn-animals", true); |
63 + | this.n = this.d.a("pvp", true); |
64 + | |
65 + | InetAddress localInetAddress = null; |
66 + | if (str1.length() > 0) { |
67 + | try { |
68 + | localInetAddress = InetAddress.getByName(str1); |
69 + | } catch (UnknownHostException ex) { |
70 + | Logger.getLogger(MinecraftServer.class.getName()).log(Level.SEVERE, null, ex); |
71 + | } |
72 + | } |
73 + | int i1 = this.d.a("server-port", 25565); |
74 + | |
75 + | a.info("Starting Minecraft server on " + (str1.length() == 0 ? "*" : str1) + ":" + i1); |
76 + | try { |
77 + | this.c = new eh(this, localInetAddress, i1); |
78 + | } catch (Throwable localIOException) { |
79 + | a.warning("**** FAILED TO BIND TO PORT!"); |
80 + | a.log(Level.WARNING, "The exception was: " + localIOException.toString()); |
81 + | a.warning("Perhaps a server is already running on that port?"); |
82 + | return false; |
83 + | } |
84 + | |
85 + | if (!this.l) { |
86 + | a.warning("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!"); |
87 + | a.warning("The server will make no attempt to authenticate usernames. Beware."); |
88 + | a.warning("While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose."); |
89 + | a.warning("To change this, set \"online-mode\" to \"true\" in the server.settings file."); |
90 + | } |
91 + | |
92 + | this.f = new hl(this); |
93 + | this.k = new hp(this); |
94 + | |
95 + | server = new CraftServer(this, "1.1"); // CraftBukkit |
96 + | |
97 + | String str2 = this.d.a("level-name", "world"); |
98 + | a.info("Preparing level \"" + str2 + "\""); |
99 + | c(str2); |
100 + | a.info("Done! For help, type \"help\" or \"?\""); |
101 + | |
102 + | return true; |
103 + | } |
104 + | |
105 + | private void c(String paramString) { |
106 + | a.info("Preparing start region"); |
107 + | this.e = new fm(this, new File("."), paramString, this.d.a("hellworld", false) ? -1 : 0); |
108 + | this.e.a(new fj(this)); |
109 + | this.e.k = (this.d.a("spawn-monsters", true) ? 1 : 0); |
110 + | this.f.a(this.e); |
111 + | int i1 = 10; |
112 + | for (int i2 = -i1; i2 <= i1; i2++) { |
113 + | a("Preparing spawn area", (i2 + i1) * 100 / (i1 + i1 + 1)); |
114 + | for (int i3 = -i1; i3 <= i1; i3++) { |
115 + | if (!this.o) { |
116 + | return; |
117 + | } |
118 + | this.e.A.d((this.e.m >> 4) + i2, (this.e.o >> 4) + i3); |
119 + | } |
120 + | } |
121 + | e(); |
122 + | } |
123 + | |
124 + | private void a(String paramString, int paramInt) { |
125 + | this.i = paramString; |
126 + | this.j = paramInt; |
127 + | System.out.println(paramString + ": " + paramInt + "%"); |
128 + | } |
129 + | |
130 + | private void e() { |
131 + | this.i = null; |
132 + | this.j = 0; |
133 + | } |
134 + | |
135 + | private void f() { |
136 + | a.info("Saving chunks"); |
137 + | this.e.a(true, null); |
138 + | } |
139 + | |
140 + | private void g() { |
141 + | a.info("Stopping server"); |
142 + | if (this.f != null) { |
143 + | this.f.d(); |
144 + | } |
145 + | if (this.e != null) { |
146 + | f(); |
147 + | } |
148 + | } |
149 + | |
150 + | public void a() { |
151 + | this.o = false; |
152 + | } |
153 + | |
154 + | public void run() { |
155 + | try { |
156 + | if (d()) { |
157 + | long l1 = System.currentTimeMillis(); |
158 + | long l2 = 0L; |
159 + | while (this.o) { |
160 + | long l3 = System.currentTimeMillis(); |
161 + | long l4 = l3 - l1; |
162 + | if (l4 > 2000L) { |
163 + | a.warning("Can't keep up! Did the system time change, or is the server overloaded?"); |
164 + | l4 = 2000L; |
165 + | } |
166 + | if (l4 < 0L) { |
167 + | a.warning("Time ran backwards! Did the system time change?"); |
168 + | l4 = 0L; |
169 + | } |
170 + | l2 += l4; |
171 + | l1 = l3; |
172 + | |
173 + | while (l2 > 50L) { |
174 + | l2 -= 50L; |
175 + | h(); |
176 + | } |
177 + | |
178 + | Thread.sleep(1L); |
179 + | } |
180 + | } else { |
181 + | while (this.o) { |
182 + | b(); |
183 + | try { |
184 + | Thread.sleep(10L); |
185 + | } catch (InterruptedException localInterruptedException1) { |
186 + | localInterruptedException1.printStackTrace(); |
187 + | } |
188 + | } |
189 + | } |
190 + | } catch (Exception localException) { |
191 + | localException.printStackTrace(); |
192 + | a.log(Level.SEVERE, "Unexpected exception", localException); |
193 + | while (this.o) { |
194 + | b(); |
195 + | try { |
196 + | Thread.sleep(10L); |
197 + | } catch (InterruptedException localInterruptedException2) { |
198 + | localInterruptedException2.printStackTrace(); |
199 + | } |
200 + | } |
201 + | } finally { |
202 + | g(); |
203 + | this.g = true; |
204 + | System.exit(0); |
205 + | } |
206 + | } |
207 + | |
208 + | private void h() { |
209 + | ArrayList localArrayList = new ArrayList(); |
210 + | for (String str : b.keySet()) { |
211 + | int i2 = ((Integer) b.get(str)).intValue(); |
212 + | if (i2 > 0) { |
213 + | b.put(str, Integer.valueOf(i2 - 1)); |
214 + | } else { |
215 + | localArrayList.add(str); |
216 + | } |
217 + | } |
218 + | for (int i1 = 0; i1 < localArrayList.size(); i1++) { |
219 + | b.remove(localArrayList.get(i1)); |
220 + | } |
221 + | |
222 + | el.a(); |
223 + | bn.a(); |
224 + | this.h += 1; |
225 + | |
226 + | if (this.h % 20 == 0) { |
227 + | this.f.a(new hc(this.e.e)); |
228 + | } |
229 + | |
230 + | this.e.f(); |
231 + | while (this.e.d()); |
232 + | this.e.c(); |
233 + | this.c.a(); |
234 + | this.f.b(); |
235 + | this.k.a(); |
236 + | |
237 + | for (int i1 = 0; i1 < this.p.size(); i1++) { |
238 + | ((fc) this.p.get(i1)).a(); |
239 + | } |
240 + | try { |
241 + | b(); |
242 + | } catch (Exception localException) { |
243 + | a.log(Level.WARNING, "Unexpected exception while parsing console command", localException); |
244 + | } |
245 + | } |
246 + | |
247 + | public void a(String paramString, fn paramfn) { |
248 + | this.q.add(new at(paramString, paramfn)); |
249 + | } |
250 + | |
251 + | public void b() { |
252 + | while (this.q.size() > 0) { |
253 + | at localat = (at) this.q.remove(0); |
254 + | String str1 = localat.a; |
255 + | fn localfn = localat.b; |
256 + | String str2 = localfn.c(); |
257 + | if ((str1.toLowerCase().startsWith("help")) || (str1.toLowerCase().startsWith("?"))) { |
258 + | localfn.b("To run the server without a gui, start it like this:"); |
259 + | localfn.b(" java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui"); |
260 + | localfn.b("Console commands:"); |
261 + | localfn.b(" help or ? shows this message"); |
262 + | localfn.b(" kick <player> removes a player from the server"); |
263 + | localfn.b(" ban <player> bans a player from the server"); |
264 + | localfn.b(" pardon <player> pardons a banned player so that they can connect again"); |
265 + | localfn.b(" ban-ip <ip> bans an IP address from the server"); |
266 + | localfn.b(" pardon-ip <ip> pardons a banned IP address so that they can connect again"); |
267 + | localfn.b(" op <player> turns a player into an op"); |
268 + | localfn.b(" deop <player> removes op status from a player"); |
269 + | localfn.b(" tp <player1> <player2> moves one player to the same location as another player"); |
270 + | localfn.b(" give <player> <id> [num] gives a player a resource"); |
271 + | localfn.b(" tell <player> <message> sends a private message to a player"); |
272 + | localfn.b(" stop gracefully stops the server"); |
273 + | localfn.b(" save-all forces a server-wide level save"); |
274 + | localfn.b(" save-off disables terrain saving (useful for backup scripts)"); |
275 + | localfn.b(" save-on re-enables terrain saving"); |
276 + | localfn.b(" list lists all currently connected players"); |
277 + | localfn.b(" say <message> broadcasts a message to all players"); |
278 + | } else if (str1.toLowerCase().startsWith("list")) { |
279 + | localfn.b("Connected players: " + this.f.c()); |
280 + | } else if (str1.toLowerCase().startsWith("stop")) { |
281 + | a(str2, "Stopping the server.."); |
282 + | this.o = false; |
283 + | } else if (str1.toLowerCase().startsWith("save-all")) { |
284 + | a(str2, "Forcing save.."); |
285 + | this.e.a(true, null); |
286 + | a(str2, "Save complete."); |
287 + | } else if (str1.toLowerCase().startsWith("save-off")) { |
288 + | a(str2, "Disabling level saving.."); |
289 + | this.e.C = true; |
290 + | } else if (str1.toLowerCase().startsWith("save-on")) { |
291 + | a(str2, "Enabling level saving.."); |
292 + | this.e.C = false; |
293 + | } else { |
294 + | Object localObject1; |
295 + | if (str1.toLowerCase().startsWith("op ")) { |
296 + | localObject1 = str1.substring(str1.indexOf(" ")).trim(); |
297 + | this.f.e((String) localObject1); |
298 + | a(str2, "Opping " + (String) localObject1); |
299 + | this.f.a((String) localObject1, "§eYou are now op!"); |
300 + | } else if (str1.toLowerCase().startsWith("deop ")) { |
301 + | localObject1 = str1.substring(str1.indexOf(" ")).trim(); |
302 + | this.f.f((String) localObject1); |
303 + | this.f.a((String) localObject1, "§eYou are no longer op!"); |
304 + | a(str2, "De-opping " + (String) localObject1); |
305 + | } else if (str1.toLowerCase().startsWith("ban-ip ")) { |
306 + | localObject1 = str1.substring(str1.indexOf(" ")).trim(); |
307 + | this.f.c((String) localObject1); |
308 + | a(str2, "Banning ip " + (String) localObject1); |
309 + | } else if (str1.toLowerCase().startsWith("pardon-ip ")) { |
310 + | localObject1 = str1.substring(str1.indexOf(" ")).trim(); |
311 + | this.f.d((String) localObject1); |
312 + | a(str2, "Pardoning ip " + (String) localObject1); |
313 + | } else { |
314 + | Object localObject2; |
315 + | if (str1.toLowerCase().startsWith("ban ")) { |
316 + | localObject1 = str1.substring(str1.indexOf(" ")).trim(); |
317 + | this.f.a((String) localObject1); |
318 + | a(str2, "Banning " + (String) localObject1); |
319 + | |
320 + | localObject2 = this.f.h((String) localObject1); |
321 + | |
322 + | if (localObject2 != null) { |
323 + | ((fi) localObject2).a.a("Banned by admin"); |
324 + | } |
325 + | |
326 + | } else if (str1.toLowerCase().startsWith("pardon ")) { |
327 + | localObject1 = str1.substring(str1.indexOf(" ")).trim(); |
328 + | this.f.b((String) localObject1); |
329 + | a(str2, "Pardoning " + (String) localObject1); |
330 + | } else if (str1.toLowerCase().startsWith("kick ")) { |
331 + | localObject1 = str1.substring(str1.indexOf(" ")).trim(); |
332 + | localObject2 = null; |
333 + | for (int i1 = 0; i1 < this.f.b.size(); i1++) { |
334 + | fi localfi2 = (fi) this.f.b.get(i1); |
335 + | if (localfi2.aw.equalsIgnoreCase((String) localObject1)) { |
336 + | localObject2 = localfi2; |
337 + | } |
338 + | } |
339 + | |
340 + | if (localObject2 != null) { |
341 + | ((fi) localObject2).a.a("Kicked by admin"); |
342 + | a(str2, "Kicking " + ((fi) localObject2).aw); |
343 + | } else { |
344 + | localfn.b("Can't find user " + (String) localObject1 + ". No kick."); |
345 + | } |
346 + | } else { |
347 + | fi localfi1; |
348 + | if (str1.toLowerCase().startsWith("tp ")) { |
349 + | String[] split = str1.split(" "); |
350 + | if (split.length == 3) { |
351 + | localObject2 = this.f.h(split[1]); |
352 + | localfi1 = this.f.h(split[2]); |
353 + | |
354 + | if (localObject2 == null) { |
355 + | localfn.b("Can't find user " + split[1] + ". No tp."); |
356 + | } else if (localfi1 == null) { |
357 + | localfn.b("Can't find user " + split[2] + ". No tp."); |
358 + | } else { |
359 + | ((fi) localObject2).a.a(localfi1.p, localfi1.q, localfi1.r, localfi1.v, localfi1.w); |
360 + | a(str2, "Teleporting " + split[1] + " to " + split[2] + "."); |
361 + | } |
362 + | } else { |
363 + | localfn.b("Syntax error, please provice a source and a target."); |
364 + | } |
365 + | } else if (str1.toLowerCase().startsWith("give ")) { |
366 + | String[] split = str1.split(" "); |
367 + | if ((split.length != 3) && (split.length != 4)) { |
368 + | return; |
369 + | } |
370 + | |
371 + | localObject2 = split[1]; |
372 + | localfi1 = this.f.h((String) localObject2); |
373 + | |
374 + | if (localfi1 != null) { |
375 + | try { |
376 + | int i2 = Integer.parseInt(split[2]); |
377 + | if (gm.c[i2] != null) { |
378 + | a(str2, "Giving " + localfi1.aw + " some " + i2); |
379 + | int i3 = 1; |
380 + | if (split.length > 3) { |
381 + | i3 = b(split[3], 1); |
382 + | } |
383 + | if (i3 < 1) { |
384 + | i3 = 1; |
385 + | } |
386 + | if (i3 > 64) { |
387 + | i3 = 64; |
388 + | } |
389 + | localfi1.b(new il(i2, i3)); |
390 + | } else { |
391 + | localfn.b("There's no item with id " + i2); |
392 + | } |
393 + | } catch (NumberFormatException localNumberFormatException) { |
394 + | localfn.b("There's no item with id " + split[2]); |
395 + | } |
396 + | } else { |
397 + | localfn.b("Can't find user " + (String) localObject2); |
398 + | } |
399 + | } else if (str1.toLowerCase().startsWith("say ")) { |
400 + | str1 = str1.substring(str1.indexOf(" ")).trim(); |
401 + | a.info("[" + str2 + "] " + str1); |
402 + | this.f.a(new br("§d[Server] " + str1)); |
403 + | } else if (str1.toLowerCase().startsWith("tell ")) { |
404 + | String[] split = str1.split(" "); |
405 + | if (split.length >= 3) { |
406 + | str1 = str1.substring(str1.indexOf(" ")).trim(); |
407 + | str1 = str1.substring(str1.indexOf(" ")).trim(); |
408 + | |
409 + | a.info("[" + str2 + "->" + split[1] + "] " + str1); |
410 + | str1 = "§7" + str2 + " whispers " + str1; |
411 + | a.info(str1); |
412 + | if (!this.f.a(split[1], new br(str1))) { |
413 + | localfn.b("There's no player by that name online."); |
414 + | } |
415 + | } |
416 + | } else { |
417 + | a.info("Unknown console command. Type \"help\" for help."); |
418 + | } |
419 + | } |
420 + | } |
421 + | } |
422 + | } |
423 + | } |
424 + | |
425 + | private void a(String paramString1, String paramString2) { |
426 + | String str = paramString1 + ": " + paramString2; |
427 + | this.f.i("§7(" + str + ")"); |
428 + | a.info(str); |
429 + | } |
430 + | |
431 + | private int b(String paramString, int paramInt) { |
432 + | try { |
433 + | return Integer.parseInt(paramString); |
434 + | } catch (NumberFormatException localNumberFormatException) { |
435 + | } |
436 + | return paramInt; |
437 + | } |
438 + | |
439 + | public void a(fc paramfc) { |
440 + | this.p.add(paramfc); |
441 + | } |
442 + | |
443 + | public static void main(String[] paramArrayOfString) { |
444 + | try { |
445 + | MinecraftServer localMinecraftServer = new MinecraftServer(); |
446 + | |
447 + | if ((!GraphicsEnvironment.isHeadless()) && ((paramArrayOfString.length <= 0) || (!paramArrayOfString[0].equals("nogui")))) { |
448 + | hg.a(localMinecraftServer); |
449 + | } |
450 + | |
451 + | new cj("Server thread", localMinecraftServer).start(); |
452 + | } catch (Exception localException) { |
453 + | a.log(Level.SEVERE, "Failed to start the minecraft server", localException); |
454 + | } |
455 + | } |
456 + | |
457 + | public File a(String paramString) { |
458 + | return new File(paramString); |
459 + | } |
460 + | |
461 + | public void b(String paramString) { |
462 + | a.info(paramString); |
463 + | } |
464 + | |
465 + | public String c() { |
466 + | return "CONSOLE"; |
467 + | } |
468 + | } |