Exemplo n.º 1
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();
      }
    }
  }
Exemplo n.º 2
0
  public void run() {
    try {
      if (this.startServer()) {
        FMLCommonHandler.instance().handleServerStarted();

        long i = System.currentTimeMillis();

        FMLCommonHandler.instance().onWorldLoadTick(worldServers);

        for (long j = 0L; this.serverRunning; this.serverIsRunning = true) {
          long k = System.currentTimeMillis();
          long l = k - i;

          if (l > 2000L && i - this.timeOfLastWarning >= 15000L) {
            this.func_98033_al()
                .func_98236_b(
                    "Can\'t keep up! Did the system time change, or is the server overloaded?");
            l = 2000L;
            this.timeOfLastWarning = i;
          }

          if (l < 0L) {
            this.func_98033_al().func_98236_b("Time ran backwards! Did the system time change?");
            l = 0L;
          }

          j += l;
          i = k;

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

          Thread.sleep(1L);
        }
        FMLCommonHandler.instance().handleServerStopping();
      } else {
        this.finalTick((CrashReport) null);
      }
    } catch (Throwable throwable) {
      if (FMLCommonHandler.instance().shouldServerBeKilledQuietly()) {
        return;
      }
      throwable.printStackTrace();
      this.func_98033_al()
          .func_98234_c(
              "Encountered an unexpected exception " + throwable.getClass().getSimpleName(),
              throwable);
      CrashReport crashreport = null;

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

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

      if (crashreport.saveToFile(file1, this.func_98033_al())) {
        this.func_98033_al()
            .func_98232_c("This crash report has been saved to: " + file1.getAbsolutePath());
      } else {
        this.func_98033_al().func_98232_c("We were unable to save this crash report to disk.");
      }

      this.finalTick(crashreport);
    } finally {
      try {
        if (FMLCommonHandler.instance().shouldServerBeKilledQuietly()) {
          return;
        }
        this.stopServer();
        this.serverStopped = true;
      } catch (Throwable throwable1) {
        throwable1.printStackTrace();
      } finally {
        FMLCommonHandler.instance().handleServerStopped();
        this.systemExitNow();
      }
    }
  }