diff options
| author | Sadie Powell <sadie@witchery.services> | 2025-03-08 12:22:07 +0000 |
|---|---|---|
| committer | Sadie Powell <sadie@witchery.services> | 2025-03-08 12:22:07 +0000 |
| commit | df0cd3ef3e9a5cd1230aebdb45569f54512373ad (patch) | |
| tree | 3abf54908e7aac069da940f1d6db85829a46b302 /include/modules/operserv | |
| parent | 9e37a643f13a8e6b5b8468f245f21fd23238f058 (diff) | |
Move some headers around.
Diffstat (limited to 'include/modules/operserv')
| -rw-r--r-- | include/modules/operserv/forbid.h | 53 | ||||
| -rw-r--r-- | include/modules/operserv/ignore.h | 46 | ||||
| -rw-r--r-- | include/modules/operserv/news.h | 51 | ||||
| -rw-r--r-- | include/modules/operserv/oper.h | 46 | ||||
| -rw-r--r-- | include/modules/operserv/session.h | 93 |
5 files changed, 289 insertions, 0 deletions
diff --git a/include/modules/operserv/forbid.h b/include/modules/operserv/forbid.h new file mode 100644 index 000000000..5c2f9d05c --- /dev/null +++ b/include/modules/operserv/forbid.h @@ -0,0 +1,53 @@ +/* + * + * (C) 2011-2025 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#pragma once + +enum ForbidType +{ + FT_NICK = 1, + FT_CHAN, + FT_EMAIL, + FT_REGISTER, + FT_SIZE +}; + +struct ForbidData +{ + Anope::string mask; + Anope::string creator; + Anope::string reason; + time_t created = 0; + time_t expires = 0; + ForbidType type; + + virtual ~ForbidData() = default; +protected: + ForbidData() = default; +}; + +class ForbidService + : public Service +{ +public: + ForbidService(Module *m) : Service(m, "ForbidService", "forbid") { } + + virtual void AddForbid(ForbidData *d) = 0; + + virtual void RemoveForbid(ForbidData *d) = 0; + + virtual ForbidData *CreateForbid() = 0; + + virtual ForbidData *FindForbid(const Anope::string &mask, ForbidType type) = 0; + + virtual ForbidData *FindForbidExact(const Anope::string &mask, ForbidType type) = 0; + + virtual std::vector<ForbidData *> GetForbids() = 0; +}; + +static ServiceReference<ForbidService> forbid_service("ForbidService", "forbid"); diff --git a/include/modules/operserv/ignore.h b/include/modules/operserv/ignore.h new file mode 100644 index 000000000..8a60a044f --- /dev/null +++ b/include/modules/operserv/ignore.h @@ -0,0 +1,46 @@ +/* OperServ ignore interface + * + * (C) 2003-2025 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +#pragma once + +struct IgnoreData +{ + Anope::string mask; + Anope::string creator; + Anope::string reason; + time_t time = 0; /* When do we stop ignoring them? */ + + virtual ~IgnoreData() = default; +protected: + IgnoreData() = default; +}; + +class IgnoreService + : public Service +{ +protected: + IgnoreService(Module *c) : Service(c, "IgnoreService", "ignore") { } + +public: + virtual void AddIgnore(IgnoreData *) = 0; + + virtual void DelIgnore(IgnoreData *) = 0; + + virtual void ClearIgnores() = 0; + + virtual IgnoreData *Create() = 0; + + virtual IgnoreData *Find(const Anope::string &mask) = 0; + + virtual std::vector<IgnoreData *> &GetIgnores() = 0; +}; + +static ServiceReference<IgnoreService> ignore_service("IgnoreService", "ignore"); diff --git a/include/modules/operserv/news.h b/include/modules/operserv/news.h new file mode 100644 index 000000000..815c71db6 --- /dev/null +++ b/include/modules/operserv/news.h @@ -0,0 +1,51 @@ +/* + * + * (C) 2011-2025 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#pragma once + +enum NewsType +{ + NEWS_LOGON, + NEWS_RANDOM, + NEWS_OPER +}; + +struct NewsMessages final +{ + NewsType type; + Anope::string name; + const char *msgs[10]; +}; + +struct NewsItem + : Serializable +{ + NewsType type; + Anope::string text; + Anope::string who; + time_t time; + + NewsItem() : Serializable("NewsItem") { } +}; + +class NewsService + : public Service +{ +public: + NewsService(Module *m) : Service(m, "NewsService", "news") { } + + virtual NewsItem *CreateNewsItem() = 0; + + virtual void AddNewsItem(NewsItem *n) = 0; + + virtual void DelNewsItem(NewsItem *n) = 0; + + virtual std::vector<NewsItem *> &GetNewsList(NewsType t) = 0; +}; + +static ServiceReference<NewsService> news_service("NewsService", "news"); diff --git a/include/modules/operserv/oper.h b/include/modules/operserv/oper.h new file mode 100644 index 000000000..154b6af08 --- /dev/null +++ b/include/modules/operserv/oper.h @@ -0,0 +1,46 @@ +/* + * + * (C) 2011-2025 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#pragma once + +struct MyOper final + : Oper + , Serializable +{ + MyOper(const Anope::string &n, OperType *o) : Oper(n, o), Serializable("Oper") { } + + void Serialize(Serialize::Data &data) const override + { + data.Store("name", this->name); + data.Store("type", this->ot->GetName()); + } + + static Serializable *Unserialize(Serializable *obj, Serialize::Data &data) + { + Anope::string stype, sname; + + data["type"] >> stype; + data["name"] >> sname; + + OperType *ot = OperType::Find(stype); + if (ot == NULL) + return NULL; + NickCore *nc = NickCore::Find(sname); + if (nc == NULL) + return NULL; + + MyOper *myo; + if (obj) + myo = anope_dynamic_static_cast<MyOper *>(obj); + else + myo = new MyOper(nc->display, ot); + nc->o = myo; + Log(LOG_NORMAL, "operserv/oper") << "Tied oper " << nc->display << " to type " << ot->GetName(); + return myo; + } +}; diff --git a/include/modules/operserv/session.h b/include/modules/operserv/session.h new file mode 100644 index 000000000..0f25f669e --- /dev/null +++ b/include/modules/operserv/session.h @@ -0,0 +1,93 @@ +/* + * + * (C) 2011-2025 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#pragma once + +struct Session final +{ + cidr addr; /* A cidr (sockaddrs + len) representing this session */ + unsigned count = 1; /* Number of clients with this host */ + unsigned hits = 0; /* Number of subsequent kills for a host */ + + Session(const sockaddrs &ip, int len) : addr(ip, len) { } +}; + +struct Exception final + : Serializable +{ + Anope::string mask; /* Hosts to which this exception applies */ + unsigned limit; /* Session limit for exception */ + Anope::string who; /* Nick of person who added the exception */ + Anope::string reason; /* Reason for exception's addition */ + time_t time; /* When this exception was added */ + time_t expires; /* Time when it expires. 0 == no expiry */ + + Exception() : Serializable("Exception") { } + void Serialize(Serialize::Data &data) const override; + static Serializable *Unserialize(Serializable *obj, Serialize::Data &data); +}; + +class SessionService + : public Service +{ +public: + typedef std::unordered_map<cidr, Session *, cidr::hash> SessionMap; + typedef std::vector<Exception *> ExceptionVector; + + SessionService(Module *m) : Service(m, "SessionService", "session") { } + + virtual Exception *CreateException() = 0; + + virtual void AddException(Exception *e) = 0; + + virtual void DelException(Exception *e) = 0; + + virtual Exception *FindException(User *u) = 0; + + virtual Exception *FindException(const Anope::string &host) = 0; + + virtual ExceptionVector &GetExceptions() = 0; + + virtual Session *FindSession(const Anope::string &ip) = 0; + + virtual SessionMap &GetSessions() = 0; +}; + +static ServiceReference<SessionService> session_service("SessionService", "session"); + +void Exception::Serialize(Serialize::Data &data) const +{ + data.Store("mask", this->mask); + data.Store("limit", this->limit); + data.Store("who", this->who); + data.Store("reason", this->reason); + data.Store("time", this->time); + data.Store("expires", this->expires); +} + +Serializable *Exception::Unserialize(Serializable *obj, Serialize::Data &data) +{ + if (!session_service) + return NULL; + + Exception *ex; + if (obj) + ex = anope_dynamic_static_cast<Exception *>(obj); + else + ex = new Exception; + data["mask"] >> ex->mask; + data["limit"] >> ex->limit; + data["who"] >> ex->who; + data["reason"] >> ex->reason; + data["time"] >> ex->time; + data["expires"] >> ex->expires; + + if (!obj) + session_service->AddException(ex); + return ex; +} |
