-
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 #14 from v4Guard/develop
v4Guard Plugin v1.1.3b
- Loading branch information
Showing
11 changed files
with
192 additions
and
4 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
45 changes: 45 additions & 0 deletions
45
src/main/java/io/v4guard/plugin/bungee/accounts/BungeeMessageReceiver.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,45 @@ | ||
package io.v4guard.plugin.bungee.accounts; | ||
|
||
import io.v4guard.plugin.core.accounts.auth.Authentication; | ||
import io.v4guard.plugin.core.accounts.messaging.MessageReceiver; | ||
import io.v4guard.plugin.core.v4GuardCore; | ||
import net.md_5.bungee.api.ProxyServer; | ||
import net.md_5.bungee.api.event.PluginMessageEvent; | ||
import net.md_5.bungee.api.plugin.Listener; | ||
import net.md_5.bungee.api.plugin.Plugin; | ||
import net.md_5.bungee.event.EventHandler; | ||
import org.bson.Document; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.DataInputStream; | ||
import java.io.IOException; | ||
|
||
public class BungeeMessageReceiver extends MessageReceiver implements Listener { | ||
|
||
public BungeeMessageReceiver(Plugin plugin) { | ||
plugin.getProxy().getPluginManager().registerListener(plugin, this); | ||
if(!MessageReceiver.CHANNEL.equals("BungeeCord")) { | ||
plugin.getProxy().registerChannel(MessageReceiver.CHANNEL); | ||
} | ||
for(String s : ProxyServer.getInstance().getChannels()) { | ||
System.out.println(s); | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onMessage(PluginMessageEvent e){ | ||
if (!e.getTag().equals(MessageReceiver.CHANNEL)) { | ||
return; | ||
} | ||
DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getData())); | ||
try { | ||
String data = in.readUTF(); | ||
Document doc = Document.parse(data); | ||
Authentication auth = Authentication.deserialize(doc); | ||
v4GuardCore.getInstance().getAccountShieldManager().sendSocketMessage(auth); | ||
} catch (IOException ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
|
||
} |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/io/v4guard/plugin/core/accounts/AccountShieldManager.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.accounts; | ||
|
||
import io.v4guard.plugin.core.accounts.auth.Authentication; | ||
import io.v4guard.plugin.core.accounts.messaging.MessageReceiver; | ||
import io.v4guard.plugin.core.v4GuardCore; | ||
import org.bson.Document; | ||
|
||
public class AccountShieldManager { | ||
|
||
private MessageReceiver receiver; | ||
|
||
public AccountShieldManager(MessageReceiver receiver) { | ||
this.receiver = receiver; | ||
} | ||
|
||
public MessageReceiver getReceiver() { | ||
return receiver; | ||
} | ||
|
||
public void sendSocketMessage(Authentication auth){ | ||
|
||
Document shieldSettings = (Document) v4GuardCore.getInstance().getBackendConnector().getSettings().getOrDefault("addons", new Document()); | ||
boolean shieldEnabled = (boolean) shieldSettings.getOrDefault("accshield", false); | ||
if(!shieldEnabled) return; | ||
|
||
String location = v4GuardCore.getInstance().getCheckManager().getProcessors().get(0).getPlayerServer(auth.getUsername()); | ||
if(location != null){ | ||
location = "not-connected"; | ||
} | ||
Document finalDocument = new Document("username", auth.getUsername()) | ||
.append("type", auth.getAuthType().toString()) | ||
.append("location", location); | ||
v4GuardCore.getInstance().getBackendConnector().getSocket().emit("accshield:login", finalDocument.toJson()); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/io/v4guard/plugin/core/accounts/auth/AuthType.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,7 @@ | ||
package io.v4guard.plugin.core.accounts.auth; | ||
|
||
public enum AuthType { | ||
|
||
LOGIN, REGISTER, UNKNOWN; | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/io/v4guard/plugin/core/accounts/auth/Authentication.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,31 @@ | ||
package io.v4guard.plugin.core.accounts.auth; | ||
|
||
import org.bson.Document; | ||
|
||
public class Authentication { | ||
|
||
private final String username; | ||
private final AuthType authType; | ||
|
||
public Authentication(String username, AuthType authType) { | ||
this.username = username; | ||
this.authType = authType; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public AuthType getAuthType() { | ||
return authType; | ||
} | ||
|
||
public Document serialize(){ | ||
return new Document("username", username) | ||
.append("authType", authType.toString()); | ||
} | ||
|
||
public static Authentication deserialize(Document doc){ | ||
return new Authentication(doc.getString("username"), AuthType.valueOf(doc.getString("authType"))); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/io/v4guard/plugin/core/accounts/messaging/MessageReceiver.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,12 @@ | ||
package io.v4guard.plugin.core.accounts.messaging; | ||
|
||
public abstract class MessageReceiver { | ||
|
||
// This is a bit of a "dirty" solution. | ||
// If we place a custom channel name the message does not reach BungeeCord/Velocity. | ||
// We will temporarily use the BungeeCord channel until we find a solution to the problem. | ||
// protected static final String CHANNEL = "v4guard:accountshield"; | ||
|
||
protected static final String CHANNEL = "BungeeCord"; | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,7 @@ public void run() { | |
}.runTask(v4GuardSpigot.getV4Guard()); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
|
43 changes: 43 additions & 0 deletions
43
src/main/java/io/v4guard/plugin/velocity/accounts/VelocityMessageReceiver.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,43 @@ | ||
package io.v4guard.plugin.velocity.accounts; | ||
|
||
import com.velocitypowered.api.event.PostOrder; | ||
import com.velocitypowered.api.event.Subscribe; | ||
import com.velocitypowered.api.event.connection.PluginMessageEvent; | ||
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; | ||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; | ||
import io.v4guard.plugin.core.accounts.auth.Authentication; | ||
import io.v4guard.plugin.core.accounts.messaging.MessageReceiver; | ||
import io.v4guard.plugin.core.v4GuardCore; | ||
import io.v4guard.plugin.velocity.v4GuardVelocity; | ||
import net.md_5.bungee.api.plugin.Listener; | ||
import org.bson.Document; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.DataInputStream; | ||
import java.io.IOException; | ||
|
||
public class VelocityMessageReceiver extends MessageReceiver implements Listener { | ||
|
||
public VelocityMessageReceiver(v4GuardVelocity plugin) { | ||
plugin.getServer().getEventManager().register(plugin, this); | ||
plugin.getServer().getChannelRegistrar().register(new LegacyChannelIdentifier(MessageReceiver.CHANNEL)); | ||
plugin.getServer().getChannelRegistrar().register(MinecraftChannelIdentifier.from(MessageReceiver.CHANNEL)); | ||
} | ||
|
||
@Subscribe(order = PostOrder.FIRST) | ||
public void onMessage(PluginMessageEvent e){ | ||
if (!e.getIdentifier().getId().equals(MessageReceiver.CHANNEL)) { | ||
return; | ||
} | ||
DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getData())); | ||
try { | ||
String data = in.readUTF(); | ||
Document doc = Document.parse(data); | ||
Authentication auth = Authentication.deserialize(doc); | ||
v4GuardCore.getInstance().getAccountShieldManager().sendSocketMessage(auth); | ||
} catch (IOException ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
|
||
} |
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