/** This is called from user_config when reading the config file
*/
void UnlockManager::load()
{
    const std::string filename=file_manager->getChallengeFile("challenges.xml");
    XMLNode* root = file_manager->createXMLTree(filename);
    if(!root || root->getName() != "challenges")
    {
        std::cerr << "Challenge file '" << filename << "' will be created." 
                  << std::endl;
        
        createSlotsIfNeeded();
        save();
        
        if (root) delete root;
        return;
    }
    
    std::vector<XMLNode*> xml_game_slots;
    root->getNodes("gameslot", xml_game_slots);
    for (unsigned int n=0; n<xml_game_slots.size(); n++)
    {
        std::string player_id;
        if (!xml_game_slots[n]->get("playerID", &player_id))
        {
            fprintf(stderr, "[UnlockManager] WARNING: Found game slot without a player ID attached. Discarding it\n");
            continue;
        }
        
        GameSlot* slot = new GameSlot(player_id);
        
        std::string kart_id;
        xml_game_slots[n]->get("kart", &kart_id);
        slot->setKartIdent(kart_id);
        
        m_game_slots[player_id] = slot;
        
        bool first_time = true;
        xml_game_slots[n]->get("firstTime", &first_time);
        slot->setFirstTime(first_time);
        
        for(AllChallengesType::iterator i = m_all_challenges.begin(); 
            i!=m_all_challenges.end();  i++)
        {
            ChallengeData* curr = i->second;
            Challenge* state = new Challenge(curr);
            
            slot->m_challenges_state[curr->getId()] = state;
            state->load(xml_game_slots[n]);
        }
        slot->computeActive();
    }
    
    bool something_changed = createSlotsIfNeeded();
    if (something_changed) save();
    
    delete root;
}   // load
Example #2
0
Auth::Challenge Auth::generateChallenge(int length) const
{
    Challenge challenge;
    challenge.resize(length);

    for (int i = 0; i < length; i++)
        challenge[i] = Utility::rand();

    return challenge;
}
Example #3
0
Auth::Response Auth::getResponse(const Challenge &challenge) const
{
    Response response;

    int inputlen = passphrase.length() + challenge.size();
    unsigned char input[inputlen];
    memcpy(input, passphrase.c_str(), passphrase.length());
    memcpy(input + passphrase.length(), &challenge[0], challenge.size());

    crypto_hash_sha256(&response.data[0], input, inputlen);

    return response;
}
Example #4
0
Auth::Response Auth::getResponse(const Challenge &challenge) const
{
    SHA1 hasher;

    Response response;

    hasher << passphrase.data();
    hasher.Input(&challenge[0], challenge.size());

    hasher.Result((unsigned int *)response.data);

    for (int i = 0; i < 5; i++)
        response.data[i] = htonl(response.data[i]);

    return response;
}
Example #5
0
void gui::MenuChallenge::draw( egn::Window& window )
{
	int score = 0;
	int temps = 0;
	egn::FontManager::get()->write( window, "shoes", "Challenge", egn::Vector2f( 255, 60 ), 50, egn::Color::Black );
	
	
	if( m_Cursor == 0 )
	{
		egn::FontManager::get()->write(window, "olympic", "<", egn::Vector2f( 20, 180 ), 64, egn::Color::Yellow);
		egn::FontManager::get()->write(window, "olympic", ">", egn::Vector2f( 740, 180 ), 64, egn::Color::Yellow);
	}
	else 
	{
		egn::FontManager::get()->write(window, "olympic", "<", egn::Vector2f( 20, 180 ), 64, egn::Color::Black);
		egn::FontManager::get()->write(window, "olympic", ">", egn::Vector2f( 740, 180 ), 64, egn::Color::Black);
	}
	
	
	if( DataManager::get()->basic_get_challenge_list().size() > 0 )
	{
		
		
			Challenge challenge = DataManager::get()->basic_get_challenge_list().at(m_CursorH);
			
			switch( challenge.getType() )
			{	
				case ChallengeType::SCORE_TIME:
				score = challenge.getScore();
				std::ostringstream oss;
    			oss << score;

    			temps = challenge.getTime();
    			std::ostringstream oss1;
    			oss1 << temps;
    	
    			std::string var = "Le but de ce challenge est \n d'atteindre " + oss.str() +" points \n en moins de " + oss1.str() + " secondes.";

    			egn::FontManager::get()->write(window, "shoes", var, egn::Vector2f( 170, 182 ), 30, egn::Color::Black);
				break;

			}
	}
	
	m_Button[0].setPosition( egn::Vector2f( 250, 380 ) );
    m_Button[1].setPosition( egn::Vector2f( 250, 380 ) );
    if( m_Cursor == 1 )
    {
        window.draw( m_Button[1] );
    }
    else 
    {
        window.draw( m_Button[0] );
    }
    egn::FontManager::get()->write( window, "shoes", "Valider", egn::Vector2f( 330, 382 ), 30, egn::Color::Black );


	m_Button[0].setPosition( egn::Vector2f( 250, 430 ) );
    m_Button[1].setPosition( egn::Vector2f( 250, 430 ) );
    if( m_Cursor == 2 )
    {
        window.draw( m_Button[1] );
    }
    else 
    {
        window.draw( m_Button[0] );
    }
    egn::FontManager::get()->write( window, "shoes", "Retour", egn::Vector2f( 340, 432 ), 30, egn::Color::Black );

}