Implementing "always offline" player list
This commit is contained in:
parent
eab9958484
commit
a1ce6b578f
|
@ -10,7 +10,7 @@ loader_version=0.10.6+build.214
|
|||
fabric_version=0.25.1+build.416-1.16
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.7.1
|
||||
mod_version = 1.7.2
|
||||
maven_group = org.samo_lego
|
||||
archives_base_name = simpleauth
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ public class MixinPlayerAdvancementTracker {
|
|||
|
||||
@Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("HEAD"))
|
||||
private void startMigratingOfflineAdvancements(ServerAdvancementLoader advancementLoader, CallbackInfo ci) {
|
||||
if(config.experimental.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) this.owner).isUsingMojangAccount() && !this.advancementFile.isFile()) {
|
||||
if(config.main.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) this.owner).isUsingMojangAccount() && !this.advancementFile.isFile()) {
|
||||
// Migrate
|
||||
String playername = owner.getGameProfile().getName();
|
||||
this.advancementFile = new File(this.advancementFile.getParent(), PlayerEntity.getOfflinePlayerUuid(playername).toString() + ".json");
|
||||
|
@ -39,7 +39,7 @@ public class MixinPlayerAdvancementTracker {
|
|||
|
||||
@Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("TAIL"))
|
||||
private void endMigratingOfflineAdvancements(ServerAdvancementLoader advancementLoader, CallbackInfo ci) {
|
||||
if(config.experimental.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) this.owner).isUsingMojangAccount()) {
|
||||
if(config.main.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) this.owner).isUsingMojangAccount()) {
|
||||
this.advancementFile = new File(this.advancementFile.getParent(), owner.getUuid() + ".json");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public abstract class MixinPlayerManager {
|
|||
ordinal = 1
|
||||
)
|
||||
private File migrateOfflineStats(File file, PlayerEntity player) {
|
||||
if(config.experimental.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) player).isUsingMojangAccount()) {
|
||||
if(config.main.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) player).isUsingMojangAccount()) {
|
||||
String playername = player.getGameProfile().getName();
|
||||
file = new File(file.getParent(), PlayerEntity.getOfflinePlayerUuid(playername) + ".json");
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ public abstract class MixinPlayerManager {
|
|||
)
|
||||
private void migrateOfflineStats(PlayerEntity player, CallbackInfoReturnable<ServerStatHandler> cir, UUID uUID, ServerStatHandler serverStatHandler, File serverStatsDir, File playerStatFile) {
|
||||
File onlineFile = new File(serverStatsDir, uUID + ".json");
|
||||
if(config.experimental.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) player).isUsingMojangAccount() && !onlineFile.exists()) {
|
||||
if(config.main.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) player).isUsingMojangAccount() && !onlineFile.exists()) {
|
||||
((ServerStatHandlerAccessor) serverStatHandler).setFile(onlineFile);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public abstract class MixinServerLoginNetworkHandler {
|
|||
*/
|
||||
@Inject(method = "tick()V", at = @At("HEAD"), cancellable = true)
|
||||
private void preTick(CallbackInfo ci) {
|
||||
if (this.acceptCrackedPlayer && config.experimental.premiumAutologin) {
|
||||
if (this.acceptCrackedPlayer && config.main.premiumAutologin) {
|
||||
((ServerLoginNetworkHandler) (Object) this).acceptPlayer();
|
||||
|
||||
if (this.loginTicks++ == 600)
|
||||
|
@ -77,12 +77,12 @@ public abstract class MixinServerLoginNetworkHandler {
|
|||
cancellable = true
|
||||
)
|
||||
private void checkPremium(LoginHelloC2SPacket packet, CallbackInfo ci) {
|
||||
if(config.experimental.premiumAutologin) {
|
||||
if(config.main.premiumAutologin) {
|
||||
try {
|
||||
String playername = packet.getProfile().getName().toLowerCase();
|
||||
Pattern pattern = Pattern.compile("^[a-z0-9_]{3,16}$");
|
||||
Matcher matcher = pattern.matcher(playername);
|
||||
if(playerCacheMap.containsKey(PlayerEntity.getOfflinePlayerUuid(playername).toString()) || !matcher.matches()) {
|
||||
if(playerCacheMap.containsKey(PlayerEntity.getOfflinePlayerUuid(playername).toString()) || !matcher.matches() || config.main.forcedOfflinePlayers.contains(playername)) {
|
||||
// Player definitely doesn't have a mojang account
|
||||
this.acceptCrackedPlayer = true;
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ public class MixinServerPlayerEntity implements PlayerAuth {
|
|||
@Override
|
||||
public boolean canSkipAuth() {
|
||||
// We ask CarpetHelper class since it has the imports needed
|
||||
return (this.isRunningCarpet && isPlayerCarpetFake(this.player)) || (isUsingMojangAccount() && config.experimental.premiumAutologin);
|
||||
return (this.isRunningCarpet && isPlayerCarpetFake(this.player)) || (isUsingMojangAccount() && config.main.premiumAutologin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -75,7 +75,7 @@ public class MixinWorldSaveHandler {
|
|||
private CompoundTag migratePlayerData(CompoundTag compoundTag, PlayerEntity player) {
|
||||
// Checking for offline player data only if online doesn't exist yet
|
||||
String playername = player.getGameProfile().getName().toLowerCase();
|
||||
if(config.experimental.premiumAutologin && mojangAccountNamesCache.contains(playername) && !this.fileExists) {
|
||||
if(config.main.premiumAutologin && mojangAccountNamesCache.contains(playername) && !this.fileExists) {
|
||||
if(config.experimental.debugMode)
|
||||
logInfo("Migrating data for " + playername);
|
||||
File file = new File(this.playerDataDir, PlayerEntity.getOfflinePlayerUuid(player.getGameProfile().getName()) + ".dat");
|
||||
|
|
|
@ -22,6 +22,9 @@ import com.google.gson.GsonBuilder;
|
|||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.samo_lego.simpleauth.SimpleAuth.serverProp;
|
||||
import static org.samo_lego.simpleauth.utils.SimpleLogger.logError;
|
||||
|
@ -150,6 +153,28 @@ public class AuthConfig {
|
|||
public boolean useSsl = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether players who have a valid session should skip the authentication process.
|
||||
* You have to set online-mode to true in server.properties!
|
||||
* (cracked players will still be able to enter, but they'll need to login)
|
||||
*
|
||||
* This protects premium usernames from being stolen, since cracked players
|
||||
* with name that is found in Mojang database, are kicked.
|
||||
*/
|
||||
public boolean premiumAutologin = false;
|
||||
|
||||
/**
|
||||
* Contains a list of lower case (!) player names
|
||||
* that should always be treated as offline.
|
||||
*
|
||||
* Used when AuthConfig#premiumAutoLogin is enabled
|
||||
* and you have some players that want to use username,
|
||||
* that is already taken.
|
||||
*/
|
||||
public ArrayList<String> forcedOfflinePlayers = new ArrayList<>(Arrays.asList(
|
||||
""
|
||||
));
|
||||
|
||||
}
|
||||
public static class LangConfig {
|
||||
public String enterPassword = "§6You need to enter your password!";
|
||||
|
@ -236,15 +261,6 @@ public class AuthConfig {
|
|||
* @see <a href="https://github.com/samolego/SimpleAuth/wiki/GLIBC-problems" target="_blank">wiki</a>
|
||||
*/
|
||||
public boolean useBCryptLibrary = false;
|
||||
/**
|
||||
* Whether players who have a valid session should skip the authentication process.
|
||||
* You have to set online-mode to true in server.properties!
|
||||
* (cracked players will still be able to enter, but they'll need to login)
|
||||
*
|
||||
* This protects premium usernames from being stolen, since cracked players
|
||||
* with name that is found in Mojang database, are kicked.
|
||||
*/
|
||||
public boolean premiumAutologin = false;
|
||||
/**
|
||||
* Whether to modify player uuids to offline style.
|
||||
* Note: this should be used only if you had your server
|
||||
|
@ -284,9 +300,9 @@ public class AuthConfig {
|
|||
logInfo("Server is in offline mode, forceoOfflineUuids option is irrelevant. Setting it to false.");
|
||||
config.experimental.forceoOfflineUuids = false;
|
||||
}
|
||||
if(config.experimental.premiumAutologin) {
|
||||
if(config.main.premiumAutologin) {
|
||||
logError("You cannot use server in offline mode and premiumAutologin! Disabling the latter.");
|
||||
config.experimental.premiumAutologin = false;
|
||||
config.main.premiumAutologin = false;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
Loading…
Reference in New Issue