Skip to content

Commit

Permalink
Added SDK to Filter, initial implementation of new Flhook types.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNen committed Nov 8, 2023
1 parent 2283221 commit de133b4
Show file tree
Hide file tree
Showing 28 changed files with 1,544 additions and 124 deletions.
2 changes: 1 addition & 1 deletion FLHookSDK
165 changes: 70 additions & 95 deletions include/API/API.hpp
Original file line number Diff line number Diff line change
@@ -1,106 +1,12 @@
#pragma once

class AdminApi;
class ClientApi;
class MathApi;
class PersonalitiesApi;
class PlayerApi;
class SolarApi;
class ZoneApi;

class DLL Api
{
friend AdminApi;
friend ClientApi;
friend MathApi;
friend PersonalitiesApi;
friend PlayerApi;
friend SolarApi;
friend ZoneApi;

static ClientId ExtractClientID(const std::variant<uint, std::wstring_view>& player)
{
// If index is 0, we just use the client Id we are given
if (!player.index())
{
const uint id = std::get<uint>(player);
return IsValidClientId(id) ? id : -1;
}

// Otherwise we have a character name
const std::wstring_view characterName = std::get<std::wstring_view>(player);

const auto client = GetClientIdFromCharName(characterName).Raw();
if (client.has_error())
{
return UINT_MAX;
}

return client.value();
}

public:
/**
* Gets the current client id of the account.
* @param acc CAccount
* @returns On success : Client id of the active user of the account.
* @returns On fail : [PlayerNotLoggedIn] The function could not find a client id associated with the account id.
*/
static Action<uint, Error> GetClientIdFromAccount(const CAccount* acc);

static std::wstring GetAccountIdByClientID(ClientId client);

static CAccount* GetAccountByClientID(ClientId client);

/**
* Gets the current client id of the character.
* @param character Wide string of the character name
* @returns On success : current client Id associated with that character name
* @returns On fail : [CharacterDoesNotExist] The function could not find a client id associated with this character name.
*/
static Action<uint, Error> GetClientIdFromCharName(std::wstring_view character);

/**
* Gets the account of the character
* @param character Wide string of the character name
* @returns On success : the account Id for that character
* @returns On fail : [CharacterDoesNotExist] The function could not find the account id associated with this character name.
*/
static Action<CAccount*, Error> GetAccountByCharName(std::wstring_view character);

/**
* Gets the account id in a wide string
* @param acc The account
* @returns On success : wide string of account Id
* @returns On fail : [CannotGetAccount] The function could not find the account.
*/
static Action<std::wstring, Error> GetAccountID(CAccount* acc);

static Action<std::wstring, Error> GetCharacterNameByID(ClientId client);

/**
* Checks to see if the client Id is valid
* @param id Client Id
* @returns If Valid: true
* @returns If Not Valid: false
*/
static bool IsValidClientId(ClientId id);

static bool IsInCharSelectMenu(const uint& player);

static Action<ClientId, Error> GetClientIdByShip(ShipId ship);

static void PrintUserCmdText(ClientId client, std::wstring_view text);
static void PrintLocalUserCmdText(ClientId client, std::wstring_view msg, float distance);
};

#include "API/FLServer/Admin.hpp"
#include "API/FLServer/Chat.hpp"
#include "API/FLServer/Client.hpp"
#include "API/FLServer/GameObject.hpp"
#include "API/FLServer/Math.hpp"
#include "API/FLServer/Personalities.hpp"
#include "API/FLServer/Player.hpp"
#include "API/FLServer/Solar.hpp"
#include "API/FLServer/ZoneUtilities.hpp"

#include "API/FLHook/ClientInfo.hpp"
Expand All @@ -110,3 +16,72 @@ class DLL Api
#include "API/Utils/FileUtils.hpp"
#include "API/Utils/IniUtils.hpp"
#include "API/Utils/PerfTimer.hpp"
#include "API/Types/ClientId.hpp"
#include "API/Types/BaseId.hpp"
#include "Api/Types/ShipId.hpp"
#include "Api/Types/SystemId.hpp"


