mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-22 02:05:16 +01:00
Started with velocity cuz its easier
I don't understand configme tho
This commit is contained in:
parent
c8a033f12c
commit
c23a0e2656
@ -2,6 +2,7 @@ package eu.authme.api;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
// todo: find a way to get this api for platforms with no service manager (singleton????)
|
||||
/** Represents the base AuthMe API */
|
||||
@ -11,19 +12,14 @@ public interface AuthMeAPI {
|
||||
* Returns the user with the specified name. If the user has not been found in AuthMe's cache, it
|
||||
* will create a one.
|
||||
*
|
||||
* <p><b>WARNING: This may or may not be a thread blocking method. Call
|
||||
* asynchronously!!!!!!1!!11!!!!</b>
|
||||
*
|
||||
* @param name name of the user you want to get
|
||||
* @return non-null user object
|
||||
*/
|
||||
User getUser(String name);
|
||||
CompletableFuture<User> getUser(String name);
|
||||
|
||||
/**
|
||||
* Returns the user with the specified name.
|
||||
*
|
||||
* <p><b>WARNING: This is a thread blocking method. Call asynchronously!!!!!!1!!11!!!!</b>
|
||||
*
|
||||
* @param name name of the user you want to get
|
||||
* @return user if present in AuthMe's cache, empty optional otherwise
|
||||
*/
|
||||
@ -32,8 +28,6 @@ public interface AuthMeAPI {
|
||||
/**
|
||||
* Returns the user with the specified unique id.
|
||||
*
|
||||
* <p><b>WARNING: This is a thread blocking method. Call asynchronously!!!!!!1!!11!!!!</b>
|
||||
*
|
||||
* @param uuid uuid of the user you want to get
|
||||
* @return user if present in AuthMe's cache, empty optional otherwise
|
||||
*/
|
||||
|
@ -1,8 +0,0 @@
|
||||
package eu.authme.common;
|
||||
|
||||
import eu.authme.api.AuthMeAPI;
|
||||
|
||||
public interface AuthMePlugin {
|
||||
|
||||
void registerInServiceManager(AuthMeAPI api);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package eu.authme.common;
|
||||
package eu.authme.common.api;
|
||||
|
||||
import eu.authme.api.AuthEventListener;
|
||||
import eu.authme.api.AuthMeAPI;
|
@ -50,6 +50,20 @@
|
||||
<version>${velocity.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Configuration library -->
|
||||
<dependency>
|
||||
<groupId>ch.jalu</groupId>
|
||||
<artifactId>configme</artifactId>
|
||||
<version>${configme.version}</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<groupId>org.yaml</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -6,11 +6,15 @@ import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import java.nio.file.Path;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public final class AuthMeVelocity {
|
||||
|
||||
public static ChannelIdentifier MESSAGING = MinecraftChannelIdentifier.create("authme", "main");
|
||||
|
||||
private final Logger logger;
|
||||
private final ProxyServer proxy;
|
||||
private final Path dataDirectory;
|
||||
@ -20,11 +24,25 @@ public final class AuthMeVelocity {
|
||||
this.logger = logger;
|
||||
this.proxy = proxy;
|
||||
this.dataDirectory = dataDirectory;
|
||||
logger.info("Initialized");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onInitialize(ProxyInitializeEvent event) {}
|
||||
public void onInitialize(ProxyInitializeEvent event) {
|
||||
proxy.getChannelRegistrar().register(MESSAGING);
|
||||
logger.info("Enabled");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onShutdown(ProxyShutdownEvent event) {}
|
||||
public void onShutdown(ProxyShutdownEvent event) {
|
||||
logger.info("Disabled");
|
||||
}
|
||||
|
||||
public ProxyServer getProxy() {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
public Path getDataDirectory() {
|
||||
return dataDirectory;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,62 @@
|
||||
package eu.authme.velocity;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import eu.authme.api.User;
|
||||
import eu.authme.common.api.AbstractAuthMeAPI;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class VelocityAuthMeAPI extends AbstractAuthMeAPI {
|
||||
|
||||
private final AuthMeVelocity plugin;
|
||||
private Map<UUID, VelocityUser> userCache = new ConcurrentHashMap<>();
|
||||
private Map<String, CompletableFuture<User>> pendingFutures = new ConcurrentHashMap<>();
|
||||
|
||||
public VelocityAuthMeAPI(AuthMeVelocity plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<User> getUser(String name) {
|
||||
for (VelocityUser user : userCache.values()) {
|
||||
if (user.getName().equalsIgnoreCase(name)) {
|
||||
return CompletableFuture.completedFuture(user);
|
||||
}
|
||||
}
|
||||
CompletableFuture<User> future = new CompletableFuture<>();
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("GetUser");
|
||||
out.writeUTF(name);
|
||||
// todo
|
||||
try {
|
||||
return future;
|
||||
} finally {
|
||||
pendingFutures.put(name, future);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<User> getUserIfPresent(String name) {
|
||||
for (VelocityUser user : userCache.values()) {
|
||||
if (user.getName().equalsIgnoreCase(name)) {
|
||||
return Optional.of(user);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<User> getUserIfPresent(UUID uuid) {
|
||||
return Optional.ofNullable(userCache.get(uuid));
|
||||
}
|
||||
|
||||
public void putToUserCache(VelocityUser user) {
|
||||
userCache.put(user.getUniqueId(), user);
|
||||
}
|
||||
|
||||
public void modify(VelocityUser user) {}
|
||||
}
|
137
velocity/src/main/java/eu/authme/velocity/VelocityUser.java
Normal file
137
velocity/src/main/java/eu/authme/velocity/VelocityUser.java
Normal file
@ -0,0 +1,137 @@
|
||||
package eu.authme.velocity;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import eu.authme.api.User;
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class VelocityUser implements User {
|
||||
|
||||
private final VelocityAuthMeAPI api;
|
||||
private final ProxyServer proxy;
|
||||
private final String name;
|
||||
private String email;
|
||||
private final UUID uuid;
|
||||
private boolean loggedIn, registered;
|
||||
private Instant registrationDate;
|
||||
private Instant lastLoginDate;
|
||||
|
||||
public VelocityUser(
|
||||
VelocityAuthMeAPI api,
|
||||
ProxyServer proxy,
|
||||
String name,
|
||||
String email,
|
||||
UUID uuid,
|
||||
boolean loggedIn,
|
||||
boolean registered,
|
||||
Instant registrationDate,
|
||||
Instant lastLoginDate) {
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
this.uuid = uuid;
|
||||
this.loggedIn = loggedIn;
|
||||
this.registered = registered;
|
||||
this.registrationDate = registrationDate;
|
||||
this.lastLoginDate = lastLoginDate;
|
||||
this.api = api;
|
||||
this.proxy = proxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUniqueId() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasLoggedIn() {
|
||||
return loggedIn;
|
||||
}
|
||||
|
||||
public void setLoggedIn(boolean loggedIn) {
|
||||
this.loggedIn = loggedIn;
|
||||
if (loggedIn) {
|
||||
api.callUserLogin(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRegistered() {
|
||||
return registered;
|
||||
}
|
||||
|
||||
public void setRegistered(boolean registered) {
|
||||
this.registered = registered;
|
||||
if (registered) {
|
||||
api.callUserRegister(this);
|
||||
} else {
|
||||
api.callUserUnregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceLogin() {
|
||||
Optional<Player> playerOpt = proxy.getPlayer(name);
|
||||
if (playerOpt.isPresent()) {
|
||||
Player player = playerOpt.get();
|
||||
if (!loggedIn && player.getCurrentServer().isPresent()) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("ForceLogin");
|
||||
out.writeUTF(player.getUniqueId().toString());
|
||||
// todo: make sure is in auth server
|
||||
player.getCurrentServer().get().sendPluginMessage(AuthMeVelocity.MESSAGING, out.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceRegister(String password) {
|
||||
Optional<Player> playerOpt = proxy.getPlayer(name);
|
||||
if (playerOpt.isPresent()) {
|
||||
Player player = playerOpt.get();
|
||||
if (!registered && player.getCurrentServer().isPresent()) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("ForceRegister");
|
||||
out.writeUTF(player.getUniqueId().toString());
|
||||
out.writeUTF(password);
|
||||
// todo: make sure is in auth server
|
||||
player.getCurrentServer().get().sendPluginMessage(AuthMeVelocity.MESSAGING, out.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Instant> getRegistrationDate() {
|
||||
return Optional.ofNullable(registrationDate);
|
||||
}
|
||||
|
||||
public void setRegistrationDate(Instant date) {
|
||||
this.registrationDate = date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Instant> getLastLoginDate() {
|
||||
return Optional.ofNullable(lastLoginDate);
|
||||
}
|
||||
|
||||
public void setLastLoginDate(Instant date) {
|
||||
this.lastLoginDate = date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getEmail() {
|
||||
return Optional.ofNullable(email);
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package eu.authme.velocity.listeners;
|
||||
|
||||
public class PluginMessageListener {
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package eu.authme.velocity.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public final class Constants {
|
||||
|
||||
public static final Gson GSON = new Gson();
|
||||
}
|
Loading…
Reference in New Issue
Block a user