コード例 #1
0
ファイル: m_searcher.cpp プロジェクト: Justasic/Navn
/**
 * \fn Flux::string search(Flux::string s, Flux::string command)
 * \brief generates search links for url's
 * This is what generates the search links.
 */
Flux::string search(const Flux::string &text, const Flux::string &command)
{
	Flux::string searchstring = text.url_str();

	if(searchstring.empty())
		return "Empty searchstring.";
	else
	{
		if(command.equals_ci("google"))
			return "http://www.google.com/search?q=" + searchstring;
		else if(command.equals_ci("youtube"))
			return "http://www.youtube.com/results?search_query=" + searchstring;
		else if(command.equals_ci("tpb"))
			return "http://thepiratebay.org/search/" + searchstring;
		else if(command.equals_ci("define"))
			return "http://dictionary.reference.com/browse/" + searchstring;
		else if(command.equals_ci("urban"))
			return "http://www.urbandictionary.com/define.php?term=" + searchstring;
		else if(command.equals_ci("movie"))
			return "www.letmewatchthis.ch/index.php?search_keywords=" + searchstring;
		else if(command.equals_ci("lmgtfy"))
			return "http://lmgtfy.com/?q=" + searchstring;
		else
			return "http://www.google.com/search?q=" + searchstring;
	}
}
コード例 #2
0
ファイル: modulehandler.cpp プロジェクト: Justasic/Navn
/**
 * \fn bool ModuleHandler::DeleteModule(Module *m)
 * \brief Delete the Module from Module lists and unload it from navn completely
 * \param Module the Module to be removed
 */
bool ModuleHandler::DeleteModule(Module *m)
{
	SET_SEGV_LOCATION();

	if(!m || !m->handle)
		return false;

	void *handle = m->handle;
	Flux::string filepath = m->filepath;

	dlerror();
	void (*df)(Module *) = function_cast<void ( *)(Module *)>(dlsym(m->handle, "ModunInit"));
	const char *err = dlerror();

	if(!df && err && *err)
	{
		Log(LOG_WARN) << "No destroy function found for " << m->name << ", chancing delete...";
		delete m; /* we just have to chance they haven't overwrote the delete operator then... */
	}
	else
		df(m); /* Let the Module delete it self, just in case */


	if(handle)
		if(dlclose(handle))
			Log() << "[" << m->name << ".so] " << dlerror();

	if(!filepath.empty())
		Delete(filepath.c_str());

	return true;
}
コード例 #3
0
ファイル: user.cpp プロジェクト: Ephasic/ANT
void User::SetNewNick(const Flux::string &newnick)
{
    if(newnick.empty())
	throw CoreException("User::SetNewNick() was called with empty arguement");

    Log(LOG_TERMINAL) << "Setting new nickname: " << this->nick << " -> " << newnick;
    this->n->UserNickList.erase(this->nick);
    this->nick = newnick;
    this->n->UserNickList[this->nick] = this;
}
コード例 #4
0
ファイル: Sepstream.cpp プロジェクト: Justasic/TandemBicycle
// Private Function! used by Flux::string.implode()
Flux::string __ConcatenateString(const Flux::vector &str, char delim = ' ')
{
	Flux::string temp;
	for (unsigned i = 0; i < str.size(); ++i)
	{
		if(!temp.empty())
		temp += delim;
		temp += str[i];
	}
	
	return temp;
}
コード例 #5
0
ファイル: user.cpp プロジェクト: Ephasic/ANT
User::User(Network *net, const Flux::string &snick, const Flux::string &sident, const Flux::string &shost, const Flux::string &srealname, const Flux::string &sserver) : nick(snick), host(shost), realname(srealname), ident(sident), fullhost(snick+"!"+sident+"@"+shost), server(sserver), n(net)
{
    /* check to see if a empty string was passed into the constructor */
    if(snick.empty() || sident.empty() || shost.empty())
	throw CoreException("Bad args sent to User constructor");
    if(!net)
	throw CoreException("User created with no network??");


    this->n->UserNickList[snick] = this;
    CUserMap[this] = std::vector<Channel*>();

    Log(LOG_RAWIO) << "New user! " << this->nick << '!' << this->ident << '@' << this->host << (this->realname.empty()?"":" :"+this->realname);

    ++usercnt;
    if(usercnt > maxusercnt)
    {
	maxusercnt = usercnt;
	Log(LOG_TERMINAL) << "New maximum user count: " << maxusercnt;
    }
}
コード例 #6
0
ファイル: m_join.cpp プロジェクト: Justasic/Navn
	void Run(CommandSource &source, const Flux::vector &params)
	{
		User *u = source.u;
		Flux::string chan = params[1];

		if(!u->IsOwner())
		{
			source.Reply(ACCESS_DENIED);
			Log(u) << "attempted to make the bot join " << chan;
			return;
		}

		if(!IsValidChannel(chan))
			source.Reply(CHANNEL_X_INVALID, chan.c_str());
		else
		{
			Log(u) << "made the bot join " << chan;
			Channel *c = findchannel(chan);

			if(!c)
			{
				ircproto->join(chan);

				Flux::string WelcomeMessage = Config->WelcomeMessage.replace_all_ci("{botnick}", Config->BotNick);
				WelcomeMessage.trim();

				if(!WelcomeMessage.empty())
					ircproto->privmsg(chan, WelcomeMessage);
			}
			else
			{
				Log(u) << "tried to make bot join " << c->name << " but we're already in that channel";
				source.Reply("Already in \2%s\2", c->name.c_str());
			}
		}
	}
