Skip to content

Commit

Permalink
added get player ip function, added functions for starting/stopping f…
Browse files Browse the repository at this point in the history
…uses, more cleanup
  • Loading branch information
Lazrius committed Nov 14, 2023
1 parent b621d0c commit 5ef0f28
Show file tree
Hide file tree
Showing 17 changed files with 266 additions and 249 deletions.
20 changes: 20 additions & 0 deletions include/API/Types/AccountId.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

class AccountId final
{
CAccount* value = nullptr;

public:
explicit AccountId(ClientId client);
explicit AccountId(std::wstring_view characterName);
explicit AccountId() = default;

bool operator==(const CAccount* next) const { return value == next; }
explicit operator bool() const;

[[nodiscard]]
CAccount* GetValue() const
{
return value;
}
};
3 changes: 2 additions & 1 deletion include/API/Types/BaseId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class BaseId
Action<ObjectId, Error> GetSpaceId() const;
Action<RepId, Error> GetAffiliation() const;
Action<std::wstring_view, Error> GetName() const;
Action<std::pair<std::wstring_view, std::wstring_view>, Error> GetDescription();
Action<std::pair<float, float>, Error> GetBaseHealth() const;
Action<std::pair<std::wstring_view, std::wstring_view>, Error> GetDescription() const;

Action<std::vector<uint>, Error> GetItemsForSale() const;

Expand Down
19 changes: 16 additions & 3 deletions include/API/Types/ClientId.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "API/Types/AccountId.hpp"
#include "API/Types/BaseId.hpp"
#include "API/Types/ShipId.hpp"
#include "API/Types/SystemId.hpp"
Expand Down Expand Up @@ -33,7 +34,6 @@ class ClientId
explicit operator bool() const;

// Returns the underlying value of the ClientId, it is generally recommended to not use this.

[[nodiscard]]
uint GetValue() const
{
Expand Down Expand Up @@ -68,11 +68,11 @@ class ClientId

/**
* @brief Gets the Account of the clientId
* @returns On success : CAccount pointer of the Account.
* @returns On success : An account id class representing the Account.
* @returns On fail : InvalidClientId if the client check fails.
*/
[[nodiscard]]
Action<CAccount *, Error> GetAccount() const;
Action<AccountId, Error> GetAccount() const;

/**
* @brief Gets the Shiparch of the ship the client is using
Expand Down Expand Up @@ -161,6 +161,19 @@ class ClientId
*/
[[nodiscard]]
ClientData &GetData() const;

/**
* @brief Gets the ip of the connected client
* @returns On success : A string containing the player's ip address
* @returns On fail : InvalidClientId
*/
[[nodiscard]]
Action<std::wstring, Error> GetPlayerIp() const;

/**
* @brief Get's the current engine state of the client
* @returns A enum representing the engine state, defaulting to the player not being in space.
*/
[[nodiscard]]
EngineState GetEngineState() const;

Expand Down
5 changes: 4 additions & 1 deletion include/API/Types/ShipId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ShipId final : public ObjectId
{
public:
explicit ShipId(const uint val) : ObjectId(val) {}
explicit ShipId() {}
explicit ShipId() = default;
explicit ShipId(const ShipId& id) : ObjectId(id.GetValue()) {}

[[nodiscard]]
Expand Down Expand Up @@ -57,4 +57,7 @@ class ShipId final : public ObjectId

return { equipment };
}

Action<void, Error> IgniteFuse(uint fuseId, float id = 0.0f) const;
Action<void, Error> ExtinguishFuse(uint fuseId, float id = 0.0f) const;
};
2 changes: 1 addition & 1 deletion include/Core/ClientServerInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class IServerImplHook
std::wstring characterName;
};

inline static const std::unique_ptr<SubmitData> chatData;
inline static std::unique_ptr<SubmitData> chatData;
inline static std::wstring charBefore;

// The maximum number of players we can support is MaxClientId
Expand Down
1 change: 1 addition & 0 deletions include/Core/FLHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class FLHook final
friend IServerImplHook;
friend IClientImpl;
friend InternalApi;
friend ClientId;

// Static things

Expand Down
6 changes: 0 additions & 6 deletions include/Defs/Structs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ struct PlayerInfo
std::wstring hostname;
};

struct BaseHealth
{
float currentHealth;
float maxHealth;
};

