mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 16:49:10 +00:00
Using JSON to gather the servers
This commit is contained in:
@@ -11,6 +11,7 @@ public class Configuration {
|
|||||||
public static final String SDN_SCRIPTS_JSON = "http://sdn.parabot.org/scripts.php?method=json&user=%s";
|
public static final String SDN_SCRIPTS_JSON = "http://sdn.parabot.org/scripts.php?method=json&user=%s";
|
||||||
public static final String GET_SDN_SCRIPT = "http://sdn.parabot.org/getscript.php?user=%s&pass=%s&scriptid=%d";
|
public static final String GET_SDN_SCRIPT = "http://sdn.parabot.org/getscript.php?user=%s&pass=%s&scriptid=%d";
|
||||||
public static final String GET_SERVER_PROVIDERS = "http://sdn.parabot.org/providers/index.php";
|
public static final String GET_SERVER_PROVIDERS = "http://sdn.parabot.org/providers/index.php";
|
||||||
|
public static final String GET_SERVER_PROVIDERS_JSON = "http://sdn.parabot.org/providers/index.php?method=json";
|
||||||
public static final String GET_SERVER_PROVIDER = "http://sdn.parabot.org/providers/provider.php?id=";
|
public static final String GET_SERVER_PROVIDER = "http://sdn.parabot.org/providers/provider.php?id=";
|
||||||
public static final String GET_SERVER_PROVIDER_INFO = "http://sdn.parabot.org/providers/getInformation.php?id=";
|
public static final String GET_SERVER_PROVIDER_INFO = "http://sdn.parabot.org/providers/getInformation.php?id=";
|
||||||
public static final String GET_BOT_VERSION = "http://bot.parabot.org/version.txt";
|
public static final String GET_BOT_VERSION = "http://bot.parabot.org/version.txt";
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.parabot.core.parsers.servers;
|
package org.parabot.core.parsers.servers;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.parabot.core.Configuration;
|
import org.parabot.core.Configuration;
|
||||||
import org.parabot.core.desc.ServerDescription;
|
import org.parabot.core.desc.ServerDescription;
|
||||||
import org.parabot.core.forum.AccountManager;
|
import org.parabot.core.forum.AccountManager;
|
||||||
@@ -16,51 +18,36 @@ import java.net.URL;
|
|||||||
* @author Everel
|
* @author Everel
|
||||||
*/
|
*/
|
||||||
public class PublicServers extends ServerParser {
|
public class PublicServers extends ServerParser {
|
||||||
|
|
||||||
private static AccountManager manager;
|
|
||||||
|
|
||||||
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
|
private static AccountManager manager;
|
||||||
|
|
||||||
@Override
|
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
|
||||||
public final void setManager(AccountManager manager) {
|
|
||||||
PublicServers.manager = manager;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
@Override
|
||||||
|
public final void setManager(AccountManager manager) {
|
||||||
|
PublicServers.manager = manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
try {
|
try {
|
||||||
BufferedReader br = WebUtil.getReader(new URL(
|
BufferedReader br = WebUtil.getReader(new URL(
|
||||||
Configuration.GET_SERVER_PROVIDERS), manager.getAccount().getUsername(), manager.getAccount().getPassword());
|
Configuration.GET_SERVER_PROVIDERS_JSON), manager.getAccount().getUsername(), manager.getAccount().getPassword());
|
||||||
int count = 0;
|
|
||||||
String line;
|
String line;
|
||||||
|
|
||||||
String name = null;
|
JSONParser parser = new JSONParser();
|
||||||
String author = null;
|
|
||||||
double version = 0D;
|
|
||||||
|
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
count++;
|
|
||||||
switch (count % 4) {
|
JSONObject jsonObject = (JSONObject) parser.parse(line);
|
||||||
case 1:
|
String name = String.valueOf(jsonObject.get("name"));
|
||||||
// server name
|
String author = String.valueOf(jsonObject.get("author"));
|
||||||
name = line;
|
double version = Double.parseDouble(String.valueOf(jsonObject.get("version")));
|
||||||
break;
|
|
||||||
case 2:
|
ServerDescription desc = new ServerDescription(name,
|
||||||
// author
|
author, version);
|
||||||
author = line;
|
SERVER_CACHE.put(desc, new PublicServerExecuter(name, line));
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
// version
|
|
||||||
version = Double.parseDouble(line);
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
// serverID
|
|
||||||
ServerDescription desc = new ServerDescription(name,
|
|
||||||
author, version);
|
|
||||||
SERVER_CACHE.put(desc, new PublicServerExecuter(name, line));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
br.close();
|
br.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user