Skip to content

Commit

Permalink
Merge branch 'master' into feature/DeviceSelectionFixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dutchman101 authored Nov 21, 2024
2 parents 479f0f7 + f095410 commit 20a5659
Show file tree
Hide file tree
Showing 29 changed files with 189 additions and 27 deletions.
1 change: 0 additions & 1 deletion Client/core/CConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class CConsole : public CConsoleInterface
bool IsInputActive();
void ActivateInput();

void HandleTextAccepted(bool bHandled);
void GetCommandInfo(const std::string& strIn, std::string& strCmdOut, std::string& strCmdLineOut);

void ResetHistoryChanges();
Expand Down
4 changes: 4 additions & 0 deletions Client/mods/deathmatch/logic/CPacketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ void CPacketHandler::Packet_ServerDisconnected(NetBitStreamInterface& bitStream)
strReason = _("Disconnected: Serial verification failed");
strErrorCode = _E("CD44");
break;
case ePlayerDisconnectType::SERIAL_DUPLICATE:
strReason = _("Disconnected: Serial already in use");
strErrorCode = _E("CD50");
break;
case ePlayerDisconnectType::CONNECTION_DESYNC:
strReason = _("Disconnected: Connection desync %s");
strErrorCode = _E("CD45");
Expand Down
3 changes: 2 additions & 1 deletion Client/mods/deathmatch/logic/CPacketHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class CPacketHandler
BAN,
KICK,
CUSTOM,
SHUTDOWN
SHUTDOWN,
SERIAL_DUPLICATE
};

struct SEntityDependantStuff
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/rpc/CWorldRPCs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ void CWorldRPCs::SetSyncIntervals(NetBitStreamInterface& bitStream)
bitStream.Read(g_TickRateSettings.iObjectSync);
bitStream.Read(g_TickRateSettings.iKeySyncRotation);
bitStream.Read(g_TickRateSettings.iKeySyncAnalogMove);
bitStream.Read(g_TickRateSettings.iPedSyncerDistance);
bitStream.Read(g_TickRateSettings.iUnoccupiedVehicleSyncerDistance);
}

void CWorldRPCs::SetMoonSize(NetBitStreamInterface& bitStream)
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/StdInc.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <bochs_internal/bochs_crc32.h>
#include <pcrecpp.h>
#include <pthread.h>
#include "version.h"

extern class CNetServer* g_pRealNetServer;
extern class CGame* g_pGame;
6 changes: 6 additions & 0 deletions Server/mods/deathmatch/editor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@
Values: 0 - Off, 1 - Enabled. Default - 1 -->
<resource_client_file_checks>1</resource_client_file_checks>

<!-- This parameter determines that the server checks when the players connect that there are no other players with the same serial number.
Note that this may break compatibility with virtual machines.
Not guarantees that the player cannot manipulate their serial.
Values: 0 - Off, 1 - Enabled. Default - 1 -->
<check_duplicate_serials>1</check_duplicate_serials>

<!-- Specifies the module(s) which are loaded with the server. To load several modules, add more <module>
parameter(s). Optional parameter. -->
<!-- <module src="sample_win32.dll"/> -->
Expand Down
12 changes: 12 additions & 0 deletions Server/mods/deathmatch/local.conf
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,18 @@
Values: 0 - Off, 1 - Enabled. Default - 1 -->
<resource_client_file_checks>1</resource_client_file_checks>

<!-- Enables extra protection for element data.
When this option is enabled, the server ignores element data sync packets from the client,
except for allowed keys.
Values: 0 - Off, 1 - Enabled. Default - 0 -->
<elementdata_whitelisted>0</elementdata_whitelisted>

<!-- This parameter determines that the server checks when the players connect that there are no other players with the same serial number.
Note that this may break compatibility with virtual machines.
Not guarantees that the player cannot manipulate their serial.
Values: 0 - Off, 1 - Enabled. Default - 1 -->
<check_duplicate_serials>1</check_duplicate_serials>

<!-- Specifies the module(s) which are loaded with the server. To load several modules, add more <module>
parameter(s). Optional parameter. -->
<!-- <module src="sample_win32.dll"/> -->
Expand Down
9 changes: 8 additions & 1 deletion Server/mods/deathmatch/logic/CCustomData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void CCustomData::Copy(CCustomData* pCustomData)
}
}

SCustomData* CCustomData::Get(const char* szName)
SCustomData* CCustomData::Get(const char* szName) const
{
assert(szName);

Expand Down Expand Up @@ -100,6 +100,7 @@ void CCustomData::Set(const char* szName, const CLuaArgument& Variable, ESyncTyp
SCustomData newData;
newData.Variable = Variable;
newData.syncType = syncType;
newData.clientChangesMode = eCustomDataClientTrust::UNSET;
m_Data[szName] = newData;
UpdateSynced(szName, Variable, syncType);
}
Expand All @@ -120,6 +121,12 @@ bool CCustomData::Delete(const char* szName)
return false;
}

void CCustomData::SetClientChangesMode(const char* szName, eCustomDataClientTrust mode)
{
SCustomData& pData = m_Data[szName];
pData.clientChangesMode = mode;
}

CXMLNode* CCustomData::OutputToXML(CXMLNode* pNode)
{
std::map<std::string, SCustomData>::const_iterator iter = m_Data.begin();
Expand Down
16 changes: 13 additions & 3 deletions Server/mods/deathmatch/logic/CCustomData.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,33 @@ enum class ESyncType
SUBSCRIBE,
};

enum class eCustomDataClientTrust : std::uint8_t
{
UNSET,
ALLOW,
DENY,
};

struct SCustomData
{
CLuaArgument Variable;
ESyncType syncType;
CLuaArgument Variable;
ESyncType syncType;
eCustomDataClientTrust clientChangesMode;
};

class CCustomData
{
public:
void Copy(CCustomData* pCustomData);

SCustomData* Get(const char* szName);
SCustomData* Get(const char* szName) const;
SCustomData* GetSynced(const char* szName);
void Set(const char* szName, const CLuaArgument& Variable, ESyncType syncType = ESyncType::BROADCAST);

bool Delete(const char* szName);

void SetClientChangesMode(const char* szName, eCustomDataClientTrust mode);

unsigned short CountOnlySynchronized();

CXMLNode* OutputToXML(CXMLNode* pNode);
Expand Down
8 changes: 6 additions & 2 deletions Server/mods/deathmatch/logic/CElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ void CElement::ReadCustomData(CEvents* pEvents, CXMLNode& Node)
}
}

CLuaArgument* CElement::GetCustomData(const char* szName, bool bInheritData, ESyncType* pSyncType)
CLuaArgument* CElement::GetCustomData(const char* szName, bool bInheritData, ESyncType* pSyncType, eCustomDataClientTrust* clientChangesMode)
{
assert(szName);

Expand All @@ -518,13 +518,17 @@ CLuaArgument* CElement::GetCustomData(const char* szName, bool bInheritData, ESy
{
if (pSyncType)
*pSyncType = pData->syncType;

if (clientChangesMode)
*clientChangesMode = pData->clientChangesMode;

return &pData->Variable;
}

// If none, try returning parent's custom data
if (bInheritData && m_pParent)
{
return m_pParent->GetCustomData(szName, true, pSyncType);
return m_pParent->GetCustomData(szName, true, pSyncType, clientChangesMode);
}

// None available
Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class CElement

void ReadCustomData(CEvents* pEvents, CXMLNode& Node);
CCustomData& GetCustomDataManager() { return m_CustomData; }
CLuaArgument* GetCustomData(const char* szName, bool bInheritData, ESyncType* pSyncType = NULL);
CLuaArgument* GetCustomData(const char* szName, bool bInheritData, ESyncType* pSyncType = nullptr, eCustomDataClientTrust* clientChangesMode = nullptr);
CLuaArguments* GetAllCustomData(CLuaArguments* table);
bool GetCustomDataString(const char* szName, char* pOut, size_t sizeBuffer, bool bInheritData);
bool GetCustomDataInt(const char* szName, int& iOut, bool bInheritData);
Expand Down
35 changes: 34 additions & 1 deletion Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,7 @@ void CGame::AddBuiltInEvents()
m_Events.AddEvent("onPlayerTriggerEventThreshold", "", nullptr, false);
m_Events.AddEvent("onPlayerTeamChange", "oldTeam, newTeam", nullptr, false);
m_Events.AddEvent("onPlayerTriggerInvalidEvent", "eventName, isAdded, isRemote", nullptr, false);
m_Events.AddEvent("onPlayerChangesProtectedData", "element, key, value", nullptr, false);

// Ped events
m_Events.AddEvent("onPedVehicleEnter", "vehicle, seat, jacked", NULL, false);
Expand Down Expand Up @@ -1797,6 +1798,21 @@ void CGame::Packet_PlayerJoinData(CPlayerJoinDataPacket& Packet)
return;
}

// Check if another player is using the same serial
if (m_pMainConfig->IsCheckDuplicateSerialsEnabled() && m_pPlayerManager->GetBySerial(strSerial))
{
// Tell the console
CLogger::LogPrintf("CONNECT: %s failed to connect (Serial already in use) (%s)\n", szNick, strIPAndSerial.c_str());

// Tell the player the problem
if (pPlayer->CanBitStream(eBitStreamVersion::CheckDuplicateSerials))
DisconnectPlayer(this, *pPlayer, CPlayerDisconnectedPacket::SERIAL_DUPLICATE);
else
DisconnectPlayer(this, *pPlayer, CPlayerDisconnectedPacket::KICK);

return;
}

// Check the nick is valid
if (!CheckNickProvided(szNick))
{
Expand Down Expand Up @@ -2652,7 +2668,24 @@ void CGame::Packet_CustomData(CCustomDataPacket& Packet)
}

ESyncType lastSyncType = ESyncType::BROADCAST;
pElement->GetCustomData(szName, false, &lastSyncType);
eCustomDataClientTrust clientChangesMode{};

pElement->GetCustomData(szName, false, &lastSyncType, &clientChangesMode);

const bool changesAllowed = clientChangesMode == eCustomDataClientTrust::UNSET ? !m_pMainConfig->IsElementDataWhitelisted()
: clientChangesMode == eCustomDataClientTrust::ALLOW;
if (!changesAllowed)
{
CLogger::ErrorPrintf("Client trying to change protected element data %s (%s)", Packet.GetSourcePlayer()->GetNick(),
szName);

CLuaArguments arguments;
arguments.PushElement(pElement);
arguments.PushString(szName);
arguments.PushArgument(Value);
pSourcePlayer->CallEvent("onPlayerChangesProtectedData", arguments);
return;
}

if (lastSyncType != ESyncType::LOCAL)
{
Expand Down
5 changes: 5 additions & 0 deletions Server/mods/deathmatch/logic/CMainConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ CMainConfig::CMainConfig(CConsole* pConsole) : CXMLConfig(NULL)
m_iBackupInterval = 3;
m_iBackupAmount = 5;
m_bSyncMapElementData = true;
m_elementDataWhitelisted = false;
m_checkDuplicateSerials = true;
}

bool CMainConfig::Load()
Expand Down Expand Up @@ -526,6 +528,9 @@ bool CMainConfig::Load()
g_TickRateSettings.iLightSync = Clamp(200, g_TickRateSettings.iLightSync, 4000);
}

GetBoolean(m_pRootNode, "elementdata_whitelisted", m_elementDataWhitelisted);
GetBoolean(m_pRootNode, "check_duplicate_serials", m_checkDuplicateSerials);

ApplyNetOptions();

return true;
Expand Down
4 changes: 4 additions & 0 deletions Server/mods/deathmatch/logic/CMainConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class CMainConfig : public CXMLConfig
const std::vector<SString>& GetOwnerEmailAddressList() const { return m_OwnerEmailAddressList; }
bool IsDatabaseCredentialsProtectionEnabled() const { return m_bDatabaseCredentialsProtectionEnabled != 0; }
bool IsFakeLagCommandEnabled() const { return m_bFakeLagCommandEnabled != 0; }
bool IsElementDataWhitelisted() const { return m_elementDataWhitelisted; }
bool IsCheckDuplicateSerialsEnabled() const noexcept { return m_checkDuplicateSerials; }
bool IsCheckResourceClientFilesEnabled() const noexcept { return m_checkResourceClientFiles != 0; }

SString GetSetting(const SString& configSetting);
Expand Down Expand Up @@ -228,5 +230,7 @@ class CMainConfig : public CXMLConfig
int m_bFakeLagCommandEnabled;
int m_iPlayerTriggeredEventIntervalMs;
int m_iMaxPlayerTriggeredEventsPerInterval;
bool m_elementDataWhitelisted;
bool m_checkDuplicateSerials;
int m_checkResourceClientFiles;
};
11 changes: 11 additions & 0 deletions Server/mods/deathmatch/logic/CPlayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ CPlayer* CPlayerManager::Get(const char* szNick, bool bCaseSensitive)
return NULL;
}

CPlayer* CPlayerManager::GetBySerial(const std::string_view serial) const noexcept
{
for (const auto& player : m_Players)
{
if (player->GetSerial() == serial)
return player;
}

return nullptr;
}

void CPlayerManager::DeleteAll()
{
// Delete all the items in the list
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CPlayerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CPlayerManager

CPlayer* Get(const NetServerPlayerID& PlayerSocket);
CPlayer* Get(const char* szNick, bool bCaseSensitive = false);
CPlayer* GetBySerial(const std::string_view serial) const noexcept;

std::list<CPlayer*>::const_iterator IterBegin() { return m_Players.begin(); };
std::list<CPlayer*>::const_iterator IterEnd() { return m_Players.end(); };
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <net/SimHeaders.h>
#include <zip.h>
#include <glob/glob.h>
#include "CStaticFunctionDefinitions.h"

#ifdef WIN32
#include <zip/iowin32.h>
Expand Down
8 changes: 4 additions & 4 deletions Server/mods/deathmatch/logic/CResourceChecker.Data.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ namespace
//{false, "doesPedHaveJetPack", "isPedWearingJetpack"},

// Base Encoding & Decoding
{false, "base64Encode", "encodeString"},
{false, "base64Decode", "decodeString"},
{true, "base64Encode", "Please manually change this to encodeString (different syntax). Refer to the wiki for details"},
{true, "base64Decode", "Please manually change this to decodeString (different syntax). Refer to the wiki for details"},

{false, "setHelicopterRotorSpeed", "setVehicleRotorSpeed"}
};
Expand Down Expand Up @@ -271,7 +271,7 @@ namespace
{true, "setPlayerDiscordJoinParams", "See GitHub PR #2499 for more details"},

// Base Encoding & Decoding
{false, "base64Encode", "encodeString"},
{false, "base64Decode", "decodeString"}
{true, "base64Encode", "Please manually change this to encodeString (different syntax). Refer to the wiki for details"},
{true, "base64Decode", "Please manually change this to decodeString (different syntax). Refer to the wiki for details"}
};
} // namespace
21 changes: 15 additions & 6 deletions Server/mods/deathmatch/logic/CResourceChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,25 @@ void CResourceChecker::CheckMetaSourceForIssues(CXMLNode* pRootNode, const strin
attributes.Delete("client");
attributes.Delete("both");

if (!m_strReqServerVersion.empty())
// Use "both" if client and server versions are the same
if (!m_strReqServerVersion.empty() && !m_strReqClientVersion.empty() && m_strReqServerVersion == m_strReqClientVersion)
{
CXMLAttribute* pAttr = attributes.Create("server");
CXMLAttribute* pAttr = attributes.Create("both");
pAttr->SetValue(m_strReqServerVersion);
}

if (!m_strReqClientVersion.empty())
else
{
CXMLAttribute* pAttr = attributes.Create("client");
pAttr->SetValue(m_strReqClientVersion);
if (!m_strReqServerVersion.empty())
{
CXMLAttribute* pAttr = attributes.Create("server");
pAttr->SetValue(m_strReqServerVersion);
}

if (!m_strReqClientVersion.empty())
{
CXMLAttribute* pAttr = attributes.Create("client");
pAttr->SetValue(m_strReqClientVersion);
}
}

if (pbOutHasChanged)
Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CResourceChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* PROJECT: Multi Theft Auto v1.0
* LICENSE: See LICENSE in the top level directory
* FILE: mods/deathmatch/logic/CResourceChecker.cpp
* FILE: mods/deathmatch/logic/CResourceChecker.h
* PURPOSE: Resource file content checker/validator/upgrader
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
Expand Down
Loading

0 comments on commit 20a5659

Please sign in to comment.