1
0
Fork 0
cuberite-2a/src/Protocol/Packetizer.cpp

138 lines
6.0 KiB
C++
Raw Normal View History

// Packetizer.cpp
// Implements the cPacketizer class representing a wrapper for sending a single packet over a protocol.
#include "Globals.h"
#include "Packetizer.h"
#include "../UUID.h"
////////////////////////////////////////////////////////////////////////////////
// cPacketizer:
cPacketizer::~cPacketizer()
{
m_Protocol.SendPacket(*this);
}
void cPacketizer::WriteByteAngle(double a_Angle)
{
WriteBEInt8(static_cast<Int8>(255 * a_Angle / 360));
}
void cPacketizer::WriteFPInt(double a_Value)
{
WriteBEInt32(static_cast<Int32>(a_Value * 32));
}
2017-08-25 12:43:18 +00:00
void cPacketizer::WriteUUID(const cUUID & a_UUID)
{
2017-08-25 12:43:18 +00:00
for (auto val : a_UUID.ToRaw())
{
VERIFY(m_Out.WriteBEUInt8(val));
}
}
AString cPacketizer::PacketTypeToStr(cProtocol::ePacketType a_PacketType)
{
switch (a_PacketType)
{
case cProtocol::pktAttachEntity: return "pktAttachEntity";
case cProtocol::pktBlockAction: return "pktBlockAction";
case cProtocol::pktBlockBreakAnim: return "pktBlockBreakAnim";
case cProtocol::pktBlockChange: return "pktBlockChange";
case cProtocol::pktBlockChanges: return "pktBlockChanges";
case cProtocol::pktCameraSetTo: return "pktCameraSetTo";
case cProtocol::pktChatRaw: return "pktChatRaw";
case cProtocol::pktCollectEntity: return "pktCollectEntity";
case cProtocol::pktDestroyEntity: return "pktDestroyEntity";
case cProtocol::pktDifficulty: return "pktDifficulty";
case cProtocol::pktDisconnectDuringLogin: return "pktDisconnectDuringLogin";
case cProtocol::pktDisconnectDuringGame: return "pktDisconnectDuringGame";
case cProtocol::pktDisplayObjective: return "pktDisplayObjective";
case cProtocol::pktEditSign: return "pktEditSign";
case cProtocol::pktEncryptionRequest: return "pktEncryptionRequest";
case cProtocol::pktEntityAnimation: return "pktEntityAnimation";
case cProtocol::pktEntityEffect: return "pktEntityEffect";
case cProtocol::pktEntityEquipment: return "pktEntityEquipment";
case cProtocol::pktEntityHeadLook: return "pktEntityHeadLook";
case cProtocol::pktEntityLook: return "pktEntityLook";
case cProtocol::pktEntityMeta: return "pktEntityMeta";
case cProtocol::pktEntityProperties: return "pktEntityProperties";
case cProtocol::pktEntityRelMove: return "pktEntityRelMove";
case cProtocol::pktEntityRelMoveLook: return "pktEntityRelMoveLook";
case cProtocol::pktEntityStatus: return "pktEntityStatus";
case cProtocol::pktEntityVelocity: return "pktEntityVelocity";
case cProtocol::pktExperience: return "pktExperience";
case cProtocol::pktExplosion: return "pktExplosion";
case cProtocol::pktGameMode: return "pktGameMode";
case cProtocol::pktHeldItemChange: return "pktHeldItemChange";
case cProtocol::pktInventorySlot: return "pktInventorySlot";
case cProtocol::pktJoinGame: return "pktJoinGame";
case cProtocol::pktKeepAlive: return "pktKeepAlive";
case cProtocol::pktLeashEntity: return "pktLeashEntity";
case cProtocol::pktLoginSuccess: return "pktLoginSuccess";
case cProtocol::pktMapData: return "pktMapData";
case cProtocol::pktParticleEffect: return "pktParticleEffect";
case cProtocol::pktPingResponse: return "pktPingResponse";
case cProtocol::pktPlayerAbilities: return "pktPlayerAbilities";
case cProtocol::pktPlayerList: return "pktPlayerList";
case cProtocol::pktPlayerMaxSpeed: return "pktPlayerMaxSpeed";
case cProtocol::pktPlayerMoveLook: return "pktPlayerMoveLook";
case cProtocol::pktPluginMessage: return "pktPluginMessage";
case cProtocol::pktRemoveEntityEffect: return "pktRemoveEntityEffect";
2020-04-07 21:23:54 +00:00
case cProtocol::pktResourcePack: return "pktResourcePack";
case cProtocol::pktRespawn: return "pktRespawn";
case cProtocol::pktScoreboardObjective: return "pktScoreboardObjective";
case cProtocol::pktSpawnObject: return "pktSpawnObject";
case cProtocol::pktSoundEffect: return "pktSoundEffect";
case cProtocol::pktSoundParticleEffect: return "pktSoundParticleEffect";
case cProtocol::pktSpawnExperienceOrb: return "pktSpawnExperienceOrb";
case cProtocol::pktSpawnGlobalEntity: return "pktSpawnGlobalEntity";
case cProtocol::pktSpawnMob: return "pktSpawnMob";
case cProtocol::pktSpawnOtherPlayer: return "pktSpawnOtherPlayer";
case cProtocol::pktSpawnPainting: return "pktSpawnPainting";
case cProtocol::pktSpawnPosition: return "pktSpawnPosition";
case cProtocol::pktStartCompression: return "pktStartCompression";
case cProtocol::pktStatistics: return "pktStatistics";
case cProtocol::pktStatusResponse: return "pktStatusResponse";
case cProtocol::pktTabCompletionResults: return "pktTabCompletionResults";
case cProtocol::pktTeleportEntity: return "pktTeleportEntity";
case cProtocol::pktTimeUpdate: return "pktTimeUpdate";
case cProtocol::pktTitle: return "pktTitle";
case cProtocol::pktUnloadChunk: return "pktUnloadChunk";
Introduce recipe book functionality (#4493) * Introduce recipe book functionality The recipe book helps especially new players. Missing it gives the impression that cuberite is not as advanced as it is. The handling of the recipe book uses the following functions: - Unlock Recipes (https://wiki.vg/index.php?title=Protocol&oldid=14204#Unlock_Recipes) to make recipes available and show the notification for new recipes. Initialization is done on player login for known ones, the update is done when new items are discovered. - Craft Recipe Request (https://wiki.vg/index.php?title=Protocol&oldid=14204#Craft_Recipe_Request) when the user selects a recipe from the recipe book to fill the slots. Known recipes are initialized on player login via `Unlock Recipes` with `Action` 0. As soon as a new recipe is discovered this is added via `Unlock Recipes` with `Action` 1. To be able to know and recognize new recipes the player class is extended with `KnownItems` and `KnownRecipes`. As soon as a player touches an item this is compared to the list of `KnownItems`, if the item is unknown the recipes are checked for this item and the other ingredients are checked with the list of `KnownItems`. If a full match is discovered the recipe is unlocked with the client and stored in the `KnownRecipes`. To unlock recipes the recipe ID is sent to the client. A mapping file (for protocol 1.12.2) translated the minecraft recipe names to ids. The crafting.txt is extended with and minecraft recipe names is possible. Limitations: Only a single recipe is added to the crafting area. Multiple clicks or shift click does not increase the number of builds. Co-authored-by: peterbell10 <peterbell10@live.co.uk> * Address first issues mentioned by @peterbell10 - Some linting - Extract loading of recipe specific protocol mapping into a function - Build `RecipeNameMap` only once - Use `std::optional` - Extract `LoadRecipe` from `Window` * Start to implement new suggestions * Update with suggestions from @peterbell10 * Some minor cleanup * Update protocol packet IDs * Remove unused include * Include header in cmake * Change a vector to integer counter * Change dromedaryCase method names to PascalCase * Address suggestions from @madmaxoft * Read Protocol subdirectories to load recipe books To load all recipebooks iterate over the `Protocol` subdirectories to find mapping files. Co-authored-by: peterbell10 <peterbell10@live.co.uk>
2020-07-14 16:56:42 +00:00
case cProtocol::pktUnlockRecipe: return "pktUnlockRecipe";
case cProtocol::pktUpdateBlockEntity: return "pktUpdateBlockEntity";
case cProtocol::pktUpdateHealth: return "pktUpdateHealth";
case cProtocol::pktUpdateScore: return "pktUpdateScore";
case cProtocol::pktUpdateSign: return "pktUpdateSign";
case cProtocol::pktUseBed: return "pktUseBed";
case cProtocol::pktWeather: return "pktWeather";
case cProtocol::pktWindowItems: return "pktWindowItems";
case cProtocol::pktWindowClose: return "pktWindowClose";
case cProtocol::pktWindowOpen: return "pktWindowOpen";
case cProtocol::pktWindowProperty: return "pktWindowProperty";
}
return Printf("Unknown packet type: 0x%02x", a_PacketType);
}