From c9a66c570def3562813167ca9759048c28c970a2 Mon Sep 17 00:00:00 2001 From: kurta999 Date: Sat, 11 Mar 2017 10:40:07 +0100 Subject: [PATCH] Added protection against missing YSF.cfg Now YSF self will create YSF.cfg if it missing + GetNPCommandLine has been enabled --- src/CPlayerData.cpp | 3 +- src/CServer.cpp | 71 ++++++++++++++++++++++++++++++++++++++------- src/CServer.h | 4 +-- 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/src/CPlayerData.cpp b/src/CPlayerData.cpp index a6ec9bf..8b02a85 100644 --- a/src/CPlayerData.cpp +++ b/src/CPlayerData.cpp @@ -108,14 +108,13 @@ CPlayerData::CPlayerData( WORD playerid ) { pNetGame->pPlayerPool->pPlayer[playerid]->dwNickNameColor = dwPlayerColors[playerid % 100]; } - /* + // Store NPC Process ID if it's an NPC if (pNetGame->pPlayerPool->bIsNPC[playerid]) { if (CSAMPFunctions::GetPlayerIDFromIndex(playerid).binaryAddress == 0x0100007F) iNPCProcessID = CServer::Get()->FindNPCProcessID(playerid); } - */ } CPlayerData::~CPlayerData( void ) diff --git a/src/CServer.cpp b/src/CServer.cpp index e2e5661..557a2d0 100644 --- a/src/CServer.cpp +++ b/src/CServer.cpp @@ -53,18 +53,10 @@ void CServer::Initialize(SAMPVersion version) m_bNightVisionFix = true; m_bOnServerMessage = false; m_dwAFKAccuracy = 1500; + + // Loading configurations from plugins/YSF.cfg + LoadConfig(); - m_bPickupProtection = static_cast(Utility::CFGLoad("PickupProtection") != 0); - m_bDeathProtection = static_cast(Utility::CFGLoad("DeathProtection") != 0); - m_bDialogProtection = static_cast(Utility::CFGLoad("DialogProtection") != 0); - m_bUseCustomSpawn = static_cast(Utility::CFGLoad("UseCustomSpawn") != 0); - m_bAllowRemoteRCONWithBannedIPs = static_cast(Utility::CFGLoad("AllowRemoteRCONWithBannedIPs") != 0); - m_bIncreaseRakNetInternalPlayers = static_cast(Utility::CFGLoad("IncreaseRakNetInternalPlayers") != 0); - m_iRakNetInternalSleepTime = Utility::CFGLoad("RakNetInternalSleepTime"); - m_iAttachObjectDelay = Utility::CFGLoad("AttachObjectDelay"); - m_bStorePlayerObjectsMaterial = static_cast(Utility::CFGLoad("StorePlayerObjectsMaterial") != 0); - - //logprintf("%d, %d, %d, %d", m_bPickupProtection, m_bDeathProtection, m_iRakNetInternalSleepTime, m_iAttachObjectDelay); #ifndef _WIN32 LoadTickCount(); #endif @@ -1039,4 +1031,61 @@ int CServer::FindNPCProcessID(WORD npcid) } return pid; #endif +} + +void CServer::LoadConfig() +{ + // Avoid errors when somebody forgotten to copy YSF.cfg to plugins directory + FILE* fileConfig = fopen("plugins/YSF.cfg", "r"); + if (!fileConfig) + { + fileConfig = fopen("plugins/YSF.cfg", "w"); + + fprintf(fileConfig, "# Protection against fake pickup ids\n"); + fprintf(fileConfig, "PickupProtection 0\n"); + fprintf(fileConfig, "\n"); + fprintf(fileConfig, "# Protection against fakekill\n"); + fprintf(fileConfig, "DeathProtection 0\n"); + fprintf(fileConfig, "\n"); + fprintf(fileConfig, "# Protection against sproofed dialog ids\n"); + fprintf(fileConfig, "DialogProtection 0\n"); + fprintf(fileConfig, "\n"); + fprintf(fileConfig, "# Use redirected YSF's own RPC for spawning\n"); + fprintf(fileConfig, "UseCustomSpawn 0\n"); + fprintf(fileConfig, "\n"); + fprintf(fileConfig, "# Allowing remote RCON connections with banned IPs (its very good to enable when you need to unban yourself)\n"); + fprintf(fileConfig, "AllowRemoteRCONWithBannedIPs 0\n"); + fprintf(fileConfig, "\n"); + fprintf(fileConfig, "# Use this if you want to use SetMaxPlayers to increase your server slots at runtime\n"); + fprintf(fileConfig, "# DANGER: With enabling this option server will allow to connect 1000 players, doesn't matter what is your \"maxplayers\" value in server.cfg!\n"); + fprintf(fileConfig, "IncreaseRakNetInternalPlayers 0\n"); + fprintf(fileConfig, "\n"); + fprintf(fileConfig, "# If the option above isn't enabled this option won't have any effect\n"); + fprintf(fileConfig, "# Change raknet internal threads sleeping time, lowering the value migh result in smoother sync - by default is 5ms\n"); + fprintf(fileConfig, "RakNetInternalSleepTime 5\n"); + fprintf(fileConfig, "\n"); + fprintf(fileConfig, "# Delay im ms - object will be attached to player after this delay passed, lowering this delay might result in crashes \n"); + fprintf(fileConfig, "AttachObjectDelay 2000\n"); + fprintf(fileConfig, "\n"); + fprintf(fileConfig, "# SA-MP by default doesn't store material info for per-player objects, which made GetPlayerObjectMaterial/MaterialText broken\n"); + fprintf(fileConfig, "# If you just use streamer for objects and you don't wanna use those two natives below, then disable this option\n"); + fprintf(fileConfig, "StorePlayerObjectsMaterial 1\n"); + fprintf(fileConfig, "\n"); + fprintf(fileConfig, "# With this option you can load YSF on whatever server version, but it can result unwanted behavior\n"); + fprintf(fileConfig, "SkipVersionCheck 0\n"); + + fclose(fileConfig); + } + + m_bPickupProtection = static_cast(Utility::CFGLoad("PickupProtection") != 0); + m_bDeathProtection = static_cast(Utility::CFGLoad("DeathProtection") != 0); + m_bDialogProtection = static_cast(Utility::CFGLoad("DialogProtection") != 0); + m_bUseCustomSpawn = static_cast(Utility::CFGLoad("UseCustomSpawn") != 0); + m_bAllowRemoteRCONWithBannedIPs = static_cast(Utility::CFGLoad("AllowRemoteRCONWithBannedIPs") != 0); + m_bIncreaseRakNetInternalPlayers = static_cast(Utility::CFGLoad("IncreaseRakNetInternalPlayers") != 0); + m_iRakNetInternalSleepTime = Utility::CFGLoad("RakNetInternalSleepTime"); + m_iAttachObjectDelay = Utility::CFGLoad("AttachObjectDelay"); + m_bStorePlayerObjectsMaterial = static_cast(Utility::CFGLoad("StorePlayerObjectsMaterial") != 0); + + //logprintf("%d, %d, %d, %d", m_bPickupProtection, m_bDeathProtection, m_iRakNetInternalSleepTime, m_iAttachObjectDelay); } \ No newline at end of file diff --git a/src/CServer.h b/src/CServer.h index cafdac8..866b130 100644 --- a/src/CServer.h +++ b/src/CServer.h @@ -58,8 +58,6 @@ class CServer : public CSingleton bool inline IsInitialized(void) { return m_bInitialized; } void Process(); - void ProcessSysExec(); - bool AddPlayer(int playerid); bool RemovePlayer(int playerid); @@ -144,6 +142,8 @@ class CServer : public CSingleton std::mutex m_SysExecMutex; private: + void LoadConfig(); + void ProcessSysExec(); SAMPVersion m_Version; int m_iTicks;