/*main program, creates a tree, takes in the account id and transaction, and determines whether or not the record is in the tree already. If it is, simply update the transaction, if its not, put it into the tree and update the transaction. Output tree at the end of the program.*/ int main() { AccountDB tree; string accountID; Transaction t; cin >> accountID; cin >> t; while(cin) { AccountRecord * p; p = tree.find(accountID); if(p == 0) { AccountRecord temp = AccountRecord(accountID); temp.addTransaction(t); tree.insert(temp); } else { p -> addTransaction(t); } cin >> accountID; cin >> t; } cout << tree; return 0; }
AccountRecord* cAccounts::createAccount( const QString& login, const QString& password ) { AccountRecord* d = new AccountRecord; d->login_ = login; d->password_ = password; accounts.insert(d->login(), d); if ( accounts.count() == 1 ) // first account, it must be admin! d->setAcl( "admin" ); else d->setAcl( "player" ); d->refreshAcl(); save(); //make sure to save it. return d; }
void cAccounts::load() { ISerialization* archive = cPluginFactory::serializationArchiver( SrvParams->accountsArchiver()); archive->prepareReading("accounts"); for (uint i = 0; i < archive->size(); ++i) { QString objectID; archive->readObjectID( objectID ); if ( objectID == "ACCOUNT" ) { AccountRecord* d = new AccountRecord; archive->readObject( d ); accounts.insert( d->login(), d ); } else throw wpException( "Error parsing account records." ); } archive->close(); delete archive; }
int main() { string id; Transaction info; // create a database of id and accounts Map<string, AccountRecord> accounts; // build our map from input data while (cin >> id >> info) { if(accounts.find(id) == accounts.end()) { // need to insert new account AccountRecord *p = new AccountRecord(id); p->addTransaction(info); accounts[id] = *p; } else { // account exist; insert transaction accounts[id].addTransaction(info); } } // output all account info Map<string, AccountRecord>::Iterator iter; for(iter = accounts.begin(); iter!= accounts.end(); iter++) { cout << iter->data; } }
void commandAccount( cUOSocket *socket, const QString &command, QStringList &args ) throw() { Q_UNUSED(command); // Account Create User Pass // Account Remove User // Account Set User Pass // Account Show User Pass if( args.count() == 0 ) { socket->sysMessage( tr( "Usage: account <create|remove|set|show>" ) ); return; } QString subCommand = args[0].lower(); // Create Accounts if( subCommand == "create" ) { // Create a new account if( args.count() < 3 ) { socket->sysMessage( tr( "Usage: account create <username> <password>" ) ); } else if( Accounts::instance()->getRecord( args[1].left( 30 ) ) ) { socket->sysMessage( tr( "Account '%1' already exists" ).arg( args[1].left( 30 ) ) ); } else { Accounts::instance()->createAccount( args[1].left( 30 ), args[2].left( 30 ) ); socket->sysMessage( tr( "Account '%1' with password '%2' has been created" ).arg( args[1].left( 30 ) ).arg( args[2].left( 30 ) ) ); } } // Remove an Account and all associated characters else if( subCommand == "remove" ) { if( args.count() < 2 ) { socket->sysMessage( tr( "Usage: account remove <username>" ) ); } else if( !Accounts::instance()->getRecord( args[1].left( 30 ) ) ) { socket->sysMessage( tr( "Account '%1' does not exist" ).arg( args[1].left( 30 ) ) ); } else { AccountRecord *account = Accounts::instance()->getRecord( args[1].left( 30 ) ); QValueVector<P_PLAYER> characters = account->caracterList(); Accounts::instance()->remove( account ); UINT32 i = 0; for(; i < characters.size(); ++i ) if( characters[i] ) cCharStuff::DeleteChar( characters[i] ); socket->sysMessage( tr( "Account '%1' and %2 characters have been removed" ).arg( args[1].left( 30 ) ).arg( i+1 ) ); } } // Set properties of accounts else if( subCommand == "set" ) { if( args.count() < 4 ) { socket->sysMessage( tr( "Usage: account set <username> <key> <value>" ) ); } else if( !Accounts::instance()->getRecord( args[1].left( 30 ) ) ) { socket->sysMessage( tr( "Account '%1' does not exist" ).arg( args[1].left( 30 ) ) ); } else { AccountRecord *account = Accounts::instance()->getRecord( args[1].left( 30 ) ); QString key = args[2]; QString value = args[3]; if( key == "password" ) { account->setPassword( value.left( 30 ) ); // Maximum of 30 Chars allowed socket->sysMessage( tr( "The password of account '%1' has been set to '%2'" ).arg( account->login() ).arg( value.left( 30 ) ) ); } else if( key == "block" ) { if( value.lower() == "on" ) { account->setBlocked( true ); socket->sysMessage( tr( "Account '%1' has been blocked" ).arg( account->login() ) ); } else if( value.lower() == "off" ) { account->setBlocked( false ); socket->sysMessage( tr( "Account '%1' has been unblocked" ).arg( account->login() ) ); } else { bool ok = false; UINT32 blockTime = hex2dec( value ).toUInt( &ok ); if( ok ) { account->block( blockTime ); socket->sysMessage( tr( "Account '%1' will be blocked for %2 seconds" ).arg( account->login() ).arg( blockTime ) ); } else { socket->sysMessage( tr( "Usage: account set <username> block <on|off>" ) ); } } } else if( key == "acl" ) { if( !cCommands::instance()->getACL( value ) ) { socket->sysMessage( tr( "You tried to specify an unknown acl '%1'" ).arg( value ) ); } else { account->setAcl( value ); account->refreshAcl(); } } else { socket->sysMessage( tr( "Unknown field '%1' for account '%2'" ).arg( args[2] ).arg( account->login() ) ); } } } // Show properties of accounts else if( subCommand == "show" ) { if( args.count() < 3 ) { socket->sysMessage( tr( "Usage: account show <username> <key>" ) ); } else if( !Accounts::instance()->getRecord( args[1].left( 30 ) ) ) { socket->sysMessage( tr( "Account '%1' does not exist" ).arg( args[1].left( 30 ) ) ); } else { AccountRecord *account = Accounts::instance()->getRecord( args[1].left( 30 ) ); QString key = args[2]; if( key == "password" ) { socket->sysMessage( tr( "The password of account '%1' is '%2'" ).arg( account->login() ).arg( account->password() ) ); } else if( key == "block" ) { if( account->isBlocked() ) socket->sysMessage( tr( "Account '%1' is currently blocked" ).arg( account->login() ) ); else if( account->secsToUnblock() ) socket->sysMessage( tr( "Account '%1' will be unblocked in %2 seconds" ).arg( account->login() ).arg( account->secsToUnblock() ) ); else socket->sysMessage( tr( "Account '%1' is currently not blocked" ).arg( account->login() ) ); } else if( key == "loginattempts" ) { socket->sysMessage( tr( "There were %1 unsuccesul login attempts for account '%2'" ).arg( account->loginAttempts() ).arg( account->login() ) ); } else if( key == "lastlogin" ) { socket->sysMessage( tr( "The last login of account '%1' was on %2" ).arg( account->login() ).arg( account->lastLogin().toString( Qt::ISODate ) ) ); } else if( key == "acl" ) { socket->sysMessage( tr( "The acl of account '%1' is %2" ).arg( account->login() ).arg( account->acl() ) ); } else if( key == "chars" ) { QStringList sCharList; QValueVector< P_PLAYER > pCharList = account->caracterList(); for( UINT32 i = 0; i < pCharList.size(); ++i ) if( pCharList[i] ) sCharList.push_back( QString( "0x%1" ).arg( pCharList[i]->serial(), 8, 16 ) ); socket->sysMessage( tr( "Account '%1' has the following characters: %2" ).arg( account->login() ).arg( sCharList.join( ", " ) ) ); } else { socket->sysMessage( tr( "Unknown field '%1' for account '%2'" ).arg( args[2] ).arg( account->login() ) ); } } } }