Commit fe1266e3 authored by Geovanny Vera's avatar Geovanny Vera

Transition between maps using game menu done

parent 79a96684
......@@ -36,7 +36,7 @@ bOffsetPlayerGamepadIds=False
GameInstanceClass=/Script/VRClassroom.VRCGameInstance
GameDefaultMap=/Game/Campus/Maps/Login.Login
ServerDefaultMap=/Game/Campus/Maps/TestServer.TestServer
GlobalDefaultGameMode=/Game/Campus/Blueprints/BP_GameMode.BP_GameMode_C
GlobalDefaultGameMode=/Game/Campus/Blueprints/BP_CGameMode.BP_CGameMode_C
GlobalDefaultServerGameMode=None
[/Script/AndroidRuntimeSettings.AndroidRuntimeSettings]
......
......@@ -3,6 +3,7 @@ const Router = require("@koa/router");
const bodyParser = require('koa-body');
const fetch = require('node-fetch');
const publicIp = require('public-ip');
const UE_CONFIG = require("./ue4/config.js");
async function main(){
......@@ -18,6 +19,7 @@ async function main(){
app.use(router.routes()).use(router.allowedMethods());
const ip = await publicIp.v4();
UE_CONFIG.ip = ip;
//const api = 'https://api.ev3.me/';
const api = 'http://localhost:1337/';
......
......@@ -7,7 +7,7 @@ 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}`], {
const sub = spawn(CONFIG.UE4_PATH, [CONFIG.PROJECT_PATH, `${body.name}?listen?ip=${CONFIG.ip}?port=${body.port}`, '-server', '-log', '-nosteam', '-messaging', `-port=${body.port}`], {
detached: true,
stdio: 'ignore'
});
......@@ -17,10 +17,10 @@ router.post('/', (ctx, next) => {
ctx.response.status = 204;
});
router.post('/classroom', (ctx, next) => {
router.post('/meeting', (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?ip=${CONFIG.ip}?port=${body.port}`, '-server', '-log', '-nosteam', '-messaging', `-port=${body.port}`], {
detached: true,
stdio: 'ignore'
});
......
// Copyright 2020 Testy
#include "VRCGameMode.h"
#include "HttpService.h"
#include "VRCGameInstance.h"
AVRCGameMode::AVRCGameMode() {
EndTimeout = 10.0f;
}
void AVRCGameMode::ShutDown() {
GIsRequestingExit = true;
}
void AVRCGameMode::RemoveInstanceFromAPI(const FString& route, const FString& IP, const FString& PORT) {
UVRCGameInstance* GameInstance = Cast<UVRCGameInstance>(GetWorld()->GetGameInstance());
Http = GameInstance->GetHttpService();
FString token = GameInstance->GetUserToken();
Http->SetTimeout(EndTimeout);
TArray<FStringFormatArg> args;
args.Add(FStringFormatArg(IP));
args.Add(FStringFormatArg(PORT));
FString content = FString::Format(TEXT("{\"ip\":\"{0}\", \"port\":\"{1}\"}"), args);
UE_LOG(LogTemp, Log, TEXT("Content: %s"), *content);
TSharedRef<IHttpRequest> Request = Http->PostRequest(route, content);
Request->OnProcessRequestComplete().BindUObject(this, &AVRCGameMode::OnRemoveInstanceFromAPI);
Request->SetHeader("Content-Type", TEXT("application/json"));
FString auth = "Bearer ";
auth.Append(token);
Request->SetHeader("Authorization", auth);
Request->ProcessRequest();
}
void AVRCGameMode::OnRemoveInstanceFromAPI(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) {
if (Http->ResponseIsValid(Response, bWasSuccessful)) {
UE_LOG(LogTemp, Log, TEXT("Shutting Down!"));
ShutDown();
}
else {
UE_LOG(LogTemp, Error, TEXT("OnRemoveInstanceFromAPI Error removing from API!"));
}
}
void AVRCGameMode::RemoveHubFromAPI(const FString& IP, const FString& PORT) {
RemoveInstanceFromAPI(TEXT("instances/remove-hub"), IP, PORT);
}
void AVRCGameMode::RemoveMeetingFromAPI(const FString& IP, const FString& PORT) {
RemoveInstanceFromAPI(TEXT("instances/remove-meeting"), IP, PORT);
}
\ No newline at end of file
......@@ -39,6 +39,7 @@ class VRCLASSROOM_API UVRCGameInstance : public UGameInstance
public:
UVRCGameInstance(const class FObjectInitializer& ObjectInitializer);
UPROPERTY(BlueprintReadOnly)
FUserData User;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
......
// Copyright 2020 Testy
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameMode.h"
#include "HttpService.h"
#include "VRCGameMode.generated.h"
/**
*
*/
UCLASS()
class VRCLASSROOM_API AVRCGameMode : public AGameMode
{
GENERATED_BODY()
UHttpService* Http;
public:
AVRCGameMode();
UFUNCTION(BlueprintCallable, Category = "Engine", meta = (HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject", Keywords = "Shut Down"))
void ShutDown();
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Connection")
float EndTimeout;
UFUNCTION(BlueprintCallable, Category = "API")
void RemoveInstanceFromAPI(const FString& route, const FString& IP, const FString& PORT);
UFUNCTION(BlueprintCallable, Category = "API")
void RemoveHubFromAPI(const FString& IP, const FString& PORT);
UFUNCTION(BlueprintCallable, Category = "API")
void RemoveMeetingFromAPI(const FString& IP, const FString& PORT);
void OnRemoveInstanceFromAPI(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
};
......@@ -38,9 +38,6 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Connection")
float TravelTimeout;
UPROPERTY(BlueprintReadWrite, Category = "Config")
FString VRCAPIPath = "http://localhost:1337/";
UFUNCTION(BlueprintCallable, Category = "Travel")
void TravelToMap(const FString& URL, const bool SeamlessTravel);
......
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