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

feature: allow calling [Command]s on server-only directly. #3450 #3451

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

miwarnec
Copy link
Collaborator

@miwarnec miwarnec commented Apr 8, 2023

TODO

  • IL2CPP builds still fail
  • test coverage
  • try in assets: ummorpg and replace the old wrappers
  • reset changes to Tanks.cs
  • change to isServer / is Client?
  • uMMORPG: PlayerParty [Command] wrappers removed. editor=host, build=client, host invites client to party, client closes. warning: "Command Function System.Void PlayerParty::CmdDismiss() called on y without authority."

calling [Command] on server-only gives the following error:

Command Function System.Void Mirror.Tests.RemoteAttrributeTest.AuthorityBehaviour::SendInt(System.Int32) called on New Game Object without an active client.

before:

    [Command]
    private void CmdTest(int value)
    {
        NetworkWriterPooled writer = NetworkWriterPool.Get();
        writer.WriteInt(value);
        SendCommandInternal("System.Void Mirror.Examples.Tanks.Tank::CmdTest(System.Int32)", 897081557, writer, 0);
        NetworkWriterPool.Return(writer);
    }

    public override void OnStartServer()
    {
        CmdTest(42);
    }

after:

    [Command]
    private void CmdTest(int value)
    {
        if (NetworkServer.active && !NetworkClient.active)
        {
            UserCode_CmdTest__Int32(value);
            return;
        }
        NetworkWriterPooled writer = NetworkWriterPool.Get();
        writer.WriteInt(value);
        SendCommandInternal("System.Void Mirror.Examples.Tanks.Tank::CmdTest(System.Int32)", 897081557, writer, 0);
        NetworkWriterPool.Return(writer);
    }

    public override void OnStartServer()
    {
        CmdTest(42);
    }

use cases in ummorpg. before:

    // version without cmd because we need to call it from the server too
    public void Leave()
    {
        // try to leave. party system will do all the validation.
        PartySystem.LeaveParty(party.partyId, name);
    }
    [Command]
    public void CmdLeave() { Leave(); }

    // version without cmd because we need to call it from the server too
    public void Dismiss()
    {
        // try to dismiss. party system will do all the validation.
        PartySystem.DismissParty(party.partyId, name);
    }
    [Command]
    public void CmdDismiss() { Dismiss(); }

@miwarnec
Copy link
Collaborator Author

miwarnec commented Apr 8, 2023

CmdOnAnimationServerMessage still fails to weave properly:

[Command]
private void CmdOnAnimationServerMessage(int stateHash, float normalizedTime, int layerId, float weight, byte[] parameters)
{
    //IL_001b: Expected O, but got I4
    //IL_001b: Expected F4, but got O
    if (NetworkServer.active && !NetworkClient.active)
    {
        ((NetworkAnimator)/*Error near IL_001b: Stack underflow*/).UserCode_CmdOnAnimationServerMessage__Int32__Single__Int32__Single__Byte[]((int)/*Error near IL_001b: Stack underflow*/, (float)/*Error near IL_001b: Stack underflow*/, (int)/*Error near IL_001b: Stack underflow*/, (float)this, (byte[])stateHash);
        return;
    }
    NetworkWriterPooled writer = NetworkWriterPool.Get();
    writer.WriteInt(stateHash);
    writer.WriteFloat(normalizedTime);
    writer.WriteInt(layerId);
    writer.WriteFloat(weight);
    writer.WriteBytesAndSize(parameters);
    SendCommandInternal("System.Void Mirror.NetworkAnimator::CmdOnAnimationServerMessage(System.Int32,System.Single,System.Int32,System.Single,System.Byte[])", -1895293543, writer, 0);
    NetworkWriterPool.Return(writer);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant