Skip to content

Commit

Permalink
Add UUID Fixer Module
Browse files Browse the repository at this point in the history
  • Loading branch information
Satxm committed Aug 18, 2024
1 parent c5ec214 commit 79a82db
Show file tree
Hide file tree
Showing 19 changed files with 89 additions and 88 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
[7]: https://img.shields.io/github/license/Satxm/mcwifipnp?label=License&logo=github&style=flat&color=E51050&labelcolor=2D2D2D
[8]: https://github.com/satxm/mcwifipnp


**Fabric: Requires [Fabric Loader](https://fabricmc.net/use/) and [Fabric API](https://modrinth.com/mod/fabric-api)**.

**Quilt: Requires [Quilt Loader](https://quiltmc.org/install/) and [QFAPI/QSL](https://modrinth.com/mod/qsl)**.
Expand Down Expand Up @@ -61,7 +60,17 @@ Modified from [TheGlitch76/mcpnp](https://github.com/TheGlitch76/mcpnp) project

## What Can It Do - 它的作用

添加了 UUID 修复模块,对于离线玩家,可以使离线玩家从mojang服务器获取对应的UUID,使UUID固定,不会因为客户端变化而变化。
Added UUID Fixer module, which allows offline players to obtain a unique UUID from the Mojang server, keeping the UUID fixed and not changing due to client changes.

添加了 UUID 修复模块,对于离线玩家,可以使离线玩家从 Mojang 服务器获取唯一的 UUID,使 UUID 固定,不会因为客户端变化而变化。

Added a new command `/forceoffline` to control whether players are forced into offline mode without obtaining UUIDs from Mojang servers. `/forceoffline list` command can list players who in the force offline list, `/forceoffline add` command can add players to the force offline list, `/forceoffline remove` command can remove players from the force offline list.

添加了一个新指令 `/forceoffline` 以便于控制玩家是否强制玩家为离线模式,不从 Mojang 服务器获取 UUID。`/forceoffline list` 指令可以查看列表中玩家,`/forceoffline add` 指令可以添加玩家到列表,`/forceoffline remove` 指令可以从列表中移除玩家。

For the `Oline Mode` button, there are now three options: 'Enable': enable genuine verification, which will verify login information against the Mojang server database, only allowing players who login with a Microsoft account to join, `Disable`: not verify login information, allows offline players to join, `Disable + UUID Fixer`: Attempt to match the Mojang server user name with the player name for offline mode players to obtain a unique UUID, Meanwhile, UUIDs are retained for users logging in with Microsoft accounts, It can also prevent the loss of backpack and inventory items.

对于`正版验证`按钮,现在有三个选项:`启用`:启用正版验证,将会比对Mojang服务器数据库验证登录信息,即只允许使用微软帐户登录的玩家加入;`禁用`:即不验证登录信息,允许使用离线模式登录的玩家加入;`禁用 + 修复UUID`:尝试使用离线模式登录的玩家名匹配Mojang服务器用户名称以获取唯一UUID,同时为使用微软帐户登录的用户保留UUID,它也可以防止背包和物品栏内容丢失。

Allows you to change the port number of the LAN world and choose whether to map this port to the public network using UPnP (if your router supports UPnP).

Expand All @@ -79,10 +88,9 @@ Allows you control other players' op permissions when they join your world, and

你可以控制其他玩家加入时是否有op权限、是否可以作弊,你也可以使用```/op``` ```/deop```命令进行控制。

You can control haw many players can join your world. You can use whitelist (command `/whitelist`) to block other players join your world.

You can control haw many players can join your world. You can use whitelist to block other players join your world.

你可以决定有多少玩家可以加入你的世界,你可以使用白名单来组建其他玩家进加入你的游戏世界。
你可以决定有多少玩家可以加入你的世界,你可以使用白名单(命令 `/whitelist`)来组建其他玩家进加入你的游戏世界。

Allows players to connect your world from anywhere, this includes toggling online mode.

Expand Down
4 changes: 2 additions & 2 deletions fabric/src/main/java/io/github/satxm/mcwifipnp/MCWiFiPnP.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public void onInitialize() {
BanIpCommands.register(dispatcher);
BanListCommands.register(dispatcher);
BanPlayerCommands.register(dispatcher);
OfflinePlayerCommand.register(dispatcher);
});
ForceOfflineCommand.register(dispatcher);
});
}

