Beispiel #1
0
void tokenize(const char* string, Words& words)
{

	enum State
	{
		ScanningForWordBeginning,
		ScanningForWordEnd,
	};

	State state = ScanningForWordBeginning;

	const char* wordStart = string;
	const char* wordEnd = string;

	while (true)
	{
		char ch = *wordEnd;

		switch (state)
		{
		case ScanningForWordBeginning:
			{
				if (ch == '\0')
				{
					return;
				}
				else if (ch != ' ' && ch != '\t')
				{
					wordStart = wordEnd;
					wordEnd++;
					state = ScanningForWordEnd;
				}
			}
			break;

		case ScanningForWordEnd:
			{
				if (ch == '\0')
				{
					words.push_back(std::string(wordStart));
					return;
				}
				if (ch != ' ' && ch != '\t')
				{
					wordEnd++;
				}
				else
				{
					words.push_back(std::string(wordStart, wordEnd - wordStart));
					wordEnd++;
					state = ScanningForWordBeginning;
				}
			}
			break;
		}
	}
}
Beispiel #2
0
void RconConnection::EnableEvents(void)
{
	Words command;
	command.clear();
	command.push_back("admin.eventsEnabled");
	command.push_back("true");

	if(sendRequest(command))
		throw string("sendRequest failed :: eventsEnabled");

	TextRconPacket response = getResponse();

	if(!response.m_isResponse || response.m_data[0] != "OK")
		throw string("eventsEnabled failed");
}
Beispiel #3
0
void LoadDic() {
    const int MAX_LEN = 32;
    int lengths[MAX_LEN] = {0};
    if( FILE * fp = fopen( "enable1.txt", "rt" ) ) {
        //double start = PerfTime();
        while( !feof( fp ) ) {
            char buf[MAX_LEN];
            char * got = fgets( buf, 63, fp );

            if( got ) {
                char *end = buf + strlen(buf) -1;
                while( end > buf && !isalpha( *end ) ) {
                    *end = 0;
                    end -= 1;
                }

                int l = strlen(buf);
                lengths[l] += 1;

                if( l <= 15 ) {
                    words.push_back(std::string(buf));
                    wordSet.insert(std::string(buf));
                }
            }
        }
        fclose( fp );
        //double loaded = PerfTime();
    }
}
Beispiel #4
0
void RconConnection::Login(void)
{
	Words loginCommand;
	loginCommand.push_back("login.hashed");

	if(sendRequest(loginCommand))
		throw string("Login failed");

	TextRconPacket response = getResponse();

	if(response.m_isResponse && response.m_data[0] == "OK")
	{
		string salt = response.m_data[1];

		const char* hex_str = salt.c_str();
		string hash, saltHex;
		uint32_t ch;

		for( ; sscanf( hex_str, "%2x", &ch) == 1 ; hex_str += 2)
			hash += ch;

		saltHex = hash;

		hash.append( this->password );
		hash = MD5String( (char*)hash.c_str() );

		boost::to_upper(hash);

		loginCommand.clear();
		loginCommand.push_back("login.hashed");
		loginCommand.push_back(hash);

		if(sendRequest(loginCommand))
			throw string("sendRequest failed :: Login");

		response = getResponse();

		if(response.m_isResponse && response.m_data[0] == "InvalidPasswordHash")
			throw string("Login failed :: InvalidPasswordHash (Salt: " + salt + " | SaltHex: "+ saltHex +" | Hash: " + hash + ")");

	}
	else
		throw string("Login failed");


}
Beispiel #5
0
int main( int argc, char * argv[] ) {
    char from[10] = "aablls?";

    if( argc >= 2 ) {
        std::string arg(argv[1]);
        std::sort( arg.begin(), arg.end() );
        strcpy( from, arg.c_str() );
    }

    if( argc >= 3 ) {
        min_length = atoi( argv[2] );
    }


    logf( 1, CLEAR "Score %s -> %i\n", from, ScoreString( from ) );

    const int MAX_LEN = 32;
    int lengths[MAX_LEN] = {0};
    if( FILE * fp = fopen( "enable1.txt", "rt" ) ) {
        double start = PerfTime();
        while( !feof( fp ) ) {
            char buf[MAX_LEN];
            char * got = fgets( buf, 63, fp );

            if( got ) {
                char *end = buf + strlen(buf) -1;
                while( end > buf && !isalpha( *end ) ) {
                    *end = 0;
                    end -= 1;
                }

                int l = strlen(buf);
                lengths[l] += 1;

                if( l <= 15 ) {
                    words.push_back(std::string(buf));
                }
            }
        }
        double loaded = PerfTime();

        double runTime = PerfTime();
        Words gathered = GatherAngrams( from );
        std::sort( gathered.begin(), gathered.end(), XScoresLessThanY );
        for( auto s : gathered ) {
            logf( 1, CLEAR "%s - %i\n", s.c_str(), ScoreString( s ) );
        }
        double done = PerfTime();
        logf( 1, CLEAR "Timing (%f s) Loading\n", loaded-start );
        //logf( 1, CLEAR "Timing (%f s) Preparing\n", prepared-prepping);
        logf( 1, CLEAR "Timing (%f s) running\n", done-runTime );
    }

    return 0;
}
Beispiel #6
0
Words GatherAngrams( const char * from ) {
    int wild = 0;
    int find_freq[26] = {0};
    uint32_t find_have = 0;
    for( const char *s = from; *s; ++s ) {
        if( *s == '?' ) {
            wild += 1;
        } else {
            const int ord = *s - 'a';
            find_freq[ord] += 1;
            find_have |= (1<<ord);
        }
    }
    uint32_t find_dont = ~find_have;

    Words matchList;
    const int count = words.size();
    for( int i = 0; i < count; ++i ) {
        const char *s = words[i].c_str();
        if( strlen( s ) < min_length )
            continue;
        int freq[26] = {0};
        uint32_t have = 0;
        for( ; *s; ++s ) {
            const int ord = *s - 'a';
            freq[ord] += 1;
            have |= (1<<ord);
        }

        if( wild == 0 && find_dont & have )
            continue;
        int over = 0;
        for( int c = 0; c < 26; ++c ) {
            if( freq[c] > find_freq[c] )
                over += freq[c] - find_freq[c];
        }
        if( over <= wild ) {
            logf( 1, RED "From (%s) -> (%s)\n", from, words[i].c_str() );
            matchList.push_back( words[i] );
        }
    }
    return matchList;
}
Beispiel #7
0
void readContributors(NameMap& names, const string& file)
{
    osgDB::ifstream fin(file.c_str());

    Words words;
    while(fin)
    {
        string keyword;
        fin >> keyword;
        words.push_back(keyword);
    }

    string blank_string;

    for(unsigned int i = 0; i < words.size(); ++i)
    {
        if (submissionsSequence(words, i))
        {
            if (i + 2 < words.size() && validName(words[i + 1]))
            {
                NamePair name = createName(words[i + 1], words[i + 2]);
                nameCorrection(name);
                if (!name.first.empty()) ++names[name];
                i += 2;
            }
            else if (i + 1 < words.size() && validName(words[i + 1]))
            {
                NamePair name = createName(words[i + 1], blank_string);
                nameCorrection(name);
                if (!name.first.empty()) ++names[name];
                i += 1;
            }
        }
        else
        {
            if (words[i] == "robert")
            {
                ++names[NameRobertOsfield];
            }
            else if (words[i] == "don")
            {
                ++names[NameDonBurns];
            }
        }
    }

    // reassign fisrt name entries to their full names entries
    if (names.size() > 1)
    {
        for (NameMap::iterator itr = names.begin(); itr != names.end(); )
        {
            if (itr->first.second.empty())
            {
                NameMap::iterator next_itr = itr;
                ++next_itr;

                if (next_itr != names.end() && itr->first.first == next_itr->first.first)
                {
                    next_itr->second += itr->second;
                    names.erase(itr);
                    itr = next_itr;
                }
                else
                {
                    ++itr;
                }
            }
            else
            {
                ++itr;
            }
        }
    }

    // remove the double entries from Robert's contributions
    if (names.size() > 1)
    {
        for (NameMap::iterator itr = names.begin(); itr != names.end(); ++itr)
        {
            if (itr->first != NameRobertOsfield && itr->first != NameDonBurns)
            {
                names[NameRobertOsfield] -= itr->second;
            }
        }
    }
}
Beispiel #8
0
void WordsWithTotalChoices::update(Dictionary const& dictionary, Word const guess)
{
	choices_.push_back(guess);
	count_ += dictionary.anagramCount(guess);
}