Skip to content

Unreal Server Start Server

This how-to starts and maintains a Server Session in Unreal Engine, using the Unreal Server SDK in C++.

Prerequisites

  • The Unreal Server SDK installed and set up in your Unreal Server project.
  • An Unreal Server Project.

Start and Maintain a Server Session

A Server Session is valid for 60 minutes; any subsequent call to LootLocker resets the timer back to 60 minutes. To make sure your server is always available, call LootLocker every 55 minutes so you always have a fresh Server Session token to use.

#include "ServerSession.h"
#include "LootLockerServerForCpp.h"
#include "Templates/SharedPointer.h"
#include "TimerManager.h"
// Timer handle to maintain the session
FTimerHandle MaintainSessionTimerHandle;
void OnServerAuthCompleted(FLootLockerServerAuthenticationResponse Response)
{
if (Response.Success)
{
UE_LOG(LogTemp, Log, TEXT("LootLocker server session started successfully. Next refresh in 55 minutes."));
// Here we create a new instance of ServerSession to refresh the session.
// We recommend using a singleton pattern or a static instance for better management in a real application.
// Adapt to your game code as needed.
TSharedPtr<ServerSession> MyServerSession = MakeShared<ServerSession>();
if (GWorld)
{
FTimerDelegate TimerDel = FTimerDelegate::CreateRaw(MyServerSession, &ServerSession::MaintainServerSession);
GWorld->GetTimerManager().SetTimer(
MyServerSession->MaintainSessionTimerHandle,
TimerDel,
3300.0f, // 3300 seconds = 55 minutes
true // Loop the timer to maintain the session every 55 minutes
);
}
}
else
{
UE_LOG(LogTemp, Error, TEXT("Failed to start LootLocker session: %s"), *Response.ErrorData.Message);
}
}
// Call this function when you start your Server: GameModeBase, GameInstance, Server Actor, etc.
void ServerSession::StartLootLockerSession()
{
// CPP delegate
FLootLockerServerAuthResponseDelegate CPPDelegate;
CPPDelegate.BindStatic(&OnServerAuthCompleted);
// Call Start Session
ULootLockerServerForCpp::StartSession(CPPDelegate);
}
void OnMaintainSessionCompleted(FLootLockerServerMaintainSessionResponse Response)
{
if (Response.Success)
{
UE_LOG(LogTemp, Log, TEXT("LootLocker server session refreshed. Next refresh in 55 minutes."));
}
else
{
UE_LOG(LogTemp, Error, TEXT("Failed to start refresh session: %s"), *Response.ErrorData.Message);
}
}
void ServerSession::MaintainServerSession()
{
// CPP delegate
FLootLockerServerMaintainSessionResponseDelegate CPPDelegate;
CPPDelegate.BindStatic(&OnMaintainSessionCompleted);
// Call Start Session
ULootLockerServerForCpp::MaintainSession(CPPDelegate);
}

In the code above, you started a Server Session with LootLocker and set a looping timer to maintain the session every 55 minutes. Now you can be sure your server is always ready whenever it needs to talk with LootLocker.

Conclusion

You've started a LootLocker Server Session and made sure it stays alive for as long as your server is running. With an active Server Session, you can start using any of the features available in the Unreal Server SDK, and combine it with the Unreal SDK to access the full LootLocker Server API from your game server. Next, learn how to create Players from the server.