Skip to content

Commit

Permalink
Merge branch 'refs/heads/1.18.2' into 1.17.1
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	libs.versions.toml
  • Loading branch information
senseiwells committed Sep 25, 2024
2 parents 0495b73 + f169457 commit 47dd8e0
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 320 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ After you boot the server a new file will be generated in the path
"pause_notify_players": true,
"notify_admins_of_status": true,
"fix_carpet_bot_view_distance": false,
"include_resource_packs": true,
"ignore_sound_packets": false,
"ignore_light_packets": true,
"ignore_chat_packets": false,
Expand Down Expand Up @@ -261,6 +262,7 @@ After you boot the server a new file will be generated in the path
| `"pause_notify_players"` | <p> If `pause_unloaded_chunks` is enabled and this is enabled then when the recording for the chunk area is paused or resumed all online players will be notified. </p> |
| `"notify_admins_of_status"` | <p> When enabled this will notify admins of when a replay starts, when a replay ends, and when a replay has finished saving, as well as any errors that occur. </p> |
| `"fix_carpet_bot_view_distance"` | <p> If you are recording carpet bots you want to enable this as it sets the view distance to the server view distance. Otherwise it will only record a distance of 2 chunks around the bot. </p> |
| `"include_resource_packs"` | <p> If enabled all server-side resource packs will be copied in the replay file to ensure correct playback. Disabling this will decrease file size but instead it'll try to download the pack from the original source whenever viewing the replay, there is no guarantee that this will work correctly. </p> |
| `"ignore_sound_packets"` | <p> If you are recording a large area for a timelapse it's unlikely you'll want to record any sounds, these can eat up significant storage space. </p> |
| `"ignore_light_packets"` | <p> Light is calculated on the client as well as on the server so light packets are mostly redundant. </p> |
| `"ignore_chat_packets"` | <p> Stops chat packets (from both the server and other players) from being recorded if they are not necessary for your replay. </p> |
Expand Down Expand Up @@ -450,7 +452,7 @@ repositories {
}

dependencies {
modImplementation("me.senseiwells:server-replay:1.1.3+1.17.1")
modImplementation("me.senseiwells:server-replay:1.1.5+1.17.1")
}
```

Expand Down
8 changes: 6 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ plugins {
val shade: Configuration by configurations.creating

repositories {
maven("https://maven.supersanta.me/snapshots")
maven("https://maven.parchmentmc.org/")
maven("https://masa.dy.fi/maven")
maven("https://jitpack.io")
Expand All @@ -25,7 +26,7 @@ repositories {
}


val modVersion = "1.1.3"
val modVersion = "1.1.5"
val releaseVersion = "${modVersion}+mc${libs.versions.minecraft.get()}"
version = releaseVersion
group = "me.senseiwells"
Expand All @@ -42,6 +43,8 @@ dependencies {
modImplementation(libs.fabric.api)
modImplementation(libs.fabric.kotlin)

include(modImplementation(libs.arcade.pack.host.get())!!)

modCompileOnly(libs.carpet)
modCompileOnly(libs.voicechat)
implementation(libs.voicechat.api)
Expand Down Expand Up @@ -108,7 +111,8 @@ tasks {
file = remapJar.get().archiveFile
changelog.set(
"""
- Fixed an issue that caused players to not be able to join when auto recording
- Added `"include_resource_packs"` config
- Optimized resource pack hosting
""".trimIndent()
)
type = STABLE
Expand Down
21 changes: 12 additions & 9 deletions libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ parchment = "1.17.1:2021.12.12"
fabric-api = "0.46.1+1.17"
fabric-kotlin = "1.9.2+kotlin.1.8.10"
permissions = "0.3.1"
arcade = "0.2.0-alpha.46+1.21.1"
carpet = "1.17.1-1.4.57+v220119"
voicechat = "fabric-1.17.1-2.5.7"
voicechat-api = "2.4.0"
replay-studio = "1e96fda605"

[libraries]
minecraft = { module = "com.mojang:minecraft" , version.ref = "minecraft" }
fabric-loader = { module = "net.fabricmc:fabric-loader" , version.ref = "fabric-loader" }
fabric-api = { module = "net.fabricmc.fabric-api:fabric-api" , version.ref = "fabric-api" }
fabric-kotlin = { module = "net.fabricmc:fabric-language-kotlin" , version.ref = "fabric-kotlin" }
permissions = { module = "me.lucko:fabric-permissions-api" , version.ref = "permissions" }
carpet = { module = "carpet:fabric-carpet" , version.ref = "carpet" }
voicechat = { module = "maven.modrinth:simple-voice-chat" , version.ref = "voicechat" }
voicechat-api = { module = "de.maxhenkel.voicechat:voicechat-api" , version.ref = "voicechat-api" }
replay-studio = { module = "com.github.ReplayMod:ReplayStudio" , version.ref = "replay-studio" }
minecraft = { module = "com.mojang:minecraft" , version.ref = "minecraft" }
fabric-loader = { module = "net.fabricmc:fabric-loader" , version.ref = "fabric-loader" }
fabric-api = { module = "net.fabricmc.fabric-api:fabric-api" , version.ref = "fabric-api" }
fabric-kotlin = { module = "net.fabricmc:fabric-language-kotlin" , version.ref = "fabric-kotlin" }
permissions = { module = "me.lucko:fabric-permissions-api" , version.ref = "permissions" }
replay-studio = { module = "com.github.ReplayMod:ReplayStudio" , version.ref = "replay-studio" }
arcade-pack-host = { module = "net.casual-championships:arcade-resource-pack-host", version.ref = "arcade" }

carpet = { module = "carpet:fabric-carpet" , version.ref = "carpet" }
voicechat = { module = "maven.modrinth:simple-voice-chat" , version.ref = "voicechat" }
voicechat-api = { module = "de.maxhenkel.voicechat:voicechat-api" , version.ref = "voicechat-api" }

[plugins]
fabric-loom = { id = "fabric-loom", version.ref = "fabric-loom" }
Expand Down
36 changes: 30 additions & 6 deletions src/main/kotlin/me/senseiwells/replay/ServerReplay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import me.senseiwells.replay.commands.PackCommand
import me.senseiwells.replay.commands.ReplayCommand
import me.senseiwells.replay.config.ReplayConfig
import me.senseiwells.replay.download.DownloadHost
import net.casual.arcade.host.PackHost
import net.casual.arcade.host.pack.ReadablePack
import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents
Expand All @@ -17,9 +19,10 @@ object ServerReplay: ModInitializer {
const val MOD_ID = "server-replay"

private var downloads: DownloadHost? = null
private var packs: PackHost? = null

@JvmField
val logger: Logger = LoggerFactory.getLogger("ServerReplay")
val logger: Logger = LoggerFactory.getLogger(MOD_ID)

val replay: ModContainer = FabricLoader.getInstance().getModContainer(MOD_ID).get()
val version: String = this.replay.metadata.version.friendlyString
Expand All @@ -29,12 +32,17 @@ object ServerReplay: ModInitializer {
private set

override fun onInitialize() {
this.reload()
this.config = ReplayConfig.read()

ServerReplayPluginManager.loadPlugins()

ServerLifecycleEvents.SERVER_STARTING.register { this.downloads?.start() }
ServerLifecycleEvents.SERVER_STOPPING.register { this.downloads?.stop() }
ServerLifecycleEvents.SERVER_STARTING.register {
this.reloadHost()
}
ServerLifecycleEvents.SERVER_STOPPING.register {
this.downloads?.stop()
this.packs?.stop()
}

CommandRegistrationCallback.EVENT.register { dispatcher, _ ->
ReplayCommand.register(dispatcher)
Expand All @@ -52,12 +60,28 @@ object ServerReplay: ModInitializer {
fun reload() {
this.config = ReplayConfig.read()

this.reloadHost()
}

fun hostPack(pack: ReadablePack): PackHost.HostedPackRef? {
return this.packs?.addPack(pack)
}

fun removePack(pack: ReadablePack) {
this.packs?.removePack(pack.name)
}

private fun reloadHost() {
this.downloads?.stop()
this.packs?.stop()

if (this.config.allowDownloadingReplays) {
val downloads = DownloadHost(this.config.replayServerIp, this.config.replayDownloadPort)
downloads.start()
this.downloads = downloads
} else {
this.downloads?.stop()
}
val packs = PackHost(this.config.replayServerIp, this.config.replayViewerPackPort)
packs.start()
this.packs = packs
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import net.minecraft.commands.Commands
import net.minecraft.network.protocol.game.ClientboundResourcePackPacket

object PackCommand {
@JvmStatic
fun register(dispatcher: CommandDispatcher<CommandSourceStack>) {
dispatcher.register(
Commands.literal("resource-pack").then(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import java.util.concurrent.TimeUnit
import kotlin.io.path.*

object ReplayCommand {
@JvmStatic
fun register(dispatcher: CommandDispatcher<CommandSourceStack>) {
dispatcher.register(
Commands.literal("replay").requires {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.senseiwells.replay.compat

import com.google.common.collect.HashMultimap
import me.senseiwells.replay.ServerReplay
import net.fabricmc.loader.api.FabricLoader
import org.objectweb.asm.tree.ClassNode
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin
Expand Down Expand Up @@ -30,15 +29,10 @@ class ReplayMixinConfig: IMixinConfigPlugin {
override fun shouldApplyMixin(targetClassName: String, mixinClassName: String): Boolean {
if (mixinClassName.startsWith(MIXIN_COMPAT)) {
val modId = mixinClassName.removePrefix(MIXIN_COMPAT).substringBefore('.')
val isModLoaded = FabricLoader.getInstance().isModLoaded(modId)
if (!isModLoaded) {
ServerReplay.logger.debug("Not applying compat mixin for mod $modId, mod was not loaded")
}
return isModLoaded
return FabricLoader.getInstance().isModLoaded(modId)
}
for (modId in incompatible.get(mixinClassName)) {
if (FabricLoader.getInstance().isModLoaded(modId)) {
ServerReplay.logger.debug("Not applying $mixinClassName, $modId is incompatible")
return false
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/me/senseiwells/replay/config/ReplayConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ data class ReplayConfig(
var notifyAdminsOfStatus: Boolean = true,
@SerialName("fix_carpet_bot_view_distance")
var fixCarpetBotViewDistance: Boolean = false,
@SerialName("include_resource_packs")
var includeResourcePacks: Boolean = true,
@SerialName("ignore_sound_packets")
var ignoreSoundPackets: Boolean = false,
@SerialName("ignore_light_packets")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ package me.senseiwells.replay.download
import com.sun.net.httpserver.HttpExchange
import com.sun.net.httpserver.HttpServer
import me.senseiwells.replay.ServerReplay
import me.senseiwells.replay.util.HttpHost
import net.casual.arcade.host.core.HttpHost
import java.io.IOException
import java.net.URLDecoder
import java.nio.charset.StandardCharsets
import java.nio.file.Path
import java.util.function.Consumer
import kotlin.io.path.*

class DownloadHost(ip: String?, port: Int): HttpHost(ip, port) {
class DownloadHost(ip: String?, port: Int): HttpHost(ip, port, 3) {
override fun getName(): String {
return "ReplayDownloadHost"
return "replay-download-host"
}

override fun onStart(server: HttpServer, async: Consumer<Runnable>) {
override fun onStart(server: HttpServer) {
server.createContext("/player", this::handlePlayerDownloadRequest)
server.createContext("/chunk", this::handleChunkDownloadRequest)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ abstract class ReplayRecorder(
}

private fun downloadAndRecordResourcePack(packet: ClientboundResourcePackPacket): Boolean {
if (packet.url.startsWith("replay://")) {
if (!ServerReplay.config.includeResourcePacks ||packet.url.startsWith("replay://")) {
return false
}
@Suppress("DEPRECATION", "UnstableApiUsage")
Expand Down
95 changes: 0 additions & 95 deletions src/main/kotlin/me/senseiwells/replay/util/HttpHost.kt

This file was deleted.

Loading

0 comments on commit 47dd8e0

Please sign in to comment.