summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2010-10-04 18:57:54 -0400
committerAdam <Adam@anope.org>2010-10-04 18:57:54 -0400
commit592060ac756dd7ac5983aac987264ff5eaecd265 (patch)
tree84143f0773fb4ba2887fa724c440c5fbb9c57f61
parent92338c13b871378b8e828085b8b724d4217649a8 (diff)
Attempt to write back the old mlock to the databases if we try and fail to connect to the uplink. Because we may not know modes until after we are synced we could accidentally nuke all of the mlocks
-rw-r--r--modules/core/db_plain.cpp54
-rw-r--r--modules/extra/db_mysql.cpp40
-rw-r--r--src/regchannel.cpp5
3 files changed, 74 insertions, 25 deletions
diff --git a/modules/core/db_plain.cpp b/modules/core/db_plain.cpp
index 432313bc2..af342786f 100644
--- a/modules/core/db_plain.cpp
+++ b/modules/core/db_plain.cpp
@@ -976,11 +976,20 @@ class DBPlain : public Module
if (ci->GetMLockCount(true))
{
db << "MD MLOCK_ON";
- for (std::map<char, ChannelMode *>::iterator it = ModeManager::ChannelModesByChar.begin(), it_end = ModeManager::ChannelModesByChar.end(); it != it_end; ++it)
+
+ Anope::string oldmodes;
+ if ((!Me || !Me->IsSynced()) && ci->GetExtRegular("db_mlock_modes_on", oldmodes))
{
- ChannelMode *cm = it->second;
- if (ci->HasMLock(cm->Name, true))
- db << " " << cm->NameAsString;
+ db << " " << oldmodes;
+ }
+ else
+ {
+ for (std::map<char, ChannelMode *>::iterator it = ModeManager::ChannelModesByChar.begin(), it_end = ModeManager::ChannelModesByChar.end(); it != it_end; ++it)
+ {
+ ChannelMode *cm = it->second;
+ if (ci->HasMLock(cm->Name, true))
+ db << " " << cm->NameAsString;
+ }
}
db << endl;
}
@@ -988,21 +997,40 @@ class DBPlain : public Module
{
db << "MD MLOCK_OFF";
- for (std::map<char, ChannelMode *>::iterator it = ModeManager::ChannelModesByChar.begin(), it_end = ModeManager::ChannelModesByChar.end(); it != it_end; ++it)
+ Anope::string oldmodes;
+ if ((!Me || !Me->IsSynced()) && ci->GetExtRegular("db_mlock_modes_off", oldmodes))
{
- ChannelMode *cm = it->second;
- if (ci->HasMLock(cm->Name, false))
- db << " " << cm->NameAsString;
+ db << " " << oldmodes;
+ }
+ else
+ {
+ for (std::map<char, ChannelMode *>::iterator it = ModeManager::ChannelModesByChar.begin(), it_end = ModeManager::ChannelModesByChar.end(); it != it_end; ++it)
+ {
+ ChannelMode *cm = it->second;
+ if (ci->HasMLock(cm->Name, false))
+ db << " " << cm->NameAsString;
+ }
}
db << endl;
}
- for (std::map<char, ChannelMode *>::iterator it = ModeManager::ChannelModesByChar.begin(), it_end = ModeManager::ChannelModesByChar.end(); it != it_end; ++it)
+ 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 << "MD MLP " << it->first << " " << it->second << endl;
+ }
+ }
+ else
{
- ChannelMode *cm = it->second;
- Anope::string Param;
+ for (std::map<char, ChannelMode *>::iterator it = ModeManager::ChannelModesByChar.begin(), it_end = ModeManager::ChannelModesByChar.end(); it != it_end; ++it)
+ {
+ ChannelMode *cm = it->second;
+ Anope::string Param;
- if (ci->GetParam(cm->Name, Param))
- db << "MD MLP " << cm->NameAsString << " " << Param << endl;
+ if (ci->GetParam(cm->Name, Param))
+ db << "MD MLP " << cm->NameAsString << " " << Param << endl;
+ }
}
if (!ci->memos.memos.empty())
{
diff --git a/modules/extra/db_mysql.cpp b/modules/extra/db_mysql.cpp
index 274f653b2..cd901e9e4 100644
--- a/modules/extra/db_mysql.cpp
+++ b/modules/extra/db_mysql.cpp
@@ -199,15 +199,20 @@ static Anope::string MakeMLock(ChannelInfo *ci, bool status)
{
Anope::string ret;
- for (std::map<char, ChannelMode *>::iterator it = ModeManager::ChannelModesByChar.begin(), it_end = ModeManager::ChannelModesByChar.end(); it != it_end; ++it)
+ if ((!Me || !Me->IsSynced()) && ci->GetExtRegular(status ? "db_mlock_modes_on" : "db_mlock_modes_off", ret))
+ ;
+ else
{
- ChannelMode *cm = it->second;
- if (ci->HasMLock(cm->Name, status))
- ret += " " + cm->NameAsString;
- }
+ for (std::map<char, ChannelMode *>::iterator it = ModeManager::ChannelModesByChar.begin(), it_end = ModeManager::ChannelModesByChar.end(); it != it_end; ++it)
+ {
+ ChannelMode *cm = it->second;
+ if (ci->HasMLock(cm->Name, status))
+ ret += " " + cm->NameAsString;
+ }
- if (!ret.empty())
- ret.erase(ret.begin());
+ if (!ret.empty())
+ ret.erase(ret.begin());
+ }
return ret;
}
@@ -226,13 +231,24 @@ static Anope::string GetMLockParams(ChannelInfo *ci)
{
Anope::string ret;
- for (std::map<char, ChannelMode *>::iterator it = ModeManager::ChannelModesByChar.begin(), it_end = ModeManager::ChannelModesByChar.end(); it != it_end; ++it)
+ std::vector<std::pair<Anope::string, Anope::string> > oldparams;;
+ if ((!Me || !Me->IsSynced()) && ci->GetExtRegular("db_mlp", oldparams))
{
- ChannelMode *cm = it->second;
+ 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::map<char, ChannelMode *>::iterator it = ModeManager::ChannelModesByChar.begin(), it_end = ModeManager::ChannelModesByChar.end(); it != it_end; ++it)
+ {
+ ChannelMode *cm = it->second;
- Anope::string param;
- if (ci->GetParam(cm->Name, param))
- ret += " " + cm->NameAsString + " " + param;
+ Anope::string param;
+ if (ci->GetParam(cm->Name, param))
+ ret += " " + cm->NameAsString + " " + param;
+ }
}
if (!ret.empty())
diff --git a/src/regchannel.cpp b/src/regchannel.cpp
index 9bb79b8cc..053f75d5b 100644
--- a/src/regchannel.cpp
+++ b/src/regchannel.cpp
@@ -387,8 +387,13 @@ void ChannelInfo::LoadMLock()
this->SetMLock(cm->Name, true, it->second);
}
}
+
}
+ this->Shrink("db_mlock_modes_on");
+ this->Shrink("db_mlock_modes_off");
+ this->Shrink("db_mlp");
+
/* Create perm channel */
if (this->HasFlag(CI_PERSIST) && !this->c)
{