153 lines
3.9 KiB
C++
153 lines
3.9 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "Game/ShooterGameMode.h"
|
|
#include "Logging/LogMacros.h"
|
|
|
|
#if WITH_GAMELIFT
|
|
#include "GameLiftServerSDK.h"
|
|
#endif
|
|
|
|
DEFINE_LOG_CATEGORY(LogShooterGameMode)
|
|
|
|
AShooterGameMode::AShooterGameMode()
|
|
{
|
|
UE_LOG(LogShooterGameMode, Log, TEXT("Initializing ShooterGameMode..."));
|
|
}
|
|
|
|
void AShooterGameMode::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
#if WITH_GAMELIFT
|
|
// InitGameLift();
|
|
#endif
|
|
}
|
|
|
|
void AShooterGameMode::InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage)
|
|
{
|
|
Super::InitGame(MapName, Options, ErrorMessage);
|
|
CachedCommandLine = FCommandLine::Get();
|
|
bool bIsCriticalError = false;
|
|
|
|
// Parsing of Command Line
|
|
bDebugMode = FParse::Param(*CachedCommandLine, TEXT("Debug"));
|
|
|
|
if (bDebugMode)
|
|
{
|
|
UE_LOG(LogShooterGameMode, Log, TEXT("Debug mode: ENABLED"));
|
|
UE_LOG(LogShooterGameMode, Log, TEXT("Command Line Arguments: %s"), *CachedCommandLine);
|
|
}
|
|
|
|
ServerPort = GetConfiguredOrDefaultPort();
|
|
|
|
bIsAnywhereFleet = FParse::Param(*CachedCommandLine, TEXT("glAnywhere"));
|
|
if (bIsAnywhereFleet)
|
|
{
|
|
UE_LOG(LogShooterGameMode, Log, TEXT("GameLift Anywhere Fleet Command Line Parsing"));
|
|
UE_LOG(LogShooterGameMode, Log, TEXT("======Command Line Parameters======"));
|
|
|
|
if (!FParse::Value(*CachedCommandLine, TEXT("fleetID="), FleetId))
|
|
{
|
|
UE_LOG(LogShooterGameMode, Error, TEXT(">>>FleetId Missing in Command Line"));
|
|
bIsCriticalError = true;
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogShooterGameMode, Log, TEXT(">>>Fleet ID: %s"), *FleetId);
|
|
}
|
|
|
|
if (!FParse::Value(*CachedCommandLine, TEXT("authtoken="), AuthToken))
|
|
{
|
|
UE_LOG(LogShooterGameMode, Error, TEXT(">>>AuthToken Missing in Command Line"));
|
|
bIsCriticalError = true;
|
|
}
|
|
else
|
|
{
|
|
if (bDebugMode)
|
|
{
|
|
UE_LOG(LogShooterGameMode, Log, TEXT(">>>AuthToken: %s"), *AuthToken);
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogShooterGameMode, Log, TEXT(">>>AuthToken Length: %d"), AuthToken.Len());
|
|
}
|
|
}
|
|
if (!FParse::Value(*CachedCommandLine, TEXT("hostId="), HostId))
|
|
{
|
|
UE_LOG(LogShooterGameMode, Error, TEXT(">>>HostId Missing in Command Line"));
|
|
bIsCriticalError = true;
|
|
}
|
|
{
|
|
UE_LOG(LogShooterGameMode, Log, TEXT(">>>Host ID: %s"), *HostId);
|
|
}
|
|
if (!FParse::Value(*CachedCommandLine, TEXT("websocketUrl="), WebSocketUrl))
|
|
{
|
|
UE_LOG(LogShooterGameMode, Error, TEXT(">>>WebSocketUrl Missing in Command Line"));
|
|
bIsCriticalError = true;
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogShooterGameMode, Log, TEXT(">>>Websocket URL: %s"), *WebSocketUrl);
|
|
}
|
|
if (ServerPort == 0)
|
|
{
|
|
UE_LOG(LogShooterGameMode, Error, TEXT("Invalid or Missing Server Port Number."));
|
|
bIsCriticalError = true;
|
|
}
|
|
if (!FParse::Value(*CachedCommandLine, TEXT("serverRegion="), ServerRegion))
|
|
{
|
|
UE_LOG(LogShooterGameMode, Error, TEXT(">>>ServerRegion Missing in Command Line"));
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogShooterGameMode, Log, TEXT(">>>Server Region: %s"), *ServerRegion);
|
|
}
|
|
|
|
UE_LOG(LogShooterGameMode, Log, TEXT("==================================="));
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogShooterGameMode, Log, TEXT("GameLift EC2 Fleet"));
|
|
if (ServerPort == 0)
|
|
{
|
|
UE_LOG(LogShooterGameMode, Error, TEXT("Invalid or Missing Server Port Number. Shutting Down."));
|
|
bIsCriticalError = true;
|
|
}
|
|
}
|
|
|
|
if (bIsCriticalError)
|
|
{
|
|
UE_LOG(LogShooterGameMode, Error, TEXT("Critical Missing or Invalid Arguments in Command Line. Shutting Down."));
|
|
FPlatformMisc::RequestExit(true);
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogShooterGameMode, Log, TEXT("Command Line Parsed Successfully."));
|
|
}
|
|
|
|
|
|
}
|
|
|
|
int32 AShooterGameMode::GetConfiguredOrDefaultPort() const
|
|
{
|
|
// Default Unreal Engine listen/dedicated server port
|
|
int32 Port = 7777;
|
|
|
|
// Check if a port was passed via command line: -port=xxxx
|
|
int32 CmdPort = 0;
|
|
if (FParse::Value(*CachedCommandLine, TEXT("port="), CmdPort))
|
|
{
|
|
if (CmdPort > 0 && CmdPort <= 65535)
|
|
{
|
|
Port = CmdPort;
|
|
}
|
|
else
|
|
{
|
|
Port = 0;
|
|
}
|
|
}
|
|
return Port;
|
|
}
|
|
|