Skip to content
Open
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
2 changes: 0 additions & 2 deletions Source/FLHook/FLHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,6 @@ void ProcessEvent(wstring wscText, ...)

wscText = wszBuf;

CALL_PLUGINS_V(PLUGIN_ProcessEvent_BEFORE, , (wstring &wscText), (wscText));

foreach(lstSockets, SOCKET_CONNECTION*, i)
{
if ((*i)->csock.bEventMode)
Expand Down
4 changes: 3 additions & 1 deletion Source/FLHook/HkCbIClientImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ bool HkIClientImpl::Send_FLPACKET_SERVER_CHARACTERINFO(uint iClientID, FLPACKET_
ISERVER_LOG();
ISERVER_LOGARG_UI(iClientID);

ClientInfo[iClientID].iCharMenuEnterTime = time(0);

CALL_CLIENT_METHOD(Send_FLPACKET_SERVER_CHARACTERINFO(iClientID, pDunno));
return reinterpret_cast<bool>(vRet);
}
Expand Down Expand Up @@ -1111,7 +1113,7 @@ bool HkIClientImpl::Startup(uint iDunno, uint iDunno2)

bi.scBasename = szBaseName;
bi.iBaseID = CreateID(szBaseName);
lstBases.push_back(bi);
lstBases[bi.iBaseID] = bi;
pub::System::LoadSystem(base->iSystemID);

base = Universe::GetNextBase();
Expand Down
80 changes: 7 additions & 73 deletions Source/FLHook/HkCbIServerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ namespace HkIServerImpl

CHECK_FOR_DISCONNECT

ClientInfo[iClientID].iCharMenuEnterTime = 0;

CALL_PLUGINS_V(PLUGIN_HkIServerImpl_CharacterSelect, __stdcall, (struct CHARACTER_ID const & cId, unsigned int iClientID), (cId, iClientID));

wstring wscCharBefore;
Expand All @@ -482,36 +484,17 @@ namespace HkIServerImpl
if (set_bUserCmdHelp)
PrintUserCmdText(iClientID, L"To get a list of available commands, type \"/help\" in chat.");

// anti-cheat check
list <CARGO_INFO> lstCargo;
int iHold;
HkEnumCargo(ARG_CLIENTID(iClientID), lstCargo, iHold);
foreach(lstCargo, CARGO_INFO, it)
{
if ((*it).iCount < 0)
{
HkAddCheaterLog(wscCharname, L"Negative good-count, likely to have cheated in the past");

wchar_t wszBuf[256];
swprintf(wszBuf, L"Possible cheating detected (%s)", wscCharname.c_str());
HkMsgU(wszBuf);
HkBan(ARG_CLIENTID(iClientID), true);
HkKick(ARG_CLIENTID(iClientID));
return;
}
}

// event
CAccount *acc = Players.FindAccountFromClientID(iClientID);
wstring wscDir;
HkGetAccountDirName(acc, wscDir);
HKPLAYERINFO pi;
HkGetPlayerInfo(ARG_CLIENTID(iClientID), pi, false);
wstring playerIP;
HkGetPlayerIP(iClientID, playerIP);
ProcessEvent(L"login char=%s accountdirname=%s id=%d ip=%s",
wscCharname.c_str(),
wscDir.c_str(),
iClientID,
pi.wscIP.c_str());
playerIP.c_str());
}
} CATCH_HOOK({})

Expand Down Expand Up @@ -704,19 +687,12 @@ namespace HkIServerImpl

EXECUTE_SERVER_CALL(Server.TerminateTrade(iClientID, iAccepted));

TRY_HOOK {
if (iAccepted)
{ // save both chars to prevent cheating in case of server crash
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to remove this? It seems to me that removing this creates an obvious duplication cheat.

  1. Let's say I have characters A and B in game. Character A has 0 credits and character B has 100 million.
  2. I use a trade to move 100 million from character B to character A.
  3. I then take character A, dock it and log it off, saving those credits.
  4. I then park character B in space and wait for some server crash (or do it myself if I know some behaviour that might trigger one), never having the new character file saved.
  5. Now I have two characters with 100 million credits.

HkSaveChar(ARG_CLIENTID(iClientID));
if (ClientInfo[iClientID].iTradePartner)
HkSaveChar(ARG_CLIENTID(ClientInfo[iClientID].iTradePartner));
}

if (ClientInfo[iClientID].iTradePartner)
ClientInfo[ClientInfo[iClientID].iTradePartner].iTradePartner = 0;
ClientInfo[iClientID].iTradePartner = 0;

} CATCH_HOOK({})


CALL_PLUGINS_V(PLUGIN_HkIServerImpl_TerminateTrade_AFTER, __stdcall, (unsigned int iClientID, int iAccepted), (iClientID, iAccepted));
}
Expand Down Expand Up @@ -1017,50 +993,8 @@ namespace HkIServerImpl
return;
}

CALL_PLUGINS_V(PLUGIN_HkIServerImpl_Login, __stdcall, (struct SLoginInfo const &li, unsigned int iClientID), (li, iClientID));


// check for ip ban
wstring wscIP;
HkGetPlayerIP(iClientID, wscIP);

foreach(set_lstBans, wstring, itb)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we seem to be getting rid of random things without proper cleanup here - set_lstBans is still defined somewhere

{
if (Wildcard::wildcardfit(wstos(*itb).c_str(), wstos(wscIP).c_str()))
{
HkAddKickLog(iClientID, L"IP ban(%s matches %s)", wscIP.c_str(), (*itb).c_str());
if (set_bBanAccountOnMatch)
HkBan(ARG_CLIENTID(iClientID), true);
HkKick(ARG_CLIENTID(iClientID));
}
}

// count players
struct PlayerData *pPD = 0;
uint iPlayers = 0;
while (pPD = Players.traverse_active(pPD))
iPlayers++;

if (iPlayers > (Players.GetMaxPlayerCount() - set_iReservedSlots))
{ // check if player has a reserved slot
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're getting rid of the reserved slots functionality altogether, HkSetReservedSlot/CmdSetReservedSlot/HkGetReservedSlot/CmdGetReservedSlot must go too

CAccount *acc = Players.FindAccountFromClientID(iClientID);
wstring wscDir;
HkGetAccountDirName(acc, wscDir);
string scUserFile = scAcctPath + wstos(wscDir) + "\\flhookuser.ini";

bool bReserved = IniGetB(scUserFile, "Settings", "ReservedSlot", false);
if (!bReserved)
{
HkKick(acc);
return;
}
}

LoadUserSettings(iClientID);

// log
if (set_bLogConnects)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

HkAddConnectLog(iClientID, wscIP);

} CATCH_HOOK({
CAccount *acc = Players.FindAccountFromClientID(iClientID);
Expand All @@ -1070,7 +1004,7 @@ namespace HkIServerImpl
}
})

CALL_PLUGINS_V(PLUGIN_HkIServerImpl_Login_AFTER, __stdcall, (struct SLoginInfo const &li, unsigned int iClientID), (li, iClientID));
CALL_PLUGINS_V(PLUGIN_HkIServerImpl_Login, __stdcall, (struct SLoginInfo const& li, unsigned int iClientID), (li, iClientID));
}

