project: proxy and world support

project: proxy and world support

--proxy USERNAME:PASSWORD
--proxy IP:PORT:USERNAME:PASSWORD
--world WORLD
This commit is contained in:
Kyle
2021-02-23 16:58:52 +00:00
parent d390a516dd
commit 323a2d7bf0
4 changed files with 120 additions and 9 deletions

View File

@@ -33,12 +33,15 @@ import com.google.inject.Injector;
import java.io.File; import java.io.File;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean; import java.lang.management.RuntimeMXBean;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.Locale; import java.util.Locale;
import java.util.Optional;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -62,6 +65,7 @@ import net.runelite.client.config.ConfigManager;
import net.runelite.client.discord.DiscordService; import net.runelite.client.discord.DiscordService;
import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.EventBus;
import net.runelite.client.externalplugins.ExternalPluginManager; import net.runelite.client.externalplugins.ExternalPluginManager;
import net.runelite.client.game.WorldService;
import net.runelite.client.plugins.OPRSExternalPluginManager; import net.runelite.client.plugins.OPRSExternalPluginManager;
import net.runelite.client.rs.ClientLoader; import net.runelite.client.rs.ClientLoader;
import net.runelite.client.rs.ClientUpdateCheckMode; import net.runelite.client.rs.ClientUpdateCheckMode;
@@ -73,7 +77,10 @@ import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.WidgetOverlay; import net.runelite.client.ui.overlay.WidgetOverlay;
import net.runelite.client.ui.overlay.tooltip.TooltipOverlay; import net.runelite.client.ui.overlay.tooltip.TooltipOverlay;
import net.runelite.client.ui.overlay.worldmap.WorldMapOverlay; import net.runelite.client.ui.overlay.worldmap.WorldMapOverlay;
import net.runelite.client.util.WorldUtil;
import net.runelite.http.api.RuneLiteAPI; import net.runelite.http.api.RuneLiteAPI;
import net.runelite.http.api.worlds.World;
import net.runelite.http.api.worlds.WorldResult;
import okhttp3.Cache; import okhttp3.Cache;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -132,6 +139,9 @@ public class RuneLite
@Inject @Inject
private Provider<WorldMapOverlay> worldMapOverlay; private Provider<WorldMapOverlay> worldMapOverlay;
@Inject
private WorldService worldService;
@Inject @Inject
@Nullable @Nullable
private Client client; private Client client;
@@ -151,6 +161,14 @@ public class RuneLite
.withValuesConvertedBy(new ConfigFileConverter()) .withValuesConvertedBy(new ConfigFileConverter())
.defaultsTo(DEFAULT_SESSION_FILE); .defaultsTo(DEFAULT_SESSION_FILE);
final ArgumentAcceptingOptionSpec<String> proxyInfo = parser
.accepts("proxy")
.withRequiredArg().ofType(String.class);
final ArgumentAcceptingOptionSpec<Integer> worldInfo = parser
.accepts("world")
.withRequiredArg().ofType(Integer.class);
final ArgumentAcceptingOptionSpec<File> configfile = parser.accepts("config", "Use a specified config file") final ArgumentAcceptingOptionSpec<File> configfile = parser.accepts("config", "Use a specified config file")
.withRequiredArg() .withRequiredArg()
.withValuesConvertedBy(new ConfigFileConverter()) .withValuesConvertedBy(new ConfigFileConverter())
@@ -185,6 +203,42 @@ public class RuneLite
logger.setLevel(Level.DEBUG); logger.setLevel(Level.DEBUG);
} }
if (options.has("proxy"))
{
String[] proxy = options.valueOf(proxyInfo).split(":");
if (proxy.length >= 2)
{
System.setProperty("socksProxyHost", proxy[0]);
System.setProperty("socksProxyPort", proxy[1]);
}
if (proxy.length >= 4)
{
System.setProperty("java.net.socks.username", proxy[2]);
System.setProperty("java.net.socks.password", proxy[3]);
final String user = proxy[2];
final char[] pass = proxy[3].toCharArray();
Authenticator.setDefault(new Authenticator()
{
private final PasswordAuthentication auth = new PasswordAuthentication(user, pass);
protected PasswordAuthentication getPasswordAuthentication()
{
return auth;
}
});
}
}
if (options.has("world"))
{
int world = options.valueOf(worldInfo);
System.setProperty("cli.world", String.valueOf(world));
}
Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> Thread.setDefaultUncaughtExceptionHandler((thread, throwable) ->
{ {
log.error("Uncaught exception:", throwable); log.error("Uncaught exception:", throwable);
@@ -336,6 +390,10 @@ public class RuneLite
SplashScreen.stop(); SplashScreen.stop();
clientUI.show(); clientUI.show();
//Set the world if specified via CLI args - will not work until clientUI.init is called
Optional<Integer> worldArg = Optional.ofNullable(System.getProperty("cli.world")).map(Integer::parseInt);
worldArg.ifPresent(this::setWorld);
} }
@VisibleForTesting @VisibleForTesting
@@ -383,6 +441,44 @@ public class RuneLite
} }
} }
private void setWorld(int cliWorld)
{
int correctedWorld = cliWorld < 300 ? cliWorld + 300 : cliWorld;
if (correctedWorld <= 300 || client.getWorld() == correctedWorld)
{
return;
}
final WorldResult worldResult = worldService.getWorlds();
if (worldResult == null)
{
log.warn("Failed to lookup worlds.");
return;
}
final World world = worldResult.findWorld(correctedWorld);
if (world != null)
{
final net.runelite.api.World rsWorld = client.createWorld();
rsWorld.setActivity(world.getActivity());
rsWorld.setAddress(world.getAddress());
rsWorld.setId(world.getId());
rsWorld.setPlayerCount(world.getPlayers());
rsWorld.setLocation(world.getLocation());
rsWorld.setTypes(WorldUtil.toWorldTypes(world.getTypes()));
client.changeWorld(rsWorld);
log.debug("Applied new world {}", correctedWorld);
}
else
{
log.warn("World {} not found.", correctedWorld);
}
}
private static void setupInsecureTrustManager(OkHttpClient.Builder okHttpClientBuilder) private static void setupInsecureTrustManager(OkHttpClient.Builder okHttpClientBuilder)
{ {
try try

View File

@@ -34,6 +34,7 @@ import okhttp3.HttpUrl;
public class RuneLiteProperties public class RuneLiteProperties
{ {
private static final String RUNELITE_TITLE = "runelite.title";
private static final String RUNELITE_VERSION = "runelite.version"; private static final String RUNELITE_VERSION = "runelite.version";
private static final String DISCORD_INVITE = "runelite.discord.invite"; private static final String DISCORD_INVITE = "runelite.discord.invite";
private static final String LAUNCHER_VERSION_PROPERTY = "runelite.launcher.version"; private static final String LAUNCHER_VERSION_PROPERTY = "runelite.launcher.version";
@@ -61,6 +62,17 @@ public class RuneLiteProperties
} }
} }
public static String getTitle()
{
final StringBuilder sb = new StringBuilder(properties.getProperty(RUNELITE_TITLE));
String proxy;
if ((proxy = System.getProperty("socksProxyHost")) != null)
{
sb.append(String.format(" (%s)", proxy));
}
return sb.toString();
}
public static String getVersion() public static String getVersion()
{ {
return properties.getProperty(RUNELITE_VERSION); return properties.getProperty(RUNELITE_VERSION);

View File

@@ -152,6 +152,11 @@ public class DefaultWorldPlugin extends Plugin
log.debug("Stored old world {}", worldCache); log.debug("Stored old world {}", worldCache);
} }
if (System.getProperty("cli.world") != null)
{
return;
}
final int newWorld = !config.useLastWorld() ? config.getWorld() : config.lastWorld(); final int newWorld = !config.useLastWorld() ? config.getWorld() : config.lastWorld();
changeWorld(newWorld); changeWorld(newWorld);
} }

