diff --git a/Source/SkyFrontier/Private/MyButton.cpp b/Source/SkyFrontier/Private/MyButton.cpp deleted file mode 100644 index ed16293..0000000 --- a/Source/SkyFrontier/Private/MyButton.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "MyButton.h" - -UMyButton::UMyButton() -{ - OnClicked.AddDynamic(this, &UMyButton::OnClick); -} -void UMyButton::SetSessionInfo(int sID, TCPClient *tclient) -{ - sessionID = sID; tcpClient = tclient; -} -void UMyButton::OnClick() -{ - tcpClient->JoinGameSession(sessionID); -} \ No newline at end of file diff --git a/Source/SkyFrontier/Private/MyButtonHost.cpp b/Source/SkyFrontier/Private/MyButtonHost.cpp deleted file mode 100644 index f382b9d..0000000 --- a/Source/SkyFrontier/Private/MyButtonHost.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "MyButtonHost.h" - -UMyButtonHost::UMyButtonHost() -{ - OnClicked.AddDynamic(this, &UMyButtonHost::OnClick); -} -void UMyButtonHost::SetSessionInfo(FString sname, TCPClient *tclient) -{ - sessionName = sname; tcpClient = tclient; -} -void UMyButtonHost::OnClick() -{ - tcpClient->CreateNewGameSession(sessionName); -} \ No newline at end of file diff --git a/Source/SkyFrontier/Private/MyPlayerState.cpp b/Source/SkyFrontier/Private/MyPlayerState.cpp deleted file mode 100644 index 50738a0..0000000 --- a/Source/SkyFrontier/Private/MyPlayerState.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "MyPlayerState.h" -#include "MyButton.h" -#include "TCPClient.h" -#include "Blueprint/UserWidget.h" -#include "Components/Button.h" -#include "Components/ScrollBox.h" -#include "Components/TextBlock.h" -#include "Components/VerticalBox.h" -#include "Components/VerticalBoxSlot.h" - -void AMyPlayerState::BeginPlay() -{ - FString levelName = GetWorld()->GetMapName(); - levelName.RemoveFromStart(GetWorld()->StreamingLevelsPrefix); - if (levelName == "StartMap") - { - tcpClient = new TCPClient(this); - canConnectToGameServer = false; - if ((MatchmakingWidgetClass) && (tcpClient->IsConnected())) - { - serversList = new TArray(); - GetWorld()->GetTimerManager().SetTimer(serverListTimerHandle, this, &AMyPlayerState::OnUpdateServerList, 2, true); - MatchmakingWidget = CreateWidget(GetWorld(),MatchmakingWidgetClass); - MatchmakingWidget->AddToViewport(); - serverListScrollBoxWidget = Cast(MatchmakingWidget->GetWidgetFromName(TEXT("MyScrollBox"))); - UButton* newSessionButton = Cast(MatchmakingWidget->GetWidgetFromName(TEXT("NewSession"))); - if (newSessionButton) - { - newSessionButton->SetIsEnabled(true); - newSessionButton->OnClicked.AddDynamic(this, &AMyPlayerState::OnNewSessionClicked); - } - } - } -} -void AMyPlayerState::OnNewSessionClicked() -{ - tcpClient->CreateNewGameSession("My test session"); -} -void AMyPlayerState::UpdateSessionsList(FString serverinfo) -{ - TArray Out; serverinfo.ParseIntoArray(Out, TEXT("|"), true); - for (int i = 1; i < Out.Num() - 1; i += 2) { FSessionInfo *tempInfo = new FSessionInfo(); - tempInfo->id = FCString::Atoi(*Out[i]); - tempInfo->name = Out[i + 1]; - tempInfo->serverip = ""; - tempInfo->serverport = -1; - serversList->Add(tempInfo); } -} -void AMyPlayerState::ConnectToGameServer(FSessionInfo session) -{ - canConnectToGameServer = true; connectToGameServerSession = session; -} -void AMyPlayerState::OnUpdateServerList() { - if (tcpClient) { - if (tcpClient->IsConnected()) { - if (serversList->Num() > 0) { - if ((MatchmakingWidget) && (serverListScrollBoxWidget)) { - TArray allChildren = serverListScrollBoxWidget-> GetAllChildren(); - for (int i = 0; i < allChildren.Num(); i++) - { - allChildren[i]->RemoveFromParent(); - } - for (int i = 0; i < serversList->Num(); i++) - { - UVerticalBox* ItemWidgetsBox = NewObject(); - serverListScrollBoxWidget->AddChild(ItemWidgetsBox); - UMyButton* ItemWidget = NewObject(this); - ItemWidget->SetSessionInfo((*serversList)[i]->id, tcpClient); - UTextBlock* ItemWidgetText = NewObject(); - ItemWidgetText->SetText(FText::FromString( (*serversList)[i]->name)); - ItemWidget->AddChild(ItemWidgetText); - UVerticalBoxSlot* Slot = ItemWidgetsBox-> AddChildToVerticalBox(ItemWidget); - static FMargin Padding(5); - Slot->SetPadding(Padding); - } - } - } - if (canConnectToGameServer){ APlayerController* pController = GetWorld()-> GetFirstPlayerController(); - if (pController){ FString cmd = "open " + connectToGameServerSession.serverip + ":" + FString::FromInt(connectToGameServerSession.serverport); - tcpClient->Stop(); - canConnectToGameServer = false; - MatchmakingWidget->RemoveFromViewport(); - pController->ConsoleCommand(cmd); - } - } - } - } -} \ No newline at end of file diff --git a/Source/SkyFrontier/Private/TCPClient.cpp b/Source/SkyFrontier/Private/TCPClient.cpp deleted file mode 100644 index c610cb2..0000000 --- a/Source/SkyFrontier/Private/TCPClient.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "TCPClient.h" - -#include "MyPlayerState.h" -#include "Sockets.h" -#include "SocketSubsystem.h" -#include "Interfaces/IPv4/IPv4Address.h" -#include "TraceServices/Model/Diagnostics.h" - -TCPClient::TCPClient(AMyPlayerState* pState) -{ - Thread = FRunnableThread::Create(this, TEXT("TCPClientThread"), 0, TPri_Normal); PlayerState = pState; -} -TCPClient::~TCPClient() -{ - TCPClient::Stop(); delete Thread; -} -void TCPClient::Stop() -{ - running = false; -} -bool TCPClient::IsConnected() -{ - return connected; -} - -bool TCPClient::Init() -{ - Socket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_Stream, TEXT("default"), false); - int32 NewSize = 0; - Socket->SetReceiveBufferSize(1024, NewSize); - FIPv4Address matchmakingServerIP(127, 0, 0, 1); - TSharedRef matchmakingServer = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr(); - matchmakingServer->SetIp(matchmakingServerIP.Value); - matchmakingServer->SetPort(8856); - - connected = Socket->Connect(*matchmakingServer); - if (connected) - { - UE_LOG(LogTemp, Log, TEXT("CONNECTED!")); - FString serialized = TEXT("g|#"); - TCHAR *serializedChar = serialized.GetCharArray().GetData(); - int32 size = FCString::Strlen(serializedChar); - int32 sent = 0; - bool successful = Socket->Send((uint8*)TCHAR_TO_UTF8(serializedChar), size, sent); - if (successful) - {UE_LOG(LogTemp, Log, TEXT("MESSAGE SENT THROUGH SOCKET")); - return true; - } - else - { - UE_LOG(LogTemp, Log, TEXT("ERROR: NOT CONNECTED!"));return false; - } - } - return 0; -} - uint32 TCPClient::Run() - { - running = true; - TArray ReceivedData; - while (running) - { - uint32 Size = 0; - if (Socket->HasPendingData(Size)) - { - ReceivedData.Init(0, Size); - int32 Read = 0; - Socket->Recv(ReceivedData.GetData(), ReceivedData.Num(), Read); - FString ServerMessage = FString(UTF8_TO_TCHAR(ReceivedData.GetData())); - UE_LOG(LogTemp, Log, TEXT("RECEIVED: %s"), *ServerMessage); - if ((ServerMessage[0] == 's') && (PlayerState)) - { - PlayerState->UpdateSessionsList(ServerMessage); - } - else if((ServerMessage[0] == 'o') && (PlayerState)) - { - TArray Out; - ServerMessage.ParseIntoArray(Out, TEXT("|"), true); - FSessionInfo session; - session.id = -1; - session.name = ""; - session.serverip = Out[1]; - session.serverport = FCString::Atoi(*Out[2]); - PlayerState->ConnectToGameServer(session); - } - } - } - return 0; - } - - void TCPClient::CreateNewGameSession(FString sname) - { - FString serialized = "c|" + sname + "|#"; - TCHAR *serializedChar = serialized.GetCharArray().GetData(); - int32 size = FCString::Strlen(serializedChar); - int32 sent = 0; - bool successful = Socket->Send((uint8*) TCHAR_TO_UTF8(serializedChar), size, sent); - if (successful) - UE_LOG(LogTemp, Log, TEXT("MESSAGE SENT!!!!")); - } - void TCPClient::JoinGameSession(int sID) - { - FString serialized = "j|" + FString::FromInt(sID) + "|#"; - TCHAR *serializedChar = serialized.GetCharArray().GetData(); - int32 size = FCString::Strlen(serializedChar); - int32 sent = 0; - bool successful = Socket->Send((uint8*) TCHAR_TO_UTF8(serializedChar), size, sent); - if (successful) - UE_LOG(LogTemp, Log, TEXT("MESSAGE SENT!!!!")); - } \ No newline at end of file diff --git a/Source/SkyFrontier/Private/Test_anim_Class.cpp b/Source/SkyFrontier/Private/Test_anim_Class.cpp deleted file mode 100644 index 3820b29..0000000 --- a/Source/SkyFrontier/Private/Test_anim_Class.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "Test_anim_Class.h" - -// Sets default values -ATest_anim_Class::ATest_anim_Class() -{ - // Set this pawn 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 ATest_anim_Class::BeginPlay() -{ - Super::BeginPlay(); - -} - -// Called every frame -void ATest_anim_Class::Tick(float DeltaTime) -{ - Super::Tick(DeltaTime); - -} - -// Called to bind functionality to input -void ATest_anim_Class::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) -{ - Super::SetupPlayerInputComponent(PlayerInputComponent); - -} - diff --git a/Source/SkyFrontier/Public/MyButton.h b/Source/SkyFrontier/Public/MyButton.h deleted file mode 100644 index 57e7828..0000000 --- a/Source/SkyFrontier/Public/MyButton.h +++ /dev/null @@ -1,26 +0,0 @@ -// Fill out your copyright notice in the Description page of Project Settings. - -#pragma once - -#include "CoreMinimal.h" -#include "TCPClient.h" -#include "Components/Button.h" -#include "MyButton.generated.h" - -/** - * - */ -UCLASS() -class SKYFRONTIER_API UMyButton : public UButton -{ - GENERATED_BODY() -public: - UMyButton(); - void SetSessionInfo(int sID, TCPClient *tclient); -protected: int sessionID; - TCPClient *tcpClient; - - UFUNCTION() - void OnClick(); - -}; diff --git a/Source/SkyFrontier/Public/MyButtonHost.h b/Source/SkyFrontier/Public/MyButtonHost.h deleted file mode 100644 index c810c7b..0000000 --- a/Source/SkyFrontier/Public/MyButtonHost.h +++ /dev/null @@ -1,26 +0,0 @@ -// Fill out your copyright notice in the Description page of Project Settings. - -#pragma once - -#include "CoreMinimal.h" -#include "TCPClient.h" -#include "Components/Button.h" -#include "MyButtonHost.generated.h" - -/** - * - */ -UCLASS() -class SKYFRONTIER_API UMyButtonHost : public UButton -{ - GENERATED_BODY() -public: - UMyButtonHost(); - void SetSessionInfo(FString sname, TCPClient *tclient); -protected: FString sessionName; - TCPClient *tcpClient; - - UFUNCTION() - void OnClick(); - -}; \ No newline at end of file diff --git a/Source/SkyFrontier/Public/MyPlayerState.h b/Source/SkyFrontier/Public/MyPlayerState.h deleted file mode 100644 index 816fe70..0000000 --- a/Source/SkyFrontier/Public/MyPlayerState.h +++ /dev/null @@ -1,52 +0,0 @@ -// Fill out your copyright notice in the Description page of Project Settings. - -#pragma once - -#include "CoreMinimal.h" -#include "GameFramework/PlayerState.h" -#include "MyPlayerState.generated.h" - -USTRUCT() -struct FSessionInfo -{ - GENERATED_BODY() - UPROPERTY() - int id; - UPROPERTY() - FString name; - UPROPERTY() - FString serverip; - UPROPERTY() - int serverport; -}; - -UCLASS() -class SKYFRONTIER_API AMyPlayerState : public APlayerState -{ - GENERATED_BODY() -public: - void UpdateSessionsList(FString serverinfo); - void ConnectToGameServer(FSessionInfo session); - -protected: - virtual void BeginPlay() override; - - class TCPClient* tcpClient; - - UPROPERTY(EditDefaultsOnly, Category = "UI") - TSubclassOf MatchmakingWidgetClass; - class UUserWidget* MatchmakingWidget; - class UScrollBox* serverListScrollBoxWidget; - - TArray *serversList; - FTimerHandle serverListTimerHandle; - - bool canConnectToGameServer; - FSessionInfo connectToGameServerSession; - - UFUNCTION() - void OnNewSessionClicked(); - - UFUNCTION() - void OnUpdateServerList(); -}; diff --git a/Source/SkyFrontier/Public/TCPClient.h b/Source/SkyFrontier/Public/TCPClient.h deleted file mode 100644 index 5e83447..0000000 --- a/Source/SkyFrontier/Public/TCPClient.h +++ /dev/null @@ -1,29 +0,0 @@ -// Fill out your copyright notice in the Description page of Project Settings. - -#pragma once - -#include "CoreMinimal.h" - -/** - * - */ -class SKYFRONTIER_API TCPClient : public FRunnable -{ -public: - TCPClient(class AMyPlayerState* pState); - ~TCPClient(); - virtual bool Init(); - virtual uint32 Run(); - virtual void Stop(); - void CreateNewGameSession(FString sname); - void JoinGameSession(int sID); - bool IsConnected(); - -private: - FRunnableThread* Thread; - FSocket* Socket; - FSocket* ListenerSocket; - bool running; - bool connected; - class AMyPlayerState* PlayerState; -}; diff --git a/Source/SkyFrontier/Public/Test_anim_Class.h b/Source/SkyFrontier/Public/Test_anim_Class.h deleted file mode 100644 index 29a249b..0000000 --- a/Source/SkyFrontier/Public/Test_anim_Class.h +++ /dev/null @@ -1,29 +0,0 @@ -// Fill out your copyright notice in the Description page of Project Settings. - -#pragma once - -#include "CoreMinimal.h" -#include "GameFramework/Pawn.h" -#include "Test_anim_Class.generated.h" - -UCLASS() -class SKYFRONTIER_API ATest_anim_Class : public APawn -{ - GENERATED_BODY() - -public: - // Sets default values for this pawn's properties - ATest_anim_Class(); - -protected: - // Called when the game starts or when spawned - virtual void BeginPlay() override; - -public: - // Called every frame - virtual void Tick(float DeltaTime) override; - - // Called to bind functionality to input - virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; - -};