mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
Added ids to settings map & added logger
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/parabotv2/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="fag" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -16,6 +16,8 @@ public class Configuration {
|
||||
public static final String REGISTRATION_PAGE = "https://www.parabot.org/community/index.php?app=core&module=global§ion=register";
|
||||
public static final String GET_PASSWORD = "http://bdn.parabot.org/api/get.php?action=password";
|
||||
public static final String GET_RANDOMS = "http://bdn.parabot.org/api/get.php?action=randoms";
|
||||
public static final String DATA_API = "http://bdn.parabot.org/api/v2/data/";
|
||||
public static final String ITEM_API = DATA_API + "items/";
|
||||
|
||||
public static final double BOT_VERSION = 2.1;
|
||||
}
|
||||
|
||||
@@ -3,15 +3,13 @@ package org.parabot.core;
|
||||
import org.parabot.Landing;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.DigestInputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* The core of parabot
|
||||
@@ -148,6 +146,37 @@ public class Core {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean policyValid(){
|
||||
return new File(Directories.getSettingsPath() + "/java.policy").exists();
|
||||
}
|
||||
|
||||
private static void createPolicy(){
|
||||
File policy = new File(Directories.getSettingsPath() + "/java.policy");
|
||||
if (!policy.exists()){
|
||||
try {
|
||||
final BufferedReader in = WebUtil.getReader(Configuration.DATA_API + "policy");
|
||||
if (in != null) {
|
||||
String line;
|
||||
PrintWriter printWriter = new PrintWriter(Directories.getSettingsPath() + "/java.policy");
|
||||
while ((line = in.readLine()) != null) {
|
||||
if (line.contains("%parabot_resources%")){
|
||||
line = line.replace("%parabot_resources%", Directories.getResourcesPath().getAbsolutePath());
|
||||
}
|
||||
printWriter.println(line);
|
||||
}
|
||||
printWriter.close();
|
||||
in.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
createPolicy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for updates.
|
||||
*
|
||||
|
||||
@@ -16,14 +16,14 @@ public class Directories {
|
||||
private static Map<String, File> cached;
|
||||
|
||||
static {
|
||||
cached = new HashMap<>();
|
||||
switch (OperatingSystem.getOS()) {
|
||||
case WINDOWS:
|
||||
cached.put("Root", new JFileChooser().getFileSystemView().getDefaultDirectory());
|
||||
break;
|
||||
default:
|
||||
cached.put("Root", new File(System.getProperty("user.home")));
|
||||
}
|
||||
cached = new HashMap<>();
|
||||
switch (OperatingSystem.getOS()) {
|
||||
case WINDOWS:
|
||||
cached.put("Root", new JFileChooser().getFileSystemView().getDefaultDirectory());
|
||||
break;
|
||||
default:
|
||||
cached.put("Root", new File(System.getProperty("user.home")));
|
||||
}
|
||||
|
||||
Core.verbose("Caching directories...");
|
||||
cached.put("Root", getDefaultDirectory());
|
||||
@@ -38,30 +38,31 @@ public class Directories {
|
||||
|
||||
clearCache(259200);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set script bin folder
|
||||
*
|
||||
* @param f
|
||||
*/
|
||||
public static void setScriptCompiledDirectory(File f) {
|
||||
if(!f.isDirectory()) {
|
||||
throw new IllegalArgumentException(f + "is not a directory.");
|
||||
}
|
||||
cached.put("Compiled", f);
|
||||
if (!f.isDirectory()) {
|
||||
throw new IllegalArgumentException(f + "is not a directory.");
|
||||
}
|
||||
cached.put("Compiled", f);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set server bin folder
|
||||
*
|
||||
* @param f
|
||||
*/
|
||||
public static void setServerCompiledDirectory(File f) {
|
||||
if(!f.isDirectory()) {
|
||||
throw new IllegalArgumentException(f + "is not a directory.");
|
||||
}
|
||||
cached.put("Servers", f);
|
||||
if (!f.isDirectory()) {
|
||||
throw new IllegalArgumentException(f + "is not a directory.");
|
||||
}
|
||||
cached.put("Servers", f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the root directory outside of the main Parabot folder.
|
||||
@@ -178,13 +179,14 @@ public class Directories {
|
||||
|
||||
/**
|
||||
* Clears the cache based on the latest modification
|
||||
*
|
||||
* @param remove A long that represents the amount of seconds that a file may have since the latest modification
|
||||
*/
|
||||
private static void clearCache(int remove){
|
||||
private static void clearCache(int remove) {
|
||||
File[] cache = getCachePath().listFiles();
|
||||
if (cache != null){
|
||||
for (File f : cache){
|
||||
if (f != null && System.currentTimeMillis() / 1000 - f.lastModified() / 1000 > remove){
|
||||
if (cache != null) {
|
||||
for (File f : cache) {
|
||||
if (f != null && System.currentTimeMillis() / 1000 - f.lastModified() / 1000 > remove) {
|
||||
Core.verbose("Clearing " + f.getName() + " from cache...");
|
||||
f.delete();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.parabot.core.asm;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ClassRemapper extends Remapper {
|
||||
private static HashMap<String, String> remapNames = new HashMap<String, String>();
|
||||
static {
|
||||
|
||||
@@ -10,6 +10,7 @@ import javax.swing.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -21,12 +22,12 @@ import java.util.Properties;
|
||||
*/
|
||||
public class ServerProviderInfo {
|
||||
|
||||
private Properties settings;
|
||||
private HashMap<String, Integer> settings;
|
||||
private Properties properties;
|
||||
|
||||
public ServerProviderInfo(URL providerInfo, String username, String password) {
|
||||
this.properties = new Properties();
|
||||
this.settings = new Properties();
|
||||
this.settings = new HashMap<>();
|
||||
try {
|
||||
String line;
|
||||
Core.verbose("Reading info: " + providerInfo);
|
||||
@@ -39,7 +40,13 @@ public class ServerProviderInfo {
|
||||
for (Object o : jsonObject.entrySet()) {
|
||||
Map.Entry<?, ?> pairs = (Map.Entry<?, ?>) o;
|
||||
if (String.valueOf(pairs.getKey()).equalsIgnoreCase("settings")){
|
||||
settings.putAll((JSONObject) pairs.getValue());
|
||||
JSONObject object = (JSONObject) pairs.getValue();
|
||||
for (Object settingObject : object.entrySet()){
|
||||
Map.Entry<?, ?> settingValue = (Map.Entry<?, ?>) settingObject;
|
||||
String key = (String) settingValue.getKey();
|
||||
long value = (Long) settingValue.getValue();
|
||||
settings.put(key, (int) value);
|
||||
}
|
||||
}else {
|
||||
properties.put(String.valueOf(pairs.getKey()), String.valueOf(pairs.getValue()));
|
||||
}
|
||||
@@ -108,7 +115,7 @@ public class ServerProviderInfo {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public Properties getSettings(){
|
||||
return this.settings;
|
||||
public HashMap<String, Integer> getSettings() {
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
||||
|
||||
add(GamePanel.getInstance());
|
||||
GamePanel.getInstance().add(VerboseLoader.get(username, password), BorderLayout.CENTER);
|
||||
add(Logger.getInstance(), BorderLayout.SOUTH);
|
||||
|
||||
SwingUtil.setParabotIcons(this);
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.parabot.core.ui;
|
||||
|
||||
import org.parabot.core.ui.components.GamePanel;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author JKetelaar
|
||||
*/
|
||||
public class Logger extends JPanel {
|
||||
private static Logger instance;
|
||||
private final DefaultListModel<String> model;
|
||||
|
||||
private Logger(){
|
||||
setLayout(new BorderLayout());
|
||||
JList<String> list = new JList<>();
|
||||
|
||||
JScrollPane pane = new JScrollPane(list);
|
||||
add(pane, BorderLayout.CENTER);
|
||||
|
||||
list.setCellRenderer(getRenderer());
|
||||
|
||||
model = new DefaultListModel<>();
|
||||
list.setModel(model);
|
||||
setPreferredSize(new Dimension((int) GamePanel.getInstance().getPreferredSize().getWidth(), 150));
|
||||
model.addElement("Logger started");
|
||||
}
|
||||
|
||||
private ListCellRenderer<? super String> getRenderer() {
|
||||
return new DefaultListCellRenderer(){
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList<?> list,
|
||||
Object value, int index, boolean isSelected,
|
||||
boolean cellHasFocus) {
|
||||
JLabel listCellRendererComponent = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected,cellHasFocus);
|
||||
listCellRendererComponent.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0,Color.BLACK));
|
||||
return listCellRendererComponent;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Logger getInstance() {
|
||||
return instance == null ? instance = new Logger() : instance;
|
||||
}
|
||||
|
||||
public static void addMessage(String message){
|
||||
instance.model.addElement(message);
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,8 @@ import org.parabot.core.Context;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.ui.BotUI;
|
||||
import org.parabot.environment.api.utils.Time;
|
||||
import org.parabot.environment.scripts.framework.AbstractFramework;
|
||||
import org.parabot.environment.scripts.framework.*;
|
||||
import org.parabot.environment.scripts.framework.Frameworks;
|
||||
import org.parabot.environment.scripts.framework.LoopTask;
|
||||
import org.parabot.environment.scripts.framework.SleepCondition;
|
||||
import org.parabot.environment.scripts.framework.Strategy;
|
||||
import org.parabot.environment.scripts.randoms.Random;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -68,7 +65,15 @@ public class Script implements Runnable {
|
||||
@Override
|
||||
public final void run() {
|
||||
Context context = Context.getInstance();
|
||||
|
||||
|
||||
// Core.verbose("Initializing security manager...");
|
||||
// String previousPolicy = System.getProperty("java.security.policy");
|
||||
// SecurityManager previousSecurityManager = System.getSecurityManager();
|
||||
|
||||
// System.setProperty("java.security.policy", Directories.getSettingsPath() + "/java.policy");
|
||||
// SecurityManagerDemo sm = new SecurityManagerDemo();
|
||||
// System.setSecurityManager(sm);
|
||||
|
||||
Core.verbose("Initializing script...");
|
||||
context.getServerProvider().initScript(this);
|
||||
Core.verbose("Done.");
|
||||
@@ -122,6 +127,8 @@ public class Script implements Runnable {
|
||||
this.state = STATE_STOPPED;
|
||||
context.setRunningScript(null);
|
||||
BotUI.getInstance().toggleRun();
|
||||
// System.setProperty("java.security.policy", previousPolicy);
|
||||
// System.setSecurityManager(previousSecurityManager);
|
||||
Core.verbose("Done.");
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ public abstract class ScriptExecuter {
|
||||
* @param script
|
||||
*/
|
||||
public final void finalize(final ThreadGroup tg, final Script script) {
|
||||
new Thread(tg, script).start();
|
||||
Thread thread = new Thread(tg, script);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.parabot.environment.scripts.executers;
|
||||
|
||||
public class SecurityManagerDemo extends SecurityManager {
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.parabot.environment.scripts.randoms;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.ui.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -89,7 +90,7 @@ public class RandomHandler {
|
||||
public boolean checkAndRun() {
|
||||
for(Random r : this.activeRandoms) {
|
||||
if(r.activate()) {
|
||||
Core.verbose("Running random '" + r.getName() + "'.");
|
||||
Logger.addMessage("Running random '" + r.getName() + "'.");
|
||||
r.execute();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.parabot.environment.servers.executers;
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.parsers.randoms.RandomParser;
|
||||
import org.parabot.core.ui.components.PaintComponent;
|
||||
import org.parabot.environment.scripts.executers.SecurityManagerDemo;
|
||||
import org.parabot.environment.servers.ServerProvider;
|
||||
|
||||
/**
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
java -jar Client.jar -login paradox Cn4VoAythFeaBFunRwuHHTswWuTUDv -loadlocal -verbose
|
||||
Reference in New Issue
Block a user