X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fserver.h;h=f44716531f2d3c6cf49576f6ee2f64ed8bc42ac7;hb=1780adeea63630e67f4af8b300f6ae710d9af486;hp=d61840871b933d6afa9b1cf84f45d4be52f58909;hpb=26b39f1eae1f576669cbf49c6db94ef4ed8624df;p=dragonfireclient.git diff --git a/src/server.h b/src/server.h index d61840871..f44716531 100644 --- a/src/server.h +++ b/src/server.h @@ -27,12 +27,14 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content/mods.h" #include "inventorymanager.h" #include "content/subgames.h" -#include "tileanimation.h" // struct TileAnimationParams +#include "tileanimation.h" // TileAnimationParams +#include "particles.h" // ParticleParams #include "network/peerhandler.h" #include "network/address.h" #include "util/numeric.h" #include "util/thread.h" #include "util/basic_macros.h" +#include "util/metricsbackend.h" #include "serverenvironment.h" #include "clientiface.h" #include "chatmessage.h" @@ -61,8 +63,13 @@ class ServerScripting; class ServerEnvironment; struct SimpleSoundSpec; struct CloudParams; +struct SkyboxParams; +struct SunParams; +struct MoonParams; +struct StarParams; class ServerThread; class ServerModManager; +class ServerInventoryManager; enum ClientDeletionReason { CDR_LEAVE, @@ -98,6 +105,7 @@ struct ServerSoundParams v3f pos; u16 object = 0; std::string to_player = ""; + std::string exclude_player = ""; v3f getPos(ServerEnvironment *env, bool *pos_exists) const; }; @@ -110,7 +118,7 @@ struct ServerPlayingSound }; class Server : public con::PeerHandler, public MapEventReceiver, - public InventoryManager, public IGameDef + public IGameDef { public: /* @@ -128,7 +136,6 @@ class Server : public con::PeerHandler, public MapEventReceiver, ~Server(); DISABLE_CLASS_COPY(Server); - void init(); void start(); void stop(); // This is mainly a way to pass the time to the server. @@ -160,7 +167,6 @@ class Server : public con::PeerHandler, public MapEventReceiver, void handleCommand_InventoryAction(NetworkPacket* pkt); void handleCommand_ChatMessage(NetworkPacket* pkt); void handleCommand_Damage(NetworkPacket* pkt); - void handleCommand_Password(NetworkPacket* pkt); void handleCommand_PlayerItem(NetworkPacket* pkt); void handleCommand_Respawn(NetworkPacket* pkt); void handleCommand_Interact(NetworkPacket* pkt); @@ -191,15 +197,9 @@ class Server : public con::PeerHandler, public MapEventReceiver, */ void onMapEditEvent(const MapEditEvent &event); - /* - Shall be called with the environment and the connection locked. - */ - Inventory* getInventory(const InventoryLocation &loc); - void setInventoryModified(const InventoryLocation &loc); - // Connection must be locked when called std::wstring getStatusString(); - inline double getUptime() const { return m_uptime.m_value; } + inline double getUptime() const { return m_uptime_counter->get(); } // read shutdown state inline bool isShutdownRequested() const { return m_shutdown_state.is_requested; } @@ -209,7 +209,8 @@ class Server : public con::PeerHandler, public MapEventReceiver, // Returns -1 if failed, sound handle on success // Envlock - s32 playSound(const SimpleSoundSpec &spec, const ServerSoundParams ¶ms); + s32 playSound(const SimpleSoundSpec &spec, const ServerSoundParams ¶ms, + bool ephemeral=false); void stopSound(s32 handle); void fadeSound(s32 handle, float step, float gain); @@ -226,31 +227,19 @@ class Server : public con::PeerHandler, public MapEventReceiver, void notifyPlayer(const char *name, const std::wstring &msg); void notifyPlayers(const std::wstring &msg); + void spawnParticle(const std::string &playername, - v3f pos, v3f velocity, v3f acceleration, - float expirationtime, float size, - bool collisiondetection, bool collision_removal, bool object_collision, - bool vertical, const std::string &texture, - const struct TileAnimationParams &animation, u8 glow); - - u32 addParticleSpawner(u16 amount, float spawntime, - v3f minpos, v3f maxpos, - v3f minvel, v3f maxvel, - v3f minacc, v3f maxacc, - float minexptime, float maxexptime, - float minsize, float maxsize, - bool collisiondetection, bool collision_removal, bool object_collision, - ServerActiveObject *attached, - bool vertical, const std::string &texture, - const std::string &playername, const struct TileAnimationParams &animation, - u8 glow); + const ParticleParameters &p); + + u32 addParticleSpawner(const ParticleSpawnerParameters &p, + ServerActiveObject *attached, const std::string &playername); void deleteParticleSpawner(const std::string &playername, u32 id); - // Creates or resets inventory - Inventory *createDetachedInventory(const std::string &name, - const std::string &player = ""); - bool removeDetachedInventory(const std::string &name); + bool dynamicAddMedia(const std::string &filepath); + + ServerInventoryManager *getInventoryMgr() const { return m_inventory_mgr.get(); } + void sendDetachedInventory(Inventory *inventory, const std::string &name, session_t peer_id); // Envlock and conlock should be locked when using scriptapi ServerScripting *getScriptIface(){ return m_script; } @@ -305,12 +294,14 @@ class Server : public con::PeerHandler, public MapEventReceiver, f32 frame_speed); void setPlayerEyeOffset(RemotePlayer *player, const v3f &first, const v3f &third); - void setSky(RemotePlayer *player, const video::SColor &bgcolor, - const std::string &type, const std::vector ¶ms, - bool &clouds); + void setSky(RemotePlayer *player, const SkyboxParams ¶ms); + void setSun(RemotePlayer *player, const SunParams ¶ms); + void setMoon(RemotePlayer *player, const MoonParams ¶ms); + void setStars(RemotePlayer *player, const StarParams ¶ms); + void setClouds(RemotePlayer *player, const CloudParams ¶ms); - bool overrideDayNightRatio(RemotePlayer *player, bool do_override, float brightness); + void overrideDayNightRatio(RemotePlayer *player, bool do_override, float brightness); /* con::PeerHandler implementation. */ void peerAdded(con::Peer *peer); @@ -327,7 +318,7 @@ class Server : public con::PeerHandler, public MapEventReceiver, bool getClientConInfo(session_t peer_id, con::rtt_stat_type type, float *retval); bool getClientInfo(session_t peer_id, ClientState *state, u32 *uptime, u8* ser_vers, u16* prot_vers, u8* major, u8* minor, u8* patch, - std::string* vers_string); + std::string* vers_string, std::string* lang_code); void printToConsoleOnly(const std::string &text); @@ -351,6 +342,9 @@ class Server : public con::PeerHandler, public MapEventReceiver, // Send block to specific player only bool SendBlock(session_t peer_id, const v3s16 &blockpos); + // Load translations for a language + void loadTranslationLanguage(const std::string &lang_code); + // Bind address Address m_bind_addr; @@ -378,6 +372,8 @@ class Server : public con::PeerHandler, public MapEventReceiver, float m_timer = 0.0f; }; + void init(); + void SendMovement(session_t peer_id); void SendHP(session_t peer_id, u16 hp); void SendBreath(session_t peer_id, u16 breath); @@ -411,9 +407,10 @@ class Server : public con::PeerHandler, public MapEventReceiver, void SendHUDChange(session_t peer_id, u32 id, HudElementStat stat, void *value); void SendHUDSetFlags(session_t peer_id, u32 flags, u32 mask); void SendHUDSetParam(session_t peer_id, u16 param, const std::string &value); - void SendSetSky(session_t peer_id, const video::SColor &bgcolor, - const std::string &type, const std::vector ¶ms, - bool &clouds); + void SendSetSky(session_t peer_id, const SkyboxParams ¶ms); + void SendSetSun(session_t peer_id, const SunParams ¶ms); + void SendSetMoon(session_t peer_id, const MoonParams ¶ms); + void SendSetStars(session_t peer_id, const StarParams ¶ms); void SendCloudParams(session_t peer_id, const CloudParams ¶ms); void SendOverrideDayNightRatio(session_t peer_id, bool do_override, float ratio); void broadcastModChannelMessage(const std::string &channel, @@ -440,35 +437,22 @@ class Server : public con::PeerHandler, public MapEventReceiver, // Sends blocks to clients (locks env and con on its own) void SendBlocks(float dtime); + bool addMediaFile(const std::string &filename, const std::string &filepath, + std::string *filedata = nullptr, std::string *digest = nullptr); void fillMediaCache(); void sendMediaAnnouncement(session_t peer_id, const std::string &lang_code); void sendRequestedMedia(session_t peer_id, const std::vector &tosend); - void sendDetachedInventory(const std::string &name, session_t peer_id); - // Adds a ParticleSpawner on peer with peer_id (PEER_ID_INEXISTENT == all) void SendAddParticleSpawner(session_t peer_id, u16 protocol_version, - u16 amount, float spawntime, - v3f minpos, v3f maxpos, - v3f minvel, v3f maxvel, - v3f minacc, v3f maxacc, - float minexptime, float maxexptime, - float minsize, float maxsize, - bool collisiondetection, bool collision_removal, bool object_collision, - u16 attached_id, - bool vertical, const std::string &texture, u32 id, - const struct TileAnimationParams &animation, u8 glow); + const ParticleSpawnerParameters &p, u16 attached_id, u32 id); void SendDeleteParticleSpawner(session_t peer_id, u32 id); // Spawns particle on peer with peer_id (PEER_ID_INEXISTENT == all) void SendSpawnParticle(session_t peer_id, u16 protocol_version, - v3f pos, v3f velocity, v3f acceleration, - float expirationtime, float size, - bool collisiondetection, bool collision_removal, bool object_collision, - bool vertical, const std::string &texture, - const struct TileAnimationParams &animation, u8 glow); + const ParticleParameters &p); void SendActiveObjectRemoveAdd(RemoteClient *client, PlayerSAO *playersao); void SendActiveObjectMessages(session_t peer_id, const std::string &datas, @@ -580,9 +564,6 @@ class Server : public con::PeerHandler, public MapEventReceiver, float m_step_dtime = 0.0f; std::mutex m_step_dtime_mutex; - // current server step lag counter - float m_lag; - // The server mainly operates in this thread ServerThread *m_thread = nullptr; @@ -591,8 +572,6 @@ class Server : public con::PeerHandler, public MapEventReceiver, */ // Timer for sending time of day over network float m_time_of_day_send_timer = 0.0f; - // Uptime of server in seconds - MutexedVariable m_uptime; /* Client interface @@ -646,15 +625,8 @@ class Server : public con::PeerHandler, public MapEventReceiver, Sounds */ std::unordered_map m_playing_sounds; - s32 m_next_sound_id = 0; - - /* - Detached inventories (behind m_env_mutex) - */ - // key = name - std::map m_detached_inventories; - // value = "" (visible to all players) or player name - std::map m_detached_inventories_player; + s32 m_next_sound_id = 0; // positive values only + s32 nextSoundId(); std::unordered_map m_mod_storages; float m_mod_storage_save_timer = 10.0f; @@ -665,6 +637,22 @@ class Server : public con::PeerHandler, public MapEventReceiver, // ModChannel manager std::unique_ptr m_modchannel_mgr; + + // Inventory manager + std::unique_ptr m_inventory_mgr; + + // Global server metrics backend + std::unique_ptr m_metrics_backend; + + // Server metrics + MetricCounterPtr m_uptime_counter; + MetricGaugePtr m_player_gauge; + MetricGaugePtr m_timeofday_gauge; + // current server step lag + MetricGaugePtr m_lag_gauge; + MetricCounterPtr m_aom_buffer_counter; + MetricCounterPtr m_packet_recv_counter; + MetricCounterPtr m_packet_recv_processed_counter; }; /*