mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 16:49:10 +00:00
Configured JSON script gathering
This commit is contained in:
@@ -8,6 +8,7 @@ package org.parabot.core;
|
|||||||
public class Configuration {
|
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 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 = "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_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_PROVIDER = "http://sdn.parabot.org/providers/provider.php?id=";
|
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;
|
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.Configuration;
|
||||||
import org.parabot.core.desc.ScriptDescription;
|
import org.parabot.core.desc.ScriptDescription;
|
||||||
import org.parabot.core.forum.AccountManager;
|
import org.parabot.core.forum.AccountManager;
|
||||||
@@ -11,9 +13,9 @@ import java.io.BufferedReader;
|
|||||||
import java.net.URL;
|
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 {
|
public class SDNScripts extends ScriptParser {
|
||||||
private static AccountManager manager;
|
private static AccountManager manager;
|
||||||
@@ -28,63 +30,36 @@ public class SDNScripts extends ScriptParser {
|
|||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute(){
|
||||||
if (!manager.isLoggedIn()) {
|
if (!manager.isLoggedIn()) {
|
||||||
System.err.println("Not logged in...");
|
System.err.println("Not logged in...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSONParser parser = new JSONParser();
|
||||||
try {
|
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())));
|
.getUsername())));
|
||||||
int count = 0;
|
|
||||||
String line;
|
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) {
|
while ((line = br.readLine()) != null){
|
||||||
case 1:
|
Object obj = parser.parse(line);
|
||||||
// jarname
|
JSONObject jsonObject = (JSONObject) obj;
|
||||||
jarName = line;
|
String jarName = String.valueOf(jsonObject.get("jarname"));
|
||||||
break;
|
int sdnId = Integer.parseInt(String.valueOf(jsonObject.get("scriptid")));
|
||||||
case 2:
|
String scriptName = String.valueOf(jsonObject.get("scriptname"));
|
||||||
// sdn id
|
String author = String.valueOf(jsonObject.get("author"));
|
||||||
sdnId = Integer.parseInt(line);
|
double version = Double.parseDouble(String.valueOf(jsonObject.get("version")));
|
||||||
break;
|
String category = String.valueOf(jsonObject.get("category"));
|
||||||
case 3:
|
String description = String.valueOf(jsonObject.get("description"));
|
||||||
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,
|
final ScriptDescription desc = new ScriptDescription(jarName, scriptName,
|
||||||
author, category, version, description,
|
author, category, version, description,
|
||||||
servers, sdnId);
|
null, sdnId);
|
||||||
SCRIPT_CACHE.put(desc, new SDNScriptExecuter(sdnId));
|
SCRIPT_CACHE.put(desc, new SDNScriptExecuter(sdnId));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
br.close();
|
br.close();
|
||||||
@@ -93,5 +68,4 @@ public class SDNScripts extends ScriptParser {
|
|||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user