You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
[NOTE: Switch changes have been removed from this list, and will be in a comment in //UE4/Main/Engine/Build/Switch/SwitchChanges.txt]
Change 3207431 on 2016/11/22 by Keith.Judge
Make VectorSign on XB1 match (incorrect) SSE implementation rather than the reference FPU implementation. Too many things seem to rely on this to change the default behaviour now.
#jira UE-36921
#jira UE-38560
Change 3208206 on 2016/11/22 by Josh.Adams
- Changed plugins upgrading a content-only project to code-based, even if the modules inside aren't compiled for the current platform. There are issues with runtime not knowing the plugin isn't needed. The proper way is to non-whitelist the platform in the project, not in the modules, if you don't want it to upgrade the project. See the comments in this change for more info.
#jira UE-38929
Change 3209137 on 2016/11/23 by Alicia.Cano
Add a check to iOS tool chain for exception flag
#jira UE-36528
#ios
Change 3209296 on 2016/11/23 by Ben.Marsh
Always send build failure notifications in Dev-Platform to Will.Fissler@epicgames.com and Owen.Stupka@epicgames.com
Change 3211316 on 2016/11/28 by Joe.Barnes
Fix some typos
Change 3211318 on 2016/11/28 by Joe.Barnes
Fix wrong function name in header file. Didn't match actual function name in RenderingThread.cpp
Change 3213227 on 2016/11/29 by Dmitry.Rekman
Add -fPIC to libwebsockets on Linux.
Change 3213463 on 2016/11/29 by Nick.Shin
helper build scripts for CentOS 7 Linux (via Docker)
LINUX: pull source and compile: zlib openssl libcurl & libwebsockets
using [ glibc 2.17 ] & [ gcc 4.8.5 ]
Docker creates an image (that is essentially a CentOS box) and runs the build script within that environment (called a container). think of this as a VM -- but waaaaaaay better -- nothing is virtualized -- it's all on the metal.
#jira UEPLAT-1246 - Update libWebsockets
#jira UEPLAT-1221 - update websocket library
#jira UEPLAT-1203 - Add Linux library for libwebsockets
#jira UEPLAT-1204 - Rebuild libwebsockets with SSL
Change 3213939 on 2016/11/29 by Michael.Trepka
Ignore parent widget's geometry scale when showing a popup menu in a separate window
#jira UE-38706
Change 3215583 on 2016/11/30 by Josh.Adams
Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform)
Change 3216345 on 2016/11/30 by Josh.Adams
Better fix for poison proxy fix
Change 3217106 on 2016/12/01 by Michael.Trepka
Fixed a crash caused by an attempt to use FPlayWorldCommands::GlobalPlayWorldActions before it's initialized when showing suppressable warning dialogs in UEditorEngine::UpdateAutoLoadProject()
#jira UE-38816
Change 3217223 on 2016/12/01 by Josh.Adams
- Fixed some TEXT macro warnings that crept in from IWYU changes
Change 3217253 on 2016/12/01 by Dmitry.Rekman
Linux: fix GL crash (UE-17649).
- Making sure all streams are set up. Fix by Cengiz.
Change 3217473 on 2016/12/01 by Daniel.Lamb
Fixed a case when we load a map it might not have it's sublevels loaded because it's not treated like a map.
#test cook run QAGame
Change 3217588 on 2016/12/01 by Peter.Sauerbrei
Pull in IPv6 fix
Change 3217654 on 2016/12/01 by Michael.Trepka
Changed the Mac-specific high DPI code to use system backingScaleFactor only if NSHighResolutionCapable in Info.plist is set to true. This solves the problem with macOS Sierra giving us actual backingScaleFactor values even in low DPI modes.
Change 3217873 on 2016/12/01 by Josh.Adams
- Added some logging to a tvOS assert, since debugging it right away is tricky
Change 3218097 on 2016/12/01 by Josh.Adams
- Fixed up the Switch MediaFramework, making editor better, etc
- ALso changed PS4 and Xbox plugins to be enabled by default by having two entries in the plugin module for the Factory modules (an editor only entry, and a platform specific runtime entry... this will make it so that UE4Game.exe won't ahve it compiled in, even with it enabled by default)
Change 3218133 on 2016/12/01 by Dmitry.Rekman
Linux: report server hangs by crashing the hung thread (UE-39164).
Change 3218512 on 2016/12/01 by Josh.Adams
- Made the MfMedia plugin to be distributable in public builds, since it's for Windows and Xbox
Change 3219804 on 2016/12/02 by Dmitry.Rekman
Linux: fix project settings crash (UE-38800).
- Also submitted as a pull request #2945.
Change 3220027 on 2016/12/02 by Nick.Shin
plow all physx libs into build
NOTE: most browsers will not function
- chrome and firefox nightly only works
checking this in as per email
#jira UE-38323 VehicleTemplate Vehicle does not move in HTML5
Change 3221620 on 2016/12/05 by Joe.Barnes
UE-37275 - Temporary workaround for log lines losing carriage returns. Add's a \n when outputting lines if there isn't one at the end.
Change 3221689 on 2016/12/05 by Dmitry.Rekman
Attempt to change/rename.
Change 3221700 on 2016/12/05 by Dmitry.Rekman
Another attempt to change renamed file (from Linux).
Change 3221731 on 2016/12/05 by Michael.Trepka
Added missing initialization for FAvfVideoSampler::MetalTextureCache
#jira UE-38689
Change 3221792 on 2016/12/05 by Michael.Trepka
Fixed a crash in FMetalDynamicRHI::RHIAsyncReallocateTexture2D for PVRTC2 textures
Change 3222675 on 2016/12/05 by Josh.Adams
- Removed some resolution setting junk that was recently added to PlatformerGame - settings resolution on AppleTV is bad, it doesn't need to change resolution on non-desktop platforms
#jira UE-39188
Change 3223546 on 2016/12/06 by Brent.Pease
+ Properly set and use the realtime compression for ios.
+ Reduce unused memory on ios from the precached first buffer
+ Fix a resource tracking issue that was causing a double free on the sound buffer
Change 3223785 on 2016/12/06 by Brent.Pease
+ Add support for iPhone7 (implemented by peter.sauerbrei, merged in from WEX)
#jira ue-38701
Change 3224314 on 2016/12/06 by Chris.Babcock
Send OnTargetPlatformChangedSupportedFormats when format changed in Android project settings in editor
#jira UE-38361
#ue4
#android
Change 3225367 on 2016/12/07 by Josh.Adams
- Added FKey::Virtual_Accept and Virtual_Back, which will map to FaceButton Right/Down appropriately based on platform (Switch swaps them)
- Made changes to ShooterGame and VehicleGame for Virtual_Accept and Back
- Added some icons for ShooterGame, and changed some text blocks to SRichTextBlock to insert the icons
Change 3225426 on 2016/12/07 by Chris.Babcock
Add missing Android UPL file for binary builds
#jira UE-39420
#ue4
#android
Change 3225471 on 2016/12/07 by Dmitry.Rekman
Update all platforms to C++14.
Change 3225525 on 2016/12/07 by Nick.Shin
Cook-On-The-Fly for HTML5
- re-enabled: ENetworkFileServerProtocol::NFSP_Http
- cleaned up port numbers used with cook-on-the-fly situations
- fixed null_ptr in NetworkFileServerHttp.cpp
- fix CORS issue with HTML5LaunchHelper (not really needed -- but doesn't hurt to have it in the test server)
- finally, the core of the jira issue:
o fix serialization bug: do not append zero sized data
o fix de-serialization bug: removed double insertion of packet "Marker and Size" header
#jira UE-38281 Quicklaunch UFE HTML5 fails to get COTF Header Size
Change 3225690 on 2016/12/07 by Dmitry.Rekman
Linux: improvements in touch support.
- Multiple fingers.
- Filtering out "moved" events from the same location.
- Consistent logging.
(Edigrating 3225194 from Wombat to Dev-Platform)
Change 3225868 on 2016/12/07 by Josh.Stoddard
Gracefully handle delete without matching new on iOS & Mac
#jira UE-39395
Change 3226159 on 2016/12/07 by Omar.Rodriguez
UEPLAT-1423 WEX: Improved virtual keyboard for Android
* Renamed old virtual keyboard functions by adding "Dialog" suffix to the name
* Added new virtual keyboard functions that use InputMethodManager to show/hide keyboard
* Hide the virtual keyboard, if shown, onPause
* Slate edit box decides which functions to call for showing/hiding keyboard
- eventually will be based on command line parameter like in IOS
#jira UEPLAT-1423
Change 3226167 on 2016/12/07 by Dmitry.Rekman
Allow running as root on ARM.
(Edigrating 3204974 to Dev-Platform)
Change 3226168 on 2016/12/07 by Dmitry.Rekman
Print current CVar value when denying an override.
(Based on CL 3205476).
Change 3226169 on 2016/12/07 by Dmitry.Rekman
Allow enabling sound (if disabled by default).
(Based on CL 3205505)
Change 3226171 on 2016/12/07 by Dmitry.Rekman
Allow running from symlinks.
(Edigrating 3205518 to Dev-Platform).
Change 3226174 on 2016/12/07 by Dmitry.Rekman
Linux: do not init SDL audio (we do not use it anyway).
(Based on CL 3205505).
Change 3226327 on 2016/12/07 by Nick.Shin
fix CIS warning
#jira UE-38281 Quicklaunch UFE HTML5 fails to get COTF Header Size
Change 3226506 on 2016/12/08 by Dmitry.Rekman
Fix one more case-sensitive misspelling (UE-39030).
- Submitted as part of PR #2976.
Change 3226542 on 2016/12/08 by Dmitry.Rekman
Linux: fix weirdness with tesselation in GL4 (UE-32865).
- Workaround by CengizT. Proper fix tracked as UE-39489.
Change 3226570 on 2016/12/08 by Dmitry.Rekman
Fix for ar failing due to too long command line (UE-39009).
- Based on PR #2973.
Change 3226575 on 2016/12/08 by Dmitry.Rekman
Add build-essential to dependencies (UE-39053).
- PR #2981 contributed by cpyarger.
Change 3227129 on 2016/12/08 by Josh.Adams
Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform)
Fixed up a deferred GL error as well
Fixed some copyrights of files not in main
Change 3227260 on 2016/12/08 by Omar.Rodriguez
UE-39140 Projects with iCloud are failing provisioning check when code signing.
* Set default value of bEnableCloudKitSupport to False
* Set value of get-task-allow to true only on non-distribution builds
* Only write out the entitlements file if changes have been made
#jira UE-39140
Change 3229312 on 2016/12/09 by Dmitry.Rekman
Fix missing responses (UE-39572).
- Proper implementation of UE-39009.
Change 3230849 on 2016/12/12 by Dmitry.Rekman
Linux: fixed Android packaging (UE-39635).
- Misspelled case; fixed by JohnHenry Carawon.
#jira UE-39635
Change 3231591 on 2016/12/12 by Peter.Sauerbrei
fix for splash screen not being turned off by default
#jira UE-39591
Change 3231880 on 2016/12/12 by Josh.Adams
- Fixing StaticAnalysis warnings, but -enablecodeanalysis stopped working for some reason, and the /Zm thing has hit me really hard, so this is a hopeful checkin for static analysis issues
#jira UE-39680
Change 3232816 on 2016/12/13 by Dmitry.Rekman
Linux: fix for CEF (UE-39682)
- Fix by Cengiz.Terzibas.
Change 3232873 on 2016/12/13 by Josh.Adams
Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform)
Change 3232933 on 2016/12/13 by Josh.Adams
- Missed the files that were needed to fix up after merge from main, but didn';t come from main
Change 3233066 on 2016/12/13 by Ben.Marsh
UBT: Ignore exception if PATH variable contains invalid characters when looking for XGE.
Change 3233512 on 2016/12/13 by Ben.Marsh
Fix static analysis warnings.
[CL 3233813 by Josh Adams in Main branch]
500 lines
14 KiB
C++
500 lines
14 KiB
C++
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "NetworkFileServerHttp.h"
|
|
#include "NetworkFileServerConnection.h"
|
|
#include "NetworkFileSystemLog.h"
|
|
#include "NetworkMessage.h"
|
|
#include "HAL/RunnableThread.h"
|
|
#include "SocketSubsystem.h"
|
|
#include "Misc/Paths.h"
|
|
#include "Misc/FileHelper.h"
|
|
#include "IPAddress.h"
|
|
#include "Serialization/MemoryReader.h"
|
|
|
|
#if ENABLE_HTTP_FOR_NFS
|
|
|
|
class FNetworkFileServerClientConnectionHTTP : public FNetworkFileServerClientConnection
|
|
{
|
|
|
|
public:
|
|
FNetworkFileServerClientConnectionHTTP(const FFileRequestDelegate& InFileRequestDelegate,
|
|
const FRecompileShadersDelegate& InRecompileShadersDelegate, const TArray<ITargetPlatform*>& InActiveTargetPlatforms )
|
|
: FNetworkFileServerClientConnection( InFileRequestDelegate,InRecompileShadersDelegate,InActiveTargetPlatforms)
|
|
{
|
|
}
|
|
|
|
bool SendPayload( TArray<uint8> &Out )
|
|
{
|
|
// Make Boundaries between payloads, add a visual marker for easier debugging.
|
|
|
|
// uint32 Marker = 0xDeadBeef;
|
|
// uint32 Size = Out.Num();
|
|
//
|
|
// OutBuffer.Append((uint8*)&Marker,sizeof(uint32));
|
|
// OutBuffer.Append((uint8*)&Size,sizeof(uint32));
|
|
OutBuffer.Append(Out);
|
|
|
|
return true;
|
|
}
|
|
|
|
private:
|
|
|
|
TArray<uint8>& GetOutBuffer() { return OutBuffer; }
|
|
void ResetBuffer() { OutBuffer.Reset(); }
|
|
|
|
TArray<uint8> OutBuffer;
|
|
|
|
friend class FNetworkFileServerHttp;
|
|
};
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// LibWebsockets specific structs.
|
|
|
|
// a object of this type is associated by libwebsocket to every http session.
|
|
struct PerSessionData
|
|
{
|
|
// data being received.
|
|
TArray<uint8> In;
|
|
// data being sent out.
|
|
TArray<uint8> Out;
|
|
};
|
|
|
|
|
|
// protocol array.
|
|
static struct lws_protocols Protocols[] = {
|
|
/* first protocol must always be HTTP handler */
|
|
{
|
|
"http-only", // name
|
|
FNetworkFileServerHttp::CallBack_HTTP, // callback
|
|
sizeof(PerSessionData), // per_session_data_size
|
|
15 * 1024, // rx_buffer_size
|
|
0, // id
|
|
NULL
|
|
},
|
|
{
|
|
NULL, NULL, 0, 0, 0, NULL /* End of list */
|
|
}
|
|
};
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
FNetworkFileServerHttp::FNetworkFileServerHttp(
|
|
int32 InPort,
|
|
const FFileRequestDelegate* InFileRequestDelegate,
|
|
const FRecompileShadersDelegate* InRecompileShadersDelegate,
|
|
const TArray<ITargetPlatform*>& InActiveTargetPlatforms
|
|
)
|
|
:ActiveTargetPlatforms(InActiveTargetPlatforms)
|
|
,Port(InPort)
|
|
{
|
|
if (Port < 0 )
|
|
{
|
|
Port = DEFAULT_HTTP_FILE_SERVING_PORT;
|
|
}
|
|
|
|
UE_LOG(LogFileServer, Warning, TEXT("Unreal Network Http File Server starting up..."));
|
|
|
|
if (InFileRequestDelegate && InFileRequestDelegate->IsBound())
|
|
{
|
|
FileRequestDelegate = *InFileRequestDelegate;
|
|
}
|
|
|
|
if (InRecompileShadersDelegate && InRecompileShadersDelegate->IsBound())
|
|
{
|
|
RecompileShadersDelegate = *InRecompileShadersDelegate;
|
|
}
|
|
|
|
|
|
StopRequested.Reset();
|
|
Ready.Reset();
|
|
|
|
// spin up the worker thread, this will block till Init has executed on the freshly spinned up thread, Ready will have appropriate value
|
|
// set by the end of this function.
|
|
WorkerThread = FRunnableThread::Create(this,TEXT("FNetworkFileServerHttp"), 8 * 1024, TPri_AboveNormal);
|
|
}
|
|
|
|
|
|
bool FNetworkFileServerHttp::IsItReadyToAcceptConnections(void) const
|
|
{
|
|
return (Ready.GetValue() != 0);
|
|
}
|
|
|
|
#if UE_BUILD_DEBUG
|
|
void lws_debugLog(int level, const char *line)
|
|
{
|
|
UE_LOG(LogFileServer, Warning, TEXT(" LibWebsocket: %s"), ANSI_TO_TCHAR(line));
|
|
}
|
|
#endif
|
|
|
|
bool FNetworkFileServerHttp::Init()
|
|
{
|
|
// setup log level.
|
|
#if UE_BUILD_DEBUG
|
|
lws_set_log_level( LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_DEBUG , lws_debugLog);
|
|
#endif
|
|
|
|
struct lws_context_creation_info Info;
|
|
memset(&Info,0,sizeof(lws_context_creation_info));
|
|
|
|
// look up libwebsockets.h for details.
|
|
Info.port = Port;
|
|
// we listen on all available interfaces.
|
|
Info.iface = NULL;
|
|
// serve only the http protocols.
|
|
Info.protocols = Protocols;
|
|
// no extensions
|
|
Info.extensions = NULL;
|
|
Info.gid = -1;
|
|
Info.uid = -1;
|
|
Info.options = 0;
|
|
// tack on this object.
|
|
Info.user = this;
|
|
|
|
Context = lws_create_context(&Info);
|
|
|
|
Port = Info.port;
|
|
|
|
if (Context == NULL) {
|
|
UE_LOG(LogFileServer, Fatal, TEXT(" Could not create a libwebsocket content for port : %d"), Port);
|
|
return false;
|
|
}
|
|
|
|
Ready.Set(true);
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
FString FNetworkFileServerHttp::GetSupportedProtocol() const
|
|
{
|
|
return FString("http");
|
|
}
|
|
|
|
|
|
bool FNetworkFileServerHttp::GetAddressList(TArray<TSharedPtr<FInternetAddr> >& OutAddresses) const
|
|
{
|
|
// if Init failed, its already too late.
|
|
ensure( Context != nullptr);
|
|
|
|
// we are listening to all local interfaces.
|
|
ISocketSubsystem::Get()->GetLocalAdapterAddresses(OutAddresses);
|
|
// Fix up ports.
|
|
for (int32 AddressIndex = 0; AddressIndex < OutAddresses.Num(); ++AddressIndex)
|
|
{
|
|
OutAddresses[AddressIndex]->SetPort(Port);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
int32 FNetworkFileServerHttp::NumConnections() const
|
|
{
|
|
return RequestHandlers.Num();
|
|
}
|
|
|
|
void FNetworkFileServerHttp::Shutdown()
|
|
{
|
|
// Allow multiple calls to this function.
|
|
if ( WorkerThread )
|
|
{
|
|
WorkerThread->Kill(true); // Kill Nicely. Wait for everything to shutdown.
|
|
delete WorkerThread;
|
|
WorkerThread = NULL;
|
|
}
|
|
}
|
|
|
|
uint32 FNetworkFileServerHttp::Run()
|
|
{
|
|
UE_LOG(LogFileServer, Display, TEXT("Unreal Network File Http Server is ready for client connections on port %d"), Port);
|
|
|
|
// start servicing.
|
|
|
|
// service libwebsocket context.
|
|
while(!StopRequested.GetValue())
|
|
{
|
|
// service libwebsocket, have a slight delay so it doesn't spin on zero load.
|
|
lws_service(Context, 10);
|
|
lws_callback_on_writable_all_protocol(Context, &Protocols[0]);
|
|
}
|
|
|
|
UE_LOG(LogFileServer, Display, TEXT("Unreal Network File Http Server is now Shutting down "));
|
|
return true;
|
|
}
|
|
|
|
// Called internally by FRunnableThread::Kill.
|
|
void FNetworkFileServerHttp::Stop()
|
|
{
|
|
StopRequested.Set(true);
|
|
}
|
|
|
|
void FNetworkFileServerHttp::Exit()
|
|
{
|
|
// let's start shutting down.
|
|
// fires a LWS_CALLBACK_PROTOCOL_DESTROY callback, we clean up after ourselves there.
|
|
lws_context_destroy(Context);
|
|
Context = NULL;
|
|
}
|
|
|
|
FNetworkFileServerHttp::~FNetworkFileServerHttp()
|
|
{
|
|
Shutdown();
|
|
// delete our request handlers.
|
|
for ( auto& Element : RequestHandlers)
|
|
{
|
|
delete Element.Value;
|
|
}
|
|
// make sure context has been already cleaned up.
|
|
check( Context == NULL );
|
|
}
|
|
|
|
FNetworkFileServerClientConnectionHTTP* FNetworkFileServerHttp::CreateNewConnection()
|
|
{
|
|
return new FNetworkFileServerClientConnectionHTTP(FileRequestDelegate,RecompileShadersDelegate,ActiveTargetPlatforms);
|
|
}
|
|
|
|
// Have a similar process function for the normal tcp connection.
|
|
void FNetworkFileServerHttp::Process(FArchive& In, TArray<uint8>&Out, FNetworkFileServerHttp* Server)
|
|
{
|
|
int loops = 0;
|
|
while(!In.AtEnd())
|
|
{
|
|
UE_LOG(LogFileServer, Log, TEXT("In %d "), loops++);
|
|
// Every Request has a Guid attached to it - similar to Web session IDs.
|
|
FGuid ClientGuid;
|
|
In << ClientGuid;
|
|
|
|
UE_LOG(LogFileServer, Log, TEXT("Recieved GUID %s"), *ClientGuid.ToString());
|
|
|
|
FNetworkFileServerClientConnectionHTTP* Connection = NULL;
|
|
if (Server->RequestHandlers.Contains(ClientGuid))
|
|
{
|
|
UE_LOG(LogFileServer, Log, TEXT("Picking up an existing handler" ));
|
|
Connection = Server->RequestHandlers[ClientGuid];
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogFileServer, Log, TEXT("Creating a handler" ));
|
|
Connection = Server->CreateNewConnection();
|
|
Server->RequestHandlers.Add(ClientGuid,Connection);
|
|
}
|
|
|
|
Connection->ProcessPayload(In);
|
|
Out.Append(Connection->GetOutBuffer());
|
|
Connection->ResetBuffer();
|
|
}
|
|
}
|
|
|
|
// This static function handles all callbacks coming in and when context is services via lws_service
|
|
// return value of -1, closes the connection.
|
|
int FNetworkFileServerHttp::CallBack_HTTP(
|
|
struct lws *Wsi,
|
|
enum lws_callback_reasons Reason,
|
|
void *User,
|
|
void *In,
|
|
size_t Len)
|
|
{
|
|
struct lws_context *Context = lws_get_context(Wsi);
|
|
PerSessionData* BufferInfo = (PerSessionData*)User;
|
|
FNetworkFileServerHttp* Server = (FNetworkFileServerHttp*)lws_context_user(Context);
|
|
|
|
switch (Reason)
|
|
{
|
|
|
|
case LWS_CALLBACK_HTTP:
|
|
|
|
// hang on to socket even if there's no data for atleast 60 secs.
|
|
lws_set_timeout(Wsi, NO_PENDING_TIMEOUT, 60);
|
|
|
|
/* if it was not legal POST URL, let it continue and accept data */
|
|
if (!lws_hdr_total_length(Wsi, WSI_TOKEN_POST_URI))
|
|
{
|
|
char *requested_uri = (char *) In;
|
|
|
|
// client request the base page. e.g http://unrealfileserver:port/
|
|
// just return a banner, probably add some more information, e,g Version, Config, Game. etc.
|
|
if ( FCString::Strcmp(ANSI_TO_TCHAR(requested_uri), TEXT("/")) == 0 )
|
|
{
|
|
TCHAR Buffer[1024];
|
|
TCHAR ServerBanner[] = TEXT("<HTML>This is Unreal File Server</HTML>");
|
|
int x = FCString::Sprintf(
|
|
Buffer,
|
|
TEXT("HTTP/1.0 200 OK\x0d\x0a")
|
|
TEXT("Server: Unreal File Server\x0d\x0a")
|
|
TEXT("Connection: close\x0d\x0a")
|
|
TEXT("Content-Type: text/html; charset=utf-8\x0d\x0a")
|
|
TEXT("Content-Length: %u\x0d\x0a\x0d\x0a%s"),
|
|
FCString::Strlen(ServerBanner),
|
|
ServerBanner
|
|
);
|
|
|
|
// very small data being sent, its fine to just send.
|
|
lws_write(Wsi,(unsigned char*)TCHAR_TO_ANSI(Buffer),FCStringAnsi::Strlen(TCHAR_TO_ANSI(Buffer)), LWS_WRITE_HTTP);
|
|
}
|
|
else
|
|
{
|
|
// client has asked for a file. ( only html/js files are served.)
|
|
|
|
// what type is being served.
|
|
FString FilePath = FPaths::GameDir() / TEXT("Binaries/HTML5") + FString((ANSICHAR*)In);
|
|
TCHAR Mime[512];
|
|
|
|
|
|
if ( FilePath.Contains(".js"))
|
|
{
|
|
FCStringWide::Strcpy(Mime,TEXT("application/javascript;charset=UTF-8"));
|
|
}
|
|
else
|
|
{
|
|
FCStringWide::Strcpy(Mime,TEXT("text/html;charset=UTF-8"));
|
|
}
|
|
|
|
UE_LOG(LogFileServer, Warning, TEXT("HTTP Serving file %s with mime %s "), *FilePath, (Mime));
|
|
|
|
FString AbsoluteFilePath = FPaths::ConvertRelativePathToFull(FilePath);
|
|
AbsoluteFilePath.ReplaceInline(TEXT("/"),TEXT("\\"));
|
|
|
|
// we are going to read the complete file in memory and then serve it in batches.
|
|
// rather than reading and sending in batches because Unreal NFS servers are not running in memory
|
|
// constrained env and the added complexity is not worth it.
|
|
|
|
|
|
TArray<uint8> FileData;
|
|
FFileHelper::LoadFileToArray(FileData, *AbsoluteFilePath, FILEREAD_Silent);
|
|
|
|
if (FileData.Num() == 0)
|
|
{
|
|
// umm. we didn't find file, we should tell the client that we couldn't find it.
|
|
// send 404.
|
|
char Header[]= "HTTP/1.1 404 Not Found\x0d\x0a"
|
|
"Server: Unreal File Server\x0d\x0a"
|
|
"Connection: close\x0d\x0a";
|
|
|
|
lws_write(Wsi,(unsigned char*)Header,FCStringAnsi::Strlen(Header), LWS_WRITE_HTTP);
|
|
// chug along, client will close the connection.
|
|
break;
|
|
}
|
|
|
|
// file up the header.
|
|
TCHAR Header[1024];
|
|
int Length = 0;
|
|
if (FilePath.Contains("gz"))
|
|
{
|
|
Length = FCString::Sprintf(Header,
|
|
TEXT("HTTP/1.1 200 OK\x0d\x0a")
|
|
TEXT("Server: Unreal File Server\x0d\x0a")
|
|
TEXT("Connection: close\x0d\x0a")
|
|
TEXT("Content-Type: %s \x0d\x0a")
|
|
TEXT("Content-Encoding: gzip\x0d\x0a")
|
|
TEXT("Content-Length: %u\x0d\x0a\x0d\x0a"),
|
|
Mime, FileData.Num());
|
|
}
|
|
else
|
|
{
|
|
Length = FCString::Sprintf(Header,
|
|
TEXT("HTTP/1.1 200 OK\x0d\x0a")
|
|
TEXT("Server: Unreal File Server\x0d\x0a")
|
|
TEXT("Connection: close\x0d\x0a")
|
|
TEXT("Content-Type: %s \x0d\x0a")
|
|
TEXT("Content-Length: %u\x0d\x0a\x0d\x0a"),
|
|
Mime, FileData.Num());
|
|
}
|
|
|
|
// make space for the whole file in our out buffer.
|
|
BufferInfo->Out.Append((uint8*)TCHAR_TO_ANSI(Header),Length);
|
|
BufferInfo->Out.Append(FileData);
|
|
// we need to write back to the client, queue up a write callback.
|
|
lws_callback_on_writable(Wsi);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// we got a post request!, queue up a write callback.
|
|
lws_callback_on_writable(Wsi);
|
|
}
|
|
|
|
break;
|
|
case LWS_CALLBACK_HTTP_BODY:
|
|
{
|
|
// post data is coming in, push it on to our incoming buffer.
|
|
UE_LOG(LogFileServer, Log, TEXT("Incoming HTTP Partial Body Size %d, total size %d"),Len, Len+ BufferInfo->In.Num());
|
|
BufferInfo->In.Append((uint8*)In,Len);
|
|
// we received some data - update time out.
|
|
lws_set_timeout(Wsi, NO_PENDING_TIMEOUT, 60);
|
|
}
|
|
break;
|
|
case LWS_CALLBACK_HTTP_BODY_COMPLETION:
|
|
{
|
|
// we have all the post data from the client.
|
|
// create archives and process them.
|
|
UE_LOG(LogFileServer, Log, TEXT("Incoming HTTP total size %d"), BufferInfo->In.Num());
|
|
FMemoryReader Reader(BufferInfo->In);
|
|
TArray<uint8> Writer;
|
|
|
|
FNetworkFileServerHttp::Process(Reader,Writer,Server);
|
|
|
|
// even if we have 0 data to push, tell the client that we don't any data.
|
|
ANSICHAR Header[1024];
|
|
int Length = FCStringAnsi::Sprintf(
|
|
(ANSICHAR*)Header,
|
|
"HTTP/1.1 200 OK\x0d\x0a"
|
|
"Server: Unreal File Server\x0d\x0a"
|
|
"Connection: close\x0d\x0a"
|
|
"Content-Type: application/octet-stream \x0d\x0a"
|
|
"Content-Length: %u\x0d\x0a\x0d\x0a",
|
|
Writer.Num()
|
|
);
|
|
|
|
// Add Http Header
|
|
BufferInfo->Out.Append((uint8*)Header,Length);
|
|
// Add Binary Data.
|
|
BufferInfo->Out.Append(Writer);
|
|
|
|
// we have enqueued data increase timeout and push a writable callback.
|
|
lws_set_timeout(Wsi, NO_PENDING_TIMEOUT, 60);
|
|
lws_callback_on_writable(Wsi);
|
|
|
|
}
|
|
break;
|
|
case LWS_CALLBACK_CLOSED_HTTP:
|
|
|
|
if ( BufferInfo == NULL )
|
|
break;
|
|
|
|
// client went away or
|
|
//clean up.
|
|
BufferInfo->In.Empty();
|
|
BufferInfo->Out.Empty();
|
|
|
|
break;
|
|
|
|
case LWS_CALLBACK_PROTOCOL_DESTROY:
|
|
// we are going away.
|
|
|
|
break;
|
|
|
|
case LWS_CALLBACK_HTTP_WRITEABLE:
|
|
|
|
// get rid of superfluous write callbacks.
|
|
if ( BufferInfo == NULL )
|
|
break;
|
|
|
|
// we have data o send out.
|
|
if (BufferInfo->Out.Num())
|
|
{
|
|
int SentSize = lws_write(Wsi,(unsigned char*)BufferInfo->Out.GetData(),BufferInfo->Out.Num(), LWS_WRITE_HTTP);
|
|
// get rid of the data that has been sent.
|
|
BufferInfo->Out.RemoveAt(0,SentSize);
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
#endif
|