Added a WebAdmin interface to view users their groups, and the permissions of groups.
cChunk::Tick did an assertion in cCSLock, I used a cCSUnlock to fix it, but not sure if this is correct. git-svn-id: http://mc-server.googlecode.com/svn/trunk@194 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
51dc47bc70
commit
9dfa0f1f15
@ -129,9 +129,10 @@ function Initialize( Plugin )
|
||||
|
||||
local WebPlugin = Plugin:CreateWebPlugin()
|
||||
WebPlugin:SetName( Plugin:GetName() )
|
||||
WebPlugin:AddTab( "Playerlist", HandleRequest_PlayerList )
|
||||
WebPlugin:AddTab( "Whitelist", HandleRequest_WhiteList )
|
||||
WebPlugin:AddTab( "Reload", HandleRequest_Reload )
|
||||
WebPlugin:AddTab( "Playerlist", HandleRequest_PlayerList )
|
||||
WebPlugin:AddTab( "Permissions", HandleRequest_Permissions )
|
||||
|
||||
LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
|
||||
return true
|
||||
|
79
Plugins/Core/web_permissions.lua
Normal file
79
Plugins/Core/web_permissions.lua
Normal file
@ -0,0 +1,79 @@
|
||||
local function ShowUsersTable()
|
||||
local Content = "<h4>Users</h4>"
|
||||
|
||||
local UsersIni = cIniFile("users.ini")
|
||||
if( UsersIni:ReadFile() == false ) then
|
||||
return "Could not read users.ini!"
|
||||
end
|
||||
|
||||
local NumUsers = UsersIni:GetNumKeys()
|
||||
|
||||
Content = Content .. "<table>"
|
||||
|
||||
if( NumUsers > 0 ) then
|
||||
Content = Content .. "<tr><td></td><td>User</td><td>Groups</td></tr>"
|
||||
|
||||
for i=0, NumUsers-1 do
|
||||
local UserName = UsersIni:GetKeyName( i )
|
||||
|
||||
Content = Content .. "<tr>"
|
||||
Content = Content .. "<td style='width: 10px;'>" .. i .. ".</td>"
|
||||
Content = Content .. "<td>" .. UserName .. "</td>"
|
||||
Content = Content .. "<td>"
|
||||
Content = Content .. UsersIni:GetValue( UserName, "Groups", "-" )
|
||||
Content = Content .. "</td>"
|
||||
Content = Content .. "</tr>"
|
||||
end
|
||||
else
|
||||
Content = Content .. "<tr><td>None</td></tr>"
|
||||
end
|
||||
Content = Content .. "</table>"
|
||||
|
||||
|
||||
return Content
|
||||
end
|
||||
|
||||
local function ShowGroupsTable()
|
||||
local Content = "<h4>Groups</h4>"
|
||||
|
||||
local GroupsIni = cIniFile("groups.ini")
|
||||
if( GroupsIni:ReadFile() == false ) then
|
||||
return "Could not read groups.ini!"
|
||||
end
|
||||
|
||||
local NumGroups = GroupsIni:GetNumKeys()
|
||||
|
||||
Content = Content .. "<table>"
|
||||
if( NumGroups > 0 ) then
|
||||
Content = Content .. "<tr><td></td><td>Name</td><td>Permissions</td><td>Color</td></tr>"
|
||||
|
||||
for i=0, NumGroups-1 do
|
||||
local GroupName = GroupsIni:GetKeyName( i )
|
||||
|
||||
Content = Content .. "<tr>"
|
||||
Content = Content .. "<td style='width: 10px;'>" .. i .. ".</td>"
|
||||
Content = Content .. "<td>" .. GroupName .. "</td>"
|
||||
Content = Content .. "<td>"
|
||||
Content = Content .. GroupsIni:GetValue( GroupName, "Permissions", "-" )
|
||||
Content = Content .. "</td>"
|
||||
Content = Content .. "<td>"
|
||||
Content = Content .. GroupsIni:GetValue( GroupName, "Color", "-" )
|
||||
Content = Content .. "</td>"
|
||||
Content = Content .. "</tr>"
|
||||
end
|
||||
else
|
||||
Content = Content .. "<tr><td>None</td></tr>"
|
||||
end
|
||||
Content = Content .. "</table>"
|
||||
|
||||
return Content
|
||||
end
|
||||
|
||||
function HandleRequest_Permissions( Request )
|
||||
local Content = ""
|
||||
|
||||
Content = Content .. ShowGroupsTable()
|
||||
Content = Content .. ShowUsersTable()
|
||||
|
||||
return Content
|
||||
end
|
@ -18,6 +18,7 @@ function HandleRequest_PlayerList( Request )
|
||||
|
||||
|
||||
local PlayerList = World:GetAllPlayers()
|
||||
if( #PlayerList > 0 ) then
|
||||
for i, Player in ipairs( PlayerList ) do
|
||||
Content = Content .. "<tr>"
|
||||
Content = Content .. "<td style='width: 10px;'>" .. i .. ".</td>"
|
||||
@ -25,7 +26,9 @@ function HandleRequest_PlayerList( Request )
|
||||
Content = Content .. "<td><a href='?playerlist-kick=" .. Player:GetName() .. "'>Kick</a></td>"
|
||||
Content = Content .. "</tr>"
|
||||
end
|
||||
|
||||
else
|
||||
Content = Content .. "<tr><td>None</td></tr>"
|
||||
end
|
||||
Content = Content .. "</table>"
|
||||
Content = Content .. "<br>"
|
||||
return Content
|
||||
|
@ -15,7 +15,7 @@ NewPlugin=Core
|
||||
ShowPluginNames=1
|
||||
|
||||
[Physics]
|
||||
Water=1
|
||||
Water=0
|
||||
|
||||
[Monsters]
|
||||
AnimalsOn=0
|
||||
|
@ -1,10 +1,8 @@
|
||||
/*
|
||||
** Lua binding: AllToLua
|
||||
** Generated automatically by tolua++-1.0.92 on 01/27/12 00:53:11.
|
||||
** Generated automatically by tolua++-1.0.92 on 01/30/12 17:26:14.
|
||||
*/
|
||||
|
||||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include "stdlib.h"
|
||||
#endif
|
||||
@ -15,6 +13,7 @@
|
||||
/* Exported function */
|
||||
TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S);
|
||||
|
||||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||
#include "tolua_base.h"
|
||||
#include "cTorch.h"
|
||||
#include "cStairs.h"
|
||||
@ -5897,6 +5896,37 @@ static int tolua_AllToLua_cPlayer_MoveToWorld00(lua_State* tolua_S)
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: LoadPermissionsFromDisk of class cPlayer */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_LoadPermissionsFromDisk00
|
||||
static int tolua_AllToLua_cPlayer_LoadPermissionsFromDisk00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,2,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'LoadPermissionsFromDisk'", NULL);
|
||||
#endif
|
||||
{
|
||||
self->LoadPermissionsFromDisk();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'LoadPermissionsFromDisk'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
class Lua__cPlayer : public cPlayer, public ToluaBase {
|
||||
@ -16785,6 +16815,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
|
||||
tolua_function(tolua_S,"SetVisible",tolua_AllToLua_cPlayer_SetVisible00);
|
||||
tolua_function(tolua_S,"IsVisible",tolua_AllToLua_cPlayer_IsVisible00);
|
||||
tolua_function(tolua_S,"MoveToWorld",tolua_AllToLua_cPlayer_MoveToWorld00);
|
||||
tolua_function(tolua_S,"LoadPermissionsFromDisk",tolua_AllToLua_cPlayer_LoadPermissionsFromDisk00);
|
||||
tolua_endmodule(tolua_S);
|
||||
tolua_cclass(tolua_S,"Lua__cPlayer","Lua__cPlayer","cPlayer",NULL);
|
||||
tolua_beginmodule(tolua_S,"Lua__cPlayer");
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
** Lua binding: AllToLua
|
||||
** Generated automatically by tolua++-1.0.92 on 01/27/12 00:53:12.
|
||||
** Generated automatically by tolua++-1.0.92 on 01/30/12 17:26:15.
|
||||
*/
|
||||
|
||||
/* Exported function */
|
||||
|
@ -140,6 +140,27 @@ static int tolua_cPlayer_GetGroups(lua_State* tolua_S)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_cPlayer_GetResolvedPermissions(lua_State* tolua_S)
|
||||
{
|
||||
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
|
||||
|
||||
cPlayer::StringList AllPermissions = self->GetResolvedPermissions();
|
||||
|
||||
lua_createtable(tolua_S, AllPermissions.size(), 0);
|
||||
int newTable = lua_gettop(tolua_S);
|
||||
int index = 1;
|
||||
cPlayer::StringList::iterator iter = AllPermissions.begin();
|
||||
while(iter != AllPermissions.end())
|
||||
{
|
||||
std::string& Permission = *iter;
|
||||
tolua_pushstring( tolua_S, Permission.c_str() );
|
||||
lua_rawseti(tolua_S, newTable, index);
|
||||
++iter;
|
||||
++index;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_cPlugin_BindCommand(lua_State* tolua_S)
|
||||
{
|
||||
cPlugin* self = (cPlugin*) tolua_tousertype(tolua_S,1,0);
|
||||
@ -267,6 +288,7 @@ void ManualBindings::Bind( lua_State* tolua_S )
|
||||
tolua_endmodule(tolua_S);
|
||||
tolua_beginmodule(tolua_S,"cPlayer");
|
||||
tolua_function(tolua_S,"GetGroups",tolua_cPlayer_GetGroups);
|
||||
tolua_function(tolua_S,"GetResolvedPermissions",tolua_cPlayer_GetResolvedPermissions);
|
||||
tolua_endmodule(tolua_S);
|
||||
tolua_beginmodule(tolua_S,"cWebPlugin_Lua");
|
||||
tolua_function(tolua_S,"AddTab",tolua_cWebPlugin_Lua_AddTab);
|
||||
|
@ -249,7 +249,7 @@ void cChunk::Tick(float a_Dt)
|
||||
}
|
||||
m_pState->PendingSendBlocks.clear();
|
||||
}
|
||||
Lock.Unlock();
|
||||
cCSUnlock Unlock( Lock );
|
||||
|
||||
while( !m_pState->UnloadQuery.empty() )
|
||||
{
|
||||
|
@ -380,7 +380,7 @@ void cChunkMap::UnloadUnusedChunks()
|
||||
cChunk* Chunk = Layer.m_Chunks[i].m_LiveChunk;
|
||||
if( Chunk && Chunk->GetClients().size() == 0 && Chunk->GetReferenceCount() <= 0 )
|
||||
{
|
||||
Chunk->SaveToDisk();
|
||||
//Chunk->SaveToDisk();
|
||||
World->RemoveSpread( ptr_cChunk( Chunk ) );
|
||||
RemoveChunk( Chunk );
|
||||
delete Chunk;
|
||||
|
@ -732,8 +732,11 @@ bool cPlayer::MoveToWorld( const char* a_WorldName )
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cPlayer::LoadFromDisk() // TODO - This should also get/set/whatever the correct world for this player
|
||||
void cPlayer::LoadPermissionsFromDisk()
|
||||
{
|
||||
m_pState->Groups.clear();
|
||||
m_pState->Permissions.clear();
|
||||
|
||||
cIniFile IniFile("users.ini");
|
||||
if( IniFile.ReadFile() )
|
||||
{
|
||||
@ -759,6 +762,11 @@ bool cPlayer::LoadFromDisk() // TODO - This should also get/set/whatever the cor
|
||||
AddToGroup("Default");
|
||||
}
|
||||
ResolvePermissions();
|
||||
}
|
||||
|
||||
bool cPlayer::LoadFromDisk() // TODO - This should also get/set/whatever the correct world for this player
|
||||
{
|
||||
LoadPermissionsFromDisk();
|
||||
|
||||
// Log player permissions, cause it's what the cool kids do
|
||||
LOGINFO("Player %s has permissions:", m_pState->PlayerName.c_str() );
|
||||
@ -891,6 +899,19 @@ const cPlayer::GroupList & cPlayer::GetGroups()
|
||||
return m_pState->Groups;
|
||||
}
|
||||
|
||||
cPlayer::StringList cPlayer::GetResolvedPermissions()
|
||||
{
|
||||
StringList Permissions;
|
||||
|
||||
const PermissionMap& ResolvedPermissions = m_pState->ResolvedPermissions;
|
||||
for( PermissionMap::const_iterator itr = ResolvedPermissions.begin(); itr != ResolvedPermissions.end(); ++itr )
|
||||
{
|
||||
if( itr->second ) Permissions.push_back( itr->first );
|
||||
}
|
||||
|
||||
return Permissions;
|
||||
}
|
||||
|
||||
const char* cPlayer::GetLoadedWorldName()
|
||||
{
|
||||
return m_pState->LoadedWorldName.c_str();
|
||||
|
@ -63,10 +63,12 @@ public:
|
||||
void SetName( const char* a_Name ); //tolua_export
|
||||
|
||||
typedef std::list< cGroup* > GroupList;
|
||||
typedef std::list< std::string > StringList;
|
||||
void AddToGroup( const char* a_GroupName ); //tolua_export
|
||||
bool CanUseCommand( const char* a_Command ); //tolua_export
|
||||
bool HasPermission( const char* a_Permission ); //tolua_export
|
||||
const GroupList & GetGroups(); // >> EXPORTED IN MANUALBINDINGS <<
|
||||
StringList GetResolvedPermissions(); // >> EXPORTED IN MANUALBINDINGS <<
|
||||
bool IsInGroup( const char* a_Group ); //tolua_export
|
||||
|
||||
std::string GetColor(); //tolua_export
|
||||
@ -86,6 +88,7 @@ public:
|
||||
|
||||
bool SaveToDisk();
|
||||
bool LoadFromDisk();
|
||||
void LoadPermissionsFromDisk(); //tolua_export
|
||||
|
||||
const char* GetLoadedWorldName();
|
||||
|
||||
|
@ -84,18 +84,21 @@ std::string cWebPlugin_Lua::HandleRequest( HTTPRequest* a_Request )
|
||||
tolua_pushusertype( LuaState, a_Request, "HTTPRequest" );
|
||||
LOGINFO("Calling bound function! :D");
|
||||
int s = lua_pcall( LuaState, 1, 1, 0);
|
||||
if( report_errors( LuaState, s ) )
|
||||
{
|
||||
LOGINFO("error. Stack size: %i", lua_gettop(LuaState) );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( s != 0 )
|
||||
{
|
||||
std::string err = lua_tostring(LuaState, -1);
|
||||
LOGERROR("-- %s", err.c_str() );
|
||||
lua_pop(LuaState, 1);
|
||||
LOGINFO("error. Stack size: %i", lua_gettop(LuaState) );
|
||||
return err; // Show the error message in the web page, looks cool
|
||||
}
|
||||
|
||||
if( !lua_isstring( LuaState, -1 ) )
|
||||
{
|
||||
LOGWARN("WARNING: WebPlugin tab '%s' did not return a string!", Tab->Title.c_str() );
|
||||
lua_pop(LuaState, 1); // Pop return value
|
||||
return "";
|
||||
return std::string("WARNING: WebPlugin tab '") + Tab->Title + std::string("' did not return a string!");
|
||||
}
|
||||
|
||||
RetVal += tolua_tostring(LuaState, -1, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user