@@ -9,10 +9,15 @@ namespace Mirror.Tests.Rpcs
99 class AuthorityBehaviour : NetworkBehaviour
1010 {
1111 public event Action < int > onSendInt ;
12+ public event Action < int , string , bool > onSendMulti ;
1213
1314 [ Command ]
1415 public void SendInt ( int someInt ) =>
1516 onSendInt ? . Invoke ( someInt ) ;
17+
18+ [ Command ]
19+ public void SendMulti ( int someInt , string someString , bool someBool ) =>
20+ onSendMulti ? . Invoke ( someInt , someString , someBool ) ;
1621 }
1722
1823 class IgnoreAuthorityBehaviour : NetworkBehaviour
@@ -278,4 +283,48 @@ public void Command_RequiresAuthorityFalse_ForOtherObjectWithoutConnectionToServ
278283 Assert . That ( called , Is . EqualTo ( 1 ) ) ;
279284 }
280285 }
286+
287+ // need server-only mode for some test
288+ public class CommandTest_ServerOnly : MirrorTest
289+ {
290+ [ SetUp ]
291+ public override void SetUp ( )
292+ {
293+ base . SetUp ( ) ;
294+ // start server without client
295+ NetworkServer . Listen ( 1 ) ;
296+ }
297+
298+ [ TearDown ]
299+ public override void TearDown ( ) => base . TearDown ( ) ;
300+
301+ // [Command] functions should be callable on server-only for convenience.
302+ // https://github.com/MirrorNetworking/Mirror/issues/3450
303+ [ Test ]
304+ public void CommandCalledWhenServerOnly ( )
305+ {
306+ // spawn
307+ CreateNetworked ( out _ , out _ , out AuthorityBehaviour serverComponent ) ;
308+
309+ // set up a callback and check
310+ int callCount = 0 ;
311+ serverComponent . onSendMulti += ( a , b , c ) =>
312+ {
313+ callCount ++ ;
314+ Assert . That ( a , Is . EqualTo ( 42 ) ) ;
315+ Assert . That ( b , Is . EqualTo ( "test" ) ) ;
316+ Assert . That ( c , Is . EqualTo ( true ) ) ;
317+ } ;
318+
319+ // call [Command] on server.
320+ // test multiple parameters to ensure weaver properly injects all
321+ // LdArg0,1,2, etc. instructions.
322+ //
323+ // this should call the function immediately,
324+ // without processing messages.
325+ serverComponent . SendMulti ( 42 , "test" , true ) ;
326+ // ProcessMessages();
327+ Assert . That ( callCount , Is . EqualTo ( 1 ) ) ;
328+ }
329+ }
281330}
0 commit comments