Skip to content

Commit

Permalink
nLogin integration
Browse files Browse the repository at this point in the history
Closes #30
  • Loading branch information
nickuc committed Jan 14, 2024
1 parent cca5cc3 commit f2d85a5
Show file tree
Hide file tree
Showing 17 changed files with 204 additions and 23 deletions.
2 changes: 2 additions & 0 deletions bukkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ repositories {
maven { url 'https://repo.papermc.io/repository/maven-public/' }
maven { url 'https://repo.codemc.io/repository/maven-public/' }
maven { url 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
maven { url 'https://repo.nickuc.com/maven-releases/' }
}

dependencies {
implementation project(':azlink-common')
compileOnly 'dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT'
compileOnly 'io.netty:netty-all:4.1.25.Final'
compileOnly 'fr.xephi:authme:5.6.0-beta2'
compileOnly 'com.nickuc.login:nlogin-api:10.2'
compileOnly 'me.clip:placeholderapi:2.11.1'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.azuriom.azlink.bukkit.integrations.FoliaSchedulerAdapter;
import com.azuriom.azlink.bukkit.integrations.MoneyPlaceholderExpansion;
import com.azuriom.azlink.bukkit.integrations.SkinsRestorerIntegration;
import com.azuriom.azlink.bukkit.integrations.NLoginIntegration;
import com.azuriom.azlink.common.AzLinkPlatform;
import com.azuriom.azlink.common.AzLinkPlugin;
import com.azuriom.azlink.common.command.CommandSender;
Expand All @@ -20,6 +21,7 @@
import com.azuriom.azlink.common.scheduler.JavaSchedulerAdapter;
import com.azuriom.azlink.common.scheduler.SchedulerAdapter;
import com.azuriom.azlink.common.tasks.TpsTask;
import com.nickuc.login.api.nLoginAPI;
import org.bukkit.entity.Player;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -85,6 +87,15 @@ && getServer().getPluginManager().getPlugin("AuthMe") != null) {
getServer().getPluginManager().registerEvents(new AuthMeIntegration(this), this);
}

if (getConfig().getBoolean("nlogin-integration")
&& getServer().getPluginManager().getPlugin("nLogin") != null) {
if (nLoginAPI.getApi().getApiVersion() >= 5) {
getServer().getPluginManager().registerEvents(new NLoginIntegration(this), this);
} else {
this.plugin.getLogger().warn("nLogin integration requires API version v5 or higher");
}
}

if (getConfig().getBoolean("skinrestorer-integration")
&& getServer().getPluginManager().getPlugin("SkinsRestorer") != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

import com.azuriom.azlink.bukkit.AzLinkBukkitPlugin;
import com.azuriom.azlink.common.http.server.HttpServer;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.*;
import org.bukkit.Bukkit;

import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.azuriom.azlink.bukkit.integrations;

import com.azuriom.azlink.bukkit.AzLinkBukkitPlugin;
import com.azuriom.azlink.common.integrations.BaseNLogin;
import com.nickuc.login.api.enums.TwoFactorType;
import com.nickuc.login.api.event.bukkit.auth.RegisterEvent;
import com.nickuc.login.api.event.bungee.twofactor.TwoFactorAddEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import java.net.InetSocketAddress;

public class NLoginIntegration
extends BaseNLogin implements Listener {

public NLoginIntegration(AzLinkBukkitPlugin plugin) {
super(plugin.getPlugin());
}

@EventHandler
public void onEmailAdded(TwoFactorAddEvent event) {
if (event.getType() != TwoFactorType.EMAIL) {
return;
}

handleEmailUpdated(event.getPlayerId(), event.getPlayerName(), event.getAccount());
}

@EventHandler
public void onRegister(RegisterEvent event) {
Player player = event.getPlayer();
InetSocketAddress ip = player.getAddress();

handleRegister(player.getUniqueId(), player.getName(), event.getPassword(), ip != null ? ip.getAddress() : null);
}
}
6 changes: 6 additions & 0 deletions bukkit/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ ignore-vanished-players: false
# from registering multiple times
authme-integration: false

# When enabled, new users registered with the nLogin plugin will automatically be registered on the website
# WARNING: You need nLogin version 10.2.43 or newer!
# If you are using multiples serves, you should use the same database for nLogin to prevent users
# from registering multiple times
nlogin-integration: false

# When enabled, if SkinsRestorer is installed, and the SkinAPI plugin is present on the website,
# the player's skin will be updated to the website's skin
skinrestorer-integration: false
2 changes: 2 additions & 0 deletions bungee/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://repo.nickuc.com/maven-releases/' }
}

dependencies {
implementation project(':azlink-common')
compileOnly 'net.md-5:bungeecord-api:1.16-R0.4'
compileOnly 'com.nickuc.login:nlogin-api:10.2'
}

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

import com.azuriom.azlink.bungee.command.BungeeCommandExecutor;
import com.azuriom.azlink.bungee.command.BungeeCommandSender;
import com.azuriom.azlink.bungee.integrations.NLoginIntegration;
import com.azuriom.azlink.bungee.integrations.SkinsRestorerIntegration;
import com.azuriom.azlink.common.AzLinkPlatform;
import com.azuriom.azlink.common.AzLinkPlugin;
Expand All @@ -11,6 +12,7 @@
import com.azuriom.azlink.common.platform.PlatformInfo;
import com.azuriom.azlink.common.platform.PlatformType;
import com.azuriom.azlink.common.scheduler.SchedulerAdapter;
import com.nickuc.login.api.nLoginAPI;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
Expand Down Expand Up @@ -43,6 +45,15 @@ public void onEnable() {

loadConfig();

if (this.config.getBoolean("nlogin-integration")
&& getProxy().getPluginManager().getPlugin("nLogin") != null) {
if (nLoginAPI.getApi().getApiVersion() >= 5) {
getProxy().getPluginManager().registerListener(this, new NLoginIntegration(this));
} else {
this.plugin.getLogger().warn("nLogin integration requires API version v5 or higher");
}
}

if (this.config.getBoolean("skinsrestorer-integration")
&& getProxy().getPluginManager().getPlugin("SkinsRestorer") != null) {
getProxy().getPluginManager().registerListener(this, new SkinsRestorerIntegration(this));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.azuriom.azlink.bungee.integrations;

import com.azuriom.azlink.bungee.AzLinkBungeePlugin;
import com.azuriom.azlink.common.integrations.BaseNLogin;
import com.nickuc.login.api.enums.TwoFactorType;
import com.nickuc.login.api.event.bungee.auth.RegisterEvent;
import com.nickuc.login.api.event.bungee.twofactor.TwoFactorAddEvent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;

public class NLoginIntegration
extends BaseNLogin implements Listener {

public NLoginIntegration(AzLinkBungeePlugin plugin) {
super(plugin.getPlugin());
}

@EventHandler
public void onEmailAdded(TwoFactorAddEvent event) {
if (event.getType() != TwoFactorType.EMAIL) {
return;
}

handleEmailUpdated(event.getPlayerId(), event.getPlayerName(), event.getAccount());
}

@EventHandler
public void onRegister(RegisterEvent event) {
ProxiedPlayer player = event.getPlayer();
SocketAddress socketAddress = player.getSocketAddress();
InetAddress ip = socketAddress instanceof InetSocketAddress ? ((InetSocketAddress) socketAddress).getAddress() : null;

handleRegister(player.getUniqueId(), player.getName(), event.getPassword(), ip);
}
}
6 changes: 6 additions & 0 deletions bungee/src/main/resources/bungee-config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# When enabled, new users registered with the nLogin plugin will automatically be registered on the website
# WARNING: You need nLogin version 10.2.43 or newer!
# If you are using multiples serves, you should use the same database for nLogin to prevent users
# from registering multiple times
nlogin-integration: false

# When enabled, if SkinsRestorer is installed, and the SkinAPI plugin is present on the website,
# the player's skin will be updated to the website's skin
skinsrestorer-integration: false
2 changes: 2 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
repositories {
maven { url 'https://repo.codemc.io/repository/maven-public/' }
maven { url 'https://repo.nickuc.com/maven-releases/' }
}

dependencies {
compileOnly 'org.slf4j:slf4j-api:1.7.36'
compileOnly 'com.google.code.gson:gson:2.10.1'
compileOnly 'io.netty:netty-all:4.1.42.Final'
compileOnly 'net.skinsrestorer:skinsrestorer-api:15.0.2'
compileOnly 'com.nickuc.login:nlogin-api:10.2'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.10.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import com.azuriom.azlink.common.command.AzLinkCommand;
import com.azuriom.azlink.common.command.CommandSender;
import com.azuriom.azlink.common.config.PluginConfig;
import com.azuriom.azlink.common.data.PlatformData;
import com.azuriom.azlink.common.data.PlayerData;
import com.azuriom.azlink.common.data.ServerData;
import com.azuriom.azlink.common.data.SystemData;
import com.azuriom.azlink.common.data.WorldData;
import com.azuriom.azlink.common.data.*;
import com.azuriom.azlink.common.http.client.HttpClient;
import com.azuriom.azlink.common.http.server.HttpServer;
import com.azuriom.azlink.common.http.server.NettyHttpServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.*;

import java.nio.charset.StandardCharsets;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.azuriom.azlink.common.integrations;

import com.azuriom.azlink.common.AzLinkPlugin;

import java.net.InetAddress;
import java.util.UUID;

public class BaseNLogin {

protected final AzLinkPlugin plugin;

public BaseNLogin(AzLinkPlugin plugin) {
this.plugin = plugin;

this.plugin.getLogger().info("nLogin integration enabled.");
}

protected void handleEmailUpdated(UUID playerId, String playerName, String newEmail) {
this.plugin
.getHttpClient()
.updateEmail(playerId, newEmail)
.exceptionally(ex -> {
this.plugin.getLogger().error("Unable to update email for " + playerName, ex);

return null;
});
}

protected void handleRegister(UUID playerId, String playerName, String password, InetAddress ip) {
this.plugin
.getHttpClient()
.registerUser(playerName, null, playerId, password, ip)
.exceptionally(ex -> {
this.plugin.getLogger().error("Unable to register " + playerName, ex);

return null;
});
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.azuriom.azlink.common.scheduler;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;

public class JavaSchedulerAdapter implements SchedulerAdapter {

Expand Down
2 changes: 2 additions & 0 deletions velocity/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ plugins {
repositories {
maven { url 'https://nexus.velocitypowered.com/repository/maven-public/' }
maven { url 'https://maven.elytrium.net/repo/' }
maven { url 'https://repo.nickuc.com/maven-releases/' }
}

dependencies {
implementation project(':azlink-common')
compileOnly 'com.velocitypowered:velocity-api:3.1.1'
compileOnly 'net.elytrium.limboapi:api:1.1.13'
compileOnly 'net.elytrium:limboauth:1.1.1'
compileOnly 'com.nickuc.login:nlogin-api:10.2'
annotationProcessor 'com.velocitypowered:velocity-api:3.1.1'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import com.azuriom.azlink.velocity.command.VelocityCommandExecutor;
import com.azuriom.azlink.velocity.command.VelocityCommandSender;
import com.azuriom.azlink.velocity.integrations.LimboAuthIntegration;
import com.azuriom.azlink.velocity.integrations.NLoginIntegration;
import com.azuriom.azlink.velocity.integrations.SkinsRestorerIntegration;
import com.google.inject.Inject;
import com.nickuc.login.api.nLoginAPI;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
Expand Down Expand Up @@ -81,6 +83,14 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
this.proxy.getEventManager().register(this, new LimboAuthIntegration(this));
}

if (this.proxy.getPluginManager().getPlugin("nlogin").isPresent()) {
if (nLoginAPI.getApi().getApiVersion() >= 5) {
this.proxy.getEventManager().register(this, new NLoginIntegration(this));
} else {
this.plugin.getLogger().warn("nLogin integration requires API version v5 or higher");
}
}

if (this.proxy.getPluginManager().getPlugin("skinsrestorer").isPresent()
&& this.config.getNode("skinsrestorer-integration").getBoolean()) {
this.proxy.getEventManager().register(this, new SkinsRestorerIntegration(this));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.azuriom.azlink.velocity.integrations;

import com.azuriom.azlink.common.integrations.BaseNLogin;
import com.azuriom.azlink.velocity.AzLinkVelocityPlugin;
import com.nickuc.login.api.enums.TwoFactorType;
import com.nickuc.login.api.event.bungee.twofactor.TwoFactorAddEvent;
import com.nickuc.login.api.event.velocity.auth.RegisterEvent;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.proxy.Player;

public class NLoginIntegration extends BaseNLogin {

public NLoginIntegration(AzLinkVelocityPlugin plugin) {
super(plugin.getPlugin());
}

@Subscribe
public void onEmailAdded(TwoFactorAddEvent event) {
if (event.getType() != TwoFactorType.EMAIL) {
return;
}

handleEmailUpdated(event.getPlayerId(), event.getPlayerName(), event.getAccount());
}

@Subscribe
public void onRegister(RegisterEvent event) {
Player player = event.getPlayer();

handleRegister(player.getUniqueId(), player.getUsername(), event.getPassword(), player.getRemoteAddress().getAddress());
}
}

0 comments on commit f2d85a5

Please sign in to comment.