Skip to content

Commit

Permalink
Finishing of implementation of systemId implemented logic at updating…
Browse files Browse the repository at this point in the history
… smallest and largest client ids.
  • Loading branch information
MrNen committed Nov 13, 2023
1 parent b613403 commit 7efcc33
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 35 deletions.
49 changes: 45 additions & 4 deletions include/API/FLHook/ClientList.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include "Core/ClientServerInterface.hpp"

struct ClientData
{
Expand Down Expand Up @@ -93,9 +94,48 @@ class ClientList

std::array<ClientData, MaxClientId + 1> clients;

void PlayerConnect(uint clientId);
void PlayerDisconnect(uint clientId);
void PlayerCharacterSelect();
void PlayerConnect(uint clientId)
{
clients[clientId].isValid = true;
if (clientId > largestClientId )
{
largestClientId = clientId;

}
if (clientId < smallestClientId)
{
smallestClientId = clientId;
}
}

void PlayerDisconnect(uint clientId)
{
clients[clientId].isValid = false;
if (largestClientId == clientId)
{
for (uint i = largestClientId - 1; i != smallestClientId; i--)
{
if (clients[i].isValid == true)
{
largestClientId = i;
break;
}
}
}
if (smallestClientId == clientId)
{
for (uint i = smallestClientId + 1; i != smallestClientId; i++)
{
if (clients[i].isValid == true)
{
smallestClientId = i;
break;
}
}
}
}

void PlayerCharacterSelect(); // TODO: Figure when player data is valid
void PlayerLogout();

inline static uint largestClientId = 0;
Expand Down Expand Up @@ -149,4 +189,5 @@ class ClientList
client++;
return Iterator(client, this);
}
};

};
4 changes: 2 additions & 2 deletions include/API/Types/ClientId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ class ClientId
[[nodiscard]]
Action<const Archetype::Ship *, Error> GetShipArch();
[[nodiscard]]
Action<ShipId, Error> GetShipId();
Action<ShipId, Error> GetShipId() const;
[[nodiscard]]
Action<CPlayerGroup *, Error> GetGroup();
[[nodiscard]]
Action<RepId, Error> GetReputation() const;
[[nodiscard]]
Action<CShip *, Error> GetShip();
Action<CShip *, Error> GetShip() const;
[[nodiscard]]
Action<uint, Error> GetRank();
[[nodiscard]]
Expand Down
8 changes: 2 additions & 6 deletions include/API/Types/SystemId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ class SystemId
Action<std::vector<SystemId>, Error> GetNeighboringSystems() const; // TODO: Look into Freelancer System Enumerator.
Action<std::vector<CSolar*>, Error> GetSolars(bool onlyDockables = false);
Action<std::vector<ClientId>, Error> GetPlayersInSystem(bool includeDocked = false) const;
Action<std::vector<ShipId>, Error> GetShipsInSystem();

Action<void, Error> Message(std::wstring_view, std::optional<MessageFormat> format = {}, std::optional<MessageColor> color = {});
Action<void, Error> SetSystemMusic(std::wstring trackNickName, std::optional<std::pair<Vector, float>> sphere = {});
Action<void, Error> PlaySound(std::wstring trackNickNameSound, std::optional<std::pair<Vector, float>> sphere = {});
Action<void, Error> ToggleSystemLock(bool locked); // TODO: Check into finding ways to lock gates.
Action<void, Error> ToggleDockables(bool locked);
Action<void, Error> Message(std::wstring_view msg, MessageColor color = MessageColor::Default, MessageFormat format = MessageFormat::Normal);
Action<void, Error> PlaySoundOrMusic(std::wstring trackNickNameSound,bool isMusic = false, std::optional<std::pair<Vector, float>> sphere = {});
Action<uint, Error> KillAllPlayers() const;
};
134 changes: 111 additions & 23 deletions source/API/Types/SystemId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,39 +75,127 @@ Action<std::vector<ClientId>, Error> SystemId::GetPlayersInSystem(bool includeDo

return { clients };
}
Action<std::vector<ShipId>, Error> SystemId::GetShipsInSystem()
{
//
//
}

