LuckyWorldV2/Source/Luckyrobots/Private/GameModes/LuckyRobotsGameState.cpp
martinluckyrobots 5d8e225db5 Fix Folder Structure
2025-04-07 10:28:47 +08:00

55 lines
1.4 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "GameModes/LuckyRobotsGameState.h"
#include "SocketIOClientComponent.h"
#include "FunctionLibraries/LuckyRobotsFunctionLibrary.h"
#include "Core/LuckyRobotsGameInstance.h"
ALuckyRobotsGameState::ALuckyRobotsGameState()
{
SocketIOClientComponent = CreateDefaultSubobject<USocketIOClientComponent>(TEXT("SocketIOClientComponent"));
}
void ALuckyRobotsGameState::BeginPlay()
{
Super::BeginPlay();
if (SocketIOClientComponent)
{
SocketIOClientComponent->Connect(L"http://localhost:3000/");
}
}
void ALuckyRobotsGameState::DoSendMessage(FString SendValue)
{
if (SocketIOClientComponent)
{
if (SocketIOClientComponent->bIsConnected)
{
USIOJsonValue* SIOJsonValue = USIOJsonValue::ConstructJsonValueString(this, SendValue);
SocketIOClientComponent->Emit("message", SIOJsonValue);
}
}
}
void ALuckyRobotsGameState::DoSocketOnConnect(FString SocketId, FString SessionId, bool IsReconnection)
{
if (SocketIOClientComponent)
{
if (SocketIOClientComponent->bIsConnected)
{
SocketIOClientComponent->BindEventToGenericEvent("response");
}
}
}
void ALuckyRobotsGameState::DoSocketOnGenericEvent(FString EventName, USIOJsonValue* EventData)
{
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = ULuckyRobotsFunctionLibrary::GetLuckyRobotsGameInstance(this);
if (LuckyRobotsGameInstance)
{
LuckyRobotsGameInstance->DoGetDispatch(EventName, EventData);
}
}