Fixed bug where cPlayer's cClientHandle was used after cPlayer was destroyed http://forum.mc-server.org/showthread.php?tid=380

Also removed the SetClientHandle() function from cPlayer
Added a Destroyed() function to cEntity that is called ONLY ONCE after an entity has been 'destroyed'
Cleaned up some code, using enums for GameMode and Weather and replaced some 'const char *' with 'const AString &'
Exposed some more functions to Lua

git-svn-id: http://mc-server.googlecode.com/svn/trunk@382 0a769ca7-a7f5-676a-18bf-c427514a06d6
master
faketruth 2012-03-07 13:36:30 +00:00
parent d63b092e02
commit 787382caf8
13 changed files with 306 additions and 107 deletions

View File

@ -1,6 +1,6 @@
/* /*
** Lua binding: AllToLua ** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 03/04/12 14:40:53. ** Generated automatically by tolua++-1.0.92 on 03/07/12 14:22:38.
*/ */
#ifndef __cplusplus #ifndef __cplusplus
@ -5116,7 +5116,7 @@ static int tolua_AllToLua_cPlayer_GetGameMode00(lua_State* tolua_S)
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetGameMode'", NULL); if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetGameMode'", NULL);
#endif #endif
{ {
int tolua_ret = (int) self->GetGameMode(); eGameMode tolua_ret = (eGameMode) self->GetGameMode();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
} }
} }
@ -5305,7 +5305,7 @@ static int tolua_AllToLua_cPlayer_SetGameMode00(lua_State* tolua_S)
#endif #endif
{ {
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
int a_GameMode = ((int) tolua_tonumber(tolua_S,2,0)); eGameMode a_GameMode = ((eGameMode) (int) tolua_tonumber(tolua_S,2,0));
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetGameMode'", NULL); if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetGameMode'", NULL);
#endif #endif
@ -9473,6 +9473,38 @@ static int tolua_AllToLua_cWorld_GetTime00(lua_State* tolua_S)
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* method: GetGameMode of class cWorld */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_GetGameMode00
static int tolua_AllToLua_cWorld_GetGameMode00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const cWorld",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const cWorld* self = (const cWorld*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetGameMode'", NULL);
#endif
{
eGameMode tolua_ret = (eGameMode) self->GetGameMode();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetGameMode'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: SetWorldTime of class cWorld */ /* method: SetWorldTime of class cWorld */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_SetWorldTime00 #ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_SetWorldTime00
static int tolua_AllToLua_cWorld_SetWorldTime00(lua_State* tolua_S) static int tolua_AllToLua_cWorld_SetWorldTime00(lua_State* tolua_S)
@ -9542,6 +9574,71 @@ static int tolua_AllToLua_cWorld_GetHeight00(lua_State* tolua_S)
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* method: GetMaxPlayers of class cWorld */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_GetMaxPlayers00
static int tolua_AllToLua_cWorld_GetMaxPlayers00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const cWorld",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const cWorld* self = (const cWorld*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetMaxPlayers'", NULL);
#endif
{
unsigned int tolua_ret = (unsigned int) self->GetMaxPlayers();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetMaxPlayers'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: SetMaxPlayers of class cWorld */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_SetMaxPlayers00
static int tolua_AllToLua_cWorld_SetMaxPlayers00(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 iMax = ((int) tolua_tonumber(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetMaxPlayers'", NULL);
#endif
{
self->SetMaxPlayers(iMax);
}
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'SetMaxPlayers'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: GetNumPlayers of class cWorld */ /* method: GetNumPlayers of class cWorld */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_GetNumPlayers00 #ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_GetNumPlayers00
static int tolua_AllToLua_cWorld_GetNumPlayers00(lua_State* tolua_S) static int tolua_AllToLua_cWorld_GetNumPlayers00(lua_State* tolua_S)
@ -9608,6 +9705,55 @@ static int tolua_AllToLua_cWorld_GetPlayer00(lua_State* tolua_S)
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* method: UpdateSign of class cWorld */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_UpdateSign00
static int tolua_AllToLua_cWorld_UpdateSign00(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_isnumber(tolua_S,3,0,&tolua_err) ||
!tolua_isnumber(tolua_S,4,0,&tolua_err) ||
!tolua_iscppstring(tolua_S,5,0,&tolua_err) ||
!tolua_iscppstring(tolua_S,6,0,&tolua_err) ||
!tolua_iscppstring(tolua_S,7,0,&tolua_err) ||
!tolua_iscppstring(tolua_S,8,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,9,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0);
int a_X = ((int) tolua_tonumber(tolua_S,2,0));
int a_Y = ((int) tolua_tonumber(tolua_S,3,0));
int a_Z = ((int) tolua_tonumber(tolua_S,4,0));
const AString a_Line1 = ((const AString) tolua_tocppstring(tolua_S,5,0));
const AString a_Line2 = ((const AString) tolua_tocppstring(tolua_S,6,0));
const AString a_Line3 = ((const AString) tolua_tocppstring(tolua_S,7,0));
const AString a_Line4 = ((const AString) tolua_tocppstring(tolua_S,8,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'UpdateSign'", NULL);
#endif
{
self->UpdateSign(a_X,a_Y,a_Z,a_Line1,a_Line2,a_Line3,a_Line4);
tolua_pushcppstring(tolua_S,(const char*)a_Line1);
tolua_pushcppstring(tolua_S,(const char*)a_Line2);
tolua_pushcppstring(tolua_S,(const char*)a_Line3);
tolua_pushcppstring(tolua_S,(const char*)a_Line4);
}
}
return 4;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'UpdateSign'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: SetBlock of class cWorld */ /* method: SetBlock of class cWorld */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_SetBlock00 #ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_SetBlock00
static int tolua_AllToLua_cWorld_SetBlock00(lua_State* tolua_S) static int tolua_AllToLua_cWorld_SetBlock00(lua_State* tolua_S)
@ -10288,14 +10434,14 @@ static int tolua_AllToLua_cWorld_CastThunderbolt00(lua_State* tolua_S)
#endif #endif
{ {
cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0); cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0);
int tolua_var_2 = ((int) tolua_tonumber(tolua_S,2,0)); int a_X = ((int) tolua_tonumber(tolua_S,2,0));
int tolua_var_3 = ((int) tolua_tonumber(tolua_S,3,0)); int a_Y = ((int) tolua_tonumber(tolua_S,3,0));
int tolua_var_4 = ((int) tolua_tonumber(tolua_S,4,0)); int a_Z = ((int) tolua_tonumber(tolua_S,4,0));
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CastThunderbolt'", NULL); if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CastThunderbolt'", NULL);
#endif #endif
{ {
self->CastThunderbolt(tolua_var_2,tolua_var_3,tolua_var_4); self->CastThunderbolt(a_X,a_Y,a_Z);
} }
} }
return 0; return 0;
@ -10323,12 +10469,12 @@ static int tolua_AllToLua_cWorld_SetWeather00(lua_State* tolua_S)
#endif #endif
{ {
cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0); cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0);
int tolua_var_5 = ((int) tolua_tonumber(tolua_S,2,0)); eWeather a_Weather = ((eWeather) (int) tolua_tonumber(tolua_S,2,0));
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetWeather'", NULL); if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetWeather'", NULL);
#endif #endif
{ {
self->SetWeather(tolua_var_5); self->SetWeather(a_Weather);
} }
} }
return 0; return 0;
@ -10359,7 +10505,7 @@ static int tolua_AllToLua_cWorld_GetWeather00(lua_State* tolua_S)
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetWeather'", NULL); if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetWeather'", NULL);
#endif #endif
{ {
int tolua_ret = (int) self->GetWeather(); eWeather tolua_ret = (eWeather) self->GetWeather();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
} }
} }
@ -12191,23 +12337,24 @@ static int tolua_AllToLua_cRoot_GetWorld01(lua_State* tolua_S)
tolua_Error tolua_err; tolua_Error tolua_err;
if ( if (
!tolua_isusertype(tolua_S,1,"cRoot",0,&tolua_err) || !tolua_isusertype(tolua_S,1,"cRoot",0,&tolua_err) ||
!tolua_isstring(tolua_S,2,0,&tolua_err) || !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err) !tolua_isnoobj(tolua_S,3,&tolua_err)
) )
goto tolua_lerror; goto tolua_lerror;
else else
{ {
cRoot* self = (cRoot*) tolua_tousertype(tolua_S,1,0); cRoot* self = (cRoot*) tolua_tousertype(tolua_S,1,0);
const char* a_WorldName = ((const char*) tolua_tostring(tolua_S,2,0)); const AString a_WorldName = ((const AString) tolua_tocppstring(tolua_S,2,0));
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetWorld'", NULL); if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetWorld'", NULL);
#endif #endif
{ {
cWorld* tolua_ret = (cWorld*) self->GetWorld(a_WorldName); cWorld* tolua_ret = (cWorld*) self->GetWorld(a_WorldName);
tolua_pushusertype(tolua_S,(void*)tolua_ret,"cWorld"); tolua_pushusertype(tolua_S,(void*)tolua_ret,"cWorld");
tolua_pushcppstring(tolua_S,(const char*)a_WorldName);
} }
} }
return 1; return 2;
tolua_lerror: tolua_lerror:
return tolua_AllToLua_cRoot_GetWorld00(tolua_S); return tolua_AllToLua_cRoot_GetWorld00(tolua_S);
} }
@ -17317,6 +17464,11 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"IsValidBlock",tolua_AllToLua_IsValidBlock00); tolua_function(tolua_S,"IsValidBlock",tolua_AllToLua_IsValidBlock00);
tolua_function(tolua_S,"IsValidItem",tolua_AllToLua_IsValidItem00); tolua_function(tolua_S,"IsValidItem",tolua_AllToLua_IsValidItem00);
tolua_function(tolua_S,"AddDirection",tolua_AllToLua_AddDirection00); tolua_function(tolua_S,"AddDirection",tolua_AllToLua_AddDirection00);
tolua_constant(tolua_S,"eGameMode_Survival",eGameMode_Survival);
tolua_constant(tolua_S,"eGameMode_Creative",eGameMode_Creative);
tolua_constant(tolua_S,"eWeather_Sunny",eWeather_Sunny);
tolua_constant(tolua_S,"eWeather_Rain",eWeather_Rain);
tolua_constant(tolua_S,"eWeather_ThunderStorm",eWeather_ThunderStorm);
tolua_function(tolua_S,"GetTime",tolua_AllToLua_GetTime00); tolua_function(tolua_S,"GetTime",tolua_AllToLua_GetTime00);
tolua_function(tolua_S,"GetChar",tolua_AllToLua_GetChar00); tolua_function(tolua_S,"GetChar",tolua_AllToLua_GetChar00);
tolua_cclass(tolua_S,"cStringMap","cStringMap","",NULL); tolua_cclass(tolua_S,"cStringMap","cStringMap","",NULL);
@ -17605,10 +17757,14 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_beginmodule(tolua_S,"cWorld"); tolua_beginmodule(tolua_S,"cWorld");
tolua_function(tolua_S,"GetWorld",tolua_AllToLua_cWorld_GetWorld00); tolua_function(tolua_S,"GetWorld",tolua_AllToLua_cWorld_GetWorld00);
tolua_function(tolua_S,"GetTime",tolua_AllToLua_cWorld_GetTime00); tolua_function(tolua_S,"GetTime",tolua_AllToLua_cWorld_GetTime00);
tolua_function(tolua_S,"GetGameMode",tolua_AllToLua_cWorld_GetGameMode00);
tolua_function(tolua_S,"SetWorldTime",tolua_AllToLua_cWorld_SetWorldTime00); tolua_function(tolua_S,"SetWorldTime",tolua_AllToLua_cWorld_SetWorldTime00);
tolua_function(tolua_S,"GetHeight",tolua_AllToLua_cWorld_GetHeight00); tolua_function(tolua_S,"GetHeight",tolua_AllToLua_cWorld_GetHeight00);
tolua_function(tolua_S,"GetMaxPlayers",tolua_AllToLua_cWorld_GetMaxPlayers00);
tolua_function(tolua_S,"SetMaxPlayers",tolua_AllToLua_cWorld_SetMaxPlayers00);
tolua_function(tolua_S,"GetNumPlayers",tolua_AllToLua_cWorld_GetNumPlayers00); tolua_function(tolua_S,"GetNumPlayers",tolua_AllToLua_cWorld_GetNumPlayers00);
tolua_function(tolua_S,"GetPlayer",tolua_AllToLua_cWorld_GetPlayer00); tolua_function(tolua_S,"GetPlayer",tolua_AllToLua_cWorld_GetPlayer00);
tolua_function(tolua_S,"UpdateSign",tolua_AllToLua_cWorld_UpdateSign00);
tolua_function(tolua_S,"SetBlock",tolua_AllToLua_cWorld_SetBlock00); tolua_function(tolua_S,"SetBlock",tolua_AllToLua_cWorld_SetBlock00);
tolua_function(tolua_S,"FastSetBlock",tolua_AllToLua_cWorld_FastSetBlock00); tolua_function(tolua_S,"FastSetBlock",tolua_AllToLua_cWorld_FastSetBlock00);
tolua_function(tolua_S,"GetBlock",tolua_AllToLua_cWorld_GetBlock00); tolua_function(tolua_S,"GetBlock",tolua_AllToLua_cWorld_GetBlock00);

