Initial Commit
This commit is contained in:
53
Common/build.gradle
Normal file
53
Common/build.gradle
Normal file
@@ -0,0 +1,53 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
archivesBaseName = "${mod_name}-common-${minecraft_version}"
|
||||
|
||||
minecraft {
|
||||
version(minecraft_version)
|
||||
runs {
|
||||
if (project.hasProperty('common_runs_enabled') ? project.findProperty('common_runs_enabled').toBoolean() : true) {
|
||||
|
||||
server(project.hasProperty('common_server_run_name') ? project.findProperty('common_server_run_name') : 'vanilla_server') {
|
||||
workingDirectory(this.file("run"))
|
||||
}
|
||||
client(project.hasProperty('common_client_run_name') ? project.findProperty('common_client_run_name') : 'vanilla_client') {
|
||||
workingDirectory(this.file("run"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly group:'org.spongepowered', name:'mixin', version:'0.8.5'
|
||||
compileOnly("me.hypherionmc.craterlib:CraterLib-common-${minecraft_version}:${craterlib_version}")
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
||||
def buildProps = project.properties.clone()
|
||||
|
||||
filesMatching(['pack.mcmeta']) {
|
||||
|
||||
expand buildProps
|
||||
}
|
||||
}
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
groupId project.group
|
||||
artifactId project.archivesBaseName
|
||||
version project.version
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url "file://" + System.getenv("local_maven")
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package me.hypherionmc.ftimeouts;
|
||||
|
||||
public class Constants {
|
||||
|
||||
public static final String MOD_ID = "ftimeouts";
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package me.hypherionmc.ftimeouts;
|
||||
|
||||
import me.hypherionmc.ftimeouts.config.FTimeoutsConfig;
|
||||
|
||||
public class ServerInit {
|
||||
|
||||
public static FTimeoutsConfig config = new FTimeoutsConfig();
|
||||
|
||||
public static void load() {}
|
||||
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
package me.hypherionmc.ftimeouts.config;
|
||||
|
||||
import me.hypherionmc.craterlib.common.config.ModuleConfig;
|
||||
import me.hypherionmc.ftimeouts.ServerInit;
|
||||
import me.hypherionmc.ftimeouts.Constants;
|
||||
import me.hypherionmc.moonconfig.core.conversion.Path;
|
||||
import me.hypherionmc.moonconfig.core.conversion.SpecComment;
|
||||
|
||||
public class FTimeoutsConfig extends ModuleConfig {
|
||||
|
||||
@Path("connectionTimeout")
|
||||
@SpecComment("The login timeout in ticks")
|
||||
public int connectionTimeout = 2400;
|
||||
|
||||
@Path("readTimeout")
|
||||
@SpecComment("The connection read timeout in seconds")
|
||||
public int readTimeout = 120;
|
||||
|
||||
@Path("keepAlive")
|
||||
@SpecComment("How long (in seconds) before server keep alive ends")
|
||||
public int keepAlive = 60;
|
||||
|
||||
@Path("keepAlivePacket")
|
||||
@SpecComment("""
|
||||
The KeepAlive timeout in seconds.
|
||||
This is how long the server waits for a player to return a KeepAlive packet\s
|
||||
before disconnecting them.
|
||||
This is automatically rounded up to a multiple of the KeepAlive packet interval.""")
|
||||
public int keepAlivePacket = 120;
|
||||
|
||||
public FTimeoutsConfig() {
|
||||
super(Constants.MOD_ID, "ftimeouts");
|
||||
registerAndSetup(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configReloaded() {
|
||||
ServerInit.config = loadConfig(this);
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package me.hypherionmc.ftimeouts.mixin;
|
||||
|
||||
import me.hypherionmc.ftimeouts.ServerInit;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
@Mixin(targets = {
|
||||
"net/minecraft/network/Connection$1",
|
||||
"net/minecraft/server/network/ServerConnectionListener$1"
|
||||
})
|
||||
public class ConnectionMixin {
|
||||
|
||||
@ModifyArg(method = "initChannel",
|
||||
at = @At(value = "INVOKE", target = "Lio/netty/handler/timeout/ReadTimeoutHandler;<init>(I)V")
|
||||
)
|
||||
private int getReadTimeout(int timeout) {
|
||||
return ServerInit.config.readTimeout;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package me.hypherionmc.ftimeouts.mixin;
|
||||
|
||||
import me.hypherionmc.ftimeouts.ServerInit;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Constant;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(ServerGamePacketListenerImpl.class)
|
||||
public class ServerGamePacketMixin {
|
||||
|
||||
@Shadow private long keepAliveTime;
|
||||
|
||||
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;disconnect(Lnet/minecraft/network/chat/Component;)V"))
|
||||
private void disconnect(ServerGamePacketListenerImpl instance, Component $$0) {
|
||||
final long keepAliveTimeoutMillis = ServerInit.config.keepAlive * 1000L;
|
||||
|
||||
if (Util.getMillis() - keepAliveTime >= keepAliveTimeoutMillis) {
|
||||
instance.disconnect($$0);
|
||||
}
|
||||
}
|
||||
|
||||
@ModifyConstant(method = "tick", constant = { @Constant(longValue = 15000L), @Constant(longValue = 25000L) })
|
||||
private long getKeepAlivePacketInterval(long interval) {
|
||||
return ServerInit.config.keepAlivePacket * 1000L;
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package me.hypherionmc.ftimeouts.mixin;
|
||||
|
||||
import me.hypherionmc.ftimeouts.ServerInit;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ServerLoginPacketListenerImpl.class)
|
||||
public class ServerLoginMixin {
|
||||
|
||||
@Shadow private int tick;
|
||||
|
||||
@Inject(method = "tick", at = @At("TAIL"))
|
||||
private void injectTick(CallbackInfo ci) {
|
||||
if (tick >= ServerInit.config.connectionTimeout) {
|
||||
((ServerLoginPacketListenerImpl) (Object) this).disconnect(
|
||||
Component.translatable("multiplayer.disconnect.slow_login")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerLoginPacketListenerImpl;disconnect(Lnet/minecraft/network/chat/Component;)V"))
|
||||
private void disconnect(ServerLoginPacketListenerImpl instance, Component $$0) {
|
||||
|
||||
}
|
||||
}
|
15
Common/src/main/resources/ftimeouts.mixins.json
Normal file
15
Common/src/main/resources/ftimeouts.mixins.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "me.hypherionmc.ftimeouts.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"server": [
|
||||
"ConnectionMixin",
|
||||
"ServerLoginMixin",
|
||||
"ServerGamePacketMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"refmap": "${refmap_target}refmap.json"
|
||||
}
|
6
Common/src/main/resources/pack.mcmeta
Normal file
6
Common/src/main/resources/pack.mcmeta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"pack": {
|
||||
"description": "${mod_name}",
|
||||
"pack_format": 9
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user