summaryrefslogtreecommitdiffstats
path: root/source/cClientHandle.cpp
diff options
context:
space:
mode:
authoradmin@omencraft.com <admin@omencraft.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-11-01 21:09:13 +0100
committeradmin@omencraft.com <admin@omencraft.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-11-01 21:09:13 +0100
commitf849b664e085034a5c1e09bbb9a4ceb4127c05ae (patch)
tree35054d7ba1e231d71c1280eb5be26b7b0ab97f07 /source/cClientHandle.cpp
parentPlayers can now place blocks in creative mode. The blocks players select from the creative mode inventory are not stored in the players' inventory. (I kind of like that) (diff)
downloadcuberite-f849b664e085034a5c1e09bbb9a4ceb4127c05ae.tar
cuberite-f849b664e085034a5c1e09bbb9a4ceb4127c05ae.tar.gz
cuberite-f849b664e085034a5c1e09bbb9a4ceb4127c05ae.tar.bz2
cuberite-f849b664e085034a5c1e09bbb9a4ceb4127c05ae.tar.lz
cuberite-f849b664e085034a5c1e09bbb9a4ceb4127c05ae.tar.xz
cuberite-f849b664e085034a5c1e09bbb9a4ceb4127c05ae.tar.zst
cuberite-f849b664e085034a5c1e09bbb9a4ceb4127c05ae.zip
Diffstat (limited to '')
-rw-r--r--source/cClientHandle.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index 4c0cefc3e..18ba84d88 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -471,6 +471,14 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
break;
case E_BLOCK_DIG:
{
+ LOG("TimeP: %f", m_Player->GetLastBlockActionTime() );
+ LOG("TimeN: %f", cRoot::Get()->GetWorld()->GetTime() );
+ 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->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
@@ -482,10 +490,10 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
cWorld* World = m_Player->GetWorld();
char OldBlock = World->GetBlock(PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ);
char MetaData = World->GetBlockMeta(PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ);
- bool bBroken = (PacketData->m_Status == 0x02) || g_BlockOneHitDig[(int)OldBlock] || ( (PacketData->m_Status == 0x00) && (World->GetGameMode() == 1) ); //need to change to check for client's gamemode.
+ bool bBroken = (PacketData->m_Status == 0x02) || g_BlockOneHitDig[(int)OldBlock] || ( (PacketData->m_Status == 0x00) && (m_Player->GetGameMode() == 1) );
cItem PickupItem;
- if( bBroken && !(World->GetGameMode() == 1) ) // broken
+ if( bBroken && !(m_Player->GetGameMode() == 1) ) // broken
{
ENUM_ITEM_ID PickupID = cBlockToPickup::ToPickup( (ENUM_BLOCK_ID)OldBlock, m_Player->GetInventory().GetEquippedItem().m_ItemID );
PickupItem.m_ItemID = PickupID;
@@ -579,10 +587,18 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
break;
case E_BLOCK_PLACE:
{
+ LOG("TimeP: %f", m_Player->GetLastBlockActionTime() );
+ LOG("TimeN: %f", cRoot::Get()->GetWorld()->GetTime() );
+ 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->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
- if( (Equipped.m_ItemID != PacketData->m_ItemType) && (cRoot::Get()->GetWorld()->GetGameMode() != 1) ) // Not valid
+ if( (Equipped.m_ItemID != PacketData->m_ItemType) && (m_Player->GetGameMode() != 1) ) // Not valid
{
LOGWARN("Player %s tried to place a block that was not selected! (could indicate bot)", GetUsername() );
break;
@@ -721,7 +737,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
if( IsValidBlock( PacketData->m_ItemType) )
{
- if( (m_Player->GetInventory().RemoveItem( Item )) || (cRoot::Get()->GetWorld()->GetGameMode() == 1) )
+ if( (m_Player->GetInventory().RemoveItem( Item )) || (m_Player->GetGameMode() == 1) )
{
int X = PacketData->m_PosX;
char Y = PacketData->m_PosY;
@@ -914,7 +930,9 @@ void cClientHandle::SendLoginResponse()
cPacket_Login LoginResponse;
LoginResponse.m_ProtocolVersion = m_Player->GetUniqueID();
//LoginResponse.m_Username = "";
- LoginResponse.m_ServerMode = cRoot::Get()->GetWorld()->GetGameMode(); //set gamemode from world.
+ //m_Player->SetGameMode ( 0 );
+ m_Player->SetGameMode ( cRoot::Get()->GetWorld()->GetGameMode() ); //set player's gamemode to server's gamemode at login.
+ LoginResponse.m_ServerMode = m_Player->GetGameMode(); //set gamemode from player.
LoginResponse.m_MapSeed = 0;
LoginResponse.m_Dimension = 0;
Send( LoginResponse );