summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/mysql/tables.sql29
-rw-r--r--include/extern.h5
-rw-r--r--include/regchannel.h2
-rw-r--r--modules/core/cs_mode.cpp5
-rw-r--r--modules/core/db_plain.cpp94
-rw-r--r--modules/extra/db_mysql.cpp182
-rw-r--r--modules/extra/db_mysql_live.cpp33
-rw-r--r--src/misc.cpp111
-rw-r--r--src/regchannel.cpp83
9 files changed, 133 insertions, 411 deletions
diff --git a/data/mysql/tables.sql b/data/mysql/tables.sql
index b3cf06a00..54699c4c8 100644
--- a/data/mysql/tables.sql
+++ b/data/mysql/tables.sql
@@ -3,7 +3,7 @@
-- http://www.phpmyadmin.net
--
-- Host: localhost
--- Generation Time: Oct 31, 2010 at 03:02 AM
+-- Generation Time: Mar 09, 2011 at 01:23 AM
-- Server version: 5.1.50
-- PHP Version: 5.3.3-pl1-gentoo
@@ -108,10 +108,6 @@ CREATE TABLE IF NOT EXISTS `anope_cs_info` (
`forbidby` text NOT NULL,
`forbidreason` text NOT NULL,
`bantype` smallint(6) NOT NULL DEFAULT '0',
- `mlock_on` text NOT NULL,
- `mlock_off` text NOT NULL,
- `mlock_params` text NOT NULL,
- `mlock_params_off` text NOT NULL,
`memomax` smallint(5) unsigned NOT NULL DEFAULT '0',
`botnick` varchar(255) NOT NULL DEFAULT '',
`botflags` text NOT NULL,
@@ -152,6 +148,22 @@ CREATE TABLE IF NOT EXISTS `anope_cs_levels` (
-- --------------------------------------------------------
--
+-- Table structure for table `anope_cs_mlock`
+--
+
+CREATE TABLE IF NOT EXISTS `anope_cs_mlock` (
+ `channel` varchar(255) NOT NULL,
+ `mode` varchar(127) NOT NULL,
+ `status` int(11) NOT NULL,
+ `setter` varchar(255) NOT NULL,
+ `created` int(11) NOT NULL,
+ `param` varchar(255) NOT NULL,
+ KEY `FK_anope_cs_mlock` (`channel`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+-- --------------------------------------------------------
+
+--
-- Table structure for table `anope_cs_ttb`
--
@@ -395,6 +407,13 @@ ALTER TABLE `anope_cs_levels`
UPDATE CASCADE;
--
+-- Constraints for table `anope_cs_mlock`
+--
+ALTER TABLE `anope_cs_mlock`
+ ADD CONSTRAINT `FK_anope_cs_mlock_channel` FOREIGN KEY (`channel`) REFERENCES `anope_cs_info` (`name`) ON DELETE CASCADE ON
+UPDATE CASCADE;
+
+--
-- Constraints for table `anope_cs_ttb`
--
ALTER TABLE `anope_cs_ttb`
diff --git a/include/extern.h b/include/extern.h
index d670ad331..c158c6381 100644
--- a/include/extern.h
+++ b/include/extern.h
@@ -259,14 +259,9 @@ E char *str_signed(unsigned char *str);
E std::list<Anope::string> BuildStringList(const Anope::string &, char = ' ');
E std::vector<Anope::string> BuildStringVector(const Anope::string &, char = ' ');
-E uint32 cidr_to_netmask(uint16 cidr);
-E uint16 netmask_to_cidr(uint32 mask);
-
E bool str_is_wildcard(const Anope::string &str);
E bool str_is_pure_wildcard(const Anope::string &str);
-E bool str_is_cidr(const Anope::string &str, uint32 &ip, uint32 &mask, Anope::string &host);
-
/**** modes.cpp ****/
/* Number of generic modes we support */
E unsigned GenericChannelModes, GenericUserModes;
diff --git a/include/regchannel.h b/include/regchannel.h
index 5d1735cb3..80277803c 100644
--- a/include/regchannel.h
+++ b/include/regchannel.h
@@ -302,7 +302,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
* @param created When the mlock was created
* @return true on success, false on failure (module blocking)
*/
- bool SetMLock(ChannelMode *mode, bool status, const Anope::string &param = "", const Anope::string &setter = "", time_t created = Anope::CurTime);
+ bool SetMLock(ChannelMode *mode, bool status, const Anope::string &param = "", Anope::string setter = "", time_t created = Anope::CurTime);
/** Remove a mlock
* @param mode The mode
diff --git a/modules/core/cs_mode.cpp b/modules/core/cs_mode.cpp
index 4d3705845..793a04dc2 100644
--- a/modules/core/cs_mode.cpp
+++ b/modules/core/cs_mode.cpp
@@ -129,10 +129,7 @@ class CommandCSMode : public Command
Anope::string modeparam = ml.param;
if (!modeparam.empty())
modeparam = " " + modeparam;
- Anope::string setter = ml.setter;
- if (setter.empty())
- setter = ci->founder ? ci->founder->display : "Unknown";
- source.Reply(_("%c%c%s, by %s on %s"), ml.set ? '+' : '-', cm->ModeChar, modeparam.c_str(), setter.c_str(), do_strftime(ml.created).c_str());
+ source.Reply(_("%c%c%s, by %s on %s"), ml.set ? '+' : '-', cm->ModeChar, modeparam.c_str(), ml.setter.c_str(), do_strftime(ml.created).c_str());
}
}
}
diff --git a/modules/core/db_plain.cpp b/modules/core/db_plain.cpp
index 44b5cbefa..c20a78577 100644
--- a/modules/core/db_plain.cpp
+++ b/modules/core/db_plain.cpp
@@ -614,32 +614,17 @@ class DBPlain : public Module
ak->SetFlag(AK_ISNICK);
}
- else if (key.equals_ci("MLOCK_ON") || key.equals_ci("MLOCK_OFF"))
+ else if (key.equals_ci("MLOCK"))
{
- bool Set = key.equals_ci("MLOCK_ON");
+ std::vector<Anope::string> mlocks;
+ ci->GetExtRegular("db_mlock", mlocks);
- /* For now store mlock in extensible, Anope hasn't yet connected to the IRCd and doesn't know what modes exist */
- ci->Extend(Set ? "db_mlock_modes_on" : "db_mlock_modes_off", new ExtensibleItemRegular<std::vector<Anope::string> >(params));
- }
- else if (key.equals_ci("MLP"))
- {
- std::vector<std::pair<Anope::string, Anope::string> > mlp;
- ci->GetExtRegular("db_mlp", mlp);
-
- mlp.push_back(std::make_pair(params[0], params[1]));
+ Anope::string mlock_string = params[0] + " " + params[1] + " " + params[2] + " " + params[3];
+ if (params.size() > 4)
+ mlock_string += " " + params[4];
- /* For now store mlocked modes in extensible, Anope hasn't yet connected to the IRCd and doesn't know what modes exist */
- ci->Extend("db_mlp", new ExtensibleItemRegular<std::vector<std::pair<Anope::string, Anope::string> > >(mlp));
- }
- else if (key.equals_ci("MLP_OFF"))
- {
- std::vector<std::pair<Anope::string, Anope::string> > mlp;
- ci->GetExtRegular("db_mlp_off", mlp);
-
- mlp.push_back(std::make_pair(params[0], params[1]));
-
- /* For now store mlocked modes in extensible, Anope hasn't yet connected to the IRCd and doesn't know what modes exist */
- ci->Extend("db_mlp_off", new ExtensibleItemRegular<std::vector<std::pair<Anope::string, Anope::string> > >(mlp));
+ mlocks.push_back(mlock_string);
+ ci->Extend("db_mlock", new ExtensibleItemRegular<std::vector<Anope::string> >(mlocks));
}
else if (key.equals_ci("MI"))
{
@@ -832,70 +817,19 @@ class DBPlain : public Module
db_buffer << ci->GetAkick(k)->reason;
db_buffer << endl;
}
- db_buffer << "MD MLOCK_ON";
- {
- std::vector<Anope::string> oldmodes;
- if ((!Me || !Me->IsSynced()) && ci->GetExtRegular("db_mlock_modes_on", oldmodes))
- for (unsigned i = 0; i < oldmodes.size(); ++i)
- db_buffer << " " << oldmodes[i];
- else
- {
- for (std::multimap<ChannelModeName, ModeLock>::const_iterator it = ci->GetMLock().begin(), it_end = ci->GetMLock().end(); it != it_end; ++it)
- {
- const ModeLock &ml = it->second;
- if (ml.set)
- {
- ChannelMode *cm = ModeManager::FindChannelModeByName(ml.name);
- if (!cm || cm->Type != MODE_REGULAR)
- continue;
- db_buffer << " " << cm->NameAsString();
- }
- }
- }
- }
- db_buffer << endl;
- db_buffer << "MD MLOCK_OFF";
- {
- std::vector<Anope::string> oldmodes;
- if ((!Me || !Me->IsSynced()) && ci->GetExtRegular("db_mlock_modes_off", oldmodes))
- for (unsigned i = 0; i < oldmodes.size(); ++i)
- db_buffer << " " << oldmodes[i];
- else
- {
- for (std::multimap<ChannelModeName, ModeLock>::const_iterator it = ci->GetMLock().begin(), it_end = ci->GetMLock().end(); it != it_end; ++it)
- {
- const ModeLock &ml = it->second;
- if (!ml.set)
- {
- ChannelMode *cm = ModeManager::FindChannelModeByName(ml.name);
- if (!cm || cm->Type != MODE_REGULAR)
- continue;
- db_buffer << " " << cm->NameAsString();
- }
- }
- }
- }
- db_buffer << endl;
{
- std::vector<std::pair<Anope::string, Anope::string> > oldparams;;
- if ((!Me || !Me->IsSynced()) && ci->GetExtRegular("db_mlp", oldparams))
- {
- for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = oldparams.begin(), it_end = oldparams.end(); it != it_end; ++it)
- {
- db_buffer << "MD MLP " << it->first << " " << it->second << endl;
- }
- }
+ std::vector<Anope::string> mlocks;
+ if (ci->GetExtRegular("db_mlock", mlocks))
+ for (unsigned i = 0; i < mlocks.size(); ++i)
+ db_buffer << mlocks[i] << endl;
else
{
for (std::multimap<ChannelModeName, ModeLock>::const_iterator it = ci->GetMLock().begin(), it_end = ci->GetMLock().end(); it != it_end; ++it)
{
const ModeLock &ml = it->second;
ChannelMode *cm = ModeManager::FindChannelModeByName(ml.name);
- if (!cm)
- continue;
-
- if (!ml.param.empty())
- db_buffer << "MD MLP" << (ml.set ? " " : "_OFF ") << cm->NameAsString() << " " << ml.param << endl;
+ if (cm != NULL)
+ db_buffer << "MD MLOCK " << (ml.set ? 1 : 0) << " " << cm->NameAsString() << " " << ml.setter << " " << ml.created << " " << ml.param << endl;
}
}
}
diff --git a/modules/extra/db_mysql.cpp b/modules/extra/db_mysql.cpp
index c328bbb9d..57ef498c2 100644
--- a/modules/extra/db_mysql.cpp
+++ b/modules/extra/db_mysql.cpp
@@ -37,76 +37,6 @@ static std::vector<Anope::string> MakeVector(const Anope::string &buf)
return params;
}
-static Anope::string MakeMLock(ChannelInfo *ci, bool status)
-{
- Anope::string ret;
-
- if ((!Me || !Me->IsSynced()) && ci->GetExtRegular(status ? "db_mlock_modes_on" : "db_mlock_modes_off", ret))
- ;
- else
- {
- for (std::multimap<ChannelModeName, ModeLock>::const_iterator it = ci->GetMLock().begin(), it_end = ci->GetMLock().end(); it != it_end; ++it)
- {
- const ModeLock &ml = it->second;
- if (ml.set == status)
- {
- ChannelMode *cm = ModeManager::FindChannelModeByName(ml.name);
- if (!cm || cm->Type != MODE_REGULAR)
- continue;
- ret += " " + cm->NameAsString();
- }
- }
-
- if (!ret.empty())
- ret.erase(ret.begin());
- }
-
- return ret;
-}
-
-static inline Anope::string GetMLockOn(ChannelInfo *ci)
-{
- return MakeMLock(ci, true);
-}
-
-static inline Anope::string GetMLockOff(ChannelInfo *ci)
-{
- return MakeMLock(ci, false);
-}
-
-static Anope::string GetMLockParams(ChannelInfo *ci, bool onoff)
-{
- Anope::string ret;
-
- std::vector<std::pair<Anope::string, Anope::string> > oldparams;;
- if ((!Me || !Me->IsSynced()) && ci->GetExtRegular(onoff ? "db_mlp" : "db_mlp_off", oldparams))
- {
- for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = oldparams.begin(), it_end = oldparams.end(); it != it_end; ++it)
- {
- ret += " " + it->first + " " + it->second;
- }
- }
- else
- {
- for (std::multimap<ChannelModeName, ModeLock>::const_iterator it = ci->GetMLock().begin(), it_end = ci->GetMLock().end(); it != it_end; ++it)
- {
- const ModeLock &ml = it->second;
-
- if (!ml.param.empty() && ml.set == onoff)
- {
- ChannelMode *cm = ModeManager::FindChannelModeByName(ml.name);
- if (cm)
- ret += " " + cm->NameAsString() + " " + ml.param;
- }
- }
- }
-
- if (!ret.empty())
- ret.erase(ret.begin());
-
- return ret;
-}
-
static NickAlias *CurNick = NULL;
static NickCore *CurCore = NULL;
static ChannelInfo *CurChannel = NULL;
@@ -223,7 +153,7 @@ class DBMySQL : public Module
/* ChanServ */
I_OnAccessAdd, I_OnAccessDel, I_OnAccessChange, I_OnAccessClear, I_OnLevelChange,
I_OnChanForbidden, I_OnDelChan, I_OnChanRegistered, I_OnChanSuspend,
- I_OnAkickAdd, I_OnAkickDel,
+ I_OnAkickAdd, I_OnAkickDel, I_OnMLock, I_OnUnMLock,
/* BotServ */
I_OnBotCreate, I_OnBotChange, I_OnBotDelete,
I_OnBotAssign, I_OnBotUnAssign,
@@ -236,7 +166,7 @@ class DBMySQL : public Module
/* HostServ */
I_OnSetVhost, I_OnDeleteVhost
};
- ModuleManager::Attach(i, this, 40);
+ ModuleManager::Attach(i, this, 42);
}
EventReturn OnLoadDatabase()
@@ -428,51 +358,6 @@ class DBMySQL : public Module
ci->botflags.FromString(flags);
}
- if (!r.Get(i, "mlock_on").empty())
- {
- std::vector<Anope::string> modes;
-
- spacesepstream sep(r.Get(i, "mlock_on"));
- Anope::string buf;
- while (sep.GetToken(buf))
- modes.push_back(buf);
-
- ci->Extend("db_mlock_modes_on", new ExtensibleItemRegular<std::vector<Anope::string> >(modes));
- }
- if (!r.Get(i, "mlock_off").empty())
- {
- std::vector<Anope::string> modes;
-
- spacesepstream sep(r.Get(i, "mlock_off"));
- Anope::string buf;
- while (sep.GetToken(buf))
- modes.push_back(buf);
-
- ci->Extend("db_mlock_modes_off", new ExtensibleItemRegular<std::vector<Anope::string> >(modes));
- }
- if (!r.Get(i, "mlock_params").empty())
- {
- std::vector<std::pair<Anope::string, Anope::string> > mlp;
-
- spacesepstream sep(r.Get(i, "mlock_params"));
- Anope::string buf, buf2;
- while (sep.GetToken(buf) && sep.GetToken(buf2))
- mlp.push_back(std::make_pair(buf, buf2));
-
- ci->Extend("db_mlp", new ExtensibleItemRegular<std::vector<std::pair<Anope::string, Anope::string> > >(mlp));
- }
- if (!r.Get(i, "mlock_params_off").empty())
- {
- std::vector<std::pair<Anope::string, Anope::string> > mlp;
-
- spacesepstream sep(r.Get(i, "mlock_params_off"));
- Anope::string buf, buf2;
- while (sep.GetToken(buf) && sep.GetToken(buf2))
- mlp.push_back(std::make_pair(buf, buf2));
-
- ci->Extend("db_mlp_off", new ExtensibleItemRegular<std::vector<std::pair<Anope::string, Anope::string> > >(mlp));
- }
-
if (!r.Get(i, "flags").empty())
{
spacesepstream sep(r.Get(i, "flags"));
@@ -573,7 +458,7 @@ class DBMySQL : public Module
ci->levels[atoi(r.Get(i, "position").c_str())] = atoi(r.Get(i, "level").c_str());
}
- r = SQL->RunQuery("SELECT * FROM `anope_cs_info_metadata");
+ r = SQL->RunQuery("SELECT * FROM `anope_cs_info_metadata`");
for (int i = 0; i < r.Rows(); ++i)
{
ChannelInfo *ci = cs_findchan(r.Get(i, "channel"));
@@ -588,6 +473,26 @@ class DBMySQL : public Module
FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(ci, ci->name, Params));
}
+ r = SQL->RunQuery("SELECT * FROM `anope_cs_mlock`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ ChannelInfo *ci = cs_findchan(r.Get(i, "channel"));
+ if (!ci)
+ {
+ Log() << "MySQL: Channel mlock for nonexistant channel " << r.Get(i, "channel");
+ continue;
+ }
+
+ std::vector<Anope::string> mlocks;
+ ci->GetExtRegular("db_mlock", mlocks);
+
+ Anope::string modestring = r.Get(i, "status") + " " + r.Get(i, "mode") + " " + r.Get(i, "setter") + " " + r.Get(i, "created") + " " + r.Get(i, "param");
+
+ mlocks.push_back(modestring);
+
+ ci->Extend("db_mlock", new ExtensibleItemRegular<std::vector<Anope::string> >(mlocks));
+ }
+
r = SQL->RunQuery("SELECT * FROM `anope_ms_info`");
for (int i = 0; i < r.Rows(); ++i)
{
@@ -806,13 +711,6 @@ class DBMySQL : public Module
{
this->RunQuery("UPDATE `anope_cs_info` SET `descr` = '" + this->Escape(ci->desc) + "' WHERE `name` = '" + this->Escape(ci->name) + "'");
}
- else if (params[1].equals_ci("MLOCK"))
- {
- this->RunQuery("UPDATE `anope_cs_info` SET `mlock_on` = '" + GetMLockOn(ci) + "' WHERE `name` = '" + this->Escape(ci->name) + "'");
- this->RunQuery("UPDATE `anope_cs_info` SET `mlock_off` = '" + GetMLockOff(ci) + "' WHERE `name` = '" + this->Escape(ci->name) + "'");
- this->RunQuery("UPDATE `anope_cs_info` SET `mlock_params` = '" + GetMLockParams(ci, true) + "' WHERE `name` = '" + this->Escape(ci->name) + "'");
- this->RunQuery("UPDATE `anope_cs_info` SET `mlock_params_off` = '" + GetMLockParams(ci, false) + "' WHERE `name` = '" + this->Escape(ci->name) + "'");
- }
else if (params[1].equals_ci("BANTYPE"))
{
this->RunQuery("UPDATE `anope_cs_info` SET `bantype` = " + stringify(ci->bantype) + " WHERE `name` = '" + this->Escape(ci->name) + "'");
@@ -1022,17 +920,25 @@ class DBMySQL : public Module
void OnChanRegistered(ChannelInfo *ci)
{
- Anope::string mlockon = GetMLockOn(ci), mlockoff = GetMLockOff(ci), mlockparams = GetMLockParams(ci, true), mlockparams_off = GetMLockParams(ci, false);
- this->RunQuery("INSERT INTO `anope_cs_info` (name, founder, successor, descr, time_registered, last_used, last_topic, last_topic_setter, last_topic_time, flags, forbidby, forbidreason, bantype, mlock_on, mlock_off, mlock_params, mlock_params_off, memomax, botnick, botflags, capsmin, capspercent, floodlines, floodsecs, repeattimes) VALUES('" +
+ this->RunQuery("INSERT INTO `anope_cs_info` (name, founder, successor, descr, time_registered, last_used, last_topic, last_topic_setter, last_topic_time, flags, forbidby, forbidreason, bantype, memomax, botnick, botflags, capsmin, capspercent, floodlines, floodsecs, repeattimes) VALUES('" +
this->Escape(ci->name) + "', '" + this->Escape(ci->founder ? ci->founder->display : "") + "', '" +
this->Escape(ci->successor ? ci->successor->display : "") + "', '" + this->Escape(ci->desc) + "', " +
stringify(ci->time_registered) + ", " + stringify(ci->last_used) + ", '" + this->Escape(ci->last_topic) + "', '" +
this->Escape(ci->last_topic_setter) + "', " + stringify(ci->last_topic_time) + ", '" + ToString(ci->ToString()) + "', '" +
- this->Escape(ci->forbidby) + "', '" + this->Escape(ci->forbidreason) + "', " + stringify(ci->bantype) + ", '" +
- mlockon + "', '" + mlockoff + "', '" + mlockparams + "', '" + mlockparams_off + "', " +
+ this->Escape(ci->forbidby) + "', '" + this->Escape(ci->forbidreason) + "', " + stringify(ci->bantype) + ", " +
stringify(ci->memos.memomax) + ", '" + this->Escape(ci->bi ? ci->bi->nick : "") + "', '" + ToString(ci->botflags.ToString()) +
"', " + stringify(ci->capsmin) + ", " + stringify(ci->capspercent) + ", " + stringify(ci->floodlines) + ", " + stringify(ci->floodsecs) + ", " + stringify(ci->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), forbidby=VALUES(forbidby), forbidreason=VALUES(forbidreason), bantype=VALUES(bantype), mlock_on=VALUES(mlock_on), mlock_off=VALUES(mlock_off), mlock_params=VALUES(mlock_params), memomax=VALUES(memomax), botnick=VALUES(botnick), botflags=VALUES(botflags), capsmin=VALUES(capsmin), capspercent=VALUES(capspercent), floodlines=VALUES(floodlines), floodsecs=VALUES(floodsecs), repeattimes=VALUES(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), forbidby=VALUES(forbidby), forbidreason=VALUES(forbidreason), 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)");
+
+ this->RunQuery("DELETE from `anope_cs_mlock` WHERE `channel` = '" + this->Escape(ci->name) + "'");
+ for (std::multimap<ChannelModeName, ModeLock>::const_iterator it = ci->GetMLock().begin(), it_end = ci->GetMLock().end(); it != it_end; ++it)
+ {
+ const ModeLock &ml = it->second;
+ ChannelMode *cm = ModeManager::FindChannelModeByName(ml.name);
+
+ if (cm != NULL)
+ this->RunQuery("INSERT INTO `anope_cs_mlock` (channel, mode, status, setter, created, param) VALUES('" + this->Escape(ci->name) + "', '" + cm->NameAsString() + "', " + stringify(ml.set ? 1 : 0) + ", '" + this->Escape(ml.setter) + "', " + stringify(ml.created) + ", '" + this->Escape(ml.param) + "')");
+ }
}
void OnChanSuspend(ChannelInfo *ci)
@@ -1055,6 +961,22 @@ class DBMySQL : public Module
this->RunQuery("DELETE FROM `anope_cs_akick` WHERE `channel`= '" + this->Escape(ci->name) + "' AND `mask` = '" + (ak->HasFlag(AK_ISNICK) ? ak->nc->display : ak->mask));
}
+ EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock)
+ {
+ ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name);
+ if (cm != NULL)
+ this->RunQuery("INSERT INTO `anope_cs_mlock` (channel, mode, status, setter, created, param) VALUES('" + this->Escape(ci->name) + "', '" + cm->NameAsString() + "', " + stringify(lock->set ? 1 : 0) + ", '" + this->Escape(lock->setter) + "', " + stringify(lock->created) + ", '" + this->Escape(lock->param) + "')");
+ return EVENT_CONTINUE;
+ }
+
+ EventReturn OnUnMLock(ChannelInfo *ci, ChannelMode *mode, const Anope::string &param)
+ {
+ ChannelMode *cm = ModeManager::FindChannelModeByName(mode->Name);
+ if (cm != NULL)
+ this->RunQuery("DELETE FROM `anope_cs_mlock` WHERE `channel` = '" + this->Escape(ci->name) + "' AND `mode` = '" + mode->NameAsString() + "' AND `param` = '" + this->Escape(param) + "'");
+ return EVENT_CONTINUE;
+ }
+
void OnBotCreate(BotInfo *bi)
{
this->RunQuery("INSERT INTO `anope_bs_core` (nick, user, host, rname, flags, created, chancount) VALUES('" +
diff --git a/modules/extra/db_mysql_live.cpp b/modules/extra/db_mysql_live.cpp
index 16467936d..1b688f439 100644
--- a/modules/extra/db_mysql_live.cpp
+++ b/modules/extra/db_mysql_live.cpp
@@ -51,39 +51,6 @@ static void ChanInfoUpdate(const SQLResult &res)
ci->bantype = convertTo<int>(res.Get(0, "bantype"));
ci->memos.memomax = convertTo<unsigned>(res.Get(0, "memomax"));
- Anope::string mlock_on = res.Get(0, "mlock_on"),
- mlock_off = res.Get(0, "mlock_off"),
- mlock_params = res.Get(0, "mlock_params"),
- mlock_params_off = res.Get(0, "mlock_params_off");
-
- Anope::string mode;
- std::vector<Anope::string> modes;
-
- spacesepstream sep(mlock_on);
- while (sep.GetToken(mode))
- modes.push_back(mode);
- ci->Extend("db_mlock_modes_on", new ExtensibleItemRegular<std::vector<Anope::string> >(modes));
-
- modes.clear();
- sep = mlock_off;
- while (sep.GetToken(mode))
- modes.push_back(mode);
- ci->Extend("db_mlock_modes_off", new ExtensibleItemRegular<std::vector<Anope::string> >(modes));
-
- modes.clear();
- sep = mlock_params;
- while (sep.GetToken(mode))
- modes.push_back(mode);
- ci->Extend("mlock_params", new ExtensibleItemRegular<std::vector<Anope::string> >(modes));
-
- modes.clear();
- sep = mlock_params_off;
- while (sep.GetToken(mode))
- modes.push_back(mode);
- ci->Extend("mlock_params_off", new ExtensibleItemRegular<std::vector<Anope::string> >(modes));
-
- ci->LoadMLock();
-
if (res.Get(0, "botnick").equals_cs(ci->bi ? ci->bi->nick : "") == false)
{
if (ci->bi)
diff --git a/src/misc.cpp b/src/misc.cpp
index 0ad233402..431f6bc03 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -1050,37 +1050,6 @@ bool SupportedWindowsVersion()
#endif
/*************************************************************************/
-/* This 2 functions were originally found in Bahamut */
-
-/**
- * Turn a cidr value into a netmask
- * @param cidr CIDR value
- * @return Netmask value
- */
-uint32 cidr_to_netmask(uint16 cidr)
-{
- if (!cidr)
- return 0;
-
- return 0xFFFFFFFF - (1 << (32 - cidr)) + 1;
-}
-
-/**
- * Turn a netmask into a cidr value
- * @param mask Netmask
- * @return CIDR value
- */
-uint16 netmask_to_cidr(uint32 mask)
-{
- int tmp = 0;
-
- while (!(mask & (1 << tmp)) && tmp < 32)
- ++tmp;
-
- return 32 - tmp;
-}
-
-/*************************************************************************/
/**
* Check if the given string is some sort of wildcard
@@ -1104,86 +1073,6 @@ bool str_is_pure_wildcard(const Anope::string &str)
/*************************************************************************/
-/**
- * Check if the given string is an IP or CIDR mask, and fill the given
- * ip/cidr params if so.
- * @param str String to check
- * @param ip The ipmask to fill when a CIDR is found
- * @param mask The CIDR mask to fill when a CIDR is found
- * @param host Displayed host
- * @return 1 for IP/CIDR, 0 for anything else
- */
-bool str_is_cidr(const Anope::string &str, uint32 &ip, uint32 &mask, Anope::string &host)
-{
- int octets[4] = { -1, -1, -1, -1 };
- std::vector<Anope::string> octets_str = BuildStringVector(str, '.');
-
- if (octets_str.size() != 4)
- return false;
-
- Anope::string cidr_str;
- for (unsigned i = 0; i < 4; ++i)
- {
- Anope::string octet = octets_str[i];
-
- if (i == 3)
- {
- size_t slash = octet.find('/');
- if (slash != Anope::string::npos)
- {
- cidr_str = octet.substr(slash + 1);
- octet = octet.substr(0, slash);
- }
- }
-
- if (!octet.is_number_only())
- return false;
-
- octets[i] = convertTo<int>(octet);
- /* Bail out if the octet is invalid or wrongly terminated */
- if (octets[i] < 0 || octets[i] > 255)
- return false;
- }
-
- /* Fill the IP - the dirty way */
- ip = octets[3];
- ip += octets[2] * 256;
- ip += octets[1] * 65536;
- ip += octets[0] * 16777216;
-
- uint16 cidr;
- if (!cidr_str.empty())
- {
- Anope::string s;
- /* There's a CIDR mask here! */
- cidr = convertTo<uint16>(cidr_str.substr(1), s, false);
- /* Bail out if the CIDR is invalid or the string isn't done yet */
- if (cidr > 32 || !s.empty())
- return false;
- }
- else
- /* No CIDR mask here - use 32 so the whole ip will be matched */
- cidr = 32;
-
- mask = cidr_to_netmask(cidr);
- /* Apply the mask to avoid 255.255.255.255/8 bans */
- ip &= mask;
-
- /* Refill the octets to fill the host */
- octets[0] = (ip & 0xFF000000) / 16777216;
- octets[1] = (ip & 0x00FF0000) / 65536;
- octets[2] = (ip & 0x0000FF00) / 256;
- octets[3] = (ip & 0x000000FF);
-
- host = stringify(octets[0]) + "." + stringify(octets[1]) + "." + stringify(octets[2]) + "." + stringify(octets[3]);
- if (cidr != 32)
- host += "/" + stringify(cidr);
-
- return true;
-}
-
-/********************************************************************************/
-
/** Converts a string to hex
* @param the data to be converted
* @return a anope::string containing the hex value
diff --git a/src/regchannel.cpp b/src/regchannel.cpp
index 20cfc7aed..a5788d9af 100644
--- a/src/regchannel.cpp
+++ b/src/regchannel.cpp
@@ -501,52 +501,30 @@ void ChannelInfo::LoadMLock()
if (chm)
this->SetMLock(chm, true);
- std::vector<Anope::string> modenames;
- if (this->GetExtRegular("db_mlock_modes_on", modenames))
+ std::vector<Anope::string> mlock;
+ if (this->GetExtRegular("db_mlock", mlock))
{
- for (std::vector<Anope::string>::iterator it = modenames.begin(), it_end = modenames.end(); it != it_end; ++it)
+ for (unsigned i = 0; i < mlock.size(); ++i)
{
- ChannelMode *m = ModeManager::FindChannelModeByString(*it);
- if (m)
- this->SetMLock(m, true);
- }
- }
+ std::vector<Anope::string> mlockv = BuildStringVector(mlock[i]);
- if (this->GetExtRegular("db_mlock_modes_off", modenames))
- {
- for (std::vector<Anope::string>::iterator it = modenames.begin(), it_end = modenames.end(); it != it_end; ++it)
- {
- ChannelMode *m = ModeManager::FindChannelModeByString(*it);
- if (m)
- this->SetMLock(m, false);
- }
- }
+ bool set = mlockv[0] == "1";
+ ChannelMode *cm = ModeManager::FindChannelModeByString(mlockv[1]);
+ const Anope::string &setter = mlockv[2];
+ time_t created = Anope::CurTime;
+ try
+ {
+ created = convertTo<time_t>(mlockv[3]);
+ }
+ catch (const ConvertException &) { }
+ const Anope::string &param = mlockv.size() > 4 ? mlockv[4] : "";
- std::vector<std::pair<Anope::string, Anope::string> > params;
- if (this->GetExtRegular("db_mlp", params))
- {
- for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = params.begin(), it_end = params.end(); it != it_end; ++it)
- {
- ChannelMode *m = ModeManager::FindChannelModeByString(it->first);
- if (m)
- this->SetMLock(m, true, it->second);
- }
-
- }
- if (this->GetExtRegular("db_mlp_off", params))
- {
- for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = params.begin(), it_end = params.end(); it != it_end; ++it)
- {
- ChannelMode *m = ModeManager::FindChannelModeByString(it->first);
- if (m)
- this->SetMLock(m, false, it->second);
+ if (cm != NULL)
+ this->SetMLock(cm, set, param, setter, created);
}
- }
- this->Shrink("db_mlock_modes_on");
- this->Shrink("db_mlock_modes_off");
- this->Shrink("db_mlp");
- this->Shrink("db_mlp_off");
+ this->Shrink("db_mlock");
+ }
/* Create perm channel */
if (this->HasFlag(CI_PERSIST) && !this->c)
@@ -605,8 +583,10 @@ bool ChannelInfo::HasMLock(ChannelMode *mode, const Anope::string &param, bool s
* @param param The param to use for this mode, if required
* @return true on success, false on failure (module blocking)
*/
-bool ChannelInfo::SetMLock(ChannelMode *mode, bool status, const Anope::string &param, const Anope::string &setter, time_t created)
+bool ChannelInfo::SetMLock(ChannelMode *mode, bool status, const Anope::string &param, Anope::string setter, time_t created)
{
+ if (setter.empty())
+ setter = this->founder ? this->founder->display : "Unknown";
std::pair<ChannelModeName, ModeLock> ml = std::make_pair(mode->Name, ModeLock(status, mode->Name, param, setter, created));
EventReturn MOD_RESULT;
@@ -615,7 +595,26 @@ bool ChannelInfo::SetMLock(ChannelMode *mode, bool status, const Anope::string &
return false;
/* First, remove this */
- this->RemoveMLock(mode, param);
+ if (mode->Type == MODE_REGULAR || mode->Type == MODE_PARAM)
+ this->mode_locks.erase(mode->Name);
+ else
+ {
+ // For list or status modes, we must check the parameter
+ std::multimap<ChannelModeName, ModeLock>::iterator it = this->mode_locks.find(mode->Name);
+ if (it != this->mode_locks.end())
+ {
+ std::multimap<ChannelModeName, ModeLock>::iterator it_end = this->mode_locks.upper_bound(mode->Name);
+ for (; it != it_end; ++it)
+ {
+ const ModeLock &modelock = it->second;
+ if (modelock.param == param)
+ {
+ this->mode_locks.erase(it);
+ break;
+ }
+ }
+ }
+ }
this->mode_locks.insert(ml);