Skip to content

Way to mark [ServerRPC] Attribute as executable by servers #2615

Description

@Reag

Is your feature request related to a problem? Please describe.
In the project I lead, we have two modes of operation: as a local host and as a dedicated headless server. Given this restriction, we have begun to run into issues in terms of code cleanliness on how to handle certain actions in a consistent way between the two modes. Specifically, this boils down to us really wishing we could call certain ServerRPCs as a dedicated server, as the design of the function is pretty blind to who executed said call.

Describe the solution you'd like
Perhaps some override in the attribute tag, such as [ServerRPC(ExecutableBy = RpcOwner.Everyone)]

Describe alternatives you've considered
Currently, we create a single entry-point function that then does a if-else branch into the rpc or the logic. Said rpc just calls the logic anyway, and it makes the code feel very ugly.

Additional context
Example of the pattern is below. We unfortunately use this in several parts of the code, and a more streamlined system would be very much appreciated!

private void LoadRulers(List<RulerSaveState> savedRulers)
{
    var r = savedRulers.ToArray();
    if (IsServer) LoadRulers_ServerLogic(r);
    else LoadRulers_ServerRPC(r);
}

[ServerRpc]
private void LoadRulers_ServerRPC(RulerSaveState[] savedRulers)
{
    LoadRulers_ServerLogic(savedRulers);
}

private void LoadRulers_ServerLogic(RulerSaveState[] savedRulers)
{
    foreach (var r in savedRulers)
    {
        var prefab = mapper.MeasuringTape;
        var tool = Instantiate(prefab);
        tool.GetComponent<IMeasuringTape>().SetTapeGuids(r.tapeStart, r.tapeEnd);
        var nobj = tool.GetComponent<NetworkObject>();
        nobj.Spawn();
        tool.transform.SetParent(AbsorberSceneManager.Instance.UIContainer.transform);
    }
}

Metadata

Metadata

Assignees

Labels

type:featureNew feature, request or improvement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions