mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-04 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 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_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_INFO = "http://sdn.parabot.org/providers/getInformation.php?id=";
|
||||
public static final String GET_BOT_VERSION = "http://bot.parabot.org/version.txt";
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
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.desc.ServerDescription;
|
||||
import org.parabot.core.forum.AccountManager;
|
||||
@@ -16,51 +18,36 @@ import java.net.URL;
|
||||
* @author Everel
|
||||
*/
|
||||
public class PublicServers extends ServerParser {
|
||||
|
||||
private static AccountManager manager;
|
||||
|
||||
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
|
||||
private static AccountManager manager;
|
||||
|
||||
@Override
|
||||
public final void setManager(AccountManager manager) {
|
||||
PublicServers.manager = manager;
|
||||
}
|
||||
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
|
||||
|
||||
};
|
||||
@Override
|
||||
public final void setManager(AccountManager manager) {
|
||||
PublicServers.manager = manager;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
try {
|
||||
BufferedReader br = WebUtil.getReader(new URL(
|
||||
Configuration.GET_SERVER_PROVIDERS), manager.getAccount().getUsername(), manager.getAccount().getPassword());
|
||||
int count = 0;
|
||||
Configuration.GET_SERVER_PROVIDERS_JSON), manager.getAccount().getUsername(), manager.getAccount().getPassword());
|
||||
String line;
|
||||
|
||||
String name = null;
|
||||
String author = null;
|
||||
double version = 0D;
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
while ((line = br.readLine()) != null) {
|
||||
count++;
|
||||
switch (count % 4) {
|
||||
case 1:
|
||||
// server name
|
||||
name = line;
|
||||
break;
|
||||
case 2:
|
||||
// author
|
||||
author = 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));
|
||||
}
|
||||
|
||||
JSONObject jsonObject = (JSONObject) parser.parse(line);
|
||||
String name = String.valueOf(jsonObject.get("name"));
|
||||
String author = String.valueOf(jsonObject.get("author"));
|
||||
double version = Double.parseDouble(String.valueOf(jsonObject.get("version")));
|
||||
|
||||
ServerDescription desc = new ServerDescription(name,
|
||||
author, version);
|
||||
SERVER_CACHE.put(desc, new PublicServerExecuter(name, line));
|
||||
}
|
||||
|
||||
br.close();
|
||||
|
||||
Reference in New Issue
Block a user