Got rid of dangerous GetEntity(), not using DoWithEntity()
git-svn-id: http://mc-server.googlecode.com/svn/trunk@278 0a769ca7-a7f5-676a-18bf-c427514a06d6master
parent
415d4eaa68
commit
008addf5d7
|
@ -11,7 +11,7 @@ local function ShowUsersTable()
|
|||
Content = Content .. "<table>"
|
||||
|
||||
if( NumUsers > 0 ) then
|
||||
Content = Content .. "<tr><td></td><td>User</td><td>Groups</td></tr>"
|
||||
Content = Content .. "<tr><th></th><th>User</th><th>Groups</th></tr>"
|
||||
|
||||
for i=0, NumUsers-1 do
|
||||
local UserName = UsersIni:GetKeyName( i )
|
||||
|
@ -45,7 +45,7 @@ local function ShowGroupsTable()
|
|||
|
||||
Content = Content .. "<table>"
|
||||
if( NumGroups > 0 ) then
|
||||
Content = Content .. "<tr><td></td><td>Name</td><td>Permissions</td><td>Color</td></tr>"
|
||||
Content = Content .. "<tr><th></th><th>Name</th><th>Permissions</th><th>Color</th></tr>"
|
||||
|
||||
for i=0, NumGroups-1 do
|
||||
local GroupName = GroupsIni:GetKeyName( i )
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
** Lua binding: AllToLua
|
||||
** Generated automatically by tolua++-1.0.92 on 02/15/12 23:43:42.
|
||||
** Generated automatically by tolua++-1.0.92 on 02/16/12 18:16:16.
|
||||
*/
|
||||
|
||||
#ifndef __cplusplus
|
||||
|
@ -9587,40 +9587,6 @@ static int tolua_AllToLua_cWorld_GetPlayer00(lua_State* tolua_S)
|
|||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: GetEntity of class cWorld */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_GetEntity00
|
||||
static int tolua_AllToLua_cWorld_GetEntity00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cWorld",0,&tolua_err) ||
|
||||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0);
|
||||
int a_UniqueID = ((int) tolua_tonumber(tolua_S,2,0));
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetEntity'", NULL);
|
||||
#endif
|
||||
{
|
||||
cEntity* tolua_ret = (cEntity*) self->GetEntity(a_UniqueID);
|
||||
tolua_pushusertype(tolua_S,(void*)tolua_ret,"cEntity");
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'GetEntity'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: SetBlock of class cWorld */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_SetBlock00
|
||||
static int tolua_AllToLua_cWorld_SetBlock00(lua_State* tolua_S)
|
||||
|
@ -17594,7 +17560,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
|
|||
tolua_function(tolua_S,"GetHeight",tolua_AllToLua_cWorld_GetHeight00);
|
||||
tolua_function(tolua_S,"GetNumPlayers",tolua_AllToLua_cWorld_GetNumPlayers00);
|
||||
tolua_function(tolua_S,"GetPlayer",tolua_AllToLua_cWorld_GetPlayer00);
|
||||
tolua_function(tolua_S,"GetEntity",tolua_AllToLua_cWorld_GetEntity00);
|
||||
tolua_function(tolua_S,"SetBlock",tolua_AllToLua_cWorld_SetBlock00);
|
||||
tolua_function(tolua_S,"FastSetBlock",tolua_AllToLua_cWorld_FastSetBlock00);
|
||||
tolua_function(tolua_S,"GetBlock",tolua_AllToLua_cWorld_GetBlock00);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
** Lua binding: AllToLua
|
||||
** Generated automatically by tolua++-1.0.92 on 02/15/12 23:43:42.
|
||||
** Generated automatically by tolua++-1.0.92 on 02/16/12 18:16:17.
|
||||
*/
|
||||
|
||||
/* Exported function */
|
||||
|
|
|
@ -1532,13 +1532,27 @@ void cClientHandle::HandleUseEntity(cPacket_UseEntity * a_Packet)
|
|||
{
|
||||
return;
|
||||
}
|
||||
cWorld * World = m_Player->GetWorld();
|
||||
cEntity * Entity = World->GetEntity(a_Packet->m_TargetID);
|
||||
if ((Entity != NULL) && Entity->IsA("cPawn"))
|
||||
|
||||
class cDamageEntity : public cEntityCallback
|
||||
{
|
||||
cPawn * Pawn = (cPawn *)Entity;
|
||||
Pawn->TakeDamage(1, m_Player);
|
||||
virtual bool Item(cEntity * a_Entity) override
|
||||
{
|
||||
if( a_Entity->IsA("cPawn") )
|
||||
{
|
||||
reinterpret_cast< cPawn* >( a_Entity )->TakeDamage(Damage, Instigator );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
int Damage;
|
||||
cEntity * Instigator;
|
||||
} Callback;
|
||||
|
||||
Callback.Damage = 1; // TODO: Find proper damage from current item equipped
|
||||
Callback.Instigator = m_Player;
|
||||
|
||||
cWorld * World = m_Player->GetWorld();
|
||||
World->DoWithEntity( a_Packet->m_TargetID, Callback );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1168,18 +1168,17 @@ void cWorld::SendPlayerList(cPlayer * a_DestPlayer)
|
|||
|
||||
|
||||
|
||||
// TODO: This interface is dangerous!
|
||||
cEntity * cWorld::GetEntity( int a_UniqueID )
|
||||
bool cWorld::DoWithEntity( int a_UniqueID, cEntityCallback & a_Callback )
|
||||
{
|
||||
cCSLock Lock(m_CSEntities);
|
||||
for (cEntityList::iterator itr = m_AllEntities.begin(); itr != m_AllEntities.end(); ++itr )
|
||||
{
|
||||
if( (*itr)->GetUniqueID() == a_UniqueID )
|
||||
{
|
||||
return *itr;
|
||||
return a_Callback.Item(*itr);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
} // for itr - m_AllEntities[]
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ class cWorldGenerator; // The generator that actually generates the chunks for
|
|||
class cChunkGenerator; // The thread responsible for generating chunks
|
||||
typedef std::list< cPlayer * > cPlayerList;
|
||||
typedef cItemCallback<cPlayer> cPlayerListCallback;
|
||||
typedef cItemCallback<cEntity> cEntityCallback;
|
||||
|
||||
|
||||
|
||||
|
@ -103,11 +104,8 @@ public:
|
|||
void AddEntity( cEntity* a_Entity );
|
||||
void RemoveEntityFromChunk( cEntity * a_Entity);
|
||||
|
||||
// TODO: This interface is dangerous!
|
||||
cEntityList & GetEntities(void) {return m_AllEntities; }
|
||||
|
||||
// TODO: This interface is dangerous!
|
||||
cEntity * GetEntity( int a_UniqueID ); //tolua_export
|
||||
// TODO: Export to Lua
|
||||
bool DoWithEntity( int a_UniqueID, cEntityCallback & a_Callback );
|
||||
|
||||
void SetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_BlockMeta ); //tolua_export
|
||||
void FastSetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_BlockMeta ); //tolua_export
|
||||
|
|
Loading…
Reference in New Issue