View File

@ -1,6 +1,6 @@
/* /*
** Lua binding: AllToLua ** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 03/04/12 14:40:54. ** Generated automatically by tolua++-1.0.92 on 03/07/12 14:22:38.
*/ */
/* Exported function */ /* Exported function */

View File

@ -122,12 +122,12 @@ inline void AddDirection( int & a_X, unsigned char & a_Y, int & a_Z, char a_Dire
#define MAX(a,b) (((a)>(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b))
inline void EulerToVector( float a_Pan, float a_Pitch, float & a_X, float & a_Y, float & a_Z ) inline void EulerToVector( float a_Pan, float a_Pitch, float & a_X, float & a_Y, float & a_Z )
{ {
// a_X = sinf ( a_Pan / 180 * PI ) * cosf ( a_Pitch / 180 * PI ); // a_X = sinf ( a_Pan / 180 * PI ) * cosf ( a_Pitch / 180 * PI );
// a_Y = -sinf ( a_Pitch / 180 * PI ); // a_Y = -sinf ( a_Pitch / 180 * PI );
// a_Z = -cosf ( a_Pan / 180 * PI ) * cosf ( a_Pitch / 180 * PI ); // a_Z = -cosf ( a_Pan / 180 * PI ) * cosf ( a_Pitch / 180 * PI );
a_X = cos(a_Pan / 180 * PI)*cos(a_Pitch / 180 * PI); a_X = cos(a_Pan / 180 * PI)*cos(a_Pitch / 180 * PI);
a_Y = sin(a_Pan / 180 * PI)*cos(a_Pitch / 180 * PI); a_Y = sin(a_Pan / 180 * PI)*cos(a_Pitch / 180 * PI);
a_Z = sin(a_Pitch / 180 * PI); a_Z = sin(a_Pitch / 180 * PI);
} }
inline void VectorToEuler( float a_X, float a_Y, float a_Z, float & a_Pan, float & a_Pitch ) inline void VectorToEuler( float a_X, float a_Y, float a_Z, float & a_Pan, float & a_Pitch )
@ -180,3 +180,19 @@ namespace ItemCategory
|| a_ItemID == E_ITEM_DIAMOND_SWORD; || a_ItemID == E_ITEM_DIAMOND_SWORD;
} }
} }
//tolua_begin
enum eGameMode
{
eGameMode_Survival = 0,
eGameMode_Creative = 1,
};
enum eWeather
{
eWeather_Sunny = 0,
eWeather_Rain = 1,
eWeather_ThunderStorm = 2,
};
//tolua_end

