Unreal Engine Module - Run a Dedicated Server on AccelByte Multiplayer Server (AMS) - Test run AMS flow locally
About
In this section, you will learn how to test your dedicated server flow on AccelByte Multiplayer Servers (AMS) locally using AMS Simulator. AMS Simulator is the tool to verify how your dedicated server will react to state changes and unexpected events that originate from AMS. This way, we can make sure that our dedicated server will work properly with the flow without uploading the dedicated server first.
Package dedicated server
Please compile your project and open the Unreal Engine editor. In the Unreal Engine Editor, package your game server for Windows.
注記We chose the Development build to enable logging for debugging purposes. Building as Shipping will disable logging.
Unreal Engine will take some time to package your game server. Once the process is complete, you can move to the next section.
Test run dedicated server locally
This section will test your packaged game server locally to check whether it is able to handle the state changes within the lifecycle of AMS.
Open your Demo AGS Admin Portal dashboard and select your game namespace. Go to AccelByte Multiplayer Servers > Download Resource. Then, download AMS Simulator for Windows.
Before we run the AMS Simulator, we need to set up a new IAM client for the simulator namely ByteWars-AMSSim. To create it, you can follow the same steps when you set up the server and AMS CLI IAM, but this time you need to use the following permission instead.
Resource Permission NAMESPACE:{namespace}:AMS:LOCALDS Create After successfully downloading AMS Simulator and creating the IAM client, open Windows PowerShell and run the AMS Simulator executable using the following command to generate a config file.
amssim.exe generate-config
You should be able to see the
config.json
in the same path as the AMS Simulator executable, open the file using text editor and fill the configuration. Please replace the client id and the client secret that we just created above.{
"WatchdogPort": 5555,
"AGSEnvironmentURL": "demo.accelbyte.io",
"AGSNamespace": "bytewars",
"IAM": {
"ClientID": "XXXXXXXX",
"ClientSecret": "XXXXXXXX"
},
"LocalDSHost": "localhost",
"LocalDSPort": 7777,
"ClaimKeys": [],
"ServerName": "YOUR_PC_NAME"
}Tips- WatchdogPort is the port the app going to use to connect to your dedicated server.
- AGSEnvironmentURL Use the URL of the environment you want to register your local dedicated server to, without the scheme (e.g., http://).
- IAM Use the
ClientID
andClientSecret
that were used to authenticate your AMS Simulator that we created on the previous step. - LocalDSHost and LocalDSPort Use the IP and Port of the machine that runs the local dedicated server, so that your playtester knows where to connect.
- ClaimKeys Provide the list of claim keys that the session service uses to claim your local dedicated server. By default, the ServerName is registered as one of the claim key.
- ServerName Provide the name you want to call your local dedicated server. By default, it is automatically generated using your computer name, which you can change as preferred. Note that, by default, this is registered as one of the claim keys.
Once the configuration is complete, then run the AMS Simulator executable for real.
amssim.exe run
Here is the output of the AMS Simulator. Notice that it provides an example ID format for your local dedicated server. In this example is the
ds_018c1f42-5eb6-7ca3-9650-a732ed75ce6a
. Copy it as you will need it in the next step.AMS simulator url ws://0.0.0.0:5555/watchdog
AMS simulator session id: 01hfaxxvfqhe9gkk2zesfx0b66.
AMS simulator session log path: session\01hfaxxvfqhe9gkk2zesfx0b66.log
Ready to accept local DS
Start the local DS with a valid DS ID that conforms to uuid standards
An example that can be copied and pasted is:
ds_018c1f42-5eb6-7ca3-9650-a732ed75ce6a
==================================Command list=================================================
help show the command list again
info show AMS simulator info
ds
status show status of the ds
ready explicitly set ds into ready state.
claim claim the ds for a game session.
drain drain the ds
exit, quit exit ams simulator
=============================================================================================Next, run the game server executable using the following commands in Windows PowerShell to run your packaged game server. Notice that it uses the
ds_018c1f42-5eb6-7ca3-9650-a732ed75ce6a
from the previous step as its local dedicated server ID.E:/WindowsServer/AccelByteWarsServer.exe -server -log -nosteam -dsid=ds_018c1f42-5eb6-7ca3-9650-a732ed75ce6a -watchdog_url="ws://localhost:5555/watchdog"
Tips- log will show Unreal Engine's log.
- nosteam is used to not run the Steam plugin on the game server side.
- server is used to run the game as a server.
- dsid is the dedicated server identification that will be used by the game server to initialize AMS configuration. You can use the example ID given by the AMS Simulator. In this example is the
ds_018c1f42-5eb6-7ca3-9650-a732ed75ce6a
. Note: This launch parameter will be filled automatically on the AMS side when this dedicated server is launched on the AMS Cloud. - watchdog_url is the URL and the port that will be used to connect the game server to AMS. We used
ws://localhost:5555/watchdog
as the value because this is the default IP and port for the AMS Simulator. You can change the configuration for AMS Simulator inconfig.json
. Note: This launch parameter will be filled automatically on the AMS side when this dedicated server is launched on the AMS Cloud.
Once your game server runs, confirm the local windows server connected to AMS local, from the DS log, once the local server running noticed that we have this following logs under ams log
LogAccelByteAMS
signaling the local server connected to the AMS simulator.LogAccelByteAMS: Connecting to ws://localhost:5555/watchdog
LogAccelByteAMS: ConnectedYou can also confirm the successfull connection from the AMS Simulator.
amssim> DS Connected
Check the dedicated server status using AMS Simulator by executing
ds status
. If the game server successfully registers, then it should display the following log. Notice that theDS State
has changed toReady
.ds status
AMS Simulator will show the following log:
amssim> ds status
ID: xxxxx
Connected at: 2023-XX-XX 10:00:00
Last Heartbeat: 2023-XX-XX 10:00:00
DS State: ReadyYou can also check the dedicate server log, go to the
/Saved
folder from your packaged project (in our example,E:/WindowsServer/AccelByteWars/Saved/Logs/AccelByteWars.log
). Once you see the following log lines, that means your server was completely initiated:// Logged in to IAM successfully
LogAccelByteOSS: Verbose: >>> FOnlineAsyncTaskAccelByteLoginServer::Initialize (AsyncTask method) was called.
LogAccelByteOSS: Verbose: >>> FOnlineAsyncTaskAccelByteLoginServer::TriggerDelegates (AsyncTask method) was called. Args: bWasSuccessful: true
// Connected and registered (ready message sent) to AMS
LogAccelByteAMS: Connecting to ws://localhost:5555/watchdog
LogAccelByteAMS: Connected
LogAccelByteAMS: Send ready message to AMS
{"ready":{"dsid":"testid"}}
// Connected to DS Hub
LogAccelByteDSHub: Connecting to wss://demo.accelbyte.io/dshub/
LogAccelByteDSHub: Connected
LogAccelByteDSHub: New message received from DSHub:
{"MessageID":"","Code":200,"topic":"","payload":{}}
// The wrapper log, the server completely initiated
LogMultiplayerDSEssentials: UMultiplayerDSEssentialsSubsystem_Starter::OnRegisterServerComplete succeeded: TRUETips- DS log should be in your packaged server Saved folder. Example:
E:/WindowsServer/AccelByteWars/Saved/Logs/AccelByteWars.log
. - AMS Simulator Log should be in the
[AMSSimPath]/session
folder.
- DS log should be in your packaged server Saved folder. Example:
You can also check if the game server is able to handle a drain state by executing
ds drain
. If the game server successfully handles the drain state, it should display the following log. Notice that theDS State
has changed toDraining
.ds drain
AMS Simulator will show the following log:
amssim> ds status
Use
ds status
to check theDS State
.amssim> ds status
no connected dedicated serverThe game server log should show the following and then shut down the server.
LogMultiplayerDSEssentials: Received AMS drain message; Shutting down the server now!
To quit AMS Simulator, type in the following command:
quit
Congratulations! You have successfully tested the connection of your local dedicated server to AMS.