コード例 #1
0
ファイル: cs_fantasy_top.cpp プロジェクト: bonnedav/anope
	void OnError(const SQL::Result &r) override
	{
		if (!r.GetQuery().query.empty())
			Log(LOG_DEBUG) << "Chanstats: Error executing query " << r.finished_query << ": " << r.GetError();
		else
			Log(LOG_DEBUG) << "Chanstats: Error executing query: " << r.GetError();
	}
コード例 #2
0
	SQL::Result RunQuery(const SQL::Query &query)
	{
		if (!this->sql)
			throw SQL::Exception("Unable to locate SQL reference, is m_mysql loaded and configured correctly?");

		SQL::Result res = this->sql->RunQuery(query);
		if (!res.GetError().empty())
			throw SQL::Exception(res.GetError());
		return res;
	}
コード例 #3
0
ファイル: cs_fantasy_top.cpp プロジェクト: bonnedav/anope
	void DoTop(CommandSource &source, const std::vector<Anope::string> &params, bool is_global, int limit = 1)
	{

		Anope::string channel;
		if (!params.empty())
			channel = params[0];
		else if (source.c && source.c->ci)
			channel = source.c->ci->GetName();

		if (!is_global && channel.empty())
			is_global = true;

		try
		{
			SQL::Query query;
			query = "SELECT nick, letters, words, line, actions,"
				"smileys_happy+smileys_sad+smileys_other as smileys "
				"FROM `" + prefix + "chanstats` "
				"WHERE `nick` != '' AND `chan` = @channel@ AND `type` = 'total' "
				"ORDER BY `letters` DESC LIMIT @limit@;";
			query.SetValue("limit", limit, false);

			if (is_global)
				query.SetValue("channel", "");
			else
				query.SetValue("channel", channel.c_str());

			SQL::Result res = this->RunQuery(query);

			if (res.Rows() > 0)
			{
				source.Reply(_("Top %i of %s"), limit, (is_global ? "Network" : channel.c_str()));
				for (int i = 0; i < res.Rows(); ++i)
				{
					source.Reply(_("%2lu \002%-16s\002 letters: %s, words: %s, lines: %s, smileys: %s, actions: %s"),
						i+1, res.Get(i, "nick").c_str(), res.Get(i, "letters").c_str(),
						res.Get(i, "words").c_str(), res.Get(i, "line").c_str(),
						res.Get(i, "smileys").c_str(), res.Get(i, "actions").c_str());
				}
			}
			else
				source.Reply(_("No stats for %s."), is_global ? "Network" : channel.c_str());
		}
		catch (const SQL::Exception &ex)
		{
			Log(LOG_DEBUG) << ex.GetReason();
		}
	}
コード例 #4
0
ファイル: sql_oper.cpp プロジェクト: SaberUK/anope
	void OnResult(const SQL::Result &r) override
	{
		SQLOperResultDeleter d(this);

		if (!user || !user->Account() || r.Rows() == 0)
			return;

		Anope::string opertype;
		try
		{
			opertype = r.Get(0, "opertype");
		}
		catch (const SQL::Exception &)
		{
			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 SQL::Exception &) { }

		ServiceBot *OperServ = Config->GetClient("OperServ");
		if (opertype.empty())
		{
			if (user->Account() && user->Account()->o && dynamic_cast<SQLOper *>(user->Account()->o))
			{
				delete user->Account()->o;
				user->Account()->o = NULL;

				Log(this->owner) << "m_sql_oper: Removed services operator from " << user->nick << " (" << user->Account()->GetDisplay() << ")";
				user->RemoveMode(OperServ, "OPER"); // Probably not set, just incase
			}
			return;
		}

		OperType *ot = OperType::Find(opertype);
		if (ot == NULL)
		{
			Log(this->owner) << "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(this->owner) << "m_sql_oper: Tieing oper " << user->nick << " to type " << opertype;
			user->Account()->o = new SQLOper(user->Account()->GetDisplay(), ot);
		}

		if (!user->HasMode("OPER"))
		{
			IRCD->SendOper(user);

			if (!modes.empty())
				user->SetModes(OperServ, "%s", modes.c_str());
		}
	}
