enetServerFunction.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #define GLM_ENABLE_EXPERIMENTAL
  3. #include <glm/gtx/hash.hpp>
  4. #include <enet/enet.h>
  5. #include "threadStuff.h"
  6. #include "packet.h"
  7. #include "createConnection.h"
  8. #include "gamePlayLogic.h"
  9. #include <unordered_set>
  10. #include "serverChunkStorer.h"
  11. #include <multyPlayer/client.h>
  12. bool startEnetListener(ENetHost *_server, const std::string &path);
  13. void closeEnetListener();
  14. struct ServerTask
  15. {
  16. Task t;
  17. std::uint64_t cid;
  18. };
  19. struct EntityIdHolder
  20. {
  21. std::uint64_t entityIds[EntitiesTypesCount] = {};
  22. //todo an init method and stuff
  23. void create()
  24. {
  25. for (int i = 0; i < EntitiesTypesCount; i++)
  26. {
  27. entityIds[i] = RESERVED_CLIENTS_ID + 1;
  28. }
  29. }
  30. };
  31. Client getClient(std::uint64_t cid);
  32. Client *getClientSafe(std::uint64_t cid);
  33. Client *getClientNotLocked(std::uint64_t cid);
  34. std::unordered_map<std::uint64_t, Client> getAllClients();
  35. std::unordered_map<std::uint64_t, Client> &getAllClientsReff();
  36. void sendPlayerInventoryAndIncrementRevision(Client &client,
  37. int channel = channelChunksAndBlocks);
  38. void sendPlayerInventoryNotIncrementRevision(Client &client,
  39. int channel = channelChunksAndBlocks);
  40. void sendPlayerExitInteraction(Client &client, unsigned char revisionNumber);
  41. //this updates the player's effects
  42. void updatePlayerEffects(Client &client);
  43. void broadCast(Packet p, void *data, size_t size, ENetPeer *peerToIgnore, bool reliable, int channel);
  44. void broadCastNotLocked(Packet p, void *data, size_t size, ENetPeer *peerToIgnore, bool reliable, int channel);
  45. bool checkIfPlayerShouldGetChunk(glm::ivec2 playerPos2D,
  46. glm::ivec2 chunkPos, int playerSquareDistance);
  47. std::uint64_t getEntityIdAndIncrement(WorldSaver &worldSaver, int entityType);
  48. std::uint64_t getCurrentEntityId(int entityType);