public static void afterScreenInit(Minecraft client, Screen screen, int i, int j) {
Expand Down
2 changes: 0 additions & 2 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty '
minecraft {
mappings channel: 'official', version: project.minecraft_version

accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')

runs {
client {
workingDirectory project.file('run')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void onRegisterCommands(RegisterCommandsEvent event) {
BanIpCommands.register(event.getDispatcher());
BanListCommands.register(event.getDispatcher());
BanPlayerCommands.register(event.getDispatcher());
OfflinePlayerCommand.register(event.getDispatcher());
ForceOfflineCommand.register(event.getDispatcher());
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void onInitialize(ModContainer mod) {
BanIpCommands.register(dispatcher);
BanListCommands.register(dispatcher);
BanPlayerCommands.register(dispatcher);
OfflinePlayerCommand.register(dispatcher);
ForceOfflineCommand.register(dispatcher);
});
}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/dosse/upnp/Gateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public String getLocalIP() {
return iface.getHostAddress();
}


public String getExternalIP() {
try {
Map<String, String> r = command("GetExternalIPAddress", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
import net.minecraft.server.players.PlayerList;
import org.apache.commons.lang3.StringUtils;

public class OfflinePlayerCommand {
private static final SimpleCommandExceptionType ERROR_ALREADY_IN = new SimpleCommandExceptionType(Component.translatable("mcwifipnp.commands.offlineplayers.add.failed"));
private static final SimpleCommandExceptionType ERROR_NOT_IN = new SimpleCommandExceptionType(Component.translatable("mcwifipnp.commands.offlineplayers.remove.failed"));
public class ForceOfflineCommand {
private static final SimpleCommandExceptionType ERROR_ALREADY_IN = new SimpleCommandExceptionType(Component.translatable("mcwifipnp.commands.forceoffline.add.failed"));
private static final SimpleCommandExceptionType ERROR_NOT_IN = new SimpleCommandExceptionType(Component.translatable("mcwifipnp.commands.forceoffline.remove.failed"));

public OfflinePlayerCommand() {
public ForceOfflineCommand() {
}

public static void register(CommandDispatcher<CommandSourceStack> commandDispatcher) {
commandDispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)Commands.literal("offlineplayer").requires((commandSourceStack) -> {
commandDispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)Commands.literal("forceoffline").requires((commandSourceStack) -> {
return commandSourceStack.hasPermission(3);
})).then(Commands.literal("list").executes((commandContext) -> {
return showList((CommandSourceStack)commandContext.getSource());
Expand All @@ -36,9 +36,9 @@ public static void register(CommandDispatcher<CommandSourceStack> commandDispatc
PlayerList playerList = server.getPlayerList();
MCWiFiPnPUnit.ReadingConfig(server);
MCWiFiPnPUnit.Config cfg = MCWiFiPnPUnit.getConfig(server);
List<String> alwaysOfflinePlayers = cfg.alwaysOfflinePlayers;
List<String> ForceOfflinePlayers = cfg.ForceOfflinePlayers;
return SharedSuggestionProvider.suggest(playerList.getPlayers().stream().filter((serverPlayer) -> {
return !alwaysOfflinePlayers.contains(serverPlayer.getGameProfile().getName());
return !ForceOfflinePlayers.contains(serverPlayer.getGameProfile().getName());
}).map((serverPlayer) -> {
return serverPlayer.getGameProfile().getName();
}), suggestionsBuilder);
Expand All @@ -48,29 +48,28 @@ public static void register(CommandDispatcher<CommandSourceStack> commandDispatc
MinecraftServer server = ((CommandSourceStack) commandContext.getSource()).getServer();
MCWiFiPnPUnit.ReadingConfig(server);
MCWiFiPnPUnit.Config cfg = MCWiFiPnPUnit.getConfig(server);
List<String> alwaysOfflinePlayers = cfg.alwaysOfflinePlayers;
return SharedSuggestionProvider.suggest(alwaysOfflinePlayers.stream(), suggestionsBuilder);
List<String> ForceOfflinePlayers = cfg.ForceOfflinePlayers;
return SharedSuggestionProvider.suggest(ForceOfflinePlayers.stream(), suggestionsBuilder);
}).executes((commandContext) -> {
return removePlayers((CommandSourceStack)commandContext.getSource(), GameProfileArgument.getGameProfiles(commandContext, "targets"));
}))));
}


private static int addPlayers(CommandSourceStack commandSourceStack, Collection<GameProfile> collection) throws CommandSyntaxException {
MinecraftServer server = commandSourceStack.getServer();
MCWiFiPnPUnit.ReadingConfig(server);
MCWiFiPnPUnit.Config cfg = MCWiFiPnPUnit.getConfig(server);
List<String> alwaysOfflinePlayers = cfg.alwaysOfflinePlayers;
List<String> ForceOfflinePlayers = cfg.ForceOfflinePlayers;

int i = 0;
Iterator var4 = collection.iterator();

while (var4.hasNext()) {
GameProfile gameProfile = (GameProfile) var4.next();
if (!alwaysOfflinePlayers.contains(gameProfile.getName())) {
alwaysOfflinePlayers.add(gameProfile.getName());
if (!ForceOfflinePlayers.contains(gameProfile.getName())) {
ForceOfflinePlayers.add(gameProfile.getName());
MCWiFiPnPUnit.saveConfig(cfg);
commandSourceStack.sendSuccess(Component.translatable("mcwifipnp.commands.offlineplayers.add.success",
commandSourceStack.sendSuccess(Component.translatable("mcwifipnp.commands.forceoffline.add.success",
new Object[] { ComponentUtils.getDisplayName(gameProfile) }), true);
++i;
}
Expand All @@ -87,17 +86,17 @@ private static int removePlayers(CommandSourceStack commandSourceStack, Collecti
MinecraftServer server = commandSourceStack.getServer();
MCWiFiPnPUnit.ReadingConfig(server);
MCWiFiPnPUnit.Config cfg = MCWiFiPnPUnit.getConfig(server);
List<String> alwaysOfflinePlayers = cfg.alwaysOfflinePlayers;
List<String> ForceOfflinePlayers = cfg.ForceOfflinePlayers;

int i = 0;
Iterator var4 = collection.iterator();

while (var4.hasNext()) {
GameProfile gameProfile = (GameProfile) var4.next();
if (alwaysOfflinePlayers.contains(gameProfile.getName())) {
alwaysOfflinePlayers.remove(gameProfile.getName());
if (ForceOfflinePlayers.contains(gameProfile.getName())) {
ForceOfflinePlayers.remove(gameProfile.getName());
MCWiFiPnPUnit.saveConfig(cfg);
commandSourceStack.sendSuccess(Component.translatable("mcwifipnp.commands.offlineplayers.remove.success",
commandSourceStack.sendSuccess(Component.translatable("mcwifipnp.commands.forceoffline.remove.success",
new Object[] { ComponentUtils.getDisplayName(gameProfile) }), true);
++i;
}
Expand All @@ -115,15 +114,15 @@ private static int showList(CommandSourceStack commandSourceStack) {
MinecraftServer server = commandSourceStack.getServer();
MCWiFiPnPUnit.ReadingConfig(server);
MCWiFiPnPUnit.Config cfg = MCWiFiPnPUnit.getConfig(server);
List<String> alwaysOfflinePlayers = cfg.alwaysOfflinePlayers;
List<String> ForceOfflinePlayers = cfg.ForceOfflinePlayers;

if (alwaysOfflinePlayers.size() == 0) {
commandSourceStack.sendSuccess(Component.translatable("mcwifipnp.commands.offlineplayers.none"), false);
if (ForceOfflinePlayers.size() == 0) {
commandSourceStack.sendSuccess(Component.translatable("mcwifipnp.commands.forceoffline.none"), false);
} else {
commandSourceStack.sendSuccess(Component.translatable("mcwifipnp.commands.offlineplayers.list",
new Object[] { alwaysOfflinePlayers.size(), StringUtils.join(alwaysOfflinePlayers, ", ") }), false);
commandSourceStack.sendSuccess(Component.translatable("mcwifipnp.commands.forceoffline.list",
new Object[] { ForceOfflinePlayers.size(), StringUtils.join(ForceOfflinePlayers, ", ") }), false);
}

return alwaysOfflinePlayers.size();
return ForceOfflinePlayers.size();
}
}
8 changes: 4 additions & 4 deletions src/main/java/io/github/satxm/mcwifipnp/MCWiFiPnPUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public static void OpenToLan() {
playerList.setUsingWhiteList(cfg.Whitelist);
playerList.getOps().add(new ServerOpListEntry(server.getSingleplayerProfile(), 4, playerList.canBypassPlayerLimit(server.getSingleplayerProfile())));
playerList.setAllowCheatsForAllPlayers(cfg.AllPlayersCheats);
UUIDFixer.EnableUUIDFix = cfg.EnableUUIDFix;
UUIDFixer.alwaysOfflinePlayers = cfg.alwaysOfflinePlayers;
UUIDFixer.EnableUUIDFixer = cfg.EnableUUIDFixer;
UUIDFixer.ForceOfflinePlayers = cfg.ForceOfflinePlayers;

new Thread(() -> {
MCWiFiPnPUnit.UseUPnP(cfg, client);
Expand Down Expand Up @@ -193,8 +193,8 @@ public static class Config {
public boolean UseUPnP = true;
public boolean AllowCommands = false;
public boolean OnlineMode = true;
public boolean EnableUUIDFix = false;
public List<String> alwaysOfflinePlayers = Collections.emptyList();
public boolean EnableUUIDFixer = false;
public List<String> ForceOfflinePlayers = Collections.emptyList();
public boolean PvP = true;
public boolean CopyToClipboard = true;
public transient Path location;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/github/satxm/mcwifipnp/OnlineMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ public boolean getFixUUID() {
return this.fixuuid;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public ShareToLanScreenNew(Screen screen) {
cfg.AllowCommands = client.getSingleplayerServer().getWorldData().getAllowCommands();
cfg.GameMode = client.getSingleplayerServer().getDefaultGameType().getName();
cfg.OnlineMode = client.getSingleplayerServer().usesAuthentication();
cfg.alwaysOfflinePlayers = Collections.emptyList();
cfg.needsDefaults = false;
cfg.ForceOfflinePlayers = Collections.emptyList();
cfg.needsDefaults = false;
}
}

Expand Down Expand Up @@ -167,11 +167,11 @@ protected void init() {

this.addRenderableWidget(CycleButton.builder(OnlineMode::getDisplayName)
.withValues(OnlineMode.values())
.withInitialValue(OnlineMode.of(cfg.OnlineMode, cfg.EnableUUIDFix)).withTooltip((OnlineMode) -> Tooltip.create(OnlineMode.gettoolTip()))
.withInitialValue(OnlineMode.of(cfg.OnlineMode, cfg.EnableUUIDFixer)).withTooltip((OnlineMode) -> Tooltip.create(OnlineMode.gettoolTip()))
.create(this.width / 2 - 155, 148, 150, 20,
Component.translatable("mcwifipnp.gui.OnlineMode"), (cycleButton, OnlineMode) -> {
cfg.OnlineMode = OnlineMode.getOnlieMode();
cfg.EnableUUIDFix = OnlineMode.getFixUUID();
cfg.EnableUUIDFixer = OnlineMode.getFixUUID();
}));

this.addRenderableWidget(CycleButton.onOffBuilder(cfg.PvP).create(this.width / 2 + 5, 148, 150, 20,
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/io/github/satxm/mcwifipnp/UUIDFixer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@
import com.google.gson.JsonSyntaxException;

public class UUIDFixer {
public static boolean EnableUUIDFix = false;
public static List<String> alwaysOfflinePlayers = Collections.emptyList();

public static boolean EnableUUIDFixer = false;
public static List<String> ForceOfflinePlayers = Collections.emptyList();

/**
* Mixin/ Coremod callback
*/
public static UUID hookEntry(String playerName) {
if (alwaysOfflinePlayers.contains(playerName))
if (ForceOfflinePlayers.contains(playerName))
return null;

if (EnableUUIDFix)
if (EnableUUIDFixer)
return getOfficialUUID(playerName);

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.core.UUIDUtil;


@Mixin(UUIDUtil.class)
public abstract class MixinUUIDUtil {
@Inject(method = "createOfflinePlayerUUID", at = @At("HEAD"), cancellable = true)
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/assets/mcwifipnp/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"mcwifipnp.upnp.failed.disabled": "Unable to forward port %s: UPnP is not enabled on your router, You may need to use port mapping software.",
"mcwifipnp.upnp.failed.unknownerror": "Unable to forward port %s: Unknown error while adding port mapping, Please use a port mapping software.",
"mcwifipnp.upnp.failed": "Unable to forward port %s!",
"mcwifipnp.commands.offlineplayers.add.failed": "Player is already in force offline list",
"mcwifipnp.commands.offlineplayers.add.success": "Added %s to the force offline list",
"mcwifipnp.commands.offlineplayers.list": "There are %s players in force offline list: %s",
"mcwifipnp.commands.offlineplayers.none": "There are no players in force offline list",
"mcwifipnp.commands.offlineplayers.remove.failed": "Player is not in force offline list",
"mcwifipnp.commands.offlineplayers.remove.success": "Removed %s from the force offline list"
"mcwifipnp.commands.forceoffline.add.failed": "Player is already in force offline list",
"mcwifipnp.commands.forceoffline.add.success": "Added %s to the force offline list",
"mcwifipnp.commands.forceoffline.list": "There are %s players in force offline list: %s",
"mcwifipnp.commands.forceoffline.none": "There are no players in force offline list",
"mcwifipnp.commands.forceoffline.remove.failed": "Player is not in force offline list",
"mcwifipnp.commands.forceoffline.remove.success": "Removed %s from the force offline list"
}
12 changes: 6 additions & 6 deletions src/main/resources/assets/mcwifipnp/lang/es_es.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"mcwifipnp.upnp.failed.disabled": "No se pudo reenviar el puerto %s: UPnP no estaba habilitado en tu enrutador. Puede que necesites usar software de asignación de puertos.",
"mcwifipnp.upnp.failed.unknownerror": "No se pudo reenviar el puerto %s: Error desconocido al agregar la asignación de puertos. Usa un software de asignación de puertos.",
"mcwifipnp.upnp.failed": "No se pudo reenviar el puerto %s.",
"mcwifipnp.commands.offlineplayers.add.failed": "El jugador ya estaba en la lista fuera de línea",
"mcwifipnp.commands.offlineplayers.add.success": "Se ha añadido a %s a la lista fuera de línea",
"mcwifipnp.commands.offlineplayers.list": "Hay %s jugador(es) en la lista fuera de línea: %s",
"mcwifipnp.commands.offlineplayers.none": "No hay jugadores en la lista fuera de línea",
"mcwifipnp.commands.offlineplayers.remove.failed": "El jugador no estaba en la lista fuera de línea",
"mcwifipnp.commands.offlineplayers.remove.success": "Se ha eliminado a %s de la lista fuera de línea"
"mcwifipnp.commands.forceoffline.add.failed": "El jugador ya estaba en la lista fuera de línea",
"mcwifipnp.commands.forceoffline.add.success": "Se ha añadido a %s a la lista fuera de línea",
"mcwifipnp.commands.forceoffline.list": "Hay %s jugador(es) en la lista fuera de línea: %s",
"mcwifipnp.commands.forceoffline.none": "No hay jugadores en la lista fuera de línea",
"mcwifipnp.commands.forceoffline.remove.failed": "El jugador no estaba en la lista fuera de línea",
"mcwifipnp.commands.forceoffline.remove.success": "Se ha eliminado a %s de la lista fuera de línea"
}
Loading

0 comments on commit 79a82db

Please sign in to comment.