1
0

Merge pull request #309 from mc-server/configautogen

Autogeneration of settings.ini and webadmin.ini
This commit is contained in:
Mattes D 2013-11-05 13:24:23 -08:00
commit 12eeb3f6c8
18 changed files with 101 additions and 117 deletions

View File

@ -11,5 +11,3 @@ Lua-LICENSE.txt
LuaExpat-license.html LuaExpat-license.html
LuaSQLite3-LICENSE.txt LuaSQLite3-LICENSE.txt
MersenneTwister-LICENSE.txt MersenneTwister-LICENSE.txt
settings.example.ini
webadmin.example.ini

View File

@ -1,32 +0,0 @@
; This is the main server configuration
; For help, please visit the Wiki page: http://www.mc-server.org/wiki/doku.php?id=configure:settings.ini
; Most of these settings can also be set using the webadmin interface, if it is enabled.
[Server]
Port=25565
MaxPlayers=100
Description=MCServer - in C++
DefaultViewDistance=9
[Worlds]
DefaultWorld=world
[Plugins]
; Plugin=Debuggers
; Plugin=DiamondMover
; Plugin=HookNotify
Plugin=Core
Plugin=ChunkWorx
Plugin=ChatLog
Plugin=TransAPI
[Monsters]
AnimalsOn=0
AnimalSpawnInterval=10
Types=Spider,Chicken,Cow,Pig,Sheep,Squid,Enderman,Zombiepigman,Cavespider,Creeper,Ghast,Silverfish,Skeleton,Slime,Spider,Zombie
[Authentication]
Server=session.minecraft.net
Address=/game/checkserver.jsp?user=%USERNAME%&serverId=%SERVERID%
Authenticate=0

View File

@ -1,6 +0,0 @@
[WebAdmin]
Enabled=1
Port=8081
[User:admin]
Password=admin

View File

@ -46,28 +46,9 @@ cAuthenticator::~cAuthenticator()
/// Read custom values from INI /// Read custom values from INI
void cAuthenticator::ReadINI(cIniFile & IniFile) void cAuthenticator::ReadINI(cIniFile & IniFile)
{ {
m_Server = IniFile.GetValue("Authentication", "Server"); m_Server = IniFile.GetValueSet("Authentication", "Server", DEFAULT_AUTH_SERVER);
m_Address = IniFile.GetValue("Authentication", "Address"); m_Address = IniFile.GetValueSet("Authentication", "Address", DEFAULT_AUTH_ADDRESS);
m_ShouldAuthenticate = IniFile.GetValueB("Authentication", "Authenticate", true); m_ShouldAuthenticate = IniFile.GetValueSetB("Authentication", "Authenticate", true);
bool bSave = false;
if (m_Server.length() == 0)
{
m_Server = DEFAULT_AUTH_SERVER;
IniFile.SetValue("Authentication", "Server", m_Server);
bSave = true;
}
if (m_Address.length() == 0)
{
m_Address = DEFAULT_AUTH_ADDRESS;
IniFile.SetValue("Authentication", "Address", m_Address);
bSave = true;
}
if (bSave)
{
IniFile.SetValueB("Authentication", "Authenticate", m_ShouldAuthenticate);
}
} }
@ -199,7 +180,7 @@ bool cAuthenticator::AuthFromAddress(const AString & a_Server, const AString & a
} }
else if (code == 200) else if (code == 200)
{ {
LOGINFO("Got 200 OK :D"); LOGD("cAuthenticator: Received status 200 OK! :D");
bOK = true; bOK = true;
} }
} }
@ -268,17 +249,16 @@ bool cAuthenticator::AuthFromAddress(const AString & a_Server, const AString & a
std::string Result; std::string Result;
ss >> Result; ss >> Result;
LOGINFO("Got result: %s", Result.c_str()); LOGD("cAuthenticator: Authentication result was %s", Result.c_str());
//if (Result.compare("3") == 0) // FIXME: Quick and dirty hack to support auth
//Lapayo: Wtf 3?
if (Result.compare("YES") == 0) //Works well if (Result.compare("YES") == 0) //Works well
{ {
LOGINFO("Result was \"YES\", so player is authenticated!"); LOGINFO("Authentication result \"YES\", player authentication success!");
return true; return true;
} }
LOGINFO("Result was \"%s\", so player is NOT authenticated!", Result.c_str()); LOGINFO("Authentication result was \"%s\", player authentication failure!", Result.c_str());
return false; return false;
} }

View File

