1
0
mirror of https://github.com/anope/anope.git synced 2026-07-08 06:23:13 +02:00

Add m_sql_oper

This commit is contained in:
Adam
2012-10-13 00:32:29 -04:00
parent 76a0471c29
commit 4424abd15d
6 changed files with 154 additions and 1 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ struct CoreExport Oper
std::vector<Anope::string> hosts;
Anope::string vhost;
Oper(const Anope::string &n, OperType *o) : name(n), ot(o) { this->config = false; }
Oper(const Anope::string &n, OperType *o) : name(n), ot(o), require_oper(false), config(false) { }
virtual ~Oper() { }
+5
View File
@@ -120,6 +120,11 @@ class CoreExport IRCDProto
* On most TS6 IRCds this is a SJOIN with no nick
*/
virtual void SendChannel(Channel *c) { }
/** Make the user an IRC operator
* Normally this is a simple +o, though some IRCds require us to send the oper type
*/
virtual void SendOper(User *u);
};
enum IRCDMessageFlag
+135
View File
@@ -0,0 +1,135 @@
#include "module.h"
#include "sql.h"
class SQLOperResult : public SQLInterface
{
dynamic_reference<User> user;
struct SQLOperResultDeleter
{
SQLOperResult *res;
SQLOperResultDeleter(SQLOperResult *r) : res(r) { }
~SQLOperResultDeleter() { delete res; }
};
public:
SQLOperResult(Module *m, User *u) : SQLInterface(m), user(u) { }
void OnResult(const SQLResult &r) anope_override
{
SQLOperResultDeleter d(this);
if (!user || !user->Account() || r.Rows() == 0)
return;
Anope::string opertype;
try
{
opertype = r.Get(0, "opertype");
}
catch (const SQLException &)
{
return;
}
Log(LOG_DEBUG) << "m_sql_oper: Got result for " << user->nick << ", opertype " << opertype;
Anope::string modes;
try
{
modes = r.Get(0, "modes");
}
catch (const SQLException &) { }
if (opertype.empty())
{
if (user->Account() && user->Account()->o && !user->Account()->o->config)
{
std::vector<Oper *>::iterator it = std::find(Config->Opers.begin(), Config->Opers.end(), user->Account()->o);
if (it != Config->Opers.end())
Config->Opers.erase(it);
delete user->Account()->o;
user->Account()->o = NULL;
Log() << "m_sql_oper: Removed services operator from " << user->nick << " (" << user->Account()->display << ")";
user->RemoveMode(findbot(Config->OperServ), UMODE_OPER); // Probably not set, just incase
}
return;
}
OperType *ot = OperType::Find(opertype);
if (ot == NULL)
{
Log() << "m_sql_oper: Oper " << user->nick << " has type " << opertype << ", but this opertype does not exist?";
return;
}
if (!user->Account()->o || user->Account()->o->ot != ot)
{
Log() << "m_sql_oper: Tieing oper " << user->nick << " to type " << opertype;
user->Account()->o = new Oper(user->Account()->display, ot);
Config->Opers.push_back(user->Account()->o);
}
if (!user->HasMode(UMODE_OPER))
{
ircdproto->SendOper(user);
if (!modes.empty())
user->SetModes(findbot(Config->OperServ), "%s", modes.c_str());
}
}
void OnError(const SQLResult &r) anope_override
{
SQLOperResultDeleter d(this);
Log() << "m_sql_oper: Error executing query " << r.GetQuery().query << ": " << r.GetError();
}
};
class ModuleSQLOper : public Module
{
Anope::string engine;
Anope::string query;
service_reference<SQLProvider> SQL;
public:
ModuleSQLOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED)
{
this->SetAuthor("Anope");
Implementation i[] = { I_OnReload, I_OnNickIdentify };
ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
this->OnReload();
}
void OnReload() anope_override
{
ConfigReader config;
this->engine = config.ReadValue("m_sql_oper", "engine", "", 0);
this->query = config.ReadValue("m_sql_oper", "query", "", 0);
this->SQL = service_reference<SQLProvider>("SQLProvider", this->engine);
}
void OnNickIdentify(User *u) anope_override
{
if (!this->SQL)
{
Log() << "m_sql_oper: Unable to find SQL engine";
return;
}
SQLQuery q(this->query);
q.setValue("a", u->Account()->display);
q.setValue("i", u->ip);
this->SQL->Run(new SQLOperResult(this, u), q);
Log(LOG_DEBUG) << "m_sql_oper: Checking authentication for " << u->Account()->display;
}
};
MODULE_INIT(ModuleSQLOper)
+4
View File
@@ -361,6 +361,10 @@ class InspIRCdTS6Proto : public IRCDProto
return true;
}
void SendOper(User *u) anope_override
{
}
};
struct IRCDMessageEndburst : IRCDMessage
+6
View File
@@ -316,6 +316,12 @@ bool IRCDProto::IsChannelValid(const Anope::string &chan)
return true;
}
void IRCDProto::SendOper(User *u)
{
SendNumericInternal(381, u->GetUID(), ":You are now an IRC operator (set by services)");
u->SetMode(findbot(Config->OperServ), UMODE_OPER);
}
MessageSource::MessageSource(const Anope::string &src) : source(src), u(NULL), s(NULL)
{
if (src.empty())
+3
View File
@@ -431,6 +431,9 @@ void User::Identify(NickAlias *na)
this->SetModes(bi, "%s", this->nc->o->ot->modes.c_str());
if (bi != NULL)
this->SendMessage(bi, "Changing your usermodes to \002%s\002", this->nc->o->ot->modes.c_str());
UserMode *um = ModeManager::FindUserModeByName(UMODE_OPER);
if (um && !this->HasMode(UMODE_OPER) && this->nc->o->ot->modes.find(um->ModeChar) != Anope::string::npos)
ircdproto->SendOper(this);
}
if (ircdproto->CanSetVHost && !this->nc->o->vhost.empty())
{