forked from PaperMC/Velocity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7af5538
commit ef2e4e8
Showing
13 changed files
with
425 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
.../java/com/velocitypowered/proxy/protocol/packet/uuidrewrite/EntityPacketUuidRewriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (C) 2024 Velocity Contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.velocitypowered.proxy.protocol.packet.uuidrewrite; | ||
|
||
import com.velocitypowered.api.proxy.Player; | ||
import com.velocitypowered.proxy.VelocityServer; | ||
import com.velocitypowered.proxy.config.PlayerInfoForwarding; | ||
|
||
import java.util.UUID; | ||
import java.util.function.Function; | ||
|
||
public class EntityPacketUuidRewriter { | ||
|
||
public static void rewriteS2C(VelocityServer server, Player connectionPlayer, PacketToRewriteEntityUuid packet) { | ||
rewrite(server, connectionPlayer, packet, Player::getOfflineUuid, Player::getUniqueId); | ||
} | ||
|
||
public static void rewriteC2S(VelocityServer server, Player connectionPlayer, PacketToRewriteEntityUuid packet) { | ||
rewrite(server, connectionPlayer, packet, Player::getUniqueId, Player::getOfflineUuid); | ||
} | ||
|
||
private static void rewrite(VelocityServer server, Player connectionPlayer, PacketToRewriteEntityUuid packet, | ||
Function<Player, UUID> uuidFrom, Function<Player, UUID> uuidTo) { | ||
var config = server.getConfiguration(); | ||
if (!(config.isOnlineMode() && config.getPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE)) { | ||
return; | ||
} | ||
if (!packet.isPlayer()) { | ||
return; | ||
} | ||
UUID uuid = packet.getEntityUuid(); | ||
if (uuid == null) { | ||
return; | ||
} | ||
|
||
// FIXME: inefficient implementation using for loop. Replace it with map lookup? | ||
for (Player player : server.getAllPlayers()) { | ||
if (uuidFrom.apply(player).equals(uuid)) { | ||
UUID newUuid = uuidTo.apply(player); | ||
if (!newUuid.equals(uuid)) { | ||
packet.setEntityUuid(newUuid); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...java/com/velocitypowered/proxy/protocol/packet/uuidrewrite/PacketToRewriteEntityUuid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (C) 2024 Velocity Contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.velocitypowered.proxy.protocol.packet.uuidrewrite; | ||
|
||
import java.util.UUID; | ||
|
||
public interface PacketToRewriteEntityUuid { | ||
|
||
boolean isPlayer(); | ||
|
||
UUID getEntityUuid(); | ||
|
||
void setEntityUuid(UUID entityUuid); | ||
} |
74 changes: 74 additions & 0 deletions
74
...in/java/com/velocitypowered/proxy/protocol/packet/uuidrewrite/UrSpawnEntityS2CPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (C) 2024 Velocity Contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.velocitypowered.proxy.protocol.packet.uuidrewrite; | ||
|
||
import com.velocitypowered.api.network.ProtocolVersion; | ||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; | ||
import com.velocitypowered.proxy.protocol.MinecraftPacket; | ||
import com.velocitypowered.proxy.protocol.ProtocolUtils; | ||
import io.netty.buffer.ByteBuf; | ||
|
||
import java.util.UUID; | ||
|
||
// [fallen's fork] player uuid rewrite - entity packet | ||
public class UrSpawnEntityS2CPacket implements MinecraftPacket, PacketToRewriteEntityUuid { | ||
|
||
private int entityId; | ||
private UUID entityUuid; | ||
private int entityType; | ||
private byte[] remainingBuf; | ||
|
||
@Override | ||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) { | ||
this.entityId = ProtocolUtils.readVarInt(buf); | ||
this.entityUuid = ProtocolUtils.readUuid(buf); | ||
this.entityType = ProtocolUtils.readVarInt(buf); | ||
this.remainingBuf = new byte[buf.readableBytes()]; | ||
buf.readBytes(this.remainingBuf); | ||
} | ||
|
||
@Override | ||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) { | ||
ProtocolUtils.writeVarInt(buf, this.entityId); | ||
ProtocolUtils.writeUuid(buf, this.entityUuid); | ||
ProtocolUtils.writeVarInt(buf, this.entityType); | ||
buf.writeBytes(this.remainingBuf); | ||
} | ||
|
||
@Override | ||
public boolean handle(MinecraftSessionHandler handler) { | ||
return handler.handle(this); | ||
} | ||
|
||
@Override | ||
public boolean isPlayer() { | ||
// https://wiki.vg/Entity_metadata#Mobs | ||
int playerEntityType = 122; // mc1.20.2 | ||
return this.entityType == playerEntityType; | ||
} | ||
|
||
@Override | ||
public UUID getEntityUuid() { | ||
return this.entityUuid; | ||
} | ||
|
||
@Override | ||
public void setEntityUuid(UUID entityUuid) { | ||
this.entityUuid = entityUuid; | ||
} | ||
} |
Oops, something went wrong.