namespace HkApi
{
// Making sure these functions is only accessible within Flhook

/**
* Gets the current client id of the account.
* @param acc CAccount
* @returns On success : Client id of the active user of the account.
* @returns On fail : [PlayerNotLoggedIn] The function could not find a client id associated with the account id.
*/
Action<uint, Error> GetClientIdFromAccount(const CAccount* acc);

std::wstring GetAccountIdByClientID(ClientId client);

CAccount* GetAccountByClientID(ClientId client);

/**
* Gets the current client id of the character.
* @param character Wide string of the character name
* @returns On success : current client Id associated with that character name
* @returns On fail : [CharacterDoesNotExist] The function could not find a client id associated with this character name.
*/
Action<uint, Error> GetClientIdFromCharName(std::wstring_view character);

/**
* Gets the account of the character
* @param character Wide string of the character name
* @returns On success : the account Id for that character
* @returns On fail : [CharacterDoesNotExist] The function could not find the account id associated with this character name.
*/
Action<CAccount*, Error> GetAccountByCharName(std::wstring_view character);

/**
* Gets the account id in a wide string
* @param acc The account
* @returns On success : wide string of account Id
* @returns On fail : [CannotGetAccount] The function could not find the account.
*/
DLL Action<std::wstring, Error> GetAccountID(CAccount* acc);

DLL Action<std::wstring, Error> GetCharacterNameByID(ClientId client);

/**
* Checks to see if the client Id is valid
* @param id Client Id
* @returns If Valid: true
* @returns If Not Valid: false
*/
DLL bool IsValidClientId(ClientId id);

DLL bool IsInCharSelectMenu(const uint& player);

DLL Action<ClientId, Error> GetClientIdByShip(ShipId ship);

DLL void PrintUserCmdText(ClientId client, std::wstring_view text);
DLL void PrintLocalUserCmdText(ClientId client, std::wstring_view msg, float distance);

#ifdef FLHOOK


#endif

} // namespace HkApi
33 changes: 18 additions & 15 deletions include/API/FLServer/Admin.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
#pragma once

class DLL Admin
namespace Hk
{
static std::wstring GetPlayerIP(ClientId client);
static Action<PlayerInfo, Error> GetPlayerInfo(const std::variant<uint, std::wstring_view>& player, bool alsoCharmenu);
static std::list<PlayerInfo> GetPlayers();
static Action<DPN_CONNECTION_INFO, Error> GetConnectionStats(ClientId client);
static Action<void, Error> ChangeNPCSpawn(bool disable);
static Action<BaseHealth, Error> GetBaseStatus(std::wstring_view basename);
static Fuse* GetFuseFromID(uint fuseId);
static bool LightFuse(IObjRW* ship, uint fuseId, float delay, float lifetime, float skip);
static bool UnLightFuse(IObjRW* ship, uint fuseId);
static CEqObj* GetEqObjFromObjRW(IObjRW* objRW);
static Action<void, Error> AddRoles(std::wstring_view characterName, const std::vector<std::wstring_view>& roles);
static Action<void, Error> RemoveRoles(std::wstring_view characterName, const std::vector<std::wstring_view>& roles, bool clear);
static Action<void, Error> SetRoles(std::wstring_view characterName, const std::vector<std::wstring_view>& roles);
};
class DLL Admin
{
static std::wstring GetPlayerIP(ClientId client);
static Action<PlayerInfo, Error> GetPlayerInfo(const std::variant<uint, std::wstring_view>& player, bool alsoCharmenu);
static std::list<PlayerInfo> GetPlayers();
static Action<DPN_CONNECTION_INFO, Error> GetConnectionStats(ClientId client);
static Action<void, Error> ChangeNPCSpawn(bool disable);
static Action<BaseHealth, Error> GetBaseStatus(std::wstring_view basename);
static Fuse* GetFuseFromID(uint fuseId);
static bool LightFuse(IObjRW* ship, uint fuseId, float delay, float lifetime, float skip);
static bool UnLightFuse(IObjRW* ship, uint fuseId);
static CEqObj* GetEqObjFromObjRW(IObjRW* objRW);
static Action<void, Error> AddRoles(std::wstring_view characterName, const std::vector<std::wstring_view>& roles);
static Action<void, Error> RemoveRoles(std::wstring_view characterName, const std::vector<std::wstring_view>& roles, bool clear);
static Action<void, Error> SetRoles(std::wstring_view characterName, const std::vector<std::wstring_view>& roles);
};
}
File renamed without changes.
2 changes: 0 additions & 2 deletions include/API/FLServer/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ namespace Hk::Player
DLL Action<float, Error> GetRep(const std::variant<uint, std::wstring_view>& player, const std::variant<uint, std::wstring_view>& repGroup);
DLL Action<std::list<std::wstring>, Error> ReadCharFile(const std::variant<uint, std::wstring_view>& player);
DLL Action<void, Error> WriteCharFile(const std::variant<uint, std::wstring_view>& player, std::wstring data);
DLL Action<void, Error> PlayerRecalculateCRC(ClientId client);
DLL std::wstring GetPlayerSystemS(ClientId client);
DLL bool IsInRange(ClientId client, float distance);
DLL Action<void, Error> SetEquip(const std::variant<uint, std::wstring_view>& player, const st6::list<EquipDesc>& equip);
DLL Action<void, Error> AddEquip(const std::variant<uint, std::wstring_view>& player, uint goodId, const std::wstring& hardpoint);
DLL Action<void, Error> AntiCheat(ClientId client);
DLL void DelayedKick(ClientId client, uint secs);
DLL void DeleteCharacter(CAccount* acc, const std::wstring& character);
DLL Action<void, Error> NewCharacter(CAccount* acc, std::wstring& character);
Expand Down
25 changes: 25 additions & 0 deletions include/API/Types/BaseId.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

