Skip to content

Commit f34d367

Browse files
committed
Don't log ping disconnects
1 parent 0695054 commit f34d367

File tree

4 files changed

+64
-39
lines changed

4 files changed

+64
-39
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66

77
allprojects {
88
group = "com.minekube.connect"
9-
version = "0.2.9"
9+
version = "0.2.10"
1010
description =
1111
"Connects the server/proxy to the global Connect network to reach more players while also supporting online mode server, bungee or velocity mode. Visit https://minekube.com/connect"
1212
}

core/src/main/java/com/minekube/connect/network/netty/LocalChannelInboundHandler.java

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -49,40 +49,6 @@ public class LocalChannelInboundHandler extends SimpleChannelInboundHandler<Byte
4949

5050
private TunnelConn tunnelConn;
5151

52-
@Override
53-
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
54-
// Reject session proposal in case we are still able to and connection was stopped very early.
55-
rejectProposal(context, StatusProto.fromThrowable(cause));
56-
ctx.close();
57-
super.exceptionCaught(ctx, cause);
58-
}
59-
60-
@Override
61-
public void channelActive(@NotNull ChannelHandlerContext ctx) throws Exception {
62-
// Start tunnel from downstream server -> upstream TunnelService
63-
tunnelConn = tunneler.tunnel(
64-
context.getSessionProposal().getSession().getTunnelServiceAddr(),
65-
context.getSessionProposal().getSession().getId(),
66-
new TunnelHandler(logger, ctx.channel())
67-
);
68-
context.tunnelConn.set(tunnelConn);
69-
super.channelActive(ctx);
70-
}
71-
72-
@Override
73-
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf buf) {
74-
// Get underlying byte array from buf without copy
75-
byte[] data = ByteBufUtil.getBytes(buf, buf.readerIndex(), buf.readableBytes(), false);
76-
// downstream server -> local session server -> TunnelService
77-
tunnelConn.write(data);
78-
}
79-
80-
@Override
81-
public void channelInactive(@NotNull ChannelHandlerContext ctx) throws Exception {
82-
onChannelClosed(context, api, logger);
83-
super.channelInactive(ctx);
84-
}
85-
8652
public static void onChannelClosed(Context context,
8753
SimpleConnectApi api,
8854
ConnectLogger logger
@@ -96,8 +62,10 @@ public static void onChannelClosed(Context context,
9662
}
9763

9864
if (api.setPendingRemove(context.getPlayer())) {
99-
logger.translatedInfo("connect.ingame.disconnect_name",
100-
context.getPlayer().getUsername());
65+
if (!context.getPlayer().getUsername().isEmpty()) { // might be just a ping request
66+
logger.translatedInfo("connect.ingame.disconnect_name",
67+
context.getPlayer().getUsername());
68+
}
10169
}
10270

10371
Status reason = Status.newBuilder()
@@ -120,4 +88,38 @@ static void rejectProposal(Context context, Status reason) {
12088
context.getSessionProposal().reject(reason);
12189
}
12290
}
91+
92+
@Override
93+
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
94+
// Reject session proposal in case we are still able to and connection was stopped very early.
95+
rejectProposal(context, StatusProto.fromThrowable(cause));
96+
ctx.close();
97+
super.exceptionCaught(ctx, cause);
98+
}
99+
100+
@Override
101+
public void channelActive(@NotNull ChannelHandlerContext ctx) throws Exception {
102+
// Start tunnel from downstream server -> upstream TunnelService
103+
tunnelConn = tunneler.tunnel(
104+
context.getSessionProposal().getSession().getTunnelServiceAddr(),
105+
context.getSessionProposal().getSession().getId(),
106+
new TunnelHandler(logger, ctx.channel())
107+
);
108+
context.tunnelConn.set(tunnelConn);
109+
super.channelActive(ctx);
110+
}
111+
112+
@Override
113+
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf buf) {
114+
// Get underlying byte array from buf without copy
115+
byte[] data = ByteBufUtil.getBytes(buf, buf.readerIndex(), buf.readableBytes(), false);
116+
// downstream server -> local session server -> TunnelService
117+
tunnelConn.write(data);
118+
}
119+
120+
@Override
121+
public void channelInactive(@NotNull ChannelHandlerContext ctx) throws Exception {
122+
onChannelClosed(context, api, logger);
123+
super.channelInactive(ctx);
124+
}
123125
}

core/src/main/java/com/minekube/connect/util/ReflectionUtils.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ public static Class<?> getClassOrFallback(String className, String fallbackClass
136136
}
137137

138138
@Nullable
139-
public static <T> Constructor<T> getConstructor(Class<T> clazz, boolean declared, Class<?>... parameters) {
139+
public static <T> Constructor<T> getConstructor(Class<T> clazz, boolean declared,
140+
Class<?>... parameters) {
140141
try {
141142
Constructor<T> constructor;
142143
if (declared) {
@@ -246,6 +247,9 @@ public static Field getFieldOfType(Class<?> clazz, Class<?> fieldType) {
246247
*/
247248
@Nullable
248249
public static Object getValue(Object instance, Field field) {
250+
if (field == null) {
251+
return null;
252+
}
249253
makeAccessible(field);
250254
try {
251255
return field.get(instance);
@@ -432,7 +436,8 @@ public static Method getMethod(
432436

433437
Method[] methods = declared ? clazz.getDeclaredMethods() : clazz.getMethods();
434438

435-
outer : for (Method method : methods) {
439+
outer:
440+
for (Method method : methods) {
436441
if (parameterTypes.length != method.getParameterCount() ||
437442
!method.getReturnType().equals(returnType)) {
438443
continue;

spigot/src/main/java/com/minekube/connect/inject/spigot/SpigotInjector.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,31 @@ public final class SpigotInjector extends CommonPlatformInjector {
7272

7373
@Getter private boolean injected;
7474

75+
// We need to disable the enforceSecureProfile in server.properties.
76+
// This has no effect if the server is already in offline mode.
77+
// private static void disableEnforceSecureProfile() {
78+
// Server server = Bukkit.getServer();
79+
// Method getProperties = ReflectionUtils.getMethod(server, "getProperties");
80+
// if (getProperties == null) {
81+
// return;
82+
// }
83+
// Object serverProperties = ReflectionUtils.invoke(server, getProperties);
84+
// if (serverProperties == null) {
85+
// return;
86+
// }
87+
// // enforceSecureProfile field is obfuscated, need to find another way to get this field
88+
// ReflectionUtils.setValue(serverProperties, "enforceSecureProfile", false);
89+
// }
90+
7591
@Override
7692
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
7793
public boolean inject() throws Exception {
7894
if (isInjected()) {
7995
return true;
8096
}
8197

98+
// disableEnforceSecureProfile();
99+
82100
if (getServerConnection() != null) {
83101
for (Field field : serverConnection.getClass().getDeclaredFields()) {
84102
if (field.getType() == List.class) {

0 commit comments

Comments
 (0)