Skip to content

🛡️ Crafting — Authority

⚠️ Not a multiplayer framework.
This folder provides authority hooks and helpers (interface, resolver, and a default binder).
Replication, prediction, reconciliation, and job state synchronization are the responsibility of your chosen netcode.

Authority here is a runtime, netcode-agnostic gating seam: a small contract (ICraftingAuthority) that callers can consult to decide whether a crafting mutation should be allowed.

✅ Works in single-player and multiplayer (as a gating hook)
✅ No dependency on any netcode SDK
✅ Integrates via a single interface: ICraftingAuthority


🧩 Components & API

ICraftingAuthority

Minimal interface used to allow or deny a crafting mutation.

public interface ICraftingAuthority
{
    bool CanMutate(GameObject owner, out CraftFailReason denyReason);
}

Contract truths - owner may be null (callers may gate non-owner-specific operations with null). - Implementations must tolerate owner == null. - The interface does not define when it is called, what is gated, or how denial reasons are interpreted — those are caller/service semantics.


CraftingAuthority (static resolver, framework-internal)

Framework-internal resolver for locating an ICraftingAuthority relative to a context.

Resolution order (first usable wins): 1. Local component on the context GameObject
2. Parents of the context transform
3. Root GameObjects in the same scene (searches children; includes inactive for discovery, but returns only active and enabled binders)
4. Global scan (last resort; includes inactive for diagnostics; returns only active and enabled binders)

“First usable” means the first active binder encountered during traversal.
From scene roots and the global scan onward, this is based on Unity traversal order rather than proximity or specificity.

Resolver entry points (framework-internal):

static ICraftingAuthority Resolve(MonoBehaviour ctx);
static ICraftingAuthority Resolve(Component c);
static ICraftingAuthority Resolve(GameObject go);

Warning

Binders must be active, enabled, and in-hierarchy to be returned. Inactive or disabled binders may be detected for diagnostics but are never used.


CraftingAuthorityBinder (Local / Single-Player default)

Built-in permissive authority binder intended for single-player and local testing.

[AddComponentMenu("RevFramework/Crafting/Authority/Crafting Authority Binder (Local)")]
public sealed class CraftingAuthorityBinder : MonoBehaviour, ICraftingAuthority
{
    [SerializeField] private bool alwaysTrue = true;
}

Behaviour guaranteed by the binder - When alwaysTrue == true, CanMutate returns true and denyReason = None. - When alwaysTrue == false, CanMutate returns false and denyReason = Unauthorized. - owner is allowed to be null.

Usage - Place this on the same GameObject as the system consulting authority (commonly the Crafting service) to make intent explicit. - Multiplayer or server-authoritative projects should replace this with a custom binder that returns true only on the authority side (server/host).


⚙️ How to Use Authority

This folder provides the hook and resolution helper. The caller or service defines: - Which operations are gated - When authority is consulted - What happens when no authority is found - How denial reasons are surfaced or normalised

Suggested pattern (service/caller responsibility)

  • Resolve an authority from a suitable context (or use an explicitly assigned reference).
  • Before a state mutation, call CanMutate(owner, out reason).
  • If denied, return or emit the caller’s failure result using reason (or a caller-defined default).

🚀 Quick Start

Single-Player / Local

  • Add CraftingAuthorityBinder (Local) with alwaysTrue = true if you want an explicit “always allow” binder, or
  • Don’t add a binder if your caller or service already treats “no authority” as permissive.

Multiplayer / Server-Authoritative

  1. Implement ICraftingAuthority in a custom binder.
  2. Return true only on the authoritative side (server or host).
  3. Replicate crafting and job state using your netcode of choice.

Warning

Authority only answers “may mutate?”
Synchronization, prediction, rollback, and reconciliation are netcode-dependent and out of scope.


❓ FAQs

Q: Where should the authority binder live?
A: Anywhere resolvable by your caller. A common, explicit choice is the same GameObject as the Crafting service.

Q: Why is owner sometimes null?
A: Callers may gate non-owner-specific mutations (for example, scheduler or configuration operations) with owner == null.

Q: Can multiple binders exist?
A: Yes. The resolver returns the first usable binder it encounters based on the resolution order and traversal rules.

Q: Does authority replicate crafting jobs?
A: No. Authority only provides a yes/no decision hook.


🧱 Support Stance

This system is an integration seam, not a networking solution.

RevFramework does not provide: - Crafting job replication - Client-side prediction - Rollback or reconciliation

Context Recommendation
Single-Player Use the local binder (optional) or permissive caller defaults
Multiplayer Bring your own netcode and a server/host authority binder