コード例 #7
0
ファイル: modulehandler.cpp プロジェクト: Justasic/Navn
/**
 * \fn ModErr ModuleHandler::LoadModule(const Flux::string &modname)
 * \brief Load a Module into the bot
 * \param Module the Module to load
 */
ModErr ModuleHandler::LoadModule(const Flux::string &modname)
{
	SET_SEGV_LOCATION();

	if(modname.empty())
		return MOD_ERR_PARAMS;

	if(FindModule(modname))
		return MOD_ERR_EXISTS;

	Log() << "Attempting to load Module [" << modname << ']';

	Flux::string mdir = binary_dir + "/runtime/" + (modname.search(".so") ? modname + ".XXXXXX" : modname + ".so.XXXXXX");
	Flux::string input = Flux::string(binary_dir + "/" + (Config->ModuleDir.empty() ? modname : Config->ModuleDir + "/" + modname) + ".so").replace_all_cs("//", "/");

	TextFile mod(input);
	Flux::string output = TextFile::TempFile(mdir);
	Log(LOG_RAWIO) << "Runtime Module location: " << output;
	mod.Copy(output);

	if(mod.GetLastError() != FILE_IO_OK)
	{
		Log(LOG_RAWIO) << "Runtime Copy Error: " << mod.DecodeLastError();
		return MOD_ERR_FILE_IO;
	}

	dlerror();

	// FIXME: Somehow the binary_dir variable is lost when this executes >:|
	void *handle = dlopen(output.c_str(), RTLD_LAZY | RTLD_LOCAL);
	const char *err = dlerror();

	if(!handle && err && *err)
	{
		Log() << '[' << modname << "] " << err;
		return MOD_ERR_NOLOAD;
	}

	dlerror();
	Module *(*f)(const Flux::string &) = function_cast<Module * ( *)(const Flux::string &)>(dlsym(handle, "ModInit"));
	err = dlerror();

	if(!f && err && *err)
	{
		Log() << "No Module init function, moving on.";
		dlclose(handle);
		return MOD_ERR_NOLOAD;
	}

	if(!f)
		throw CoreException("Can't find Module constructor, yet no moderr?");

	Module *m;

	try
	{
		m = f(modname);
	}
	catch(const ModuleException &e)
	{
		Log() << "Error while loading " << modname << ": " << e.GetReason();
		return MOD_ERR_EXCEPTION;
	}

	m->filepath = output;
	m->filename = (modname.search(".so") ? modname : modname + ".so");
	m->handle = handle;

	FOREACH_MOD(OnModuleLoad, m);

	return MOD_ERR_OK;
}
コード例 #8
0
ファイル: signal.cpp プロジェクト: Justasic/TandemBicycle
/** Segmentation Fault Handler
 * \fn void HandleSegfault(module *m)
 * \brief A segfault handler to report what happened and where it happened.
 * \param module the module class in which the segfault happened include
 */
