Skip to content

Conversation

@miwarnec
Copy link
Collaborator

@miwarnec miwarnec commented Apr 8, 2023

NEW PLAN

MrG:
Command(allowServerCall = true)]


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.

2 participants