/** * Write out the steam app id to the steam_appid.txt file before initializing the API * @param SteamAppId id assigned to the application by Steam */ static void WriteSteamAppIdToDisk(int32 SteamAppId) { if (SteamAppId > 0) { // Turn off sandbox temporarily to make sure file is where it's always expected FScopeSandboxContext ScopedSandbox(false); // Access the physical file writer directly so that we still write next to the executable in CotF builds. FString SteamAppIdFilename = GetSteamAppIdFilename(); IFileHandle* Handle = IPlatformFile::GetPlatformPhysical().OpenWrite(*SteamAppIdFilename, false, false); if (!Handle) { UE_LOG_ONLINE(Fatal, TEXT("Failed to create file: %s"), *SteamAppIdFilename); } else { FString AppId = FString::Printf(TEXT("%d"), SteamAppId); FBufferArchive Archive; Archive.Serialize((void*)TCHAR_TO_ANSI(*AppId), AppId.Len()); Handle->Write(Archive.GetData(), Archive.Num()); delete Handle; Handle = nullptr; } } }
bool FNFSMessageHeader::WrapAndSendPayload(const TArray<uint8>& Payload, const FSimpleAbstractSocket& Socket) { // make a header for the payload FNFSMessageHeader Header(Socket, Payload); // serialize out the header FBufferArchive Ar; Ar << Header; // append the payload bytes to send it in one network packet Ar.Append(Payload); // Send it, and make sure it sent it all if (!Socket.Send(Ar.GetData(), Ar.Num())) { UE_LOG(LogSockets, Error, TEXT("Unable to send.")); return false; } return true; }
FString& UCreatureAnimationAsset::GetJsonString() { // Decompress only when needed if (CreatureFileJSonData.IsEmpty()) { FArchiveLoadCompressedProxy Decompressor = FArchiveLoadCompressedProxy(CreatureZipBinary, ECompressionFlags::COMPRESS_ZLIB); if (Decompressor.IsError() || (CreatureZipBinary.Num() == 0)) { UE_LOG(LogTemp, Warning, TEXT("UCreatureAnimationAsset::Could not uncompress data")); return CreatureFileJSonData; } FBufferArchive DecompressedBinaryArray; Decompressor << DecompressedBinaryArray; CreatureFileJSonData = UTF8_TO_TCHAR((char *)DecompressedBinaryArray.GetData()); } return CreatureFileJSonData; }
bool FSocketMessageHeader::WrapAndSendPayload(const TArray<uint8>& Payload, FSocket* Socket) { FSocketMessageHeader Header(Payload); FBufferArchive Ar; Ar << Header.Magic; Ar << Header.PayloadSize; Ar.Append(Payload); int32 TotalAmountSent = 0; // How many bytes have been sent int32 AmountToSend = Ar.Num(); int NumTrial = 100; // Only try a limited amount of times // int ChunkSize = 4096; while (AmountToSend > 0) { int AmountSent = 0; // GetData returns a uint8 pointer Socket->Send(Ar.GetData() + TotalAmountSent, Ar.Num() - TotalAmountSent, AmountSent); NumTrial--; if (AmountSent == -1) { continue; } if (NumTrial < 0) { UE_LOG(LogUnrealCV, Error, TEXT("Unable to send. Expect to send %d, sent %d"), Ar.Num(), TotalAmountSent); return false; } UE_LOG(LogUnrealCV, Verbose, TEXT("Sending bytes %d/%d, sent %d"), TotalAmountSent, Ar.Num(), AmountSent); AmountToSend -= AmountSent; TotalAmountSent += AmountSent; } check(AmountToSend == 0); return true; }
bool FHTTPTransport::SendPayloadAndReceiveResponse(TArray<uint8>& In, TArray<uint8>& Out) { RecieveBuffer.Empty(); ReadPtr = 0; #if !PLATFORM_HTML5 if (GIsRequestingExit) // We have already lost HTTP Module. return false; class HTTPRequestHandler { public: HTTPRequestHandler(TArray<uint8>& InOut) :Out(InOut) {} void HttpRequestComplete( FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded) { if (HttpResponse.IsValid()) Out.Append(HttpResponse->GetContent()); } private: TArray<uint8>& Out; }; HTTPRequestHandler Handler(RecieveBuffer); HttpRequest->OnProcessRequestComplete().BindRaw(&Handler,&HTTPRequestHandler::HttpRequestComplete ); if ( In.Num() ) { HttpRequest->SetVerb("POST"); FBufferArchive Ar; Ar << Guid; Ar.Append(In); HttpRequest->SetContent(Ar); } else { HttpRequest->SetVerb("GET"); } HttpRequest->ProcessRequest(); FDateTime StartTime; FTimespan Span = FDateTime::UtcNow() - StartTime; while( HttpRequest->GetStatus() != EHttpRequestStatus::Failed && HttpRequest->GetStatus() != EHttpRequestStatus::Succeeded && Span.GetSeconds() < 10 ) { HttpRequest->Tick(0); Span = FDateTime::UtcNow() - StartTime; } if (HttpRequest->GetStatus() == EHttpRequestStatus::Succeeded) return true; HttpRequest->CancelRequest(); return false; #else // PLATFORM_HTML5 FBufferArchive Ar; if ( In.Num() ) { Ar << Guid; } Ar.Append(In); unsigned char *OutData = NULL; unsigned int OutSize= 0; bool RetVal = true; #if PLATFORM_HTML5_WIN32 RetVal = HTML5Win32::NFSHttp::SendPayLoadAndRecieve(Ar.GetData(), Ar.Num(), &OutData, OutSize); #endif #if PLATFORM_HTML5_BROWSER UE_SendAndRecievePayLoad(TCHAR_TO_ANSI(Url),(char*)Ar.GetData(),Ar.Num(),(char**)&OutData,(int*)&OutSize); #endif if (!Ar.Num()) { uint32 Size = OutSize; uint32 Marker = 0xDeadBeef; RecieveBuffer.Append((uint8*)&Marker,sizeof(uint32)); RecieveBuffer.Append((uint8*)&Size,sizeof(uint32)); } if (OutSize) { RecieveBuffer.Append(OutData,OutSize); #if PLATFORM_HTML5_WIN32 free (OutData); #endif #if PLATFORM_HTML5_BROWSER // don't go through the Unreal Memory system. ::free(OutData); #endif } return RetVal & ReceiveResponse(Out); #endif }