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
This commit is contained in:
parent
6062002d17
commit
88270be669
@ -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<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) ) // 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 );
|
||||
|
@ -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
|
||||
|
@ -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 );
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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 )
|
||||
|
@ -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; }
|
||||
|
Loading…
Reference in New Issue
Block a user