| 1 | package net.minecraft.client.multiplayer;
|
| 2 |
|
| 3 | import net.minecraft.nbt.NBTTagCompound;
|
| 4 | import net.minecraft.util.ChatComponentTranslation;
|
| 5 | import net.minecraft.util.IChatComponent;
|
| 6 |
|
| 7 | public class ServerData
|
| 8 | {
|
| 9 | public String serverName;
|
| 10 | public String serverIP;
|
| 11 |
|
| 12 | /**
|
| 13 | * the string indicating number of players on and capacity of the server that is shown on the server browser (i.e.
|
| 14 | * "5/20" meaning 5 slots used out of 20 slots total)
|
| 15 | */
|
| 16 | public String populationInfo;
|
| 17 |
|
| 18 | /**
|
| 19 | * (better variable name would be 'hostname') server name as displayed in the server browser's second line (grey
|
| 20 | * text)
|
| 21 | */
|
| 22 | public String serverMOTD;
|
| 23 |
|
| 24 | /** last server ping that showed up in the server browser */
|
| 25 | public long pingToServer;
|
| 26 | public int version = 47;
|
| 27 |
|
| 28 | /** Game version for this server. */
|
| 29 | public String gameVersion = "1.8.9";
|
| 30 | public boolean field_78841_f;
|
| 31 | public String playerList;
|
| 32 | private ServerData.ServerResourceMode resourceMode = ServerData.ServerResourceMode.PROMPT;
|
| 33 | private String serverIcon;
|
| 34 |
|
| 35 | /** True if the server is a LAN server */
|
| 36 | private boolean lanServer;
|
| 37 |
|
| 38 | public ServerData(String name, String ip, boolean isLan)
|
| 39 | {
|
| 40 | this.serverName = name;
|
| 41 | this.serverIP = ip;
|
| 42 | this.lanServer = isLan;
|
| 43 | }
|
| 44 |
|
| 45 | /**
|
| 46 | * Returns an NBTTagCompound with the server's name, IP and maybe acceptTextures.
|
| 47 | */
|
| 48 | public NBTTagCompound getNBTCompound()
|
| 49 | {
|
| 50 | NBTTagCompound nbttagcompound = new NBTTagCompound();
|
| 51 | nbttagcompound.setString("name", this.serverName);
|
| 52 | nbttagcompound.setString("ip", this.serverIP);
|
| 53 |
|
| 54 | if (this.serverIcon != null)
|
| 55 | {
|
| 56 | nbttagcompound.setString("icon", this.serverIcon);
|
| 57 | }
|
| 58 |
|
| 59 | if (this.resourceMode == ServerData.ServerResourceMode.ENABLED)
|
| 60 | {
|
| 61 | nbttagcompound.setBoolean("acceptTextures", true);
|
| 62 | }
|
| 63 | else if (this.resourceMode == ServerData.ServerResourceMode.DISABLED)
|
| 64 | {
|
| 65 | nbttagcompound.setBoolean("acceptTextures", false);
|
| 66 | }
|
| 67 |
|
| 68 | return nbttagcompound;
|
| 69 | }
|
| 70 |
|
| 71 | public ServerData.ServerResourceMode getResourceMode()
|
| 72 | {
|
| 73 | return this.resourceMode;
|
| 74 | }
|
| 75 |
|
| 76 | public void setResourceMode(ServerData.ServerResourceMode mode)
|
| 77 | {
|
| 78 | this.resourceMode = mode;
|
| 79 | }
|
| 80 |
|
| 81 | /**
|
| 82 | * Takes an NBTTagCompound with 'name' and 'ip' keys, returns a ServerData instance.
|
| 83 | */
|
| 84 | public static ServerData getServerDataFromNBTCompound(NBTTagCompound nbtCompound)
|
| 85 | {
|
| 86 | ServerData serverdata = new ServerData(nbtCompound.getString("name"), nbtCompound.getString("ip"), false);
|
| 87 |
|
| 88 | if (nbtCompound.hasKey("icon", 8))
|
| 89 | {
|
| 90 | serverdata.setBase64EncodedIconData(nbtCompound.getString("icon"));
|
| 91 | }
|
| 92 |
|
| 93 | if (nbtCompound.hasKey("acceptTextures", 1))
|
| 94 | {
|
| 95 | if (nbtCompound.getBoolean("acceptTextures"))
|
| 96 | {
|
| 97 | serverdata.setResourceMode(ServerData.ServerResourceMode.ENABLED);
|
| 98 | }
|
| 99 | else
|
| 100 | {
|
| 101 | serverdata.setResourceMode(ServerData.ServerResourceMode.DISABLED);
|
| 102 | }
|
| 103 | }
|
| 104 | else
|
| 105 | {
|
| 106 | serverdata.setResourceMode(ServerData.ServerResourceMode.PROMPT);
|
| 107 | }
|
| 108 |
|
| 109 | return serverdata;
|
| 110 | }
|
| 111 |
|
| 112 | /**
|
| 113 | * Returns the base-64 encoded representation of the server's icon, or null if not available
|
| 114 | */
|
| 115 | public String getBase64EncodedIconData()
|
| 116 | {
|
| 117 | return this.serverIcon;
|
| 118 | }
|
| 119 |
|
| 120 | public void setBase64EncodedIconData(String icon)
|
| 121 | {
|
| 122 | this.serverIcon = icon;
|
| 123 | }
|
| 124 |
|
| 125 | /**
|
| 126 | * Return true if the server is a LAN server
|
| 127 | */
|
| 128 | public boolean isOnLAN()
|
| 129 | {
|
| 130 | return this.lanServer;
|
| 131 | }
|
| 132 |
|
| 133 | public void copyFrom(ServerData serverDataIn)
|
| 134 | {
|
| 135 | this.serverIP = serverDataIn.serverIP;
|
| 136 | this.serverName = serverDataIn.serverName;
|
| 137 | this.setResourceMode(serverDataIn.getResourceMode());
|
| 138 | this.serverIcon = serverDataIn.serverIcon;
|
| 139 | this.lanServer = serverDataIn.lanServer;
|
| 140 | }
|
| 141 |
|
| 142 | public static enum ServerResourceMode
|
| 143 | {
|
| 144 | ENABLED("enabled"),
|
| 145 | DISABLED("disabled"),
|
| 146 | PROMPT("prompt");
|
| 147 |
|
| 148 | private final IChatComponent motd;
|
| 149 |
|
| 150 | private ServerResourceMode(String name)
|
| 151 | {
|
| 152 | this.motd = new ChatComponentTranslation("addServer.resourcePack." + name, new Object[0]);
|
| 153 | }
|
| 154 |
|
| 155 | public IChatComponent getMotd()
|
| 156 | {
|
| 157 | return this.motd;
|
| 158 | }
|
| 159 | }
|
| 160 | }
|
| 161 |
|