]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/unittest/test.cpp
Implement mod communication channels (#6351)
[dragonfireclient.git] / src / unittest / test.cpp
index 570807ba7626bb8be941d808383dd4a27e23b09a..1985fdc6c550513b77a6506daa2fe856dcf2995a 100644 (file)
@@ -22,7 +22,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "nodedef.h"
 #include "itemdef.h"
 #include "gamedef.h"
+#include "modchannels.h"
 #include "mods.h"
+#include "util/numeric.h"
 
 content_t t_CONTENT_STONE;
 content_t t_CONTENT_GRASS;
@@ -68,22 +70,31 @@ class TestGameDef : public IGameDef {
        virtual std::string getModStoragePath() const { return "."; }
        virtual bool registerModStorage(ModMetadata *meta) { return true; }
        virtual void unregisterModStorage(const std::string &name) {}
+       bool joinModChannel(const std::string &channel);
+       bool leaveModChannel(const std::string &channel);
+       bool sendModChannelMessage(const std::string &channel, const std::string &message);
+       ModChannel *getModChannel(const std::string &channel)
+       {
+               return m_modchannel_mgr->getModChannel(channel);
+       }
 
 private:
-       IItemDefManager *m_itemdef;
-       INodeDefManager *m_nodedef;
-       ICraftDefManager *m_craftdef;
-       ITextureSource *m_texturesrc;
-       IShaderSource *m_shadersrc;
-       ISoundManager *m_soundmgr;
-       MtEventManager *m_eventmgr;
-       scene::ISceneManager *m_scenemgr;
-       IRollbackManager *m_rollbackmgr;
-       EmergeManager *m_emergemgr;
+       IItemDefManager *m_itemdef = nullptr;
+       INodeDefManager *m_nodedef = nullptr;
+       ICraftDefManager *m_craftdef = nullptr;
+       ITextureSource *m_texturesrc = nullptr;
+       IShaderSource *m_shadersrc = nullptr;
+       ISoundManager *m_soundmgr = nullptr;
+       MtEventManager *m_eventmgr = nullptr;
+       scene::ISceneManager *m_scenemgr = nullptr;
+       IRollbackManager *m_rollbackmgr = nullptr;
+       EmergeManager *m_emergemgr = nullptr;
+       std::unique_ptr<ModChannelMgr> m_modchannel_mgr;
 };
 
 
-TestGameDef::TestGameDef()
+TestGameDef::TestGameDef() :
+       m_modchannel_mgr(new ModChannelMgr())
 {
        m_itemdef = createItemDefManager();
        m_nodedef = createNodeDefManager();
@@ -119,8 +130,8 @@ void TestGameDef::defineSomeNodes()
                "{default_stone.png";
        f = ContentFeatures();
        f.name = itemdef.name;
-       for(int i = 0; i < 6; i++)
-               f.tiledef[i].name = "default_stone.png";
+       for (TileDef &tiledef : f.tiledef)
+               tiledef.name = "default_stone.png";
        f.is_ground_content = true;
        idef->registerItem(itemdef);
        t_CONTENT_STONE = ndef->set(f.name, f);
@@ -174,8 +185,8 @@ void TestGameDef::defineSomeNodes()
        f.liquid_viscosity = 4;
        f.is_ground_content = true;
        f.groups["liquids"] = 3;
-       for(int i = 0; i < 6; i++)
-               f.tiledef[i].name = "default_water.png";
+       for (TileDef &tiledef : f.tiledef)
+               tiledef.name = "default_water.png";
        idef->registerItem(itemdef);
        t_CONTENT_WATER = ndef->set(f.name, f);
 
@@ -196,8 +207,8 @@ void TestGameDef::defineSomeNodes()
        f.light_source = LIGHT_MAX-1;
        f.is_ground_content = true;
        f.groups["liquids"] = 3;
-       for(int i = 0; i < 6; i++)
-               f.tiledef[i].name = "default_lava.png";
+       for (TileDef &tiledef : f.tiledef)
+               tiledef.name = "default_lava.png";
        idef->registerItem(itemdef);
        t_CONTENT_LAVA = ndef->set(f.name, f);
 
@@ -214,21 +225,38 @@ void TestGameDef::defineSomeNodes()
                "{default_brick.png";
        f = ContentFeatures();
        f.name = itemdef.name;
-       for(int i = 0; i < 6; i++)
-               f.tiledef[i].name = "default_brick.png";
+       for (TileDef &tiledef : f.tiledef)
+               tiledef.name = "default_brick.png";
        f.is_ground_content = true;
        idef->registerItem(itemdef);
        t_CONTENT_BRICK = ndef->set(f.name, f);
 }
 
+bool TestGameDef::joinModChannel(const std::string &channel)
+{
+       return m_modchannel_mgr->joinChannel(channel, PEER_ID_SERVER);
+}
+
+bool TestGameDef::leaveModChannel(const std::string &channel)
+{
+       return m_modchannel_mgr->leaveChannel(channel, PEER_ID_SERVER);
+}
+
+bool TestGameDef::sendModChannelMessage(const std::string &channel,
+       const std::string &message)
+{
+       if (!m_modchannel_mgr->channelRegistered(channel))
+               return false;
+
+       return true;
+}
+
 ////
 //// run_tests
 ////
 
 bool run_tests()
 {
-       DSTACK(FUNCTION_NAME);
-
        u64 t1 = porting::getTimeMs();
        TestGameDef gamedef;