Skip to content

Add support for WaterdogPE XUID and IP #1986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
protected Vector3 teleportPosition = null;

protected boolean connected = true;
protected final InetSocketAddress socketAddress;
protected final InetSocketAddress rawSocketAddress;
protected InetSocketAddress socketAddress;
protected boolean removeFormat = true;

protected String username;
Expand Down Expand Up @@ -616,6 +617,7 @@ public Player(SourceInterface interfaz, Long clientID, InetSocketAddress socketA
this.perm = new PermissibleBase(this);
this.server = Server.getInstance();
this.lastBreak = -1;
this.rawSocketAddress = socketAddress;
this.socketAddress = socketAddress;
this.clientID = clientID;
this.loaderId = Level.generateChunkLoaderId(this);
Expand Down Expand Up @@ -678,6 +680,18 @@ public void setSkin(Skin skin) {
}
}

public String getRawAddress() {
return this.rawSocketAddress.getAddress().getHostAddress();
}

public int getRawPort() {
return this.rawSocketAddress.getPort();
}

public InetSocketAddress getRawSocketAddress() {
return this.rawSocketAddress;
}

public String getAddress() {
return this.socketAddress.getAddress().getHostAddress();
}
Expand Down Expand Up @@ -2107,6 +2121,10 @@ public void handleDataPacket(DataPacket packet) {
break;
}

if (this.server.getConfig("settings.waterdogpe", false) && loginChainData.getWaterdogIP() != null) {
this.socketAddress = new InetSocketAddress(this.loginChainData.getWaterdogIP(), this.getRawPort());
}

this.randomClientId = loginPacket.clientId;

this.uuid = loginPacket.clientUUID;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/nukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ public void batchPackets(Player[] players, DataPacket[] packets, boolean forceSy
List<InetSocketAddress> targets = new ArrayList<>();
for (Player p : players) {
if (p.isConnected()) {
targets.add(p.getSocketAddress());
targets.add(p.getRawSocketAddress());
}
}

Expand Down Expand Up @@ -1851,7 +1851,7 @@ public Player[] matchPlayer(String partialName) {
}

public void removePlayer(Player player) {
Player toRemove = this.players.remove(player.getSocketAddress());
Player toRemove = this.players.remove(player.getRawSocketAddress());
if (toRemove != null) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/cn/nukkit/network/RakNetInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public boolean process() {

@Override
public int getNetworkLatency(Player player) {
RakNetServerSession session = this.raknet.getSession(player.getSocketAddress());
RakNetServerSession session = this.raknet.getSession(player.getRawSocketAddress());
return session == null ? -1 : (int) session.getPing();
}

Expand All @@ -143,7 +143,7 @@ public void close(Player player) {

@Override
public void close(Player player, String reason) {
RakNetServerSession session = this.raknet.getSession(player.getSocketAddress());
RakNetServerSession session = this.raknet.getSession(player.getRawSocketAddress());
if (session != null) {
session.close();
}
Expand Down Expand Up @@ -214,7 +214,7 @@ public Integer putPacket(Player player, DataPacket packet, boolean needACK) {

@Override
public Integer putPacket(Player player, DataPacket packet, boolean needACK, boolean immediate) {
NukkitRakNetSession session = this.sessions.get(player.getSocketAddress());
NukkitRakNetSession session = this.sessions.get(player.getRawSocketAddress());

if (session != null) {
packet.tryEncode();
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/cn/nukkit/utils/ClientChainData.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.nukkit.utils;

import cn.nukkit.Server;
import cn.nukkit.network.protocol.LoginPacket;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -109,7 +110,11 @@ public String getLanguageCode() {

@Override
public String getXUID() {
return xuid;
if (Server.getInstance().getConfig("waterdogpe", false) && Waterdog_XUID != null) {
return Waterdog_XUID;
} else {
return xuid;
}
}

private boolean xboxAuthed;
Expand Down Expand Up @@ -137,6 +142,16 @@ public int getUIProfile() {
return UIProfile;
}

@Override
public String getWaterdogXUID() {
return Waterdog_XUID;
}

@Override
public String getWaterdogIP() {
return Waterdog_IP;
}

@Override
public JsonObject getRawData() {
return rawData;
Expand Down Expand Up @@ -180,6 +195,8 @@ private static ECPublicKey generateKey(String base64) throws NoSuchAlgorithmExce
private String languageCode;
private int currentInputMode;
private int defaultInputMode;
private String Waterdog_IP;
private String Waterdog_XUID;

private int UIProfile;

Expand Down Expand Up @@ -215,6 +232,14 @@ private void decodeSkinData() {
if (skinToken.has("DefaultInputMode")) this.defaultInputMode = skinToken.get("DefaultInputMode").getAsInt();
if (skinToken.has("UIProfile")) this.UIProfile = skinToken.get("UIProfile").getAsInt();
if (skinToken.has("CapeData")) this.capeData = skinToken.get("CapeData").getAsString();
if (skinToken.has("Waterdog_IP")) this.Waterdog_IP = skinToken.get("Waterdog_IP").getAsString();
if (skinToken.has("Waterdog_XUID")) this.Waterdog_XUID = skinToken.get("Waterdog_XUID").getAsString();

boolean useWaterdog = Server.getInstance().getConfig("settings.waterdogpe", false);

if (useWaterdog && this.Waterdog_XUID != null) {
xboxAuthed = true;
}

this.rawData = skinToken;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/cn/nukkit/utils/LoginChainData.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,9 @@ public interface LoginChainData {

int getUIProfile();

String getWaterdogXUID();

String getWaterdogIP();

JsonObject getRawData();
}
2 changes: 1 addition & 1 deletion src/main/resources/lang
Submodule lang updated from bd94ef to f6f851