Skip to content

Commit

Permalink
add multilogin api
Browse files Browse the repository at this point in the history
  • Loading branch information
CaaMoe committed May 12, 2024
1 parent 878550a commit 4b4e3ab
Show file tree
Hide file tree
Showing 35 changed files with 109 additions and 37 deletions.
13 changes: 13 additions & 0 deletions api/src/main/java/moe/caa/multilogin/api/MultiLoginAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package moe.caa.multilogin.api;

import moe.caa.multilogin.api.data.MultiLoginPlayerData;
import moe.caa.multilogin.api.service.IService;

import java.util.Collection;
import java.util.UUID;

public interface MultiLoginAPI {
Collection<? extends IService> getServices();

MultiLoginPlayerData getPlayerData(UUID inGameUUID);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package moe.caa.multilogin.api;

import lombok.Getter;

public class MultiLoginAPIProvider {
@Getter
private static MultiLoginAPI api;

public synchronized static void setApi(MultiLoginAPI api) {
if (MultiLoginAPIProvider.api != null) throw new UnsupportedOperationException("duplicate api.");
MultiLoginAPIProvider.api = api;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package moe.caa.multilogin.api.data;

import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.service.IService;

public interface MultiLoginPlayerData {
GameProfile getOnlineProfile();

IService getLoginService();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package moe.caa.multilogin.api.internal.auth;

import moe.caa.multilogin.api.profile.GameProfile;

/**
* 验证结果
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package moe.caa.multilogin.api.internal.handle;

import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.internal.plugin.IPlayer;
import moe.caa.multilogin.api.internal.util.Pair;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package moe.caa.multilogin.api.internal.skinrestorer;

import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;

public interface SkinRestorerResult {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package moe.caa.multilogin.api.internal.auth;
package moe.caa.multilogin.api.profile;

import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package moe.caa.multilogin.api.internal.auth;
package moe.caa.multilogin.api.profile;

import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package moe.caa.multilogin.api.service;

public interface IService {
int getServiceId();

String getServiceName();

ServiceType getServiceType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class YggdrasilMinecraftSessionServiceInvocationHandler(
try {
val result = multiCoreAPI.authHandler.auth(profileName, serverId, ip) as LoginAuthResult
if (result.result == AuthResult.Result.ALLOW) {
var gameProfile: moe.caa.multilogin.api.internal.auth.GameProfile = result.response
var gameProfile: moe.caa.multilogin.api.profile.GameProfile = result.response
try {
val restorerResult: SkinRestorerResult = multiCoreAPI.skinRestorerHandler.doRestorer(result)
if (restorerResult.throwable != null) {
Expand Down Expand Up @@ -79,7 +79,7 @@ class YggdrasilMinecraftSessionServiceInvocationHandler(
return null
}

private fun generateResponse(returnType: Type, response: moe.caa.multilogin.api.internal.auth.GameProfile): Any {
private fun generateResponse(returnType: Type, response: moe.caa.multilogin.api.profile.GameProfile): Any {
val result = GameProfile(response.id, response.name)
response.propertyMap.forEach { (k, u) ->
result.properties.put(k, Property(u.name, u.value, u.signature))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.google.common.base.Preconditions;
import moe.caa.multilogin.api.internal.auth.AuthResult;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.internal.logger.LoggerProvider;
import moe.caa.multilogin.api.internal.main.MultiCoreAPI;
import moe.caa.multilogin.api.internal.skinrestorer.SkinRestorerResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.Getter;
import moe.caa.multilogin.api.internal.auth.AuthAPI;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.internal.logger.LoggerProvider;
import moe.caa.multilogin.core.auth.service.BaseServiceAuthenticationResult;
import moe.caa.multilogin.core.auth.service.yggdrasil.YggdrasilAuthenticationResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.Getter;
import moe.caa.multilogin.api.internal.auth.AuthResult;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.core.auth.service.BaseServiceAuthenticationResult;
import moe.caa.multilogin.core.auth.service.yggdrasil.UnmodifiableGameProfile;
import moe.caa.multilogin.core.auth.service.yggdrasil.YggdrasilAuthenticationResult;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package moe.caa.multilogin.core.auth.service;

import lombok.Getter;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.core.configuration.service.BaseServiceConfig;

@Getter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package moe.caa.multilogin.core.auth.service.floodgate;

import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.core.auth.service.BaseServiceAuthenticationResult;
import moe.caa.multilogin.core.configuration.service.FloodgateServiceConfig;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package moe.caa.multilogin.core.auth.service.floodgate;

import moe.caa.multilogin.api.internal.auth.AuthResult;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.internal.util.ValueUtil;
import moe.caa.multilogin.core.auth.LoginAuthResult;
import moe.caa.multilogin.core.auth.service.yggdrasil.UnmodifiableGameProfile;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package moe.caa.multilogin.core.auth.service.yggdrasil;

import lombok.Data;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.internal.util.Pair;
import moe.caa.multilogin.core.configuration.service.yggdrasil.BaseYggdrasilServiceConfig;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package moe.caa.multilogin.core.auth.service.yggdrasil;

import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.internal.auth.Property;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.profile.Property;

import java.util.Collections;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package moe.caa.multilogin.core.auth.service.yggdrasil;

import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.internal.util.Pair;
import moe.caa.multilogin.core.configuration.service.yggdrasil.BaseYggdrasilServiceConfig;
import moe.caa.multilogin.core.main.MultiCore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.Getter;
import lombok.ToString;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.core.auth.service.BaseServiceAuthenticationResult;
import moe.caa.multilogin.core.configuration.service.yggdrasil.BaseYggdrasilServiceConfig;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.google.gson.*;
import lombok.NoArgsConstructor;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.internal.auth.Property;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.profile.Property;
import moe.caa.multilogin.api.internal.util.ValueUtil;
import moe.caa.multilogin.core.auth.service.yggdrasil.UnmodifiableGameProfile;

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

import com.google.gson.*;
import lombok.NoArgsConstructor;
import moe.caa.multilogin.api.internal.auth.Property;
import moe.caa.multilogin.api.profile.Property;
import moe.caa.multilogin.core.auth.service.yggdrasil.UnmodifiableGameProfile;

import java.lang.reflect.Type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;

/**
* 游戏内验证结果
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package moe.caa.multilogin.core.auth.validate;

import lombok.Data;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.core.auth.service.BaseServiceAuthenticationResult;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.mojang.brigadier.suggestion.Suggestion;
import com.mojang.brigadier.suggestion.Suggestions;
import lombok.Getter;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.internal.command.CommandAPI;
import moe.caa.multilogin.api.internal.logger.LoggerProvider;
import moe.caa.multilogin.api.internal.plugin.IPlayer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.internal.plugin.IPlayer;
import moe.caa.multilogin.api.internal.plugin.ISender;
import moe.caa.multilogin.api.internal.util.Pair;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import lombok.SneakyThrows;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.internal.plugin.IPlayer;
import moe.caa.multilogin.api.internal.plugin.ISender;
import moe.caa.multilogin.api.internal.util.Pair;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import lombok.SneakyThrows;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.internal.plugin.IPlayer;
import moe.caa.multilogin.api.internal.plugin.ISender;
import moe.caa.multilogin.api.internal.util.Pair;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import lombok.SneakyThrows;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.internal.plugin.IPlayer;
import moe.caa.multilogin.api.internal.plugin.ISender;
import moe.caa.multilogin.api.internal.util.Pair;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import moe.caa.multilogin.api.data.MultiLoginPlayerData;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.internal.handle.HandleResult;
import moe.caa.multilogin.api.internal.handle.HandlerAPI;
import moe.caa.multilogin.api.internal.logger.LoggerProvider;
Expand Down Expand Up @@ -98,6 +98,10 @@ public void callPlayerJoinGame(IPlayer player) {
}, 3000);
}

public MultiLoginPlayerData getPlayerData(UUID inGameUUID){
return cache.get(inGameUUID);
}

@Override
public Pair<GameProfile, Integer> getPlayerOnlineProfile(UUID inGameUUID) {
Entry entry = cache.get(inGameUUID);
Expand Down
27 changes: 24 additions & 3 deletions core/src/main/java/moe/caa/multilogin/core/main/MultiCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.Getter;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.internal.auth.Property;
import moe.caa.multilogin.api.MultiLoginAPI;
import moe.caa.multilogin.api.MultiLoginAPIProvider;
import moe.caa.multilogin.api.data.MultiLoginPlayerData;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.profile.Property;
import moe.caa.multilogin.api.internal.logger.LoggerProvider;
import moe.caa.multilogin.api.internal.main.MultiCoreAPI;
import moe.caa.multilogin.api.internal.plugin.IPlugin;
import moe.caa.multilogin.api.service.IService;
import moe.caa.multilogin.core.auth.AuthHandler;
import moe.caa.multilogin.core.auth.service.floodgate.FloodgateAuthenticationService;
import moe.caa.multilogin.core.auth.service.yggdrasil.serialize.GameProfileSerializer;
import moe.caa.multilogin.core.auth.service.yggdrasil.serialize.PropertySerializer;
import moe.caa.multilogin.core.command.CommandHandler;
import moe.caa.multilogin.core.configuration.PluginConfig;
import moe.caa.multilogin.core.configuration.service.BaseServiceConfig;
import moe.caa.multilogin.core.database.SQLManager;
import moe.caa.multilogin.core.handle.CacheWhitelistHandler;
import moe.caa.multilogin.core.handle.PlayerHandler;
Expand All @@ -25,11 +30,15 @@
import java.io.IOException;
import java.net.URISyntaxException;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

/**
* 猫踢核心
*/
public class MultiCore implements MultiCoreAPI {
public class MultiCore implements MultiCoreAPI, MultiLoginAPI {
@Getter
private final IPlugin plugin;
@Getter
Expand Down Expand Up @@ -108,6 +117,8 @@ private void showBanner() {
*/
@Override
public void load() throws IOException, SQLException, ClassNotFoundException, URISyntaxException {
MultiLoginAPIProvider.setApi(this);

showBanner();
buildManifest.read();
buildManifest.checkStable();
Expand Down Expand Up @@ -161,4 +172,14 @@ public void reload() throws IOException, URISyntaxException {
public void close() {
sqlManager.close();
}

@Override
public Collection<BaseServiceConfig> getServices() {
return Collections.unmodifiableCollection(pluginConfig.getServiceIdMap().values());
}

@Override
public MultiLoginPlayerData getPlayerData(UUID inGameUUID) {
return playerHandler.getPlayerData(inGameUUID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.google.gson.JsonParser;
import lombok.SneakyThrows;
import moe.caa.multilogin.api.internal.auth.AuthResult;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.internal.auth.Property;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.profile.Property;
import moe.caa.multilogin.api.internal.logger.LoggerProvider;
import moe.caa.multilogin.api.internal.skinrestorer.SkinRestorerAPI;
import moe.caa.multilogin.api.internal.util.Pair;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.internal.auth.Property;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.profile.Property;
import moe.caa.multilogin.api.internal.logger.LoggerProvider;
import moe.caa.multilogin.api.internal.util.ValueUtil;
import moe.caa.multilogin.core.configuration.SkinRestorerConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import moe.caa.multilogin.api.internal.auth.GameProfile;
import moe.caa.multilogin.api.profile.GameProfile;
import moe.caa.multilogin.api.internal.logger.LoggerProvider;
import moe.caa.multilogin.api.internal.skinrestorer.SkinRestorerResult;

Expand Down
Loading

0 comments on commit 4b4e3ab

Please sign in to comment.