@ -166,19 +166,6 @@ public:
} }
/*
virtual bool CanBePlacedAt(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) override
{
if (TorchCanBePlacedAt(a_World, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace))
{
return true;
}
return (FindSuitableFace(a_World, a_BlockX, a_BlockY, a_BlockZ) != BLOCK_FACE_BOTTOM);
}
*/
virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{ {
char Face = MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); char Face = MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ));

View File

@ -205,7 +205,7 @@ void cClientHandle::Kick(const AString & a_Reason)
{ {
if (m_State >= csAuthenticating) // Don't log pings if (m_State >= csAuthenticating) // Don't log pings
{ {
LOG("Kicking user \"%s\" for \"%s\"", m_Username.c_str(), a_Reason.c_str()); LOG("Kicking user \"%s\" for \"%s\"", m_Username.c_str(), StripColorCodes(a_Reason).c_str());
} }
SendDisconnect(a_Reason); SendDisconnect(a_Reason);
} }
@ -2187,7 +2187,7 @@ void cClientHandle::SocketClosed(void)
{ {
// The socket has been closed for any reason // The socket has been closed for any reason
LOG("Client \"%s\" @ %s disconnected", m_Username.c_str(), m_IPString.c_str()); LOGD("Client \"%s\" @ %s disconnected", m_Username.c_str(), m_IPString.c_str());
Destroy(); Destroy();
} }

View File

@ -35,10 +35,15 @@ extern bool g_BlockPistonBreakable[256];
/// Can this block hold snow atop? /// Can this block hold snow atop?
extern bool g_BlockIsSnowable[256]; extern bool g_BlockIsSnowable[256];
/// Does this block require a tool to drop?
extern bool g_BlockRequiresSpecialTool[256]; extern bool g_BlockRequiresSpecialTool[256];
/// Is this block solid (player cannot walk through)?
extern bool g_BlockIsSolid[256]; extern bool g_BlockIsSolid[256];
/// Can torches be placed on this block?
extern bool g_BlockIsTorchPlaceable[256];

View File

@ -108,8 +108,8 @@
#include "LeakFinder.h" #include "LeakFinder.h"
// Currently only tested with MS VC++ 5 to 10 // Currently only tested with MS VC++ 5 to 10
#if (_MSC_VER < 1100) || (_MSC_VER > 1700) #if (_MSC_VER < 1100) || (_MSC_VER > 1800)
#error Only MS VC++ 5/6/7/7.1/8/9 supported. Check if the '_CrtMemBlockHeader' has not changed with this compiler! #error Only MS VC++ 5/6/7/7.1/8/9/10/11/12 supported. Check if the '_CrtMemBlockHeader' has not changed with this compiler!
#endif #endif

View File

@ -71,10 +71,10 @@ cMonster::eType cMobSpawner::ChooseMobType(EMCSBiome a_Biome)
addIfAllowed(cMonster::mtZombiePigman, allowedMobs); addIfAllowed(cMonster::mtZombiePigman, allowedMobs);
addIfAllowed(cMonster::mtMagmaCube, allowedMobs); addIfAllowed(cMonster::mtMagmaCube, allowedMobs);
} }
/*else if (a_Biome == biEnder) MG TODO : figure out what are the biomes of the ender else if (a_Biome == biEnd)
{ {
addIfAllowed(cMonster::mtEnderman, allowedMobs); addIfAllowed(cMonster::mtEnderman, allowedMobs);
}*/ }
else else
{ {
addIfAllowed(cMonster::mtBat, allowedMobs); addIfAllowed(cMonster::mtBat, allowedMobs);
@ -210,7 +210,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
return (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && (!g_BlockTransparent[BlockBelow]) && return (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && (!g_BlockTransparent[BlockBelow]) &&
(m_Random.NextInt(20,a_Biome) == 0); (m_Random.NextInt(20,a_Biome) == 0);
default: default:
LOGD("MG TODO : check I've got a Rule to write for type %d",a_MobType); LOGD("MG TODO: Write spawning rule for mob type %d", a_MobType);
return false; return false;
} }
} }

View File

