Integrate a Local Dedicated Server to the DSM
Last updated on
Make sure you set up all this function when on the dedicated server scene or level. And the function is only called by the server, not the client.
Register your Local Dedicated Server to the DSM.
- Unreal Engine
- Unity
FString IpAddress = FString("https://127.0.0.1");
int32 Port = 7777;
FString ServerName = FString("my-awesome-game-server");
FRegistry::ServerDSM.RegisterLocalServerToDSM(IpAddress, Port, ServerName, FVoidHandler::CreateLambda([]()
{
// Do something if RegisterLocalServerToDSM has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if RegisterLocalServerToDSM has an error
UE_LOG(LogTemp, Log, TEXT("Error RegisterLocalServerToDSM, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));string ip = "https://127.0.0.1";
uint port = 7777;
string name = "my-awesome-game-server";
AccelByteServerPlugin.GetDedicatedServerManager().RegisterLocalServer(ip, port, name, result =>
{
if (result.IsError)
{
// Do something if RegisterLocalServer has an error
Debug.Log($"Error RegisterLocalServer, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if RegisterLocalServer has been successful
}
});Once completed, if any match request is received, the Dedicated Server will accept the connections from game clients and will be able to start the match.
After the match is finished, you will need to make sure the Dedicated Server is no longer registered in the Dedicated Server Management. Call this function to deregister the Dedicated Server.
- Unreal Engine
- Unity
FString ServerName = FString("my-awesome-game-server");
FRegistry::ServerDSM.DeregisterLocalServerFromDSM(ServerName, FVoidHandler::CreateLambda([]()
{
// Do something if DeregisterLocalServerFromDSM has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if DeregisterLocalServerFromDSM has an error
UE_LOG(LogTemp, Log, TEXT("Error DeregisterLocalServerFromDSM, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));AccelByteServerPlugin.GetDedicatedServerManager().DeregisterLocalServer(result =>
{
if (result.IsError)
{
// Do something if DeregisterLocalServer has an error
Debug.Log($"Error DeregisterLocalServer, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if DeregisterLocalServer has been successful
}
});