From a5af50c293d87a21632c2811577c7b1838f6974f Mon Sep 17 00:00:00 2001 From: "admin@omencraft.com" Date: Wed, 2 Nov 2011 20:40:39 +0000 Subject: Added New/Invaid State and Thunderbolt packets. For testing purposes it now rains whenever a player opens a workbench and stops when they pen a chest. The rain start/stop in only sent to the sole clientopening the items. git-svn-id: http://mc-server.googlecode.com/svn/trunk@47 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/PacketID.h | 2 ++ source/cClientHandle.cpp | 33 +++++++++++++++++++++++------- source/packets/cPacket_NewInvalidState.cpp | 30 +++++++++++++++++++++++++++ source/packets/cPacket_NewInvalidState.h | 24 ++++++++++++++++++++++ source/packets/cPacket_Thunderbolt.cpp | 19 +++++++++++++++++ source/packets/cPacket_Thunderbolt.h | 27 ++++++++++++++++++++++++ 6 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 source/packets/cPacket_NewInvalidState.cpp create mode 100644 source/packets/cPacket_NewInvalidState.h create mode 100644 source/packets/cPacket_Thunderbolt.cpp create mode 100644 source/packets/cPacket_Thunderbolt.h (limited to 'source') diff --git a/source/PacketID.h b/source/PacketID.h index 75482bbb0..98d6fc415 100644 --- a/source/PacketID.h +++ b/source/PacketID.h @@ -39,6 +39,8 @@ enum ENUM_PACKET_ID E_MAP_CHUNK = 0x33, E_MULTI_BLOCK = 0x34, E_BLOCK_CHANGE = 0x35, + E_NEW_INVALID_STATE = 0x46, + E_THUNDERBOLT = 0x47, E_WINDOW_OPEN = 0x64, E_WINDOW_CLOSE = 0x65, E_WINDOW_CLICK = 0x66, diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index 621e8a19e..4c09c4309 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -56,6 +56,7 @@ #include "packets/cPacket_ItemSwitch.h" #include "packets/cPacket_EntityEquipment.h" #include "packets/cPacket_CreateInventoryAction.h" +#include "packets/cPacket_NewInvalidState.h" #include "packets/cPacket_UseEntity.h" #include "packets/cPacket_WindowClose.h" #include "packets/cPacket_13.h" @@ -127,16 +128,17 @@ cClientHandle::cClientHandle(const cSocket & a_Socket) m_pState->PacketMap[E_LOGIN] = new cPacket_Login; m_pState->PacketMap[E_PLAYERPOS] = new cPacket_PlayerPosition; m_pState->PacketMap[E_PLAYERLOOK] = new cPacket_PlayerLook; - m_pState->PacketMap[E_PLAYERMOVELOOK] = new cPacket_PlayerMoveLook; - m_pState->PacketMap[E_CHAT] = new cPacket_Chat; + m_pState->PacketMap[E_PLAYERMOVELOOK] = new cPacket_PlayerMoveLook; + m_pState->PacketMap[E_CHAT] = new cPacket_Chat; m_pState->PacketMap[E_ANIMATION] = new cPacket_ArmAnim; m_pState->PacketMap[E_FLYING] = new cPacket_Flying; m_pState->PacketMap[E_BLOCK_DIG] = new cPacket_BlockDig; m_pState->PacketMap[E_BLOCK_PLACE] = new cPacket_BlockPlace; 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_ENTITY_EQUIPMENT] = new cPacket_EntityEquipment; + m_pState->PacketMap[E_CREATE_INVENTORY_ACTION] = new cPacket_CreateInventoryAction; + m_pState->PacketMap[E_NEW_INVALID_STATE] = new cPacket_NewInvalidState; 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; @@ -144,7 +146,7 @@ cClientHandle::cClientHandle(const cSocket & a_Socket) m_pState->PacketMap[E_PACKET_13] = new cPacket_13; m_pState->PacketMap[E_UPDATE_SIGN] = new cPacket_UpdateSign; m_pState->PacketMap[E_RESPAWN] = new cPacket_Respawn; - m_pState->PacketMap[E_PING] = new cPacket_Ping; + m_pState->PacketMap[E_PING] = new cPacket_Ping; memset( m_LoadedChunks, 0x00, sizeof(cChunk*)*VIEWDISTANCE*VIEWDISTANCE ); @@ -372,12 +374,22 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) { switch( a_Packet->m_PacketID ) { + case E_NEW_INVALID_STATE: // New/Invalid State packet received. I'm guessing the client only sends it when there's a problem with the bed? + { + LOGINFO("Got New Invalid State packet"); + } + break; + case E_CREATE_INVENTORY_ACTION: // I don't think we need to do anything with this packet, but justin case... + { + LOGINFO("Got Create Inventory Action packet"); + } + break; case E_PING: // Somebody tries to retreive information about the server { LOGINFO("Got ping"); char NumPlayers[8]; sprintf_s(NumPlayers, 8, "%i", cRoot::Get()->GetWorld()->GetNumPlayers() ); - std::string response = std::string("Should be able to connect now!" + cChatColor::Delimiter + NumPlayers + cChatColor::Delimiter + "9001" ); + std::string response = std::string("MCServer! - It's OVER 9000!" + cChatColor::Delimiter + NumPlayers + cChatColor::Delimiter + "9001" ); Kick( response.c_str() ); } break; @@ -630,6 +642,10 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) { case E_BLOCK_WORKBENCH: { + LOG("WorkBench"); + cPacket_NewInvalidState RainPacket; + RainPacket.m_Reason = 1; //begin rain + Send( RainPacket ); bPlaceBlock = false; cWindow* Window = new cCraftingWindow( 0, true ); m_Player->OpenWindow( Window ); @@ -638,6 +654,10 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) case E_BLOCK_FURNACE: case E_BLOCK_CHEST: { + LOG("Chest"); + cPacket_NewInvalidState RainPacket; + RainPacket.m_Reason = 2; //end rain + Send( RainPacket ); bPlaceBlock = false; cBlockEntity* BlockEntity = m_Player->GetWorld()->GetBlockEntity( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ ); if( BlockEntity ) @@ -971,7 +991,6 @@ void cClientHandle::Tick(float a_Dt) Send( cPacket_UpdateHealth( (short)m_Player->GetHealth() ) ); //quick bugfix to prevent players from spawning in ground -// m_Player->TeleportTo( cRoot::Get()->GetWorld()->GetPosX(), cRoot::Get()->GetWorld()->GetPosY()+1, cRoot::Get()->GetWorld()->GetPosZ() ); m_Player->TeleportTo( m_Player->GetPosX(), m_Player->GetPosY()+1, m_Player->GetPosZ() ); World->UnlockEntities(); diff --git a/source/packets/cPacket_NewInvalidState.cpp b/source/packets/cPacket_NewInvalidState.cpp new file mode 100644 index 000000000..6755ec207 --- /dev/null +++ b/source/packets/cPacket_NewInvalidState.cpp @@ -0,0 +1,30 @@ +#include "cPacket_NewInvalidState.h" + +cPacket_NewInvalidState::cPacket_NewInvalidState( const cPacket_NewInvalidState & a_Copy ) +{ + m_PacketID = E_NEW_INVALID_STATE; + m_Reason = a_Copy.m_Reason; + m_GameMode = a_Copy.m_GameMode; +} + +bool cPacket_NewInvalidState::Parse(cSocket & a_Socket) { + m_Socket = a_Socket; + if( !ReadByte ( m_Reason ) ) return false; + if( !ReadByte ( m_GameMode ) ) return false; + return true; +} + +bool cPacket_NewInvalidState::Send(cSocket & a_Socket) +{ + unsigned int TotalSize = c_Size; + char* Message = new char[TotalSize]; + + unsigned int i = 0; + AppendByte ( (char)m_PacketID, Message, i ); + AppendByte ( m_Reason, Message, i ); + AppendByte ( m_GameMode, Message, i ); + + bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) ); + delete [] Message; + return RetVal; +} diff --git a/source/packets/cPacket_NewInvalidState.h b/source/packets/cPacket_NewInvalidState.h new file mode 100644 index 000000000..a83cb8080 --- /dev/null +++ b/source/packets/cPacket_NewInvalidState.h @@ -0,0 +1,24 @@ +#pragma once + +#include "cPacket.h" +#include "PacketID.h" + + +class cPacket_NewInvalidState : public cPacket +{ +public: + cPacket_NewInvalidState() + : m_Reason( 0 ) + , m_GameMode( 0 ) + { m_PacketID = E_NEW_INVALID_STATE;} + cPacket_NewInvalidState( const cPacket_NewInvalidState & a_Copy ); + virtual cPacket* Clone() const { return new cPacket_NewInvalidState(*this); } + + bool Parse(cSocket & a_Socket); + bool Send(cSocket & a_Socket); + + char m_Reason; // 0 = Invalid Bed, 1 = Begin Raining, 2 End Raining, 3 = Change Gamemode + char m_GameMode; // Used only when reason = 3. 0 is survival, 1 is creative. + + static const unsigned int c_Size = 1 + 1 + 1; +}; diff --git a/source/packets/cPacket_Thunderbolt.cpp b/source/packets/cPacket_Thunderbolt.cpp new file mode 100644 index 000000000..c6fdefb60 --- /dev/null +++ b/source/packets/cPacket_Thunderbolt.cpp @@ -0,0 +1,19 @@ +#include "cPacket_Thunderbolt.h" + +bool cPacket_Thunderbolt::Send(cSocket & a_Socket) +{ + unsigned int TotalSize = c_Size; + char* Message = new char[TotalSize]; + + unsigned int i = 0; + AppendByte ( (char)m_PacketID, Message, i ); + AppendInteger ( m_UniqueID, Message, i ); + AppendBool ( m_Unknown, Message, i ); + AppendInteger ( m_xLBPos, Message, i ); + AppendInteger ( m_yLBPos, Message, i ); + AppendInteger ( m_zLBPos, Message, i ); + + bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) ); + delete [] Message; + return RetVal; +} diff --git a/source/packets/cPacket_Thunderbolt.h b/source/packets/cPacket_Thunderbolt.h new file mode 100644 index 000000000..51dad5814 --- /dev/null +++ b/source/packets/cPacket_Thunderbolt.h @@ -0,0 +1,27 @@ +#pragma once + +#include "cPacket.h" +#include "PacketID.h" + +class cPacket_Thunderbolt : public cPacket +{ +public: + cPacket_Thunderbolt() + : m_UniqueID( 0 ) + , m_Unknown( 0 ) + , m_xLBPos( 0 ) + , m_yLBPos( 0 ) + , m_zLBPos( 0 ) + { m_PacketID = E_THUNDERBOLT;} + virtual cPacket* Clone() const { return new cPacket_Thunderbolt(*this); } + + bool Send(cSocket & a_Socket); + + int m_UniqueID; // The entity ID of the thunderbolt + bool m_Unknown; // Always true. Might have a meaning in the future... + int m_xLBPos; // Thunderbolt X as Absolute Integer + int m_yLBPos; // Thunderbolt Y as Absolute Integer + int m_zLBPos; // Thunderbolt Z as Absolute Integer + + static const unsigned int c_Size = 1 + 4 + 1 + 4 + 4 + 4; +}; -- cgit v1.2.3