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
|
fabric_version=0.25.1+build.416-1.16
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.7.1
|
mod_version = 1.7.2
|
||||||
maven_group = org.samo_lego
|
maven_group = org.samo_lego
|
||||||
archives_base_name = simpleauth
|
archives_base_name = simpleauth
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class MixinPlayerAdvancementTracker {
|
||||||
|
|
||||||
@Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("HEAD"))
|
@Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("HEAD"))
|
||||||
private void startMigratingOfflineAdvancements(ServerAdvancementLoader advancementLoader, CallbackInfo ci) {
|
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
|
// Migrate
|
||||||
String playername = owner.getGameProfile().getName();
|
String playername = owner.getGameProfile().getName();
|
||||||
this.advancementFile = new File(this.advancementFile.getParent(), PlayerEntity.getOfflinePlayerUuid(playername).toString() + ".json");
|
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"))
|
@Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("TAIL"))
|
||||||
private void endMigratingOfflineAdvancements(ServerAdvancementLoader advancementLoader, CallbackInfo ci) {
|
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");
|
this.advancementFile = new File(this.advancementFile.getParent(), owner.getUuid() + ".json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ public abstract class MixinPlayerManager {
|
||||||
ordinal = 1
|
ordinal = 1
|
||||||
)
|
)
|
||||||
private File migrateOfflineStats(File file, PlayerEntity player) {
|
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();
|
String playername = player.getGameProfile().getName();
|
||||||
file = new File(file.getParent(), PlayerEntity.getOfflinePlayerUuid(playername) + ".json");
|
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) {
|
private void migrateOfflineStats(PlayerEntity player, CallbackInfoReturnable<ServerStatHandler> cir, UUID uUID, ServerStatHandler serverStatHandler, File serverStatsDir, File playerStatFile) {
|
||||||
File onlineFile = new File(serverStatsDir, uUID + ".json");
|
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);
|
((ServerStatHandlerAccessor) serverStatHandler).setFile(onlineFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ public abstract class MixinServerLoginNetworkHandler {
|
||||||
*/
|
*/
|
||||||
@Inject(method = "tick()V", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "tick()V", at = @At("HEAD"), cancellable = true)
|
||||||
private void preTick(CallbackInfo ci) {
|
private void preTick(CallbackInfo ci) {
|
||||||
if (this.acceptCrackedPlayer && config.experimental.premiumAutologin) {
|
if (this.acceptCrackedPlayer && config.main.premiumAutologin) {
|
||||||
((ServerLoginNetworkHandler) (Object) this).acceptPlayer();
|
((ServerLoginNetworkHandler) (Object) this).acceptPlayer();
|
||||||
|
|
||||||
if (this.loginTicks++ == 600)
|
if (this.loginTicks++ == 600)
|
||||||
|
@ -77,12 +77,12 @@ public abstract class MixinServerLoginNetworkHandler {
|
||||||
cancellable = true
|
cancellable = true
|
||||||
)
|
)
|
||||||
private void checkPremium(LoginHelloC2SPacket packet, CallbackInfo ci) {
|
private void checkPremium(LoginHelloC2SPacket packet, CallbackInfo ci) {
|
||||||
if(config.experimental.premiumAutologin) {
|
if(config.main.premiumAutologin) {
|
||||||
try {
|
try {
|
||||||
String playername = packet.getProfile().getName().toLowerCase();
|
String playername = packet.getProfile().getName().toLowerCase();
|
||||||
Pattern pattern = Pattern.compile("^[a-z0-9_]{3,16}$");
|
Pattern pattern = Pattern.compile("^[a-z0-9_]{3,16}$");
|
||||||
Matcher matcher = pattern.matcher(playername);
|
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
|
// Player definitely doesn't have a mojang account
|
||||||
this.acceptCrackedPlayer = true;
|
this.acceptCrackedPlayer = true;
|
||||||
|
|
||||||
|
|
|
@ -162,7 +162,7 @@ public class MixinServerPlayerEntity implements PlayerAuth {
|
||||||
@Override
|
@Override
|
||||||
public boolean canSkipAuth() {
|
public boolean canSkipAuth() {
|
||||||
// We ask CarpetHelper class since it has the imports needed
|
// 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) {
|
private CompoundTag migratePlayerData(CompoundTag compoundTag, PlayerEntity player) {
|
||||||
// Checking for offline player data only if online doesn't exist yet
|
// Checking for offline player data only if online doesn't exist yet
|
||||||
String playername = player.getGameProfile().getName().toLowerCase();
|
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)
|
if(config.experimental.debugMode)
|
||||||
logInfo("Migrating data for " + playername);
|
logInfo("Migrating data for " + playername);
|
||||||
File file = new File(this.playerDataDir, PlayerEntity.getOfflinePlayerUuid(player.getGameProfile().getName()) + ".dat");
|
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.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
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.SimpleAuth.serverProp;
|
||||||
import static org.samo_lego.simpleauth.utils.SimpleLogger.logError;
|
import static org.samo_lego.simpleauth.utils.SimpleLogger.logError;
|
||||||
|
@ -150,6 +153,28 @@ public class AuthConfig {
|
||||||
public boolean useSsl = true;
|
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 static class LangConfig {
|
||||||
public String enterPassword = "§6You need to enter your password!";
|
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>
|
* @see <a href="https://github.com/samolego/SimpleAuth/wiki/GLIBC-problems" target="_blank">wiki</a>
|
||||||
*/
|
*/
|
||||||
public boolean useBCryptLibrary = false;
|
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.
|
* Whether to modify player uuids to offline style.
|
||||||
* Note: this should be used only if you had your server
|
* 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.");
|
logInfo("Server is in offline mode, forceoOfflineUuids option is irrelevant. Setting it to false.");
|
||||||
config.experimental.forceoOfflineUuids = 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.");
|
logError("You cannot use server in offline mode and premiumAutologin! Disabling the latter.");
|
||||||
config.experimental.premiumAutologin = false;
|
config.main.premiumAutologin = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
Loading…
Reference in New Issue