added amb727 (sm_time_adjustment)
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401377
This commit is contained in:
parent
d9866748f7
commit
af4a59c071
@ -33,6 +33,13 @@ sm_vote_delay 30
|
||||
// 12 hour format: %m/%d/%Y - %I:%M:%S %p
|
||||
sm_datetime_format "%m/%d/%Y - %H:%M:%S"
|
||||
|
||||
// Sets how many seconds SourceMod should adjust time values for incorrect
|
||||
// server clocks. This can be positive or negative and will affect every
|
||||
// system time in SourceMod, including logging stamps.
|
||||
// --
|
||||
// Default: 0
|
||||
sm_time_adjustment 0
|
||||
|
||||
// Specifies the amount of time that is allowed between chat messages. This
|
||||
// includes the say and say_team commands. If a client sends a message faster
|
||||
// than this time, they receive a flood token. When the client has accumulated
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "sm_stringutil.h"
|
||||
#include "Logger.h"
|
||||
#include "systems/LibrarySys.h"
|
||||
#include "TimerSys.h"
|
||||
#include "sm_version.h"
|
||||
|
||||
Logger g_Logger;
|
||||
@ -119,7 +120,7 @@ void Logger::_NewMapFile()
|
||||
int i = 0;
|
||||
|
||||
time_t t;
|
||||
time(&t);
|
||||
GetAdjustedTime(&t);
|
||||
tm *curtime = localtime(&t);
|
||||
|
||||
while (true)
|
||||
@ -189,7 +190,7 @@ void Logger::InitLogger(LoggingMode mode)
|
||||
m_Active = m_InitialState;
|
||||
|
||||
time_t t;
|
||||
time(&t);
|
||||
GetAdjustedTime(&t);
|
||||
tm *curtime = localtime(&t);
|
||||
m_CurDay = curtime->tm_mday;
|
||||
|
||||
@ -257,7 +258,7 @@ void Logger::LogMessage(const char *vafmt, ...)
|
||||
|
||||
char date[32];
|
||||
time_t t;
|
||||
time(&t);
|
||||
GetAdjustedTime(&t);
|
||||
tm *curtime = localtime(&t);
|
||||
strftime(date, sizeof(date), "%m/%d/%Y - %H:%M:%S", curtime);
|
||||
|
||||
@ -314,7 +315,7 @@ void Logger::LogError(const char *vafmt, ...)
|
||||
}
|
||||
|
||||
time_t t;
|
||||
time(&t);
|
||||
GetAdjustedTime(&t);
|
||||
tm *curtime = localtime(&t);
|
||||
|
||||
char date[32];
|
||||
|
@ -29,11 +29,25 @@
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include "TimerSys.h"
|
||||
#include "sourcemm_api.h"
|
||||
|
||||
TimerSystem g_Timers;
|
||||
TickInfo g_SimTicks;
|
||||
|
||||
ConVar sm_time_adjustment("sm_time_adjustment", "0", 0, "Adjusts the server time in seconds");
|
||||
|
||||
time_t GetAdjustedTime(time_t *buf)
|
||||
{
|
||||
time_t val = time(NULL) + sm_time_adjustment.GetInt();
|
||||
if (buf)
|
||||
{
|
||||
*buf = val;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
inline float GetSimulatedTime()
|
||||
{
|
||||
if (g_SimTicks.ticking)
|
||||
|
@ -87,6 +87,8 @@ private:
|
||||
float m_LastExecTime;
|
||||
};
|
||||
|
||||
time_t GetAdjustedTime(time_t *buf = NULL);
|
||||
|
||||
extern TimerSystem g_Timers;
|
||||
extern TickInfo g_SimTicks;
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "PluginSys.h"
|
||||
#include "HandleSys.h"
|
||||
#include "LibrarySys.h"
|
||||
#include "TimerSys.h"
|
||||
|
||||
#if defined PLATFORM_WINDOWS
|
||||
#include <windows.h>
|
||||
@ -93,7 +94,7 @@ static cell_t ThrowError(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
static cell_t GetTime(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
time_t t = time(NULL);
|
||||
time_t t = GetAdjustedTime();
|
||||
cell_t *addr;
|
||||
pContext->LocalToPhysAddr(params[1], &addr);
|
||||
|
||||
@ -130,7 +131,7 @@ static cell_t FormatTime(IPluginContext *pContext, const cell_t *params)
|
||||
_invalid_parameter_handler handler = _set_invalid_parameter_handler(_ignore_invalid_parameter);
|
||||
#endif
|
||||
|
||||
time_t t = (params[4] == -1) ? time(NULL) : (time_t)params[4];
|
||||
time_t t = (params[4] == -1) ? GetAdjustedTime() : (time_t)params[4];
|
||||
size_t written = strftime(buffer, params[2], format, localtime(&t));
|
||||
|
||||
#if defined SUBPLATFORM_SECURECRT
|
||||
|
@ -756,6 +756,11 @@ void SourceModBase::AllPluginsLoaded()
|
||||
}
|
||||
}
|
||||
|
||||
time_t SourceModBase::GetAdjustedTime()
|
||||
{
|
||||
return GetAdjustedTime();
|
||||
}
|
||||
|
||||
SMGlobalClass *SMGlobalClass::head = NULL;
|
||||
|
||||
SMGlobalClass::SMGlobalClass()
|
||||
|
@ -115,6 +115,7 @@ public: // ISourceMod
|
||||
ISourcePawnEngine *GetScriptingEngine();
|
||||
IVirtualMachine *GetScriptingVM();
|
||||
void AllPluginsLoaded();
|
||||
time_t GetAdjustedTime();
|
||||
private:
|
||||
/**
|
||||
* @brief Loading plugins
|
||||
|
@ -191,6 +191,13 @@ namespace SourceMod
|
||||
* @return A pointer to the JIT interface.
|
||||
*/
|
||||
virtual SourcePawn::IVirtualMachine *GetScriptingVM() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the adjusted server time.
|
||||
*
|
||||
* @return Adjusted server time.
|
||||
*/
|
||||
virtual time_t GetAdjustedTime() =0;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user