mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
fixed last commit, generalized config saving and path check
This commit is contained in:
parent
c77518d2e1
commit
6506cf4ddf
|
@ -1610,14 +1610,25 @@ void str_sanitize_cc(char *str_in)
|
|||
}
|
||||
}
|
||||
|
||||
int str_safe_as_pathname(const char* str_in)
|
||||
/* check if the string contains '.' or '..' paths */
|
||||
int str_check_pathname(const char* str)
|
||||
{
|
||||
unsigned char *str = (unsigned char *)str_in;
|
||||
int parse_counter = 1;
|
||||
while(*str)
|
||||
{
|
||||
if (*str == '\\' || *str == '/')
|
||||
return -1;
|
||||
str++;
|
||||
if(*str == '\\' || *str == '/')
|
||||
{
|
||||
if(parse_counter >= 2 && parse_counter <= 3)
|
||||
return -1;
|
||||
else
|
||||
parse_counter = 1;
|
||||
}
|
||||
else if(*str != '.')
|
||||
parse_counter = 0;
|
||||
else
|
||||
++parse_counter;
|
||||
|
||||
++str;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ extern "C" {
|
|||
|
||||
/* Group: Debug */
|
||||
/*
|
||||
|
||||
Function: dbg_assert
|
||||
Breaks into the debugger based on a test.
|
||||
|
||||
|
@ -814,18 +815,19 @@ void str_sanitize_cc(char *str);
|
|||
void str_sanitize(char *str);
|
||||
|
||||
/*
|
||||
Function: str_sanitize_pathname_from_character
|
||||
Checks whether the input string contains \ or / characters, that could
|
||||
indicate an attempt of path hijacking.
|
||||
Returns 0 if string is safe, -1 otherwise.
|
||||
Function: str_check_pathnam
|
||||
Check if the string contains '.' or '..' paths.
|
||||
|
||||
Parameters:
|
||||
str - String to check.
|
||||
|
||||
Returns:
|
||||
Returns 0 if the path is valid, -1 otherwise.
|
||||
|
||||
Remarks:
|
||||
- The strings are treated as zero-terminated strings.
|
||||
*/
|
||||
int str_safe_as_pathname(const char* str_in);
|
||||
int str_check_pathname(const char* str);
|
||||
|
||||
/*
|
||||
Function: str_clean_whitespaces
|
||||
|
|
|
@ -2261,8 +2261,9 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
pClient->RegisterInterfaces();
|
||||
|
||||
// create the components
|
||||
int FlagMask = CFGFLAG_CLIENT;
|
||||
IEngine *pEngine = CreateEngine("Teeworlds");
|
||||
IConsole *pConsole = CreateConsole(CFGFLAG_CLIENT);
|
||||
IConsole *pConsole = CreateConsole(FlagMask);
|
||||
IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_CLIENT, argc, argv); // ignore_convention
|
||||
IConfig *pConfig = CreateConfig();
|
||||
IEngineSound *pEngineSound = CreateEngineSound();
|
||||
|
@ -2302,7 +2303,7 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
}
|
||||
|
||||
pEngine->Init();
|
||||
pConfig->Init();
|
||||
pConfig->Init(FlagMask);
|
||||
pEngineMasterServer->Init();
|
||||
pEngineMasterServer->Load();
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#define ENGINE_CONFIG_H
|
||||
|
||||
#include "kernel.h"
|
||||
#include "console.h"
|
||||
|
||||
class IConfig : public IInterface
|
||||
{
|
||||
|
@ -12,11 +11,10 @@ class IConfig : public IInterface
|
|||
public:
|
||||
typedef void (*SAVECALLBACKFUNC)(IConfig *pConfig, void *pUserData);
|
||||
|
||||
virtual void Init() = 0;
|
||||
virtual void Init(int FlagMask) = 0;
|
||||
virtual void Reset() = 0;
|
||||
virtual void RestoreStrings() = 0;
|
||||
virtual void Save() = 0;
|
||||
virtual int SaveServerConfigs(const char *filename) = 0;
|
||||
virtual void Save(const char *pFilename=0) = 0;
|
||||
|
||||
virtual void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) = 0;
|
||||
|
||||
|
|
|
@ -1478,19 +1478,8 @@ void CServer::ConRecord(IConsole::IResult *pResult, void *pUser)
|
|||
{
|
||||
CServer* pServer = (CServer *)pUser;
|
||||
char aFilename[128];
|
||||
char aBuf[256];
|
||||
if(pResult->NumArguments())
|
||||
{
|
||||
const char *pFilename = pResult->GetString(0);
|
||||
if (str_safe_as_pathname(pFilename) == 0)
|
||||
str_format(aFilename, sizeof(aFilename), "demos/%s.demo", pFilename);
|
||||
else
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "failed to start recording: %s is not an allowed path", pFilename);
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
str_format(aFilename, sizeof(aFilename), "demos/%s.demo", pResult->GetString(0));
|
||||
else
|
||||
{
|
||||
char aDate[20];
|
||||
|
@ -1510,44 +1499,6 @@ void CServer::ConMapReload(IConsole::IResult *pResult, void *pUser)
|
|||
((CServer *)pUser)->m_MapReload = 1;
|
||||
}
|
||||
|
||||
void CServer::ConSaveConfig(IConsole::IResult *pResult, void *pUser)
|
||||
{
|
||||
CServer *pThis = ((CServer *)pUser);
|
||||
IConfig* currentConfig = pThis->Kernel()->RequestInterface<IConfig>();
|
||||
|
||||
char aFilename[128];
|
||||
char aBuf[256];
|
||||
if(pResult->NumArguments())
|
||||
{
|
||||
const char *pFilename = pResult->GetString(0);
|
||||
if (str_safe_as_pathname(pFilename) == 0)
|
||||
str_format(aFilename, sizeof(aFilename), "serverconf/%s.cfg", pFilename);
|
||||
else
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "failed to save server configuration: %s is not an allowed path", pFilename);
|
||||
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char aDate[20];
|
||||
str_timestamp(aDate, sizeof(aDate));
|
||||
str_format(aFilename, sizeof(aFilename), "serverconf/server_config_%s.cfg", aDate);
|
||||
}
|
||||
|
||||
if (currentConfig->SaveServerConfigs(aFilename) == 0)
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "saved server configuration to %s", aFilename);
|
||||
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "failed to save server configuration to %s", aFilename);
|
||||
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
|
||||
}
|
||||
}
|
||||
|
||||
void CServer::ConLogout(IConsole::IResult *pResult, void *pUser)
|
||||
{
|
||||
CServer *pServer = (CServer *)pUser;
|
||||
|
@ -1642,8 +1593,6 @@ void CServer::RegisterCommands()
|
|||
|
||||
Console()->Register("reload", "", CFGFLAG_SERVER, ConMapReload, this, "Reload the map");
|
||||
|
||||
Console()->Register("save_conf", "?s", CFGFLAG_SERVER, ConSaveConfig, this, "Save current configuration to file");
|
||||
|
||||
Console()->Chain("sv_name", ConchainSpecialInfoupdate, this);
|
||||
Console()->Chain("password", ConchainSpecialInfoupdate, this);
|
||||
|
||||
|
@ -1699,6 +1648,7 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
IKernel *pKernel = IKernel::Create();
|
||||
|
||||
// create the components
|
||||
int FlagMask = CFGFLAG_SERVER|CFGFLAG_ECON;
|
||||
IEngine *pEngine = CreateEngine("Teeworlds");
|
||||
IEngineMap *pEngineMap = CreateEngineMap();
|
||||
IGameServer *pGameServer = CreateGameServer();
|
||||
|
@ -1728,7 +1678,7 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
}
|
||||
|
||||
pEngine->Init();
|
||||
pConfig->Init();
|
||||
pConfig->Init(FlagMask);
|
||||
pEngineMasterServer->Init();
|
||||
pEngineMasterServer->Load();
|
||||
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
||||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||
#include <engine/config.h>
|
||||
#include <engine/console.h>
|
||||
#include <engine/storage.h>
|
||||
#include <engine/shared/config.h>
|
||||
|
||||
|
||||
CConfiguration g_Config;
|
||||
|
||||
class CConfig : public IConfig
|
||||
{
|
||||
IStorage *m_pStorage;
|
||||
IConsole *m_pConsole;
|
||||
IOHANDLE m_ConfigFile;
|
||||
int m_FlagMask;
|
||||
|
||||
struct CCallback
|
||||
{
|
||||
|
@ -36,18 +40,40 @@ class CConfig : public IConfig
|
|||
*pDst = 0;
|
||||
}
|
||||
|
||||
static void Con_SaveConfig(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
char aFilename[128];
|
||||
if(pResult->NumArguments())
|
||||
str_format(aFilename, sizeof(aFilename), "configs/%s.cfg", pResult->GetString(0));
|
||||
else
|
||||
{
|
||||
char aDate[20];
|
||||
str_timestamp(aDate, sizeof(aDate));
|
||||
str_format(aFilename, sizeof(aFilename), "configs/config_%s.cfg", aDate);
|
||||
}
|
||||
((CConfig*)pUserData)->Save(aFilename);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
CConfig()
|
||||
{
|
||||
m_pStorage = 0;
|
||||
m_pConsole = 0;
|
||||
m_ConfigFile = 0;
|
||||
m_FlagMask = 0;
|
||||
m_NumCallbacks = 0;
|
||||
}
|
||||
|
||||
virtual void Init()
|
||||
virtual void Init(int FlagMask)
|
||||
{
|
||||
m_pStorage = Kernel()->RequestInterface<IStorage>();
|
||||
m_pConsole = Kernel()->RequestInterface<IConsole>();
|
||||
m_FlagMask = FlagMask;
|
||||
Reset();
|
||||
|
||||
if(m_pConsole)
|
||||
m_pConsole->Register("save_config", "?s", CFGFLAG_SERVER|CFGFLAG_CLIENT|CFGFLAG_STORE, Con_SaveConfig, this, "Save config to file");
|
||||
}
|
||||
|
||||
virtual void Reset()
|
||||
|
@ -72,11 +98,11 @@ public:
|
|||
#undef MACRO_CONFIG_STR
|
||||
}
|
||||
|
||||
virtual void Save()
|
||||
virtual void Save(const char *pFilename)
|
||||
{
|
||||
if(!m_pStorage)
|
||||
return;
|
||||
m_ConfigFile = m_pStorage->OpenFile("settings.cfg", IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||
m_ConfigFile = m_pStorage->OpenFile(pFilename ? pFilename : "settings.cfg", IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||
|
||||
if(!m_ConfigFile)
|
||||
return;
|
||||
|
@ -84,8 +110,8 @@ public:
|
|||
char aLineBuf[1024*2];
|
||||
char aEscapeBuf[1024*2];
|
||||
|
||||
#define MACRO_CONFIG_INT(Name,ScriptName,def,min,max,flags,desc) if((flags)&CFGFLAG_SAVE){ str_format(aLineBuf, sizeof(aLineBuf), "%s %i", #ScriptName, g_Config.m_##Name); WriteLine(aLineBuf); }
|
||||
#define MACRO_CONFIG_STR(Name,ScriptName,len,def,flags,desc) if((flags)&CFGFLAG_SAVE){ EscapeParam(aEscapeBuf, g_Config.m_##Name, sizeof(aEscapeBuf)); str_format(aLineBuf, sizeof(aLineBuf), "%s \"%s\"", #ScriptName, aEscapeBuf); WriteLine(aLineBuf); }
|
||||
#define MACRO_CONFIG_INT(Name,ScriptName,def,min,max,flags,desc) if(((flags)&(CFGFLAG_SAVE))&&((flags)&(m_FlagMask))){ str_format(aLineBuf, sizeof(aLineBuf), "%s %i", #ScriptName, g_Config.m_##Name); WriteLine(aLineBuf); }
|
||||
#define MACRO_CONFIG_STR(Name,ScriptName,len,def,flags,desc) if(((flags)&(CFGFLAG_SAVE))&&((flags)&(m_FlagMask))){ EscapeParam(aEscapeBuf, g_Config.m_##Name, sizeof(aEscapeBuf)); str_format(aLineBuf, sizeof(aLineBuf), "%s \"%s\"", #ScriptName, aEscapeBuf); WriteLine(aLineBuf); }
|
||||
|
||||
#include "config_variables.h"
|
||||
|
||||
|
@ -96,33 +122,13 @@ public:
|
|||
m_aCallbacks[i].m_pfnFunc(this, m_aCallbacks[i].m_pUserData);
|
||||
|
||||
io_close(m_ConfigFile);
|
||||
m_ConfigFile = 0;
|
||||
}
|
||||
|
||||
virtual int SaveServerConfigs(const char *filename)
|
||||
{
|
||||
if(!m_pStorage)
|
||||
return -1;
|
||||
|
||||
IOHANDLE serverConfig = m_pStorage->OpenFile(filename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||
|
||||
if (!serverConfig)
|
||||
return -1;
|
||||
|
||||
char aLineBuf[1024*2];
|
||||
char aEscapeBuf[1024*2];
|
||||
|
||||
#define MACRO_CONFIG_INT(Name,ScriptName,def,min,max,flags,desc) if((flags)&CFGFLAG_SERVER){ str_format(aLineBuf, sizeof(aLineBuf), "%s %i", #ScriptName, g_Config.m_##Name); WriteLineToConfigFile(aLineBuf, serverConfig); }
|
||||
#define MACRO_CONFIG_STR(Name,ScriptName,len,def,flags,desc) if((flags)&CFGFLAG_SERVER){ EscapeParam(aEscapeBuf, g_Config.m_##Name, sizeof(aEscapeBuf)); str_format(aLineBuf, sizeof(aLineBuf), "%s \"%s\"", #ScriptName, aEscapeBuf); WriteLineToConfigFile(aLineBuf, serverConfig); }
|
||||
|
||||
#include "config_variables.h"
|
||||
|
||||
#undef MACRO_CONFIG_INT
|
||||
#undef MACRO_CONFIG_STR
|
||||
|
||||
io_close(serverConfig);
|
||||
serverConfig = 0;
|
||||
return 0;
|
||||
if(m_pConsole)
|
||||
{
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "saved config to '%s'", pFilename);
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "config", aBuf);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData)
|
||||
|
@ -137,17 +143,9 @@ public:
|
|||
{
|
||||
if(!m_ConfigFile)
|
||||
return;
|
||||
WriteLineToConfigFile(pLine, m_ConfigFile);
|
||||
io_write(m_ConfigFile, pLine, str_length(pLine));
|
||||
io_write_newline(m_ConfigFile);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void WriteLineToConfigFile(const char *pLine, const IOHANDLE hConfig)
|
||||
{
|
||||
io_write(hConfig, pLine, str_length(pLine));
|
||||
io_write_newline(hConfig);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
IConfig *CreateConfig() { return new CConfig; }
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
MACRO_CONFIG_STR(PlayerName, player_name, 16, "nameless tee", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Name of the player")
|
||||
MACRO_CONFIG_STR(PlayerClan, player_clan, 12, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Clan of the player")
|
||||
MACRO_CONFIG_INT(PlayerCountry, player_country, -1, -1, 1000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Country of the player")
|
||||
MACRO_CONFIG_STR(Password, password, 32, "", CFGFLAG_CLIENT|CFGFLAG_SERVER, "Password to the server")
|
||||
MACRO_CONFIG_STR(Password, password, 32, "", CFGFLAG_SAVE|CFGFLAG_CLIENT|CFGFLAG_SERVER, "Password to the server")
|
||||
MACRO_CONFIG_STR(Logfile, logfile, 128, "", CFGFLAG_SAVE|CFGFLAG_CLIENT|CFGFLAG_SERVER, "Filename to log all output to")
|
||||
MACRO_CONFIG_INT(ConsoleOutputLevel, console_output_level, 0, 0, 2, CFGFLAG_CLIENT|CFGFLAG_SERVER, "Adjusts the amount of information in the console")
|
||||
MACRO_CONFIG_INT(ConsoleOutputLevel, console_output_level, 0, 0, 2, CFGFLAG_SAVE|CFGFLAG_CLIENT|CFGFLAG_SERVER, "Adjusts the amount of information in the console")
|
||||
|
||||
MACRO_CONFIG_INT(ClCpuThrottle, cl_cpu_throttle, 0, 0, 100, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
|
||||
MACRO_CONFIG_INT(ClEditor, cl_editor, 0, 0, 1, CFGFLAG_CLIENT, "")
|
||||
|
@ -75,30 +75,30 @@ MACRO_CONFIG_INT(GfxAsyncRender, gfx_asyncrender, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_
|
|||
|
||||
MACRO_CONFIG_INT(InpMousesens, inp_mousesens, 100, 5, 100000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Mouse sensitivity")
|
||||
|
||||
MACRO_CONFIG_STR(SvName, sv_name, 128, "unnamed server", CFGFLAG_SERVER, "Server name")
|
||||
MACRO_CONFIG_STR(SvHostname, sv_hostname, 128, "", CFGFLAG_SERVER, "Server hostname")
|
||||
MACRO_CONFIG_STR(Bindaddr, bindaddr, 128, "", CFGFLAG_CLIENT|CFGFLAG_SERVER|CFGFLAG_MASTER, "Address to bind the client/server to")
|
||||
MACRO_CONFIG_INT(SvPort, sv_port, 8303, 0, 0, CFGFLAG_SERVER, "Port to use for the server")
|
||||
MACRO_CONFIG_INT(SvExternalPort, sv_external_port, 0, 0, 0, CFGFLAG_SERVER, "External port to report to the master servers")
|
||||
MACRO_CONFIG_STR(SvMap, sv_map, 128, "dm1", CFGFLAG_SERVER, "Map to use on the server")
|
||||
MACRO_CONFIG_INT(SvMaxClients, sv_max_clients, 8, 1, MAX_CLIENTS, CFGFLAG_SERVER, "Maximum number of clients that are allowed on a server")
|
||||
MACRO_CONFIG_INT(SvMaxClientsPerIP, sv_max_clients_per_ip, 4, 1, MAX_CLIENTS, CFGFLAG_SERVER, "Maximum number of clients with the same IP that can connect to the server")
|
||||
MACRO_CONFIG_INT(SvMapDownloadSpeed, sv_map_download_speed, 2, 1, 16, CFGFLAG_SERVER, "Number of map data packages a client gets on each request")
|
||||
MACRO_CONFIG_INT(SvHighBandwidth, sv_high_bandwidth, 0, 0, 1, CFGFLAG_SERVER, "Use high bandwidth mode. Doubles the bandwidth required for the server. LAN use only")
|
||||
MACRO_CONFIG_INT(SvRegister, sv_register, 1, 0, 1, CFGFLAG_SERVER, "Register server with master server for public listing")
|
||||
MACRO_CONFIG_STR(SvRconPassword, sv_rcon_password, 32, "", CFGFLAG_SERVER, "Remote console password (full access)")
|
||||
MACRO_CONFIG_STR(SvRconModPassword, sv_rcon_mod_password, 32, "", CFGFLAG_SERVER, "Remote console password for moderators (limited access)")
|
||||
MACRO_CONFIG_INT(SvRconMaxTries, sv_rcon_max_tries, 3, 0, 100, CFGFLAG_SERVER, "Maximum number of tries for remote console authentication")
|
||||
MACRO_CONFIG_INT(SvRconBantime, sv_rcon_bantime, 5, 0, 1440, CFGFLAG_SERVER, "The time a client gets banned if remote console authentication fails. 0 makes it just use kick")
|
||||
MACRO_CONFIG_INT(SvAutoDemoRecord, sv_auto_demo_record, 0, 0, 1, CFGFLAG_SERVER, "Automatically record demos")
|
||||
MACRO_CONFIG_INT(SvAutoDemoMax, sv_auto_demo_max, 10, 0, 1000, CFGFLAG_SERVER, "Maximum number of automatically recorded demos (0 = no limit)")
|
||||
MACRO_CONFIG_STR(SvName, sv_name, 128, "unnamed server", CFGFLAG_SAVE|CFGFLAG_SERVER, "Server name")
|
||||
MACRO_CONFIG_STR(SvHostname, sv_hostname, 128, "", CFGFLAG_SAVE|CFGFLAG_SERVER, "Server hostname")
|
||||
MACRO_CONFIG_STR(Bindaddr, bindaddr, 128, "", CFGFLAG_SAVE|CFGFLAG_CLIENT|CFGFLAG_SERVER|CFGFLAG_MASTER, "Address to bind the client/server to")
|
||||
MACRO_CONFIG_INT(SvPort, sv_port, 8303, 0, 0, CFGFLAG_SAVE|CFGFLAG_SERVER, "Port to use for the server")
|
||||
MACRO_CONFIG_INT(SvExternalPort, sv_external_port, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_SERVER, "External port to report to the master servers")
|
||||
MACRO_CONFIG_STR(SvMap, sv_map, 128, "dm1", CFGFLAG_SAVE|CFGFLAG_SERVER, "Map to use on the server")
|
||||
MACRO_CONFIG_INT(SvMaxClients, sv_max_clients, 8, 1, MAX_CLIENTS, CFGFLAG_SAVE|CFGFLAG_SERVER, "Maximum number of clients that are allowed on a server")
|
||||
MACRO_CONFIG_INT(SvMaxClientsPerIP, sv_max_clients_per_ip, 4, 1, MAX_CLIENTS, CFGFLAG_SAVE|CFGFLAG_SERVER, "Maximum number of clients with the same IP that can connect to the server")
|
||||
MACRO_CONFIG_INT(SvMapDownloadSpeed, sv_map_download_speed, 2, 1, 16, CFGFLAG_SAVE|CFGFLAG_SERVER, "Number of map data packages a client gets on each request")
|
||||
MACRO_CONFIG_INT(SvHighBandwidth, sv_high_bandwidth, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_SERVER, "Use high bandwidth mode. Doubles the bandwidth required for the server. LAN use only")
|
||||
MACRO_CONFIG_INT(SvRegister, sv_register, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_SERVER, "Register server with master server for public listing")
|
||||
MACRO_CONFIG_STR(SvRconPassword, sv_rcon_password, 32, "", CFGFLAG_SAVE|CFGFLAG_SERVER, "Remote console password (full access)")
|
||||
MACRO_CONFIG_STR(SvRconModPassword, sv_rcon_mod_password, 32, "", CFGFLAG_SAVE|CFGFLAG_SERVER, "Remote console password for moderators (limited access)")
|
||||
MACRO_CONFIG_INT(SvRconMaxTries, sv_rcon_max_tries, 3, 0, 100, CFGFLAG_SAVE|CFGFLAG_SERVER, "Maximum number of tries for remote console authentication")
|
||||
MACRO_CONFIG_INT(SvRconBantime, sv_rcon_bantime, 5, 0, 1440, CFGFLAG_SAVE|CFGFLAG_SERVER, "The time a client gets banned if remote console authentication fails. 0 makes it just use kick")
|
||||
MACRO_CONFIG_INT(SvAutoDemoRecord, sv_auto_demo_record, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_SERVER, "Automatically record demos")
|
||||
MACRO_CONFIG_INT(SvAutoDemoMax, sv_auto_demo_max, 10, 0, 1000, CFGFLAG_SAVE|CFGFLAG_SERVER, "Maximum number of automatically recorded demos (0 = no limit)")
|
||||
|
||||
MACRO_CONFIG_STR(EcBindaddr, ec_bindaddr, 128, "localhost", CFGFLAG_ECON, "Address to bind the external console to. Anything but 'localhost' is dangerous")
|
||||
MACRO_CONFIG_INT(EcPort, ec_port, 0, 0, 0, CFGFLAG_ECON, "Port to use for the external console")
|
||||
MACRO_CONFIG_STR(EcPassword, ec_password, 32, "", CFGFLAG_ECON, "External console password")
|
||||
MACRO_CONFIG_INT(EcBantime, ec_bantime, 0, 0, 1440, CFGFLAG_ECON, "The time a client gets banned if econ authentication fails. 0 just closes the connection")
|
||||
MACRO_CONFIG_INT(EcAuthTimeout, ec_auth_timeout, 30, 1, 120, CFGFLAG_ECON, "Time in seconds before the the econ authentification times out")
|
||||
MACRO_CONFIG_INT(EcOutputLevel, ec_output_level, 1, 0, 2, CFGFLAG_ECON, "Adjusts the amount of information in the external console")
|
||||
MACRO_CONFIG_STR(EcBindaddr, ec_bindaddr, 128, "localhost", CFGFLAG_SAVE|CFGFLAG_ECON, "Address to bind the external console to. Anything but 'localhost' is dangerous")
|
||||
MACRO_CONFIG_INT(EcPort, ec_port, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_ECON, "Port to use for the external console")
|
||||
MACRO_CONFIG_STR(EcPassword, ec_password, 32, "", CFGFLAG_SAVE|CFGFLAG_ECON, "External console password")
|
||||
MACRO_CONFIG_INT(EcBantime, ec_bantime, 0, 0, 1440, CFGFLAG_SAVE|CFGFLAG_ECON, "The time a client gets banned if econ authentication fails. 0 just closes the connection")
|
||||
MACRO_CONFIG_INT(EcAuthTimeout, ec_auth_timeout, 30, 1, 120, CFGFLAG_SAVE|CFGFLAG_ECON, "Time in seconds before the the econ authentification times out")
|
||||
MACRO_CONFIG_INT(EcOutputLevel, ec_output_level, 1, 0, 2, CFGFLAG_SAVE|CFGFLAG_ECON, "Adjusts the amount of information in the external console")
|
||||
|
||||
MACRO_CONFIG_INT(Debug, debug, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SERVER, "Debug mode")
|
||||
MACRO_CONFIG_INT(DbgStress, dbg_stress, 0, 0, 0, CFGFLAG_CLIENT|CFGFLAG_SERVER, "Stress systems")
|
||||
|
|
|
@ -574,15 +574,8 @@ void CNetBan::ConBansSave(IConsole::IResult *pResult, void *pUser)
|
|||
{
|
||||
CNetBan *pThis = static_cast<CNetBan *>(pUser);
|
||||
char aBuf[256];
|
||||
|
||||
const char *pFilename = pResult->GetString(0);
|
||||
if (str_safe_as_pathname(pFilename) != 0)
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "failed to save server banlist: '%s' is not an allowed path", pFilename);
|
||||
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aBuf);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
IOHANDLE File = pThis->Storage()->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||
if(!File)
|
||||
{
|
||||
|
|
|
@ -68,7 +68,7 @@ public:
|
|||
fs_makedir(GetPath(TYPE_SAVE, "dumps", aPath, sizeof(aPath)));
|
||||
fs_makedir(GetPath(TYPE_SAVE, "demos", aPath, sizeof(aPath)));
|
||||
fs_makedir(GetPath(TYPE_SAVE, "demos/auto", aPath, sizeof(aPath)));
|
||||
fs_makedir(GetPath(TYPE_SAVE, "serverconf", aPath, sizeof(aPath)));
|
||||
fs_makedir(GetPath(TYPE_SAVE, "configs", aPath, sizeof(aPath)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -263,6 +263,14 @@ public:
|
|||
BufferSize = sizeof(aBuffer);
|
||||
}
|
||||
|
||||
// check for valid path
|
||||
if(str_check_pathname(pFilename) != 0)
|
||||
{
|
||||
pBuffer[0] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// open file
|
||||
if(Flags&IOFLAG_WRITE)
|
||||
{
|
||||
return io_open(GetPath(TYPE_SAVE, pFilename, pBuffer, BufferSize), Flags);
|
||||
|
|
|
@ -87,34 +87,34 @@ MACRO_CONFIG_INT(ClRotationSpeed, cl_rotation_speed, 40, 1, 120, CFGFLAG_CLIENT|
|
|||
MACRO_CONFIG_INT(ClShowStartMenuImages, cl_show_start_menu_images, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show start menu images")
|
||||
|
||||
// server
|
||||
MACRO_CONFIG_INT(SvWarmup, sv_warmup, 0, -1, 1000, CFGFLAG_SERVER, "Number of seconds to do warmup before match starts (0 disables, -1 all players ready)")
|
||||
MACRO_CONFIG_STR(SvMotd, sv_motd, 900, "", CFGFLAG_SERVER, "Message of the day to display for the clients")
|
||||
MACRO_CONFIG_INT(SvTeamdamage, sv_teamdamage, 0, 0, 1, CFGFLAG_SERVER, "Team damage")
|
||||
MACRO_CONFIG_STR(SvMaprotation, sv_maprotation, 768, "", CFGFLAG_SERVER, "Maps to rotate between")
|
||||
MACRO_CONFIG_INT(SvMatchesPerMap, sv_matches_per_map, 1, 1, 100, CFGFLAG_SERVER, "Number of matches on each map before rotating")
|
||||
MACRO_CONFIG_INT(SvMatchSwap, sv_match_swap, 1, 0, 1, CFGFLAG_SERVER, "Swap teams between matches")
|
||||
MACRO_CONFIG_INT(SvPowerups, sv_powerups, 1, 0, 1, CFGFLAG_SERVER, "Allow powerups like ninja")
|
||||
MACRO_CONFIG_INT(SvScorelimit, sv_scorelimit, 20, 0, 1000, CFGFLAG_SERVER, "Score limit (0 disables)")
|
||||
MACRO_CONFIG_INT(SvTimelimit, sv_timelimit, 0, 0, 1000, CFGFLAG_SERVER, "Time limit in minutes (0 disables)")
|
||||
MACRO_CONFIG_STR(SvGametype, sv_gametype, 32, "dm", CFGFLAG_SERVER, "Game type (dm, tdm, ctf, lms, sur)")
|
||||
MACRO_CONFIG_INT(SvTournamentMode, sv_tournament_mode, 0, 0, 1, CFGFLAG_SERVER, "Tournament mode. When enabled, players joins the server as spectator")
|
||||
MACRO_CONFIG_INT(SvPlayerReadyMode, sv_player_ready_mode, 0, 0, 1, CFGFLAG_SERVER, "When enabled, players can pause/unpause the game and start the game on warmup via their ready state")
|
||||
MACRO_CONFIG_INT(SvSpamprotection, sv_spamprotection, 1, 0, 1, CFGFLAG_SERVER, "Spam protection")
|
||||
MACRO_CONFIG_INT(SvWarmup, sv_warmup, 0, -1, 1000, CFGFLAG_SAVE|CFGFLAG_SERVER, "Number of seconds to do warmup before match starts (0 disables, -1 all players ready)")
|
||||
MACRO_CONFIG_STR(SvMotd, sv_motd, 900, "", CFGFLAG_SAVE|CFGFLAG_SERVER, "Message of the day to display for the clients")
|
||||
MACRO_CONFIG_INT(SvTeamdamage, sv_teamdamage, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_SERVER, "Team damage")
|
||||
MACRO_CONFIG_STR(SvMaprotation, sv_maprotation, 768, "", CFGFLAG_SAVE|CFGFLAG_SERVER, "Maps to rotate between")
|
||||
MACRO_CONFIG_INT(SvMatchesPerMap, sv_matches_per_map, 1, 1, 100, CFGFLAG_SAVE|CFGFLAG_SERVER, "Number of matches on each map before rotating")
|
||||
MACRO_CONFIG_INT(SvMatchSwap, sv_match_swap, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_SERVER, "Swap teams between matches")
|
||||
MACRO_CONFIG_INT(SvPowerups, sv_powerups, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_SERVER, "Allow powerups like ninja")
|
||||
MACRO_CONFIG_INT(SvScorelimit, sv_scorelimit, 20, 0, 1000, CFGFLAG_SAVE|CFGFLAG_SERVER, "Score limit (0 disables)")
|
||||
MACRO_CONFIG_INT(SvTimelimit, sv_timelimit, 0, 0, 1000, CFGFLAG_SAVE|CFGFLAG_SERVER, "Time limit in minutes (0 disables)")
|
||||
MACRO_CONFIG_STR(SvGametype, sv_gametype, 32, "dm", CFGFLAG_SAVE|CFGFLAG_SERVER, "Game type (dm, tdm, ctf, lms, sur)")
|
||||
MACRO_CONFIG_INT(SvTournamentMode, sv_tournament_mode, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_SERVER, "Tournament mode. When enabled, players joins the server as spectator")
|
||||
MACRO_CONFIG_INT(SvPlayerReadyMode, sv_player_ready_mode, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_SERVER, "When enabled, players can pause/unpause the game and start the game on warmup via their ready state")
|
||||
MACRO_CONFIG_INT(SvSpamprotection, sv_spamprotection, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_SERVER, "Spam protection")
|
||||
|
||||
MACRO_CONFIG_INT(SvRespawnDelayTDM, sv_respawn_delay_tdm, 3, 0, 10, CFGFLAG_SERVER, "Time needed to respawn after death in tdm gametype")
|
||||
MACRO_CONFIG_INT(SvRespawnDelayTDM, sv_respawn_delay_tdm, 3, 0, 10, CFGFLAG_SAVE|CFGFLAG_SERVER, "Time needed to respawn after death in tdm gametype")
|
||||
|
||||
MACRO_CONFIG_INT(SvSpectatorSlots, sv_spectator_slots, 0, 0, MAX_CLIENTS, CFGFLAG_SERVER, "Number of slots to reserve for spectators")
|
||||
MACRO_CONFIG_INT(SvSkillLevel, sv_skill_level, 1, SERVERINFO_LEVEL_MIN, SERVERINFO_LEVEL_MAX, CFGFLAG_SERVER, "Supposed player skill level")
|
||||
MACRO_CONFIG_INT(SvTeambalanceTime, sv_teambalance_time, 1, 0, 1000, CFGFLAG_SERVER, "How many minutes to wait before autobalancing teams")
|
||||
MACRO_CONFIG_INT(SvInactiveKickTime, sv_inactivekick_time, 3, 0, 1000, CFGFLAG_SERVER, "How many minutes to wait before taking care of inactive players")
|
||||
MACRO_CONFIG_INT(SvInactiveKick, sv_inactivekick, 1, 0, 2, CFGFLAG_SERVER, "How to deal with inactive players (0=move to spectator, 1=move to free spectator slot/kick, 2=kick)")
|
||||
MACRO_CONFIG_INT(SvSpectatorSlots, sv_spectator_slots, 0, 0, MAX_CLIENTS, CFGFLAG_SAVE|CFGFLAG_SERVER, "Number of slots to reserve for spectators")
|
||||
MACRO_CONFIG_INT(SvSkillLevel, sv_skill_level, 1, SERVERINFO_LEVEL_MIN, SERVERINFO_LEVEL_MAX, CFGFLAG_SAVE|CFGFLAG_SERVER, "Supposed player skill level")
|
||||
MACRO_CONFIG_INT(SvTeambalanceTime, sv_teambalance_time, 1, 0, 1000, CFGFLAG_SAVE|CFGFLAG_SERVER, "How many minutes to wait before autobalancing teams")
|
||||
MACRO_CONFIG_INT(SvInactiveKickTime, sv_inactivekick_time, 3, 0, 1000, CFGFLAG_SAVE|CFGFLAG_SERVER, "How many minutes to wait before taking care of inactive players")
|
||||
MACRO_CONFIG_INT(SvInactiveKick, sv_inactivekick, 1, 0, 2, CFGFLAG_SAVE|CFGFLAG_SERVER, "How to deal with inactive players (0=move to spectator, 1=move to free spectator slot/kick, 2=kick)")
|
||||
|
||||
MACRO_CONFIG_INT(SvStrictSpectateMode, sv_strict_spectate_mode, 0, 0, 1, CFGFLAG_SERVER, "Restricts information in spectator mode")
|
||||
MACRO_CONFIG_INT(SvVoteSpectate, sv_vote_spectate, 1, 0, 1, CFGFLAG_SERVER, "Allow voting to move players to spectators")
|
||||
MACRO_CONFIG_INT(SvVoteSpectateRejoindelay, sv_vote_spectate_rejoindelay, 3, 0, 1000, CFGFLAG_SERVER, "How many minutes to wait before a player can rejoin after being moved to spectators by vote")
|
||||
MACRO_CONFIG_INT(SvVoteKick, sv_vote_kick, 1, 0, 1, CFGFLAG_SERVER, "Allow voting to kick players")
|
||||
MACRO_CONFIG_INT(SvVoteKickMin, sv_vote_kick_min, 0, 0, MAX_CLIENTS, CFGFLAG_SERVER, "Minimum number of players required to start a kick vote")
|
||||
MACRO_CONFIG_INT(SvVoteKickBantime, sv_vote_kick_bantime, 5, 0, 1440, CFGFLAG_SERVER, "The time to ban a player if kicked by vote. 0 makes it just use kick")
|
||||
MACRO_CONFIG_INT(SvStrictSpectateMode, sv_strict_spectate_mode, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_SERVER, "Restricts information in spectator mode")
|
||||
MACRO_CONFIG_INT(SvVoteSpectate, sv_vote_spectate, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_SERVER, "Allow voting to move players to spectators")
|
||||
MACRO_CONFIG_INT(SvVoteSpectateRejoindelay, sv_vote_spectate_rejoindelay, 3, 0, 1000, CFGFLAG_SAVE|CFGFLAG_SERVER, "How many minutes to wait before a player can rejoin after being moved to spectators by vote")
|
||||
MACRO_CONFIG_INT(SvVoteKick, sv_vote_kick, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_SERVER, "Allow voting to kick players")
|
||||
MACRO_CONFIG_INT(SvVoteKickMin, sv_vote_kick_min, 0, 0, MAX_CLIENTS, CFGFLAG_SAVE|CFGFLAG_SERVER, "Minimum number of players required to start a kick vote")
|
||||
MACRO_CONFIG_INT(SvVoteKickBantime, sv_vote_kick_bantime, 5, 0, 1440, CFGFLAG_SAVE|CFGFLAG_SERVER, "The time to ban a player if kicked by vote. 0 makes it just use kick")
|
||||
|
||||
// debug
|
||||
#ifdef CONF_DEBUG // this one can crash the server if not used correctly
|
||||
|
|
|
@ -330,10 +330,11 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
mem_copy(m_CountData.m_Header, SERVERBROWSE_COUNT, sizeof(SERVERBROWSE_COUNT));
|
||||
mem_copy(m_CountDataLegacy.m_Header, SERVERBROWSE_COUNT_LEGACY, sizeof(SERVERBROWSE_COUNT_LEGACY));
|
||||
|
||||
int FlagMask = CFGFLAG_MASTER;
|
||||
IKernel *pKernel = IKernel::Create();
|
||||
IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_BASIC, argc, argv);
|
||||
IConfig *pConfig = CreateConfig();
|
||||
m_pConsole = CreateConsole(CFGFLAG_MASTER);
|
||||
m_pConsole = CreateConsole(FlagMask);
|
||||
|
||||
bool RegisterFail = !pKernel->RegisterInterface(pStorage);
|
||||
RegisterFail |= !pKernel->RegisterInterface(m_pConsole);
|
||||
|
@ -342,7 +343,7 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
if(RegisterFail)
|
||||
return -1;
|
||||
|
||||
pConfig->Init();
|
||||
pConfig->Init(FlagMask);
|
||||
m_NetBan.Init(m_pConsole, pStorage);
|
||||
if(argc > 1) // ignore_convention
|
||||
m_pConsole->ParseArguments(argc-1, &argv[1]); // ignore_convention
|
||||
|
|
Loading…
Reference in a new issue