Skip to content

Commit

Permalink
Merge pull request #3 from v4Guard/develop
Browse files Browse the repository at this point in the history
v4Guard Plugin v1.0.3
  • Loading branch information
samfces authored Aug 6, 2022
2 parents e81df2c + 30d67d6 commit 0223d93
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

<groupId>io.v4guard</groupId>
<artifactId>v4guard-plugin</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<packaging>jar</packaging>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<build>
<finalName>v4Guard-1.0</finalName>
<finalName>v4Guard-1.0.3</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;

public class BackendConnector {
private Socket socket;
Expand All @@ -32,7 +34,7 @@ public class BackendConnector {
public BackendConnector() throws IOException, URISyntaxException {
HashMap<String, List<String>> headers = new HashMap<>();
headers.put("v4g-version", Collections.singletonList("1.0.0"));
headers.put("v4g-hostname", Collections.singletonList(InetAddress.getLocalHost().getHostName()));
headers.put("v4g-hostname", Collections.singletonList(getHostname()));
headers.put("v4g-name", Collections.singletonList(new File(System.getProperty("user.dir")).getName()));
headers.put("v4g-service", Collections.singletonList("minecraft"));
headers.put("v4g-mode", Collections.singletonList(v4GuardCore.getInstance().getPluginMode().name()));
Expand Down Expand Up @@ -131,4 +133,24 @@ public void setReconnected(boolean reconnected) {
public Runtime getRuntime() {
return runtime;
}

public String getHostname(){
if(isRunningInsideDocker()){
return "Docker Container";
} else {
try {
return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
return "Unknown";
}
}
}

public static Boolean isRunningInsideDocker() {
try (Stream<String> stream = Files.lines(Paths.get("/proc/1/cgroup"))) {
return stream.anyMatch(line -> line.contains("/docker"));
} catch (IOException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ public void onPreLogin(final AsyncPlayerPreLoginEvent e) {
}
Document kickMessages = (Document) v4GuardSpigot.getCoreInstance().getBackendConnector().getSettings().get("messages");
final boolean wait = (boolean) v4GuardSpigot.getCoreInstance().getBackendConnector().getSettings().get("waitResponse");
//((CraftPlayer) player).getHandle().playerConnection.networkManager.getVersion() <- this is the version of the client
new CompletableNameCheckTask(e.getName()) {
@Override
public void complete(boolean nameIsValid) {
if(nameIsValid){
new CompletableIPCheckTask(e.getAddress().getHostAddress(), e.getName(), -1 /*version*/) {
new CompletableIPCheckTask(e.getAddress().getHostAddress(), e.getName(), -1) {
CompletableIPCheckTask task = this;
@Override
public void complete() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import java.util.logging.Logger;

@Plugin(id = "v4guard-plugin", name = "v4Guard Plugin", version = "1.0.2",
@Plugin(id = "v4guard-plugin", name = "v4Guard Plugin", version = "1.0.3",
url = "https://v4guard.io", description = "v4Guard Plugin for Minecraft Servers", authors = {"DigitalSynware"})
public class v4GuardVelocity {

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/bungee.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: v4guard-plugin
version: 1.0.2
version: 1.0.3
main: io.v4guard.plugin.bungee.v4GuardBungee
author: DigitalSynware
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: v4guard-plugin
version: 1.0.2
version: 1.0.3
main: io.v4guard.plugin.spigot.v4GuardSpigot
author: DigitalSynware

0 comments on commit 0223d93

Please sign in to comment.