OperationPathList::OperationPathList(std::queue<std::wstring> & oArgList) : Operation(oArgList)
{
	// exit if there are not enough arguments to parse
	std::vector<std::wstring> sSubArgs = ProcessAndCheckArgs(1, oArgList, L"\\0");

	// open the file
	std::wifstream fFile(sSubArgs[0].c_str());

	// adapt the stream to read windows unicode files
	(void) fFile.imbue(std::locale(fFile.getloc(), new std::codecvt_utf8<wchar_t,
		0x10ffff, std::consume_header>));

	// read the file line-by-line
	std::wstring sLine;
	while (std::getline(fFile, sLine))
	{
		// sometimes a carriage return appears in the input stream so adding 
		// it here ensures it is stripped from the very end
		std::vector<std::wstring> oLineItems = SplitArgs(sLine, L"\r");
		if (oLineItems.size() != 1)
		{
			wprintf(L"ERROR: Unable to parse string path list file.");
			exit(-1);
		}

		// store off the argument
		InputOutput::ScanPaths().push_back(oLineItems[0]);
	}

	// cleanup
	fFile.close();
};
Exemple #2
0
void IrcBot::SockRecv()
{
    char sizebuffer[MAXDATASIZE];

    memset(sizebuffer, 0, MAXDATASIZE);
    
    int recievedBytes = recv(_socket, sizebuffer, MAXDATASIZE - 1, 0);
    if (recievedBytes == -1)
    {
        sLog->outError("<IrcBot> - Connection lost");
        Disconnect();
    }
    else
    {
        if (-1 == recievedBytes)
            sLog->outError("<IrcBot> - Error while receiving from socket");
        else
        {
            std::string reply;
            std::istringstream iss(sizebuffer);

            while (getline(iss, reply))
            {
                // PING/PONG
                if (!strcmp(reply.substr(0, 4).c_str(), "PING"))
                {
                    reply.replace(1, 1, "O");
                    SendData(NONE, reply.c_str());
                    return;
                }

                // Join Channel
                //  - SJGR has no MOTD, so we need to look for MOTD File is Missing
                //  - Also make sure that it is not a PRIVMSG
                if (reply.find("252") != std::string::npos &&
                    reply.find("PRIVMSG") == std::string::npos)
                {
                    SendData(IDENTIFY, IRC_PASS);
                    SendData(JOIN, IRC_CHANNEL);
                    return;
                }

                std::vector<char const*> args;
                if (reply.find("PRIVMSG") != std::string::npos)
                    SplitArgs(reply.c_str(), args);

                if (args.size() < 1)
                    return;

                if (!stricmp(args[1], "PRIVMSG") && !stricmp(args[2], IRC_CHANNEL) && args[3][1] == '!')
                {
                    std::string command = args[3];
                    command.erase(0, 2); // erase : and ! from the commands

                    if (command[command.length()-1] == '\r')
                        command.erase(command.length()-1); // remove the trailing newline

                    std::vector<char const*> params;
                    for (_itr = args.begin() + 4; _itr != args.end(); _itr++)
                        params.push_back(*_itr);

                    // Get nick (Inbetween first : and first !)
                    std::string nick = args[0];
                    nick.erase(0, 1);
                    std::stringstream nstream;
                    for (uint32 i = 0; nick[i] != '!'; i++)
                        nstream << nick[i];
                    std::string ntemp = nstream.str();
                    ParseCommand(ntemp.c_str(), command.c_str(), params);
                }
            }
        }
    }
}