summaryrefslogtreecommitdiff
path: root/modules/extra/sql_oper.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2016-10-01 10:34:32 -0400
committerAdam <Adam@anope.org>2016-10-01 10:34:39 -0400
commit806f77760b3ef764218926a3d3a12957dd2daa70 (patch)
tree182907ae5c61e49cd70ea3f74749e758318a934b /modules/extra/sql_oper.cpp
parentddfe45c4d9cad8999b7f11ea623149aa441e1b58 (diff)
sql_oper: deoper users more reliably
Diffstat (limited to 'modules/extra/sql_oper.cpp')
-rw-r--r--modules/extra/sql_oper.cpp40
1 files changed, 31 insertions, 9 deletions
diff --git a/modules/extra/sql_oper.cpp b/modules/extra/sql_oper.cpp
index a82d1f258..17c825828 100644
--- a/modules/extra/sql_oper.cpp
+++ b/modules/extra/sql_oper.cpp
@@ -31,6 +31,18 @@ class SQLOperResult : public SQL::Interface
~SQLOperResultDeleter() { delete res; }
};
+ void Deoper()
+ {
+ if (user->Account()->o && user->Account()->o->owner == this->owner)
+ {
+ user->Account()->o->Delete();
+ user->Account()->o = nullptr;
+
+ Log(this->owner) << "Removed services operator from " << user->nick << " (" << user->Account()->GetDisplay() << ")";
+ user->RemoveMode(Config->GetClient("OperServ"), "OPER"); // Probably not set, just incase
+ }
+ }
+
public:
SQLOperResult(Module *m, User *u) : SQL::Interface(m), user(u) { }
@@ -38,9 +50,16 @@ class SQLOperResult : public SQL::Interface
{
SQLOperResultDeleter d(this);
- if (!user || !user->Account() || r.Rows() == 0)
+ if (!user || !user->Account())
return;
+ if (r.Rows() == 0)
+ {
+ Log(LOG_DEBUG) << "m_sql_oper: Got 0 rows for " << user->nick;
+ Deoper();
+ return;
+ }
+
Anope::string opertype;
try
{
@@ -48,6 +67,7 @@ class SQLOperResult : public SQL::Interface
}
catch (const SQL::Exception &)
{
+ Log(this->owner) << "Expected column named \"opertype\" but one was not found";
return;
}
@@ -63,14 +83,7 @@ class SQLOperResult : public SQL::Interface
ServiceBot *OperServ = Config->GetClient("OperServ");
if (opertype.empty())
{
- if (user->Account()->o && user->Account()->o->owner == this->owner)
- {
- user->Account()->o->Delete();
- user->Account()->o = nullptr;
-
- Log(this->owner) << "m_sql_oper: Removed services operator from " << user->nick << " (" << user->Account()->GetDisplay() << ")";
- user->RemoveMode(OperServ, "OPER"); // Probably not set, just incase
- }
+ Deoper();
return;
}
@@ -81,10 +94,19 @@ class SQLOperResult : public SQL::Interface
return;
}
+ if (user->Account()->o && user->Account()->o->owner != this->owner)
+ {
+ Log(this->owner) << "Oper " << user->Account()->GetDisplay() << " has type " << ot->GetName() << ", but is already configured as an oper of type " << user->Account()->o->GetType()->GetName();
+ return;
+ }
+
if (!user->Account()->o || user->Account()->o->GetType() != ot)
{
Log(this->owner) << "m_sql_oper: Tieing oper " << user->nick << " to type " << opertype;
+ if (user->Account()->o)
+ user->Account()->o->Delete();
+
Oper *o = Serialize::New<Oper *>();
o->owner = this->owner;
o->SetName(user->Account()->GetDisplay());