/**************************************************************************************************************
Expand Down
14 changes: 4 additions & 10 deletions Source/FLHook/HkDataBaseMarket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,13 @@ bool HkLoadBaseMarket()
continue;

const char *szBaseName = ini.get_value_string();
BASE_INFO *biBase = 0;
foreach(lstBases, BASE_INFO, it)
const auto& baseIter = lstBases.find(CreateID(szBaseName));
if (baseIter == lstBases.end())
{
const char *szBN = it->scBasename.c_str();
if (!ToLower(it->scBasename).compare(ToLower(szBaseName)))
{
biBase = &(*it);
break;
}
continue;
}

if (!biBase)
continue; // base not found
BASE_INFO* biBase = &baseIter->second;

ini.read_value();

Expand Down
4 changes: 2 additions & 2 deletions Source/FLHook/HkFuncTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ uint HkGetClientIdFromAccount(CAccount *acc)

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

uint HkGetClientIdFromPD(struct PlayerData *pPD)
inline uint HkGetClientIdFromPD(struct PlayerData *pPD)
{
return pPD->iOnlineID;
}
Expand Down Expand Up @@ -300,7 +300,7 @@ wstring HkGetPlayerSystem(uint iClientID)
{
uint iSystemID;
pub::Player::GetSystem(iClientID, iSystemID);
char szSystemname[1024] = "";
char szSystemname[64] = "";
pub::GetSystemNickname(szSystemname, sizeof(szSystemname), iSystemID);
return stows(szSystemname);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/FLHook/HkInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ char *g_FLServerDataPtr;

_GetShipInspect GetShipInspect;

list<BASE_INFO> lstBases;
unordered_map<uint, BASE_INFO> lstBases;

char szRepFreeFixOld[5];

Expand Down
46 changes: 19 additions & 27 deletions Source/FLHook/HkTimers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ void HkTimerCheckKick()
TRY_HOOK {
// for all players
struct PlayerData *pPD = 0;
mstime msTime = timeInMS();
time_t currTime = time(0);
while (pPD = Players.traverse_active(pPD))
{
uint iClientID = HkGetClientIdFromPD(pPD);
Expand All @@ -57,43 +59,33 @@ void HkTimerCheckKick()

if (ClientInfo[iClientID].tmKickTime)
{
if (timeInMS() >= ClientInfo[iClientID].tmKickTime)
if (msTime >= ClientInfo[iClientID].tmKickTime)
{
HkKick(ARG_CLIENTID(iClientID)); // kick time expired
ClientInfo[iClientID].tmKickTime = 0;
}
continue; // player will be kicked anyway
}

if (set_iAntiBaseIdle)
if (set_iAntiBaseIdle && ClientInfo[iClientID].iBaseEnterTime)
{ // anti base-idle check
uint iBaseID;
pub::Player::GetBase(iClientID, iBaseID);
if (iBaseID && ClientInfo[iClientID].iBaseEnterTime)
if ((currTime - ClientInfo[iClientID].iBaseEnterTime) >= set_iAntiBaseIdle)
{
if ((time(0) - ClientInfo[iClientID].iBaseEnterTime) >= set_iAntiBaseIdle)
{
HkAddKickLog(iClientID, L"Base idling");
HkMsgAndKick(iClientID, L"Base idling", set_iKickMsgPeriod);
ClientInfo[iClientID].iBaseEnterTime = 0;
}
HkAddKickLog(iClientID, L"Base idling");
HkMsgAndKick(iClientID, L"Base idling", set_iKickMsgPeriod);
ClientInfo[iClientID].iBaseEnterTime = 0;
}
continue;
}

if (set_iAntiCharMenuIdle)
{ // anti charmenu-idle check
if (HkIsInCharSelectMenu(iClientID)) {
if (!ClientInfo[iClientID].iCharMenuEnterTime)
ClientInfo[iClientID].iCharMenuEnterTime = (uint)time(0);
else if ((time(0) - ClientInfo[iClientID].iCharMenuEnterTime) >= set_iAntiCharMenuIdle) {
HkAddKickLog(iClientID, L"Charmenu idling");
HkKick(ARG_CLIENTID(iClientID));
ClientInfo[iClientID].iCharMenuEnterTime = 0;
continue;
}
}
else
if (ClientInfo[iClientID].iCharMenuEnterTime
&& (currTime - ClientInfo[iClientID].iCharMenuEnterTime) >= set_iAntiCharMenuIdle) {
HkAddKickLog(iClientID, L"Charmenu idling");
HkKick(ARG_CLIENTID(iClientID));
ClientInfo[iClientID].iCharMenuEnterTime = 0;
}
}

}
Expand All @@ -106,21 +98,21 @@ Check if NPC spawns should be disabled

void HkTimerNPCAndF1Check()
{
//CALL_PLUGINS_V(PLUGIN_HkTimerNPCAndF1Check, , (), ());


TRY_HOOK {
struct PlayerData *pPD = 0;
struct PlayerData *pPD = nullptr;
mstime currTime = timeInMS();
while (pPD = Players.traverse_active(pPD))
{
uint iClientID = HkGetClientIdFromPD(pPD);
if (iClientID < 1 || iClientID > MAX_CLIENT_ID)
continue;

if (ClientInfo[iClientID].tmF1Time && (timeInMS() >= ClientInfo[iClientID].tmF1Time)) { // f1
if (ClientInfo[iClientID].tmF1Time && (currTime >= ClientInfo[iClientID].tmF1Time)) { // f1
Server.CharacterInfoReq(iClientID, false);
ClientInfo[iClientID].tmF1Time = 0;
}
else if (ClientInfo[iClientID].tmF1TimeDisconnect && (timeInMS() >= ClientInfo[iClientID].tmF1TimeDisconnect)) {
else if (ClientInfo[iClientID].tmF1TimeDisconnect && (currTime >= ClientInfo[iClientID].tmF1TimeDisconnect)) {
ulong lArray[64] = { 0 };
lArray[26] = iClientID;
__asm
Expand Down
3 changes: 2 additions & 1 deletion Source/FLHook/Hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "flcodec.h"

#include <plugin.h>
#include <unordered_map>

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// defines
Expand Down Expand Up @@ -848,7 +849,7 @@ namespace HkIEngine
void HkTimerCheckKick();
void HkTimerNPCAndF1Check();

extern EXPORT list<BASE_INFO> lstBases;
extern EXPORT unordered_map<uint, BASE_INFO> lstBases;

// namespaces
namespace HkIServerImpl
Expand Down
24 changes: 24 additions & 0 deletions Source/FLHookPluginSDK/headers/FLCoreCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@
#define OBJ_ASTEROID (1 << 29)


enum EquipmentClass : uint
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok but I don't see what this has to do with optimisations

{
None = 0,
LightEquip = 1 << 0,
AttachedFx = 1 << 1, // contrails
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are 1<<2, 1<<3, 1<<4?

Mine = 1 << 5,
CM = 1 << 6,
Gun = 1 << 7,
Shield = 1 << 8,
ShieldGenerator = 1 << 9,
Thruster = 1 << 10,
CargoPod = 1 << 11,
CloakingDevice = 1 << 12,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are 1<<13, 1<<14, 1<<15?

Cargo = 1 << 16, // commodities, ammo
Engine = 1 << 17,
Power = 1 << 18,
Scanner = 1 << 19,
TractorBeam = 1 << 20,
RepairDroid = 1 << 21,
InternalFX = 1 << 22,
TradeLaneEquip = 1 << 23,
Armor = 1 << 24,
};

struct IMPORT CacheString
{
void clear(void);
Expand Down
3 changes: 2 additions & 1 deletion Source/FLHookPluginSDK/headers/FLHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <string>
#include <list>
#include <time.h>
#include <unordered_map>
using namespace std;


Expand Down Expand Up @@ -819,7 +820,7 @@ extern IMPORT bool set_bLogUserCmds;
extern IMPORT bool set_bPerfTimer;


extern IMPORT list<BASE_INFO> lstBases;
extern IMPORT unordered_map<uint, BASE_INFO> lstBases;

extern IMPORT CDPClientProxy **g_cClientProxyArray;
extern IMPORT void *pClient;
Expand Down