Added auto-restart functionality to the Updater extensions (bug 3530, r=pred).
Added auto-restart functionality to the Updater extensions (
bug 3530, r=pred).
1.1 --- a/core/GameConfigs.cpp Thu Feb 26 12:47:56 2009 +1300
1.2 +++ b/core/GameConfigs.cpp Sat Feb 28 23:14:16 2009 -0500
1.3 @@ -49,9 +49,9 @@
1.4
1.5 GameConfigManager g_GameConfigs;
1.6 IGameConfig *g_pGameConf = NULL;
1.7 -char g_Game[256];
1.8 -char g_GameDesc[256] = {'!', '\0'};
1.9 -char g_GameName[256] = {'$', '\0'};
1.10 +static char g_Game[256];
1.11 +static char g_GameDesc[256] = {'!', '\0'};
1.12 +static char g_GameName[256] = {'$', '\0'};
1.13
1.14 #define PSTATE_NONE 0
1.15 #define PSTATE_GAMES 1
2.1 --- a/core/HalfLife2.cpp Thu Feb 26 12:47:56 2009 +1300
2.2 +++ b/core/HalfLife2.cpp Sat Feb 28 23:14:16 2009 -0500
2.3 @@ -632,3 +632,13 @@
2.4
2.5 hndl.Set(pEntOther);
2.6 }
2.7 +
2.8 +const char *CHalfLife2::GetCurrentMap()
2.9 +{
2.10 + return STRING(gpGlobals->mapname);
2.11 +}
2.12 +
2.13 +void CHalfLife2::ServerCommand(const char *buffer)
2.14 +{
2.15 + engine->ServerCommand(buffer);
2.16 +}
3.1 --- a/core/HalfLife2.h Thu Feb 26 12:47:56 2009 +1300
3.2 +++ b/core/HalfLife2.h Sat Feb 28 23:14:16 2009 -0500
3.3 @@ -113,6 +113,8 @@
3.4 int IndexOfEdict(edict_t *pEnt);
3.5 edict_t *GetHandleEntity(CBaseHandle &hndl);
3.6 void SetHandleEntity(CBaseHandle &hndl, edict_t *pEnt);
3.7 + const char *GetCurrentMap();
3.8 + void ServerCommand(const char *buffer);
3.9 public:
3.10 void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
3.11 void ProcessFakeCliCmdQueue();
4.1 --- a/core/sourcemod.cpp Thu Feb 26 12:47:56 2009 +1300
4.2 +++ b/core/sourcemod.cpp Sat Feb 28 23:14:16 2009 -0500
4.3 @@ -717,6 +717,11 @@
4.4 return g_CoreConfig.GetCoreConfigValue(key);
4.5 }
4.6
4.7 +int SourceModBase::GetPluginId()
4.8 +{
4.9 + return g_PLID;
4.10 +}
4.11 +
4.12 SMGlobalClass *SMGlobalClass::head = NULL;
4.13
4.14 SMGlobalClass::SMGlobalClass()
5.1 --- a/core/sourcemod.h Thu Feb 26 12:47:56 2009 +1300
5.2 +++ b/core/sourcemod.h Sat Feb 28 23:14:16 2009 -0500
5.3 @@ -133,6 +133,7 @@
5.4 size_t FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list ap);
5.5 void AddFrameAction(FRAMEACTION fn, void *data);
5.6 const char *GetCoreConfigValue(const char *key);
5.7 + int GetPluginId();
5.8 private:
5.9 CStack<CDataPack *> m_freepacks;
5.10 char m_SMBaseDir[PLATFORM_MAX_PATH];
6.1 --- a/extensions/updater/extension.cpp Thu Feb 26 12:47:56 2009 +1300
6.2 +++ b/extensions/updater/extension.cpp Sat Feb 28 23:14:16 2009 -0500
6.3 @@ -120,6 +120,7 @@
6.4 static void PumpUpdate(void *data)
6.5 {
6.6 String *str;
6.7 + bool new_files = false;
6.8 List<String *>::iterator iter;
6.9
6.10 char path[PLATFORM_MAX_PATH];
6.11 @@ -163,6 +164,7 @@
6.12 smutils->LogMessage(myself,
6.13 "Successfully updated gamedata file \"%s\"",
6.14 part->file);
6.15 + new_files = true;
6.16 }
6.17 skip_create:
6.18 temp = part->next;
6.19 @@ -186,6 +188,31 @@
6.20
6.21 smutils->LogError(myself, "--- END ERRORS FROM AUTOMATIC UPDATER ---");
6.22 }
6.23 +
6.24 + if (new_files)
6.25 + {
6.26 + const char *force_restart = smutils->GetCoreConfigValue("ForceRestartAfterUpdate");
6.27 + if (force_restart == NULL || strcasecmp(force_restart, "yes") != 0)
6.28 + {
6.29 + smutils->LogMessage(myself,
6.30 + "SourceMod has been updated, please reload it or restart your server.");
6.31 + }
6.32 + else
6.33 + {
6.34 + char buffer[255];
6.35 + smutils->Format(buffer,
6.36 + sizeof(buffer),
6.37 + "meta unload %d\n",
6.38 + smutils->GetPluginId());
6.39 + gamehelpers->ServerCommand(buffer);
6.40 + smutils->Format(buffer,
6.41 + sizeof(buffer),
6.42 + "changelevel \"%s\"\n",
6.43 + gamehelpers->GetCurrentMap());
6.44 + gamehelpers->ServerCommand(buffer);
6.45 + gamehelpers->ServerCommand("echo SourceMod has been restarted from an automatic update.\n");
6.46 + }
6.47 + }
6.48 }
6.49
6.50 void SmUpdater::RunThread(IThreadHandle *pHandle)
7.1 --- a/extensions/updater/sdk/smsdk_config.h Thu Feb 26 12:47:56 2009 +1300
7.2 +++ b/extensions/updater/sdk/smsdk_config.h Sat Feb 28 23:14:16 2009 -0500
7.3 @@ -66,7 +66,7 @@
7.4 //#define SMEXT_ENABLE_DBMANAGER
7.5 #define SMEXT_ENABLE_GAMECONF
7.6 //#define SMEXT_ENABLE_MEMUTILS
7.7 -//#define SMEXT_ENABLE_GAMEHELPERS
7.8 +#define SMEXT_ENABLE_GAMEHELPERS
7.9 //#define SMEXT_ENABLE_TIMERSYS
7.10 #define SMEXT_ENABLE_THREADER
7.11 #define SMEXT_ENABLE_LIBSYS
8.1 --- a/public/IGameHelpers.h Thu Feb 26 12:47:56 2009 +1300
8.2 +++ b/public/IGameHelpers.h Sat Feb 28 23:14:16 2009 -0500
8.3 @@ -40,7 +40,7 @@
8.4 */
8.5
8.6 #define SMINTERFACE_GAMEHELPERS_NAME "IGameHelpers"
8.7 -#define SMINTERFACE_GAMEHELPERS_VERSION 3
8.8 +#define SMINTERFACE_GAMEHELPERS_VERSION 4
8.9
8.10 class CBaseEntity;
8.11 class CBaseHandle;
8.12 @@ -179,6 +179,20 @@
8.13 * @noreturn
8.14 */
8.15 virtual void SetHandleEntity(CBaseHandle &hndl, edict_t *pEnt) =0;
8.16 +
8.17 + /**
8.18 + * @brief Returns the current map name.
8.19 + *
8.20 + * @return Current map name.
8.21 + */
8.22 + virtual const char *GetCurrentMap() =0;
8.23 +
8.24 + /**
8.25 + * @brief Wraps IVEngineServer::ServerCommand.
8.26 + *
8.27 + * @param buffer Command buffer (does not auto \n terminate).
8.28 + */
8.29 + virtual void ServerCommand(const char *buffer) =0;
8.30 };
8.31 }
8.32
9.1 --- a/public/ISourceMod.h Thu Feb 26 12:47:56 2009 +1300
9.2 +++ b/public/ISourceMod.h Sat Feb 28 23:14:16 2009 -0500
9.3 @@ -43,7 +43,7 @@
9.4 #include <time.h>
9.5
9.6 #define SMINTERFACE_SOURCEMOD_NAME "ISourceMod"
9.7 -#define SMINTERFACE_SOURCEMOD_VERSION 10
9.8 +#define SMINTERFACE_SOURCEMOD_VERSION 11
9.9
9.10 /**
9.11 * @brief Forward declaration of the KeyValues class.
9.12 @@ -296,6 +296,13 @@
9.13 * The string will be destroyed on core.cfg reparses.
9.14 */
9.15 virtual const char *GetCoreConfigValue(const char *key) = 0;
9.16 +
9.17 + /**
9.18 + * @brief Returns SourceMod's Metamod:Source plugin ID.
9.19 + *
9.20 + * @return Metamod:Source PluginId.
9.21 + */
9.22 + virtual int GetPluginId() = 0;
9.23 };
9.24 }
9.25