IntegratedServer .java

net.minecraft.server.integrated.IntegratedServer (class): members: setStaticInstance, theWorldSettings, lanServerPing, getPublic, isPublic, finalTick.

net.minecraft.server.integratedclass448 linesserverextends MinecraftServer13.8 KB

API Surface (29)

ServerCommandManager createNewCommandManager()
void loadAllWorlds(String saveName, String worldNameIn, long seed, WorldType type, String worldNameIn2)
boolean startServer()
void tick()
boolean canStructuresSpawn()
WorldSettings.GameType getGameType()
EnumDifficulty getDifficulty()
boolean isHardcore()
boolean shouldBroadcastRconToOps()
boolean shouldBroadcastConsoleToOps()
File getDataDirectory()
boolean isDedicatedServer()
boolean shouldUseNativeTransport()
void finalTick(CrashReport report)
CrashReport addServerInfoToCrashReport(CrashReport report)
String call()
String call()
void setDifficultyForAllWorlds(EnumDifficulty difficulty)
void addServerStatsToSnooper(PlayerUsageSnooper playerSnooper)
boolean isSnooperEnabled()
String shareToLAN(WorldSettings.GameType type, boolean allowCheats)
void stopServer()
void initiateShutdown()
void run()
void setStaticInstance()
boolean getPublic()
void setGameType(WorldSettings.GameType gameMode)
boolean isCommandBlockEnabled()
int getOpPermissionLevel()

Fields & Constants (6)

logger
mc
theWorldSettings
isGamePaused
isPublic
lanServerPing

String literals (11)

"saves"
"Generating keypair"
"Saving and pausing game..."
"Integrated Server (map_client.txt)"
"Is Modded"
"vanilla"
"Definitely; Client brand changed to \'"
"Definitely; Server brand changed to \'"
"Very likely; Jar signature invalidated"
"snooper_partner"
"Started on "

Full Source

