Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions Engine/Source/Engine/Network/FFragmentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ void FragmentManager::DestroyFragments(void)
{
if (m_fragmentsToDelete.empty()) { return; }

std::cout << "[manager] we deleting and shit" << std::endl;
m_fragments.erase(
std::remove_if(
m_fragments.begin(),
Expand Down Expand Up @@ -109,7 +108,6 @@ void FragmentManager::MergeFragments(
completeData.end(), chunk.data.begin(), chunk.data.end()
);
}
std::cout << "[manager] its processing time little one" << std::endl;
// Process the reassembled packet through the normal packet pipeline
networkBase->ProcessReceivedData(
completeData.data(), completeData.size(), entry.sender
Expand All @@ -127,9 +125,9 @@ Bool FragmentManager::IsFragmentComplete(const FragmentEntry& entry) const
}

///////////////////////////////////////////////////////////////////////////////
std::vector<std::vector<Byte>> FragmentManager::FragmentPacket(
const std::vector<Byte>& serializedData
) const
std::vector<std::vector<Byte>>
FragmentManager::FragmentPacket(const std::vector<Byte>& serializedData
) const
{
std::vector<std::vector<Byte>> chunks;

Expand Down Expand Up @@ -164,8 +162,8 @@ FragmentEntry* FragmentManager::FindFragmentEntry(const UUID& fragmentID)
}

///////////////////////////////////////////////////////////////////////////////
const FragmentEntry*
FragmentManager::FindFragmentEntry(const UUID& fragmentID) const
const FragmentEntry* FragmentManager::FindFragmentEntry(const UUID& fragmentID
) const
{
for (const auto& entry: m_fragments)
{
Expand All @@ -192,7 +190,6 @@ UUID FragmentManager::SendFullTransmission(
)
{
if (!networkBase) { return UUID::Nil; }
std::cout << "[MANAGER] we out here and shit" << std::endl;
// Create new fragment entry
FragmentEntry entry;
entry.id = UUID::V4(); // Generate unique ID
Expand All @@ -211,7 +208,6 @@ UUID FragmentManager::SendFullTransmission(
(static_cast<UInt32>(uuidData[1]) << 16) |
(static_cast<UInt32>(uuidData[2]) << 8) |
static_cast<UInt32>(uuidData[3]);
std::cout << "[MANAGER] id created" << std::endl;

// Create chunk entries and send them
for (SizeT i = 0; i < chunks.size(); ++i)
Expand Down
24 changes: 16 additions & 8 deletions Engine/Source/Engine/Network/FNetworkServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,8 @@ void FNetworkServer::CheckConnectionTimeouts(const TimePoint& now)
SendPacket(disconnectPacket, endpoint);

// Emit event
EmitEvent(
Events::ClientDisconnected{ clientID,
EDisconnectionReason::Timeout }
);
EmitEvent(Events::ClientDisconnected{
clientID, EDisconnectionReason::Timeout });

// Remove connection
m_connections.erase(it);
Expand Down Expand Up @@ -337,6 +335,17 @@ void FNetworkServer::HandleDisconnectPacket(

FLogger::SetNamespace("Network");
FLogger::Info("Client ID: {} disconnected", clientID);

{
// Add a new RPC deferred call to destroy the client entity
Packets::RemoteProcedureCall rpc(
"DestroyClient", ERPCType::Server, UUID::World, clientID
);

// Add parameters to the RPC
std::lock_guard<std::mutex> lock(m_rpcQueueMutex);
m_deferredRPCs.push({ rpc, endpoint });
}
}
}

Expand Down Expand Up @@ -378,8 +387,7 @@ void FNetworkServer::HandleConnectPacket(
if (packet.gameName != m_settings->game.title ||
packet.gameVersion != m_settings->game.version)
{
FLogger::Warn(
"[SERVER] Rejecting connection - Game/Version mismatch!"
FLogger::Warn("[SERVER] Rejecting connection - Game/Version mismatch!"
);

Packets::ConnectResponse response;
Expand Down Expand Up @@ -598,8 +606,8 @@ void FNetworkServer::Cleanup(void)
}

///////////////////////////////////////////////////////////////////////////////
FConnectionInformation*
FNetworkServer::GetClientInformation(UInt32 clientID) const
FConnectionInformation* FNetworkServer::GetClientInformation(UInt32 clientID
) const
{
std::lock_guard<std::mutex> lock(m_connectionsMutex);
auto it = m_clientIDToEndpoint.find(clientID);
Expand Down
32 changes: 31 additions & 1 deletion Engine/Source/Engine/Runtime/World/UWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ UWorld::UWorld(const FString& name)
ERPCType::Client,
std::bind(&UWorld::RPC_SyncSnapshot, this, std::placeholders::_1)
)
, DestroyClientRPC(
*this,
"DestroyClient",
ERPCType::Server,
std::bind(&UWorld::RPC_DestroyClient, this, std::placeholders::_1)
)
{
#if TKD_ENGINE_SERVER
SetNetRole(ENetRole::Authority);
Expand Down Expand Up @@ -446,12 +452,36 @@ void UWorld::RPC_DestroyActor(const UUID& actorID)
m_actors.begin(),
m_actors.end(),
[&actorID](const std::shared_ptr<AActor>& actor)
{ return actor && actor->GetNetworkID() == actorID; }
{ return actor && actor->GetUUID() == actorID; }
);

if (it != m_actors.end()) { (*it)->MarkForDeletion(); }
}

///////////////////////////////////////////////////////////////////////////////
void UWorld::RPC_DestroyClient(UInt32 owningClientID)
{
std::vector<UUID> actorsToDestroy;

// Find and destroy all actors owned by the specified client
for (const auto& actor: m_actors)
{
if (actor && actor->GetOwningClientID() == owningClientID)
{
actorsToDestroy.push_back(actor->GetUUID());
actor->MarkForDeletion();
}
}

// Send DestroyActorRPC for each actor to all clients
for (const auto& actorID: actorsToDestroy)
{
this->DestroyActorRPC.SetRPCType(ERPCType::Multicast);
this->DestroyActorRPC(actorID);
this->DestroyActorRPC.SetRPCType(ERPCType::Client);
}
}

///////////////////////////////////////////////////////////////////////////////
void UWorld::RPC_SpawnPlayer(
UInt32 owningClientID, const UUID& playerID, const FTransform& transform
Expand Down
9 changes: 9 additions & 0 deletions Engine/Source/Engine/Runtime/World/UWorld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class UWorld
UFunction<UInt32> SpawnClientRPC;
UFunction<UInt32, UUID, FTransform> SpawnPlayerRPC;
UFunction<std::vector<Byte>> SyncSnapshotRPC;
UFunction<UInt32> DestroyClientRPC;

public:
///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -138,6 +139,14 @@ class UWorld
///////////////////////////////////////////////////////////////////////////
void RPC_SyncSnapshot(const std::vector<Byte>& snapshot);

///////////////////////////////////////////////////////////////////////////
/// \brief Destroy client RPC handler
///
/// \param owningClientID The ID of the client to destroy
///
///////////////////////////////////////////////////////////////////////////
void RPC_DestroyClient(UInt32 owningClientID);

public:
///////////////////////////////////////////////////////////////////////////
/// \brief Spawn an actor of type T in the world
Expand Down
7 changes: 2 additions & 5 deletions Games/RType/Source/Core/AI/AI_Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ void AI_Player::Tick(Float32 deltaTime)
);
}
}
else
{
velocity = FVector2f::Zero;
}
else { velocity = FVector2f::Zero; }
m_lastPosition = currentPosition;
}

Expand Down Expand Up @@ -141,7 +138,7 @@ FTransform AI_Player::SimulateMovement(
// Determine the Y direction needed to reach the targetY
FVector3 currentPosition = startTransform.GetPosition();
Float32 directionY = 0.0f;
_Float32 m_forwardSpeed = -1.0f;
Float32 m_forwardSpeed = -1.0f;

if (targetY > currentPosition.y + 1.0f)
{
Expand Down
8 changes: 7 additions & 1 deletion Games/RType/Source/GameMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ RTypeGameMode::RTypeGameMode(void)
}

///////////////////////////////////////////////////////////////////////////////
void RTypeGameMode::BeginPlay(void) { Super::BeginPlay(); }
void RTypeGameMode::BeginPlay(void)
{
Super::BeginPlay();
Audio::PlaySoundFromPak(
"Assets/Audios/Music/M_02_Opening.wav", 0.5f, true
);
}

///////////////////////////////////////////////////////////////////////////////
void RTypeGameMode::Tick(Float32 deltaTime) { Super::Tick(deltaTime); }
Expand Down