View File

@ -187,7 +187,6 @@ cClientHandle::~cClientHandle()
if (m_Player != NULL) if (m_Player != NULL)
{ {
m_Player->SetClientHandle(NULL);
m_Player->Destroy(); m_Player->Destroy();
m_Player = NULL; m_Player = NULL;
} }

View File

@ -181,6 +181,8 @@ void cEntity::Destroy()
m_World->BroadcastToChunk(m_ChunkX, m_ChunkY, m_ChunkZ, cPacket_DestroyEntity(this)); m_World->BroadcastToChunk(m_ChunkX, m_ChunkY, m_ChunkZ, cPacket_DestroyEntity(this));
m_bDestroyed = true; m_bDestroyed = true;
Destroyed();
} }

View File

@ -87,7 +87,7 @@ public: //tolua_export
void SetPosX( const double & a_PosX ); //tolua_export void SetPosX( const double & a_PosX ); //tolua_export
void SetPosY( const double & a_PosY ); //tolua_export void SetPosY( const double & a_PosY ); //tolua_export
void SetPosZ( const double & a_PosZ ); //tolua_export void SetPosZ( const double & a_PosZ ); //tolua_export
void SetPosition( const double & a_PosX, const double & a_PosY, const double & a_PosZ ); //tolua_export void SetPosition( const double & a_PosX, const double & a_PosY, const double & a_PosZ );//tolua_export
void SetPosition( const Vector3d & a_Pos ); //tolua_export void SetPosition( const Vector3d & a_Pos ); //tolua_export
void SetRot( const Vector3f & a_Rot ); //tolua_export void SetRot( const Vector3f & a_Rot ); //tolua_export
void SetRotation( float a_Rotation ); //tolua_export void SetRotation( float a_Rotation ); //tolua_export
@ -108,6 +108,7 @@ public: //tolua_export
void WrapRotation(); void WrapRotation();
protected: protected:
virtual void Destroyed() {} // Called after the entity has been destroyed
void SetWorld( cWorld* a_World ) { m_World = a_World; } void SetWorld( cWorld* a_World ) { m_World = a_World; }
void MoveToCorrectChunk(bool a_bIgnoreOldChunk = false); void MoveToCorrectChunk(bool a_bIgnoreOldChunk = false);

