mirror of
https://github.com/storytold/UE4-OSC.git
synced 2026-10-18 00:33:14 +00:00
validate the "SendTargets" setting
This commit is contained in:
@@ -103,7 +103,7 @@ public:
|
|||||||
{
|
{
|
||||||
FIPv4Address receiveAddress(0);
|
FIPv4Address receiveAddress(0);
|
||||||
uint32_t receivePort;
|
uint32_t receivePort;
|
||||||
if(UOscSettings::Parse(settings->ReceiveFrom, &receiveAddress, &receivePort))
|
if(UOscSettings::Parse(settings->ReceiveFrom, &receiveAddress, &receivePort, UOscSettings::ParseOption::OptionalAddress))
|
||||||
{
|
{
|
||||||
_dispatcher->Listen(receiveAddress, receivePort, settings->MulticastLoopback);
|
_dispatcher->Listen(receiveAddress, receivePort, settings->MulticastLoopback);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ int32 UOscSettings::AddSendTarget(const FString & ip_port)
|
|||||||
|
|
||||||
FIPv4Address address(0);
|
FIPv4Address address(0);
|
||||||
uint32_t port;
|
uint32_t port;
|
||||||
if(Parse(ip_port, &address, &port) && address != FIPv4Address::Any)
|
if(Parse(ip_port, &address, &port, ParseOption::Strict))
|
||||||
{
|
{
|
||||||
target->SetIp(address.Value);
|
target->SetIp(address.Value);
|
||||||
target->SetPort(port);
|
target->SetPort(port);
|
||||||
@@ -142,30 +142,54 @@ void UOscSettings::Send(const uint8 *buffer, int32 length, int32 targetIndex)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UOscSettings::Parse(const FString & ip_port, FIPv4Address * address, uint32_t * port)
|
bool UOscSettings::Parse(const FString & ip_port, FIPv4Address * address, uint32_t * port, ParseOption option)
|
||||||
{
|
{
|
||||||
if(ip_port.IsEmpty())
|
if(ip_port.IsEmpty())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FIPv4Address addressResult(0);
|
FIPv4Address addressResult = FIPv4Address::Any;
|
||||||
uint32_t portResult;
|
uint32_t portResult = 0;
|
||||||
|
|
||||||
int32 sep = -1;
|
int32 sep = -1;
|
||||||
if(ip_port.FindChar(TEXT(':'), sep))
|
const bool hasSep = ip_port.FindChar(TEXT(':'), sep);
|
||||||
|
|
||||||
|
if(hasSep)
|
||||||
{
|
{
|
||||||
|
portResult = FCString::Atoi(&ip_port.GetCharArray()[sep+1]);
|
||||||
|
if(portResult == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const auto ip = ip_port.Left(sep).Trim();
|
const auto ip = ip_port.Left(sep).Trim();
|
||||||
if(!FIPv4Address::Parse(ip, addressResult))
|
if(!FIPv4Address::Parse(ip, addressResult))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
portResult = FCString::Atoi(&ip_port.GetCharArray()[sep+1]);
|
|
||||||
if(portResult == 0)
|
|
||||||
{
|
{
|
||||||
return false;
|
if(option == ParseOption::Strict)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if(option == ParseOption::OptionalAddress)
|
||||||
|
{
|
||||||
|
portResult = FCString::Atoi(ip_port.GetCharArray().GetData());
|
||||||
|
if(portResult == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(option == ParseOption::OptionalPort)
|
||||||
|
{
|
||||||
|
if(!FIPv4Address::Parse(ip_port, addressResult))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*address = addressResult;
|
*address = addressResult;
|
||||||
@@ -194,3 +218,27 @@ void UOscSettings::UpdateKeyInputs(UOscDispatcher & dispatcher)
|
|||||||
_keyReceivers.Add(std::move(receiver));
|
_keyReceivers.Add(std::move(receiver));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UOscSettings::PostEditChangeProperty(FPropertyChangedEvent & PropertyChangedEvent)
|
||||||
|
{
|
||||||
|
static const FName SendTargetsName("SendTargets");
|
||||||
|
|
||||||
|
if( PropertyChangedEvent.GetPropertyName() == SendTargetsName )
|
||||||
|
{
|
||||||
|
for(auto & target : SendTargets)
|
||||||
|
{
|
||||||
|
FIPv4Address address;
|
||||||
|
uint32_t port;
|
||||||
|
if( !Parse(target, &address, &port, ParseOption::OptionalPort) || address == FIPv4Address::Any )
|
||||||
|
{
|
||||||
|
target = "127.0.0.1:8000";
|
||||||
|
}
|
||||||
|
else if( port == 0 )
|
||||||
|
{
|
||||||
|
target = address.ToString() + ":8000";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Super::PostEditChangeProperty(PropertyChangedEvent);
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ public:
|
|||||||
UPROPERTY(Config, EditAnywhere, Category=Receive)
|
UPROPERTY(Config, EditAnywhere, Category=Receive)
|
||||||
FString ReceiveFrom;
|
FString ReceiveFrom;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the addresses (ip:port) to send messages to.
|
||||||
|
*
|
||||||
|
* Addresses can also be added at runtime with the AddSendOscTarget function.
|
||||||
|
*/
|
||||||
UPROPERTY(Config, EditAnywhere, Category=Send)
|
UPROPERTY(Config, EditAnywhere, Category=Send)
|
||||||
TArray<FString> SendTargets;
|
TArray<FString> SendTargets;
|
||||||
|
|
||||||
@@ -58,13 +63,22 @@ public:
|
|||||||
|
|
||||||
void UpdateKeyInputs(UOscDispatcher & dispatcher);
|
void UpdateKeyInputs(UOscDispatcher & dispatcher);
|
||||||
|
|
||||||
|
void PostEditChangeProperty( struct FPropertyChangedEvent& PropertyChangedEvent) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
enum class ParseOption
|
||||||
|
{
|
||||||
|
Strict, /// "192.168.0.12:8000"
|
||||||
|
OptionalPort, /// "192.168.0.12" or "192.168.0.12:8000"
|
||||||
|
OptionalAddress, /// "8000" or "192.168.0.12:8000"
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Parse "8000" and "192.168.0.12" to IP and port values.
|
* @brief Parse "8000" and "192.168.0.12" to IP and port values.
|
||||||
* @return true if succeed
|
* @return true if succeed
|
||||||
*/
|
*/
|
||||||
static bool Parse(const FString & ip_port, FIPv4Address * address, uint32_t * port);
|
static bool Parse(const FString & ip_port, FIPv4Address * address, uint32_t * port, ParseOption option);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32 AddSendTarget(const FString & ip_port);
|
int32 AddSendTarget(const FString & ip_port);
|
||||||
|
|||||||
@@ -124,5 +124,5 @@ public:
|
|||||||
* @see SendOsc
|
* @see SendOsc
|
||||||
*/
|
*/
|
||||||
UFUNCTION(BlueprintCallable, Category=OSC)
|
UFUNCTION(BlueprintCallable, Category=OSC)
|
||||||
static int32 AddSendOscTarget(FString IpPort);
|
static int32 AddSendOscTarget(FString IpPort = "127.0.0.1:8000");
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user