void HandleSegfault(Module *m)
{
#ifdef HAVE_BACKTRACE
	void *array[10];
	char **strings;
	char tbuf[256];
	Flux::string mbuf;
	size_t size;
	time_t now = time(NULL);

	size = backtrace(array, 10);
	
	if(TextFile::IsFile("SEGFAULT.log"))
		Delete("SEGFAULT.log");
	
	std::stringstream slog;
	std::fstream sslog("SEGFAULT.log", std::ifstream::out | std::ifstream::app);
	if(sslog.is_open())
	{
		struct utsname uts;
		if(uname(&uts) < 0)
			throw CoreException("uname() Error");

		strftime(tbuf, sizeof(tbuf), "[%b %d %H:%M:%S %Y]", localtime(&now));
		slog << "====================== Segmentation Fault ======================" << std::endl;
		slog << "Please report this bug to http://bugs.Azuru.net/ and submit a bug report." << std::endl;
		slog << "Please note that the Azuru developers may ask you to re-run this under gdb!" << std::endl;
		slog << "Time of crash: " << tbuf << std::endl;
		slog << Flux::string(COMPILED_NAME).toupper() << " version: " << VERSION_FULL << std::endl;
		slog << "System info: " << uts.sysname << " " << uts.nodename << " " <<  uts.release << " " << uts.machine << std::endl;
		slog << "System version: " << uts.version << std::endl;
		slog << "C++ Version: " << __VERSION__ << std::endl;
		slog << "Socket Buffer: " << LastBuf << std::endl;
		slog << "Location: " << segv_location << std::endl;

		if(m)
		{
			slog << "Module: " << m->name << std::endl;
			slog << "Module Version: " << m->GetVersion() << std::endl;
			slog << "Module Author: " << m->GetAuthor() << std::endl;
		}

		for(auto it : Modules)
			mbuf += it->name+" ";

		mbuf.trim();
		slog << "Modules Loaded: " << (mbuf.empty()?"None":mbuf) << std::endl;
		strings = backtrace_symbols(array, size);

		for(unsigned i=1; i < size; i++)
			slog << "BackTrace(" << (i - 1) << "): " << strings[i] << std::endl;

		free(strings);
		slog << "======================== END OF REPORT ==========================" << std::endl;
		sslog << slog.str() << std::endl; //Write to SEGFAULT.log
		sslog.close(); //Close pointer to SEGFAULT.log
		std::cout << slog.str(); //Write to terminal.
		std::cout.flush(); //Clear output
		
		if(m)
			Log() << "Segmentation Fault in module " << m->name << ", please review SEGFAULT.log";
		else
			Log(LOG_SILENT) << "\033[0mSegmentation Fault, Please read SEGFAULT.log";
	}
	else
		throw CoreException("Segmentation Fault, cannot write backtrace!");
#else
	Log(LOG_SILENT) << "Segmentation Fault";
	printf("\033[0mOh no! A Segmentation Fault has occured!\n");
	printf("This system does not support backtracing, please use gdb or a similar debugger!\n");
	printf("Please follow these instructions on how to file a bug report of Flux-Net:\n");
	printf("1) type \"gdb ant\"\n2) type \"r -n --protocoldebug\"\n3) Cause the program to crash\n4) Type \"bt full\" and copy and paste the output to http://www.pastebin.com/\n5) File a bug report at http://flux-net.net/bugs/\n");
#endif
}
コード例 #9
0
ファイル: Socket.cpp プロジェクト: Justasic/TandemBicycle
/** Construct the object, sets everything to 0
 */
sockaddrs::sockaddrs(const Flux::string &address)
{
	this->clear();
	if (!address.empty())
		this->pton(address.find(':') != Flux::string::npos ? AF_INET6 : AF_INET, address);
}