alwaysAdmin extension is now a checkbox in Extra

This commit is contained in:
sirjonasxx 2021-08-14 02:47:17 +02:00
parent 9efb62c8cd
commit bdf8f81d73
7 changed files with 97 additions and 204 deletions

25
.gitignore vendored
View File

@ -15,22 +15,9 @@ Extensions/BlockReplacePackets/.classpath
.project .project
.settings/org.eclipse.m2e.core.prefs .settings/org.eclipse.m2e.core.prefs
.vscode/launch.json .vscode/launch.json
Extensions/AdminOnConnect/.classpath
Extensions/AdminOnConnect/.project *.classpath
Extensions/AdminOnConnect/.settings/org.eclipse.jdt.apt.core.prefs *.project
Extensions/AdminOnConnect/.settings/org.eclipse.jdt.core.prefs *.settings/org.eclipse.jdt.apt.core.prefs
Extensions/AdminOnConnect/.settings/org.eclipse.m2e.core.prefs *.settings/org.eclipse.jdt.core.prefs
Extensions/BlockReplacePackets/.project *.settings/org.eclipse.m2e.core.prefs
Extensions/BlockReplacePackets/.settings/org.eclipse.jdt.apt.core.prefs
Extensions/BlockReplacePackets/.settings/org.eclipse.jdt.core.prefs
Extensions/BlockReplacePackets/.settings/org.eclipse.m2e.core.prefs
Extensions/HappySpeech/.classpath
Extensions/HappySpeech/.project
Extensions/HappySpeech/.settings/org.eclipse.jdt.apt.core.prefs
Extensions/HappySpeech/.settings/org.eclipse.jdt.core.prefs
Extensions/HappySpeech/.settings/org.eclipse.m2e.core.prefs
G-Earth/.classpath
G-Earth/.project
G-Earth/.settings/org.eclipse.jdt.apt.core.prefs
G-Earth/.settings/org.eclipse.jdt.core.prefs
G-Earth/.settings/org.eclipse.m2e.core.prefs

View File

@ -1,113 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>AdminOnConnect</artifactId>
<packaging>jar</packaging>
<version>0.0.1-beta</version>
<parent>
<groupId>G-Earth</groupId>
<artifactId>G-Earth-Parent</artifactId>
<version>1.4.1</version>
<relativePath>../../</relativePath>
</parent>
<build>
<resources>
<!-- Embedded FXML and CSS resources -->
<resource>
<filtering>false</filtering>
<directory>src/main/java</directory>
<includes>
<include>**/*.fxml</include>
<include>**/*.css</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<outputDirectory>${project.build.directory}/bin</outputDirectory>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
<mainClass>extensions.adminonconnect.AdminOnConnect</mainClass>
<useUniqueVersions>false</useUniqueVersions>
<classpathPrefix>lib/</classpathPrefix>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
<finalName>${project.artifactId}</finalName>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.directory}/bin</outputDirectory>
<archive>
<manifest>
<mainClass>extensions.adminonconnect.AdminOnConnect</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
<!-- global build folder -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target name="copy to extensions folder">
<copy file="target/bin/AdminOnConnect.jar" todir="../../Build/Linux/Extensions"/>
<copy file="target/bin/AdminOnConnect.jar" todir="../../Build/Mac/Extensions"/>
<copy file="target/bin/AdminOnConnect.jar" todir="../../Build/Windows_32bit/Extensions"/>
<copy file="target/bin/AdminOnConnect.jar" todir="../../Build/Windows_64bit/Extensions"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>G-Earth</groupId>
<artifactId>G-Earth</artifactId>
<version>1.4.1</version>
<!--<scope>provided</scope>-->
</dependency>
</dependencies>
</project>

View File

