Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-10984

GS4 query listener fails to send player list when len(players) > 127

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Minecraft 13w41a
    • Minecraft 1.4.7, Snapshot 13w10a, Minecraft 1.5, Snapshot 13w11a, Minecraft 1.5.1, Minecraft 1.6.1, Minecraft 1.6.2
    • barney@invert:~$ java -version
      java version "1.7.0_04"
      Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
      Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
    • Plausible

      The GS4 Query protocol that minecraft uses is described here, and can be enabled with `enable-query=true` in server.properties.

      In short, in full stat mode, the server sends an empty player list if `count(players) > 127`.

      The exact bug is slightly more subtle. Excerpt from RemoteStatusListener.java:

                  this.cachedReply.write("player_");
                  this.cachedReply.write((int) 0);
                  String[] astring = this.server.getPlayers();
                  byte b0 = (byte) astring.length;
      
                  for (byte b1 = (byte) (b0 - 1); b1 >= 0; --b1) {
                      this.cachedReply.write(astring[b1]);
                  }
      
                  this.cachedReply.write((int) 0);
      

      The byte cast causes the player list length variable to overflow, and as the loop counts backwards to zero, no players are sent when the count is 128-255. Beyond this the pattern repeats (i.e. with 300 players online, 44 would be listed), so the players list is only reliable for 127 players or fewer.

      By contrast, the 'this.server.getPlayers()' method is implemented with an int counter in PlayerList.java:

              String[] astring = new String[this.players.size()];
      
              for (int i = 0; i < this.players.size(); ++i) {
                  astring[i] = ((EntityPlayer) this.players.get(i)).getName();
              }
      
              return astring;
      

      I also can't think of a reason for the player list to be reversed, as its stored in a largely non-useful order anyway.

            dinnerbone [Mojang] Nathan Adams
            barneygale Barney Gale
            Votes:
            10 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: