-
Notifications
You must be signed in to change notification settings - Fork 5
/
InputApplier.cpp
73 lines (64 loc) · 2.07 KB
/
InputApplier.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2023 Haguk Kim
// Author: Haguk Kim
#include "InputApplier.h"
#include "PlayerPawn.h"
InputApplier::InputApplier()
{
}
InputApplier::~InputApplier()
{
}
bool InputApplier::Init(TSharedPtr<NetSession> session, UGameInstance* gameInstance)
{
if (!PacketApplier::Init(session, gameInstance)) return false;
return true;
}
bool InputApplier::ApplyPacket(TSharedPtr<RecvBuffer> packet, class ANetHandler* netHandler)
{
URovenhellGameInstance* gameInstance = Cast<URovenhellGameInstance>(GameInstance);
if (!gameInstance) return false;
bool applied = true;
switch (gameInstance->GetExecType()->GetHostType())
{
case HostTypeEnum::CLIENT:
case HostTypeEnum::CLIENT_HEADLESS:
{
applied &= ApplyPacket_UEClient(packet, netHandler);
break;
}
case HostTypeEnum::LOGIC_SERVER:
case HostTypeEnum::LOGIC_SERVER_HEADLESS:
{
applied &= ApplyPacket_UEServer(packet, netHandler);
break;
}
}
return applied;
}
bool InputApplier::ApplyPacket_UEClient(TSharedPtr<RecvBuffer> packet, class ANetHandler* netHandler)
{
return false; // 클라이언트는 Input 패킷을 처리하지 않음
}
bool InputApplier::ApplyPacket_UEServer(TSharedPtr<RecvBuffer> packet, class ANetHandler* netHandler)
{
netHandler->GetDeserializerShared()->Clear();
SD_GameInputHistory* inputData = new SD_GameInputHistory();
netHandler->GetDeserializerShared()->ReadDataFromBuffer(packet);
netHandler->GetDeserializerShared()->Deserialize((SD_Data*)inputData);
uint16 sessionId = packet->GetHeader()->senderId;
// 모든 플레이어들의 인풋 처리
for (const SD_GameInput& input : inputData->GameInputs)
{
if (input.ActionType == (uint32)ActionTypeEnum::MOVE)
{
APlayerPawn* playerPawn = netHandler->GetRovenhellGameInstance()->GetPlayerOfOwner(sessionId);
if (!playerPawn)
{
UE_LOG(LogTemp, Error, TEXT("세션 %i번 플레이어 폰이 없습니다."), sessionId);
return false;
}
playerPawn->Move_UEServer(FInputActionValue(FVector(input.X * (input.XSign ? -1 : 1), input.Y * (input.YSign ? -1 : 1), input.Z * (input.ZSign ? -1 : 1))), input.DeltaTime);
}
}
return true;
}