Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
Bugfix -> Added Identifier for fixing false tracking + logging bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
EinfacheSache committed Aug 27, 2023
1 parent ddcec70 commit 45ad182
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public Stats getStats() {
);
}

@Override
public String getServerAddress() {
return getProxy().getConfig().getListeners().stream().findFirst().orElseThrow(null).getSocketAddress().toString();
}

@Override
public void sendMessage(Object receiver, String text) {
sendMessage(receiver, text, null, null, null, null);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/de/cubeattack/neoprotect/core/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Core {
private final RestAPIRequests restAPIRequests;
private final NeoProtectPlugin plugin;
private final Localization localization;
private final boolean isJPremiumInstalled;
private final List<Object> playerInSetup = new ArrayList<>();
private final List<String> directConnectWhitelist= new ArrayList<>();
private final ConcurrentHashMap<KeepAliveResponseKey, Long> pingMap = new ConcurrentHashMap<>();
Expand All @@ -41,6 +42,7 @@ public Core(NeoProtectPlugin plugin) {
LogManager.getLogger().setLogger(plugin.getLogger());

this.plugin = plugin;
this.isJPremiumInstalled = plugin.getPlugins().contains("JPremium");
this.versionResult = VersionUtils.checkVersion("NeoProtect", "NeoPlugin", "v" + plugin.getPluginVersion(), VersionUtils.UpdateSetting.DISABLED).message();

FileUtils config = new FileUtils(Core.class.getResourceAsStream("/config.yml"), "plugins/NeoProtect", "config.yml", false);
Expand Down Expand Up @@ -132,6 +134,6 @@ public void setVersionResult(VersionUtils.Result versionResult) {
}

public boolean isPlayerMaintainer(UUID playerUUID, boolean onlineMode) {
return (onlineMode && playerUUID.equals(maintainerOnlineUUID)) || (!onlineMode && playerUUID.equals(maintainerOfflineeUUID));
return ((onlineMode || isJPremiumInstalled) && playerUUID.equals(maintainerOnlineUUID)) || ((!onlineMode || isJPremiumInstalled) && playerUUID.equals(maintainerOfflineeUUID));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public interface NeoProtectPlugin {

Logger getLogger();

String getServerAddress();

ArrayList<String> getPlugins();

PluginType getPluginType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected Response callRequest(Request request) {
try {
return client.newCall(request).execute();
} catch (UnknownHostException | SocketTimeoutException | SocketException connectionException) {
if(!request.url().toString().equals(core.getRestAPI().getPasteServer())) {
if(!request.url().toString().equals(core.getRestAPI().getPasteServer()) && !request.url().toString().equals(core.getRestAPI().getStatsServer())) {
core.severe(request + " failed cause (" + connectionException + ")");
}else
core.debug(request + " failed cause (" + connectionException + ")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
import de.cubeattack.neoprotect.core.model.Firewall;
import de.cubeattack.neoprotect.core.model.Gameshield;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class RestAPIRequests {

Expand Down Expand Up @@ -82,14 +80,14 @@ public String getPlan() {
return null;
}

private boolean updateStats(RequestBody requestBody, String gameshieldID, String backendID) {
return new ResponseManager(rest.callRequest(new Request.Builder().url(statsServer).header("GameshieldID", gameshieldID).header("BackendID", backendID).post(requestBody).build())).checkCode(200);
}

private boolean updateBackend(RequestBody requestBody, String backendID) {
return rest.request(RequestType.POST_GAMESHIELD_BACKEND_UPDATE, requestBody, Config.getGameShieldID(),backendID).checkCode(200);
}

public boolean updateStats(RequestBody requestBody, String identifier, String gameshieldID, String backendID) {
return new ResponseManager(rest.callRequest(new Request.Builder().url(statsServer).header("identifier", identifier).header("GameshieldID", gameshieldID).header("BackendID", backendID).post(requestBody).build())).checkCode(200);
}

public void setProxyProtocol(boolean setting) {
rest.request(RequestType.POST_GAMESHIELD_UPDATE, RequestBody.create(MediaType.parse("application/json"), new JsonBuilder().appendField("proxyProtocol", String.valueOf(setting)).build().toString()), Config.getGameShieldID());
}
Expand Down Expand Up @@ -235,7 +233,7 @@ public void run() {
if (!setup) return;

RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new Gson().toJson(core.getPlugin().getStats()));
if(!updateStats(requestBody, Config.getGameShieldID(),Config.getBackendID()))
if(!updateStats(requestBody, String.valueOf(UUID.nameUUIDFromBytes((Config.getGameShieldID() + ":" + Config.getBackendID() + ":" + core.getPlugin().getServerAddress()).getBytes(StandardCharsets.UTF_8))), Config.getGameShieldID(), Config.getBackendID()))
core.debug("Request to Update stats failed");
}
}, 1000, 1000 * 5);
Expand Down Expand Up @@ -346,6 +344,10 @@ public String getPasteServer() {
return pasteServer;
}

public String getStatsServer() {
return statsServer;
}

public boolean isSetup() {
return setup;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public Stats getStats() {
);
}

@Override
public String getServerAddress() {
return "/0.0.0.0:" + getServer().getPort();
}

@Override
public void sendMessage(Object receiver, String text) {
sendMessage(receiver, text, null, null, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public ProxyServer getProxy() {
return proxy;
}

@Override
public String getServerAddress() {
return getProxy().getBoundAddress().toString();
}

@Override
public void sendMessage(Object receiver, String text) {
sendMessage(receiver, text, null, null, null, null);
Expand Down

0 comments on commit 45ad182

Please sign in to comment.