@ -94,6 +94,17 @@ void cPluginManager::FindPlugins(void)
void cPluginManager::ReloadPluginsNow(void) void cPluginManager::ReloadPluginsNow(void)
{
cIniFile a_SettingsIni;
a_SettingsIni.ReadFile("settings.ini");
ReloadPluginsNow(a_SettingsIni);
}
void cPluginManager::ReloadPluginsNow(cIniFile & a_SettingsIni)
{ {
LOG("-- Loading Plugins --"); LOG("-- Loading Plugins --");
m_bReloadPlugins = false; m_bReloadPlugins = false;
@ -103,25 +114,20 @@ void cPluginManager::ReloadPluginsNow(void)
cServer::BindBuiltInConsoleCommands(); cServer::BindBuiltInConsoleCommands();
cIniFile IniFile; unsigned int KeyNum = a_SettingsIni.FindKey("Plugins");
if (!IniFile.ReadFile("settings.ini")) unsigned int NumPlugins = ((KeyNum != -1) ? (a_SettingsIni.GetNumValues(KeyNum)) : 0);
if (KeyNum == -1)
{ {
LOGWARNING("cPluginManager: Can't find settings.ini, so can't load any plugins."); InsertDefaultPlugins(a_SettingsIni);
} }
else if (NumPlugins > 0)
unsigned int KeyNum = IniFile.FindKey("Plugins");
unsigned int NumPlugins = IniFile.GetNumValues(KeyNum);
if (NumPlugins > 0)
{ {
for(unsigned int i = 0; i < NumPlugins; i++) for(unsigned int i = 0; i < NumPlugins; i++)
{ {
AString ValueName = IniFile.GetValueName(KeyNum, i ); AString ValueName = a_SettingsIni.GetValueName(KeyNum, i);
if ( if (ValueName.compare("Plugin") == 0)
(ValueName.compare("NewPlugin") == 0) ||
(ValueName.compare("Plugin") == 0)
)
{ {
AString PluginFile = IniFile.GetValue(KeyNum, i); AString PluginFile = a_SettingsIni.GetValue(KeyNum, i);
if (!PluginFile.empty()) if (!PluginFile.empty())
{ {
if (m_Plugins.find(PluginFile) != m_Plugins.end()) if (m_Plugins.find(PluginFile) != m_Plugins.end())
@ -137,7 +143,7 @@ void cPluginManager::ReloadPluginsNow(void)
{ {
LOG("-- No Plugins Loaded --"); LOG("-- No Plugins Loaded --");
} }
else if ((GetNumPlugins() > 1) || (GetNumPlugins() == 0)) else if (GetNumPlugins() > 1)
{ {
LOG("-- Loaded %i Plugins --", GetNumPlugins()); LOG("-- Loaded %i Plugins --", GetNumPlugins());
} }
@ -151,6 +157,22 @@ void cPluginManager::ReloadPluginsNow(void)
void cPluginManager::InsertDefaultPlugins(cIniFile & a_SettingsIni)
{
a_SettingsIni.AddKeyName("Plugins");
a_SettingsIni.AddKeyComment("Plugins", " Plugin=Debuggers");
a_SettingsIni.AddKeyComment("Plugins", " Plugin=HookNotify");
a_SettingsIni.AddKeyComment("Plugins", " Plugin=ChunkWorx");
a_SettingsIni.AddKeyComment("Plugins", " Plugin=APIDump");
a_SettingsIni.SetValue("Plugins", "Plugin", "Core");
a_SettingsIni.SetValue("Plugins", "Plugin", "TransAPI");
a_SettingsIni.SetValue("Plugins", "Plugin", "ChatLog");
}
void cPluginManager::Tick(float a_Dt) void cPluginManager::Tick(float a_Dt)
{ {
while (!m_DisablePluginList.empty()) while (!m_DisablePluginList.empty())

View File

@ -271,9 +271,18 @@ private:
cPluginManager(); cPluginManager();
~cPluginManager(); ~cPluginManager();
/// Reloads all plugins, defaulting to settings.ini for settings location
void ReloadPluginsNow(void); void ReloadPluginsNow(void);
/// Reloads all plugins with a cIniFile object expected to be initialised to settings.ini
void ReloadPluginsNow(cIniFile & a_SettingsIni);
/// Unloads all plugins
void UnloadPluginsNow(void); void UnloadPluginsNow(void);
/// Handles writing default plugins if 'Plugins' key not found using a cIniFile object expected to be intialised to settings.ini
void InsertDefaultPlugins(cIniFile & a_SettingsIni);
/// Adds the plugin into the internal list of plugins and initializes it. If initialization fails, the plugin is removed again. /// Adds the plugin into the internal list of plugins and initializes it. If initialization fails, the plugin is removed again.
bool AddPlugin(cPlugin * a_Plugin); bool AddPlugin(cPlugin * a_Plugin);

View File

@ -119,8 +119,12 @@ void cRoot::Start(void)
cIniFile IniFile; cIniFile IniFile;
if (!IniFile.ReadFile("settings.ini")) if (!IniFile.ReadFile("settings.ini"))
{ {
LOGWARNING("settings.ini inaccessible, all settings are reset to default values"); LOGWARN("Regenerating settings.ini, all settings will be reset");
IniFile.AddHeaderComment(" This is the main server configuration");
IniFile.AddHeaderComment(" Most of the settings here can be configured using the webadmin interface, if enabled in webadmin.ini");
IniFile.AddHeaderComment(" See: http://www.mc-server.org/wiki/doku.php?id=configure:settings.ini for further configuration help");
} }
m_PrimaryServerVersion = IniFile.GetValueI("Server", "PrimaryServerVersion", 0); m_PrimaryServerVersion = IniFile.GetValueI("Server", "PrimaryServerVersion", 0);
if (m_PrimaryServerVersion == 0) if (m_PrimaryServerVersion == 0)
{ {
@ -129,7 +133,7 @@ void cRoot::Start(void)
else else
{ {
// Make a note in the log that the primary server version is explicitly set in the ini file // Make a note in the log that the primary server version is explicitly set in the ini file
LOGINFO("settings.ini: [Server].PrimaryServerVersion set to %d.", m_PrimaryServerVersion); LOGINFO("Primary server version set explicitly to %d.", m_PrimaryServerVersion);
} }
LOG("Starting server..."); LOG("Starting server...");
@ -152,7 +156,7 @@ void cRoot::Start(void)
LOGD("Loading plugin manager..."); LOGD("Loading plugin manager...");
m_PluginManager = new cPluginManager(); m_PluginManager = new cPluginManager();
m_PluginManager->ReloadPluginsNow(); m_PluginManager->ReloadPluginsNow(IniFile);
LOGD("Loading MonsterConfig..."); LOGD("Loading MonsterConfig...");
m_MonsterConfig = new cMonsterConfig; m_MonsterConfig = new cMonsterConfig;
@ -261,6 +265,7 @@ void cRoot::LoadWorlds(cIniFile & IniFile)
return; return;
} }
bool FoundAdditionalWorlds = false;
for (unsigned int i = 0; i < NumWorlds; i++) for (unsigned int i = 0; i < NumWorlds; i++)
{ {
AString ValueName = IniFile.GetValueName(KeyNum, i ); AString ValueName = IniFile.GetValueName(KeyNum, i );
@ -273,9 +278,15 @@ void cRoot::LoadWorlds(cIniFile & IniFile)
{ {
continue; continue;
} }
FoundAdditionalWorlds = true;
cWorld* NewWorld = new cWorld( WorldName.c_str() ); cWorld* NewWorld = new cWorld( WorldName.c_str() );
m_WorldsByName[ WorldName ] = NewWorld; m_WorldsByName[ WorldName ] = NewWorld;
} // for i - Worlds } // for i - Worlds
if (!FoundAdditionalWorlds)
{
IniFile.AddKeyComment("Worlds", " World=secondworld");
}
} }

View File

@ -195,8 +195,9 @@ void cServer::PlayerDestroying(const cPlayer * a_Player)
bool cServer::InitServer(cIniFile & a_SettingsIni) bool cServer::InitServer(cIniFile & a_SettingsIni)
{ {
m_Description = a_SettingsIni.GetValue ("Server", "Description", "MCServer! - In C++!").c_str(); m_Description = a_SettingsIni.GetValueSet("Server", "Description", "MCServer - in C++!").c_str();
m_MaxPlayers = a_SettingsIni.GetValueI("Server", "MaxPlayers", 100); m_MaxPlayers = a_SettingsIni.GetValueSetI("Server", "MaxPlayers", 100);
m_bIsHardcore = a_SettingsIni.GetValueSetB("Server", "HardcoreEnabled", false);
m_PlayerCount = 0; m_PlayerCount = 0;
m_PlayerCountDiff = 0; m_PlayerCountDiff = 0;
@ -320,7 +321,7 @@ void cServer::OnConnectionAccepted(cSocket & a_Socket)
return; return;
} }
LOG("Client \"%s\" connected!", ClientIP.c_str()); LOGD("Client \"%s\" connected!", ClientIP.c_str());
cClientHandle * NewHandle = new cClientHandle(&a_Socket, m_ClientViewDistance); cClientHandle * NewHandle = new cClientHandle(&a_Socket, m_ClientViewDistance);
if (!m_SocketThreads.AddClient(a_Socket, NewHandle)) if (!m_SocketThreads.AddClient(a_Socket, NewHandle))

View File

@ -46,6 +46,9 @@ public: // tolua_export
int GetNumPlayers(void); int GetNumPlayers(void);
void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; } void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; }
// Hardcore mode or not:
bool IsHardcore(void) const {return m_bIsHardcore; }
// tolua_end // tolua_end
bool Start(void); bool Start(void);
@ -161,6 +164,7 @@ private:
AString m_Description; AString m_Description;
int m_MaxPlayers; int m_MaxPlayers;
bool m_bIsHardcore;
cTickThread m_TickThread; cTickThread m_TickThread;
cEvent m_RestartEvent; cEvent m_RestartEvent;

View File

@ -56,7 +56,7 @@ cWebAdmin::~cWebAdmin()
{ {
if (m_IsInitialized) if (m_IsInitialized)
{ {
LOG("Stopping WebAdmin..."); LOGD("Stopping WebAdmin...");
} }
} }
@ -87,7 +87,11 @@ bool cWebAdmin::Init(void)
{ {
if (!m_IniFile.ReadFile("webadmin.ini")) if (!m_IniFile.ReadFile("webadmin.ini"))
{ {
return false; LOGWARN("Regenerating webadmin.ini, all settings will be reset");
m_IniFile.AddHeaderComment(" This file controls the webadmin feature of MCServer");
m_IniFile.AddHeaderComment(" Username format: [User:*username*] | Password format: Password=*password*; for example:");
m_IniFile.AddHeaderComment(" [User:admin]");
m_IniFile.AddHeaderComment(" Password=admin");
} }
if (!m_IniFile.GetValueSetB("WebAdmin", "Enabled", true)) if (!m_IniFile.GetValueSetB("WebAdmin", "Enabled", true))
@ -96,7 +100,7 @@ bool cWebAdmin::Init(void)
return true; return true;
} }
LOG("Initialising WebAdmin..."); LOGD("Initialising WebAdmin...");
AString PortsIPv4 = m_IniFile.GetValueSet("WebAdmin", "Port", "8080"); AString PortsIPv4 = m_IniFile.GetValueSet("WebAdmin", "Port", "8080");
AString PortsIPv6 = m_IniFile.GetValueSet("WebAdmin", "PortsIPv6", ""); AString PortsIPv6 = m_IniFile.GetValueSet("WebAdmin", "PortsIPv6", "");
@ -106,6 +110,7 @@ bool cWebAdmin::Init(void)
return false; return false;
} }
m_IsInitialized = true; m_IsInitialized = true;
m_IniFile.WriteFile("webadmin.ini");
return true; return true;
} }
@ -121,7 +126,7 @@ bool cWebAdmin::Start(void)
return false; return false;
} }
LOG("Starting WebAdmin..."); LOGD("Starting WebAdmin...");
// Initialize the WebAdmin template script and load the file // Initialize the WebAdmin template script and load the file
m_TemplateScript.Create(); m_TemplateScript.Create();

View File

@ -509,7 +509,7 @@ void cWorld::Start(void)
break; break;
} }
} }
m_bAnimals = IniFile.GetValueB("Monsters", "AnimalsOn", true); m_bAnimals = IniFile.GetValueSetB("Monsters", "AnimalsOn", true);
AString AllMonsters = IniFile.GetValueSet("Monsters", "Types", DefaultMonsters); AString AllMonsters = IniFile.GetValueSet("Monsters", "Types", DefaultMonsters);
AStringVector SplitList = StringSplitAndTrim(AllMonsters, ","); AStringVector SplitList = StringSplitAndTrim(AllMonsters, ",");
for (AStringVector::const_iterator itr = SplitList.begin(), end = SplitList.end(); itr != end; ++itr) for (AStringVector::const_iterator itr = SplitList.begin(), end = SplitList.end(); itr != end; ++itr)
@ -784,8 +784,8 @@ void cWorld::TickMobs(float a_Dt)
SpawnMobFinalize(*itr2); SpawnMobFinalize(*itr2);
} }
} }
} // for i - AllFamilies[] } // for i - AllFamilies[]
} // if (Spawning enabled) } // if (Spawning enabled)
// move close mobs // move close mobs
cMobProximityCounter::sIterablePair allCloseEnoughToMoveMobs = MobCensus.GetProximityCounter().getMobWithinThosesDistances(-1, 64 * 16);// MG TODO : deal with this magic number (the 16 is the size of a block) cMobProximityCounter::sIterablePair allCloseEnoughToMoveMobs = MobCensus.GetProximityCounter().getMobWithinThosesDistances(-1, 64 * 16);// MG TODO : deal with this magic number (the 16 is the size of a block)