From: <spo...@us...> - 2007-07-05 21:22:42
|
Revision: 616 http://svn.sourceforge.net/opengate/?rev=616&view=rev Author: spom_spom Date: 2007-07-05 14:22:44 -0700 (Thu, 05 Jul 2007) Log Message: ----------- Add flag -M for optional connection to metaserver Modified Paths: -------------- branches/ogsector/src/opengateclient.cpp Modified: branches/ogsector/src/opengateclient.cpp =================================================================== --- branches/ogsector/src/opengateclient.cpp 2007-07-05 21:02:43 UTC (rev 615) +++ branches/ogsector/src/opengateclient.cpp 2007-07-05 21:22:44 UTC (rev 616) @@ -40,6 +40,7 @@ std::string username = "testuser"; std::string hostname = "localhost"; std::string password = "dummy"; + bool withMetaServer = false; OpenGate::LogManager *log = new OpenGate::LogManager(); log->setLogFile( "OpenGate.log" ); @@ -48,57 +49,56 @@ while (1) { static struct option long_options[] = { /* These options set a flag. */ - {"config", no_argument, &option_dialog, 1}, - {"no-config", no_argument, &option_dialog, 0}, + {"config", no_argument, &option_dialog, 1}, + {"no-config", no_argument, &option_dialog, 0}, /* These options don't set a flag. We distinguish them by their indices. */ - {"help", no_argument, 0, 'h'}, - {"username", required_argument, 0, 'u'}, - {"password", required_argument, 0, 'p'}, - {"server", required_argument, 0, 's'}, + {"help", no_argument, 0, 'h'}, + {"username", required_argument, 0, 'u'}, + {"password", required_argument, 0, 'p'}, + {"server", required_argument, 0, 's'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; - int c = getopt_long (argc, argv, "cnh:u:p:", long_options, &option_index); + int c = getopt_long (argc, argv, "cnhMu:p:s:", long_options, &option_index); /* Detect the end of the options. */ - if (c == -1) + if ( c == -1 ) break; + + switch ( c ) { + case 0: // If this option set a flag, do nothing else now + if ( long_options[option_index].flag != 0 ) break; + + printf ("option %s", long_options[option_index].name); + if ( optarg ) printf (" with arg %s", optarg); + printf ("\n"); break; - - switch (c) { - case 0: - // If this option set a flag, do nothing else now - if (long_options[option_index].flag != 0) - break; - printf ("option %s", long_options[option_index].name); - if (optarg) - printf (" with arg %s", optarg); - printf ("\n"); - break; - case 'h': + case 'h': #ifdef PACKAGE_NAME - std::cout << PACKAGE_NAME << std::endl; + std::cout << PACKAGE_NAME << std::endl; #endif - std::cout << std::endl << "Usage instructions" << std::endl; - std::cout << " -h --help Show this information" << std::endl; - std::cout << " -u name --username=name Set username to 'name'" << std::endl; - std::cout << " -p pass --password=pass Set password to 'pass'" << std::endl; - std::cout << " -s server --server=server Set server hostname to 'server'" << std::endl; - std::cout << std::endl; - std::cout << " -c --config Show config dialog" << std::endl; - std::cout << " -n --no-config Disable config dialog, reuse last settings" << std::endl; - delete log; - return EXIT_SUCCESS; - case 'u': - log->debug ( std::string ("Setting username to ") + optarg); - username = optarg; - break; - case 'p': - log->debug ( std::string ("Setting password to ") + optarg); - password = optarg; - break; - case 's': + std::cout << std::endl << "Usage instructions" << std::endl; + std::cout << " -h --help Show this information" << std::endl; + std::cout << " -M --with-metaserver Connect to metaserver" << std::endl; + std::cout << " -u name --username=name Set username to 'name'" << std::endl; + std::cout << " -p pass --password=pass Set password to 'pass'" << std::endl; + std::cout << " -s server --server=server Set server hostname to 'server'" << std::endl; + std::cout << std::endl; + std::cout << " -c --config Show config dialog" << std::endl; + std::cout << " -n --no-config Disable config dialog, reuse last settings" << std::endl; + delete log; + return EXIT_SUCCESS; + case 'M': withMetaServer = true; break; + case 'u': + log->debug ( std::string ("Setting username to ") + optarg); + username = optarg; + break; + case 'p': + log->debug ( std::string ("Setting password to ") + optarg); + password = optarg; + break; + case 's': log->debug ( std::string ("Setting server to ") + optarg); hostname = optarg; break; @@ -117,22 +117,26 @@ log->info(PACKAGE_STRING); #endif - log->info( std::string( "User: " + username + " looking for host: " + hostname ) ); asio::io_service io_service; + + if ( withMetaServer ){ + OpenGate::MetaConnection meta( io_service ); + if ( meta.login( username, password ) > 0) { + } + } + OpenGate::NetworkClient nw( io_service, hostname ); - OpenGate::MetaConnection meta( io_service ); - if (meta.login( username, password ) > 0) { - + if ( nw.online() ){ // //** waiting for userid; asio::thread t( boost::bind( & asio::io_service::run, & io_service ) ); - + while( nw.online() && nw.userID() == 0 ){ myMSleep( 100 ); } - + log->info( std::string( "Userid: " + toStr(nw.userID() ) ) ); log->info( std::string( "Login user: " + username + " to: " + nw.hostname() ) ); nw.login( username ); @@ -156,7 +160,7 @@ #endif } - } + nw.close(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |