Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter to filter searches by rollback status #233

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/networking.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Ledger supports numerous custom packets for interacting with supported client mo

## Versions

The information on this page is applicable for Ledger Networking version 2, which is the version in Ledger versions `1.2.0` and later
The information on this page is applicable for Ledger Networking versions 3, which is the version in Ledger versions `1.2.10` and later

## Packet Types

Expand Down
9 changes: 9 additions & 0 deletions docs/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,12 @@ The `before` parameter selects all results before the point in time that was the
An easy way to remember the difference between `before:1d` and `after:1d` is to think about it like this.
If you go back in time 1 day, do you want everything that happened `before` then or `after` then.
Usually you want `after`.

### Rollback Status
Key - `rolledBack:`
Value - `true` or `false`
Negative Allowed - `No`
Multiple Allowed - `No`
Example - `rolledBack:true`

This parameter allows you to filter by rollback state. If true, then it will only show results that have already been rolled back. If false, then it will only show results that have not been rolled back.
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@ data class ActionSearchParams(
val bounds: BlockBox?,
val before: Instant?,
val after: Instant?,
val rolledBack: Boolean?,
var actions: MutableSet<Negatable<String>>?,
var objects: MutableSet<Negatable<Identifier>>?,
var sourceNames: MutableSet<Negatable<String>>?,
var sourcePlayerNames: MutableSet<Negatable<String>>?,
var worlds: MutableSet<Negatable<Identifier>>?,
var worlds: MutableSet<Negatable<Identifier>>?
) {
private constructor(builder: Builder) : this(
builder.bounds,
builder.before,
builder.after,
builder.rolledBack,
builder.actions,
builder.objects,
builder.sourceNames,
builder.sourcePlayerNames,
builder.worlds
)

fun isEmpty() = listOf(bounds, before, after, actions, objects, sourceNames, sourcePlayerNames, worlds).all { it == null }
fun isEmpty() = listOf(bounds, before, after, actions, objects, sourceNames, sourcePlayerNames, worlds, rolledBack).all { it == null }

companion object {
inline fun build(block: Builder.() -> Unit) = Builder().apply(block).build()
Expand All @@ -36,6 +38,7 @@ data class ActionSearchParams(
var bounds: BlockBox? = null
var before: Instant? = null
var after: Instant? = null
var rolledBack: Boolean? = null
var actions: MutableSet<Negatable<String>>? = null
var objects: MutableSet<Negatable<Identifier>>? = null
var sourceNames: MutableSet<Negatable<String>>? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.github.quiltservertools.ledger.commands.parameters.ActionParameter
import com.github.quiltservertools.ledger.commands.parameters.DimensionParameter
import com.github.quiltservertools.ledger.commands.parameters.ObjectParameter
import com.github.quiltservertools.ledger.commands.parameters.RangeParameter
import com.github.quiltservertools.ledger.commands.parameters.RollbackStatusParameter
import com.github.quiltservertools.ledger.commands.parameters.SimpleParameter
import com.github.quiltservertools.ledger.commands.parameters.SourceParameter
import com.github.quiltservertools.ledger.commands.parameters.TimeParameter
Expand Down Expand Up @@ -39,6 +40,7 @@ object SearchParamArgument {
paramSuggesters["world"] = NegatableParameter(DimensionParameter())
paramSuggesters["before"] = Parameter(TimeParameter())
paramSuggesters["after"] = Parameter(TimeParameter())
paramSuggesters["rolledBack"] = Parameter(RollbackStatusParameter())
}

fun argument(name: String): RequiredArgumentBuilder<ServerCommandSource, String> {
Expand Down Expand Up @@ -161,6 +163,10 @@ object SearchParamArgument {
val time = value as Instant
builder.after = time
}
"rolledBack" -> {
val rolledBack = value as Boolean
builder.rolledBack = rolledBack
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.github.quiltservertools.ledger.commands.parameters

import com.mojang.brigadier.StringReader
import com.mojang.brigadier.arguments.BoolArgumentType
import com.mojang.brigadier.context.CommandContext
import com.mojang.brigadier.suggestion.Suggestions
import com.mojang.brigadier.suggestion.SuggestionsBuilder
import net.minecraft.command.CommandSource
import net.minecraft.server.command.ServerCommandSource
import java.util.concurrent.CompletableFuture

class RollbackStatusParameter : SimpleParameter<Boolean>() {
override fun parse(stringReader: StringReader): Boolean = BoolArgumentType.bool().parse(stringReader)

override fun getSuggestions(
context: CommandContext<ServerCommandSource>,
builder: SuggestionsBuilder
): CompletableFuture<Suggestions> = CommandSource.suggestMatching(setOf("true", "false"), builder)
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ object DatabaseManager {
query.andWhere { Tables.Actions.timestamp.greaterEq(params.after) }
}

if (params.rolledBack != null) {
query.andWhere { Tables.Actions.rolledBack.eq(params.rolledBack) }
}

addParameters(
query,
params.sourceNames,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import net.minecraft.util.Identifier
object Networking {
// List of players who have a compatible client mod
private var networkedPlayers = mutableSetOf<ServerPlayerEntity>()
const val protocolVersion = 2
const val PROTOCOL_VERSION = 3

init {
if (config[NetworkingSpec.networking]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@ class HandshakePacketReceiver : Receiver {
val modVersion = info.get().version
val ledgerVersion = FabricLoader.getInstance().getModContainer(
Ledger.MOD_ID).get().metadata.version.friendlyString
if (Networking.protocolVersion == info.get().protocolVersion) {
if (Networking.PROTOCOL_VERSION == info.get().protocolVersion) {
logInfo("${player.name.string} joined the server with a Ledger compatible client mod")
logInfo("Mod: $modid, Version: $modVersion")

// Player has networking permissions so we send a response
val packet = HandshakePacket()
packet.populate(HandshakeContent(Networking.protocolVersion, ledgerVersion, ActionRegistry.getTypes().toList()))
packet.populate(HandshakeContent(Networking.PROTOCOL_VERSION, ledgerVersion, ActionRegistry.getTypes().toList()))
ServerPlayNetworking.send(player, packet.channel, packet.buf)
player.enableNetworking()
} else {
player.sendMessage(
Text.translatable(
"text.ledger.network.protocols_mismatched",
Networking.protocolVersion, info.get().protocolVersion
Networking.PROTOCOL_VERSION, info.get().protocolVersion
), false
)
logInfo("${player.name.string} joined the server with a Ledger compatible client mod, " +
"but has a mismatched protocol: Ledger protocol version: ${Networking.protocolVersion}" +
"but has a mismatched protocol: Ledger protocol version: ${Networking.PROTOCOL_VERSION}" +
", Client mod protocol version ${info.get().protocolVersion}")
}
} else {
Expand Down
Loading