class BaseId
{
const uint value;

public:
explicit BaseId(const uint val) : value(val) {}
explicit BaseId(std::wstring_view name, bool isWildCard = false);
explicit operator uint() const noexcept { return value; }
bool operator==(const BaseId next) const { return value == next.value; }
bool operator!() const; // TODO: Check if BaseId is valid here



std::vector<ClientId> GetDockedPlayers();
void* GetMarket(); // Grab the bases market data.
std::optional<std::wstring> GetAffiliation();
//TODO: @Laz, look into getting the physical base from abstract baseID.
std::wstring GetName();
// std::pair<std::wstring, uint> GetDescription();

bool ToggleDocking(bool locked); //TODO: THis would be done via the CSolar.

};
58 changes: 58 additions & 0 deletions include/API/Types/ClientId.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#pragma once

class BaseId;
class ShipId;

class ClientId
{
const uint value;

Action<void, Error> AdjustCash(int amount);

public:
explicit ClientId(const uint val) : value(val) {}
explicit ClientId(std::wstring_view name);
explicit operator uint() const noexcept { return value; }
bool operator==(const ClientId next) const { return value == next.value; }
bool operator!() const { return !(value > 0 && value < 256); }

// Returns the underlying value of the ClientId, it is generally recommended to not use this.
uint GetValue();

// Type Conversions

std::wstring_view GetCharacterName();
// TODO: These eventually will be their own types as well
BaseId GetBaseId();
SystemId GetSystemId();
CAccount* GetAccount();
Archetype::Ship* GetShipArch();
ShipId GetShipId();
// std::list<ArchId> GetEquip();
CPlayerGroup* GetGroup();
std::optional<std::wstring> GetAffiliation();
CShip* GetShip();
uint GetRank();
uint GetWealth();
Action<int, Error> GetPvpKills();
Action<uint, Error> GetCash();

// State Checks

bool InSpace();
bool InCharacterSelect();
bool IsAlive();

// Manipulation

Action<void, Error> Kick(std::optional<std::wstring_view> reason = {}, std::optional<uint> delay = 10);
Action<void, Error> SaveChar();
Action<void, Error> SetPvpKills(uint killAmount);
Action<void, Error> AddCash(uint amount);
Action<void, Error> RemoveCash(uint amount);
Action<void, Error> Beam(std::variant<BaseId, std::wstring_view> base);
Action<void, Error> Message(std::wstring message, std::optional<MessageFormat> format, std::optional<MessageColor> color);
Action<void, Error> SetRep(std::variant<ushort, std::wstring_view> repGroup, float rep);
Action<void, Error> Rename(std::wstring_view);
void MarkObject(uint objId, int markStatus);
};
16 changes: 16 additions & 0 deletions include/API/Types/ObjectId.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

class ObjectId
{
const uint value;

public:
explicit ObjectId(const uint val) : value(val) {}
explicit operator uint() const noexcept { return value; }
bool operator==(const ObjectId next) const { return value == next.value; }
bool operator!() const;

ObjectType GetObjectType();
std::wstring GetNickName();

};
45 changes: 45 additions & 0 deletions include/API/Types/ShipId.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

class SystemId;

class ShipId
{
const uint value;

public:
explicit ShipId(const uint val) : value(val) {}
explicit operator uint() const noexcept { return value; }
bool operator==(const ShipId next) const { return value == next.value; }
bool operator!() const; // TODO: Check if shipId is valid

std::wstring GetNickname();
std::wstring GetName();
CShip* GetCShip();
Archetype::Ship* GetArchetype();
float GetHealth(bool percentage = false);
st6::list<EquipDesc>& GetEquipment(); // TODO: We should define a lambda to make it easy for people to get Equip lists.
float GetShields(bool percentage = false);
void* GetCargo(); // TODO: Similar to equipment but for cargo (duh).
void* GetNpcPersonality();
std::optional<ShipId> GetTarget();
std::wstring GetAffiliation();
// TODO: AI states such as formation, go to, dock etc.
SystemId GetSystem();
Vector GetPosition();
Matrix GetOrientation();
Vector GetVelocity();
float GetSpeed();

bool IsPlayer();
bool IsNpc();
bool IsInTradeLane();

void Destroy(DestroyType type = DestroyType::Fuse);
void SetHealth(float amount, bool percentage = false);
void AddCargo(std::wstring_view good, int count, bool mission);
void SetEquip(const st6::list<EquipDesc>& equip);
void AddEquip(uint goodId, const std::wstring& hardpoint);
void Relocate(Vector, std::optional<Matrix> orientation);

// TODO: SetShields() potentially, @Aingar should know more about this.
};
Loading

0 comments on commit de133b4

Please sign in to comment.