Ejemplo n.º 1
0
/**
 * \fn void ModuleHandler::SanitizeRuntime()
 * \brief Deletes all files in the runtime directory.
 */
void ModuleHandler::SanitizeRuntime()
{
	Log(LOG_DEBUG) << "Cleaning up runtime directory.";
	Flux::string dirbuf = binary_dir + "/runtime/";

	if(!TextFile::IsDirectory(dirbuf))
	{
#ifndef _WIN32

		if(mkdir(dirbuf.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
			throw CoreException(printfify("Error making new runtime directory: %s", strerror(errno)));

#else

		if(!CreateDirectory(dirbuf.c_str(), NULL))
			throw CoreException(printfify("Error making runtime new directory: %s", strerror(errno)));

#endif
	}
	else
	{
		Flux::vector files = TextFile::DirectoryListing(dirbuf);

		for(Flux::vector::iterator it = files.begin(); it != files.end(); ++it)
			Delete(Flux::string(dirbuf + (*it)).c_str());
	}
}
Ejemplo n.º 2
0
// Private function! used by Flux::string.explode()
Flux::vector __ParamString(const Flux::string &str, char delim = ' ')
{
	Flux::vector ret;
	Flux::string token;
	sepstream tok(str, delim);
	
	while (tok.GetToken(token))
		ret.push_back(token);
	
	return ret;
}
Ejemplo n.º 3
0
  void OnCTCP(const Flux::string &source, const Flux::vector &params)
  {
    Flux::string cmd = params.empty()?"":params[0];
    Log(LOG_SILENT) << "Received CTCP " << Flux::Sanitize(cmd) << " from " << source;
    Log(LOG_TERMINAL) << "\033[22;31mReceived CTCP " << Flux::Sanitize(cmd) << " from " << source << Config->LogColor;

    if(cmd == "\001VERSION\001")
    { // for CTCP VERSION reply
      struct utsname uts;
      if(uname(&uts) < 0)
	      throw CoreException("uname() Error");

	ircproto->notice(source, "\001VERSION Navn-%s %s %s\001", VERSION_FULL, uts.sysname, uts.machine);
    }

    if(cmd == "\001TIME\001")
    { // for CTCP TIME reply
	ircproto->notice(source,"\001TIME %s\001", do_strftime(time(NULL), true).c_str());
    }
    if(cmd == "\001SOURCE\001")
    {
      ircproto->notice(source, "\001SOURCE https://github.com/Justasic/Navn\001");
      ircproto->notice(source, "\1SOURCE git://github.com/Justasic/Navn.git\1");
    }
    if(cmd == "\001DCC")
      ircproto->notice(source, "I do not accept or support DCC connections.");
  }
Ejemplo n.º 4
0
/**
 * \fn void CheckLogDelete(Log *log)
 * \brief Check to see if logs need to be removed due to old age
 * \param log A log class variable
 */
void CheckLogDelete(Log *log)
{
	Flux::string dir = binary_dir + "/logs/";

	if(!TextFile::IsDirectory(dir))
	{
		Log(LOG_TERMINAL) << "Directory " << dir << " does not exist, making new directory.";
#ifndef _WIN32

		if(mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
			throw LogException("Failed to create directory " + dir + ": " + Flux::string(strerror(errno)));

#else

		if(!CreateDirectory(dir.c_str(), NULL))
			throw LogException("Failed to create directory " + dir + ": " + Flux::string(strerror(errno)));

#endif

	}

	Flux::vector files = TextFile::DirectoryListing(dir);

	if(log)
		files.push_back(log->filename);

	if(files.empty())
		Log(LOG_TERMINAL) << "No Logs!";

	for(Flux::vector::iterator it = files.begin(); it != files.end(); ++it)
	{
		Flux::string file = dir + (*it);

		if(TextFile::IsFile(file))
		{
			Flux::string t = file.isolate('-', ' ').strip('-');
			int timestamp = static_cast<int>(t);

			if(timestamp > (time(NULL) - 86400 * Config->LogAge) && timestamp != starttime)
			{
				Delete(file.c_str());
				Log(LOG_DEBUG) << "Deleted old logfile " << file;
			}
		}
	}
}
Ejemplo n.º 5
0
	void OnNoticeChannel(User *u, Channel *c, const Flux::vector &params)
	{
		if(!u || !c)
			return;

		if(c->name != Config->LogChannel)
			return;

		Flux::string msg;

		for(unsigned i = 0; i < params.size(); ++i)
			msg += params[i] + ' ';

		msg.trim();
		Flux::string nolog = params.size() == 2 ? params[1] : "";

		if(nolog != "#nl" && u)
			CLog("-Notice- %s: %s", u->nick.c_str(), Flux::Sanitize(msg).c_str());
	}
Ejemplo n.º 6
0
// 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;
}
Ejemplo n.º 7
0
/**Rehash void
 * \fn void ReadConfig()
 * \deprecated This will be removed soon.
 * This will re-read the config file values when told to do so
 */
void ModuleHandler::LoadModuleList(const Flux::vector &list)
{
	for(Flux::vector::const_iterator it = list.begin(); it != list.end(); ++it)
	{
		ModErr e = LoadModule(*it);

		if(e != MOD_ERR_OK)
			Log() << "Error loading Module " << *it << ": " << DecodeModErr(e);
	}

//   sepstream sep(Config->Modules, ',');
//   Flux::string tok;
//
//   while(sep.GetToken(tok))
//   {
//     tok.trim();
//     ModErr e = ModuleHandler::LoadModule(tok);
//     if(e != MOD_ERR_OK)
//       Log() << "ERROR loading Module " << tok << ": " << DecodeModErr(e);
//   }
}
Ejemplo n.º 8
0
  void OnPrivmsgChannel(User *u, Channel *c, const Flux::vector &params)
  {
    //Flux::vector MessageParams = StringVector(params, ' ');
    Flux::string msg;
    for(unsigned i=0; i < params.size(); ++i)
      msg += params[i]+' ';

    Flux::string cmd = params.empty()?"":params[0];

    if(cmd.equals_ci("!encyclopedia"))
    {
      SetQuery(1, params);
      Brain(u,query);
    }

    if(msg.search_ci(Config->BotNick+", what do you know about "))
    {
      SetQuery(6, params);
      Brain(u, query);
    }

    else if(msg.search_ci(Config->BotNick+", what is a ") ^ msg.search_ci(Config->BotNick+", what is the") ^ msg.search_ci(Config->BotNick+", tell me about ") ^ msg.search_ci(Config->BotNick+", who are the ") ^ msg.search_ci(Config->BotNick+", what is an "))
    {
      SetQuery(4, params);
      Brain(u, query);
    }

    else if(msg.search_ci(Config->BotNick+", what is ") ^ msg.search_ci(Config->BotNick+", what are ") ^ msg.search_ci(Config->BotNick+", who is ") ^ msg.search_ci(Config->BotNick+", what's a ") ^ msg.search_ci(Config->BotNick+", what's an "))
    {
      SetQuery(3, params);
      Brain(u, query);
    }

    else if(msg.search_ci(Config->BotNick+", tell me what you know about "))
    {
      SetQuery(7, params);
      Brain(u, query);
    }
  }
Ejemplo n.º 9
0
	void OnPrivmsgChannel(User *u, Channel *c, const Flux::vector &params)
	{
		Flux::string nolog = params.size() == 2 ? params[1] : "";

		if(!u || !c)
			return;

		if(c->name != Config->LogChannel)
			return;

		Flux::string msg = ConcatinateVector(params);

		if(nolog != "#nl" && u)
		{
			if(nolog == "\001ACTION")
			{
				msg = msg.erase(0, 8);
				CLog("*** %s %s", u->nick.c_str(), Flux::Sanitize(msg).c_str());
			}
			else
				CLog("<%s> %s", u->nick.c_str(), msg.c_str());
		}
	}
Ejemplo n.º 10
0
  void OnNumeric(int i, Network *n, const Flux::vector &params)
  {
    if((i == 5))
    {
      // Skip the nickname and the "are supported by this server" parts of the message
      for(unsigned o = 1; o < params.size() - 1; ++o)
      {
	Flux::vector sentence = ParamitizeString(params[o], '=');
	Flux::string word = sentence[0];
	Flux::string param = sentence.size() > 1 ? sentence[1] : "";

	if(word.equals_ci("NETWORK"))
	  n->isupport.Network = param;

	if(word.equals_ci("CHANTYPES"))
	  n->isupport.ChanTypes = param;

	if(word.equals_ci("AWAYLEN"))
	  n->isupport.AwayLen = static_cast<int>(param);

	if(word.equals_ci("KICKLEN"))
	  n->isupport.KickLen = static_cast<int>(param);

	if(word.equals_ci("MAXBANS"))
	  n->isupport.MaxBans = static_cast<int>(param);

	if(word.equals_ci("MAXCHANNELS"))
	  n->isupport.MaxChannels = static_cast<int>(param);

	if(word.equals_ci("CHANNELLEN"))
	  n->isupport.ChannelLen = static_cast<int>(param);

	if(word.equals_ci("NICKLEN"))
	  n->isupport.NickLen = static_cast<int>(param);

	if(word.equals_ci("TOPICLEN"))
	  n->isupport.TopicLen = static_cast<int>(param);

	n->isupport.other[word] = param;
      }
    }

    if((i == 4))
    {
      /* Numeric 004
       * params[0] = Bots nickname
       * params[1] = servername
       * params[2] = ircd version
       * params[3] = user modes
       * params[4] = channel modes
       */

      n->b->CheckNickname();

      n->isupport.ServerHost = params[1];
      n->isupport.IRCdVersion = params[2];
      n->isupport.UserModes = params[3];
      n->isupport.ChanModes = params[4];
    }

    if((i == 376))
      new SyncTimer(n);

    /* Nickname is in use numeric
     * Numeric 433
     * params[0] = our current nickname
     * params[1] = Attempted nickname
     * params[2] = message (useless)
     */
    if((i == 433))
    {
      // Make sure we're not incrementing if the server sends a random 443
      if(params[1].search(Config->NicknamePrefix))
      {
	Flux::string number = params[1].substr(Config->NicknamePrefix.size());
	if(static_cast<int>(number) == n->b->BotNum)
	  n->b->BotNum++;
      }

      n->b->CheckNickname();
    }
  }
Ejemplo n.º 11
0
 void SetQuery(unsigned n, const Flux::vector &params)
 {
   query.clear();
   if (n < params.size()) for(unsigned i=n; i < params.size(); ++i) query += params[i]+' ';
 }