server.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #include <chrono>
  3. #include <unordered_map>
  4. #include <glm/vec2.hpp>
  5. #include <glm/vec3.hpp>
  6. #include <biome.h>
  7. #include <multyPlayer/chunkSaver.h>
  8. #include <worldGenerator.h>
  9. #include <enet/enet.h>
  10. #include <tickTimer.h>
  11. constexpr std::uint64_t RESERVED_CLIENTS_ID = 100'000;
  12. struct Client;
  13. struct EventId;
  14. struct ServerChunkStorer;
  15. bool isServerRunning();
  16. bool startServer(const std::string &path);
  17. ServerChunkStorer &getServerChunkStorer();
  18. int getServerTicksPerSeccond();
  19. void clearSD(WorldSaver &worldSaver);
  20. int getChunkCapacity();
  21. void closeServer();
  22. bool computeRevisionStuff(Client &client, bool allowed,
  23. const EventId &eventId, std::uint64_t *oldid = 0, std::uint64_t *newid = 0);
  24. //todo remove most things from here or just remove it completely add it in client
  25. struct PerClientServerSettings
  26. {
  27. bool validateStuff = 1;
  28. bool resendInventory = false;
  29. bool damage = false;
  30. bool heal = false;
  31. bool killApig = false;
  32. bool generateStructure = false;
  33. glm::dvec3 outPlayerPos;
  34. };
  35. struct ServerSettings
  36. {
  37. std::unordered_map<std::uint64_t, PerClientServerSettings> perClientSettings;
  38. bool busyWait = 1;
  39. unsigned int randomTickSpeed = 3;
  40. int simulationDistanceRadius = 8;
  41. };
  42. struct ServerTask;
  43. struct Profiler;
  44. void serverWorkerUpdate(WorldGenerator &wg, StructuresManager &structuresManager,
  45. BiomesManager &biomesManager, WorldSaver &worldSaver,
  46. std::vector<ServerTask> &serverTask,
  47. float deltaTime, Profiler &profiler);
  48. //returns the timer since the start of the program
  49. std::uint64_t getTimer();
  50. void addCidToServerSettings(std::uint64_t cid);
  51. void removeCidFromServerSettings(std::uint64_t cid);
  52. void changePlayerGameMode(std::uint64_t cid, unsigned char gameMode);
  53. ServerSettings getServerSettingsCopy();
  54. ServerSettings &getServerSettingsReff();
  55. Profiler getServerProfilerCopy();
  56. Profiler getServerTickProfilerCopy();
  57. int getServerPendingReliableCount();
  58. size_t getServerTotalPendingSize();
  59. std::string executeServerCommand(std::uint64_t cid, const char *command);
  60. unsigned int getRandomTickSpeed();
  61. void setServerSettings(ServerSettings settings);
  62. void genericBroadcastEntityDeleteFromServerToPlayer(std::uint64_t eid, bool reliable,
  63. std::unordered_map < std::uint64_t, Client *> &allClients,
  64. glm::ivec2 lastChunkClientsGotUpdates);
  65. void genericBroadcastEntityKillFromServerToPlayer(std::uint64_t eid, bool reliable, ENetPeer* peerToIgnore = 0);