@ -1,52 +0,0 @@
package extensions.adminonconnect;
import gearth.extensions.Extension;
import gearth.extensions.ExtensionInfo;
import gearth.protocol.HMessage;
import gearth.protocol.HPacket;
/**
* Created by Jonas on 26/06/18.
*/
@ExtensionInfo(
Title = "Always admin!",
Description = "Gives you admin permission on connect",
Version = "1.0",
Author = "sirjonasxx"
)
public class AdminOnConnect extends Extension {
public static void main(String[] args) {
new AdminOnConnect(args).run();
}
public AdminOnConnect(String[] args) {
super(args);
}
private boolean done = true;
protected void initExtension() {
intercept(HMessage.Direction.TOCLIENT, message -> {
if (!done) {
HPacket packet = message.getPacket();
if (packet.length() == 11) {
if (packet.readByte(14) == 0 || packet.readByte(14) == 1) {
packet.replaceInt(6, 7);
packet.replaceInt(10, 7);
packet.replaceBoolean(14, true);
done = true;
writeToConsole("Replaced user permissions");
}
}
}
});
intercept(HMessage.Direction.TOSERVER, 4000, message -> done = false);
}
// protected void onStartConnection() {
// done = false;
// }
}

View File

@ -0,0 +1,54 @@
package gearth.services.always_admin;
import gearth.protocol.HConnection;
import gearth.protocol.HMessage;
import gearth.protocol.HPacket;
public class AdminService {
private final HConnection hConnection;
volatile private boolean enabled;
volatile private HPacket originalPacket;
public AdminService(boolean enabled, HConnection hConnection) {
this.enabled = enabled;
this.hConnection = hConnection;
originalPacket = null;
}
public void setEnabled(boolean enabled) {
if (enabled != this.enabled) {
this.enabled = enabled;
if (originalPacket != null) {
if (enabled) {
hConnection.sendToClient(new HPacket(originalPacket.headerId(), 7, 7, true));
}
else {
hConnection.sendToClient(originalPacket);
}
}
}
}
public void onConnect() {
originalPacket = null;
}
public void onMessage(HMessage message) {
HPacket packet = message.getPacket();
if (message.getDestination() == HMessage.Direction.TOCLIENT
&& (originalPacket == null || packet.headerId() == originalPacket.headerId())
&& packet.length() == 11 && (packet.readByte(14) == 0 || packet.readByte(14) == 1)) {
originalPacket = new HPacket(packet);
if (enabled) {
packet.replaceInt(6, 7);
packet.replaceInt(10, 7);
packet.replaceBoolean(14, true);
}
}
}
}

View File

