diff options
author | admin@omencraft.com <admin@omencraft.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2011-11-10 17:30:14 +0100 |
---|---|---|
committer | admin@omencraft.com <admin@omencraft.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2011-11-10 17:30:14 +0100 |
commit | 6027c3d0b8417c951b92f37e80cb6f99ebf40e67 (patch) | |
tree | e3169e73472f4937c5bb23678bd46d79e89feeac /source | |
parent | Fixed doors. I forgot to actually return proper Hex value. Started work on adding farmland, farming, and leaf decay support. (diff) | |
download | cuberite-6027c3d0b8417c951b92f37e80cb6f99ebf40e67.tar cuberite-6027c3d0b8417c951b92f37e80cb6f99ebf40e67.tar.gz cuberite-6027c3d0b8417c951b92f37e80cb6f99ebf40e67.tar.bz2 cuberite-6027c3d0b8417c951b92f37e80cb6f99ebf40e67.tar.lz cuberite-6027c3d0b8417c951b92f37e80cb6f99ebf40e67.tar.xz cuberite-6027c3d0b8417c951b92f37e80cb6f99ebf40e67.tar.zst cuberite-6027c3d0b8417c951b92f37e80cb6f99ebf40e67.zip |
Diffstat (limited to '')
-rw-r--r-- | source/Bindings.cpp | 180 | ||||
-rw-r--r-- | source/Bindings.h | 2 | ||||
-rw-r--r-- | source/cClientHandle.cpp | 85 | ||||
-rw-r--r-- | source/cDoors.h | 2 | ||||
-rw-r--r-- | source/cPlayer.cpp | 6 | ||||
-rw-r--r-- | source/cPlayer.h | 9 |
6 files changed, 258 insertions, 26 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp index 045065396..c4b6cb143 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -1,6 +1,6 @@ /*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 11/09/11 17:20:10.
+** Generated automatically by tolua++-1.0.92 on 11/10/11 10:15:41.
*/
#ifndef __cplusplus
@@ -5163,6 +5163,167 @@ static int tolua_AllToLua_cPlayer_GetIP00(lua_State* tolua_S) }
#endif //#ifndef TOLUA_DISABLE
+/* method: GetLastBlockActionTime of class cPlayer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_GetLastBlockActionTime00
+static int tolua_AllToLua_cPlayer_GetLastBlockActionTime00(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 'GetLastBlockActionTime'", NULL);
+#endif
+ {
+ float tolua_ret = (float) self->GetLastBlockActionTime();
+ tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'GetLastBlockActionTime'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: GetLastBlockActionCnt of class cPlayer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_GetLastBlockActionCnt00
+static int tolua_AllToLua_cPlayer_GetLastBlockActionCnt00(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 'GetLastBlockActionCnt'", NULL);
+#endif
+ {
+ int tolua_ret = (int) self->GetLastBlockActionCnt();
+ tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'GetLastBlockActionCnt'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: SetLastBlockActionCnt of class cPlayer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_SetLastBlockActionCnt00
+static int tolua_AllToLua_cPlayer_SetLastBlockActionCnt00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
+ int tolua_var_1 = ((int) tolua_tonumber(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetLastBlockActionCnt'", NULL);
+#endif
+ {
+ self->SetLastBlockActionCnt(tolua_var_1);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'SetLastBlockActionCnt'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: SetLastBlockActionTime of class cPlayer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_SetLastBlockActionTime00
+static int tolua_AllToLua_cPlayer_SetLastBlockActionTime00(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 'SetLastBlockActionTime'", NULL);
+#endif
+ {
+ self->SetLastBlockActionTime();
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'SetLastBlockActionTime'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: SetGameMode of class cPlayer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_SetGameMode00
+static int tolua_AllToLua_cPlayer_SetGameMode00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
+ int a_GameMode = ((int) tolua_tonumber(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetGameMode'", NULL);
+#endif
+ {
+ self->SetGameMode(a_GameMode);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'SetGameMode'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: MoveTo of class cPlayer */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_MoveTo00
static int tolua_AllToLua_cPlayer_MoveTo00(lua_State* tolua_S)
@@ -8764,14 +8925,14 @@ static int tolua_AllToLua_cWorld_CastThunderbolt00(lua_State* tolua_S) #endif
{
cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0);
- int tolua_var_1 = ((int) tolua_tonumber(tolua_S,2,0));
- int tolua_var_2 = ((int) tolua_tonumber(tolua_S,3,0));
- int tolua_var_3 = ((int) tolua_tonumber(tolua_S,4,0));
+ int tolua_var_2 = ((int) tolua_tonumber(tolua_S,2,0));
+ int tolua_var_3 = ((int) tolua_tonumber(tolua_S,3,0));
+ int tolua_var_4 = ((int) tolua_tonumber(tolua_S,4,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CastThunderbolt'", NULL);
#endif
{
- self->CastThunderbolt(tolua_var_1,tolua_var_2,tolua_var_3);
+ self->CastThunderbolt(tolua_var_2,tolua_var_3,tolua_var_4);
}
}
return 0;
@@ -8799,12 +8960,12 @@ static int tolua_AllToLua_cWorld_SetWeather00(lua_State* tolua_S) #endif
{
cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0);
- int tolua_var_4 = ((int) tolua_tonumber(tolua_S,2,0));
+ int tolua_var_5 = ((int) tolua_tonumber(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetWeather'", NULL);
#endif
{
- self->SetWeather(tolua_var_4);
+ self->SetWeather(tolua_var_5);
}
}
return 0;
@@ -15799,6 +15960,11 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"TeleportTo",tolua_AllToLua_cPlayer_TeleportTo01);
tolua_function(tolua_S,"GetGameMode",tolua_AllToLua_cPlayer_GetGameMode00);
tolua_function(tolua_S,"GetIP",tolua_AllToLua_cPlayer_GetIP00);
+ tolua_function(tolua_S,"GetLastBlockActionTime",tolua_AllToLua_cPlayer_GetLastBlockActionTime00);
+ tolua_function(tolua_S,"GetLastBlockActionCnt",tolua_AllToLua_cPlayer_GetLastBlockActionCnt00);
+ tolua_function(tolua_S,"SetLastBlockActionCnt",tolua_AllToLua_cPlayer_SetLastBlockActionCnt00);
+ tolua_function(tolua_S,"SetLastBlockActionTime",tolua_AllToLua_cPlayer_SetLastBlockActionTime00);
+ tolua_function(tolua_S,"SetGameMode",tolua_AllToLua_cPlayer_SetGameMode00);
tolua_function(tolua_S,"MoveTo",tolua_AllToLua_cPlayer_MoveTo00);
tolua_function(tolua_S,"GetClientHandle",tolua_AllToLua_cPlayer_GetClientHandle00);
tolua_function(tolua_S,"SendMessage",tolua_AllToLua_cPlayer_SendMessage00);
diff --git a/source/Bindings.h b/source/Bindings.h index dd6c6335f..fecc08b40 100644 --- a/source/Bindings.h +++ b/source/Bindings.h @@ -1,6 +1,6 @@ /*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 11/09/11 17:20:10.
+** Generated automatically by tolua++-1.0.92 on 11/10/11 10:15:41.
*/
/* Exported function */
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index e06dc728a..8409fce66 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -493,14 +493,21 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) break;
case E_BLOCK_DIG:
{
- //LOG("TimeP: %f", m_Player->GetLastBlockActionTime() );
- //LOG("TimeN: %f", cRoot::Get()->GetWorld()->GetTime() );
+
+ int LastActionCnt = m_Player->GetLastBlockActionCnt();
if ( cRoot::Get()->GetWorld()->GetTime() - m_Player->GetLastBlockActionTime() < 0.1 ) { //only allow block interactions every 0.1 seconds
- LOGWARN("Player %s tried to interact with a block too quickly! (could indicate bot)", GetUsername() );
m_Player->SetLastBlockActionTime(); //Player tried to interact with a block. Reset last block interation time.
- break;
+ m_Player->SetLastBlockActionCnt(LastActionCnt+1);
+ if (LastActionCnt > 3) { //kick if more than 3 interactions per .1 seconds
+ LOGWARN("Player %s tried to interact with a block too quickly! (could indicate bot) Was Kicked.", GetUsername() );
+ Kick("You're a baaaaaad boy!");
+ break;
+ }
+ } else {
+ m_Player->SetLastBlockActionCnt(0); //reset count
+ m_Player->SetLastBlockActionTime(); //Player tried to interact with a block. Reset last block interation time.
}
- m_Player->SetLastBlockActionTime(); //Player tried to interact with a block. Reset last block interation time.
+
cPacket_BlockDig* PacketData = reinterpret_cast<cPacket_BlockDig*>(a_Packet);
LOG("OnBlockDig: %i %i %i Dir: %i Stat: %i", PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, PacketData->m_Direction, PacketData->m_Status );
if( PacketData->m_Status == 0x04 ) // Drop block
@@ -643,15 +650,21 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) break;
case E_BLOCK_PLACE:
{
-
- //LOG("TimeP: %f", m_Player->GetLastBlockActionTime() );
- //LOG("TimeN: %f", cRoot::Get()->GetWorld()->GetTime() );
+
+ int LastActionCnt = m_Player->GetLastBlockActionCnt();
if ( cRoot::Get()->GetWorld()->GetTime() - m_Player->GetLastBlockActionTime() < 0.1 ) { //only allow block interactions every 0.1 seconds
- LOGWARN("Player %s tried to interact with a block too quickly! (could indicate bot)", GetUsername() );
m_Player->SetLastBlockActionTime(); //Player tried to interact with a block. Reset last block interation time.
- break;
+ m_Player->SetLastBlockActionCnt(LastActionCnt+1);
+ if (LastActionCnt > 3) { //kick if more than 3 interactions per .1 seconds
+ LOGWARN("Player %s tried to interact with a block too quickly! (could indicate bot) Was Kicked.", GetUsername() );
+ Kick("You're a baaaaaad boy!");
+ break;
+ }
+ } else {
+ m_Player->SetLastBlockActionCnt(0); //reset count
+ m_Player->SetLastBlockActionTime(); //Player tried to interact with a block. Reset last block interation time.
}
- m_Player->SetLastBlockActionTime(); //Player tried to interact with a block. Reset last block interation time.
+
cPacket_BlockPlace* PacketData = reinterpret_cast<cPacket_BlockPlace*>(a_Packet);
cItem & Equipped = m_Player->GetInventory().GetEquippedItem();
//if( (Equipped.m_ItemID != PacketData->m_ItemType) ) // Not valid
@@ -794,9 +807,31 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) if( PacketData->m_Direction < 0 ) // clicked in air
break;
+ int clickedBlock = (int)m_Player->GetWorld()->GetBlock( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ );
char MetaData = (char)Equipped.m_ItemHealth;
+ bool LavaBucket = false;
+ bool WaterBucket = false;
switch( PacketData->m_ItemType ) // Special handling for special items
{
+ case E_ITEM_BUCKET:
+ switch (clickedBlock)
+ {
+ case E_BLOCK_WATER:
+ case E_BLOCK_STATIONARY_WATER:
+ WaterBucket = true;
+ break;
+ case E_BLOCK_LAVA:
+ case E_BLOCK_STATIONARY_LAVA:
+ LavaBucket = true;
+ break;
+ }
+ break;
+ case E_ITEM_LAVA_BUCKET:
+ PacketData->m_ItemType = E_BLOCK_LAVA;
+ break;
+ case E_ITEM_WATER_BUCKET:
+ PacketData->m_ItemType = E_BLOCK_WATER;
+ break;
case E_BLOCK_WHITE_CLOTH:
MetaData = (char)PacketData->m_Uses;
break;
@@ -806,8 +841,6 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) case E_BLOCK_REDSTONE_TORCH_OFF:
{
MetaData = cTorch::DirectionToMetaData( PacketData->m_Direction );
- //check redstone circuit:
- //if( GetBlock( X, Y+1, Z ) == E_BLOCK_AIR )
if( g_BlockTransparent[ (int)m_Player->GetWorld()->GetBlock( PacketData->m_PosX, PacketData->m_PosY+2, PacketData->m_PosZ ) ] == true ) {//if block above is transparent
//printf("transparent above me\n");
} else {
@@ -884,8 +917,29 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) default:
break;
};
- if( IsValidBlock( PacketData->m_ItemType) )
- {
+
+
+ if (LavaBucket) {
+
+ if( (m_Player->GetGameMode() == 1) || (m_Player->GetInventory().RemoveItem( Item )) ) {
+ cItem NewItem;
+ NewItem.m_ItemID = E_ITEM_LAVA_BUCKET;
+ NewItem.m_ItemCount = 1;
+ m_Player->GetInventory().AddItem( NewItem );
+ m_Player->GetWorld()->SetBlock( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, E_BLOCK_AIR, 0 );
+ }
+
+ } else if (WaterBucket) {
+
+ if( (m_Player->GetGameMode() == 1) || (m_Player->GetInventory().RemoveItem( Item )) ) {
+ cItem NewItem;
+ NewItem.m_ItemID = E_ITEM_WATER_BUCKET;
+ NewItem.m_ItemCount = 1;
+ m_Player->GetInventory().AddItem( NewItem );
+ m_Player->GetWorld()->SetBlock( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, E_BLOCK_AIR, 0 );
+ }
+
+ } else if( IsValidBlock( PacketData->m_ItemType) ) {
int X = PacketData->m_PosX;
char Y = PacketData->m_PosY;
int Z = PacketData->m_PosZ;
@@ -909,6 +963,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) cRedstone Redstone(m_Player->GetWorld());
Redstone.ChangeRedstone( PacketData->m_PosX, PacketData->m_PosY+1, PacketData->m_PosZ, AddedCurrent );
}
+
}
}
}
diff --git a/source/cDoors.h b/source/cDoors.h index 0258a9625..eb1710df2 100644 --- a/source/cDoors.h +++ b/source/cDoors.h @@ -51,6 +51,8 @@ public: return 0xA;
} else if ( (int)MetaData == 15 ) {
return 0xB;
+ } else {
+ return 0x0;
}
} //tolua_export
diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp index 8aefd36ba..706886d88 100644 --- a/source/cPlayer.cpp +++ b/source/cPlayer.cpp @@ -63,6 +63,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const char* a_PlayerName) , m_GameMode( 0 )
, m_IP("")
, m_LastBlockActionTime( 0 )
+ , m_LastBlockActionCnt( 0 )
, e_EPMetaState(NORMAL)
, m_bVisible( true )
, m_LastGroundHeight( 0 )
@@ -415,6 +416,11 @@ void cPlayer::SetLastBlockActionTime() m_LastBlockActionTime = cRoot::Get()->GetWorld()->GetTime();
}
+void cPlayer::SetLastBlockActionCnt( int a_LastBlockActionCnt )
+{
+ m_LastBlockActionCnt = a_LastBlockActionCnt;
+}
+
void cPlayer::SetGameMode( int a_GameMode )
{
m_GameMode = a_GameMode;
diff --git a/source/cPlayer.h b/source/cPlayer.h index 08234df88..adefd7fdc 100644 --- a/source/cPlayer.h +++ b/source/cPlayer.h @@ -33,9 +33,11 @@ public: int GetGameMode() { return m_GameMode; } //tolua_export
std::string GetIP() { return m_IP; } //tolua_export
- float GetLastBlockActionTime() { return m_LastBlockActionTime; } //return LastBlockActionTime for player.
- void SetLastBlockActionTime();
- void SetGameMode( int a_GameMode );
+ float GetLastBlockActionTime() { return m_LastBlockActionTime; } //tolua_export
+ int GetLastBlockActionCnt() { return m_LastBlockActionCnt; } //tolua_export
+ void SetLastBlockActionCnt( int ); //tolua_export
+ void SetLastBlockActionTime(); //tolua_export
+ void SetGameMode( int a_GameMode ); //tolua_export
void SetIP( std::string a_IP );
// Tries to move to a new position, with collision checks and stuff
@@ -105,6 +107,7 @@ protected: float m_BurnPeriod;
float m_LastBlockActionTime;
+ int m_LastBlockActionCnt;
int m_GameMode;
std::string m_IP;
|