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