View File

@@ -71,6 +71,7 @@ import net.runelite.api.Point;
import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameStateChanged;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo; import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.RuneLiteProperties;
import net.runelite.client.callback.ClientThread; import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.config.ExpandResizeType; import net.runelite.client.config.ExpandResizeType;
@@ -121,7 +122,6 @@ public class ClientUI
private final Provider<ClientThread> clientThreadProvider; private final Provider<ClientThread> clientThreadProvider;
private final EventBus eventBus; private final EventBus eventBus;
private final boolean safeMode; private final boolean safeMode;
private final String title;
private final CardLayout cardLayout = new CardLayout(); private final CardLayout cardLayout = new CardLayout();
private final Rectangle sidebarButtonPosition = new Rectangle(); private final Rectangle sidebarButtonPosition = new Rectangle();
@@ -153,8 +153,7 @@ public class ClientUI
ConfigManager configManager, ConfigManager configManager,
Provider<ClientThread> clientThreadProvider, Provider<ClientThread> clientThreadProvider,
EventBus eventBus, EventBus eventBus,
@Named("safeMode") boolean safeMode, @Named("safeMode") boolean safeMode
@Named("runelite.title") String title
) )
{ {
this.config = config; this.config = config;
@@ -165,7 +164,6 @@ public class ClientUI
this.clientThreadProvider = clientThreadProvider; this.clientThreadProvider = clientThreadProvider;
this.eventBus = eventBus; this.eventBus = eventBus;
this.safeMode = safeMode; this.safeMode = safeMode;
this.title = title;
} }
@Subscribe @Subscribe
@@ -298,7 +296,7 @@ public class ClientUI
return false; return false;
} }
frame.setTitle(title + " - " + name); frame.setTitle(RuneLiteProperties.getTitle() + " - " + name);
return true; return true;
}); });
} }
@@ -325,7 +323,7 @@ public class ClientUI
// Try to enable fullscreen on OSX // Try to enable fullscreen on OSX
OSXUtil.tryEnableFullscreen(frame); OSXUtil.tryEnableFullscreen(frame);
frame.setTitle(title); frame.setTitle(RuneLiteProperties.getTitle());
frame.setIconImage(ICON); frame.setIconImage(ICON);
frame.getLayeredPane().setCursor(Cursor.getDefaultCursor()); // Prevent substance from using a resize cursor for pointing frame.getLayeredPane().setCursor(Cursor.getDefaultCursor()); // Prevent substance from using a resize cursor for pointing
frame.setLocationRelativeTo(frame.getOwner()); frame.setLocationRelativeTo(frame.getOwner());
@@ -511,7 +509,7 @@ public class ClientUI
frame.revalidateMinimumSize(); frame.revalidateMinimumSize();
// Create tray icon (needs to be created after frame is packed) // Create tray icon (needs to be created after frame is packed)
trayIcon = SwingUtil.createTrayIcon(ICON, title, frame); trayIcon = SwingUtil.createTrayIcon(ICON, RuneLiteProperties.getTitle(), frame);
// Move frame around (needs to be done after frame is packed) // Move frame around (needs to be done after frame is packed)
if (config.rememberScreenBounds() && !safeMode) if (config.rememberScreenBounds() && !safeMode)
@@ -1038,12 +1036,12 @@ public class ClientUI
if (player != null && player.getName() != null) if (player != null && player.getName() != null)
{ {
frame.setTitle(title + " - " + player.getName()); frame.setTitle(RuneLiteProperties.getTitle() + " - " + player.getName());
} }
} }
else else
{ {
frame.setTitle(title); frame.setTitle(RuneLiteProperties.getTitle());
} }
if (frame.isAlwaysOnTopSupported()) if (frame.isAlwaysOnTopSupported())