From 21febaf4b342aecd5d797b1e2017591fde208388 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 21 Feb 2014 14:53:46 +0100 Subject: Add 'Group not found', when the Server load the users.ini and add auto generate from users.ini --- src/Entities/Player.cpp | 6 +++++- src/GroupManager.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/GroupManager.h | 2 ++ src/Root.cpp | 4 +++- src/Server.cpp | 4 ++++ 5 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 70ddb3c98..7a3aaf568 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1529,7 +1529,11 @@ void cPlayer::LoadPermissionsFromDisk() AStringVector Split = StringSplit( Groups, "," ); for( unsigned int i = 0; i < Split.size(); i++ ) { - AddToGroup( Split[i].c_str() ); + if (!cRoot::Get()->GetGroupManager()->ExistsGroup(Split[i])) + { + LOGWARNING("The group %s for player %s was not found!", Split[i].c_str(), m_PlayerName.c_str()); + } + AddToGroup(Split[i].c_str()); } } else diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp index 723b86f94..5125e7586 100644 --- a/src/GroupManager.cpp +++ b/src/GroupManager.cpp @@ -46,6 +46,7 @@ cGroupManager::cGroupManager() LOGD("-- Loading Groups --"); LoadGroups(); + CheckUsers(); LOGD("-- Groups Successfully Loaded --"); } @@ -54,6 +55,42 @@ cGroupManager::cGroupManager() +void cGroupManager::CheckUsers(void) +{ + cIniFile IniFile; + if (!IniFile.ReadFile("users.ini")) + { + LOGWARN("Regenerating users.ini, all users will be reset"); + IniFile.AddHeaderComment(" This is the file in which the group the player belongs to is stored"); + IniFile.AddHeaderComment(" The format is: [PlayerName] | Groups=GroupName"); + + IniFile.WriteFile("users.ini"); + return; + } + + unsigned int NumKeys = IniFile.GetNumKeys(); + for (size_t i = 0; i < NumKeys; i++) + { + AString Player = IniFile.GetKeyName( i ); + AString Groups = IniFile.GetValue(Player, "Groups", ""); + if (!Groups.empty()) + { + AStringVector Split = StringSplit( Groups, "," ); + for( unsigned int i = 0; i < Split.size(); i++ ) + { + if (!ExistsGroup(Split[i])) + { + LOGWARNING("The group %s for player %s was not found!", Split[i].c_str(), Player.c_str()); + } + } + } + } +} + + + + + void cGroupManager::LoadGroups() { cIniFile IniFile; @@ -137,6 +174,16 @@ void cGroupManager::LoadGroups() +bool cGroupManager::ExistsGroup( const AString & a_Name ) +{ + GroupMap::iterator itr = m_pState->Groups.find( a_Name ); + return ( itr != m_pState->Groups.end() ); +} + + + + + cGroup* cGroupManager::GetGroup( const AString & a_Name ) { GroupMap::iterator itr = m_pState->Groups.find( a_Name ); diff --git a/src/GroupManager.h b/src/GroupManager.h index 02a58fe4e..377a54c98 100644 --- a/src/GroupManager.h +++ b/src/GroupManager.h @@ -14,8 +14,10 @@ class cGroup; class cGroupManager { public: + bool ExistsGroup(const AString & a_Name); cGroup * GetGroup(const AString & a_Name); void LoadGroups(void); + void CheckUsers(void); private: friend class cRoot; diff --git a/src/Root.cpp b/src/Root.cpp index 206255916..8680c0082 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -194,7 +194,7 @@ void cRoot::Start(void) #if !defined(ANDROID_NDK) LOGD("Starting InputThread..."); m_InputThread = new cThread( InputThread, this, "cRoot::InputThread" ); - m_InputThread->Start( false ); // We should NOT wait? Otherwise we can´t stop the server from other threads than the input thread + m_InputThread->Start( false ); // We should NOT wait? Otherwise we can�t stop the server from other threads than the input thread #endif long long finishmseconds = Time.GetNowTime(); @@ -536,7 +536,9 @@ void cRoot::SaveAllChunks(void) void cRoot::ReloadGroups(void) { + LOG("Reload groups ..."); m_GroupManager->LoadGroups(); + m_GroupManager->CheckUsers(); } diff --git a/src/Server.cpp b/src/Server.cpp index ab1458da4..4842c1782 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -460,16 +460,20 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac { cPluginManager::Get()->ReloadPlugins(); cRoot::Get()->ReloadGroups(); + a_Output.Finished(); return; } if (split[0] == "reloadplugins") { cPluginManager::Get()->ReloadPlugins(); + a_Output.Finished(); return; } if (split[0] == "reloadgroups") { cRoot::Get()->ReloadGroups(); + a_Output.Out("Groups reloaded!"); + a_Output.Finished(); return; } -- cgit v1.2.3 From a75575855323c59496d26d89c271641a828e223e Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 21 Feb 2014 14:55:28 +0100 Subject: Unicode :-( --- src/Root.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Root.cpp b/src/Root.cpp index 8680c0082..af2cb9e4b 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -194,7 +194,7 @@ void cRoot::Start(void) #if !defined(ANDROID_NDK) LOGD("Starting InputThread..."); m_InputThread = new cThread( InputThread, this, "cRoot::InputThread" ); - m_InputThread->Start( false ); // We should NOT wait? Otherwise we can�t stop the server from other threads than the input thread + m_InputThread->Start( false ); // We should NOT wait? Otherwise we can't stop the server from other threads than the input thread #endif long long finishmseconds = Time.GetNowTime(); -- cgit v1.2.3 From 5b3957233402c36f3262b7246047131e65c5eeb3 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 21 Feb 2014 14:56:33 +0100 Subject: Remove old Output Finish --- src/Server.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Server.cpp b/src/Server.cpp index 4842c1782..c80348872 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -460,13 +460,11 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac { cPluginManager::Get()->ReloadPlugins(); cRoot::Get()->ReloadGroups(); - a_Output.Finished(); return; } if (split[0] == "reloadplugins") { cPluginManager::Get()->ReloadPlugins(); - a_Output.Finished(); return; } if (split[0] == "reloadgroups") -- cgit v1.2.3 From 3777873f22b8a19ed282be076357d5b3c2eb43ee Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 21 Feb 2014 15:10:31 +0100 Subject: Remove users.ini generation in Player.cpp and use the CheckUsers() Function --- src/Entities/Player.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 7a3aaf568..19173592e 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1545,12 +1545,7 @@ void cPlayer::LoadPermissionsFromDisk() } else { - LOGWARN("Regenerating users.ini, player %s will be added to the \"Default\" group", m_PlayerName.c_str()); - IniFile.AddHeaderComment(" This is the file in which the group the player belongs to is stored"); - IniFile.AddHeaderComment(" The format is: [PlayerName] | Groups=GroupName"); - - IniFile.SetValue(m_PlayerName, "Groups", "Default"); - IniFile.WriteFile("users.ini"); + cRoot::Get()->GetGroupManager()->CheckUsers(); AddToGroup("Default"); } ResolvePermissions(); -- cgit v1.2.3 From b3339a6617ffd7b8358c83348e6ccfa8eba2eb92 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 21 Feb 2014 22:26:04 +0100 Subject: Better Jukebox API --- src/BlockEntities/JukeboxEntity.cpp | 48 +++++++++++++++++++++++++++---------- src/BlockEntities/JukeboxEntity.h | 16 ++++++++++--- src/BlockID.h | 4 ++++ 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/src/BlockEntities/JukeboxEntity.cpp b/src/BlockEntities/JukeboxEntity.cpp index 33042179d..c96253b11 100644 --- a/src/BlockEntities/JukeboxEntity.cpp +++ b/src/BlockEntities/JukeboxEntity.cpp @@ -30,48 +30,70 @@ cJukeboxEntity::~cJukeboxEntity() void cJukeboxEntity::UsedBy(cPlayer * a_Player) { - if (m_Record == 0) + if (IsPlayingRecord()) + { + EjectRecord(); + } + else { const cItem & HeldItem = a_Player->GetEquippedItem(); - if (HeldItem.m_ItemType >= 2256 && HeldItem.m_ItemType <= 2267) + if (PlayRecord(HeldItem.m_ItemType)) { - m_Record = HeldItem.m_ItemType; a_Player->GetInventory().RemoveOneEquippedItem(); - PlayRecord(); } } - else - { - EjectRecord(); - } } -void cJukeboxEntity::PlayRecord(void) +bool cJukeboxEntity::PlayRecord(int a_Record) { + if (!IsRecordItem(a_Record)) + { + // This isn't a Record Item + return false; + } + if (IsPlayingRecord()) + { + // A Record is already in the Jukebox. + EjectRecord(); + } + m_Record = a_Record; m_World->BroadcastSoundParticleEffect(1005, m_PosX, m_PosY, m_PosZ, m_Record); + m_World->SetBlockMeta(m_PosX, m_PosY, m_PosZ, E_META_JUKEBOX_ON); + return true; } -void cJukeboxEntity::EjectRecord(void) +bool cJukeboxEntity::EjectRecord(void) { - if ((m_Record < E_ITEM_FIRST_DISC) || (m_Record > E_ITEM_LAST_DISC)) + if (!IsPlayingRecord()) { // There's no record here - return; + return false; } cItems Drops; Drops.push_back(cItem(m_Record, 1, 0)); + m_Record = 0; m_World->SpawnItemPickups(Drops, m_PosX + 0.5, m_PosY + 1, m_PosZ + 0.5, 8); m_World->BroadcastSoundParticleEffect(1005, m_PosX, m_PosY, m_PosZ, 0); - m_Record = 0; + m_World->SetBlockMeta(m_PosX, m_PosY, m_PosZ, E_META_JUKEBOX_OFF); + return true; +} + + + + + +bool cJukeboxEntity::IsPlayingRecord(void) +{ + return (m_Record != 0); } diff --git a/src/BlockEntities/JukeboxEntity.h b/src/BlockEntities/JukeboxEntity.h index 734d7bb66..01ce52494 100644 --- a/src/BlockEntities/JukeboxEntity.h +++ b/src/BlockEntities/JukeboxEntity.h @@ -37,10 +37,20 @@ public: int GetRecord(void); void SetRecord(int a_Record); - void PlayRecord(void); - /// Ejects the currently held record as a pickup. Does nothing when no record inserted. - void EjectRecord(void); + /** Play a Record. Return false, when a_Record isn't a Record */ + bool PlayRecord(int a_Record); + + /** Ejects the currently held record as a pickup. Return false when no record inserted. */ + bool EjectRecord(void); + + /** Is in the Jukebox a Record? */ + bool IsPlayingRecord(void); + + static bool IsRecordItem(int a_Item) + { + return ((a_Item >= E_ITEM_FIRST_DISC) && (a_Item <= E_ITEM_LAST_DISC)); + } // tolua_end diff --git a/src/BlockID.h b/src/BlockID.h index 3413555f4..861bb8dae 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -466,6 +466,10 @@ enum E_META_FLOWER_PINK_TULIP = 7, E_META_FLOWER_OXEYE_DAISY = 8, + // E_BLOCK_JUKEBOX metas + E_META_JUKEBOX_OFF = 0, + E_META_JUKEBOX_ON = 1, + // E_BLOCK_HOPPER metas: E_META_HOPPER_FACING_YM = 0, E_META_HOPPER_UNATTACHED = 1, // Hopper doesn't move items up, there's no YP -- cgit v1.2.3 From a23b5d13bde0742e6208bcc75807a97c1c12f7e1 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 27 Feb 2014 15:17:42 +0100 Subject: Added a "nooutbuf" cmdline param. This forces that the stdout stream uses no buffer, even when not a TTY. Used for running MCServer under ZeroBraneStudio. --- src/Log.cpp | 4 ++-- src/main.cpp | 27 ++++++++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index 2d6be0f59..1ea327d5d 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -42,7 +42,7 @@ cLog::~cLog() -cLog* cLog::GetInstance() +cLog * cLog::GetInstance() { if (s_Log != NULL) { @@ -92,7 +92,7 @@ void cLog::ClearLog() if( m_File ) fclose (m_File); #endif - m_File = 0; + m_File = NULL; } diff --git a/src/main.cpp b/src/main.cpp index 4d2801926..2ae8a413b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -243,31 +243,36 @@ int main( int argc, char **argv ) // Check if comm logging is to be enabled: for (int i = 0; i < argc; i++) { + AString Arg(argv[i]); if ( - (NoCaseCompare(argv[i], "/commlog") == 0) || - (NoCaseCompare(argv[i], "/logcomm") == 0) + (NoCaseCompare(Arg, "/commlog") == 0) || + (NoCaseCompare(Arg, "/logcomm") == 0) ) { g_ShouldLogCommIn = true; g_ShouldLogCommOut = true; } - if ( - (NoCaseCompare(argv[i], "/commlogin") == 0) || - (NoCaseCompare(argv[i], "/comminlog") == 0) || - (NoCaseCompare(argv[i], "/logcommin") == 0) + else if ( + (NoCaseCompare(Arg, "/commlogin") == 0) || + (NoCaseCompare(Arg, "/comminlog") == 0) || + (NoCaseCompare(Arg, "/logcommin") == 0) ) { g_ShouldLogCommIn = true; } - if ( - (NoCaseCompare(argv[i], "/commlogout") == 0) || - (NoCaseCompare(argv[i], "/commoutlog") == 0) || - (NoCaseCompare(argv[i], "/logcommout") == 0) + else if ( + (NoCaseCompare(Arg, "/commlogout") == 0) || + (NoCaseCompare(Arg, "/commoutlog") == 0) || + (NoCaseCompare(Arg, "/logcommout") == 0) ) { g_ShouldLogCommOut = true; } - } + else if (NoCaseCompare(Arg, "nooutbuf") == 0) + { + setvbuf(stdout, NULL, _IONBF, 0); + } + } // for i - argv[] #if !defined(ANDROID_NDK) try -- cgit v1.2.3 From 1de2c23d648af46a2e00402d0e231678c80311aa Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Thu, 27 Feb 2014 22:04:48 +0100 Subject: added mooshroom to cow conversion --- src/Mobs/Mooshroom.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 8e4c52ae6..81bd3e3b4 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -67,6 +67,8 @@ void cMooshroom::OnRightClicked(cPlayer & a_Player) cItems Drops; Drops.push_back(cItem(E_BLOCK_RED_MUSHROOM, 5, 0)); m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + m_World->SpawnMob(GetPosX(), GetPosY(), GetPosZ(), cMonster::mtCow); + Destroy(); } break; } } -- cgit v1.2.3 From 6a191cce0af0056ecde69efe1679a084aadd810c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Feb 2014 08:26:39 +0100 Subject: Fixed compatibility with ZeroBraneStudio and LuaRocks. Lua now compiles into lua51.dll and there's a lua5.1.dll that acts as a export-forwarding proxy to lua51.dll. --- MCServer/lua5.1.dll | Bin 0 -> 6722 bytes lib/lua/CMakeLists.txt | 6 +++++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 MCServer/lua5.1.dll diff --git a/MCServer/lua5.1.dll b/MCServer/lua5.1.dll new file mode 100644 index 000000000..cca0bcb25 Binary files /dev/null and b/MCServer/lua5.1.dll differ diff --git a/lib/lua/CMakeLists.txt b/lib/lua/CMakeLists.txt index 4babae9b2..db112d557 100644 --- a/lib/lua/CMakeLists.txt +++ b/lib/lua/CMakeLists.txt @@ -47,8 +47,12 @@ if (WIN32) ) endif() + set_target_properties(lua PROPERTIES OUTPUT_NAME "lua51") + # NOTE: The DLL for each configuration is stored at the same place, thus overwriting each other. - # This is known, however such behavior is needed for LuaRocks - they always load "lua.dll" + # This is known, however such behavior is needed for LuaRocks - they always load "lua5.1.dll" or "lua51.dll" + # We make it work by compiling to "lua51.dll" and providing a proxy-DLL "lua5.1.dll" + # See http://lua-users.org/wiki/LuaProxyDllFour for details else() add_library(lua ${SOURCE}) endif() -- cgit v1.2.3 From 0aac17874c25a2c1be36a8b5d691331852cec49f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Feb 2014 08:31:35 +0100 Subject: Better fix for the 32-bit float reading. --- src/WorldStorage/FastNBT.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/WorldStorage/FastNBT.h b/src/WorldStorage/FastNBT.h index a78b610cb..49f97c458 100644 --- a/src/WorldStorage/FastNBT.h +++ b/src/WorldStorage/FastNBT.h @@ -173,13 +173,14 @@ public: { ASSERT(m_Tags[a_Tag].m_Type == TAG_Float); - // Cause a compile-time error if sizeof(int) != sizeof(float) - char Check1[sizeof(int) - sizeof(float) + 1]; // sizeof(int) >= sizeof(float) - char Check2[sizeof(float) - sizeof(int) + 1]; // sizeof(float) >= sizeof(int) + // Cause a compile-time error if sizeof(float) != 4 + // If your platform produces a compiler error here, you'll need to add code that manually decodes 32-bit floats + char Check1[5 - sizeof(float)]; // sizeof(float) <= 4 + char Check2[sizeof(float) - 3]; // sizeof(float) >= 4 UNUSED(Check1); UNUSED(Check2); - int i = GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart); + Int32 i = GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart); float f; memcpy(&f, &i, sizeof(f)); return f; -- cgit v1.2.3 From e4c3d3eb6decddddc986f1020f3fb30af48bbe4b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Feb 2014 10:37:09 +0100 Subject: Added a MobDebug enabler script. This file is to be copied to a plugin's folder in order to debug that plugin with MobDebug. --- MCServer/Plugins/@EnableMobDebug.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 MCServer/Plugins/@EnableMobDebug.lua diff --git a/MCServer/Plugins/@EnableMobDebug.lua b/MCServer/Plugins/@EnableMobDebug.lua new file mode 100644 index 000000000..48d4c36b7 --- /dev/null +++ b/MCServer/Plugins/@EnableMobDebug.lua @@ -0,0 +1,29 @@ + +-- @EnableMobDebug.lua + +-- Enables the MobDebug debugger, used by ZeroBrane Studio, for a plugin +-- Needs to be named with a @ at the start so that it's loaded as the first file of the plugin + +--[[ +Usage: +Copy this file to your plugin's folder when you want to debug that plugin +You should neither check this file into the plugin's version control system, +nor distribute it in the final release. +--]] + + + + + +-- Try to load the debugger, be silent about failures: +local IsSuccess, MobDebug = pcall(require, "mobdebug") +if (IsSuccess) then + MobDebug.start() + + -- The debugger will automatically put a breakpoint on this line, use this opportunity to set more breakpoints in your code + LOG(cPluginManager:GetCurrentPlugin():GetName() .. ": MobDebug enabled") +end + + + + -- cgit v1.2.3