createConnection.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #include <enet-1.3.18/include/enet/enet.h>
  3. #include <stdint.h>
  4. #include <vector>
  5. #include "packet.h"
  6. #include <gameplay/physics.h>
  7. #include <gameplay/battleUI.h>
  8. struct ClientEntityManager;
  9. struct UndoQueue;
  10. struct ChunkSystem;
  11. struct LightSystem;
  12. struct PlayerConnectionData;
  13. struct ChestBlock;
  14. struct Task
  15. {
  16. enum Type
  17. {
  18. none = 0,
  19. placeBlock,
  20. placeBlockForce,
  21. breakBlock,
  22. droppedItemEntity,
  23. clientMovedItem,
  24. clientOverwriteItem,
  25. clientCraftedItem,
  26. clientSwapItems,
  27. clientUsedItem,
  28. clientInteractedWithBlock,
  29. clientExitedInteractionWithBlock,
  30. clientAttackedEntity,
  31. clientWantsToRespawn,
  32. clientRecievedDamageLocally,
  33. clientRecievedDamageLocallyAndDied,
  34. clientChangedBlockData,
  35. };
  36. glm::dvec3 doublePos = {};
  37. glm::ivec3 pos = {};
  38. glm::vec3 vector = {};
  39. int taskType = 0;
  40. unsigned short craftingRecepieIndex = 0;
  41. BlockType blockType = 0;
  42. Block block = {};
  43. EventId eventId = {};
  44. glm::ivec2 playerPosForChunkGeneration = {};
  45. unsigned short blockCount = 0;
  46. std::uint64_t entityId;
  47. MotionState motionState;
  48. std::uint64_t timer;
  49. unsigned short itemType = 0;
  50. unsigned char from;
  51. unsigned char to;
  52. unsigned char revisionNumber = 0;
  53. unsigned char inventroySlot = 0;
  54. short damage = 0;
  55. HitResult hitResult = {};
  56. std::vector<unsigned char> metaData;
  57. };
  58. void submitTaskClient(Task &t);
  59. void submitTaskClient(std::vector<Task> &t);
  60. Packet formatPacket(int header);
  61. ENetPeer *getServer();
  62. struct Chunk;
  63. struct ConnectionData
  64. {
  65. ENetHost *client = 0;
  66. ENetPeer *server = 0;
  67. std::uint64_t cid = 0;
  68. bool conected = false;
  69. };
  70. ConnectionData getConnectionData();
  71. bool createConnection(Packet_ReceiveCIDAndData &playerData, const char *c);
  72. //0 for all
  73. bool placeItem(PlayerInventory &inventory, ChestBlock *chestBlock, int from, int to, int counter = 0);
  74. //0 for all
  75. bool swapItems(PlayerInventory &inventory, ChestBlock *chestBlock, int from, int to);
  76. bool grabItem(PlayerInventory &inventory, ChestBlock *chestBlock, int from, int to, int counter = 0);
  77. bool forceOverWriteItem(PlayerInventory &inventory, ChestBlock *chestBlock, int index, Item &item);
  78. void clientMessageLoop(EventCounter &validatedEvent, RevisionNumber &invalidateRevision
  79. ,glm::ivec3 playerPosition, int squareDistance, ClientEntityManager& entityManager,
  80. UndoQueue &undoQueue, ChunkSystem &chunkSystem,
  81. LightSystem &lightSystem,
  82. std::uint64_t &serverTimer, bool &disconnect,
  83. unsigned char revisionNumberBlockInteraction, bool &shouldExitBlockInteraction,
  84. bool &killedPlayer, bool &respawn,
  85. std::deque<std::string> &chat, float &chatTimer,
  86. InteractionData &playerInteraction,
  87. std::unordered_map<std::uint64_t, PlayerConnectionData> &playersConnectionData
  88. );
  89. void attackEntity(std::uint64_t eid, unsigned char inventorySlot, glm::vec3 direction,
  90. HitResult hitResult);
  91. void sendBlockInteractionMessage(
  92. std::uint64_t playerID,
  93. glm::ivec3 pos, BlockType block, unsigned char revisionNumber);
  94. void closeConnection();
  95. bool hostServer(const std::string &path);