Working connection to the server. Correct shutting down

main
Evgeny Kovalev 2 years ago
parent 4961bd5cab
commit 7a575339df
  1. BIN
      .DS_Store
  2. 6
      Config/DefaultEngine.ini
  3. BIN
      Content/Maps/M_Menu.umap
  4. 5
      PointBlank.uproject
  5. BIN
      Source/.DS_Store
  6. BIN
      Source/PointBlank/.DS_Store
  7. 2
      Source/PointBlank/PointBlank.Build.cs
  8. 56
      Source/PointBlank/ShipsGameInstance.cpp
  9. 25
      Source/PointBlank/ShipsGameInstance.h

BIN
.DS_Store vendored

Binary file not shown.

@ -1,7 +1,7 @@
[/Script/EngineSettings.GameMapsSettings]
EditorStartupMap=/Engine/Maps/Templates/OpenWorld.OpenWorld
EditorStartupMap=/Game/Maps/M_Menu.M_Menu
LocalMapOptions=
TransitionMap=None
bUseSplitscreen=False
@ -9,8 +9,8 @@ TwoPlayerSplitscreenLayout=Horizontal
ThreePlayerSplitscreenLayout=FavorTop
FourPlayerSplitscreenLayout=Grid
bOffsetPlayerGamepadIds=False
GameInstanceClass=/Script/Engine.GameInstance
GameDefaultMap=/Engine/Maps/Templates/OpenWorld.OpenWorld
GameInstanceClass=/Script/PointBlank.ShipsGameInstance
GameDefaultMap=/Game/Maps/M_Menu.M_Menu
ServerDefaultMap=/Engine/Maps/Entry.Entry
GlobalDefaultGameMode=/Script/Engine.GameModeBase
GlobalDefaultServerGameMode=None

Binary file not shown.

@ -7,7 +7,10 @@
{
"Name": "PointBlank",
"Type": "Runtime",
"LoadingPhase": "Default"
"LoadingPhase": "Default",
"AdditionalDependencies": [
"Engine"
]
}
],
"Plugins": [

BIN
Source/.DS_Store vendored

Binary file not shown.

Binary file not shown.

@ -8,7 +8,7 @@ public class PointBlank : ModuleRules
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "WebSockets" });
PrivateDependencyModuleNames.AddRange(new string[] { });

@ -0,0 +1,56 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "ShipsGameInstance.h"
#include "WebSocketsModule.h"
#include "Engine/GameEngine.h"
void UShipsGameInstance::Init()
{
Super::Init();
if (!FModuleManager::Get().IsModuleLoaded("WebSockets"))
{
FModuleManager::Get().LoadModule("WebSockets");
}
WebSocket = FWebSocketsModule::Get().CreateWebSocket("ws://localhost:8080/ws");
WebSocket->OnConnected().AddLambda([]()
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, "Connected to the server");
});
WebSocket->OnConnectionError().AddLambda([](const FString& Error)
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, Error);
});
WebSocket->OnClosed().AddLambda([](int32 StatusCode, const FString& Reason, bool bWasClean)
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, "Connection was closed");
});
WebSocket->OnMessage().AddLambda([](const FString & MessageString)
{
UE_LOG(LogTemp,Warning, TEXT("Received Message:"));
});
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, "init is happening");
WebSocket->Connect();
}
void UShipsGameInstance::Shutdown()
{
if (WebSocket->IsConnected())
{
WebSocket->Close();
}
Super::Shutdown();
}

@ -0,0 +1,25 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "IWebSocket.h"
#include "ShipsGameInstance.generated.h"
/**
*
*/
UCLASS()
class POINTBLANK_API UShipsGameInstance : public UGameInstance
{
GENERATED_BODY()
public:
virtual void Init() override;
virtual void Shutdown() override;
TSharedPtr<IWebSocket> WebSocket;
};
Loading…
Cancel
Save