@@ -9,10 +9,15 @@ namespace Mirror.Tests.RemoteAttrributeTest
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
@@ -277,4 +282,48 @@ public void Command_RequiresAuthorityFalse_ForOtherObjectWithoutConnectionToServ
277282 Assert . That ( called , Is . EqualTo ( 1 ) ) ;
278283 }
279284 }
285+
286+ // need server-only mode for some test
287+ public class CommandTest_ServerOnly : MirrorTest
288+ {
289+ [ SetUp ]
290+ public override void SetUp ( )
291+ {
292+ base . SetUp ( ) ;
293+ // start server without client
294+ NetworkServer . Listen ( 1 ) ;
295+ }
296+
297+ [ TearDown ]
298+ public override void TearDown ( ) => base . TearDown ( ) ;
299+
300+ // [Command] functions should be callable on server-only for convenience.
301+ // https://github.com/MirrorNetworking/Mirror/issues/3450
302+ [ Test ]
303+ public void CommandCalledWhenServerOnly ( )
304+ {
305+ // spawn
306+ CreateNetworked ( out _ , out _ , out AuthorityBehaviour serverComponent ) ;
307+
308+ // set up a callback and check
309+ int callCount = 0 ;
310+ serverComponent . onSendMulti += ( a , b , c ) =>
311+ {
312+ callCount ++ ;
313+ Assert . That ( a , Is . EqualTo ( 42 ) ) ;
314+ Assert . That ( b , Is . EqualTo ( "test" ) ) ;
315+ Assert . That ( c , Is . EqualTo ( true ) ) ;
316+ } ;
317+
318+ // call [Command] on server.
319+ // test multiple parameters to ensure weaver properly injects all
320+ // LdArg0,1,2, etc. instructions.
321+ //
322+ // this should call the function immediately,
323+ // without processing messages.
324+ serverComponent . SendMulti ( 42 , "test" , true ) ;
325+ // ProcessMessages();
326+ Assert . That ( callCount , Is . EqualTo ( 1 ) ) ;
327+ }
328+ }
280329}
0 commit comments