mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-10-27 14:30:14 +00:00
Merge remote-tracking branch 'origin/iris4' into iris4
This commit is contained in:
commit
713c3a4762
5 files changed
+39
-11
No files matched your search
@@ -76,6 +76,7 @@ import java.util.Objects;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@Decree(name = "studio", aliases = {"std", "s"}, description = "Studio Commands", studio = true)
|
@Decree(name = "studio", aliases = {"std", "s"}, description = "Studio Commands", studio = true)
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
mc.iterate(TileWrapper.class, (x, y, z, tile) -> {
|
mc.iterate(TileWrapper.class, (x, y, z, tile) -> {
|
||||||
int betterY = y + getWorld().minHeight();
|
int betterY = y + getWorld().minHeight();
|
||||||
if (!TileData.setTileState(c.getBlock(x, betterY, z), tile.getData()))
|
if (!TileData.setTileState(c.getBlock(x, betterY, z), tile.getData()))
|
||||||
Iris.warn("Failed to set tile entity data at [%d %d %d | %s] for tile %s!", x, betterY, z, c.getBlock(x, betterY, z).getBlockData().getMaterial().getKey(), tile.getMaterial().name());
|
Iris.warn("Failed to set tile entity data at [%d %d %d | %s] for tile %s!", x, betterY, z, c.getBlock(x, betterY, z).getBlockData().getMaterial().getKey(), tile.getData().getMaterial().name());
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
if (mc.isFlagged(MantleFlag.CUSTOM_ACTIVE)) {
|
if (mc.isFlagged(MantleFlag.CUSTOM_ACTIVE)) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.volmit.iris.server.packet.init.PingPacket;
|
|||||||
import com.volmit.iris.server.util.ConnectionHolder;
|
import com.volmit.iris.server.util.ConnectionHolder;
|
||||||
import com.volmit.iris.server.util.PacketListener;
|
import com.volmit.iris.server.util.PacketListener;
|
||||||
import com.volmit.iris.server.util.PacketSendListener;
|
import com.volmit.iris.server.util.PacketSendListener;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -55,6 +56,14 @@ public class IrisMasterClient implements ConnectionHolder, PacketListener {
|
|||||||
session.onClientPacket(this, raw);
|
session.onClientPacket(this, raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public KList<String> getVersions() {
|
||||||
|
try {
|
||||||
|
return pingResponse.get().getVersion();
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getNodeCount() {
|
public int getNodeCount() {
|
||||||
try {
|
try {
|
||||||
return nodeCount.get();
|
return nodeCount.get();
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ import com.volmit.iris.server.util.PregenHolder;
|
|||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.collection.KSet;
|
import com.volmit.iris.util.collection.KSet;
|
||||||
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
import lombok.extern.java.Log;
|
import lombok.extern.java.Log;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
@@ -45,13 +47,16 @@ public class IrisMasterServer extends IrisServer {
|
|||||||
private void addNode(InetSocketAddress address) throws InterruptedException {
|
private void addNode(InetSocketAddress address) throws InterruptedException {
|
||||||
var ping = new PingConnection(address);
|
var ping = new PingConnection(address);
|
||||||
try {
|
try {
|
||||||
for (String version : ping.getVersion().get())
|
addNode(address, ping.getVersion().get());
|
||||||
addNode(address, version);
|
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addNode(InetSocketAddress address, Collection<String> versions) {
|
||||||
|
versions.forEach(v -> addNode(address, v));
|
||||||
|
}
|
||||||
|
|
||||||
public void addNode(InetSocketAddress address, String version) {
|
public void addNode(InetSocketAddress address, String version) {
|
||||||
nodes.computeIfAbsent(version, v -> new KSet<>()).add(address);
|
nodes.computeIfAbsent(version, v -> new KSet<>()).add(address);
|
||||||
}
|
}
|
||||||
@@ -80,14 +85,27 @@ public class IrisMasterServer extends IrisServer {
|
|||||||
|
|
||||||
master.getLogger().info("Requesting nodes for session " + uuid);
|
master.getLogger().info("Requesting nodes for session " + uuid);
|
||||||
var map = new KMap<IrisMasterClient, KMap<UUID, PregenHolder>>();
|
var map = new KMap<IrisMasterClient, KMap<UUID, PregenHolder>>();
|
||||||
for (var address : master.nodes.getOrDefault(version, new KSet<>())) {
|
if (!master.nodes.containsKey(version)) {
|
||||||
try {
|
master.getLogger().warning("No nodes found for version " + version);
|
||||||
map.put(IrisConnection.connect(address, new IrisMasterClient(version, session)), new KMap<>());
|
return map;
|
||||||
} catch (Throwable e) {
|
|
||||||
master.getLogger().log(Level.WARNING, "Failed to connect to server " + address, e);
|
|
||||||
master.removeNode(address);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
var nodes = master.nodes.get(version);
|
||||||
|
var remove = new KList<InetSocketAddress>();
|
||||||
|
var burst = MultiBurst.burst.burst(nodes.size());
|
||||||
|
for (var address : nodes) {
|
||||||
|
burst.queue(() -> {
|
||||||
|
try {
|
||||||
|
var client = new IrisMasterClient(version, session);
|
||||||
|
master.addNode(address, client.getVersions());
|
||||||
|
map.put(IrisConnection.connect(address, client), new KMap<>());
|
||||||
|
} catch (Throwable e) {
|
||||||
|
master.getLogger().log(Level.WARNING, "Failed to connect to server " + address, e);
|
||||||
|
remove.add(address);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
burst.complete();
|
||||||
|
remove.forEach(nodes::remove);
|
||||||
|
|
||||||
master.sessions.put(uuid, map);
|
master.sessions.put(uuid, map);
|
||||||
return map;
|
return map;
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ public class IrisMasterSession implements ConnectionHolder, PacketListener {
|
|||||||
private IrisMasterClient pick() throws RejectedException {
|
private IrisMasterClient pick() throws RejectedException {
|
||||||
return clients.keySet()
|
return clients.keySet()
|
||||||
.stream()
|
.stream()
|
||||||
.min(Comparator.comparingInt(c -> clients.get(c).size()))
|
.min(Comparator.comparingDouble(c -> (double) clients.get(c).size() / c.getNodeCount()))
|
||||||
.orElseThrow(() -> new RejectedException("No clients available"));
|
.orElseThrow(() -> new RejectedException("No clients available"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user