Commit 84ea8963 authored by Geovanny E. Vera Pazmino's avatar Geovanny E. Vera Pazmino

Merge branch 'geo_login' into 'master'

Geo login

See merge request !4
parents 61b1397a 1510f23a
...@@ -6,8 +6,20 @@ const router = new Router(); ...@@ -6,8 +6,20 @@ const router = new Router();
router.post('/', (ctx, next) => { router.post('/', (ctx, next) => {
const body = ctx.request.body; 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}`], { const sub = spawn(CONFIG.UE4_PATH, [CONFIG.PROJECT_PATH, `${body.name}?listen`, '-server', '-log', '-nosteam', '-messaging', `-port=${body.port}`], {
detached: true, detached: true,
stdio: 'ignore' stdio: 'ignore'
......
...@@ -17,7 +17,19 @@ UHttpService::UHttpService(const class FObjectInitializer& ObjectInitializer) : ...@@ -17,7 +17,19 @@ UHttpService::UHttpService(const class FObjectInitializer& ObjectInitializer) :
Http = &FHttpModule::Get(); Http = &FHttpModule::Get();
} }
UHttpService* UHttpService::GetHttp() {
Http = &FHttpModule::Get();
return this;
}
void UHttpService::SetTimeout(float Timeout) { 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); Http->SetHttpTimeout(Timeout);
} }
...@@ -40,11 +52,12 @@ void UHttpService::SetRequestHeaders(TSharedRef<IHttpRequest>& Request) { ...@@ -40,11 +52,12 @@ void UHttpService::SetRequestHeaders(TSharedRef<IHttpRequest>& Request) {
TSharedRef<IHttpRequest> UHttpService::RequestWithRoute(FString Subroute) { 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 // 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 // TODO: Figure out why that happens and fix it to remove this line
VRCAPIPath = FString(TEXT("https://api.ev3.me/")); FString VRCAPIPath1 = FString(TEXT("https://api.ev3.me/"));
Http = &FHttpModule::Get(); Http = &FHttpModule::Get();
TSharedRef<IHttpRequest> Request = Http->CreateRequest(); TSharedRef<IHttpRequest> Request = Http->CreateRequest();
FString url = FString(VRCAPIPath + Subroute); FString url = FString(VRCAPIPath1);
url.Append(Subroute);
Request->SetURL(url); Request->SetURL(url);
SetRequestHeaders(Request); SetRequestHeaders(Request);
......
...@@ -9,5 +9,5 @@ UVRCGameInstance::UVRCGameInstance(const class FObjectInitializer& ObjectInitial ...@@ -9,5 +9,5 @@ UVRCGameInstance::UVRCGameInstance(const class FObjectInitializer& ObjectInitial
} }
UHttpService* UVRCGameInstance::GetHttpService() { UHttpService* UVRCGameInstance::GetHttpService() {
return Http; return Http->GetHttp();
} }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "VRCPlayerController.h" #include "VRCPlayerController.h"
#include "Runtime/Online/HTTP/Public/Http.h" #include "Runtime/Online/HTTP/Public/Http.h"
#include "VRCGameInstance.h"
AVRCPlayerController::AVRCPlayerController() { AVRCPlayerController::AVRCPlayerController() {
...@@ -15,30 +16,25 @@ void AVRCPlayerController::TravelToMap(const FString& URL, const bool SeamlessTr ...@@ -15,30 +16,25 @@ void AVRCPlayerController::TravelToMap(const FString& URL, const bool SeamlessTr
} }
void AVRCPlayerController::ConnectToCampus() { void AVRCPlayerController::ConnectToCampus() {
Http = &FHttpModule::Get(); if (Http == NULL) {
Http->SetHttpTimeout(TravelTimeout); 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->OnProcessRequestComplete().BindUObject(this, &AVRCPlayerController::OnConnectToCampusResponseRecieved);
Request->SetVerb("POST"); Request->SetHeader("Accepts", TEXT("application/json"));
Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");
Request->SetHeader("Content-Type", TEXT("application/json"));
Request->SetHeader(TEXT("Accepts"), TEXT("application/json"));
FString url = FString(VRCAPIPath + "instances/join-server"); 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->SetURL(url);
Request->SetContentAsString(PostParameters);
Request->ProcessRequest(); Request->ProcessRequest();
} }
void AVRCPlayerController::OnConnectToCampusResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) void AVRCPlayerController::OnConnectToCampusResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{ {
if (bWasSuccessful) { if (Http->ResponseIsValid(Response, bWasSuccessful)) {
TSharedPtr<FJsonObject> JsonObject; TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString()); TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
...@@ -55,10 +51,54 @@ void AVRCPlayerController::OnConnectToCampusResponseRecieved(FHttpRequestPtr Req ...@@ -55,10 +51,54 @@ void AVRCPlayerController::OnConnectToCampusResponseRecieved(FHttpRequestPtr Req
} }
else { else {
UE_LOG(LogTemp, Error, TEXT("OnConnectToCampus Server returned no data!")); UE_LOG(LogTemp, Error, TEXT("OnConnectToCampus Server returned no data!"));
} }
} }
else { else {
UE_LOG(LogTemp, Error, TEXT("OnConnectToCampus Error accessing server!")); 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"));
}
}
...@@ -23,6 +23,8 @@ public: ...@@ -23,6 +23,8 @@ public:
FString VRCAPIPath = ""; FString VRCAPIPath = "";
UHttpService* GetHttp();
void SetTimeout(float Timeout); void SetTimeout(float Timeout);
bool ResponseIsValid(FHttpResponsePtr Response, bool bWasSuccessful); bool ResponseIsValid(FHttpResponsePtr Response, bool bWasSuccessful);
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "GameFramework/PlayerController.h" #include "GameFramework/PlayerController.h"
#include "Runtime/Online/HTTP/Public/Http.h" #include "HttpService.h"
#include "VRCPlayerController.generated.h" #include "VRCPlayerController.generated.h"
USTRUCT(BlueprintType, Blueprintable) USTRUCT(BlueprintType, Blueprintable)
...@@ -29,7 +29,7 @@ class VRCLASSROOM_API AVRCPlayerController : public APlayerController ...@@ -29,7 +29,7 @@ class VRCLASSROOM_API AVRCPlayerController : public APlayerController
{ {
GENERATED_BODY() GENERATED_BODY()
FHttpModule* Http; UHttpService* Http;
public: public:
...@@ -41,12 +41,17 @@ public: ...@@ -41,12 +41,17 @@ public:
UPROPERTY(BlueprintReadWrite, Category = "Config") UPROPERTY(BlueprintReadWrite, Category = "Config")
FString VRCAPIPath = "http://localhost:1337/"; FString VRCAPIPath = "http://localhost:1337/";
UFUNCTION(BlueprintCallable, Category = "Travel")
void TravelToMap(const FString& URL, const bool SeamlessTravel);
UFUNCTION(BlueprintCallable, Category = "Travel") UFUNCTION(BlueprintCallable, Category = "Travel")
void ConnectToCampus(); void ConnectToCampus();
void OnConnectToCampusResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful); void OnConnectToCampusResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
UFUNCTION(BlueprintCallable, Category = "Travel") UFUNCTION(BlueprintCallable, Category = "Travel")
void TravelToMap(const FString& URL, const bool SeamlessTravel); void ConnectToMeeting(FString MeetingId);
void OnConnectToMeetingResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
}; };
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