inspircd / inspircd-contrib

Third-party InspIRCd module repository.
https://www.inspircd.org
66 stars 72 forks source link

Port Modules #219

Closed JackWyman closed 5 years ago

JackWyman commented 5 years ago

Hello, Im updated to Inspircd 3 and I have two modules that do not work in Inspircd 3. It would be nice if some developer could ported them. I have tried but the classes have changed and I do not know them.

ModuleConnJoinIdent

#include "inspircd.h"

class ModuleConnJoinIdent : public Module
{
    typedef std::vector<std::pair<std::string, std::string> > IdentChanList;
    IdentChanList chans;

 public:
    void init()
    {
        Implementation eventlist[] = { I_OnRehash, I_OnPostConnect };
        ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        OnRehash(NULL);
    }

    void OnRehash(User* user)
    {
        chans.clear();

        ConfigTagList tags = ServerInstance->Config->ConfTags("autojoinident");
        for (ConfigIter i = tags.first; i != tags.second; ++i)
        {
            ConfigTag* tag = i->second;
            chans.push_back(std::make_pair(tag->getString("ident"), tag->getString("chan")));
        }
    }

    void OnPostConnect(User* user)
    {
        if (!IS_LOCAL(user))
            return;

        for (IdentChanList::const_iterator i = chans.begin(); i != chans.end(); ++i)
        {
            if (!InspIRCd::Match(user->ident, i->first))
                continue;

            const std::string& channame = i->second;
            if (ServerInstance->IsChannel(channame.c_str(), ServerInstance->Config->Limits.ChanMax))
                Channel::JoinUser(user, channame.c_str(), false, "", false);
        }
    }

    Version GetVersion()
    {
        return Version("Autojoins users based on their ident");
    }
};

MODULE_INIT(ModuleConnJoinIdent)
<autojoinident ident="AR*" chan="#argentina">
<autojoinident ident="bad*" chan="#bads">

ModuleConnJoinGeoIP

#include "inspircd.h"

class ModuleConnJoinGeoIP : public Module
{
    typedef std::multimap<std::string, std::string> CountryChans;
    CountryChans chans;

 public:
    void init()
    {
        Implementation eventlist[] = { I_OnRehash, I_OnPostConnect };
        ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        OnRehash(NULL);
    }

    void OnRehash(User* user)
    {
        chans.clear();

        ConfigTagList tags = ServerInstance->Config->ConfTags("autojoingeoip");
        for (ConfigIter i = tags.first; i != tags.second; ++i)
        {
            ConfigTag* tag = i->second;
            chans.insert(std::make_pair(tag->getString("country"), tag->getString("chan")));
        }
    }

    void OnPostConnect(User* user)
    {
        if (!IS_LOCAL(user))
            return;

        LocalStringExt* const geoext = static_cast<LocalStringExt*>(ServerInstance->Extensions.GetItem("geoip_cc"));
        if (!geoext)
            return; // m_geoip not loaded

        const std::string* const country = geoext->get(user);
        if (!country)
            return;

        std::pair<CountryChans::const_iterator, CountryChans::const_iterator> itp = chans.equal_range(*country);
        for (CountryChans::const_iterator i = itp.first; i != itp.second; ++i)
        {
            const std::string& channame = i->second;
            if (ServerInstance->IsChannel(channame.c_str(), ServerInstance->Config->Limits.ChanMax))
                Channel::JoinUser(user, channame.c_str(), false, "", false);
        }
    }

    Version GetVersion()
    {
        return Version("Autojoins users based on GeoIP");
    }
};

MODULE_INIT(ModuleConnJoinGeoIP)

<autojoingeoip country="RU" chan="#rusia">

Thanks!