- removed OnServerCfg in favor of OnConfigsExecuted

- added AutoExecConfig() which automates safe config execution

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40984
This commit is contained in:
David Anderson
2007-06-18 07:04:22 +00:00
parent 33b2d04e2d
commit 254fc2557a
14 changed files with 447 additions and 100 deletions
+32
View File
@@ -16,6 +16,7 @@
#include <stdarg.h>
#include <string.h>
#include <sm_platform.h>
#include "sm_stringutil.h"
#include "LibrarySys.h"
LibrarySystem g_LibSys;
@@ -347,3 +348,34 @@ const char *LibrarySystem::GetFileExtension(const char *filename)
return NULL;
}
bool LibrarySystem::CreateDirectory(const char *path)
{
#if defined PLATFORM_WINDOWS
return (mkdir(path) != -1);
#elif defined PLATFORM_POSIX
return (mkdir(path, 0775) != -1);
#endif
}
size_t LibrarySystem::GetFileFromPath(char *buffer, size_t maxlength, const char *path)
{
size_t length = strlen(path);
for (size_t i = length - 1;
i >= 0 && i <= length - 1;
i++)
{
if (path[i] == '/'
#if defined PLATFORM_WINDOWS
|| path[i] == '\\'
#endif
)
{
return UTIL_Format(buffer, maxlength, "%s", &path[i+1]);
}
}
/* We scanned and found no path separator */
return UTIL_Format(buffer, maxlength, "%s", path);
}
+2
View File
@@ -75,6 +75,8 @@ public:
void GetPlatformError(char *error, size_t maxlength);
size_t PathFormat(char *buffer, size_t len, const char *fmt, ...);
const char *GetFileExtension(const char *filename);
bool CreateDirectory(const char *path);
size_t GetFileFromPath(char *buffer, size_t maxlength, const char *path);
};
extern LibrarySystem g_LibSys;
+41 -5
View File
@@ -27,6 +27,7 @@
#include "sm_stringutil.h"
#include "ConCmdManager.h"
#include "PlayerManager.h"
#include "CoreConfig.h"
CPluginManager g_PluginSys;
HandleType_t g_PluginType = 0;
@@ -85,6 +86,11 @@ CPlugin::~CPlugin()
{
sm_trie_destroy(m_pProps);
}
for (size_t i=0; i<m_configs.size(); i++)
{
delete m_configs[i];
}
m_configs.clear();
}
void CPlugin::InitIdentity()
@@ -309,12 +315,9 @@ void CPlugin::Call_OnPluginStart()
pFunction->Execute(NULL);
}
}
if (g_ConCmds.IsServerCfgDone())
if (SM_AreConfigsExecuted())
{
if ((pFunction = m_ctx.base->GetFunctionByName("OnServerCfg")) != NULL)
{
pFunction->Execute(NULL);
}
SM_ExecuteForPlugin(GetBaseContext());
}
}
}
@@ -618,6 +621,32 @@ void CPlugin::DependencyDropped(CPlugin *pOwner)
m_dependsOn.remove(pOwner);
}
unsigned int CPlugin::GetConfigCount()
{
return (unsigned int)m_configs.size();
}
AutoConfig *CPlugin::GetConfig(unsigned int i)
{
if (i >= GetConfigCount())
{
return NULL;
}
return m_configs[i];
}
void CPlugin::AddConfig(bool autoCreate, const char *cfg, const char *folder)
{
AutoConfig *c = new AutoConfig;
c->autocfg = cfg;
c->folder = folder;
c->create = autoCreate;
m_configs.push_back(c);
}
/*******************
* PLUGIN ITERATOR *
*******************/
@@ -1971,3 +2000,10 @@ CPlugin *CPluginManager::GetPluginFromIdentity(IdentityToken_t *pToken)
return (CPlugin *)(pToken->ptr);
}
void CPluginManager::ExecAndGenPluginConfs()
{
List<CPlugin *>::iterator iter;
//for (iter =
}
+14
View File
@@ -109,6 +109,13 @@ enum LoadRes
LoadRes_Failure
};
struct AutoConfig
{
String autocfg;
String folder;
bool create;
};
class CPlugin : public IPlugin
{
friend class CPluginManager;
@@ -223,6 +230,10 @@ public:
bool WasRunning();
Handle_t GetMyHandle();
void AddConfig(bool autoCreate, const char *cfg, const char *folder);
unsigned int GetConfigCount();
AutoConfig *GetConfig(unsigned int i);
protected:
void UpdateInfo();
void SetTimeStamp(time_t t);
@@ -246,6 +257,7 @@ private:
List<FakeNative *> m_fakeNatives;
Trie *m_pProps;
bool m_FakeNativesMissing;
CVector<AutoConfig *> m_configs;
};
class CPluginManager :
@@ -395,6 +407,8 @@ private:
bool LoadOrRequireExtensions(CPlugin *pPlugin, unsigned int pass, char *error, size_t maxlength);
void _SetPauseState(CPlugin *pPlugin, bool pause);
void ExecAndGenPluginConfs();
protected:
/**
* Caching internal objects