output.writeBytes(query);
output.close();
// Read the response
String response;
ObjectMap result;
try {
response = readAll(connection.getInputStream());
result = (ObjectMap)JSON.parse(response);
}
catch (IOException e) {
System.err.println("Incorrect username or password");
throw e;
}
// Check for banned or other failures
// {"rate":0,"reason":"account_banned","status":"FAILED","delay":10000,"banned":7647952951000}
if (result.get("status").equals("FAILED"))
throw new IOException("Error logging in: " + result.get("reason"));
// Handle login queue
if (!result.containsKey("token")) {
int node = result.getInt("node"); // Our login queue ID
String nodeStr = "" + node;
String champ = result.getString("champ"); // The name of our login
// queue
int rate = result.getInt("rate"); // How many tickets are processed
// every queue update
int delay = result.getInt("delay"); // How often the queue status
// updates
int id = 0;
int cur = 0;
Object[] tickers = result.getArray("tickers");
for (Object o : tickers) {
ObjectMap to = (ObjectMap)o;
// Find our queue
int tnode = to.getInt("node");
if (tnode != node)
continue;
id = to.getInt("id"); // Our ticket in line
cur = to.getInt("current"); // The current ticket being
// processed
break;
}
// Let the user know