-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from v4Guard/develop
v4Guard Plugin v1.1.3
- Loading branch information
Showing
13 changed files
with
175 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/io/v4guard/plugin/core/socket/listener/CleanCacheListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.v4guard.plugin.core.socket.listener; | ||
|
||
import io.socket.emitter.Emitter; | ||
import io.v4guard.plugin.core.check.common.CheckStatus; | ||
import io.v4guard.plugin.core.check.common.VPNCheck; | ||
import io.v4guard.plugin.core.socket.BackendConnector; | ||
import io.v4guard.plugin.core.v4GuardCore; | ||
import org.bson.Document; | ||
|
||
public class CleanCacheListener implements Emitter.Listener { | ||
|
||
BackendConnector backendConnector; | ||
|
||
public CleanCacheListener(BackendConnector backendConnector) { | ||
this.backendConnector = backendConnector; | ||
} | ||
|
||
@Override | ||
public void call(Object... args) { | ||
Document doc = Document.parse(args[0].toString()); | ||
if(doc.containsKey("username")){ | ||
v4GuardCore.getInstance().getCheckManager().cleanupChecks(doc.getString("username")); | ||
} else { | ||
for(VPNCheck s : v4GuardCore.getInstance().getCheckManager().getCheckStatusMap().values()){ | ||
if(s.getStatus() != CheckStatus.WAITING){ | ||
v4GuardCore.getInstance().getCheckManager().getCheckStatusMap().remove(s.getName()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/io/v4guard/plugin/core/socket/listener/FindListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.v4guard.plugin.core.socket.listener; | ||
|
||
import io.socket.emitter.Emitter; | ||
import io.v4guard.plugin.core.socket.BackendConnector; | ||
import io.v4guard.plugin.core.v4GuardCore; | ||
import org.bson.Document; | ||
|
||
public class FindListener implements Emitter.Listener { | ||
|
||
BackendConnector backendConnector; | ||
|
||
public FindListener(BackendConnector backendConnector) { | ||
this.backendConnector = backendConnector; | ||
} | ||
|
||
@Override | ||
public void call(Object... args) { | ||
Document doc = Document.parse(args[0].toString()); | ||
if(doc.containsKey("username")){ | ||
String taskID = doc.getString("taskID"); | ||
String username = doc.getString("username"); | ||
//Obviously the first check processor in the list of processors is the one that is active. | ||
if(v4GuardCore.getInstance().getCheckManager().getProcessors().get(0).isPlayerOnline(username)){ | ||
String server = v4GuardCore.getInstance().getCheckManager().getProcessors().get(0).getPlayerServer(username); | ||
backendConnector.getSocket().emit("find", | ||
new Document("taskID", taskID) | ||
.append("username", username) | ||
.append("location", server) | ||
.toJson() | ||
); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/io/v4guard/plugin/core/utils/HashCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.v4guard.plugin.core.utils; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.InputStream; | ||
import java.security.MessageDigest; | ||
|
||
public class HashCalculator { | ||
|
||
public static String calculateHash(){ | ||
try { | ||
File jarFile = new File(HashCalculator.class.getProtectionDomain().getCodeSource().getLocation().toURI()); | ||
MessageDigest digest = MessageDigest.getInstance("SHA-1"); | ||
InputStream fis = new FileInputStream(jarFile); | ||
int n = 0; | ||
byte[] buffer = new byte[8192]; | ||
while (n != -1) { | ||
n = fis.read(buffer); | ||
if (n > 0) { | ||
digest.update(buffer, 0, n); | ||
} | ||
} | ||
byte[] messageDigest = digest.digest(); | ||
StringBuilder hexString = new StringBuilder(); | ||
for (byte aMessageDigest : messageDigest) { | ||
String hex = Integer.toHexString(0xff & aMessageDigest); | ||
if (hex.length() == 1) hexString.append('0'); | ||
hexString.append(hex); | ||
} | ||
return hexString.toString(); | ||
} catch (Exception e) { | ||
return "7634670e00000000000000000000000000000001"; | ||
} | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters