Skip to content

Commit

Permalink
Added protection against missing YSF.cfg
Browse files Browse the repository at this point in the history
Now YSF self will create YSF.cfg if it missing

+ GetNPCommandLine has been enabled
  • Loading branch information
kurta999 committed Mar 11, 2017
1 parent 1a2ada8 commit c9a66c5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/CPlayerData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
71 changes: 60 additions & 11 deletions src/CServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(Utility::CFGLoad("PickupProtection") != 0);
m_bDeathProtection = static_cast<int>(Utility::CFGLoad("DeathProtection") != 0);
m_bDialogProtection = static_cast<int>(Utility::CFGLoad("DialogProtection") != 0);
m_bUseCustomSpawn = static_cast<int>(Utility::CFGLoad("UseCustomSpawn") != 0);
m_bAllowRemoteRCONWithBannedIPs = static_cast<int>(Utility::CFGLoad("AllowRemoteRCONWithBannedIPs") != 0);
m_bIncreaseRakNetInternalPlayers = static_cast<int>(Utility::CFGLoad("IncreaseRakNetInternalPlayers") != 0);
m_iRakNetInternalSleepTime = Utility::CFGLoad("RakNetInternalSleepTime");
m_iAttachObjectDelay = Utility::CFGLoad("AttachObjectDelay");
m_bStorePlayerObjectsMaterial = static_cast<int>(Utility::CFGLoad("StorePlayerObjectsMaterial") != 0);

//logprintf("%d, %d, %d, %d", m_bPickupProtection, m_bDeathProtection, m_iRakNetInternalSleepTime, m_iAttachObjectDelay);
#ifndef _WIN32
LoadTickCount();
#endif
Expand Down Expand Up @@ -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<int>(Utility::CFGLoad("PickupProtection") != 0);
m_bDeathProtection = static_cast<int>(Utility::CFGLoad("DeathProtection") != 0);
m_bDialogProtection = static_cast<int>(Utility::CFGLoad("DialogProtection") != 0);
m_bUseCustomSpawn = static_cast<int>(Utility::CFGLoad("UseCustomSpawn") != 0);
m_bAllowRemoteRCONWithBannedIPs = static_cast<int>(Utility::CFGLoad("AllowRemoteRCONWithBannedIPs") != 0);
m_bIncreaseRakNetInternalPlayers = static_cast<int>(Utility::CFGLoad("IncreaseRakNetInternalPlayers") != 0);
m_iRakNetInternalSleepTime = Utility::CFGLoad("RakNetInternalSleepTime");
m_iAttachObjectDelay = Utility::CFGLoad("AttachObjectDelay");
m_bStorePlayerObjectsMaterial = static_cast<int>(Utility::CFGLoad("StorePlayerObjectsMaterial") != 0);

//logprintf("%d, %d, %d, %d", m_bPickupProtection, m_bDeathProtection, m_iRakNetInternalSleepTime, m_iAttachObjectDelay);
}
4 changes: 2 additions & 2 deletions src/CServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ class CServer : public CSingleton<CServer>
bool inline IsInitialized(void) { return m_bInitialized; }
void Process();

void ProcessSysExec();

bool AddPlayer(int playerid);
bool RemovePlayer(int playerid);

Expand Down Expand Up @@ -144,6 +142,8 @@ class CServer : public CSingleton<CServer>
std::mutex m_SysExecMutex;

private:
void LoadConfig();
void ProcessSysExec();

SAMPVersion m_Version;
int m_iTicks;
Expand Down

0 comments on commit c9a66c5

Please sign in to comment.