Added CreateInventoryAction packet for creative mode. Used cPacketEntityEquipment as template. Forced server into Creative Mode. Can't break blocks yet. Player can stil be damaged in creative mode and dying takes you back to survival mode.
git-svn-id: http://mc-server.googlecode.com/svn/trunk@15 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
8e64a5d9ff
commit
acd537d533
@ -308,6 +308,7 @@
|
||||
<ClCompile Include="..\source\packets\cPacket_DestroyEntity.cpp" />
|
||||
<ClCompile Include="..\source\packets\cPacket_Disconnect.cpp" />
|
||||
<ClCompile Include="..\source\packets\cPacket_EntityEquipment.cpp" />
|
||||
<ClCompile Include="..\source\packets\cPacket_CreateInventoryAction.cpp" />
|
||||
<ClCompile Include="..\source\packets\cPacket_EntityLook.cpp" />
|
||||
<ClCompile Include="..\source\packets\cPacket_EntityStatus.cpp" />
|
||||
<ClCompile Include="..\source\packets\cPacket_Flying.cpp" />
|
||||
@ -445,6 +446,7 @@
|
||||
<ClInclude Include="..\source\packets\cPacket_DestroyEntity.h" />
|
||||
<ClInclude Include="..\source\packets\cPacket_Disconnect.h" />
|
||||
<ClInclude Include="..\source\packets\cPacket_EntityEquipment.h" />
|
||||
<ClInclude Include="..\source\packets\cPacket_CreateInventoryAction.h" />
|
||||
<ClInclude Include="..\source\packets\cPacket_EntityLook.h" />
|
||||
<ClInclude Include="..\source\packets\cPacket_EntityStatus.h" />
|
||||
<ClInclude Include="..\source\packets\cPacket_Flying.h" />
|
||||
@ -513,4 +515,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -283,6 +283,9 @@
|
||||
<Filter Include="Packets\cPacket_EntityEquipment">
|
||||
<UniqueIdentifier>{0f48e5f8-ea4d-41dc-ab9e-750c5912c778}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Packets\cPacket_CreateInventoryAction">
|
||||
<UniqueIdentifier>{0c47e5f8-ea4d-40dc-ac8e-740c5512c768}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Packets\cPacket_UseEntity">
|
||||
<UniqueIdentifier>{bff5658b-0806-430c-9929-062f4bd4760b}</UniqueIdentifier>
|
||||
</Filter>
|
||||
@ -646,6 +649,9 @@
|
||||
<ClCompile Include="..\source\packets\cPacket_EntityEquipment.cpp">
|
||||
<Filter>Packets\cPacket_EntityEquipment</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\packets\cPacket_CreateInventoryAction.cpp">
|
||||
<Filter>Packets\cPacket_CreateInventoryAction</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\packets\cPacket_UseEntity.cpp">
|
||||
<Filter>Packets\cPacket_UseEntity</Filter>
|
||||
</ClCompile>
|
||||
@ -1041,6 +1047,9 @@
|
||||
<ClInclude Include="..\source\packets\cPacket_EntityEquipment.h">
|
||||
<Filter>Packets\cPacket_EntityEquipment</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\packets\cPacket_CreateInventoryAction.h">
|
||||
<Filter>Packets\cPacket_CreateInventoryAction</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\packets\cPacket_UseEntity.h">
|
||||
<Filter>Packets\cPacket_UseEntity</Filter>
|
||||
</ClInclude>
|
||||
@ -1138,4 +1147,4 @@
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="MCServer.rc" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
6
makefile
6
makefile
@ -127,6 +127,7 @@ MCServer : \
|
||||
build/cPacket_DestroyEntity.o\
|
||||
build/cPacket_Disconnect.o\
|
||||
build/cPacket_EntityEquipment.o\
|
||||
build/cPacket_CreateInventoryAction.o\
|
||||
build/cPacket_EntityLook.o\
|
||||
build/cPacket_EntityStatus.o\
|
||||
build/cPacket_Flying.o\
|
||||
@ -307,6 +308,7 @@ MCServer : \
|
||||
build/cPacket_DestroyEntity.o\
|
||||
build/cPacket_Disconnect.o\
|
||||
build/cPacket_EntityEquipment.o\
|
||||
build/cPacket_CreateInventoryAction.o\
|
||||
build/cPacket_EntityLook.o\
|
||||
build/cPacket_EntityStatus.o\
|
||||
build/cPacket_Flying.o\
|
||||
@ -490,6 +492,7 @@ clean :
|
||||
build/cPacket_DestroyEntity.o\
|
||||
build/cPacket_Disconnect.o\
|
||||
build/cPacket_EntityEquipment.o\
|
||||
build/cPacket_CreateInventoryAction.o\
|
||||
build/cPacket_EntityLook.o\
|
||||
build/cPacket_EntityStatus.o\
|
||||
build/cPacket_Flying.o\
|
||||
@ -867,6 +870,9 @@ build/cPacket_Disconnect.o : source/packets/cPacket_Disconnect.cpp
|
||||
build/cPacket_EntityEquipment.o : source/packets/cPacket_EntityEquipment.cpp
|
||||
$(CC) $(CC_OPTIONS) source/packets/cPacket_EntityEquipment.cpp -c $(INCLUDE) -o build/cPacket_EntityEquipment.o
|
||||
|
||||
build/cPacket_CreateInventoryAction.o : source/packets/cPacket_CreateInventoryAction.cpp
|
||||
$(CC) $(CC_OPTIONS) source/packets/cPacket_CreateInventoryAction.cpp -c $(INCLUDE) -o build/cPacket_CreateInventoryAction.o
|
||||
|
||||
build/cPacket_EntityLook.o : source/packets/cPacket_EntityLook.cpp
|
||||
$(CC) $(CC_OPTIONS) source/packets/cPacket_EntityLook.cpp -c $(INCLUDE) -o build/cPacket_EntityLook.o
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
[Server]
|
||||
Port=25565
|
||||
Port=11111
|
||||
ServerID=-
|
||||
|
||||
[Plugins]
|
||||
|
@ -14816,6 +14816,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
|
||||
tolua_constant(tolua_S,"E_CHAT",E_CHAT);
|
||||
tolua_constant(tolua_S,"E_UPDATE_TIME",E_UPDATE_TIME);
|
||||
tolua_constant(tolua_S,"E_ENTITY_EQUIPMENT",E_ENTITY_EQUIPMENT);
|
||||
tolua_constant(tolua_S,"E_CREATE_INVENTORY_ACTION",E_CREATE_INVENTORY_ACTION);
|
||||
tolua_constant(tolua_S,"E_USE_ENTITY",E_USE_ENTITY);
|
||||
tolua_constant(tolua_S,"E_UPDATE_HEALTH",E_UPDATE_HEALTH);
|
||||
tolua_constant(tolua_S,"E_RESPAWN",E_RESPAWN);
|
||||
|
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
//tolua_begin
|
||||
enum ENUM_PACKET_ID
|
||||
{
|
||||
enum ENUM_PACKET_ID
|
||||
{
|
||||
E_KEEP_ALIVE = 0x00,
|
||||
E_LOGIN = 0x01,
|
||||
E_HANDSHAKE = 0x02,
|
||||
@ -45,8 +45,9 @@ enum ENUM_PACKET_ID
|
||||
E_INVENTORY_SLOT = 0x67,
|
||||
E_INVENTORY_WHOLE = 0x68,
|
||||
E_INVENTORY_PROGRESS= 0x69,
|
||||
E_CREATE_INVENTORY_ACTION = 0x6B,
|
||||
E_UPDATE_SIGN = 0x82,
|
||||
E_PING = 0xfe,
|
||||
E_DISCONNECT = 0xff,
|
||||
};
|
||||
//tolua_end
|
||||
};
|
||||
//tolua_end
|
||||
|
@ -55,6 +55,7 @@
|
||||
#include "packets/cPacket_PickupSpawn.h"
|
||||
#include "packets/cPacket_ItemSwitch.h"
|
||||
#include "packets/cPacket_EntityEquipment.h"
|
||||
#include "packets/cPacket_CreateInventoryAction.h"
|
||||
#include "packets/cPacket_UseEntity.h"
|
||||
#include "packets/cPacket_WindowClose.h"
|
||||
#include "packets/cPacket_13.h"
|
||||
@ -134,6 +135,7 @@ cClientHandle::cClientHandle(const cSocket & a_Socket)
|
||||
m_pState->PacketMap[E_DISCONNECT] = new cPacket_Disconnect;
|
||||
m_pState->PacketMap[E_ITEM_SWITCH] = new cPacket_ItemSwitch;
|
||||
m_pState->PacketMap[E_ENTITY_EQUIPMENT] = new cPacket_EntityEquipment;
|
||||
m_pState->PacketMap[E_CREATE_INVENTORY_ACTION] = new cPacket_CreateInventoryAction;
|
||||
m_pState->PacketMap[E_PICKUP_SPAWN] = new cPacket_PickupSpawn;
|
||||
m_pState->PacketMap[E_USE_ENTITY] = new cPacket_UseEntity;
|
||||
m_pState->PacketMap[E_WINDOW_CLOSE] = new cPacket_WindowClose;
|
||||
|
@ -9,6 +9,7 @@ class cClientHandle;
|
||||
class cPlayer;
|
||||
class cPacket_WindowClick;
|
||||
class cPacket_EntityEquipment;
|
||||
class cPacket_CreateInventoryAction;
|
||||
class cInventory //tolua_export
|
||||
: public cWindowOwner
|
||||
{ //tolua_export
|
||||
@ -64,4 +65,4 @@ private:
|
||||
short m_EquippedSlot;
|
||||
|
||||
cPlayer* m_Owner;
|
||||
}; //tolua_export
|
||||
}; //tolua_export
|
||||
|
@ -8,6 +8,7 @@
|
||||
class cPacket_BlockPlace;
|
||||
class cPacket_PickupSpawn;
|
||||
class cPacket_EntityEquipment;
|
||||
class cPacket_CreateInventoryAction;
|
||||
class cPacket_Disconnect;
|
||||
class cPacket_Chat;
|
||||
class cPacket_BlockDig;
|
||||
|
42
source/packets/cPacket_CreateInventoryAction.cpp
Normal file
42
source/packets/cPacket_CreateInventoryAction.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include "cPacket_CreateInventoryAction.h"
|
||||
|
||||
cPacket_CreateInventoryAction::cPacket_CreateInventoryAction( const cPacket_CreateInventoryAction & a_Copy )
|
||||
{
|
||||
m_PacketID = E_CREATE_INVENTORY_ACTION;
|
||||
m_Slot = a_Copy.m_Slot;
|
||||
m_ItemID = a_Copy.m_ItemID;
|
||||
m_Quantity = 0;
|
||||
m_Short = 0;
|
||||
}
|
||||
|
||||
bool cPacket_CreateInventoryAction::Parse(cSocket & a_Socket)
|
||||
{
|
||||
m_Socket = 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;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cPacket_CreateInventoryAction::Send(cSocket & a_Socket)
|
||||
{
|
||||
//LOG("InventoryChange:");
|
||||
unsigned int TotalSize = c_Size;
|
||||
char* Message = new char[TotalSize];
|
||||
|
||||
if( m_ItemID <= 0 ) m_ItemID = -1; // Fix, to make sure no invalid values are sent.
|
||||
// WARNING: HERE ITS -1, BUT IN NAMED ENTITY SPAWN PACKET ITS 0 !!
|
||||
//LOG("cPacket_CreateInventoryAction: Sending Creative item ID: %i", m_ItemID );
|
||||
|
||||
unsigned int i = 0;
|
||||
AppendByte ( (char)m_PacketID, Message, i );
|
||||
AppendShort ( m_Slot, Message, i );
|
||||
AppendShort ( m_ItemID, Message, i );
|
||||
AppendShort ( m_Quantity, Message, i );
|
||||
AppendShort ( m_Short, Message, i );
|
||||
|
||||
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
|
||||
delete [] Message;
|
||||
return RetVal;
|
||||
}
|
27
source/packets/cPacket_CreateInventoryAction.h
Normal file
27
source/packets/cPacket_CreateInventoryAction.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "cPacket.h"
|
||||
#include "PacketID.h"
|
||||
|
||||
class cPacket_CreateInventoryAction : public cPacket
|
||||
{
|
||||
public:
|
||||
cPacket_CreateInventoryAction()
|
||||
: m_Slot( 0 )
|
||||
, m_ItemID( 0 )
|
||||
, m_Quantity( 0 )
|
||||
, m_Short( 0 )
|
||||
{ m_PacketID = E_CREATE_INVENTORY_ACTION; m_Short = 0; m_Quantity = 1; }
|
||||
cPacket_CreateInventoryAction( const cPacket_CreateInventoryAction & a_Copy );
|
||||
virtual cPacket* Clone() const { return new cPacket_CreateInventoryAction(*this); }
|
||||
|
||||
bool Parse(cSocket & a_Socket);
|
||||
bool Send(cSocket & a_Socket);
|
||||
|
||||
short m_Slot; // 0 = hold 1-4 = armor
|
||||
short m_ItemID;
|
||||
short m_Quantity;
|
||||
short m_Short;
|
||||
|
||||
static const unsigned int c_Size = 1 + 4 + 2 + 2 + 2;
|
||||
};
|
@ -10,7 +10,7 @@ public:
|
||||
cPacket_Login()
|
||||
: m_ProtocolVersion( 0 )
|
||||
, m_MapSeed( 0 )
|
||||
, m_ServerMode( 0 )
|
||||
, m_ServerMode( 1 ) //0 for survival, 1 for creative
|
||||
, m_Dimension( 0 )
|
||||
, m_Difficulty( 0 )
|
||||
, m_WorldHeight( 0 )
|
||||
|
Loading…
Reference in New Issue
Block a user