Action<void, Error> SystemId::Message(std::wstring_view, std::optional<MessageFormat> format, std::optional<MessageColor> color)
Action<void, Error> SystemId::Message(std::wstring_view msg, MessageColor color, MessageFormat format)
{
//
//
ValidSystemCheck;

const auto clientsInSystem = GetPlayersInSystem().Raw();

if (clientsInSystem.has_error())
{
return { cpp::fail(clientsInSystem.error()) };
}

Error err = Error::Default;

for (auto& client : clientsInSystem.value())
{
const auto res = client.Message(msg, format, color).Raw();
if (res.has_error() && err != Error::Default)
{
err = res.error();
}
}
if (err != Error::Default)
{
return { cpp::fail(err) };
}
return { {} };
}
Action<void, Error> SystemId::SetSystemMusic(std::wstring trackNickName, std::optional<std::pair<Vector, float>> sphere)
{
//
//
}
ValidSystemCheck;
auto music = pub::Audio::Tryptich();
uint id = InternalAPI::CreateID(trackNickName);
music.musicId = id;
const auto clientsInSystem = GetPlayersInSystem().Raw();

Action<void, Error> SystemId::PlaySound(std::wstring trackNickNameSound, std::optional<std::pair<Vector, float>> sphere)
{
//
//
}
if (clientsInSystem.has_error())
{
return { cpp::fail(clientsInSystem.error()) };
}

Action<void, Error> SystemId::ToggleSystemLock(bool locked)
{
//
//
if (!sphere.has_value())
{

for (const auto& client : clientsInSystem.value())
{
if (pub::Audio::SetMusic(client.GetValue(), music) != (int)ResponseCode::Success)
{
return { cpp::fail(Error::InvalidSoundId) };
}
}
return { {} };
}
for (const auto& client : clientsInSystem.value())
{
const auto clientPos = client.GetShipId().Unwrap().GetPositionAndOrientation().Unwrap().first;

if (glm::length<3, float, glm::packed_highp>(clientPos - sphere.value().first) < sphere.value().second)
{
if (pub::Audio::SetMusic(client.GetValue(), music) != (int)ResponseCode::Success)
{
return { cpp::fail(Error::InvalidSoundId) };
}
}
}
}

Action<void, Error> SystemId::ToggleDockables(bool locked)
Action<void, Error> SystemId::PlaySoundOrMusic(std::wstring trackNickNameSound, bool isMusic, std::optional<std::pair<Vector, float>> sphere)
{
//
//
ValidSystemCheck;
auto sound = pub::Audio::Tryptich();
uint id = InternalAPI::CreateID(trackNickName);
sound.musicId = id;
const auto clientsInSystem = GetPlayersInSystem().Raw();

if (clientsInSystem.has_error())
{
return { cpp::fail(clientsInSystem.error()) };
}

if (!sphere.has_value())
{

for (const auto& client : clientsInSystem.value())
{
if (isMusic)
{
if (pub::Audio::SetMusic(client.GetValue(), sound) != (int)ResponseCode::Success)
{
return { cpp::fail(Error::InvalidSoundId) };
}
}
else if (pub::Audio::PlaySoundEffect(client.GetValue(), id) != (int)ResponseCode::Success)
{
return { cpp::fail(Error::InvalidSoundId) };
}
}
return { {} };
}
for (const auto& client : clientsInSystem.value())
{
const auto clientPos = client.GetShipId().Unwrap().GetPositionAndOrientation().Unwrap().first;

if (glm::length<3, float, glm::packed_highp>(clientPos - sphere.value().first) < sphere.value().second)
{
if (isMusic)
{
if (isMusic)
{
if (pub::Audio::SetMusic(client.GetValue(), sound) != (int)ResponseCode::Success)
{
return { cpp::fail(Error::InvalidSoundId) };
}
}
else if (pub::Audio::PlaySoundEffect(client.GetValue(), id) != (int)ResponseCode::Success)
{
return { cpp::fail(Error::InvalidSoundId) };
}
}
}
}
}

Action<uint, Error> SystemId::KillAllPlayers() const
Expand Down

0 comments on commit 7efcc33

Please sign in to comment.