コード例 #5
0
ファイル: sql_oper.cpp プロジェクト: SaberUK/anope
	void OnError(const SQL::Result &r) override
	{
		SQLOperResultDeleter d(this);
		Log(this->owner) << "m_sql_oper: Error executing query " << r.GetQuery().query << ": " << r.GetError();
	}
コード例 #6
0
	void DoStats(CommandSource &source, const bool is_global, const std::vector<Anope::string> &params)
	{
		Anope::string display, channel;

		/*
		 * possible parameters are:
		 *   stats [channel] [nick]
		 *   stats [channel]
		 *   stats [nick]
		 *   stats
		 */

		switch (params.size())
		{
			case 2:
				channel = params[0];
				display = params[1];
				break;
			case 1:
				if (params[0][0] == '#')
					channel = params[0];
				else
				{
					if (NickAlias *na = NickAlias::Find(params[0]))
						display = na->nc->display;
					else
					{
						source.Reply(_("%s not found."), params[0].c_str());
						return;
					}
				}
				break;
		}

		if (display.empty())
			display = source.nc->display;

		try
		{
			SQL::Query query;
			query = "SELECT letters, words, line, smileys_happy+smileys_sad+smileys_other as smileys,"
				"actions FROM `" + prefix + "chanstats` "
				"WHERE `nick` = @nick@ AND `chan` = @channel@ AND `type` = 'total';";
			if (is_global || channel.empty())
				query.SetValue("channel", "");
			else
				query.SetValue("channel", channel);
			query.SetValue("nick", display);
			SQL::Result res = this->RunQuery(query);

			if (res.Rows() > 0)
			{
				if (is_global)
					source.Reply(_("Network stats for %s:"), display.c_str());
				else
					source.Reply(_("Channel stats for %s on %s:"), display.c_str(), channel.c_str());

				source.Reply(_("letters: %s, words: %s, lines: %s, smileys: %s, actions: %s"),
						res.Get(0, "letters").c_str(), res.Get(0, "words").c_str(),
						res.Get(0, "line").c_str(), res.Get(0, "smileys").c_str(),
						res.Get(0, "actions").c_str());
			}
			else
				source.Reply(_("No stats for %s."), display.c_str());
		}
		catch (const SQL::Exception &ex)
		{
			Log(LOG_DEBUG) << ex.GetReason();
		}

	}
コード例 #7
0
ファイル: sql_oper.cpp プロジェクト: Robby-/anope
	void OnResult(const SQL::Result &r) override
	{
		SQLOperResultDeleter d(this);

		if (!user || !user->Account())
			return;

		if (r.Rows() == 0)
		{
			Log(LogType::DEBUG) << "m_sql_oper: Got 0 rows for " << user->nick;
			Deoper();
			return;
		}

		Anope::string opertype;
		try
		{
			opertype = r.Get(0, "opertype");
		}
		catch (const SQL::Exception &)
		{
			Log(this->owner) << "Expected column named \"opertype\" but one was not found";
			return;
		}

		Log(LogType::DEBUG) << "m_sql_oper: Got result for " << user->nick << ", opertype " << opertype;

		Anope::string modes;
		try
		{
			modes = r.Get(0, "modes");
		}
		catch (const SQL::Exception &) { }

		ServiceBot *OperServ = Config->GetClient("OperServ");
		if (opertype.empty())
		{
			Deoper();
			return;
		}

		OperType *ot = OperType::Find(opertype);
		if (ot == NULL)
		{
			Log(this->owner) << "m_sql_oper: Oper " << user->nick << " has type " << opertype << ", but this opertype does not exist?";
			return;
		}

		Oper *oper = user->Account()->GetOper();
		if (oper == nullptr || oper->GetType() != ot)
		{
			Log(this->owner) << "m_sql_oper: Tieing oper " << user->nick << " to type " << opertype;

			if (oper)
				oper->Delete();

			oper = Serialize::New<Oper *>();
			oper->SetName(user->Account()->GetDisplay());
			oper->SetType(ot);

			user->Account()->SetOper(oper);
		}

		if (!user->HasMode("OPER"))
		{
			IRCD->SendOper(user);

			if (!modes.empty())
				user->SetModes(OperServ, "%s", modes.c_str());
		}
	}