// Main prompts player to indicate new or existing user, then calls the appropriate function for either. Afterward, // the function containing the adventure game is called. int main(int argc, char *argv[]) { msgDisplay(0); void gameBegin(string); bool rightInp = false; while (rightInp == false){ string input; cout << "> "; cin >> input; if (input == "l"){ // Existing user rightInp = true; game.login(); gameBegin(game.getUserName()); } else if ( input == "n"){ // New user rightInp = true; game.newUser(); gameBegin(game.getUserName()); } else { msgDisplay(1); // Instructions reiterated if invalid entry given } } return 0; }
int GameLauncher::commandGen( ) { Authentication auth; auth.setUsername( username ); auth.setPassword( password ); QByteArray mainClass; QString arguments; QFile mainClassFile(QDir::currentPath()+"/versions/"+version+"/mainClass.txt" ); if( mainClassFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) { QTextStream in( &mainClassFile ); mainClass = in.readAll().toLocal8Bit(); mainClassFile.close(); } else return -666; QFile argFile( QDir::currentPath()+"/versions/"+version+"/arguments.txt" ); if( argFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) { QTextStream in( &argFile ); arguments = in.readAll().toLocal8Bit(); } else return -666; qDebug() << arguments; if( isLegit() ) { QString result = ""; QString gameUsername = ""; QEventLoop eventLoop; QNetworkAccessManager mgr; int errCode; errCode = auth.login( &mgr ); arguments.replace( "${auth_player_name}", auth.getGameUsername() ); arguments.replace( "${auth_session}", "token:"+auth.getAccessToken().toLocal8Bit()+":"+auth.getClientId().toLocal8Bit() ); arguments.replace( "${version_name}", version ); arguments.replace( "${game_directory}", "\""+mainPath+"\"" ); arguments.replace( "${game_assets}", "\""+mainPath+slash+"assets\"" ); command.append("java ").append(" -Djava.library.path=\""+mainPath+slash+"natives\"") .append( libPathGen() ).append(" "+mainClass+" ").append( arguments ); return errCode; } else { arguments.replace( "${auth_player_name}", auth.getUsername() ); arguments.replace( "${auth_session}", "token:"+auth.getAccessToken().toLocal8Bit()+":"+auth.getClientId().toLocal8Bit() ); arguments.replace( "${version_name}", version ); arguments.replace( "${game_directory}", "\""+mainPath+"\"" ); arguments.replace( "${game_assets}", "\""+mainPath+slash+"assets\"" ); command.append("java ").append(" -Djava.library.path=\""+mainPath+slash+"natives\"") .append( libPathGen() ).append(" "+mainClass+" ").append( arguments ); } return 0; }