예제 #1
0
  /** Main function called by run() every loop. */
  public void tick() {
    long var1 = System.nanoTime();
    ++this.tickCounter;

    if (this.startProfiling) {
      this.startProfiling = false;
      this.theProfiler.profilingEnabled = true;
      this.theProfiler.clearProfiling();
    }

    this.theProfiler.startSection("root");
    this.updateTimeLightAndEntities();

    if (var1 - this.nanoTimeSinceStatusRefresh >= 5000000000L) {
      this.nanoTimeSinceStatusRefresh = var1;
      this.statusResponse.setPlayerCountData(
          new ServerStatusResponse.PlayerCountData(
              this.getMaxPlayers(), this.getCurrentPlayerCount()));
      GameProfile[] var3 = new GameProfile[Math.min(this.getCurrentPlayerCount(), 12)];
      int var4 =
          MathHelper.getRandomIntegerInRange(
              this.random, 0, this.getCurrentPlayerCount() - var3.length);

      for (int var5 = 0; var5 < var3.length; ++var5) {
        var3[var5] =
            ((EntityPlayerMP) this.serverConfigManager.playerEntityList.get(var4 + var5))
                .getGameProfile();
      }

      Collections.shuffle(Arrays.asList(var3));
      this.statusResponse.getPlayerCountData().setPlayers(var3);
    }

    if (this.tickCounter % 900 == 0) {
      this.theProfiler.startSection("save");
      this.serverConfigManager.saveAllPlayerData();
      this.saveAllWorlds(true);
      this.theProfiler.endSection();
    }

    this.theProfiler.startSection("tallying");
    this.tickTimeArray[this.tickCounter % 100] = System.nanoTime() - var1;
    this.theProfiler.endSection();
    this.theProfiler.startSection("snooper");

    if (!this.usageSnooper.isSnooperRunning() && this.tickCounter > 100) {
      this.usageSnooper.startSnooper();
    }

    if (this.tickCounter % 6000 == 0) {
      this.usageSnooper.addMemoryStatsToSnooper();
    }

    this.theProfiler.endSection();
    this.theProfiler.endSection();
  }
예제 #2
0
  public void run() {
    try {
      if (this.startServer()) {
        this.currentTime = getCurrentTimeMillis();
        long var1 = 0L;
        this.statusResponse.setServerDescription(new ChatComponentText(this.motd));
        this.statusResponse.setProtocolVersionInfo(
            new ServerStatusResponse.MinecraftProtocolVersionIdentifier("1.8", 47));
        this.addFaviconToStatusResponse(this.statusResponse);

        while (this.serverRunning) {
          long var48 = getCurrentTimeMillis();
          long var5 = var48 - this.currentTime;

          if (var5 > 2000L && this.currentTime - this.timeOfLastWarning >= 15000L) {
            logger.warn(
                "Can\'t keep up! Did the system time change, or is the server overloaded? Running {}ms behind, skipping {} tick(s)",
                new Object[] {Long.valueOf(var5), Long.valueOf(var5 / 50L)});
            var5 = 2000L;
            this.timeOfLastWarning = this.currentTime;
          }

          if (var5 < 0L) {
            logger.warn("Time ran backwards! Did the system time change?");
            var5 = 0L;
          }

          var1 += var5;
          this.currentTime = var48;

          if (this.worldServers[0].areAllPlayersAsleep()) {
            this.tick();
            var1 = 0L;
          } else {
            while (var1 > 50L) {
              var1 -= 50L;
              this.tick();
            }
          }

          Thread.sleep(Math.max(1L, 50L - var1));
          this.serverIsRunning = true;
        }
      } else {
        this.finalTick((CrashReport) null);
      }
    } catch (Throwable var46) {
      logger.error("Encountered an unexpected exception", var46);
      CrashReport var2 = null;

      if (var46 instanceof ReportedException) {
        var2 = this.addServerInfoToCrashReport(((ReportedException) var46).getCrashReport());
      } else {
        var2 =
            this.addServerInfoToCrashReport(
                new CrashReport("Exception in server tick loop", var46));
      }

      File var3 =
          new File(
              new File(this.getDataDirectory(), "crash-reports"),
              "crash-"
                  + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date())
                  + "-server.txt");

      if (var2.saveToFile(var3)) {
        logger.error("This crash report has been saved to: " + var3.getAbsolutePath());
      } else {
        logger.error("We were unable to save this crash report to disk.");
      }

      this.finalTick(var2);
    } finally {
      try {
        this.stopServer();
        this.serverStopped = true;
      } catch (Throwable var44) {
        logger.error("Exception stopping the server", var44);
      } finally {
        this.systemExitNow();
      }
    }
  }