#include "GameLiftClp.h" namespace cmdlineparser { 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); } details::FParseResult cmdlineparser::GetValueOfToken(const FString& CommandLine, const details::EAvailableTokens Token) { details::FParseResult Result; FString ValueOfToken; Result.Token = Token; ensure(Token != details::EAvailableTokens::Unknown); const bool bTokenFound = FParse::Value( *CommandLine, *details::EnsureEndsWith(details::CLI_TOKENS.FindRef(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.FindRef(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.FindRef(Result.ErrorCode); FString TokenName = details::CLI_TOKENS.FindRef(Result.Token); FString Value = Result.Value; Result.ErrorMessage = ErrorMessage; return Result; } // cmdlineparser::Details namespace namespace details { FString details::EnsureEndsWith(const FString& Token, const TCHAR* Suffix) { return Token.EndsWith(Suffix) ? Token : Token + Suffix; } FPortResult 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::Printf(TEXT("Command Line Option for Port is out of ranged... Using Default Port %d"), PortResult.Port); return PortResult; } PortResult.bUsedDefaultPort = true; PortResult.WarningMessage = FString::Printf(TEXT("Command Line Option for Port not found... Using Default Port %d"), PortResult.Port); return PortResult; } bool details::DoesRegExMatch(const FString& Text, const FString& Pattern) { const FRegexPattern RegexPattern(Pattern); FRegexMatcher Matcher(RegexPattern, Text); return Matcher.FindNext(); } } }