Basic parsing completed, next step is to refactor the InitGame function.
This commit is contained in:
@@ -20,13 +20,14 @@ void AShooterGameMode::BeginPlay()
|
|||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
|
||||||
#if WITH_GAMELIFT
|
#if WITH_GAMELIFT
|
||||||
// InitGameLift();
|
InitGameLift();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void AShooterGameMode::InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage)
|
void AShooterGameMode::InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage)
|
||||||
{
|
{
|
||||||
Super::InitGame(MapName, Options, ErrorMessage);
|
Super::InitGame(MapName, Options, ErrorMessage);
|
||||||
|
UE_LOG(LogShooterGameMode, Log, TEXT("[%s] Parsing CLI"), *FDateTime::UtcNow().ToString(TEXT("%Y%m%d-%H%M%S")));
|
||||||
CachedCommandLine = FCommandLine::Get();
|
CachedCommandLine = FCommandLine::Get();
|
||||||
bool bIsCriticalError = false;
|
bool bIsCriticalError = false;
|
||||||
|
|
||||||
@@ -36,7 +37,9 @@ void AShooterGameMode::InitGame(const FString& MapName, const FString& Options,
|
|||||||
if (bDebugMode)
|
if (bDebugMode)
|
||||||
{
|
{
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Debug mode: ENABLED"));
|
UE_LOG(LogShooterGameMode, Log, TEXT("Debug mode: ENABLED"));
|
||||||
|
#if UE_BUILD_DEBUG
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Command Line Arguments: %s"), *CachedCommandLine);
|
UE_LOG(LogShooterGameMode, Log, TEXT("Command Line Arguments: %s"), *CachedCommandLine);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerPort = GetConfiguredOrDefaultPort();
|
ServerPort = GetConfiguredOrDefaultPort();
|
||||||
@@ -49,55 +52,94 @@ void AShooterGameMode::InitGame(const FString& MapName, const FString& Options,
|
|||||||
|
|
||||||
if (!FParse::Value(*CachedCommandLine, TEXT("fleetID="), FleetId))
|
if (!FParse::Value(*CachedCommandLine, TEXT("fleetID="), FleetId))
|
||||||
{
|
{
|
||||||
UE_LOG(LogShooterGameMode, Error, TEXT(">>>FleetId Missing in Command Line"));
|
UE_LOG(LogShooterGameMode, Error, TEXT("FleetId Missing in Command Line"));
|
||||||
bIsCriticalError = true;
|
bIsCriticalError = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT(">>>Fleet ID: %s"), *FleetId);
|
UE_LOG(LogShooterGameMode, Log, TEXT("Fleet ID: %s"), *FleetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FParse::Value(*CachedCommandLine, TEXT("authtoken="), AuthToken))
|
if (!FParse::Value(*CachedCommandLine, TEXT("authtoken="), AuthToken))
|
||||||
{
|
{
|
||||||
UE_LOG(LogShooterGameMode, Error, TEXT(">>>AuthToken Missing in Command Line"));
|
UE_LOG(LogShooterGameMode, Error, TEXT("AuthToken Missing in Command Line"));
|
||||||
bIsCriticalError = true;
|
bIsCriticalError = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (bDebugMode)
|
if (bDebugMode)
|
||||||
{
|
{
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT(">>>AuthToken: %s"), *AuthToken);
|
FString TokenHash = GetSHA256Hash(AuthToken);
|
||||||
|
UE_LOG(LogShooterGameMode, Log, TEXT("AuthToken: %s"), *TokenHash);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT(">>>AuthToken Length: %d"), AuthToken.Len());
|
UE_LOG(LogShooterGameMode, Log, TEXT("AuthToken Length: %d"), AuthToken.Len());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!FParse::Value(*CachedCommandLine, TEXT("hostId="), HostId))
|
if (!FParse::Value(*CachedCommandLine, TEXT("hostId="), HostId))
|
||||||
{
|
{
|
||||||
UE_LOG(LogShooterGameMode, Error, TEXT(">>>HostId Missing in Command Line"));
|
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;
|
bIsCriticalError = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT(">>>Websocket URL: %s"), *WebSocketUrl);
|
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);
|
||||||
|
|
||||||
|
bool bValidWebSocket = WebSocketUrl.StartsWith(TEXT("wss://")) || WebSocketUrl.StartsWith(TEXT("ws://"));
|
||||||
|
|
||||||
|
if (bValidWebSocket)
|
||||||
|
{
|
||||||
|
int32 ColonPos = WebSocketUrl.Find(TEXT(":"), ESearchCase::CaseSensitive);
|
||||||
|
int32 SlashPos = WebSocketUrl.Find(TEXT("/"), ESearchCase::CaseSensitive, ESearchDir::FromStart, ColonPos + 1);
|
||||||
|
|
||||||
|
int32 ParsedPort = 443; // Default wss
|
||||||
|
if (WebSocketUrl.StartsWith(TEXT("ws://"))) ParsedPort = 80;
|
||||||
|
|
||||||
|
if (ColonPos != INDEX_NONE && SlashPos != INDEX_NONE)
|
||||||
|
{
|
||||||
|
FString PortStr = WebSocketUrl.Mid(ColonPos + 1, SlashPos - ColonPos - 1);
|
||||||
|
int32 ExplicitPort = FCString::Atoi(*PortStr);
|
||||||
|
if (ExplicitPort > 1024 && ExplicitPort <= 65535) // Privileged ports OK for servers
|
||||||
|
{
|
||||||
|
ParsedPort = ExplicitPort;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bValidWebSocket = false; // Invalid explicit port
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UE_LOG(LogShooterGameMode, Log, TEXT("WebSocket Parsed Port: %d"), ParsedPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bValidWebSocket)
|
||||||
|
{
|
||||||
|
UE_LOG(LogShooterGameMode, Error, TEXT("Invalid WebSocketUrl: %s"), *WebSocketUrl);
|
||||||
|
bIsCriticalError = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ServerPort == 0)
|
if (ServerPort == 0)
|
||||||
{
|
{
|
||||||
UE_LOG(LogShooterGameMode, Error, TEXT("Invalid or Missing Server Port Number."));
|
UE_LOG(LogShooterGameMode, Error, TEXT("Invalid or Missing Server Port Number. Shutting Down."));
|
||||||
bIsCriticalError = true;
|
bIsCriticalError = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UE_LOG(LogShooterGameMode, Log, TEXT("Port: %d"), ServerPort);
|
||||||
|
}
|
||||||
if (!FParse::Value(*CachedCommandLine, TEXT("serverRegion="), ServerRegion))
|
if (!FParse::Value(*CachedCommandLine, TEXT("serverRegion="), ServerRegion))
|
||||||
{
|
{
|
||||||
UE_LOG(LogShooterGameMode, Error, TEXT(">>>ServerRegion Missing in Command Line"));
|
UE_LOG(LogShooterGameMode, Warning, TEXT("ServerRegion Missing in Command Line"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -114,6 +156,10 @@ void AShooterGameMode::InitGame(const FString& MapName, const FString& Options,
|
|||||||
UE_LOG(LogShooterGameMode, Error, TEXT("Invalid or Missing Server Port Number. Shutting Down."));
|
UE_LOG(LogShooterGameMode, Error, TEXT("Invalid or Missing Server Port Number. Shutting Down."));
|
||||||
bIsCriticalError = true;
|
bIsCriticalError = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UE_LOG(LogShooterGameMode, Log, TEXT("Port: %d"), ServerPort);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bIsCriticalError)
|
if (bIsCriticalError)
|
||||||
@@ -138,7 +184,7 @@ int32 AShooterGameMode::GetConfiguredOrDefaultPort() const
|
|||||||
int32 CmdPort = 0;
|
int32 CmdPort = 0;
|
||||||
if (FParse::Value(*CachedCommandLine, TEXT("port="), CmdPort))
|
if (FParse::Value(*CachedCommandLine, TEXT("port="), CmdPort))
|
||||||
{
|
{
|
||||||
if (CmdPort > 0 && CmdPort <= 65535)
|
if (CmdPort > 1024 && CmdPort <= 65535)
|
||||||
{
|
{
|
||||||
Port = CmdPort;
|
Port = CmdPort;
|
||||||
}
|
}
|
||||||
@@ -150,3 +196,19 @@ int32 AShooterGameMode::GetConfiguredOrDefaultPort() const
|
|||||||
return Port;
|
return Port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FString AShooterGameMode::GetSHA256Hash(const FString& Input)
|
||||||
|
{
|
||||||
|
FTCHARToUTF8 Utf8Input(Input);
|
||||||
|
FSHA256Signature Hash;
|
||||||
|
if (FPlatformMisc::GetSHA256Signature(reinterpret_cast<const uint8*>(Utf8Input.Get()), Utf8Input.Length(), Hash))
|
||||||
|
{
|
||||||
|
return Hash.ToString();
|
||||||
|
}
|
||||||
|
return FString::Printf(TEXT("Fail_%dbytes"), Input.Len());
|
||||||
|
}
|
||||||
|
|
||||||
|
void AShooterGameMode::InitGameLift()
|
||||||
|
{
|
||||||
|
//TODO: Need to write later, working on parser first.
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ private:
|
|||||||
TSharedPtr<FServerParameters> ServerParameters;
|
TSharedPtr<FServerParameters> ServerParameters;
|
||||||
|
|
||||||
int32 GetConfiguredOrDefaultPort() const;
|
int32 GetConfiguredOrDefaultPort() const;
|
||||||
|
static FString GetSHA256Hash(const FString& Input);
|
||||||
|
|
||||||
#if WITH_GAMELIFT
|
#if WITH_GAMELIFT
|
||||||
void InitGameLift();
|
void InitGameLift();
|
||||||
|
|||||||
Reference in New Issue
Block a user