mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
Configured JSON script gathering
This commit is contained in:
@@ -8,6 +8,7 @@ package org.parabot.core;
|
||||
public class Configuration {
|
||||
public static final String LOGIN_SERVER = "http://www.parabot.org/community/api/login.php?username=%s&password=%s";
|
||||
public static final String SDN_SCRIPTS = "http://sdn.parabot.org/scripts.php?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_SERVER_PROVIDERS = "http://sdn.parabot.org/providers/index.php";
|
||||
public static final String GET_SERVER_PROVIDER = "http://sdn.parabot.org/providers/provider.php?id=";
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.parabot.core.parsers.scripts;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.parabot.core.Configuration;
|
||||
import org.parabot.core.desc.ScriptDescription;
|
||||
import org.parabot.core.forum.AccountManager;
|
||||
@@ -11,9 +13,9 @@ import java.io.BufferedReader;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Parses scripts stored at parabot�s sdn
|
||||
* Parses scripts stored on the sdn of Parabot
|
||||
*
|
||||
* @author Everel
|
||||
* @author Everel, Paradox
|
||||
*/
|
||||
public class SDNScripts extends ScriptParser {
|
||||
private static AccountManager manager;
|
||||
@@ -28,63 +30,36 @@ public class SDNScripts extends ScriptParser {
|
||||
};
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
public void execute(){
|
||||
if (!manager.isLoggedIn()) {
|
||||
System.err.println("Not logged in...");
|
||||
return;
|
||||
}
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
try {
|
||||
BufferedReader br = WebUtil.getReader(new URL(String.format(Configuration.SDN_SCRIPTS, manager.getAccount()
|
||||
BufferedReader br = WebUtil.getReader(new URL(String.format(Configuration.SDN_SCRIPTS_JSON, manager.getAccount()
|
||||
.getUsername())));
|
||||
int count = 0;
|
||||
|
||||
String line;
|
||||
|
||||
String jarName = null;
|
||||
int sdnId = -1;
|
||||
String scriptName = null;
|
||||
String author = null;
|
||||
double version = 0D;
|
||||
String category = null;
|
||||
String description = null;
|
||||
String[] servers = null;
|
||||
while ((line = br.readLine()) != null) {
|
||||
count++;
|
||||
|
||||
switch (count % 8) {
|
||||
case 1:
|
||||
// jarname
|
||||
jarName = line;
|
||||
break;
|
||||
case 2:
|
||||
// sdn id
|
||||
sdnId = Integer.parseInt(line);
|
||||
break;
|
||||
case 3:
|
||||
scriptName = line;
|
||||
break;
|
||||
case 4:
|
||||
author = line;
|
||||
break;
|
||||
case 5:
|
||||
version = Double.parseDouble(line);
|
||||
break;
|
||||
case 6:
|
||||
category = line;
|
||||
break;
|
||||
case 7:
|
||||
description = line;
|
||||
break;
|
||||
case 0:
|
||||
if (line.contains(", ")) {
|
||||
servers = line.split(", ");
|
||||
} else {
|
||||
servers = new String[]{line};
|
||||
}
|
||||
final ScriptDescription desc = new ScriptDescription(jarName, scriptName,
|
||||
author, category, version, description,
|
||||
servers, sdnId);
|
||||
SCRIPT_CACHE.put(desc, new SDNScriptExecuter(sdnId));
|
||||
}
|
||||
while ((line = br.readLine()) != null){
|
||||
Object obj = parser.parse(line);
|
||||
JSONObject jsonObject = (JSONObject) obj;
|
||||
String jarName = String.valueOf(jsonObject.get("jarname"));
|
||||
int sdnId = Integer.parseInt(String.valueOf(jsonObject.get("scriptid")));
|
||||
String scriptName = String.valueOf(jsonObject.get("scriptname"));
|
||||
String author = String.valueOf(jsonObject.get("author"));
|
||||
double version = Double.parseDouble(String.valueOf(jsonObject.get("version")));
|
||||
String category = String.valueOf(jsonObject.get("category"));
|
||||
String description = String.valueOf(jsonObject.get("description"));
|
||||
|
||||
final ScriptDescription desc = new ScriptDescription(jarName, scriptName,
|
||||
author, category, version, description,
|
||||
null, sdnId);
|
||||
SCRIPT_CACHE.put(desc, new SDNScriptExecuter(sdnId));
|
||||
|
||||
}
|
||||
|
||||
br.close();
|
||||
@@ -93,5 +68,4 @@ public class SDNScripts extends ScriptParser {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user