Skip to content

Commit

Permalink
Fixes a type usage in HandleWatchMessage and replaces TArray::IsEmpty…
Browse files Browse the repository at this point in the history
… with Num() == 0 to allow it to compile in Unreal 4 and Unreal 5 (googleforgames#3060)

Co-authored-by: Malcolm Gruber <malcolmgruber@digitalsworcery.com>
  • Loading branch information
2 people authored and Kalaiselvi84 committed Apr 11, 2023
1 parent e85f18e commit 4372ea3
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions sdks/unreal/Agones/Source/Agones/Private/AgonesComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@

DEFINE_LOG_CATEGORY_STATIC(LogAgones, Log, Log);

#if ENGINE_MAJOR_VERSION > 4
typedef UTF8CHAR UTF8FromType;
#else
typedef ANSICHAR UTF8FromType;
#endif

UAgonesComponent::UAgonesComponent()
{
PrimaryComponentTick.bCanEverTick = false;
Expand Down Expand Up @@ -224,22 +230,22 @@ void UAgonesComponent::WatchGameServer(const FGameServerDelegate WatchDelegate)

void UAgonesComponent::HandleWatchMessage(const void* Data, SIZE_T Size, SIZE_T BytesRemaining)
{
if (BytesRemaining <= 0 && WatchMessageBuffer.IsEmpty())
{
FUTF8ToTCHAR Message(static_cast<const UTF8CHAR*>(Data), Size);
DeserializeAndBroadcastWatch(FString(Message.Length(), Message.Get()));
return;
}
if (BytesRemaining <= 0 && (WatchMessageBuffer.Num() == 0))
{
FUTF8ToTCHAR Message(static_cast<const UTF8FromType*>(Data), Size);
DeserializeAndBroadcastWatch(FString(Message.Length(), Message.Get()));
return;
}

WatchMessageBuffer.Insert(static_cast<const UTF8CHAR*>(Data), Size, WatchMessageBuffer.Num());
if (BytesRemaining > 0)
{
return;
}
WatchMessageBuffer.Insert(static_cast<const UTF8CHAR*>(Data), Size, WatchMessageBuffer.Num());
if (BytesRemaining > 0)
{
return;
}

FUTF8ToTCHAR Message(WatchMessageBuffer.GetData(), WatchMessageBuffer.Num());
DeserializeAndBroadcastWatch(FString(Message.Length(), Message.Get()));
WatchMessageBuffer.Empty();
FUTF8ToTCHAR Message((const UTF8FromType*)WatchMessageBuffer.GetData(), WatchMessageBuffer.Num());
DeserializeAndBroadcastWatch(FString(Message.Length(), Message.Get()));
WatchMessageBuffer.Empty();
}

void UAgonesComponent::SetLabel(
Expand Down

0 comments on commit 4372ea3

Please sign in to comment.