Skip to content

Commit

Permalink
Changed authed server config to list for ignoring multiple servers
Browse files Browse the repository at this point in the history
  • Loading branch information
GoryMoon committed Mar 9, 2021
1 parent 42733e6 commit 79b01df
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ The default config looks like this:

```toml
mclink_backend = "https://auth.mc.chs.se/"
auth_server = "auth"
ignored_servers = ["auth"]
permission = "velocity.command.server"
token = ""
```

- `mclink_backend` is the base url to the backend server running [gudchalmers/chs-mclink-backend][3].
- `auth_server` is the server to ignore connections to as it's the one running [gudchalmers/chs-mclink][1] to auth players.
- `ignored_servers` a list of servers to ignore connections to, needed for the one running [gudchalmers/chs-mclink][1] to auth players.
- `permission` if the player have this permission they bypass the auth check.
- `token` is the shared key from [gudchalmers/chs-mclink-backend][3] to auth the api.

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'se.gory_moon'
version '1.0.0'
version '1.1.0'

sourceCompatibility = 1.8

Expand Down Expand Up @@ -41,6 +41,6 @@ dependencies {
implementation okhttp
shade okhttp

compile 'com.velocitypowered:velocity-api:1.1.2'
annotationProcessor 'com.velocitypowered:velocity-api:1.1.2'
compile 'com.velocitypowered:velocity-api:1.1.4'
annotationProcessor 'com.velocitypowered:velocity-api:1.1.4'
}
9 changes: 6 additions & 3 deletions src/main/java/se/gory_moon/mclink/velocity/Config.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package se.gory_moon.mclink.velocity;

import com.google.common.collect.Lists;
import com.moandjiezana.toml.Toml;
import com.moandjiezana.toml.TomlWriter;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class Config {

Expand Down Expand Up @@ -48,8 +50,8 @@ public String getMcLinkBackend() {
return toml.getString("mclink_backend");
}

public String getAuthServer() {
return toml.getString("auth_server");
public List<String> getIgnoredServers() {
return toml.getList("ignored_servers");
}

public String getToken() {
Expand All @@ -64,9 +66,10 @@ public void reload() {
load();
}

@SuppressWarnings("unused")
static class ConfigDefaults {
String mclink_backend = "https://auth.mc.chs.se/";
String auth_server = "auth";
List<String> ignored_servers = Lists.newArrayList("auth");
String permission = "velocity.command.server";
String token = "";
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/se/gory_moon/mclink/velocity/MCLinkPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import se.gory_moon.mclink.velocity.commands.UnregisterCommand;

import java.nio.file.Path;
import java.util.List;
import java.util.Optional;

@Plugin(id = "mclink", name = "MCLink Plugin", version = "1.0.0",
Expand All @@ -32,7 +33,7 @@ public class MCLinkPlugin extends AbstractModule {

public final ProxyServer server;
private final Logger logger;
public RegisteredServer authServer;
public List<String> ignoreServers;
public final Gate gate;
public Config config;
public API api;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void onProxyInit(ProxyInitializeEvent event) {
server.getChannelRegistrar().register(CONNECT_CHANNEL);
api = new API(config);

authServer = server.getServer(config.getAuthServer()).orElseThrow(NoServerFoundExecption::new);
ignoreServers = config.getIgnoredServers();
}

@Subscribe
Expand Down Expand Up @@ -94,7 +95,7 @@ public void playerLogin(LoginEvent event) {

@Subscribe
public void playerConnect(ServerPreConnectEvent event) {
if (!authServer.getServerInfo().getName().equals(event.getOriginalServer().getServerInfo().getName())) {
if (!ignoreServers.contains(event.getOriginalServer().getServerInfo().getName())) {
gate.login(event.getPlayer());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ServerConnection;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.slf4j.Logger;
import se.gory_moon.mclink.velocity.Gate;
import se.gory_moon.mclink.velocity.MCLinkPlugin;

import java.io.IOException;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

Expand All @@ -41,12 +41,12 @@ public int unregister(CommandContext<CommandSource> ctx) {

boolean send = false;
Optional<ServerConnection> server = ((Player) source).getCurrentServer();
if (server.isPresent() && !Objects.equals(server.get().getServerInfo().getName(), plugin.config.getAuthServer())) {
if (server.isPresent() && !plugin.config.getIgnoredServers().contains(server.get().getServerInfo().getName())) {
send = true;
msg.append(Component.newline().append(Component.text("Redirecting you in 5 seconds...", NamedTextColor.YELLOW)));
msg = msg.append(Component.newline().append(Component.text("Disconnecting you in 5 seconds...", NamedTextColor.YELLOW)));
}

source.sendMessage(msg);
source.sendMessage(Identity.nil(), msg);
if (send) {
plugin.server.getScheduler().buildTask(plugin, () -> {
if (((Player) source).isActive()) {
Expand Down

0 comments on commit 79b01df

Please sign in to comment.