struct DataMarketItem
{
uint archId;
Expand Down
1 change: 1 addition & 0 deletions project/FLHook.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
<ClInclude Include="..\include\API\FLHook\InfocardManager.hpp" />
<ClInclude Include="..\Include\API\FLHook\MailManager.hpp" />
<ClInclude Include="..\Include\API\FLHook\Plugin.hpp" />
<ClInclude Include="..\include\API\Types\AccountId.hpp" />
<ClInclude Include="..\Include\API\Types\BaseId.hpp" />
<ClInclude Include="..\Include\API\Types\ClientId.hpp" />
<ClInclude Include="..\include\API\Types\GroupId.hpp" />
Expand Down
3 changes: 3 additions & 0 deletions project/FLHook.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -543,5 +543,8 @@
<ClInclude Include="..\include\API\Utils\Codec.hpp">
<Filter>Include\API\Utils</Filter>
</ClInclude>
<ClInclude Include="..\include\API\Types\AccountId.hpp">
<Filter>Include\API\Types</Filter>
</ClInclude>
</ItemGroup>
</Project>
150 changes: 1 addition & 149 deletions source/API/FLServer/Admin.cpp
Original file line number Diff line number Diff line change
@@ -1,155 +1,7 @@
#include "PCH.hpp"

#include "API/FLServer/Admin.hpp"
#include "API/FLServer/Client.hpp"
#include "Core/FLHook.hpp"
#include "Core/ApiInternal.hpp"


std::wstring GetPlayerIP(ClientId client)
{
const CDPClientProxy* cdpClient = FLHook::clientProxyArray[client - 1];
if (!cdpClient)
{
return L"";
}

// get ip
char* P1;
char* IdirectPlay8Address;
wchar_t hostname[] = L"hostname";
memcpy(&P1, DWORD(FLHook::cdpServer) + 4, 4);

wchar_t wIp[1024] = L"";
long sizeofIP = sizeof wIp;
long dataType = 1;
__asm {
push 0 ; flags
lea edx, IdirectPlay8Address
push edx ; address
mov edx, [cdpClient]
mov edx, [edx+8]
push edx ; dpnid
mov eax, [P1]
push eax
mov ecx, [eax]
call dword ptr[ecx + 0x28] ; GetClientAddress
cmp eax, 0
jnz some_error

lea eax, dataType
push eax
lea eax, sizeofIP
push eax
lea eax, wIP
push eax
lea eax, hostname
push eax
mov ecx, [IdirectPlay8Address]
push ecx
mov ecx, [ecx]
call dword ptr[ecx+0x40] ; GetComponentByName

mov ecx, [IdirectPlay8Address]
push ecx
mov ecx, [ecx]
call dword ptr[ecx+0x08] ; Release
some_error:
}

return wIp;
}

Action<PlayerInfo, Error> GetPlayerInfo(const std::variant<uint, std::wstring_view>& player, bool alsoCharmenu)
{
ClientId client = HkApi::ExtractClientID(player);

if (client == UINT_MAX || (Client::IsInCharSelectMenu(client) && !alsoCharmenu))
{
return { cpp::fail(Error::PlayerNotLoggedIn) };
}

PlayerInfo pi;
const wchar_t* activeCharname = (wchar_t*)Players.GetActiveCharacterName(client);

pi.client = client;
pi.character = activeCharname ? activeCharname : L"";
pi.baseName = pi.systemName = L"";

uint base = 0;
uint system = 0;
pub::Player::GetBase(client, base);
pub::Player::GetSystem(client, system);
pub::Player::GetShip(client, pi.ship);

if (base)
{
char Basename[1024] = "";
pub::GetBaseNickname(Basename, sizeof Basename, base);
pi.baseName = StringUtils::stows(Basename);
}

if (system)
{
char Systemname[1024] = "";
pub::GetSystemNickname(Systemname, sizeof Systemname, system);
pi.systemName = StringUtils::stows(Systemname);
pi.system = system;
}

// get ping
auto ci = GetConnectionStats(client).Raw();
if (ci.has_error())
{
FLHook::GetLogger().Log(LogLevel::Warn, L"Invalid client ID provided when getting connection stats");
return { cpp::fail(Error::PlayerNotLoggedIn) };
}
pi.connectionInfo = ci.value();

// get ip
pi.IP = GetPlayerIP(client);

pi.hostname = ClientInfo::At(client).hostname;

return { pi };
}

std::list<PlayerInfo> GetPlayers()
{
std::list<PlayerInfo> ret;

PlayerData* playerDb = nullptr;
while ((playerDb = Players.traverse_active(playerDb)))
{
ClientId client = playerDb->onlineId;

if (Client::IsInCharSelectMenu(client))
{
continue;
}

ret.emplace_back(GetPlayerInfo(client, false).Unwrap());
}
return ret;
}

Action<DPN_CONNECTION_INFO, Error> GetConnectionStats(ClientId client)
{
if (client < 1 || client > MaxClientId)
{
return { cpp::fail(Error::InvalidClientId) };
}

CDPClientProxy* cdpClient = FLHook::clientProxyArray[client - 1];

DPN_CONNECTION_INFO ci;
if (!cdpClient || !cdpClient->GetConnectionStats(&ci))
{
return { cpp::fail(Error::InvalidClientId) };
}

return { ci };
}
#include "Core/FLHook.hpp"

Action<void, Error> ChangeNPCSpawn(bool disable)
{
Expand Down
19 changes: 18 additions & 1 deletion source/API/Types/BaseId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,26 @@ Action<std::wstring_view, Error> BaseId::GetName() const

return { FLHook::GetInfocardManager().GetInfocard(base->baseIdS) };
}
Action<std::pair<std::wstring_view, std::wstring_view>, Error> BaseId::GetDescription()

Action<std::pair<float, float>, Error> BaseId::GetBaseHealth() const
{
float curHealth;
float maxHealth;
const Universe::IBase* base = Universe::get_base(value);

if (!base)
{
return { cpp::fail(Error::InvalidBase) };
}

pub::SpaceObj::GetHealth(base->spaceObjId, curHealth, maxHealth);
return { std::make_pair(curHealth, maxHealth) };
}

Action<std::pair<std::wstring_view, std::wstring_view>, Error> BaseId::GetDescription() const
{
ValidBaseCheck;

// TODO: Get internal description of base
}

Expand Down
Loading

0 comments on commit 5ef0f28

Please sign in to comment.