1
0

Merge pull request #709 from Howaner/GlobalFixes

Add 'Group not found', when the Server load the users.ini and add auto g...
This commit is contained in:
Mattes D 2014-02-28 14:28:50 +01:00
commit 6ad4b78a7b
8 changed files with 115 additions and 27 deletions

View File

@ -30,48 +30,70 @@ cJukeboxEntity::~cJukeboxEntity()
void cJukeboxEntity::UsedBy(cPlayer * a_Player) void cJukeboxEntity::UsedBy(cPlayer * a_Player)
{ {
if (m_Record == 0) if (IsPlayingRecord())
{
const cItem & HeldItem = a_Player->GetEquippedItem();
if (HeldItem.m_ItemType >= 2256 && HeldItem.m_ItemType <= 2267)
{
m_Record = HeldItem.m_ItemType;
a_Player->GetInventory().RemoveOneEquippedItem();
PlayRecord();
}
}
else
{ {
EjectRecord(); EjectRecord();
} }
else
{
const cItem & HeldItem = a_Player->GetEquippedItem();
if (PlayRecord(HeldItem.m_ItemType))
{
a_Player->GetInventory().RemoveOneEquippedItem();
}
}
} }
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->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 // There's no record here
return; return false;
} }
cItems Drops; cItems Drops;
Drops.push_back(cItem(m_Record, 1, 0)); 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->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_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);
} }

View File

@ -37,10 +37,20 @@ public:
int GetRecord(void); int GetRecord(void);
void SetRecord(int a_Record); void SetRecord(int a_Record);
void PlayRecord(void);
/// Ejects the currently held record as a pickup. Does nothing when no record inserted. /** Play a Record. Return false, when a_Record isn't a Record */
void EjectRecord(void); 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 // tolua_end

View File

@ -466,6 +466,10 @@ enum
E_META_FLOWER_PINK_TULIP = 7, E_META_FLOWER_PINK_TULIP = 7,
E_META_FLOWER_OXEYE_DAISY = 8, 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_BLOCK_HOPPER metas:
E_META_HOPPER_FACING_YM = 0, E_META_HOPPER_FACING_YM = 0,
E_META_HOPPER_UNATTACHED = 1, // Hopper doesn't move items up, there's no YP E_META_HOPPER_UNATTACHED = 1, // Hopper doesn't move items up, there's no YP

View File

@ -1532,7 +1532,11 @@ void cPlayer::LoadPermissionsFromDisk()
AStringVector Split = StringSplit( Groups, "," ); AStringVector Split = StringSplit( Groups, "," );
for( unsigned int i = 0; i < Split.size(); i++ ) 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 else
@ -1544,12 +1548,7 @@ void cPlayer::LoadPermissionsFromDisk()
} }
else else
{ {
LOGWARN("Regenerating users.ini, player %s will be added to the \"Default\" group", m_PlayerName.c_str()); cRoot::Get()->GetGroupManager()->CheckUsers();
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");
AddToGroup("Default"); AddToGroup("Default");
} }
ResolvePermissions(); ResolvePermissions();

View File

@ -46,6 +46,7 @@ cGroupManager::cGroupManager()
LOGD("-- Loading Groups --"); LOGD("-- Loading Groups --");
LoadGroups(); LoadGroups();
CheckUsers();
LOGD("-- Groups Successfully Loaded --"); 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() void cGroupManager::LoadGroups()
{ {
cIniFile IniFile; 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 ) cGroup* cGroupManager::GetGroup( const AString & a_Name )
{ {
GroupMap::iterator itr = m_pState->Groups.find( a_Name ); GroupMap::iterator itr = m_pState->Groups.find( a_Name );

View File

@ -14,8 +14,10 @@ class cGroup;
class cGroupManager class cGroupManager
{ {
public: public:
bool ExistsGroup(const AString & a_Name);
cGroup * GetGroup(const AString & a_Name); cGroup * GetGroup(const AString & a_Name);
void LoadGroups(void); void LoadGroups(void);
void CheckUsers(void);
private: private:
friend class cRoot; friend class cRoot;

View File

@ -194,7 +194,7 @@ void cRoot::Start(void)
#if !defined(ANDROID_NDK) #if !defined(ANDROID_NDK)
LOGD("Starting InputThread..."); LOGD("Starting InputThread...");
m_InputThread = new cThread( InputThread, this, "cRoot::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 #endif
long long finishmseconds = Time.GetNowTime(); long long finishmseconds = Time.GetNowTime();
@ -536,7 +536,9 @@ void cRoot::SaveAllChunks(void)
void cRoot::ReloadGroups(void) void cRoot::ReloadGroups(void)
{ {
LOG("Reload groups ...");
m_GroupManager->LoadGroups(); m_GroupManager->LoadGroups();
m_GroupManager->CheckUsers();
} }

View File

@ -472,6 +472,8 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac
if (split[0] == "reloadgroups") if (split[0] == "reloadgroups")
{ {
cRoot::Get()->ReloadGroups(); cRoot::Get()->ReloadGroups();
a_Output.Out("Groups reloaded!");
a_Output.Finished();
return; return;
} }