Example #1
0
  void turnOnServerTime() throws IOException {
    Global.log("Turning on server time...");
    while (true) {
      if (isDisposed()) throw new IOException("Client game disposed");
      Global.log("Connecting to port " + Global.serverTimePort() + "...");
      try {
        serverTime = new ClientByteStream(ip, Global.serverTimePort(), 2);
        break;
      } catch (IOException ex) {
      }
    }
    Global.log("Connected!");
    timers.add(
        new FixedTimer(
            new FixedTask() {
              public boolean fixedRate() {
                return false;
              }

              public float FPS() {
                return Global.ReceiveFPS;
              }

              public void run() {
                byte[] data = null;
                try {
                  data = serverTime.read();
                } catch (IOException ex) {
                  System.err.println("Error reading from server time: " + ex);
                  Global.onException();
                  stop();
                  return;
                }
                if (data == null) return;
                ByteBuffer bb = ByteBuffer.wrap(data);
                short time = bb.getShort();
                Game.activeGame().getHud().setTime(time);
              }
            }));
  }