Skip to content

Commit

Permalink
When the connection domain is invalid, print error and the session is…
Browse files Browse the repository at this point in the history
… not sent
  • Loading branch information
luluxe committed Oct 3, 2023
1 parent 22b96f2 commit c6afa2f
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>net</groupId>
<artifactId>communityanalytics</artifactId>
<name>communityanalytics</name>
<version>1.0.5</version>
<version>1.0.6</version>
<url>http://maven.apache.org</url>
<build>
<plugins>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>net</groupId>
<artifactId>communityanalytics</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
<packaging>jar</packaging>

<name>communityanalytics</name>
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/net/communityanalytics/common/RegexUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.communityanalytics.common;

public class RegexUtil {
/**
* Check if a string is a valid domain
*
* @param domain boolean
* @return boolean
*/
public static boolean isDomain(String domain) {
String domain_regex = "^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$";
if (domain.matches(domain_regex))
return true;
if (domain.contains(":"))
return isDomain(domain.split(":")[0]);
return false;
}
}
12 changes: 9 additions & 3 deletions src/main/java/net/communityanalytics/spigot/data/Session.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.communityanalytics.spigot.data;

import com.google.gson.JsonObject;
import net.communityanalytics.common.RegexUtil;
import net.communityanalytics.spigot.SpigotPlugin;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -79,14 +80,19 @@ public void finish() {

/**
* Check if a session is valid
* For a session to be valid, the number of seconds between the start
* of the session and the end of the session must be greater than
* For a session to be valid:
* - The ip_connect need to be a valid domain name
* - The number of seconds between the start of the session and the end of the session must be greater than
* the minimum session time configured in the config.yml file.
* We will check first if the session is finished.
*
* @return boolean
*/
public boolean isValid() {
if (!RegexUtil.isDomain(this.ip_connect)) {
SpigotPlugin.logger().printError("The ip_connect is not a valid domain name: " + this.ip_connect);
SpigotPlugin.logger().printError("Contact CommunityAnalytics on Discord, if you can't solve this problem.");
return false;
}
return ChronoUnit.SECONDS.between(this.join_at, this.quit_at) >= SpigotPlugin.config().getMinimumsSessionDuration();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class PlatformManager {
public boolean success = false;
public String version = "1.0.5";
public String version = "1.0.6";

public void getPlatformInfo() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.bstats.velocity.Metrics;
import org.slf4j.Logger;

@Plugin(id = "communityanalytics", name = "CommunityAnalytics", version = "1.0.5")
@Plugin(id = "communityanalytics", name = "CommunityAnalytics", version = "1.0.6")
public class VelocityPlugin {
public static VelocityPlugin instance;
private final ChannelIdentifier channel = new LegacyChannelIdentifier(CommunityAnalytics.CHANNEL_INFO);
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: CommunityAnalytics
author: FNetwork
main: net.communityanalytics.bungee.BungeePlugin
version: 1.0.5
version: 1.0.6
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CommunityAnalytics
author: FNetwork
main: net.communityanalytics.spigot.SpigotPlugin
website: https://communityanalytics.net
version: 1.0.5
version: 1.0.6
api-version: 1.13
commands:
communityanalytics:
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/velocity-plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "communityanalytics",
"name": "CommunityAnalytics",
"version": "1.0.5",
"version": "1.0.6",
"authors": [
"FNetwork"
],
Expand Down

0 comments on commit c6afa2f

Please sign in to comment.