Commit 61b1397a authored by Geovanny E. Vera Pazmino's avatar Geovanny E. Vera Pazmino

Merge branch 'geo_login' into 'master'

Geo login

See merge request !3
parents 032b92b2 8bb192d2
Binaries
DerivedDataCache
node_modules
Intermediate
Saved
.vscode
......
# 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}")
......
const Koa = require('koa');
const Router = require("@koa/router");
const bodyParser = require('koa-body');
const fetch = require('node-fetch');
async function main(){
const ue4Router = require('./ue4/router.js');
const app = new Koa();
const router = new Router();
router.use('/ue4', ue4Router.routes(), ue4Router.allowedMethods());
app.use(bodyParser());
app.use(router.routes()).use(router.allowedMethods());
const response = await fetch('http://localhost:1337/instances/add-world-server');
// const data = await response.json();
// console.log(data);
app.listen(8181, () => console.log('Server Started'));
}
main();
\ No newline at end of file
This diff is collapsed.
{
"name": "world-server-client",
"dependencies": {
"@koa/router": "^8.0.8",
"koa": "^2.11.0",
"koa-body": "^4.1.1",
"node-fetch": "^2.6.1"
}
}
const config = {
UE4_PATH: "C:\\UnrealEngine-4.25.3-release\\Engine\\Binaries\\Win64\\UE4Editor.exe",
PROJECT_PATH: "C:\\Users\\geova\\OneDrive\\Documents\\Unreal Projects\\VRClassroom 4.25\\src\\VRClassroom.uproject",
}
module.exports = config;
\ No newline at end of file
const Router = require('@koa/router');
const CONFIG = require('./config.js');
const {spawn} = require('child_process');
const router = new Router();
router.post('/', (ctx, next) => {
const body = ctx.request.body;
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;
});
module.exports = router;
\ No newline at end of file
......@@ -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))
......
......@@ -234,13 +234,13 @@ void AOWSPlayerController::OnTravelToLastZoneServerResponseReceived(FHttpRequest
return;
}
ServerAndPort = ServerIP + FString(TEXT(":")) + Port.Left(4);
ServerAndPort = FString(TEXT("127.0.0.1:7778"));//ServerIP + FString(TEXT(":")) + Port.Left(4);
UE_LOG(OWS, Warning, TEXT("OnTravelToLastZoneServerResponseReceived ServerAndPort: %s"), *ServerAndPort);
UE_LOG(OWS, Log, TEXT("Travel GUID: %s"), *ServerTravelUserSessionGUID);
UE_LOG(OWS, Log, TEXT("IP: %s, Port %s"), *ServerIP, *Port);
UE_LOG(OWS, Log, TEXT("IP: %s"), *ServerAndPort);
//Encrypt data to send
FString IDData = FString::SanitizeFloat(ServerTravelX)
......@@ -1968,6 +1968,6 @@ void AOWSPlayerController::GetLifetimeReplicatedProps(TArray< FLifetimeProperty
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME_CONDITION(AOWSPlayerController, MaxPredictionPing, COND_OwnerOnly);
DOREPLIFETIME_CONDITION(AOWSPlayerController, PredictionFudgeFactor, COND_OwnerOnly);
//DOREPLIFETIME_CONDITION(AOWSPlayerController, MaxPredictionPing, COND_OwnerOnly);
//DOREPLIFETIME_CONDITION(AOWSPlayerController, PredictionFudgeFactor, COND_OwnerOnly);
}
// 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();
}
void UHttpService::SetTimeout(float Timeout) {
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
VRCAPIPath = FString(TEXT("https://api.ev3.me/"));
Http = &FHttpModule::Get();
TSharedRef<IHttpRequest> Request = Http->CreateRequest();
FString url = FString(VRCAPIPath + 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;
}
// 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);
}
}
// Copyright 2020 Testy
#include "VRCPlayerController.h"
#include "Runtime/Online/HTTP/Public/Http.h"
AVRCPlayerController::AVRCPlayerController() {
TravelTimeout = 60.0f;
}
void AVRCPlayerController::TravelToMap(const FString& URL, const bool SeamlessTravel) {
UE_LOG(LogTemp, Warning, TEXT("TravelToMap: %s"), *URL);
ClientTravel(URL, TRAVEL_Absolute, false, FGuid());
}
void AVRCPlayerController::ConnectToCampus() {
Http = &FHttpModule::Get();
Http->SetHttpTimeout(TravelTimeout);
TSharedRef<IHttpRequest> Request = Http->CreateRequest();
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"));
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) {
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("OnConnectToCampus IP is %s Port %s, Both"), *IP, *PORT, *URL);
TravelToMap(URL, false);
}
else {
UE_LOG(LogTemp, Error, TEXT("OnConnectToCampus Server returned no data!"));
}
}
else {
UE_LOG(LogTemp, Error, TEXT("OnConnectToCampus Error accessing server!"));
}
}
// 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 = "";
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);
};
// Copyright 2020 Testy
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "Runtime/Online/HTTP/Public/Http.h"
#include "VRCPlayerController.generated.h"
USTRUCT(BlueprintType, Blueprintable)
struct FCourse {
GENERATED_USTRUCT_BODY()
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Course")
int32 CourseID;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Course")
FString CourseName;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Course")
FDateTime StartDate;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Course")
FDateTime EndDate;
};
/**
*
*/
UCLASS()
class VRCLASSROOM_API AVRCPlayerController : public APlayerController
{
GENERATED_BODY()
FHttpModule* Http;
public:
AVRCPlayerController();
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Connection")
float TravelTimeout;
UPROPERTY(BlueprintReadWrite, Category = "Config")
FString VRCAPIPath = "http://localhost:1337/";
UFUNCTION(BlueprintCallable, Category = "Travel")
void ConnectToCampus();
void OnConnectToCampusResponseRecieved(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
UFUNCTION(BlueprintCallable, Category = "Travel")
void TravelToMap(const FString& URL, const bool SeamlessTravel);
};
......@@ -13,13 +13,14 @@ public class VRClassroom : ModuleRules
"Engine",
"OWSPlugin",
"AIModule",
"Http",
"Json",
"JsonUtilities",
"InputCore",
"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);
......@@ -4,3 +4,5 @@
//#include "Engine.h"
#include "CoreMinimal.h"
DECLARE_LOG_CATEGORY_EXTERN(VRC, Log, All);
\ No newline at end of file
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