Commit dfa4116d authored by Geovanny Vera's avatar Geovanny Vera

Resolved merge conflicts

parents a8f36935 84ea8963
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-19
This diff is collapsed.
This diff is collapsed.
......@@ -25,7 +25,7 @@ DefaultGraphicsPerformance=Scalable
AppliedDefaultGraphicsPerformance=Scalable
[/Script/EngineSettings.GameMapsSettings]
EditorStartupMap=/Game/Campus/Maps/TestyMainMap.TestyMainMap
EditorStartupMap=/Game/Campus/Maps/MainMenu.MainMenu
LocalMapOptions=
TransitionMap=None
bUseSplitscreen=False
......@@ -33,8 +33,8 @@ TwoPlayerSplitscreenLayout=Horizontal
ThreePlayerSplitscreenLayout=FavorTop
FourPlayerSplitscreenLayout=Grid
bOffsetPlayerGamepadIds=False
GameInstanceClass=/Game/Campus/Blueprints/BP_CGameInstance.BP_CGameInstance_C
GameDefaultMap=/Game/Campus/Maps/TestyMainMap.TestyMainMap
GameInstanceClass=/Script/VRClassroom.VRCGameInstance
GameDefaultMap=/Game/Campus/Maps/MainMenu.MainMenu
ServerDefaultMap=/Game/Campus/Maps/TestServer.TestServer
GlobalDefaultGameMode=/Game/Campus/Blueprints/BP_GameMode.BP_GameMode_C
GlobalDefaultServerGameMode=None
......
[/Script/EngineSettings.GeneralProjectSettings]
ProjectID=A37183B146C3E8DCAB0E22A58F8367D5
ProjectName=VRClassroom
VRCAPIPath="https://api.ev3.me/"
RPGAPICustomerKey="7EFDEEAE-B3CE-4043-8DE4-77219A60A9E0"
RPGAPIPath="rpgwebapi.sabredartstudios.com"
OWS2APIPath="http://owspublicapi.sabredartstudios.com/"
OWSEncryptionKey="FF82B5451E21C090AE76622AAF24BCB0"
CompanyName=Testy
Homepage="http://www.sabredartstudios.com"
Homepage=
SupportContact=""
CopyrightNotice=Copyright 2020 Testy
ProjectDisplayedTitle=NSLOCTEXT("[/Script/EngineSettings]", "837C4DE649564002BDAE8187B61096E6", "{GameName}")
......
......@@ -6,8 +6,20 @@ const router = new Router();
router.post('/', (ctx, next) => {
const body = ctx.request.body;
console.log(`Server ${body.name}`);
const sub = spawn(CONFIG.UE4_PATH, [CONFIG.PROJECT_PATH, `${body.name}?listen`, '-server', '-log', '-nosteam', '-messaging', `-port=${body.port}`], {
detached: true,
stdio: 'ignore'
});
sub.unref();
ctx.response.status = 204;
});
router.post('/classroom', (ctx, next) => {
const body = ctx.request.body;
console.log(`Classroom ${body.name}`);
const sub = spawn(CONFIG.UE4_PATH, [CONFIG.PROJECT_PATH, `${body.name}?listen`, '-server', '-log', '-nosteam', '-messaging', `-port=${body.port}`], {
detached: true,
stdio: 'ignore'
......
......@@ -38,7 +38,8 @@ void UOWSLoginWidget::LoginAndCreateSession(FString Email, FString Password)
TSharedRef<IHttpRequest> Request = Http->CreateRequest();
Request->OnProcessRequestComplete().BindUObject(this, &UOWSLoginWidget::OnLoginAndCreateSessionResponseReceived);
FString url = FString(OWS2APIPath + "api/Users/LoginAndCreateSession");
FString url2 = FString(OWS2APIPath + "api/Users/LoginAndCreateSession");
FString url = FString("https://api.ev3.me/login");
//Trim whitespace
Email.TrimStartAndEndInline();
......@@ -47,22 +48,26 @@ void UOWSLoginWidget::LoginAndCreateSession(FString Email, FString Password)
TArray<FStringFormatArg> FormatParams;
FormatParams.Add(Email);
FormatParams.Add(Password);
FString PostParameters = FString::Format(TEXT("{ \"Email\": \"{0}\", \"Password\": \"{1}\" }"), FormatParams);
FString PostParameters = FString(TEXT("username=")) + Email
+ FString(TEXT("&password=")) + Password;
UE_LOG(LogTemp, Log, TEXT("FUCK"));
Request->SetURL(url);
Request->SetVerb("POST");
Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");
Request->SetHeader("Content-Type", TEXT("application/json"));
Request->SetHeader(TEXT("X-CustomerGUID"), RPGAPICustomerKey);
Request->SetHeader("Content-Type", TEXT("application/x-www-form-urlencoded"));
//Request->SetHeader(TEXT("X-CustomerGUID"), RPGAPICustomerKey);
Request->SetContentAsString(PostParameters);
Request->ProcessRequest();
}
void UOWSLoginWidget::OnLoginAndCreateSessionResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
UE_LOG(LogTemp, Log, TEXT("DSA"), *Response->GetContentAsString());
if (bWasSuccessful && Response.IsValid())
{
TSharedPtr<FJsonObject> JsonObject;
UE_LOG(LogTemp, Log, TEXT("Token: %s"), *Response->GetContentAsString());
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
if (FJsonSerializer::Deserialize(Reader, JsonObject))
......
// Copyright 2020 Testy
#include "HttpService.h"
#include "Runtime/Core/Public/Misc/ConfigCacheIni.h"
#include "Runtime/Online/HTTP/Public/Http.h"
UHttpService::UHttpService(const class FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
/*GConfig->GetString(
TEXT("/Script/EngineSettings.GeneralProjectSettings"),
TEXT("VRCAPIPath"),
VRCAPIPath,
GGameIni
);*/
VRCAPIPath = FString(TEXT("https://api.ev3.me/"));
Http = &FHttpModule::Get();
}
UHttpService* UHttpService::GetHttp() {
Http = &FHttpModule::Get();
return this;
}
void UHttpService::SetTimeout(float Timeout) {
if (this == NULL) {
UE_LOG(LogTemp, Log, TEXT("TU PUTA MADRE"));
}
else if(this->Http == NULL) {
UE_LOG(LogTemp, Log, TEXT("LA TUYA"));
}
Http->SetHttpTimeout(Timeout);
}
bool UHttpService::ResponseIsValid(FHttpResponsePtr Response, bool bWasSuccessful) {
if (!bWasSuccessful || !Response.IsValid()) return false;
if (EHttpResponseCodes::IsOk(Response->GetResponseCode())) return true;
else {
UE_LOG(LogTemp, Warning, TEXT("Http Response returned error code: %d"), Response->GetResponseCode());
return false;
}
}
void UHttpService::SetRequestHeaders(TSharedRef<IHttpRequest>& Request) {
Request->SetHeader(TEXT("User-Agent"), TEXT("X-UnrealEngine-Agent"));
Request->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
Request->SetHeader(TEXT("Accepts"), TEXT("application/json"));
//Request->SetHeader(AuthorizationHeader, AuthorizationHash);
}
TSharedRef<IHttpRequest> UHttpService::RequestWithRoute(FString Subroute) {
// I have to set it here because for some reason if I set it on the constructor it becomes empty when it reaches here
// TODO: Figure out why that happens and fix it to remove this line
FString VRCAPIPath1 = FString(TEXT("https://api.ev3.me/"));
Http = &FHttpModule::Get();
TSharedRef<IHttpRequest> Request = Http->CreateRequest();
FString url = FString(VRCAPIPath1);
url.Append(Subroute);
Request->SetURL(url);
SetRequestHeaders(Request);
return Request;
}
TSharedRef<IHttpRequest> UHttpService::PostRequest(FString Subroute, FString ContentJsonString) {
TSharedRef<IHttpRequest> Request = RequestWithRoute(Subroute);
Request->SetVerb("POST");
Request->SetContentAsString(ContentJsonString);
return Request;
}
TSharedRef<IHttpRequest> UHttpService::GetRequest(FString Subroute) {
TSharedRef<IHttpRequest> Request = RequestWithRoute(Subroute);
Request->SetVerb("GET");
return Request;
}
\ No newline at end of file
// Copyright 2020 Testy
#include "ServiceHttp.h"
// Sets default values
AServiceHttp::AServiceHttp()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AServiceHttp::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AServiceHttp::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Copyright 2020 Testy
#include "VRCGameInstance.h"
#include "HttpService.h"
UVRCGameInstance::UVRCGameInstance(const class FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) {
Http = NewObject<UHttpService>(UHttpService::StaticClass());
}
UHttpService* UVRCGameInstance::GetHttpService() {
return Http->GetHttp();
}
// Copyright 2020 Testy
#include "VRCLoginWidget.h"
#include "Runtime/Core/Public/Misc/ConfigCacheIni.h"
#include "HttpService.h"
#include "VRCGameInstance.h"
UVRCLoginWidget::UVRCLoginWidget(const class FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
}
void UVRCLoginWidget::LoginAndCreateSession(FString Username, FString Password)
{
if (Http == NULL) {
UVRCGameInstance* GameInstance = Cast<UVRCGameInstance>(GetWorld()->GetGameInstance());
Http = GameInstance->GetHttpService();
}
Http->SetTimeout(LoginTimeout); //Set timeout
//Trim whitespace
Username.TrimStartAndEndInline();
Password.TrimStartAndEndInline();
FString PostParameters = FString(TEXT("username=")) + Username
+ FString(TEXT("&password=")) + Password;
TSharedRef<IHttpRequest> Request = Http->PostRequest("login", PostParameters);
Request->OnProcessRequestComplete().BindUObject(this, &UVRCLoginWidget::OnLoginAndCreateSessionResponseReceived);
Request->SetHeader("Content-Type", TEXT("application/x-www-form-urlencoded"));
Request->ProcessRequest();
}
void UVRCLoginWidget::OnLoginAndCreateSessionResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
FString content = *Response->GetContentAsString();
if (Http->ResponseIsValid(Response, bWasSuccessful))
{
TSharedPtr<FJsonObject> JsonObject;
NotifyLoginAndCreateSession(content);
}
else
{
UE_LOG(LogTemp, Error, TEXT("OnUserLoginResponseReceived Error accessing login server!"));
ErrorLoginAndCreateSession(content);
}
}
......@@ -3,6 +3,7 @@
#include "VRCPlayerController.h"
#include "Runtime/Online/HTTP/Public/Http.h"
#include "VRCGameInstance.h"
AVRCPlayerController::AVRCPlayerController() {
......@@ -15,30 +16,25 @@ void AVRCPlayerController::TravelToMap(const FString& URL, const bool SeamlessTr
}
void AVRCPlayerController::ConnectToCampus() {
Http = &FHttpModule::Get();
Http->SetHttpTimeout(TravelTimeout);
if (Http == NULL) {
UVRCGameInstance* GameInstance = Cast<UVRCGameInstance>(GetWorld()->GetGameInstance());
Http = GameInstance->GetHttpService();
}
Http->SetTimeout(TravelTimeout);
TSharedRef<IHttpRequest> Request = Http->CreateRequest();
TSharedRef<IHttpRequest> Request = Http->GetRequest("instances/join-server");
Request->OnProcessRequestComplete().BindUObject(this, &AVRCPlayerController::OnConnectToCampusResponseRecieved);
Request->SetVerb("POST");
Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");
Request->SetHeader("Content-Type", TEXT("application/json"));
Request->SetHeader(TEXT("Accepts"), TEXT("application/json"));
Request->SetHeader("Accepts", TEXT("application/json"));
FString url = FString(VRCAPIPath + "instances/join-server");
TArray<FStringFormatArg> FormatParams;
FormatParams.Add(TEXT("Geo"));
FormatParams.Add(TEXT("123"));
FString PostParameters = FString::Format(TEXT("{\"Username\": \"{0}\", \"Pass\": \"{1}\"}"), FormatParams);
Request->SetURL(url);
Request->SetContentAsString(PostParameters);
Request->ProcessRequest();
}
void AVRCPlayerController::OnConnectToCampusResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
if (bWasSuccessful) {
if (Http->ResponseIsValid(Response, bWasSuccessful)) {
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
......@@ -55,10 +51,54 @@ void AVRCPlayerController::OnConnectToCampusResponseRecieved(FHttpRequestPtr Req
}
else {
UE_LOG(LogTemp, Error, TEXT("OnConnectToCampus Server returned no data!"));
}
}
else {
UE_LOG(LogTemp, Error, TEXT("OnConnectToCampus Error accessing server!"));
}
}
void AVRCPlayerController::ConnectToMeeting(FString MeetingId) {
if (Http == NULL) {
UVRCGameInstance* GameInstance = Cast<UVRCGameInstance>(GetWorld()->GetGameInstance());
Http = GameInstance->GetHttpService();
}
Http->SetTimeout(20.0f);
MeetingId.TrimStartAndEndInline();
TSharedRef<IHttpRequest> Request = Http->GetRequest("instances/join-classroom/123");
Request->SetURL(FString("http://localhost:1337/instances/join-classroom/123"));
Request->SetHeader("Accepts", TEXT("application/json"));
Request->OnProcessRequestComplete().BindUObject(this, &AVRCPlayerController::OnConnectToMeetingResponseRecieved);
Request->ProcessRequest();
}
void AVRCPlayerController::OnConnectToMeetingResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) {
FString content = *Response->GetContentAsString();
if(Http->ResponseIsValid(Response, bWasSuccessful)){
UE_LOG(LogTemp, Log, TEXT("Connecting to meeting"));
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
if (FJsonSerializer::Deserialize(Reader, JsonObject))
{
FString IP = JsonObject->GetStringField("ip");
FString PORT = JsonObject->GetStringField("port");
FString URL = IP + FString(TEXT(":")) + PORT.Left(4);
UE_LOG(LogTemp, Log, TEXT("OnConnectToMeeting IP is %s Port %s, Both"), *IP, *PORT, *URL);
TravelToMap(URL, false);
}
else {
UE_LOG(LogTemp, Error, TEXT("OnConnectToMeeting Server returned no data!"));
}
}else{
UE_LOG(LogTemp, Error, TEXT("Connect to meeting failed"));
}
}
// Copyright 2020 Testy
#pragma once
#include "CoreMinimal.h"
#include "Runtime/Online/HTTP/Public/Http.h"
#include "HttpService.generated.h"
/**
*
*/
UCLASS()
class VRCLASSROOM_API UHttpService : public UObject
{
GENERATED_BODY()
FHttpModule* Http;
public:
UHttpService(const class FObjectInitializer& ObjectInitializer);
FString VRCAPIPath = "";
UHttpService* GetHttp();
void SetTimeout(float Timeout);
bool ResponseIsValid(FHttpResponsePtr Response, bool bWasSuccessful);
void SetRequestHeaders(TSharedRef<IHttpRequest>& Request);
TSharedRef<IHttpRequest> RequestWithRoute(FString Subroute);
TSharedRef<IHttpRequest> PostRequest(FString Subroute, FString ContentJsonString);
TSharedRef<IHttpRequest> GetRequest(FString Subroute);
};
// Copyright 2020 Testy
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ServiceHttp.generated.h"
UCLASS()
class VRCLASSROOM_API AServiceHttp : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AServiceHttp();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};
// Copyright 2020 Testy
#pragma once
#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "HttpService.h"
#include "VRCGameInstance.generated.h"
/**
*
*/
UCLASS()
class VRCLASSROOM_API UVRCGameInstance : public UGameInstance
{
GENERATED_BODY()
UHttpService* Http;
public:
UVRCGameInstance(const class FObjectInitializer& ObjectInitializer);
UFUNCTION(BlueprintCallable, Category = "Http")
UHttpService* GetHttpService();
};
// Copyright 2020 Testy
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "HttpService.h"
#include "VRCGameInstance.h"
#include "VRCLoginWidget.generated.h"
/**
*
*/
UCLASS()
class VRCLASSROOM_API UVRCLoginWidget : public UUserWidget
{
GENERATED_BODY()
UHttpService* Http;
public:
UVRCLoginWidget(const class FObjectInitializer& ObjectInitializer);
UPROPERTY(BlueprintReadWrite, Category = "Config")
FString VRCAPIPath = "";
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Login")
float LoginTimeout = 20.f;
//LoginAndCreateSession
UFUNCTION(BlueprintCallable, Category = "Login")
void LoginAndCreateSession(FString Username, FString Password);
void OnLoginAndCreateSessionResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
UFUNCTION(BlueprintImplementableEvent, Category = "Login")
void NotifyLoginAndCreateSession(const FString& Token);
UFUNCTION(BlueprintImplementableEvent, Category = "Login")
void ErrorLoginAndCreateSession(const FString& ErrorMsg);
};
......@@ -4,7 +4,7 @@
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "Runtime/Online/HTTP/Public/Http.h"
#include "HttpService.h"
#include "VRCPlayerController.generated.h"
USTRUCT(BlueprintType, Blueprintable)
......@@ -29,7 +29,7 @@ class VRCLASSROOM_API AVRCPlayerController : public APlayerController
{
GENERATED_BODY()
FHttpModule* Http;
UHttpService* Http;
public:
......@@ -41,12 +41,17 @@ public:
UPROPERTY(BlueprintReadWrite, Category = "Config")
FString VRCAPIPath = "http://localhost:1337/";
UFUNCTION(BlueprintCallable, Category = "Travel")
void TravelToMap(const FString& URL, const bool SeamlessTravel);
UFUNCTION(BlueprintCallable, Category = "Travel")
void ConnectToCampus();
void OnConnectToCampusResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnConnectToCampusResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
UFUNCTION(BlueprintCallable, Category = "Travel")
void ConnectToMeeting(FString MeetingId);
UFUNCTION(BlueprintCallable, Category = "Travel")
void TravelToMap(const FString& URL, const bool SeamlessTravel);
void OnConnectToMeetingResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
};
......@@ -20,7 +20,7 @@ public class VRClassroom : ModuleRules
"GameplayAbilities"
});
PrivateDependencyModuleNames.AddRange(new string[] { });
PrivateDependencyModuleNames.AddRange(new string[] { "UMG" });
PublicIncludePathModuleNames.AddRange(new string[] { "OWSPlugin" });
......
......@@ -4,3 +4,5 @@
#include "Modules/ModuleManager.h"
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, VRClassroom, "VRClassroom" );
DEFINE_LOG_CATEGORY(VRC);
......@@ -3,4 +3,6 @@
#pragma once
//#include "Engine.h"
#include "CoreMinimal.h"
\ No newline at end of file
#include "CoreMinimal.h"
DECLARE_LOG_CATEGORY_EXTERN(VRC, Log, All);
\ No newline at end of file
{
"FileVersion": 3,
"EngineAssociation": "{7E4506D0-4E9A-9CE5-C703-1FAFBE0E6174}",
"EngineAssociation": "{4EDE54B2-41A6-5679-C2F5-D48179AF5635}",
"Category": "",
"Description": "",
"Modules": [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment