summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-03-09 01:25:49 -0500
committerAdam <Adam@anope.org>2011-03-09 01:25:49 -0500
commite9aa04a8f497bdd6675d9d3ca2d25ba6110c3008 (patch)
tree260cb256ffcae43697ab8118c64e84a36731f9d9 /src
parent8eb23e7d489239e8af79c2d6da587cd1c3a81b5d (diff)
Store mlock in the databases and removed some unused functions from misc.cpp
Diffstat (limited to 'src')
-rw-r--r--src/misc.cpp111
-rw-r--r--src/regchannel.cpp83
2 files changed, 41 insertions, 153 deletions
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);