Lesson 55 - Dedicated Servers Game Mode
This commit is contained in:
100
Source/DedicatedServers/Private/GameLift/GameLiftClp.cpp
Normal file
100
Source/DedicatedServers/Private/GameLift/GameLiftClp.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#include "GameLift/GameLiftClp.h"
|
||||
|
||||
FPortResult cmdlineparser::GetConfiguredOrDefaultPort(const FString& Token)
|
||||
{
|
||||
return details::GetConfiguredOrDefaultPort(FCommandLine::Get(), Token);
|
||||
}
|
||||
|
||||
FPortResult cmdlineparser::GetConfiguredOrDefaultPort(const FString& CommandLine, const FString& Token)
|
||||
{
|
||||
return details::GetConfiguredOrDefaultPort(CommandLine, Token);
|
||||
}
|
||||
|
||||
cmdlineparser::details::FParseResult cmdlineparser::GetValueOfToken(const FString& CommandLine, const details::EAvailableTokens Token)
|
||||
{
|
||||
details::FParseResult Result;
|
||||
FString ValueOfToken;
|
||||
Result.Token = Token;
|
||||
|
||||
ensure(Token != details::EAvailableTokens::Unknown);
|
||||
ensure(Token < details::EAvailableTokens::MaxToken);
|
||||
const bool bTokenFound = FParse::Value(
|
||||
*CommandLine,
|
||||
*details::EnsureEndsWith(details::CLI_TOKENS[static_cast<int32>(Token)],
|
||||
TEXT("=")),
|
||||
ValueOfToken
|
||||
);
|
||||
|
||||
if (!bTokenFound)
|
||||
{
|
||||
Result.Value = FString();
|
||||
Result.ErrorCode = details::EErrorCodes::TokenNotFound;
|
||||
Result.bIsValid = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ValueOfToken.IsEmpty())
|
||||
{
|
||||
Result.Value = FString();
|
||||
Result.ErrorCode = details::EErrorCodes::ValueEmpty;
|
||||
Result.bIsValid = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (details::DoesRegExMatch(ValueOfToken, details::REGEX_PATTERNS[static_cast<int32>(Token)]))
|
||||
{
|
||||
Result.ErrorCode = details::EErrorCodes::NoError;
|
||||
Result.bIsValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Result.ErrorCode = details::EErrorCodes::FailedValidation;
|
||||
Result.bIsValid = false;
|
||||
}
|
||||
Result.Value = ValueOfToken;
|
||||
}
|
||||
}
|
||||
|
||||
ensure(Result.ErrorCode < details::EErrorCodes::MaxCode);
|
||||
FString ErrorMessage = details::ERROR_MESSAGES[static_cast<int32>(Result.ErrorCode)];
|
||||
FString TokenName = details::CLI_TOKENS[static_cast<int32>(Result.Token)];
|
||||
FString Value = Result.Value;
|
||||
Result.ErrorMessage = ErrorMessage;
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
||||
// cmdlineparser::Details namespace
|
||||
|
||||
FString cmdlineparser::details::EnsureEndsWith(const FString& Token, const TCHAR* Suffix)
|
||||
{
|
||||
return Token.EndsWith(Suffix) ? Token : Token + Suffix;
|
||||
}
|
||||
|
||||
FPortResult cmdlineparser::details::GetConfiguredOrDefaultPort(const FString& CommandLine, const FString& Token)
|
||||
{
|
||||
FPortResult PortResult;
|
||||
PortResult.Port = FURL::UrlConfig.DefaultPort;
|
||||
|
||||
if (int32 CliPort; FParse::Value(*CommandLine, *EnsureEndsWith(Token, TEXT("=")), CliPort))
|
||||
{
|
||||
if (CliPort >= details::MIN_PORT && CliPort <= details::MAX_PORT)
|
||||
{
|
||||
PortResult.Port = CliPort;
|
||||
PortResult.bUsedDefaultPort = false;
|
||||
PortResult.WarningMessage = FString();
|
||||
return PortResult;
|
||||
}
|
||||
}
|
||||
PortResult.bUsedDefaultPort = true;
|
||||
PortResult.WarningMessage = FString("Command Line Option for Port is out of ranged... Using Default Port %s", PortResult.Port);
|
||||
return PortResult;
|
||||
}
|
||||
|
||||
bool cmdlineparser::details::DoesRegExMatch(const FString& Text, const FString& Pattern)
|
||||
{
|
||||
const FRegexPattern RegexPattern(Pattern);
|
||||
FRegexMatcher Matcher(RegexPattern, Text);
|
||||
return Matcher.FindNext();
|
||||
}
|
||||
Reference in New Issue
Block a user