Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeCrafter47 committed Oct 1, 2023
2 parents 2882aec + a05bead commit 5fd0635
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 71 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build With Gradle

on: [ push, pull_request ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout repository and submodules
uses: actions/checkout@v3
with:
submodules: recursive

- name: Set up JDK 16
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '16'
cache: 'gradle'

- name: Build with Gradle
run: ./gradlew shadowJar

- name: Archive artifacts (Bungee)
uses: actions/upload-artifact@v2
if: success()
with:
name: BungeeTabListPlus Bungee
path: bootstrap-bungee/build/libs/BungeeTabListPlus-*-SNAPSHOT.jar

- name: Archive artifacts (Bukkit)
uses: actions/upload-artifact@v2
if: success()
with:
name: BungeeTabListPlus Bukkit Bridge
path: bootstrap-bukkit/build/libs/BungeeTabListPlus_BukkitBridge-*-SNAPSHOT.jar

- name: Archive artifacts (Fabric 1.16.3)
uses: actions/upload-artifact@v2
if: success()
with:
name: BungeeTabListPlus Fabric 1.16.3 Bridge
path: fabric-bridge-1.16.3/build/libs/btlp-fabric-bridge-*-SNAPSHOT.jar

- name: Archive artifacts (Fabric 1.17)
uses: actions/upload-artifact@v2
if: success()
with:
name: BungeeTabListPlus Fabric 1.17 Bridge
path: fabric-bridge-1.17/build/libs/btlp-fabric-bridge-*-SNAPSHOT.jar
Original file line number Diff line number Diff line change
Expand Up @@ -289,64 +289,64 @@ public void resendUnconfirmedMessages() {
}

public void updateData(boolean isMainThread) throws IOException {
synchronized (updateDataLock) {
Map<Integer, Player> proxyIds = new HashMap<>();
Map<Integer, Player> proxyIds = new HashMap<>();

for (Map.Entry<Player, PlayerConnectionInfo> e : playerPlayerConnectionInfoMap.entrySet()) {
Player player = e.getKey();
PlayerConnectionInfo connectionInfo = e.getValue();
for (Map.Entry<Player, PlayerConnectionInfo> e : playerPlayerConnectionInfoMap.entrySet()) {
Player player = e.getKey();
PlayerConnectionInfo connectionInfo = e.getValue();

if (!connectionInfo.isConnectionValid) {
continue;
}
if (!connectionInfo.isConnectionValid) {
continue;
}

proxyIds.putIfAbsent(connectionInfo.proxyIdentifier, player);
proxyIds.putIfAbsent(connectionInfo.proxyIdentifier, player);

updatePlayerData(player, connectionInfo, isMainThread);
}
updatePlayerData(player, connectionInfo, isMainThread);
}

for (Map.Entry<Integer, Player> e : proxyIds.entrySet()) {
Integer proxyIdentifier = e.getKey();
Player player = e.getValue();
BridgeData bridgeData = serverBridgeDataMap.get(proxyIdentifier);
ArrayList<CacheEntry> dirtyEntries = new ArrayList<>();

if (bridgeData == null) {
continue;
}
for (Map.Entry<Integer, Player> e : proxyIds.entrySet()) {
dirtyEntries.clear();
Integer proxyIdentifier = e.getKey();
Player player = e.getValue();
BridgeData bridgeData = serverBridgeDataMap.get(proxyIdentifier);

int size = 0;
if (bridgeData == null) {
continue;
}

for (CacheEntry entry : bridgeData.requestedData) {
DataKey<?> key = entry.key;
if (requiresMainThread(key) == isMainThread) {
Object value = serverDataAccess.get(key, server);
entry.dirty = !Objects.equals(value, entry.value);
for (CacheEntry entry : bridgeData.requestedData) {
DataKey<?> key = entry.key;
if (requiresMainThread(key) == isMainThread) {
Object value = serverDataAccess.get(key, server);
synchronized (entry) {
boolean dirty = !Objects.equals(value, entry.value);
entry.value = value;

if (entry.dirty) {
size++;
if (dirty) {
dirtyEntries.add(entry);
}
}
}
}

synchronized (updateDataLock) {
ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
DataOutput output = new DataOutputStream(byteArrayOutput);

output.writeByte(BridgeProtocolConstants.MESSAGE_ID_UPDATE_DATA_SERVER);
output.writeInt(proxyIdentifier + serverIdentifier);
output.writeInt(bridgeData.nextOutgoingMessageId++);
output.writeInt(size);

for (CacheEntry entry : bridgeData.requestedData) {
if (entry.dirty) {
output.writeInt(entry.netId);
output.writeBoolean(entry.value == null);
if (entry.value != null) {
try {
typeAdapterRegistry.getTypeAdapter((TypeToken<Object>) entry.key.getType()).write(output, entry.value);
} catch (IOException e1) {
e1.printStackTrace();
}
output.writeInt(dirtyEntries.size());

for (CacheEntry entry : dirtyEntries) {
output.writeInt(entry.netId);
output.writeBoolean(entry.value == null);
if (entry.value != null) {
try {
typeAdapterRegistry.getTypeAdapter((TypeToken<Object>) entry.key.getType()).write(output, entry.value);
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
Expand All @@ -360,46 +360,44 @@ public void updateData(boolean isMainThread) throws IOException {
}

private void updatePlayerData(@Nonnull Player player, @Nonnull PlayerConnectionInfo connectionInfo, boolean isMainThread) throws IOException {
synchronized (updateDataLock) {
BridgeData bridgeData = connectionInfo.playerBridgeData;
BridgeData bridgeData = connectionInfo.playerBridgeData;

if (bridgeData == null) {
return;
}
if (bridgeData == null) {
return;
}

int size = 0;
ArrayList<CacheEntry> dirtyEntries = new ArrayList<>();

for (CacheEntry entry : bridgeData.requestedData) {
DataKey<?> key = entry.key;
if (requiresMainThread(key) == isMainThread) {
Object value = playerDataAccess.get(key, player);
entry.dirty = !Objects.equals(value, entry.value);
entry.value = value;
for (CacheEntry entry : bridgeData.requestedData) {
DataKey<?> key = entry.key;
if (requiresMainThread(key) == isMainThread) {
Object value = playerDataAccess.get(key, player);
boolean dirty = !Objects.equals(value, entry.value);
entry.value = value;

if (entry.dirty) {
size++;
}
if (dirty) {
dirtyEntries.add(entry);
}
}
}

if (size != 0) {
if (!dirtyEntries.isEmpty()) {
synchronized (updateDataLock) {
ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
DataOutput output = new DataOutputStream(byteArrayOutput);
output.writeByte(BridgeProtocolConstants.MESSAGE_ID_UPDATE_DATA);
output.writeInt(connectionInfo.connectionIdentifier);
output.writeInt(bridgeData.nextOutgoingMessageId++);
output.writeInt(size);

for (CacheEntry entry : bridgeData.requestedData) {
if (entry.dirty) {
output.writeInt(entry.netId);
output.writeBoolean(entry.value == null);
if (entry.value != null) {
try {
typeAdapterRegistry.getTypeAdapter((TypeToken<Object>) entry.key.getType()).write(output, entry.value);
} catch (IOException e1) {
e1.printStackTrace();
}
output.writeInt(dirtyEntries.size());

for (CacheEntry entry : dirtyEntries) {
output.writeInt(entry.netId);
output.writeBoolean(entry.value == null);
if (entry.value != null) {
try {
typeAdapterRegistry.getTypeAdapter((TypeToken<Object>) entry.key.getType()).write(output, entry.value);
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
Expand All @@ -423,7 +421,7 @@ public void setServerDataAccess(@Nonnull DataAccess<Server> serverDataAccess) {
protected abstract void sendMessage(@Nonnull Player player, @Nonnull byte[] message);

protected abstract void runAsync(@Nonnull Runnable task);

protected abstract boolean requiresMainThread(@Nonnull DataKey<?> key);

private static class PlayerConnectionInfo {
Expand All @@ -446,7 +444,6 @@ private static class CacheEntry {
final int netId;
@Nullable
Object value = null;
boolean dirty = false;

CacheEntry(@Nonnull DataKey<?> key, int netId) {
this.key = key;
Expand All @@ -463,7 +460,7 @@ private static class BridgeData {
long lastMessageSent = 0;

/***
*
*
* @param key
* @param netId
* @return true if a new entry has been created
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {

ext {
spigotVersion = '1.11-R0.1-SNAPSHOT'
bungeeVersion = '1.19-R0.1-SNAPSHOT'
bungeeVersion = '1.20-R0.2-SNAPSHOT'
spongeVersion = '7.0.0'
dataApiVersion = '1.0.2-SNAPSHOT'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import de.codecrafter47.taboverlay.handler.*;
import it.unimi.dsi.fastutil.objects.*;
import lombok.*;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.packet.*;
Expand Down Expand Up @@ -181,6 +182,11 @@ private void sendPacket(DefinedPacket packet) {
logVersionMismatch = true;
logger.warning("Cannot correctly update tablist for player " + player.getName() + "\nThe client and server versions do not match. Client >= 1.19.3, server < 1.19.3.\nUse ViaVersion on the spigot server for the best experience.");
}
} else if (player.getPendingConnection().getVersion() >= 764) {
// Ensure that unsafe packets are not sent in the config phase
// Why bungee doesn't expose this via api beyond me...
// https://github.com/SpigotMC/BungeeCord/blob/1ef4d27dbea48a1d47501ad2be0d75e42cc2cc12/proxy/src/main/java/net/md_5/bungee/UserConnection.java#L182-L192
((UserConnection) player).sendPacketQueued(packet);
} else {
player.unsafe().sendPacket(packet);
}
Expand Down

0 comments on commit 5fd0635

Please sign in to comment.