IntegratedServer.java448 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.server.integrated;
2
3
import com.google.common.collect.Lists;
4
import com.google.common.util.concurrent.Futures;
5
import java.io.File;
6
import java.io.IOException;
7
import java.net.InetAddress;
8
import java.util.concurrent.Callable;
9
import java.util.concurrent.FutureTask;
10
import net.minecraft.client.ClientBrandRetriever;
11
import net.minecraft.client.Minecraft;
12
import net.minecraft.client.multiplayer.ThreadLanServerPing;
13
import net.minecraft.command.ServerCommandManager;
14
import net.minecraft.crash.CrashReport;
15
import net.minecraft.entity.player.EntityPlayerMP;
16
import net.minecraft.profiler.PlayerUsageSnooper;
17
import net.minecraft.server.MinecraftServer;
18
import net.minecraft.util.CryptManager;
19
import net.minecraft.util.HttpUtil;
20
import net.minecraft.util.Util;
21
import net.minecraft.world.EnumDifficulty;
22
import net.minecraft.world.WorldManager;
23
import net.minecraft.world.WorldServer;
24
import net.minecraft.world.WorldServerMulti;
25
import net.minecraft.world.WorldSettings;
26
import net.minecraft.world.WorldType;
27
import net.minecraft.world.demo.DemoWorldServer;
28
import net.minecraft.world.storage.ISaveHandler;
29
import net.minecraft.world.storage.WorldInfo;
30
import org.apache.logging.log4j.LogManager;
31
import org.apache.logging.log4j.Logger;
32
33
public class IntegratedServer extends MinecraftServer
34
{
35
    private static final Logger logger = LogManager.getLogger();
36
37
    /** The Minecraft instance. */
38
    private final Minecraft mc;
39
    private final WorldSettings theWorldSettings;
40
    private boolean isGamePaused;
41
    private boolean isPublic;
42
    private ThreadLanServerPing lanServerPing;
43
44
    public IntegratedServer(Minecraft mcIn)
45
    {
46
        super(mcIn.getProxy(), new File(mcIn.mcDataDir, USER_CACHE_FILE.getName()));
47
        this.mc = mcIn;
48
        this.theWorldSettings = null;
49
    }
50
51
    public IntegratedServer(Minecraft mcIn, String folderName, String worldName, WorldSettings settings)
52
    {
53
        super(new File(mcIn.mcDataDir, "saves"), mcIn.getProxy(), new File(mcIn.mcDataDir, USER_CACHE_FILE.getName()));
54
        this.setServerOwner(mcIn.getSession().getUsername());
55
        this.setFolderName(folderName);
56
        this.setWorldName(worldName);
57
        this.setDemo(mcIn.isDemo());
58
        this.canCreateBonusChest(settings.isBonusChestEnabled());
59
        this.setBuildLimit(256);
60
        this.setConfigManager(new IntegratedPlayerList(this));
61
        this.mc = mcIn;
62
        this.theWorldSettings = this.isDemo() ? DemoWorldServer.demoWorldSettings : settings;
63
    }
64
65
    protected ServerCommandManager createNewCommandManager()
66
    {
67
        return new IntegratedServerCommandManager();
68
    }
69
70
    protected void loadAllWorlds(String saveName, String worldNameIn, long seed, WorldType type, String worldNameIn2)
71
    {
72
        this.convertMapIfNeeded(saveName);
73
        this.worldServers = new WorldServer[3];
74
        this.timeOfLastDimensionTick = new long[this.worldServers.length][100];
75
        ISaveHandler isavehandler = this.getActiveAnvilConverter().getSaveLoader(saveName, true);
76
        this.setResourcePackFromWorld(this.getFolderName(), isavehandler);
77
        WorldInfo worldinfo = isavehandler.loadWorldInfo();
78
79
        if (worldinfo == null)
80
        {
81
            worldinfo = new WorldInfo(this.theWorldSettings, worldNameIn);
82
        }
83
        else
84
        {
85
            worldinfo.setWorldName(worldNameIn);
86
        }
87
88
        for (int i = 0; i < this.worldServers.length; ++i)
89
        {
90
            int j = 0;
91
92
            if (i == 1)
93
            {
94
                j = -1;
95
            }
96
97
            if (i == 2)
98
            {
99
                j = 1;
100
            }
101
102
            if (i == 0)
103
            {
104
                if (this.isDemo())
105
                {
106
                    this.worldServers[i] = (WorldServer)(new DemoWorldServer(this, isavehandler, worldinfo, j, this.theProfiler)).init();
107
                }
108
                else
109
                {
110
                    this.worldServers[i] = (WorldServer)(new WorldServer(this, isavehandler, worldinfo, j, this.theProfiler)).init();
111
                }
112
113
                this.worldServers[i].initialize(this.theWorldSettings);
114
            }
115
            else
116
            {
117
                this.worldServers[i] = (WorldServer)(new WorldServerMulti(this, isavehandler, j, this.worldServers[0], this.theProfiler)).init();
118
            }
119
120
            this.worldServers[i].addWorldAccess(new WorldManager(this, this.worldServers[i]));
121
        }
122
123
        this.getConfigurationManager().setPlayerManager(this.worldServers);
124
125
        if (this.worldServers[0].getWorldInfo().getDifficulty() == null)
126
        {
127
            this.setDifficultyForAllWorlds(this.mc.gameSettings.difficulty);
128
        }
129
130
        this.initialWorldChunkLoad();
131
    }
132
133
    /**
134
     * Initialises the server and starts it.
135
     */
136
    protected boolean startServer() throws IOException
137
    {
138
        logger.info("Starting integrated minecraft server version 1.8.9");
139
        this.setOnlineMode(true);
140
        this.setCanSpawnAnimals(true);
141
        this.setCanSpawnNPCs(true);
142
        this.setAllowPvp(true);
143
        this.setAllowFlight(true);
144
        logger.info("Generating keypair");
145
        this.setKeyPair(CryptManager.generateKeyPair());
146
        this.loadAllWorlds(this.getFolderName(), this.getWorldName(), this.theWorldSettings.getSeed(), this.theWorldSettings.getTerrainType(), this.theWorldSettings.getWorldName());
147
        this.setMOTD(this.getServerOwner() + " - " + this.worldServers[0].getWorldInfo().getWorldName());
148
        return true;
149
    }
150
151
    /**
152
     * Main function called by run() every loop.
153
     */
154
    public void tick()
155
    {
156
        boolean flag = this.isGamePaused;
157
        this.isGamePaused = Minecraft.getMinecraft().getNetHandler() != null && Minecraft.getMinecraft().isGamePaused();
158
159
        if (!flag && this.isGamePaused)
160
        {
161
            logger.info("Saving and pausing game...");
162
            this.getConfigurationManager().saveAllPlayerData();
163
            this.saveAllWorlds(false);
164
        }
165
166
        if (this.isGamePaused)
167
        {
168
            synchronized (this.futureTaskQueue)
169
            {
170
                while (!this.futureTaskQueue.isEmpty())
171
                {
172
                    Util.runTask((FutureTask)this.futureTaskQueue.poll(), logger);
173
                }
174
            }
175
        }
176
        else
177
        {
178
            super.tick();
179
180
            if (this.mc.gameSettings.renderDistanceChunks != this.getConfigurationManager().getViewDistance())
181
            {
182
                logger.info("Changing view distance to {}, from {}", new Object[] {Integer.valueOf(this.mc.gameSettings.renderDistanceChunks), Integer.valueOf(this.getConfigurationManager().getViewDistance())});
183
                this.getConfigurationManager().setViewDistance(this.mc.gameSettings.renderDistanceChunks);
184
            }
185
186
            if (this.mc.theWorld != null)
187
            {
188
                WorldInfo worldinfo1 = this.worldServers[0].getWorldInfo();
189
                WorldInfo worldinfo = this.mc.theWorld.getWorldInfo();
190
191
                if (!worldinfo1.isDifficultyLocked() && worldinfo.getDifficulty() != worldinfo1.getDifficulty())
192
                {
193
                    logger.info("Changing difficulty to {}, from {}", new Object[] {worldinfo.getDifficulty(), worldinfo1.getDifficulty()});
194
                    this.setDifficultyForAllWorlds(worldinfo.getDifficulty());
195
                }
196
                else if (worldinfo.isDifficultyLocked() && !worldinfo1.isDifficultyLocked())
197
                {
198
                    logger.info("Locking difficulty to {}", new Object[] {worldinfo.getDifficulty()});
199
200
                    for (WorldServer worldserver : this.worldServers)
201
                    {
202
                        if (worldserver != null)
203
                        {
204
                            worldserver.getWorldInfo().setDifficultyLocked(true);
205
                        }
206
                    }
207
                }
208
            }
209
        }
210
    }
211
212
    public boolean canStructuresSpawn()
213
    {
214
        return false;
215
    }
216
217
    public WorldSettings.GameType getGameType()
218
    {
219
        return this.theWorldSettings.getGameType();
220
    }
221
222
    /**
223
     * Get the server's difficulty
224
     */
225
    public EnumDifficulty getDifficulty()
226
    {
227
        return this.mc.theWorld.getWorldInfo().getDifficulty();
228
    }
229
230
    /**
231
     * Defaults to false.
232
     */
233
    public boolean isHardcore()
234
    {
235
        return this.theWorldSettings.getHardcoreEnabled();
236
    }
237
238
    /**
239
     * Get if RCON command events should be broadcast to ops
240
     */
241
    public boolean shouldBroadcastRconToOps()
242
    {
243
        return true;
244
    }
245
246
    /**
247
     * Get if console command events should be broadcast to ops
248
     */
249
    public boolean shouldBroadcastConsoleToOps()
250
    {
251
        return true;
252
    }
253
254
    public File getDataDirectory()
255
    {
256
        return this.mc.mcDataDir;
257
    }
258
259
    public boolean isDedicatedServer()
260
    {
261
        return false;
262
    }
263
264
    /**
265
     * Get if native transport should be used. Native transport means linux server performance improvements and
266
     * optimized packet sending/receiving on linux
267
     */
268
    public boolean shouldUseNativeTransport()
269
    {
270
        return false;
271
    }
272
273
    /**
274
     * Called on exit from the main run() loop.
275
     */
276
    protected void finalTick(CrashReport report)
277
    {
278
        this.mc.crashed(report);
279
    }
280
281
    /**
282
     * Adds the server info, including from theWorldServer, to the crash report.
283
     */
284
    public CrashReport addServerInfoToCrashReport(CrashReport report)
285
    {
286
        report = super.addServerInfoToCrashReport(report);
287
        report.getCategory().addCrashSectionCallable("Type", new Callable<String>()
288
        {
289
            public String call() throws Exception
290
            {
291
                return "Integrated Server (map_client.txt)";
292
            }
293
        });
294
        report.getCategory().addCrashSectionCallable("Is Modded", new Callable<String>()
295
        {
296
            public String call() throws Exception
297
            {
298
                String s = ClientBrandRetriever.getClientModName();
299
300
                if (!s.equals("vanilla"))
301
                {
302
                    return "Definitely; Client brand changed to \'" + s + "\'";
303
                }
304
                else
305
                {
306
                    s = IntegratedServer.this.getServerModName();
307
                    return !s.equals("vanilla") ? "Definitely; Server brand changed to \'" + s + "\'" : (Minecraft.class.getSigners() == null ? "Very likely; Jar signature invalidated" : "Probably not. Jar signature remains and both client + server brands are untouched.");
308
                }
309
            }
310
        });
311
        return report;
312
    }
313
314
    public void setDifficultyForAllWorlds(EnumDifficulty difficulty)
315
    {
316
        super.setDifficultyForAllWorlds(difficulty);
317
318
        if (this.mc.theWorld != null)
319
        {
320
            this.mc.theWorld.getWorldInfo().setDifficulty(difficulty);
321
        }
322
    }
323
324
    public void addServerStatsToSnooper(PlayerUsageSnooper playerSnooper)
325
    {
326
        super.addServerStatsToSnooper(playerSnooper);
327
        playerSnooper.addClientStat("snooper_partner", this.mc.getPlayerUsageSnooper().getUniqueID());
328
    }
329
330
    /**
331
     * Returns whether snooping is enabled or not.
332
     */
333
    public boolean isSnooperEnabled()
334
    {
335
        return Minecraft.getMinecraft().isSnooperEnabled();
336
    }
337
338
    /**
339
     * On dedicated does nothing. On integrated, sets commandsAllowedForAll, gameType and allows external connections.
340
     */
341
    public String shareToLAN(WorldSettings.GameType type, boolean allowCheats)
342
    {
343
        try
344
        {
345
            int i = -1;
346
347
            try
348
            {
349
                i = HttpUtil.getSuitableLanPort();
350
            }
351
            catch (IOException var5)
352
            {
353
                ;
354
            }
355
356
            if (i <= 0)
357
            {
358
                i = 25564;
359
            }
360
361
            this.getNetworkSystem().addLanEndpoint((InetAddress)null, i);
362
            logger.info("Started on " + i);
363
            this.isPublic = true;
364
            this.lanServerPing = new ThreadLanServerPing(this.getMOTD(), i + "");
365
            this.lanServerPing.start();
366
            this.getConfigurationManager().setGameType(type);
367
            this.getConfigurationManager().setCommandsAllowedForAll(allowCheats);
368
            return i + "";
369
        }
370
        catch (IOException var6)
371
        {
372
            return null;
373
        }
374
    }
375
376
    /**
377
     * Saves all necessary data as preparation for stopping the server.
378
     */
379
    public void stopServer()
380
    {
381
        super.stopServer();
382
383
        if (this.lanServerPing != null)
384
        {
385
            this.lanServerPing.interrupt();
386
            this.lanServerPing = null;
387
        }
388
    }
389
390
    /**
391
     * Sets the serverRunning variable to false, in order to get the server to shut down.
392
     */
393
    public void initiateShutdown()
394
    {
395
        Futures.getUnchecked(this.addScheduledTask(new Runnable()
396
        {
397
            public void run()
398
            {
399
                for (EntityPlayerMP entityplayermp : Lists.newArrayList(IntegratedServer.this.getConfigurationManager().getPlayerList()))
400
                {
401
                    IntegratedServer.this.getConfigurationManager().playerLoggedOut(entityplayermp);
402
                }
403
            }
404
        }));
405
        super.initiateShutdown();
406
407
        if (this.lanServerPing != null)
408
        {
409
            this.lanServerPing.interrupt();
410
            this.lanServerPing = null;
411
        }
412
    }
413
414
    public void setStaticInstance()
415
    {
416
        this.setInstance();
417
    }
418
419
    /**
420
     * Returns true if this integrated server is open to LAN
421
     */
422
    public boolean getPublic()
423
    {
424
        return this.isPublic;
425
    }
426
427
    /**
428
     * Sets the game type for all worlds.
429
     */
430
    public void setGameType(WorldSettings.GameType gameMode)
431
    {
432
        this.getConfigurationManager().setGameType(gameMode);
433
    }
434
435
    /**
436
     * Return whether command blocks are enabled.
437
     */
438
    public boolean isCommandBlockEnabled()
439
    {
440
        return true;
441
    }
442
443
    public int getOpPermissionLevel()
444
    {
445
        return 4;
446
    }
447
}
448

Deobfuscated MCP 1.8.9 source of IntegratedServer from Marcelektro/MavenMCP-1.8.9 (net/minecraft/server/integrated/IntegratedServer.java), stored verbatim.