mirror of
https://github.com/anope/anope.git
synced 2026-07-05 13:43:13 +02:00
Calculate nc::channelcount at runtime
This commit is contained in:
@@ -282,7 +282,6 @@ CREATE TABLE IF NOT EXISTS `anope_ns_core` (
|
||||
`greet` text NOT NULL,
|
||||
`flags` text NOT NULL,
|
||||
`language` varchar(5) NOT NULL DEFAULT '',
|
||||
`channelcount` smallint(5) unsigned NOT NULL DEFAULT '0',
|
||||
`memomax` smallint(5) unsigned NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`display`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
+12
-2
@@ -60,7 +60,7 @@ enum ChannelInfoFlag
|
||||
|
||||
const Anope::string ChannelInfoFlagStrings[] = {
|
||||
"BEGIN", "KEEPTOPIC", "SECUREOPS", "PRIVATE", "TOPICLOCK", "RESTRICTED",
|
||||
"PEACE", "SECURE", "FORBIDDEN", "NO_EXPIRE", "MEMO_HARDMAX", "OPNOTICE", "SECUREFOUNDER",
|
||||
"PEACE", "SECURE", "NO_EXPIRE", "MEMO_HARDMAX", "OPNOTICE", "SECUREFOUNDER",
|
||||
"SIGNKICK", "SIGNKICK_LEVEL", "XOP", "SUSPENDED", "PERSIST", ""
|
||||
};
|
||||
|
||||
@@ -118,6 +118,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
|
||||
private:
|
||||
typedef std::multimap<ChannelModeName, ModeLock> ModeList;
|
||||
private:
|
||||
NickCore *founder; /* Channel founder */
|
||||
std::vector<ChanAccess *> access; /* List of authorized users */
|
||||
std::vector<AutoKick *> akick; /* List of users to kickban */
|
||||
std::vector<BadWord *> badwords; /* List of badwords */
|
||||
@@ -139,7 +140,6 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
|
||||
~ChannelInfo();
|
||||
|
||||
Anope::string name; /* Channel name */
|
||||
NickCore *founder;
|
||||
NickCore *successor; /* Who gets the channel if the founder nick is dropped or expires */
|
||||
Anope::string desc;
|
||||
|
||||
@@ -167,6 +167,16 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
|
||||
int16 floodlines, floodsecs; /* For FLOOD kicker */
|
||||
int16 repeattimes; /* For REPEAT kicker */
|
||||
|
||||
/** Change the founder of the channek
|
||||
* @params nc The new founder
|
||||
*/
|
||||
void SetFounder(NickCore *nc);
|
||||
|
||||
/** Get the founder of the channel
|
||||
* @return The founder
|
||||
*/
|
||||
NickCore *GetFounder() const;
|
||||
|
||||
/** Find which bot should send mode/topic/etc changes for this channel
|
||||
* @return The bot
|
||||
*/
|
||||
|
||||
@@ -203,7 +203,7 @@ class CommandCSAKick : public Command
|
||||
{
|
||||
ChanAccess *nc_access = ci->GetAccess(nc), *u_access = ci->GetAccess(u);
|
||||
int16 nc_level = nc_access ? nc_access->level : 0, u_level = u_access ? u_access->level : 0;
|
||||
if (nc == ci->founder || nc_level >= u_level)
|
||||
if (nc == ci->GetFounder() || nc_level >= u_level)
|
||||
{
|
||||
source.Reply(_(ACCESS_DENIED));
|
||||
return;
|
||||
@@ -236,7 +236,7 @@ class CommandCSAKick : public Command
|
||||
|
||||
ChanAccess *na_access = ci->GetAccess(na->nc), *u_access = ci->GetAccess(u);
|
||||
int16 na_level = na_access ? na_access->level : 0, u_level = u_access ? u_access->level : 0;
|
||||
if (na->nc && (na->nc == ci->founder || na_level >= u_level))
|
||||
if (na->nc && (na->nc == ci->GetFounder() || na_level >= u_level))
|
||||
{
|
||||
Anope::string buf = na->nick + "!" + na->last_usermask;
|
||||
if (Anope::Match(buf, mask))
|
||||
|
||||
@@ -54,7 +54,7 @@ class CommandCSDrop : public Command
|
||||
ci->c->RemoveMode(NULL, CMODE_REGISTERED, "", false);
|
||||
|
||||
bool override = (ci->HasFlag(CI_SECUREFOUNDER) ? !IsFounder(u, ci) : !check_access(u, ci, CA_FOUNDER));
|
||||
Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "founder: " << (ci->founder ? ci->founder->display : "none");
|
||||
Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "founder: " << (ci->GetFounder() ? ci->GetFounder()->display : "none");
|
||||
|
||||
delete ci;
|
||||
|
||||
|
||||
@@ -50,7 +50,8 @@ class CommandCSInfo : public Command
|
||||
show_all = true;
|
||||
|
||||
source.Reply(_(CHAN_INFO_HEADER), chan.c_str());
|
||||
source.Reply(_(" Founder: %s"), ci->founder->display.c_str());
|
||||
if (ci->GetFounder())
|
||||
source.Reply(_(" Founder: %s"), ci->GetFounder()->display.c_str());
|
||||
|
||||
if (show_all && ci->successor)
|
||||
source.Reply(_(" Successor: %s"), ci->successor->display.c_str());
|
||||
|
||||
@@ -123,7 +123,7 @@ class ExpireCallback : public CallBack
|
||||
if (ci->HasFlag(CI_SUSPENDED))
|
||||
extra = "suspended ";
|
||||
|
||||
Log(LOG_NORMAL, "chanserv/expire", ChanServ) << "Expiring " << extra << "channel " << ci->name << " (founder: " << (ci->founder ? ci->founder->display : "(none)") << ")";
|
||||
Log(LOG_NORMAL, "chanserv/expire", ChanServ) << "Expiring " << extra << "channel " << ci->name << " (founder: " << (ci->GetFounder() ? ci->GetFounder()->display : "(none)") << ")";
|
||||
FOREACH_MOD(I_OnChanExpire, OnChanExpire(ci));
|
||||
delete ci;
|
||||
}
|
||||
@@ -177,7 +177,7 @@ class ChanServCore : public Module
|
||||
ChannelInfo *ci = it->second;
|
||||
++it;
|
||||
|
||||
if (ci->founder == nc)
|
||||
if (ci->GetFounder() == nc)
|
||||
{
|
||||
NickCore *newowner = NULL;
|
||||
if (ci->successor && (ci->successor->IsServicesOper() || !Config->CSMaxReg || ci->successor->channelcount < Config->CSMaxReg))
|
||||
@@ -201,9 +201,8 @@ class ChanServCore : public Module
|
||||
if (newowner)
|
||||
{
|
||||
Log(LOG_NORMAL, "chanserv/expire") << "Transferring foundership of " << ci->name << " from deleted nick " << nc->display << " to " << newowner->display;
|
||||
ci->founder = newowner;
|
||||
ci->SetFounder(newowner);
|
||||
ci->successor = NULL;
|
||||
++newowner->channelcount;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -51,7 +51,7 @@ class CommandCSRegister : public Command
|
||||
else
|
||||
{
|
||||
ci = new ChannelInfo(chan);
|
||||
ci->founder = u->Account();
|
||||
ci->SetFounder(u->Account());
|
||||
ci->desc = chdesc;
|
||||
|
||||
if (c && !c->topic.empty())
|
||||
@@ -64,7 +64,6 @@ class CommandCSRegister : public Command
|
||||
ci->last_topic_setter = Config->s_ChanServ;
|
||||
|
||||
ci->bi = NULL;
|
||||
++ci->founder->channelcount;
|
||||
Log(LOG_COMMAND, u, this, ci);
|
||||
source.Reply(_("Channel \002%s\002 registered under your nickname: %s"), chan.c_str(), u->nick.c_str());
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ class CommandCSSetFounder : public Command
|
||||
}
|
||||
|
||||
NickAlias *na = findnick(params[1]);
|
||||
NickCore *nc, *nc0 = ci->founder;
|
||||
|
||||
if (!na)
|
||||
{
|
||||
@@ -44,7 +43,7 @@ class CommandCSSetFounder : public Command
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
nc = na->nc;
|
||||
NickCore *nc = na->nc;
|
||||
if (Config->CSMaxReg && nc->channelcount >= Config->CSMaxReg && !u->HasPriv("chanserv/no-register-limit"))
|
||||
{
|
||||
source.Reply(_("\002%s\002 has too many channels registered."), na->nick.c_str());
|
||||
@@ -53,13 +52,7 @@ class CommandCSSetFounder : public Command
|
||||
|
||||
Log(!this->permission.empty() ? LOG_ADMIN : LOG_COMMAND, u, this, ci) << "to change the founder to " << nc->display;
|
||||
|
||||
/* Founder and successor must not be the same group */
|
||||
if (nc == ci->successor)
|
||||
ci->successor = NULL;
|
||||
|
||||
--nc0->channelcount;
|
||||
ci->founder = nc;
|
||||
++nc->channelcount;
|
||||
ci->SetFounder(nc);
|
||||
|
||||
source.Reply(_("Founder of %s changed to \002%s\002."), ci->name.c_str(), na->nick.c_str());
|
||||
|
||||
|
||||
@@ -46,9 +46,9 @@ class CommandCSSetSuccessor : public Command
|
||||
source.Reply(_(NICK_X_NOT_REGISTERED), params[1].c_str());
|
||||
return MOD_CONT;
|
||||
}
|
||||
if (na->nc == ci->founder)
|
||||
if (na->nc == ci->GetFounder())
|
||||
{
|
||||
source.Reply(_("%s cannot be the successor on channel %s because he is its founder."), na->nick.c_str(), ci->name.c_str());
|
||||
source.Reply(_("%s cannot be the successor on channel %s they are the founder."), na->nick.c_str(), ci->name.c_str());
|
||||
return MOD_CONT;
|
||||
}
|
||||
nc = na->nc;
|
||||
|
||||
@@ -196,7 +196,6 @@ class DBMySQL : public Module
|
||||
nc->FromString(flags);
|
||||
|
||||
nc->language = r.Get(i, "language");
|
||||
nc->channelcount = r.Get(i, "channelcount").is_number_only() ? convertTo<int>(r.Get(i, "channelcount")) : 0;
|
||||
nc->memos.memomax = r.Get(i, "memomax").is_number_only() ? convertTo<int16>(r.Get(i, "memomax")) : 20;
|
||||
}
|
||||
|
||||
@@ -339,7 +338,7 @@ class DBMySQL : public Module
|
||||
}
|
||||
|
||||
ChannelInfo *ci = new ChannelInfo(r.Get(i, "name"));
|
||||
ci->founder = nc;
|
||||
ci->SetFounder(nc);
|
||||
if (!r.Get(i, "successor").empty())
|
||||
ci->successor = findcore(r.Get(i, "successor"));
|
||||
ci->desc = r.Get(i, "descr");
|
||||
@@ -760,10 +759,10 @@ class DBMySQL : public Module
|
||||
return;
|
||||
if (!u->HasPriv("chanserv/set") && check_access(u, ci, CA_SET))
|
||||
return;
|
||||
if (params[1].equals_ci("FOUNDER") && ci->founder)
|
||||
if (params[1].equals_ci("FOUNDER"))
|
||||
{
|
||||
SQLQuery query("UPDATE `anope_cs_info` SET `founder` = @founder WHERE `name` = @name");
|
||||
query.setValue("founder", ci->founder->display);
|
||||
query.setValue("founder", ci->GetFounder() ? ci->GetFounder()->display : "");
|
||||
query.setValue("name", ci->name);
|
||||
this->RunQuery(query);
|
||||
}
|
||||
@@ -976,14 +975,13 @@ class DBMySQL : public Module
|
||||
|
||||
void InsertCore(NickCore *nc)
|
||||
{
|
||||
SQLQuery query("INSERT INTO `anope_ns_core` (display, pass, email, greet, flags, language, channelcount, memomax) VALUES(@display, @pass, @email, @greet, @flags, @language, @channelcount, @memomax) ON DUPLICATE KEY UPDATE pass=VALUES(pass), email=VALUES(email), greet=VALUES(greet), flags=VALUES(flags), language=VALUES(language), channelcount=VALUES(channelcount), memomax=VALUES(memomax)");
|
||||
SQLQuery query("INSERT INTO `anope_ns_core` (display, pass, email, greet, flags, language, memomax) VALUES(@display, @pass, @email, @greet, @flags, @language, @memomax) ON DUPLICATE KEY UPDATE pass=VALUES(pass), email=VALUES(email), greet=VALUES(greet), flags=VALUES(flags), language=VALUES(language), memomax=VALUES(memomax)");
|
||||
query.setValue("display", nc->display);
|
||||
query.setValue("pass", nc->pass);
|
||||
query.setValue("email", nc->email);
|
||||
query.setValue("greet", nc->greet);
|
||||
query.setValue("flags", ToString(nc->ToString()));
|
||||
query.setValue("language", nc->language);
|
||||
query.setValue("channelcount", nc->channelcount);
|
||||
query.setValue("memomax", nc->memos.memomax);
|
||||
this->RunQuery(query);
|
||||
}
|
||||
@@ -1097,7 +1095,7 @@ class DBMySQL : public Module
|
||||
{
|
||||
SQLQuery query("INSERT INTO `anope_cs_info` (name, founder, successor, descr, time_registered, last_used, last_topic, last_topic_setter, last_topic_time, flags, bantype, memomax, botnick, botflags, capsmin, capspercent, floodlines, floodsecs, repeattimes) VALUES(@name, @founder, @successor, @descr, @time_registered, @last_used, @last_topic_text, @last_topic_setter, @last_topic_time, @flags, @bantype, @memomax, @botnick, @botflags, @capsmin, @capspercent, @floodlines, @floodsecs, @repeattimes) ON DUPLICATE KEY UPDATE founder=VALUES(founder), successor=VALUES(successor), descr=VALUES(descr), time_registered=VALUES(time_registered), last_used=VALUES(last_used), last_topic=VALUES(last_topic), last_topic_setter=VALUES(last_topic_setter), last_topic_time=VALUES(last_topic_time), flags=VALUES(flags), bantype=VALUES(bantype), memomax=VALUES(memomax), botnick=VALUES(botnick), botflags=VALUES(botflags), capsmin=VALUES(capsmin), capspercent=VALUES(capspercent), floodlines=VALUES(floodlines), floodsecs=VALUES(floodsecs), repeattimes=VALUES(repeattimes)");
|
||||
query.setValue("name", ci->name);
|
||||
query.setValue("founder", ci->founder ? ci->founder->display : "");
|
||||
query.setValue("founder", ci->GetFounder() ? ci->GetFounder()->display : "");
|
||||
query.setValue("successor", ci->successor ? ci->successor->display : "");
|
||||
query.setValue("descr", ci->desc);
|
||||
query.setValue("time_registered", ci->time_registered);
|
||||
|
||||
@@ -40,7 +40,7 @@ static void ChanInfoUpdate(const SQLResult &res)
|
||||
ChannelInfo *ci = cs_findchan(res.Get(0, "name"));
|
||||
if (!ci)
|
||||
ci = new ChannelInfo(res.Get(0, "name"));
|
||||
ci->founder = findcore(res.Get(0, "founder"));
|
||||
ci->SetFounder(findcore(res.Get(0, "founder")));
|
||||
ci->successor = findcore(res.Get(0, "successor"));
|
||||
ci->desc = res.Get(0, "descr");
|
||||
ci->time_registered = convertTo<time_t>(res.Get(0, "time_registered"));
|
||||
|
||||
@@ -171,11 +171,6 @@ static void ReadDatabase(Module *m = NULL)
|
||||
catch (const DatabaseException &ex)
|
||||
{
|
||||
Log() << "[db_plain]: " << ex.GetReason();
|
||||
if (!ci->founder)
|
||||
{
|
||||
delete ci;
|
||||
ci = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -474,8 +469,6 @@ class DBPlain : public Module
|
||||
nc->language = params[0];
|
||||
else if (key.equals_ci("MEMOMAX"))
|
||||
nc->memos.memomax = params[0].is_pos_number_only() ? convertTo<int16>(params[0]) : -1;
|
||||
else if (key.equals_ci("CHANCOUNT"))
|
||||
nc->channelcount = params[0].is_pos_number_only() ? convertTo<uint16>(params[0]) : 0;
|
||||
else if (key.equals_ci("EMAIL"))
|
||||
nc->email = params[0];
|
||||
else if (key.equals_ci("GREET"))
|
||||
@@ -553,11 +546,7 @@ class DBPlain : public Module
|
||||
else if (key.equals_ci("MEMOMAX"))
|
||||
ci->memos.memomax = params[0].is_pos_number_only() ? convertTo<int16>(params[0]) : -1;
|
||||
else if (key.equals_ci("FOUNDER"))
|
||||
{
|
||||
ci->founder = findcore(params[0]);
|
||||
if (!ci->founder)
|
||||
throw DatabaseException("Deleting founderless channel " + ci->name + " (founder: " + params[0] + ")");
|
||||
}
|
||||
ci->SetFounder(findcore(params[0]));
|
||||
else if (key.equals_ci("SUCCESSOR"))
|
||||
ci->successor = findcore(params[0]);
|
||||
else if (key.equals_ci("LEVELS"))
|
||||
@@ -716,7 +705,6 @@ class DBPlain : public Module
|
||||
db_buffer << "NC " << nc->display << " " << nc->pass << endl;
|
||||
|
||||
db_buffer << "MD MEMOMAX " << nc->memos.memomax << endl;
|
||||
db_buffer << "MD CHANCOUNT " << nc->channelcount << endl;
|
||||
|
||||
if (!nc->language.empty())
|
||||
db_buffer << "MD LANGUAGE " << nc->language << endl;
|
||||
@@ -787,8 +775,8 @@ class DBPlain : public Module
|
||||
db_buffer << "CH " << ci->name << " " << ci->time_registered << " " << ci->last_used << endl;
|
||||
db_buffer << "MD BANTYPE " << ci->bantype << endl;
|
||||
db_buffer << "MD MEMOMAX " << ci->memos.memomax << endl;
|
||||
if (ci->founder)
|
||||
db_buffer << "MD FOUNDER " << ci->founder->display << endl;
|
||||
if (ci->GetFounder())
|
||||
db_buffer << "MD FOUNDER " << ci->GetFounder()->display << endl;
|
||||
if (ci->successor)
|
||||
db_buffer << "MD SUCCESSOR " << ci->successor->display << endl;
|
||||
if (!ci->desc.empty())
|
||||
|
||||
+1
-1
@@ -282,7 +282,7 @@ bool IsFounder(User *user, ChannelInfo *ci)
|
||||
if (user->isSuperAdmin)
|
||||
return true;
|
||||
|
||||
if (user->Account() && user->Account() == ci->founder)
|
||||
if (user->Account() && user->Account() == ci->GetFounder())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
@@ -166,6 +166,28 @@ ChannelInfo::~ChannelInfo()
|
||||
--this->founder->channelcount;
|
||||
}
|
||||
|
||||
/** Change the founder of the channek
|
||||
* @params nc The new founder
|
||||
*/
|
||||
void ChannelInfo::SetFounder(NickCore *nc)
|
||||
{
|
||||
if (this->founder)
|
||||
--this->founder->channelcount;
|
||||
this->founder = nc;
|
||||
if (this->founder)
|
||||
++this->founder->channelcount;
|
||||
if (this->founder == this->successor)
|
||||
this->successor = NULL;
|
||||
}
|
||||
|
||||
/** Get the founder of the channel
|
||||
* @return The founder
|
||||
*/
|
||||
NickCore *ChannelInfo::GetFounder() const
|
||||
{
|
||||
return this->founder;
|
||||
}
|
||||
|
||||
/** Find which bot should send mode/topic/etc changes for this channel
|
||||
* @return The bot
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user