Multiplayer_AutoComponent_RPC.py 5.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. # Test Case Title : Check that the four network RPCs can be sent and received
  7. # fmt: off
  8. class TestSuccessFailTuples():
  9. enter_game_mode = ("Entered game mode", "Failed to enter game mode")
  10. exit_game_mode = ("Exited game mode", "Couldn't exit game mode")
  11. find_network_player = ("Found network player", "Couldn't find network player")
  12. # fmt: on
  13. def Multiplayer_AutoComponent_RPC():
  14. r"""
  15. Summary:
  16. Runs a test to make sure that RPCs can be sent and received via script canvas
  17. Level Description:
  18. - Dynamic
  19. 1. Although the level is nearly empty, when the server and editor connect the server will spawn and replicate the player network prefab.
  20. a. The player network prefab has a NetworkTestPlayerComponent.AutoComponent and a script canvas attached which sends and receives various RPCs.
  21. Print logs occur upon sending and receiving the RPCs; we are testing to make sure the expected events and values are received.
  22. - Static
  23. 1. NetLevelEntity. This is a networked entity which has a script attached. Used for cross-entity communication. The net-player prefab will send this level entity Server->Authority RPCs
  24. Expected Outcome:
  25. We should see editor logs stating that RPCs have been sent and received.
  26. However, if the script receives unexpected values for the Process event we will see print logs for bad data as well.
  27. :return:
  28. """
  29. import azlmbr.legacy.general as general
  30. from editor_python_test_tools.utils import Report
  31. from editor_python_test_tools.utils import Tracer
  32. from editor_python_test_tools.utils import TestHelper as helper
  33. from ly_remote_console.remote_console_commands import RemoteConsole as RemoteConsole
  34. level_name = "AutoComponent_RPC"
  35. helper.init_idle()
  36. general.set_cvar_integer('editorsv_port', 33453)
  37. # 1) Open Level
  38. helper.open_level("Multiplayer", level_name)
  39. with Tracer() as section_tracer:
  40. # 2) Enter game mode
  41. helper.multiplayer_enter_game_mode(TestSuccessFailTuples.enter_game_mode)
  42. # 3) Make sure the network player was spawned
  43. player_id = general.find_game_entity("Player")
  44. Report.critical_result(TestSuccessFailTuples.find_network_player, player_id.IsValid())
  45. # 4) Check the editor logs for expected and unexpected log output
  46. # Authority->Autonomous RPC
  47. PLAYERID_RPC_WAIT_TIME_SECONDS = 1.0 # The player id is sent from the server as soon as the player script is spawned. 1 second should be more than enough time to send/receive that RPC.
  48. helper.succeed_if_log_line_found('EditorServer', 'Script: AutoComponent_RPC: Sending client PlayerNumber 1', section_tracer.prints, PLAYERID_RPC_WAIT_TIME_SECONDS)
  49. helper.succeed_if_log_line_found('Script', "AutoComponent_RPC: I'm Player #1", section_tracer.prints, PLAYERID_RPC_WAIT_TIME_SECONDS)
  50. # Authority->Client RPC
  51. PLAYFX_RPC_WAIT_TIME_SECONDS = 1.1 # The server will send an RPC to play an fx on the client every second.
  52. helper.succeed_if_log_line_found('EditorServer', "Script: AutoComponent_RPC_NetLevelEntity Activated on entity: NetLevelEntity", section_tracer.prints, PLAYFX_RPC_WAIT_TIME_SECONDS)
  53. helper.succeed_if_log_line_found('EditorServer', "Script: AutoComponent_RPC_NetLevelEntity: Authority sending RPC to play some fx.", section_tracer.prints, PLAYFX_RPC_WAIT_TIME_SECONDS)
  54. helper.succeed_if_log_line_found('Script', "AutoComponent_RPC_NetLevelEntity: I'm a client playing some fx.", section_tracer.prints, PLAYFX_RPC_WAIT_TIME_SECONDS)
  55. # Autonomous->Authority RPC
  56. # Sending 2 RPCs: 1 containing a parameter and 1 without
  57. AUTONOMOUS_TO_AUTHORITY_RPC_WAIT_TIME_SECONDS = 1.0 # This RPC is sent as soon as the autonomous player script is spawned. 1 second should be more than enough time to send/receive that RPC.
  58. helper.succeed_if_log_line_found('Script', "AutoComponent_RPC: Sending AutonomousToAuthorityNoParam RPC.", section_tracer.prints, AUTONOMOUS_TO_AUTHORITY_RPC_WAIT_TIME_SECONDS)
  59. helper.succeed_if_log_line_found('Script', "AutoComponent_RPC: Sending AutonomousToAuthority RPC (with float param).", section_tracer.prints, AUTONOMOUS_TO_AUTHORITY_RPC_WAIT_TIME_SECONDS)
  60. helper.succeed_if_log_line_found('EditorServer', "Script: AutoComponent_RPC: Successfully received AutonomousToAuthorityNoParams RPC.", section_tracer.prints, AUTONOMOUS_TO_AUTHORITY_RPC_WAIT_TIME_SECONDS)
  61. helper.succeed_if_log_line_found('EditorServer', "Script: AutoComponent_RPC: Successfully received AutonomousToAuthority RPC (with expected float param).", section_tracer.prints, AUTONOMOUS_TO_AUTHORITY_RPC_WAIT_TIME_SECONDS)
  62. # Server->Authority RPC. Inter-Entity Communication.
  63. SERVER_TO_AUTHORITY_RPC_WAIT_TIME_SECONDS = 1.0 # This RPC is sent as soon as the networked level entity finds the player in the level, and previous tests are relying on the player's existence. 1 second should be more than enough time to send/receive that RPC.
  64. helper.succeed_if_log_line_found('EditorServer', "Script: AutoComponent_RPC_NetLevelEntity: Send ServerToAuthority RPC.", section_tracer.prints, SERVER_TO_AUTHORITY_RPC_WAIT_TIME_SECONDS)
  65. helper.succeed_if_log_line_found('EditorServer', "Script: AutoComponent_RPC: Received ServerToAuthority RPC. Damage=42.", section_tracer.prints, SERVER_TO_AUTHORITY_RPC_WAIT_TIME_SECONDS)
  66. # Exit game mode
  67. helper.exit_game_mode(TestSuccessFailTuples.exit_game_mode)
  68. if __name__ == "__main__":
  69. from editor_python_test_tools.utils import Report
  70. Report.start_test(Multiplayer_AutoComponent_RPC)