mirror of
https://github.com/anope/anope.git
synced 2026-07-02 13:33:12 +02:00
Store the setter and ts for all modes and try to restore them.
This is mostly for preserving channel list mode info.
This commit is contained in:
@@ -128,13 +128,19 @@ private:
|
||||
|
||||
const NickCore *nc = anope_dynamic_static_cast<const NickCore *>(s);
|
||||
Anope::string modes;
|
||||
for (const auto &[last_mode, last_value] : nc->last_modes)
|
||||
for (const auto &[last_mode, last_data] : nc->last_modes)
|
||||
{
|
||||
if (!modes.empty())
|
||||
modes += " ";
|
||||
|
||||
modes += '+';
|
||||
modes += last_mode;
|
||||
if (!last_value.empty())
|
||||
modes += "," + last_value;
|
||||
if (!last_data.value.empty())
|
||||
{
|
||||
modes += "," + Anope::ToString(last_data.set_at);
|
||||
modes += "," + last_data.set_by;
|
||||
modes += "," + last_data.value;
|
||||
}
|
||||
}
|
||||
data.Store("last_modes", modes);
|
||||
}
|
||||
@@ -152,11 +158,32 @@ private:
|
||||
nc->last_modes.clear();
|
||||
for (spacesepstream sep(modes); sep.GetToken(modes);)
|
||||
{
|
||||
size_t c = modes.find(',');
|
||||
if (c == Anope::string::npos)
|
||||
nc->last_modes.emplace(modes, "");
|
||||
if (modes[0] == '+')
|
||||
{
|
||||
commasepstream mode(modes, true);
|
||||
mode.GetToken(modes);
|
||||
modes.erase(0, 1);
|
||||
|
||||
ModeData info;
|
||||
Anope::string set_at;
|
||||
mode.GetToken(set_at);
|
||||
info.set_at = Anope::Convert(set_at, 0);
|
||||
mode.GetToken(info.set_by);
|
||||
info.value = mode.GetRemaining();
|
||||
|
||||
nc->last_modes.emplace(modes, info);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
nc->last_modes.emplace(modes.substr(0, c), modes.substr(c + 1));
|
||||
{
|
||||
// Begin 2.0 compatibility
|
||||
size_t c = modes.find(',');
|
||||
if (c == Anope::string::npos)
|
||||
nc->last_modes.emplace(modes, ModeData());
|
||||
else
|
||||
nc->last_modes.emplace(modes.substr(0, c), ModeData(modes.substr(c + 1)));
|
||||
// End 2.0 compatibility.
|
||||
}
|
||||
}
|
||||
}
|
||||
} keep_modes;
|
||||
@@ -197,11 +224,11 @@ public:
|
||||
{
|
||||
const auto norestore = Config->GetModule(this).Get<const Anope::string>("norestore");
|
||||
User::ModeList modes = u->Account()->last_modes;
|
||||
for (const auto &[last_mode, last_value] : modes)
|
||||
for (const auto &[last_mode, last_data] : modes)
|
||||
{
|
||||
auto *um = ModeManager::FindUserModeByName(last_mode);
|
||||
if (um && um->CanSet(nullptr) && norestore.find(um->mchar) == Anope::string::npos)
|
||||
u->SetMode(nullptr, last_mode, last_value);
|
||||
u->SetMode(nullptr, last_mode, last_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user