/
VladimirGavrilov
/
TestProjectMultiplayer
Обзор
Документация
Войти
/
VladimirGavrilov
/
TestProjectMultiplayer
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Source/TestProject/Private/HTTP/HTTPLogics.cpp
52 строки
2 KB
VladimirGavrilov
added steam sdk to the project. Now the game client can work ONLY through MatchmakerApp. If you need to use the lobby and match without MatchmakerApp, use the previous commit
24 апр 2025, 02:40
24 апр 2025, 02:40
af35be5
Код
Авторство
О чём код?
// Fill out your copyright notice in the Description page of Project Settings. #include "HTTP/HTTPLogics.h" #include "HttpModule.h" #include "Interfaces/IHttpRequest.h" #include "Interfaces/IHttpResponse.h" #include "Http.h" #include "Kismet/GameplayStatics.h" #include "Engine/World.h" void UHTTPLogics::ConnectToMatchmaker(UObject* WorldContextObject, const FString& ServerIP, const FString& PlayerName, const FString& IDPlayer, const FString& Color) { TSharedRef<IHttpRequest, ESPMode::ThreadSafe> Request = FHttpModule::Get().CreateRequest(); FString EncodedName = FPlatformHttp::UrlEncode(PlayerName); FString EncodedID = FPlatformHttp::UrlEncode(IDPlayer); FString EncodedColor = FPlatformHttp::UrlEncode(Color); FString Url = FString::Printf(TEXT("http://%s:18080/connect?name=%s&id=%s&color=%s"), *ServerIP, *EncodedName, *EncodedID, *EncodedColor); UE_LOG(LogTemp, Log, TEXT("FullURL: %s"), *Url); Request->SetURL(Url); Request->SetVerb("GET"); Request->OnProcessRequestComplete().BindLambda( [WorldContextObject](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) { if (!bWasSuccessful || !Response.IsValid()) { UE_LOG(LogTemp, Error, TEXT("Request failed or response invalid!")); return; } FString Content = Response->GetContentAsString(); UE_LOG(LogTemp, Display, TEXT("Matchmaker response: %s"), *Content); if (WorldContextObject) { UE_LOG(LogTemp, Display, TEXT("World is valid")); if (APlayerController* PC = UGameplayStatics::GetPlayerController(WorldContextObject, 0)) { UE_LOG(LogTemp, Display, TEXT("ClientTravel Request")); PC->ClientTravel(Content, ETravelType::TRAVEL_Absolute); } } }); Request->ProcessRequest(); }