1313#include < unordered_map>
1414#include < vector>
1515
16+ #define CHANFIX_CHANNEL_DATA_TYPE " ChanFixChannel"
17+
1618struct CFOpRecord final
1719{
1820 Anope::string account; // empty or "*" means no account
@@ -24,6 +26,13 @@ struct CFOpRecord final
2426};
2527
2628struct CFChannelRecord final
29+ {
30+ // Deprecated placeholder. The ChanFix DB is now stored via Anope's
31+ // serialization system using CFChannelData.
32+ };
33+
34+ struct CFChannelData final
35+ : Serializable
2736{
2837 Anope::string name;
2938 time_t ts = 0 ;
@@ -42,6 +51,19 @@ struct CFChannelRecord final
4251 time_t nofix_time = 0 ;
4352
4453 Anope::unordered_map<CFOpRecord> oprecords;
54+
55+ explicit CFChannelData (const Anope::string& chname);
56+ ~CFChannelData () override ;
57+ };
58+
59+ class ChanFixChannelDataType final
60+ : public Serialize::Type
61+ {
62+ public:
63+ explicit ChanFixChannelDataType (Module* owner);
64+
65+ void Serialize (Serializable* obj, Serialize::Data& data) const override ;
66+ Serializable* Unserialize (Serializable* obj, Serialize::Data& data) const override ;
4567};
4668
4769class ChanFixCore final
@@ -55,7 +77,10 @@ class ChanFixCore final
5577 void GatherTick ();
5678 void ExpireTick ();
5779 void AutoFixTick ();
58- void SaveDB () const ;
80+
81+ void LegacyImportIfNeeded ();
82+ bool LegacyImportNeedsSave () const { return this ->legacy_import_needs_save ; }
83+ void ClearLegacyImportNeedsSave () { this ->legacy_import_needs_save = false ; }
5984
6085 bool IsAdmin (CommandSource& source) const ;
6186 bool IsAuspex (CommandSource& source) const ;
@@ -72,14 +97,17 @@ class ChanFixCore final
7297 time_t GetGatherInterval () const { return this ->gather_interval ; }
7398 time_t GetExpireInterval () const { return this ->expire_interval ; }
7499 time_t GetAutofixInterval () const { return this ->autofix_interval ; }
75- time_t GetSaveInterval () const { return this ->save_interval ; }
76100
77101private:
78102 Module* module ;
79103 BotInfo* chanfix = nullptr ;
104+ bool legacy_import_needs_save = false ;
80105
81106 bool do_autofix = false ;
82107 bool join_to_fix = false ;
108+ bool clear_modes_on_fix = false ;
109+ bool clear_bans_on_fix = false ;
110+ bool clear_moderated_on_fix = false ;
83111
84112 unsigned int op_threshold = 3 ;
85113 unsigned int min_fix_score = 12 ;
@@ -92,42 +120,30 @@ class ChanFixCore final
92120 time_t gather_interval = 5 * 60 ;
93121 time_t expire_interval = 60 * 60 ;
94122 time_t autofix_interval = 60 ;
95- time_t save_interval = 10 * 60 ;
96123 unsigned int expire_divisor = 672 ;
97124
98125 char op_status_char = ' o' ;
99126
100127 Anope::string admin_priv = " chanfix/admin" ;
101128 Anope::string auspex_priv = " chanfix/auspex" ;
102129
103- Anope::unordered_map<CFChannelRecord> channels;
104-
105- static constexpr const char * DB_MAGIC = " chanfix" ;
106- static constexpr unsigned DB_VERSION = 1 ;
107-
108- void LoadDB ();
109- Anope::string GetDBPath () const ;
110-
111- static Anope::string EscapeValue (const Anope::string& in);
112- static Anope::string UnescapeValue (const Anope::string& in);
113-
114130 bool IsRegistered (Channel* c) const ;
115131 static bool IsValidChannelName (const Anope::string& name);
116132
117- CFChannelRecord * GetRecord (const Anope::string& chname);
118- CFChannelRecord & GetOrCreateRecord (Channel* c);
133+ CFChannelData * GetRecord (const Anope::string& chname);
134+ CFChannelData & GetOrCreateRecord (Channel* c);
119135
120136 unsigned int CountOps (Channel* c) const ;
121137 Anope::string KeyForUser (User* u) const ;
122- CFOpRecord* FindRecord (CFChannelRecord & rec, User* u);
123- void UpdateOpRecord (CFChannelRecord & rec, User* u);
138+ CFOpRecord* FindRecord (CFChannelData & rec, User* u);
139+ bool UpdateOpRecord (CFChannelData & rec, User* u);
124140
125141 unsigned int CalculateScore (const CFOpRecord& orec) const ;
126- unsigned int GetHighScore (const CFChannelRecord & rec) const ;
127- unsigned int GetThreshold (const CFChannelRecord & rec, time_t now) const ;
142+ unsigned int GetHighScore (const CFChannelData & rec) const ;
143+ unsigned int GetThreshold (const CFChannelData & rec, time_t now) const ;
128144
129- bool ShouldHandle (CFChannelRecord & rec, Channel* c) const ;
130- bool CanStartFix (const CFChannelRecord & rec, Channel* c) const ;
131- bool FixChannel (CFChannelRecord & rec, Channel* c);
145+ bool ShouldHandle (CFChannelData & rec, Channel* c) const ;
146+ bool CanStartFix (const CFChannelData & rec, Channel* c) const ;
147+ bool FixChannel (CFChannelData & rec, Channel* c);
132148 void ClearBans (Channel* c);
133149};
0 commit comments