@ -3,9 +3,12 @@ package gearth.ui.extra;
import gearth.Main; import gearth.Main;
import gearth.misc.Cacher; import gearth.misc.Cacher;
import gearth.protocol.HConnection; import gearth.protocol.HConnection;
import gearth.protocol.HMessage;
import gearth.protocol.TrafficListener;
import gearth.protocol.connection.HState; import gearth.protocol.connection.HState;
import gearth.protocol.connection.proxy.ProxyProviderFactory; import gearth.protocol.connection.proxy.ProxyProviderFactory;
import gearth.protocol.connection.proxy.SocksConfiguration; import gearth.protocol.connection.proxy.SocksConfiguration;
import gearth.services.always_admin.AdminService;
import gearth.services.g_python.GPythonVersionUtils; import gearth.services.g_python.GPythonVersionUtils;
import gearth.ui.SubForm; import gearth.ui.SubForm;
import gearth.ui.info.InfoController; import gearth.ui.info.InfoController;
@ -25,6 +28,7 @@ public class ExtraController extends SubForm implements SocksConfiguration {
public static final String INFO_URL_GPYTHON = "https://github.com/sirjonasxx/G-Earth/wiki/G-Python-qtConsole"; public static final String INFO_URL_GPYTHON = "https://github.com/sirjonasxx/G-Earth/wiki/G-Python-qtConsole";
public static final String NOTEPAD_CACHE_KEY = "notepad_text"; public static final String NOTEPAD_CACHE_KEY = "notepad_text";
public static final String ALWAYS_ADMIN_KEY = "always_admin";
public static final String SOCKS_CACHE_KEY = "socks_config"; public static final String SOCKS_CACHE_KEY = "socks_config";
public static final String GPYTHON_CACHE_KEY = "use_gpython"; public static final String GPYTHON_CACHE_KEY = "use_gpython";
@ -51,6 +55,9 @@ public class ExtraController extends SubForm implements SocksConfiguration {
public GridPane grd_socksInfo; public GridPane grd_socksInfo;
public TextField txt_socksPort; public TextField txt_socksPort;
public TextField txt_socksIp; public TextField txt_socksIp;
public CheckBox cbx_admin;
private AdminService adminService;
public void initialize() { public void initialize() {
url_troubleshooting.setTooltip(new Tooltip("https://github.com/sirjonasxx/G-Earth/wiki/Troubleshooting")); url_troubleshooting.setTooltip(new Tooltip("https://github.com/sirjonasxx/G-Earth/wiki/Troubleshooting"));
@ -72,6 +79,10 @@ public class ExtraController extends SubForm implements SocksConfiguration {
cbx_gpython.setSelected(Cacher.getCacheContents().getBoolean(GPYTHON_CACHE_KEY)); cbx_gpython.setSelected(Cacher.getCacheContents().getBoolean(GPYTHON_CACHE_KEY));
} }
if (Cacher.getCacheContents().has(ALWAYS_ADMIN_KEY)) {
cbx_admin.setSelected(Cacher.getCacheContents().getBoolean(ALWAYS_ADMIN_KEY));
}
cbx_debug.selectedProperty().addListener(observable -> HConnection.DEBUG = cbx_debug.isSelected()); cbx_debug.selectedProperty().addListener(observable -> HConnection.DEBUG = cbx_debug.isSelected());
cbx_disableDecryption.selectedProperty().addListener(observable -> HConnection.DECRYPTPACKETS = !cbx_disableDecryption.isSelected()); cbx_disableDecryption.selectedProperty().addListener(observable -> HConnection.DECRYPTPACKETS = !cbx_disableDecryption.isSelected());
@ -82,6 +93,10 @@ public class ExtraController extends SubForm implements SocksConfiguration {
@Override @Override
protected void onParentSet() { protected void onParentSet() {
adminService = new AdminService(cbx_admin.isSelected(), getHConnection());
getHConnection().addTrafficListener(1, message -> adminService.onMessage(message));
getHConnection().getStateObservable().addListener((oldState, newState) -> {if (newState == HState.CONNECTED) adminService.onConnect();});
parentController.getStage().setAlwaysOnTop(cbx_alwaysOnTop.isSelected()); parentController.getStage().setAlwaysOnTop(cbx_alwaysOnTop.isSelected());
cbx_alwaysOnTop.selectedProperty().addListener(observable -> parentController.getStage().setAlwaysOnTop(cbx_alwaysOnTop.isSelected())); cbx_alwaysOnTop.selectedProperty().addListener(observable -> parentController.getStage().setAlwaysOnTop(cbx_alwaysOnTop.isSelected()));
@ -99,6 +114,7 @@ public class ExtraController extends SubForm implements SocksConfiguration {
protected void onExit() { protected void onExit() {
Cacher.put(NOTEPAD_CACHE_KEY, txtarea_notepad.getText()); Cacher.put(NOTEPAD_CACHE_KEY, txtarea_notepad.getText());
Cacher.put(GPYTHON_CACHE_KEY, cbx_gpython.isSelected()); Cacher.put(GPYTHON_CACHE_KEY, cbx_gpython.isSelected());
Cacher.put(ALWAYS_ADMIN_KEY, cbx_admin.isSelected());
saveSocksConfig(); saveSocksConfig();
} }
@ -191,4 +207,9 @@ public class ExtraController extends SubForm implements SocksConfiguration {
} }
} }
public void adminCbxClick(ActionEvent actionEvent) {
adminService.setEnabled(cbx_admin.isSelected());
}
} }

View File

@ -1,17 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.*?>
<?import javafx.scene.control.CheckBox?> <?import javafx.scene.control.*?>
<?import javafx.scene.control.Hyperlink?> <?import javafx.scene.layout.*?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<GridPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="258.0" prefWidth="650.0" xmlns="http://javafx.com/javafx/8.0.241" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.ui.extra.ExtraController"> <GridPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="258.0" prefWidth="650.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.ui.extra.ExtraController">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="331.0" minWidth="10.0" prefWidth="318.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="331.0" minWidth="10.0" prefWidth="318.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="390.0" minWidth="10.0" prefWidth="247.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="390.0" minWidth="10.0" prefWidth="247.0" />
@ -34,12 +27,13 @@
</columnConstraints> </columnConstraints>
<rowConstraints> <rowConstraints>
<RowConstraints maxHeight="7.0" minHeight="7.0" prefHeight="7.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="7.0" minHeight="7.0" prefHeight="7.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="28.0" minHeight="28.0" prefHeight="28.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="28.0" minHeight="28.0" prefHeight="28.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="28.0" minHeight="28.0" prefHeight="28.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="10.0" prefHeight="232.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="1.7976931348623157E308" minHeight="10.0" prefHeight="232.0" vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<children> <children>
<GridPane fx:id="grd_advanced" disable="true" prefHeight="161.0" prefWidth="299.0" style="-fx-border-color: #888888; -fx-border-radius: 5px;" GridPane.rowIndex="3"> <GridPane fx:id="grd_advanced" disable="true" prefHeight="161.0" prefWidth="299.0" style="-fx-border-color: #888888; -fx-border-radius: 5px;" GridPane.rowIndex="4">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints> </columnConstraints>
@ -50,7 +44,7 @@
<RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<GridPane.margin> <GridPane.margin>
<Insets bottom="20.0" left="10.0" right="10.0" top="6.0" /> <Insets bottom="10.0" left="10.0" right="10.0" top="6.0" />
</GridPane.margin> </GridPane.margin>
<padding> <padding>
<Insets left="7.0" top="3.0" /> <Insets left="7.0" top="3.0" />
@ -110,7 +104,7 @@
</GridPane> </GridPane>
</children> </children>
</GridPane> </GridPane>
<CheckBox fx:id="cbx_advanced" mnemonicParsing="false" text="Advanced" textFill="#000000ba" GridPane.rowIndex="2"> <CheckBox fx:id="cbx_advanced" mnemonicParsing="false" text="Advanced" textFill="#000000ba" GridPane.rowIndex="3">
<GridPane.margin> <GridPane.margin>
<Insets left="10.0" top="2.0" /> <Insets left="10.0" top="2.0" />
</GridPane.margin> </GridPane.margin>
@ -118,7 +112,12 @@
<Insets top="2.0" /> <Insets top="2.0" />
</padding> </padding>
</CheckBox> </CheckBox>
<CheckBox fx:id="cbx_gpython" mnemonicParsing="false" onAction="#gpythonCbxClick" text="Enable G-Python scripting" textFill="#000000ba" GridPane.rowIndex="1"> <CheckBox fx:id="cbx_gpython" mnemonicParsing="false" onAction="#gpythonCbxClick" text="G-Python scripting" textFill="#000000ba" GridPane.rowIndex="2">
<GridPane.margin>
<Insets left="10.0" top="2.0" />
</GridPane.margin>
</CheckBox>
<CheckBox fx:id="cbx_admin" layoutX="20.0" layoutY="25.0" mnemonicParsing="false" onAction="#adminCbxClick" selected="true" text="Client-side staff permissions" textFill="#000000ba" GridPane.rowIndex="1">
<GridPane.margin> <GridPane.margin>
<Insets left="10.0" top="2.0" /> <Insets left="10.0" top="2.0" />
</GridPane.margin> </GridPane.margin>

View File

@ -15,9 +15,6 @@
<modules> <modules>
<module>G-Earth</module> <module>G-Earth</module>
<!-- Compile our extensions too please! -->
<module>Extensions/AdminOnConnect</module>
</modules> </modules>
<build> <build>