Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-28 00:50:13 +01:00
Run Velocity server change logic on event loop
Dieser Commit ist enthalten in:
Ursprung
14532bfa9a
Commit
f8def524aa
@ -36,7 +36,6 @@ public class UserConnection {
|
|||||||
// Used for handling warnings (over time)
|
// Used for handling warnings (over time)
|
||||||
private int secondsObserved = 0;
|
private int secondsObserved = 0;
|
||||||
private int warnings = 0;
|
private int warnings = 0;
|
||||||
private ReadWriteLock velocityLock = new ReentrantReadWriteLock();
|
|
||||||
|
|
||||||
public UserConnection(Channel channel) {
|
public UserConnection(Channel channel) {
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
|
@ -35,7 +35,6 @@ public class VelocityDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
|
|||||||
if (info.handlePPS())
|
if (info.handlePPS())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
info.getVelocityLock().readLock().lock();
|
|
||||||
if (info.isActive()) {
|
if (info.isActive()) {
|
||||||
// Handle ID
|
// Handle ID
|
||||||
int id = Type.VAR_INT.read(bytebuf);
|
int id = Type.VAR_INT.read(bytebuf);
|
||||||
@ -58,13 +57,11 @@ public class VelocityDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
|
|||||||
bytebuf.clear();
|
bytebuf.clear();
|
||||||
// Release Packet, be free!
|
// Release Packet, be free!
|
||||||
newPacket.release();
|
newPacket.release();
|
||||||
info.getVelocityLock().readLock().unlock();
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bytebuf.retain();
|
bytebuf.retain();
|
||||||
}
|
}
|
||||||
info.getVelocityLock().readLock().unlock();
|
|
||||||
|
|
||||||
out.add(bytebuf);
|
out.add(bytebuf);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class VelocityServerHandler {
|
public class VelocityServerHandler {
|
||||||
private static Method setProtocolVersion;
|
private static Method setProtocolVersion;
|
||||||
@ -75,27 +77,20 @@ public class VelocityServerHandler {
|
|||||||
|
|
||||||
@Subscribe(order = PostOrder.LATE)
|
@Subscribe(order = PostOrder.LATE)
|
||||||
public void connectedEvent(ServerConnectedEvent e) {
|
public void connectedEvent(ServerConnectedEvent e) {
|
||||||
|
UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId());
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
try {
|
try {
|
||||||
checkServerChange(e, Via.getManager().getConnection(e.getPlayer().getUniqueId()));
|
checkServerChange(e, Via.getManager().getConnection(e.getPlayer().getUniqueId()));
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}, user.getChannel().eventLoop()).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkServerChange(ServerConnectedEvent e, UserConnection user) throws Exception {
|
public void checkServerChange(ServerConnectedEvent e, UserConnection user) throws Exception {
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
// Handle server/version change
|
// Handle server/version change
|
||||||
if (user.has(VelocityStorage.class)) {
|
if (user.has(VelocityStorage.class)) {
|
||||||
// Wait all the scheduled packets be sent
|
|
||||||
Semaphore semaphore = new Semaphore(1);
|
|
||||||
semaphore.acquireUninterruptibly();
|
|
||||||
user.getChannel().eventLoop().submit((Runnable) semaphore::release);
|
|
||||||
semaphore.acquireUninterruptibly();
|
|
||||||
semaphore.release();
|
|
||||||
|
|
||||||
user.getVelocityLock().writeLock().lock();
|
|
||||||
|
|
||||||
try {
|
|
||||||
VelocityStorage storage = user.get(VelocityStorage.class);
|
VelocityStorage storage = user.get(VelocityStorage.class);
|
||||||
|
|
||||||
if (e.getServer() != null) {
|
if (e.getServer() != null) {
|
||||||
@ -180,9 +175,6 @@ public class VelocityServerHandler {
|
|||||||
setProtocolVersion.invoke(connection, version);
|
setProtocolVersion.invoke(connection, version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
user.getVelocityLock().writeLock().unlock();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren