mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
[TASK] Modified code to utilize latest bdn changes
This commit is contained in:
@@ -11,8 +11,10 @@ public class Configuration extends org.parabot.api.Configuration {
|
|||||||
public static final String LOGIN_SERVER = "http://bdn.parabot.org/api/v2/users/login";
|
public static final String LOGIN_SERVER = "http://bdn.parabot.org/api/v2/users/login";
|
||||||
public static final String GET_SCRIPTS = "http://bdn.parabot.org/api/get.php?action=scripts_scripts&server=";
|
public static final String GET_SCRIPTS = "http://bdn.parabot.org/api/get.php?action=scripts_scripts&server=";
|
||||||
public static final String GET_SCRIPT = "http://bdn.parabot.org/api/get.php?action=scripts_script&id=";
|
public static final String GET_SCRIPT = "http://bdn.parabot.org/api/get.php?action=scripts_script&id=";
|
||||||
|
public static final String GET_SERVER_PROVIDER_TYPE = "http://v3.bdn.parabot.org/api/bot/server/type?server=";
|
||||||
public static final String GET_SERVER_PROVIDERS = "http://bdn.parabot.org/api/get.php?action=server_providers";
|
public static final String GET_SERVER_PROVIDERS = "http://bdn.parabot.org/api/get.php?action=server_providers";
|
||||||
public static final String GET_SERVER_PROVIDER = "http://v3.bdn.parabot.org/api/bot/download/provider?nightly=%s&server=%s";
|
public static final String GET_SERVER_PROVIDER = "http://v3.bdn.parabot.org/api/bot/download/provider?nightly=%s&server=%s";
|
||||||
|
public static final String SERVER_PROVIDER_INFO = "http://v3.bdn.parabot.org/api/bot/list/%s?latest=true";
|
||||||
public static final String GET_SERVER_PROVIDER_INFO = "http://bdn.parabot.org/api/get.php?action=server_information&name=";
|
public static final String GET_SERVER_PROVIDER_INFO = "http://bdn.parabot.org/api/get.php?action=server_information&name=";
|
||||||
public static final String GET_SERVER_SETTINGS = "http://bdn.parabot.org/api/get.php?action=get_settings";
|
public static final String GET_SERVER_SETTINGS = "http://bdn.parabot.org/api/get.php?action=get_settings";
|
||||||
public static final String GET_BOT_VERSION = "http://bdn.parabot.org/api/v2/bot/version";
|
public static final String GET_BOT_VERSION = "http://bdn.parabot.org/api/v2/bot/version";
|
||||||
|
|||||||
@@ -183,29 +183,16 @@ public class ServerProviderInfo {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a temporary method until the bdn gets updated
|
* Gets the current provider version
|
||||||
* @param serverName
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String getProviderVersion(String serverName) {
|
public String getProviderVersion() {
|
||||||
try {
|
String providerType = WebUtil.getJsonValue(Configuration.GET_SERVER_PROVIDER_TYPE + properties.getProperty("name"), "type");
|
||||||
serverName = serverName.toLowerCase();
|
if(providerType != null) {
|
||||||
String providerInfo = String.format("http://v3.bdn.parabot.org/api/bot/list/%s-provider?latest=true", serverName);
|
String providerInfo = String.format(Configuration.SERVER_PROVIDER_INFO, providerType);
|
||||||
String response = WebUtil.getContents(providerInfo);
|
return WebUtil.getJsonValue(providerInfo, "version");
|
||||||
|
|
||||||
if (response.length() > 0) {
|
|
||||||
JSONObject jsonObject = (JSONObject) WebUtil.getJsonParser().parse(response);
|
|
||||||
|
|
||||||
if (jsonObject.get("version") != null) {
|
|
||||||
return jsonObject.get("version").toString();
|
|
||||||
}
|
|
||||||
} else if (response.equals("")) {
|
|
||||||
return getProviderVersion("default");
|
|
||||||
}
|
|
||||||
} catch(Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.parabot.environment.api.utils;
|
package org.parabot.environment.api.utils;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A WebUtil class fetches data from an URL
|
* A WebUtil class fetches data from an URL
|
||||||
*
|
*
|
||||||
@@ -7,4 +9,27 @@ package org.parabot.environment.api.utils;
|
|||||||
*/
|
*/
|
||||||
public class WebUtil extends org.parabot.api.io.WebUtil {
|
public class WebUtil extends org.parabot.api.io.WebUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches a single value from a JSON string at the given url
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
* @param key
|
||||||
|
* @return value that belongs to given key
|
||||||
|
*/
|
||||||
|
public static String getJsonValue(String url, String key) {
|
||||||
|
try {
|
||||||
|
String response = WebUtil.getContents(url);
|
||||||
|
|
||||||
|
if(response.length() > 0) {
|
||||||
|
JSONObject jsonObject = (JSONObject) WebUtil.getJsonParser().parse(response);
|
||||||
|
if (jsonObject.get(key) != null) {
|
||||||
|
return jsonObject.get(key).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class PublicServerExecuter extends ServerExecuter {
|
|||||||
|
|
||||||
Core.verbose("Downloading: " + jarUrl + " ...");
|
Core.verbose("Downloading: " + jarUrl + " ...");
|
||||||
|
|
||||||
String providerVersion = ServerProviderInfo.getProviderVersion(serverName);
|
String providerVersion = serverProviderInfo.getProviderVersion();
|
||||||
if(providerVersion == null) {
|
if(providerVersion == null) {
|
||||||
providerVersion = "error";
|
providerVersion = "error";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user