+/* $ModDesc: Allow/Deny connections based upon an arbitrary SQL table */
+
+enum AuthState {
+ AUTH_STATE_NONE = 0,
+ AUTH_STATE_BUSY = 1,
+ AUTH_STATE_FAIL = 2
+};
+
+class AuthQuery : public SQLQuery
+{
+ public:
+ const std::string uid;
+ LocalIntExt& pendingExt;
+ bool verbose;
+ AuthQuery(Module* me, const std::string& u, LocalIntExt& e, bool v)
+ : SQLQuery(me), uid(u), pendingExt(e), verbose(v)
+ {
+ }
+
+ void OnResult(SQLResult& res)
+ {
+ User* user = ServerInstance->FindNick(uid);
+ if (!user)
+ return;
+ if (res.Rows())
+ {
+ pendingExt.set(user, AUTH_STATE_NONE);
+ }
+ else
+ {
+ if (verbose)
+ ServerInstance->SNO->WriteGlobalSno('a', "Forbidden connection from %s (SQL query returned no matches)", user->GetFullRealHost().c_str());
+ pendingExt.set(user, AUTH_STATE_FAIL);
+ }
+ }
+
+ void OnError(SQLerror& error)
+ {
+ User* user = ServerInstance->FindNick(uid);
+ if (!user)
+ return;
+ pendingExt.set(user, AUTH_STATE_FAIL);
+ if (verbose)
+ ServerInstance->SNO->WriteGlobalSno('a', "Forbidden connection from %s (SQL query failed: %s)", user->GetFullRealHost().c_str(), error.Str());
+ }
+};