Esempio n. 1
0
int main(int argc, char* argv[]){

	std::ifstream ifs;

	if(argc == ONE)
	{
		cout << "usage: " << argv[0] << "<configuration_file_name>" << endl;
		return ONE;
	}

	cout << "Configuration File is :: " << argv[1] << endl;

	ifs.open (argv[ONE], std::ifstream::in);
	string playname="";

	if(ifs.good()){
		str_op op;
		//read the first non blank line which will be assigned playname.
		while(!ifs.eof() && op.isblank(playname)){
			getline(ifs,playname);
		}

		if(playname.length() == 0){
			cout << "Configuration file is empty, exiting" << endl;
			return ONE;
		}

		//should have playname by now. ready to initialize the class 
		Play play(playname);
		string str="";
		vector<Player> players;//To store the multiple player object
		vector<string> charstrs;//To store all the character name that is detected from the configuration file
		vector<ifstream> files;//To store all the character file that is detected from the configuration file
		//read one line at a time, validate that its well formed and based on that populate the vectors
		unsigned int i = 0;
		while(!ifs.eof()){
			getline(ifs, str);

			if(op.isblank(str))
				continue;

			vector<string> tokens = op.split(str);
			if(tokens.size() < TWO)
			{
				cout << "ignoring line as its not correctly formatted -- " <<  str;
				continue;
			}
			string charname(tokens [ZERO]);
			string filename(tokens [ONE]);
			std::ifstream playfilefs;
			playfilefs.open(filename,std::ifstream::in);
			if(!playfilefs.good())
			{
				cout << "ignoring line as file is in accessible " <<  str << endl;
				continue;
			}
			//push the character name and the file to the vector
			charstrs.push_back(move(charname));
			files.push_back(move(playfilefs));
			i++;
		}
		//for each character, create a player object
		for(unsigned int j = 0; j <= i-1; j++){
			players.push_back(move(Player(ref(play), ref(charstrs[j]), ref(files[j]))));
		}
		//call the enter method for all the player objects
		for(unsigned int j = 0; j <= i-1; j++){
			players[j].enter();
		}
		//call the exit method for all the player objects
		for(unsigned int j = 0; j <= i-1; j++){
			players[j].exit();
		}
	}else{
		cout << "Configuartion File not found. Please correct the path and try again" << endl;
		return ONE;
	}

	ifs.close();
	return 0;
}
Esempio n. 2
0
bool pawsCharacterPickerWindow::OnButtonPressed( int mouseButton, int keyModifer, pawsWidget* widget )
{
    if(!widget)
        return false;

    switch ( widget->GetID() )
    {
        case YES_DELETE_CHARACTER:
        {
            PawsManager::GetSingleton().SetModalWidget(NULL);
            widget->GetParent()->Hide();

            pawsStringPromptWindow::Create("Please enter your account password to confirm:", csString(""),false, 220, 20, this, "DeletionConfirm", 0, true); 
            pawsEditTextBox* passbox =  dynamic_cast<pawsEditTextBox*>
                                        (PawsManager::GetSingleton().FindWidget("stringPromptEntry"));

            if (passbox)
            {
               passbox->SetPassword(true);
            }
            return true;
        }

        case NO_DELETE_CHARACTER:
        {
            return true;
        }

        case CHARACTER_DELETE_BUTTON:
        {
            csString name;
            name.Format("SelectCharacter%i", selectedCharacter);
            csString confirm;
            // Catch empty selection.
            if(selectedCharacter < 0)
            {
                confirm.Format( "You must select a character to delete!" );
                PawsManager::GetSingleton().CreateWarningBox( confirm, this );
                return false;
            }
            csString charName(((pawsButton*)FindWidget(name))->GetText());
            // Catch invalid selection.
            if(charName == "New Character")
                return false;

            csString msg("Warning! this will PERMANENTLY DELETE your character.  Are you sure you want to continue?");
            pawsYesNoBox::Create(this, msg, YES_DELETE_CHARACTER, NO_DELETE_CHARACTER);

            return true;
        }

        case BACK_BUTTON:
        {
            ReturnToLoginWindow();
            return true;
        }

        case CONFIRM_YES:
        {
            //Delete the selected character
            csString name;
            name.Format("SelectCharacter%i", selectedCharacter);

            // Get Full name.
            psString charFullName( ((pawsButton*)FindWidget(name))->GetText() );
            psString charFirstName;
            charFullName.GetWord( 0, charFirstName );

            psCharDeleteMessage msg(charFirstName, 0);
            msg.SendMessage();

            return true;
        }

        case CONFIRM_NO:
        {
            PawsManager::GetSingleton().SetModalWidget(NULL);
            widget->GetParent()->Hide();
            return true;
        }

        case CHARACTER_BUTTON_0:
        case CHARACTER_BUTTON_1:
        case CHARACTER_BUTTON_2:
        case CHARACTER_BUTTON_3:
        {
            if(!connecting)
            {
                SelectCharacter(widget->GetID(),widget);
            }
            break;    
        }
        
        case CHARACTER_ACTION_BUTTON:
        {
            // if we have a character then we play as that one.
            if ( selectedCharacter != -1 && !connecting )
            {
                // Disable the button so that we don't send 2 picker message
                connecting = true;

                csString name;
                name.Format("SelectCharacter%i", selectedCharacter);
                
                // Send the name of the character to the server. 
                csString charname( ((pawsButton*)FindWidget(name))->GetText() );
                                
                psCharacterPickerMessage msg(charname);
                msg.SendMessage();
            }
            
            return true;
        }
        
        case QUIT_BUTTON:
        {
            psengine->QuitClient();
            return true;
        }
       
    }
    return false;
}
Esempio n. 3
0
bool pawsCharacterPickerWindow::OnButtonPressed(int /*mouseButton*/, int /*keyModifer*/, pawsWidget* widget)
{
    if(!widget)
        return false;

    switch ( widget->GetID() )
    {
        case CHARACTER_DELETE_BUTTON:
        {
            csString name;
            name.Format("SelectCharacter%i", selectedCharacter);
            csString confirm;
            // Catch empty selection.
            if(selectedCharacter < 0)
            {
                confirm.Format( "You must select a character to delete!" );
                PawsManager::GetSingleton().CreateWarningBox( confirm, this );
                return false;
            }
            csString charName(((pawsButton*)FindWidget(name))->GetText());
            // Catch invalid selection.
            if(charName == "New Character")
                return false;

            csString msg("Warning! this will PERMANENTLY DELETE your character.  Are you sure you want to continue?");
            pawsYesNoBox::Create(this, msg, YES_DELETE_CHARACTER, NO_DELETE_CHARACTER);

            return true;
        }

        case BACK_BUTTON:
        {
            ReturnToLoginWindow();
            return true;
        }

        case CHARACTER_BUTTON_0:
        case CHARACTER_BUTTON_1:
        case CHARACTER_BUTTON_2:
        case CHARACTER_BUTTON_3:
        {
            if(!connecting)
            {
                SelectCharacter(widget->GetID(),widget);
            }
            break;    
        }
        
        case CHARACTER_ACTION_BUTTON:
        {
            // if we have a character then we play as that one.
            if ( selectedCharacter != -1 && !connecting )
            {
                // Disable the button so that we don't send 2 picker message
                connecting = true;

                csString name;
                name.Format("SelectCharacter%i", selectedCharacter);
                
                // Send the name of the character to the server. 
                csString charname( ((pawsButton*)FindWidget(name))->GetText() );
                                
                psCharacterPickerMessage msg(charname);
                msg.SendMessage();

                //save the selected charname to the configuration file
                csString cnf_name;
                cnf_name.Format(CNF_LAST_CHAR,serverName.GetData());
                csRef<iConfigManager> cfg =  csQueryRegistry<iConfigManager> (PawsManager::GetSingleton().GetObjectRegistry());
                cfg->SetStr(cnf_name, charname);
            }
            
            return true;
        }
        
        case QUIT_BUTTON:
        {
            psengine->QuitClient();
            return true;
        }
       
    }
    return false;
}