Пример #1
0
CmdResult CommandAddLine::Handle(User* usr, std::vector<std::string>& params)
{
	XLineFactory* xlf = ServerInstance->XLines->GetFactory(params[0]);
	const std::string& setter = usr->nick;

	if (!xlf)
	{
		ServerInstance->SNO->WriteToSnoMask('d',"%s sent me an unknown ADDLINE type (%s).",setter.c_str(),params[0].c_str());
		return CMD_FAILURE;
	}

	XLine* xl = NULL;
	try
	{
		xl = xlf->Generate(ServerInstance->Time(), ConvToInt(params[4]), params[2], params[5], params[1]);
	}
	catch (ModuleException &e)
	{
		ServerInstance->SNO->WriteToSnoMask('d',"Unable to ADDLINE type %s from %s: %s", params[0].c_str(), setter.c_str(), e.GetReason().c_str());
		return CMD_FAILURE;
	}
	xl->SetCreateTime(ConvToInt(params[3]));
	if (ServerInstance->XLines->AddLine(xl, NULL))
	{
		if (xl->duration)
		{
			std::string timestr = InspIRCd::TimeString(xl->expiry);
			ServerInstance->SNO->WriteToSnoMask('X',"%s added %s%s on %s to expire on %s: %s",setter.c_str(),params[0].c_str(),params[0].length() == 1 ? "-line" : "",
					params[1].c_str(), timestr.c_str(), params[5].c_str());
		}
		else
		{
			ServerInstance->SNO->WriteToSnoMask('X',"%s added permanent %s%s on %s: %s",setter.c_str(),params[0].c_str(),params[0].length() == 1 ? "-line" : "",
					params[1].c_str(),params[5].c_str());
		}

		TreeServer* remoteserver = TreeServer::Get(usr);

		if (!remoteserver->IsBursting())
		{
			ServerInstance->XLines->ApplyLines();
		}
		return CMD_SUCCESS;
	}
	else
	{
		delete xl;
		return CMD_FAILURE;
	}
}
Пример #2
0
	CmdResult Handle(const std::vector<std::string>& parameters, User *user)
	{
		std::string target = parameters[0];
		if (parameters.size() >= 3)
		{
			IdentHostPair ih;
			User* find = ServerInstance->FindNick(target);
			if ((find) && (find->registered == REG_ALL))
			{
				ih.first = "*";
				ih.second = find->GetIPString();
				target = std::string("*@") + find->GetIPString();
			}
			else
				ih = ServerInstance->XLines->IdentSplit(target);

			if (ih.first.empty())
			{
				user->WriteServ("NOTICE %s :*** Target not found", user->nick.c_str());
				return CMD_FAILURE;
			}

			if (ServerInstance->HostMatchesEveryone(ih.first+"@"+ih.second,user))
				return CMD_FAILURE;
			else if (target.find('!') != std::string::npos)
			{
				std::string message = "NOTICE %s :*** "+linename+"-Line cannot operate on nick!user@host masks";
				user->WriteServ(message);
				return CMD_FAILURE;
			}

			XLineFactory* xlf = ServerInstance->XLines->GetFactory(linename);
			if (!xlf)
				return CMD_FAILURE;

			long duration = ServerInstance->Duration(parameters[1]);
			XLine* al = xlf->Generate(ServerInstance->Time(), duration, user->nick, parameters[2], target);
			if (ServerInstance->XLines->AddLine(al, user))
			{
				if (!duration)
				{
					ServerInstance->SNO->WriteToSnoMask('x', "%s added permanent %s-line for %s: %s",user->nick.c_str(), linename.c_str(), target.c_str(), parameters[2].c_str());
				}
				else
				{
					time_t c_requires_crap = duration + ServerInstance->Time();
					std::string timestr = ServerInstance->TimeString(c_requires_crap);
					ServerInstance->SNO->WriteToSnoMask('x',"%s added timed %s-line for %s, expires on %s: %s",user->nick.c_str(),linename.c_str(),target.c_str(),timestr.c_str(), parameters[2].c_str());
				}
				ServerInstance->XLines->ApplyLines();
			}
			else
			{
				delete al;
				user->WriteServ("NOTICE %s :*** %s-Line for %s already exists",user->nick.c_str(),linename.c_str(),target.c_str());
			}
		}
		else
		{
			if (ServerInstance->XLines->DelLine(target.c_str(),linename,user))
			{
				ServerInstance->SNO->WriteToSnoMask('x',"%s removed %s-line on %s",user->nick.c_str(),linename.c_str(),target.c_str());
			}
			else
			{
				user->WriteServ("NOTICE %s :*** %s-Line %s not found in list, try /stats %c.",user->nick.c_str(),linename.c_str(),target.c_str(), statschar);
			}
		}

		return CMD_SUCCESS;
	}
Пример #3
0
	bool ReadDatabase()
	{
		// If the xline database doesn't exist then we don't need to load it.
		if (!FileSystem::FileExists(xlinedbpath))
			return true;

		std::ifstream stream(xlinedbpath.c_str());
		if (!stream.is_open())
		{
			ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Cannot read database! %s (%d)", strerror(errno), errno);
			ServerInstance->SNO->WriteToSnoMask('a', "database: cannot read db: %s (%d)", strerror(errno), errno);
			return false;
		}

		std::string line;
		while (std::getline(stream, line))
		{
			// Inspired by the command parser. :)
			irc::tokenstream tokens(line);
			int items = 0;
			std::string command_p[7];
			std::string tmp;

			while (tokens.GetToken(tmp) && (items < 7))
			{
				command_p[items] = tmp;
				items++;
			}

			ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Processing %s", line.c_str());

			if (command_p[0] == "VERSION")
			{
				if (command_p[1] != "1")
				{
					stream.close();
					ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "I got database version %s - I don't understand it", command_p[1].c_str());
					ServerInstance->SNO->WriteToSnoMask('a', "database: I got a database version (%s) I don't understand", command_p[1].c_str());
					return false;
				}
			}
			else if (command_p[0] == "LINE")
			{
				// Mercilessly stolen from spanningtree
				XLineFactory* xlf = ServerInstance->XLines->GetFactory(command_p[1]);

				if (!xlf)
				{
					ServerInstance->SNO->WriteToSnoMask('a', "database: Unknown line type (%s).", command_p[1].c_str());
					continue;
				}

				XLine* xl = xlf->Generate(ServerInstance->Time(), atoi(command_p[5].c_str()), command_p[3], command_p[6], command_p[2]);
				xl->SetCreateTime(atoi(command_p[4].c_str()));

				if (ServerInstance->XLines->AddLine(xl, NULL))
				{
					ServerInstance->SNO->WriteToSnoMask('x', "database: Added a line of type %s", command_p[1].c_str());
				}
				else
					delete xl;
			}
		}
		stream.close();
		return true;
	}