View File

@ -65,7 +65,7 @@ struct cPlayer::sPlayerState
}; };
cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
: m_GameMode( 0 ) : m_GameMode( eGameMode_Survival )
, m_IP("") , m_IP("")
, m_LastBlockActionTime( 0 ) , m_LastBlockActionTime( 0 )
, m_LastBlockActionCnt( 0 ) , m_LastBlockActionCnt( 0 )
@ -132,7 +132,6 @@ cPlayer::~cPlayer(void)
m_ClientHandle = NULL; m_ClientHandle = NULL;
CloseWindow(-1);
delete m_Inventory; delete m_Inventory;
m_Inventory = NULL; m_Inventory = NULL;
@ -147,6 +146,16 @@ cPlayer::~cPlayer(void)
void cPlayer::Destroyed()
{
CloseWindow(-1);
m_ClientHandle = NULL;
}
cPacket * cPlayer::GetSpawnPacket(void) const cPacket * cPlayer::GetSpawnPacket(void) const
{ {
LOGD("cPlayer::GetSpawnPacket for \"%s\" at pos {%.2f, %.2f, %.2f}", LOGD("cPlayer::GetSpawnPacket for \"%s\" at pos {%.2f, %.2f, %.2f}",
@ -431,6 +440,7 @@ void cPlayer::CloseWindow(char a_WindowType)
} }
if (m_CurrentWindow) if (m_CurrentWindow)
{ {
// FIXME: If the player entity is destroyed while having a chest window open, the chest will not close
if (a_WindowType == 1 && strcmp(m_CurrentWindow->GetWindowTitle().c_str(), "UberChest") == 0) { // Chest if (a_WindowType == 1 && strcmp(m_CurrentWindow->GetWindowTitle().c_str(), "UberChest") == 0) { // Chest
cBlockEntity *block = m_CurrentWindow->GetOwner()->GetEntity(); cBlockEntity *block = m_CurrentWindow->GetOwner()->GetEntity();
cPacket_BlockAction ChestClose; cPacket_BlockAction ChestClose;
@ -469,14 +479,14 @@ void cPlayer::SetLastBlockActionCnt( int a_LastBlockActionCnt )
void cPlayer::SetGameMode( int a_GameMode ) void cPlayer::SetGameMode( eGameMode a_GameMode )
{ {
if ( (a_GameMode < 2) && (a_GameMode >= 0) ) if ( (a_GameMode < 2) && (a_GameMode >= 0) )
{ {
if (m_GameMode != a_GameMode) if (m_GameMode != a_GameMode)
{ {
cInventory *OldInventory = 0; cInventory *OldInventory = 0;
if(m_GameMode == 0) if(m_GameMode == eGameMode_Survival)
OldInventory = m_Inventory; OldInventory = m_Inventory;
else else
OldInventory = m_CreativeInventory; OldInventory = m_CreativeInventory;
@ -497,7 +507,7 @@ void cPlayer::SetGameMode( int a_GameMode )
void cPlayer::LoginSetGameMode( int a_GameMode ) void cPlayer::LoginSetGameMode( eGameMode a_GameMode )
{ {
m_GameMode = a_GameMode; m_GameMode = a_GameMode;
} }
@ -998,9 +1008,9 @@ cPlayer::StringList cPlayer::GetResolvedPermissions()
const char* cPlayer::GetLoadedWorldName() const AString & cPlayer::GetLoadedWorldName()
{ {
return m_pState->LoadedWorldName.c_str(); return m_pState->LoadedWorldName;
} }

View File

@ -4,6 +4,7 @@
#include "cPawn.h" #include "cPawn.h"
#include "cSurvivalInventory.h" #include "cSurvivalInventory.h"
#include "cCreativeInventory.h" #include "cCreativeInventory.h"
#include "Defines.h"
@ -21,9 +22,10 @@ class cClientHandle;
class cPlayer : public cPawn //tolua_export class cPlayer : public cPawn //tolua_export
{ //tolua_export { //tolua_export
public: public:
typedef cPawn super;
CLASS_PROTOTYPE(); CLASS_PROTOTYPE();
cPlayer(cClientHandle* a_Client, const AString & a_PlayerName); cPlayer(cClientHandle * a_Client, const AString & a_PlayerName);
virtual ~cPlayer(); virtual ~cPlayer();
virtual void Initialize( cWorld* a_World ); //tolua_export virtual void Initialize( cWorld* a_World ); //tolua_export
@ -37,18 +39,18 @@ public:
Vector3d GetEyePosition(); //tolua_export Vector3d GetEyePosition(); //tolua_export
inline bool GetFlying() { return m_bTouchGround; } //tolua_export inline bool GetFlying() { return m_bTouchGround; } //tolua_export
inline const double & GetStance() { return m_Stance; } //tolua_export inline const double & GetStance() { return m_Stance; } //tolua_export
inline cInventory & GetInventory() { if(GetGameMode() == 0) return *m_Inventory; else return *m_CreativeInventory; } //tolua_export inline cInventory & GetInventory() { if(GetGameMode() == eGameMode_Survival) return *m_Inventory; else return *m_CreativeInventory; } //tolua_export
virtual void TeleportTo( const double & a_PosX, const double & a_PosY, const double & a_PosZ ); //tolua_export virtual void TeleportTo( const double & a_PosX, const double & a_PosY, const double & a_PosZ ); //tolua_export
int GetGameMode() { return m_GameMode; } //tolua_export eGameMode GetGameMode() { return m_GameMode; } //tolua_export
std::string GetIP() { return m_IP; } //tolua_export std::string GetIP() { return m_IP; } //tolua_export
float GetLastBlockActionTime() { return m_LastBlockActionTime; } //tolua_export float GetLastBlockActionTime() { return m_LastBlockActionTime; } //tolua_export
int GetLastBlockActionCnt() { return m_LastBlockActionCnt; } //tolua_export int GetLastBlockActionCnt() { return m_LastBlockActionCnt; } //tolua_export
void SetLastBlockActionCnt( int ); //tolua_export void SetLastBlockActionCnt( int ); //tolua_export
void SetLastBlockActionTime(); //tolua_export void SetLastBlockActionTime(); //tolua_export
void SetGameMode( int a_GameMode ); //tolua_export void SetGameMode( eGameMode a_GameMode ); //tolua_export
void LoginSetGameMode( int a_GameMode ); void LoginSetGameMode( eGameMode a_GameMode );
void SetIP( std::string a_IP ); void SetIP( std::string a_IP );
// Tries to move to a new position, with collision checks and stuff // Tries to move to a new position, with collision checks and stuff
@ -58,8 +60,7 @@ public:
void OpenWindow( cWindow* a_Window ); void OpenWindow( cWindow* a_Window );
void CloseWindow(char a_WindowType); void CloseWindow(char a_WindowType);
cClientHandle* GetClientHandle() { return m_ClientHandle; } //tolua_export cClientHandle * GetClientHandle() { return m_ClientHandle; } //tolua_export
void SetClientHandle( cClientHandle* a_Client ) { m_ClientHandle = a_Client; }
void SendMessage( const char* a_Message ); //tolua_export void SendMessage( const char* a_Message ); //tolua_export
@ -94,12 +95,14 @@ public:
bool LoadFromDisk(); bool LoadFromDisk();
void LoadPermissionsFromDisk(); //tolua_export void LoadPermissionsFromDisk(); //tolua_export
const char* GetLoadedWorldName(); const AString & GetLoadedWorldName();
void UseEquippedItem(); void UseEquippedItem();
protected: protected:
virtual void Destroyed();
struct sPlayerState; struct sPlayerState;
sPlayerState* m_pState; sPlayerState* m_pState;
@ -121,7 +124,7 @@ protected:
float m_LastBlockActionTime; float m_LastBlockActionTime;
int m_LastBlockActionCnt; int m_LastBlockActionCnt;
int m_GameMode; eGameMode m_GameMode;
std::string m_IP; std::string m_IP;
long long m_LastPlayerListTime; long long m_LastPlayerListTime;

View File

@ -26,7 +26,7 @@
cRoot* cRoot::s_Root = 0; cRoot* cRoot::s_Root = 0;
typedef std::map< std::string, cWorld* > WorldMap; typedef std::map< AString, cWorld* > WorldMap;
struct cRoot::sRootState struct cRoot::sRootState
{ {
cWorld* pDefaultWorld; cWorld* pDefaultWorld;
@ -291,7 +291,7 @@ cWorld* cRoot::GetDefaultWorld()
cWorld* cRoot::GetWorld( const char* a_WorldName ) cWorld* cRoot::GetWorld( const AString & a_WorldName )
{ {
WorldMap::iterator itr = m_pState->WorldsByName.find( a_WorldName ); WorldMap::iterator itr = m_pState->WorldsByName.find( a_WorldName );
if( itr != m_pState->WorldsByName.end() ) if( itr != m_pState->WorldsByName.end() )

View File

@ -37,7 +37,7 @@ public:
cServer* GetServer() { return m_Server; } //tolua_export cServer* GetServer() { return m_Server; } //tolua_export
OBSOLETE cWorld* GetWorld(); //tolua_export OBSOLETE cWorld* GetWorld(); //tolua_export
cWorld* GetDefaultWorld(); //tolua_export cWorld* GetDefaultWorld(); //tolua_export
cWorld* GetWorld( const char* a_WorldName ); //tolua_export cWorld* GetWorld( const AString & a_WorldName ); //tolua_export
cMonsterConfig *GetMonsterConfig() { return m_MonsterConfig;} cMonsterConfig *GetMonsterConfig() { return m_MonsterConfig;}
cGroupManager* GetGroupManager() { return m_GroupManager; } //tolua_export cGroupManager* GetGroupManager() { return m_GroupManager; } //tolua_export

View File

@ -179,7 +179,7 @@ cWorld::~cWorld()
cWorld::cWorld( const AString & a_WorldName ) cWorld::cWorld( const AString & a_WorldName )
: m_SpawnMonsterTime( 0.f ) : m_SpawnMonsterTime( 0.f )
, m_RSList ( 0 ) , m_RSList ( 0 )
, m_Weather ( 0 ) , m_Weather ( eWeather_Sunny )
{ {
LOG("cWorld::cWorld(%s)", a_WorldName.c_str()); LOG("cWorld::cWorld(%s)", a_WorldName.c_str());
m_WorldName = a_WorldName; m_WorldName = a_WorldName;
@ -191,7 +191,7 @@ cWorld::cWorld( const AString & a_WorldName )
m_SpawnY = cChunk::c_ChunkHeight; m_SpawnY = cChunk::c_ChunkHeight;
m_SpawnZ = (double)((r1.randInt()%1000)-500); m_SpawnZ = (double)((r1.randInt()%1000)-500);
m_WorldSeed = r1.randInt(); m_WorldSeed = r1.randInt();
m_GameMode = 0; m_GameMode = eGameMode_Creative;
AString GeneratorName; AString GeneratorName;
AString StorageSchema("Default"); AString StorageSchema("Default");
@ -203,7 +203,7 @@ cWorld::cWorld( const AString & a_WorldName )
m_SpawnY = IniFile.GetValueF("SpawnPosition", "Y", m_SpawnY ); m_SpawnY = IniFile.GetValueF("SpawnPosition", "Y", m_SpawnY );
m_SpawnZ = IniFile.GetValueF("SpawnPosition", "Z", m_SpawnZ ); m_SpawnZ = IniFile.GetValueF("SpawnPosition", "Z", m_SpawnZ );
m_WorldSeed = IniFile.GetValueI("Seed", "Seed", m_WorldSeed ); m_WorldSeed = IniFile.GetValueI("Seed", "Seed", m_WorldSeed );
m_GameMode = IniFile.GetValueI("GameMode", "GameMode", m_GameMode ); m_GameMode = (eGameMode)IniFile.GetValueI("GameMode", "GameMode", m_GameMode );
GeneratorName = IniFile.GetValue("Generator", "GeneratorName", GeneratorName); GeneratorName = IniFile.GetValue("Generator", "GeneratorName", GeneratorName);
StorageSchema = IniFile.GetValue("Storage", "Schema", StorageSchema); StorageSchema = IniFile.GetValue("Storage", "Schema", StorageSchema);
} }
@ -359,26 +359,38 @@ cWorld::cWorld( const AString & a_WorldName )
void cWorld::SetWeather( int Weather ) void cWorld::SetWeather( eWeather a_Weather )
{ {
if (Weather == 2) { //thunder storm switch( a_Weather )
m_Weather = 2; {
case eWeather_Sunny:
{
m_Weather = a_Weather;
cPacket_NewInvalidState WeatherPacket;
WeatherPacket.m_Reason = 2; //stop rain
Broadcast ( WeatherPacket );
}
break;
case eWeather_Rain:
{
m_Weather = a_Weather;
cPacket_NewInvalidState WeatherPacket;
WeatherPacket.m_Reason = 1; //begin rain
Broadcast ( WeatherPacket );
}
break;
case eWeather_ThunderStorm:
{
m_Weather = a_Weather;
cPacket_NewInvalidState WeatherPacket; cPacket_NewInvalidState WeatherPacket;
WeatherPacket.m_Reason = 1; //begin rain WeatherPacket.m_Reason = 1; //begin rain
Broadcast ( WeatherPacket ); Broadcast ( WeatherPacket );
CastThunderbolt ( 0, 0, 0 ); //start thunderstorm with a lightning strike at 0, 0, 0. >:D CastThunderbolt ( 0, 0, 0 ); //start thunderstorm with a lightning strike at 0, 0, 0. >:D
} }
if (Weather == 1) { //rainstorm break;
m_Weather = 1; default:
cPacket_NewInvalidState WeatherPacket; LOGWARN("Trying to set unknown weather %d", a_Weather );
WeatherPacket.m_Reason = 1; //begin rain break;
Broadcast ( WeatherPacket );
}
if (Weather == 0) { //sunny
m_Weather = 0;
cPacket_NewInvalidState WeatherPacket;
WeatherPacket.m_Reason = 2; //stop rain
Broadcast ( WeatherPacket );
} }
} }
@ -386,13 +398,13 @@ void cWorld::SetWeather( int Weather )
void cWorld::CastThunderbolt ( int X, int Y, int Z ) void cWorld::CastThunderbolt ( int a_X, int a_Y, int a_Z )
{ {
cPacket_Thunderbolt ThunderboltPacket; cPacket_Thunderbolt ThunderboltPacket;
ThunderboltPacket.m_xLBPos = X; ThunderboltPacket.m_xLBPos = a_X;
ThunderboltPacket.m_yLBPos = Y; ThunderboltPacket.m_yLBPos = a_Y;
ThunderboltPacket.m_zLBPos = Z; ThunderboltPacket.m_zLBPos = a_Z;
Broadcast( ThunderboltPacket ); Broadcast( ThunderboltPacket ); // FIXME: Broadcast to chunk instead of entire world
} }
@ -556,12 +568,12 @@ void cWorld::TickWeather(float a_Dt)
if (randWeather == 0) if (randWeather == 0)
{ {
LOG("Starting Rainstorm!"); LOG("Starting Rainstorm!");
SetWeather ( 1 ); SetWeather ( eWeather_Rain );
} }
else if (randWeather == 1) else if (randWeather == 1)
{ {
LOG("Starting Thunderstorm!"); LOG("Starting Thunderstorm!");
SetWeather ( 2 ); SetWeather ( eWeather_ThunderStorm );
} }
} }
} }
@ -574,12 +586,12 @@ void cWorld::TickWeather(float a_Dt)
if (randWeather == 0) //2% chance per second if (randWeather == 0) //2% chance per second
{ {
LOG("Back to sunny!"); LOG("Back to sunny!");
SetWeather ( 0 ); SetWeather ( eWeather_Sunny );
} }
else if ( (randWeather > 4000) && (GetWeather() != 2) ) // random chance for rainstorm to turn into thunderstorm. else if ( (randWeather > 4000) && (GetWeather() != 2) ) // random chance for rainstorm to turn into thunderstorm.
{ {
LOG("Starting Thunderstorm!"); LOG("Starting Thunderstorm!");
SetWeather ( 2 ); SetWeather ( eWeather_ThunderStorm );
} }
} }
} }
@ -588,7 +600,7 @@ void cWorld::TickWeather(float a_Dt)
{ {
if (m_TickRand.randInt() % 199 == 0) // 0.5% chance per tick of thunderbolt if (m_TickRand.randInt() % 199 == 0) // 0.5% chance per tick of thunderbolt
{ {
CastThunderbolt ( 0, 0, 0 ); // todo: find random possitions near players to cast thunderbolts. CastThunderbolt ( 0, 0, 0 ); // TODO: find random possitions near players to cast thunderbolts.
} }
} }
} }

View File

@ -16,6 +16,7 @@
#include "cChunkGenerator.h" #include "cChunkGenerator.h"
#include "Vector3i.h" #include "Vector3i.h"
#include "ChunkSender.h" #include "ChunkSender.h"
#include "Defines.h"
@ -56,7 +57,7 @@ public:
} }
long long GetWorldTime(void) const { return m_WorldTime; } //tolua_export long long GetWorldTime(void) const { return m_WorldTime; } //tolua_export
int GetGameMode(void) const { return m_GameMode; } //return gamemode for world eGameMode GetGameMode(void) const { return m_GameMode; } //tolua_export
void SetWorldTime(long long a_WorldTime) { m_WorldTime = a_WorldTime; } //tolua_export void SetWorldTime(long long a_WorldTime) { m_WorldTime = a_WorldTime; } //tolua_export
@ -85,11 +86,11 @@ public:
void CollectPickupsByPlayer(cPlayer * a_Player); void CollectPickupsByPlayer(cPlayer * a_Player);
// MOTD // MOTD
const AString & GetDescription(void) const {return m_Description; } const AString & GetDescription(void) const {return m_Description; } // FIXME: This should not be in cWorld
// Max Players // Max Players
unsigned int GetMaxPlayers(void) const {return m_MaxPlayers; } unsigned int GetMaxPlayers(void) const {return m_MaxPlayers; } //tolua_export
void SetMaxPlayers(int iMax); void SetMaxPlayers(int iMax); //tolua_export
void AddPlayer( cPlayer* a_Player ); void AddPlayer( cPlayer* a_Player );
void RemovePlayer( cPlayer* a_Player ); void RemovePlayer( cPlayer* a_Player );
@ -148,7 +149,7 @@ public:
/// Marks the chunk as failed-to-load: /// Marks the chunk as failed-to-load:
void ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ); void ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
void UpdateSign(int a_X, int a_Y, int a_Z, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4); void UpdateSign(int a_X, int a_Y, int a_Z, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4); //tolua_export
/// Marks (a_Stay == true) or unmarks (a_Stay == false) chunks as non-unloadable. To be used only by cChunkStay! /// Marks (a_Stay == true) or unmarks (a_Stay == false) chunks as non-unloadable. To be used only by cChunkStay!
void ChunksStay(const cChunkCoordsList & a_Chunks, bool a_Stay = true); void ChunksStay(const cChunkCoordsList & a_Chunks, bool a_Stay = true);
@ -185,7 +186,7 @@ public:
void GrowTree( int a_X, int a_Y, int a_Z ); //tolua_export void GrowTree( int a_X, int a_Y, int a_Z ); //tolua_export
unsigned int GetWorldSeed(void) const { return m_WorldSeed; } //tolua_export unsigned int GetWorldSeed(void) const { return m_WorldSeed; } //tolua_export
const AString & GetName(void) const {return m_WorldName; } //tolua_export const AString & GetName(void) const { return m_WorldName; } //tolua_export
inline static void AbsoluteToRelative( int & a_X, int & a_Y, int & a_Z, int & a_ChunkX, int & a_ChunkY, int & a_ChunkZ ) inline static void AbsoluteToRelative( int & a_X, int & a_Y, int & a_Z, int & a_ChunkX, int & a_ChunkY, int & a_ChunkZ )
{ {
@ -224,9 +225,9 @@ public:
void InitializeSpawn(); void InitializeSpawn();
void CastThunderbolt ( int, int, int ); //tolua_export void CastThunderbolt (int a_X, int a_Y, int a_Z); //tolua_export
void SetWeather ( int ); //tolua_export void SetWeather ( eWeather a_Weather ); //tolua_export
int GetWeather() { return m_Weather; }; //tolua_export eWeather GetWeather() { return m_Weather; }; //tolua_export
cChunkGenerator & GetGenerator(void) { return m_Generator; } cChunkGenerator & GetGenerator(void) { return m_Generator; }
cWorldStorage & GetStorage (void) { return m_Storage; } cWorldStorage & GetStorage (void) { return m_Storage; }
@ -248,7 +249,7 @@ private:
static float m_Time; // Time in seconds static float m_Time; // Time in seconds
long long m_WorldTime; // Time in seconds*20, this is sent to clients (is wrapped) long long m_WorldTime; // Time in seconds*20, this is sent to clients (is wrapped)
unsigned long long CurrentTick; unsigned long long CurrentTick;
int m_GameMode; eGameMode m_GameMode;
float m_WorldTimeFraction; // When this > 1.f m_WorldTime is incremented by 20 float m_WorldTimeFraction; // When this > 1.f m_WorldTime is incremented by 20
// The cRedstone class simulates redstone and needs access to m_RSList // The cRedstone class simulates redstone and needs access to m_RSList
@ -280,7 +281,7 @@ private:
unsigned int m_WorldSeed; unsigned int m_WorldSeed;
int m_Weather; eWeather m_Weather;
cEntityList m_RemoveEntityQueue; cEntityList m_RemoveEntityQueue;
cEntityList m_AllEntities; cEntityList m_AllEntities;

View File

@ -56,7 +56,6 @@ void cPacket_CreativeInventoryAction::Serialize(AString & a_Data) const
// WARNING: HERE ITS -1, BUT IN NAMED ENTITY SPAWN PACKET ITS 0 !! // WARNING: HERE ITS -1, BUT IN NAMED ENTITY SPAWN PACKET ITS 0 !!
} }
unsigned int i = 0;
AppendByte (a_Data, m_PacketID); AppendByte (a_Data, m_PacketID);
AppendShort (a_Data, m_Slot); AppendShort (a_Data, m_Slot);