Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic alpha version of the UE4 plugin #485

Merged
merged 6 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@
- [Administration](./admin.md)
- [FAQ](./faq.md)
- [xDS](./xds.md)
- [SDKs](./sdks.md)
- [Unreal Engine](./sdks/unreal-engine.md)
3 changes: 3 additions & 0 deletions docs/src/sdks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SDKs

You will learn here about Quilkin SDKs that can be used as clients for interacting with your UDP proxy.
11 changes: 11 additions & 0 deletions docs/src/sdks/unreal-engine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Quilkin Unreal Engine Plugin

This is an alpha version of the Unreal Engine plugin for Quilkin. Currently it only supports adding a routing token in the following format.

```
<packet> | token | version
X bytes | 16 bytes | 1 bytes
```

## How to install
To get this client proxy installed, the SDK should be located in `Engine` path for Plugins, so copy the whole `ue4` folder (resides under `sdks` folder) in your Unreal Engine path `/[UE4 Root]/Engine/Plugins`, then you may want to rename the ue4 folder to `Quilkin`. Unreal Engine will automatically discover the plugin by searching for `.uplugin` file.
24 changes: 24 additions & 0 deletions sdks/ue4/Quilkin.uplugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"FileVersion" : 1,
"Version" : 1,
"VersionName" : "1.0",
"FriendlyName" : "Quilkin",
"Description" : "",
"Category" : "Online",
"CreatedBy" : "Embark Studios",
"CreatedByURL" : "http://embark.games",
"DocsURL" : "",
"MarketplaceURL" : "",
"SupportURL" : "",
"EnabledByDefault" : true,
"CanContainContent" : false,
"IsBetaVersion" : false,
"Installed" : false,
"Modules": [
{
"Name": "Quilkin",
"Type": "Runtime",
"LoadingPhase" : "Default"
}
]
}
19 changes: 19 additions & 0 deletions sdks/ue4/Source/Quilkin/Private/QuilkinDelegates.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "QuilkinDelegates.h"

FQuilkinDelegates::FGetQuilkinRoutingToken FQuilkinDelegates::GetQuilkinRoutingToken;
19 changes: 19 additions & 0 deletions sdks/ue4/Source/Quilkin/Private/QuilkinLog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "QuilkinLog.h"

DEFINE_LOG_CATEGORY(LogQuilkin);
21 changes: 21 additions & 0 deletions sdks/ue4/Source/Quilkin/Private/QuilkinLog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include "CoreMinimal.h"

DECLARE_LOG_CATEGORY_EXTERN(LogQuilkin, VeryVerbose, All);
79 changes: 79 additions & 0 deletions sdks/ue4/Source/Quilkin/Private/QuilkinModule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "QuilkinModule.h"
#include "QuilkinLog.h"

#include "Modules/ModuleManager.h"
#include "SocketSubsystemModule.h"
#include "UObject/NameTypes.h"

void FQuilkinModule::StartupModule()
{
UE_LOG(LogQuilkin, Log, TEXT("FQuilkinModule::StartupModule()"));

bool bEnabled = true;
if (GConfig)
{
GConfig->GetBool(TEXT("Quilkin.SocketSubsystem"), TEXT("Enabled"), bEnabled, GEngineIni);
}
UE_LOG(LogQuilkin, Log, TEXT("QuilkinSocketSubsystem is %s"), bEnabled ? TEXT("enabled") : TEXT("disabled"));

if (!bEnabled)
{
return;
}

FSocketSubsystemModule &SocketSubsystemModule = FModuleManager::LoadModuleChecked<FSocketSubsystemModule>("Sockets");

ISocketSubsystem *DefaultSocketSubsystem = SocketSubsystemModule.GetSocketSubsystem();
if (DefaultSocketSubsystem == nullptr)
{
UE_LOG(LogQuilkin, Log, TEXT("No default SocketSubsystem was set. Will not use Quilkin SocketSubsystem"));
return;
}
UE_LOG(LogQuilkin, Log, TEXT("Overriding default SocketSubsystem with QuilkinSocketSubsystem"));

QuilkinSocketSubsystem = MakeUnique<FQuilkinSocketSubsystem>(DefaultSocketSubsystem);
SocketSubsystemModule.RegisterSocketSubsystem(QUILKIN_SOCKETSUBSYSTEM_NAME, QuilkinSocketSubsystem.Get(), true);
}

void FQuilkinModule::ShutdownModule()
{
UE_LOG(LogQuilkin, Log, TEXT("FQuilkinModule::ShutdownModule()"));

if (!QuilkinSocketSubsystem.IsValid())
{
return;
}

FSocketSubsystemModule &SocketSubsystemModule = FModuleManager::LoadModuleChecked<FSocketSubsystemModule>("Sockets");
SocketSubsystemModule.UnregisterSocketSubsystem(QUILKIN_SOCKETSUBSYSTEM_NAME);
QuilkinSocketSubsystem.Reset();
}

bool FQuilkinModule::SupportsDynamicReloading()
{
return false;
}

bool FQuilkinModule::SupportsAutomaticShutdown()
{
// Shutdown gets called by the SocketSubsystem, if we were registered (and we don't do anything if we weren't)
return false;
}

IMPLEMENT_MODULE(FQuilkinModule, Quilkin);
35 changes: 35 additions & 0 deletions sdks/ue4/Source/Quilkin/Private/QuilkinModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include "CoreMinimal.h"
#include "Modules/ModuleInterface.h"
#include "QuilkinSocketSubsystem.h"

class FQuilkinModule : public IModuleInterface
{
public:
//~ Begin IModuleInterface interface
virtual void StartupModule() override;
virtual void ShutdownModule() override;
virtual bool SupportsDynamicReloading() override;
virtual bool SupportsAutomaticShutdown() override;
//~ End IModuleInterface Interface

private:
TUniquePtr<FQuilkinSocketSubsystem> QuilkinSocketSubsystem;
};
32 changes: 32 additions & 0 deletions sdks/ue4/Source/Quilkin/Private/QuilkinPacketHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "QuilkinPacketHandler.h"
#include "QuilkinDelegates.h"


FQuilkinPacketHandler::FQuilkinPacketHandler()
{
if (FQuilkinDelegates::GetQuilkinRoutingToken.IsBound())
{
RoutingToken = FQuilkinDelegates::GetQuilkinRoutingToken.Execute();
}
}

bool FQuilkinPacketHandler::IsEnabled()
{
return RoutingToken.Num() > 0;
}
44 changes: 44 additions & 0 deletions sdks/ue4/Source/Quilkin/Private/QuilkinPacketHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include "CoreMinimal.h"

class FQuilkinPacketHandler
{
public:
FQuilkinPacketHandler();
bool IsEnabled();

FORCEINLINE const FBitWriter Handle(const uint8* Packet, int32 CountBytes)
{
// Add the current packet version.
uint8 PacketVersion = 0;
int PacketVersionNumBytes = 1;

// Reserve enough space for the token and packet version.
FBitWriter NewPacket((CountBytes + RoutingToken.Num() + PacketVersionNumBytes) * 8, true);

NewPacket.Serialize((void*)Packet, CountBytes);
NewPacket.Serialize(RoutingToken.GetData(), RoutingToken.Num());
NewPacket.Serialize(&PacketVersion, PacketVersionNumBytes);
return NewPacket;
}

private:
TArray<uint8> RoutingToken;
};
Loading