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();
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'
......
......@@ -17,7 +17,19 @@ UHttpService::UHttpService(const class FObjectInitializer& ObjectInitializer) :
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);
}
......@@ -40,11 +52,12 @@ void UHttpService::SetRequestHeaders(TSharedRef<IHttpRequest>& Request) {
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
VRCAPIPath = FString(TEXT("https://api.ev3.me/"));
FString VRCAPIPath1 = FString(TEXT("https://api.ev3.me/"));
Http = &FHttpModule::Get();
TSharedRef<IHttpRequest> Request = Http->CreateRequest();
FString url = FString(VRCAPIPath + Subroute);
FString url = FString(VRCAPIPath1);
url.Append(Subroute);
Request->SetURL(url);
SetRequestHeaders(Request);
......
......@@ -9,5 +9,5 @@ UVRCGameInstance::UVRCGameInstance(const class FObjectInitializer& ObjectInitial
}
UHttpService* UVRCGameInstance::GetHttpService() {
return Http;
return Http->GetHttp();
}
......@@ -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"));
}
}
......@@ -23,6 +23,8 @@ public:
FString VRCAPIPath = "";
UHttpService* GetHttp();
void SetTimeout(float Timeout);
bool ResponseIsValid(FHttpResponsePtr Response, bool bWasSuccessful);
......
......@@ -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);
};
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