From 88270be66928f3b73b73fc1f3b26a74358089223 Mon Sep 17 00:00:00 2001 From: "admin@omencraft.com" Date: Wed, 26 Oct 2011 20:52:19 +0000 Subject: Made several recomended changes. Gamemode is now world based. Need to add it to player. git-svn-id: http://mc-server.googlecode.com/svn/trunk@18 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cClientHandle.cpp | 7 ++++--- source/cInventory.h | 1 - source/cPlayer.cpp | 9 +++++++-- source/cPlugin.h | 1 - source/cWorld.cpp | 3 ++- source/cWorld.h | 4 ++++ source/packets/cPacket.h | 2 -- source/packets/cPacket_CreateInventoryAction.cpp | 6 +++--- source/packets/cPacket_CreateInventoryAction.h | 8 ++++---- source/packets/cPacket_Login.h | 2 +- source/packets/cPacket_Respawn.h | 2 +- 11 files changed, 26 insertions(+), 19 deletions(-) diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index c5c6dbd20..3fef88bfc 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -482,10 +482,10 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) cWorld* World = cRoot::Get()->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) && (cPacket::GAMEMODE == 1) ); //need to change to check for client's gamemode. + bool bBroken = (PacketData->m_Status == 0x02) || g_BlockOneHitDig[(int)OldBlock] || ( (PacketData->m_Status == 0x00) && (cRoot::Get()->GetWorld()->GetGameMode() == 1) ); //need to change to check for client's gamemode. cItem PickupItem; - if( bBroken && !(cPacket::GAMEMODE == 1) ) // broken + if( bBroken && !(cRoot::Get()->GetWorld()->GetGameMode() == 1) ) // broken { ENUM_ITEM_ID PickupID = cBlockToPickup::ToPickup( (ENUM_BLOCK_ID)OldBlock, m_Player->GetInventory().GetEquippedItem().m_ItemID ); PickupItem.m_ItemID = PickupID; @@ -581,7 +581,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) { cPacket_BlockPlace* PacketData = reinterpret_cast(a_Packet); cItem & Equipped = m_Player->GetInventory().GetEquippedItem(); - if( Equipped.m_ItemID != PacketData->m_ItemType ) // Not valid + if( (Equipped.m_ItemID != PacketData->m_ItemType) ) // Not valid { LOGWARN("Player %s tried to place a block that was not selected! (could indicate bot)", GetUsername() ); break; @@ -913,6 +913,7 @@ 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. LoginResponse.m_MapSeed = 0; LoginResponse.m_Dimension = 0; Send( LoginResponse ); diff --git a/source/cInventory.h b/source/cInventory.h index 01f505ab1..cebcf346b 100644 --- a/source/cInventory.h +++ b/source/cInventory.h @@ -9,7 +9,6 @@ class cClientHandle; class cPlayer; class cPacket_WindowClick; class cPacket_EntityEquipment; -class cPacket_CreateInventoryAction; class cInventory //tolua_export : public cWindowOwner { //tolua_export diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp index 21c08fc5a..2f7e27988 100644 --- a/source/cPlayer.cpp +++ b/source/cPlayer.cpp @@ -317,7 +317,7 @@ void cPlayer::Heal( int a_Health ) void cPlayer::TakeDamage( int a_Damage, cEntity* a_Instigator ) { - if ( !(cPacket::GAMEMODE == 1) ) { + if ( !(cRoot::Get()->GetWorld()->GetGameMode() == 1) ) { cPawn::TakeDamage( a_Damage, a_Instigator ); cPacket_UpdateHealth Health; @@ -356,7 +356,12 @@ void cPlayer::Respawn() m_Health = 20; cWorld* World = cRoot::Get()->GetWorld(); - m_ClientHandle->Send( cPacket_Respawn() ); + // Create Respawn player packet + cPacket_Respawn Packet; + //Set Gamemode for packet by looking at world's gamemode (Need to check players gamemode.) + Packet.m_CreativeMode = cRoot::Get()->GetWorld()->GetGameMode(); + //Send Packet + m_ClientHandle->Send( Packet ); TeleportTo( World->GetSpawnX(), World->GetSpawnY(), World->GetSpawnZ() ); SetVisible( true ); } diff --git a/source/cPlugin.h b/source/cPlugin.h index add455006..6c38871f3 100644 --- a/source/cPlugin.h +++ b/source/cPlugin.h @@ -8,7 +8,6 @@ class cPacket_BlockPlace; class cPacket_PickupSpawn; class cPacket_EntityEquipment; -class cPacket_CreateInventoryAction; class cPacket_Disconnect; class cPacket_Chat; class cPacket_BlockDig; diff --git a/source/cWorld.cpp b/source/cWorld.cpp index 54fd090dc..c5dfc683e 100644 --- a/source/cWorld.cpp +++ b/source/cWorld.cpp @@ -184,6 +184,7 @@ cWorld::cWorld() m_Time = 0; m_WorldTimeFraction = 0.f; m_WorldTime = 0; + m_GameMode = 1; m_LastSave = 0; m_LastUnload = 0; m_ClientHandleCriticalSection = new cCriticalSection(); @@ -810,4 +811,4 @@ void cWorld::AddToRemoveEntityQueue( cEntity & a_Entity ) { m_pState->m_AllEntities.remove( &a_Entity); m_pState->m_RemoveEntityQueue.push_back( &a_Entity ); -} \ No newline at end of file +} diff --git a/source/cWorld.h b/source/cWorld.h index 0b2f8ec85..74f8ae8e8 100644 --- a/source/cWorld.h +++ b/source/cWorld.h @@ -33,6 +33,9 @@ public: return m_Time; } long long GetWorldTime() { return m_WorldTime; } //tolua_export + + int GetGameMode() { return m_GameMode; } //return gamemode for world + void SetWorldTime(long long a_WorldTime) { m_WorldTime = a_WorldTime; } //tolua_export cChunk* GetChunk( int a_X, int a_Y, int a_Z ); @@ -136,6 +139,7 @@ private: float m_LastSave; static float m_Time; // Time in seconds long long m_WorldTime; // Time in seconds*20, this is sent to clients (is wrapped) + int m_GameMode; float m_WorldTimeFraction; // When this > 1.f m_WorldTime is incremented by 20 cWaterSimulator* m_WaterSimulator; diff --git a/source/packets/cPacket.h b/source/packets/cPacket.h index ff4366c7a..304d6b8d3 100644 --- a/source/packets/cPacket.h +++ b/source/packets/cPacket.h @@ -22,8 +22,6 @@ public: virtual bool Send( cSocket & a_Socket) { a_Socket=0; printf("ERROR: Undefined NEW Send function %x\n", m_PacketID ); return false; } virtual cPacket* Clone() const = 0; - static const int GAMEMODE = 1; //0 = Survival, 1 = Creative; - unsigned char m_PacketID; cSocket m_Socket; // Current socket being used protected: diff --git a/source/packets/cPacket_CreateInventoryAction.cpp b/source/packets/cPacket_CreateInventoryAction.cpp index 19996769f..40aad22e8 100644 --- a/source/packets/cPacket_CreateInventoryAction.cpp +++ b/source/packets/cPacket_CreateInventoryAction.cpp @@ -6,7 +6,7 @@ cPacket_CreateInventoryAction::cPacket_CreateInventoryAction( const cPacket_Crea m_Slot = a_Copy.m_Slot; m_ItemID = a_Copy.m_ItemID; m_Quantity = 0; - m_Short = 0; + m_Damage = 0; } bool cPacket_CreateInventoryAction::Parse(cSocket & a_Socket) @@ -15,7 +15,7 @@ bool cPacket_CreateInventoryAction::Parse(cSocket & a_Socket) if( !ReadShort ( m_Slot ) ) return false; if( !ReadShort ( m_ItemID ) ) return false; if( !ReadShort ( m_Quantity ) ) return false; - if( !ReadShort ( m_Short ) ) return false; + if( !ReadShort ( m_Damage ) ) return false; return true; } @@ -34,7 +34,7 @@ bool cPacket_CreateInventoryAction::Send(cSocket & a_Socket) AppendShort ( m_Slot, Message, i ); AppendShort ( m_ItemID, Message, i ); AppendShort ( m_Quantity, Message, i ); - AppendShort ( m_Short, Message, i ); + AppendShort ( m_Damage, Message, i ); bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) ); delete [] Message; diff --git a/source/packets/cPacket_CreateInventoryAction.h b/source/packets/cPacket_CreateInventoryAction.h index e4ed2d9f8..02af3a64e 100644 --- a/source/packets/cPacket_CreateInventoryAction.h +++ b/source/packets/cPacket_CreateInventoryAction.h @@ -10,8 +10,8 @@ public: : m_Slot( 0 ) , m_ItemID( 0 ) , m_Quantity( 0 ) - , m_Short( 0 ) - { m_PacketID = E_CREATE_INVENTORY_ACTION; m_Short = 0; m_Quantity = 1; } + , m_Damage( 0 ) + { m_PacketID = E_CREATE_INVENTORY_ACTION; m_Quantity = 1; } cPacket_CreateInventoryAction( const cPacket_CreateInventoryAction & a_Copy ); virtual cPacket* Clone() const { return new cPacket_CreateInventoryAction(*this); } @@ -21,7 +21,7 @@ public: short m_Slot; // 0 = hold 1-4 = armor short m_ItemID; short m_Quantity; - short m_Short; + short m_Damage; - static const unsigned int c_Size = 1 + 4 + 2 + 2 + 2; + static const unsigned int c_Size = 1 + 2 + 2 + 2 + 2; }; diff --git a/source/packets/cPacket_Login.h b/source/packets/cPacket_Login.h index 81c8af39b..91919a799 100644 --- a/source/packets/cPacket_Login.h +++ b/source/packets/cPacket_Login.h @@ -10,7 +10,7 @@ public: cPacket_Login() : m_ProtocolVersion( 0 ) , m_MapSeed( 0 ) - , m_ServerMode( GAMEMODE ) //0 for survival, 1 for creative + , m_ServerMode( 0 ) , m_Dimension( 0 ) , m_Difficulty( 0 ) , m_WorldHeight( 0 ) diff --git a/source/packets/cPacket_Respawn.h b/source/packets/cPacket_Respawn.h index 9a87d11ae..ab8fbe72a 100644 --- a/source/packets/cPacket_Respawn.h +++ b/source/packets/cPacket_Respawn.h @@ -9,7 +9,7 @@ public: cPacket_Respawn() : m_World( 0 ) , m_Difficulty( 0 ) - , m_CreativeMode( GAMEMODE ) + , m_CreativeMode( 0 ) , m_WorldHeight( 0 ) , m_MapSeed( 0 ) { m_PacketID = E_RESPAWN; } -- cgit v1.2.3