Esempio n. 1
0
void  do_client(t_server *server)
{
  int i;

  if (server->actual == 4)
    {
      for(i = 0; i < server->actual; i++)
	write(clients[i].sock, "go\n", my_strlen("go\n"));  
      my_putstr("GAME ON !!\n");
      launch_game(server);
    }
}
Esempio n. 2
0
bool game_launcher::goto_campaign()
{
	if(jump_to_campaign_.jump_){
		if(new_campaign()) {
			jump_to_campaign_.jump_ = false;
			launch_game(NO_RELOAD_DATA);
		}else{
			jump_to_campaign_.jump_ = false;
			return false;
		}
	}
	return true;
}
Esempio n. 3
0
bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
{
    init_args(game_params, cmd_args);

    // List video modes if requested
    if (list_video_modes)
        return print_video_modes();

    if (!init_engine(game_params.log_level)) {
        errorstream << "Could not initialize game engine." << std::endl;
        return false;
    }

    // Create time getter
    g_timegetter = new IrrlichtTimeGetter(device);

    // Speed tests (done after irrlicht is loaded to get timer)
    if (cmd_args.getFlag("speedtests")) {
        dstream << "Running speed tests" << std::endl;
        speed_tests();
        return true;
    }

    video::IVideoDriver *video_driver = device->getVideoDriver();
    if (video_driver == NULL) {
        errorstream << "Could not initialize video driver." << std::endl;
        return false;
    }

    porting::setXorgClassHint(video_driver->getExposedVideoData(), PROJECT_NAME_C);

    /*
    	This changes the minimum allowed number of vertices in a VBO.
    	Default is 500.
    */
    //driver->setMinHardwareBufferVertexCount(50);

    // Create game callback for menus
    g_gamecallback = new MainGameCallback(device);

    device->setResizable(true);

    if (random_input)
        input = new RandomInputHandler();
    else
        input = new RealInputHandler(device, receiver);

    smgr = device->getSceneManager();
    smgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);

    guienv = device->getGUIEnvironment();
    skin = guienv->getSkin();
    skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255, 255, 255, 255));
    skin->setColor(gui::EGDC_3D_LIGHT, video::SColor(0, 0, 0, 0));
    skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255, 30, 30, 30));
    skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255, 0, 0, 0));
    skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 70, 120, 50));
    skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255, 255, 255, 255));

    g_fontengine = new FontEngine(g_settings, guienv);
    FATAL_ERROR_IF(g_fontengine == NULL, "Font engine creation failed.");

#if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2
    // Irrlicht 1.8 input colours
    skin->setColor(gui::EGDC_EDITABLE, video::SColor(255, 128, 128, 128));
    skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255, 96, 134, 49));
#endif

    // Create the menu clouds
    if (!g_menucloudsmgr)
        g_menucloudsmgr = smgr->createNewSceneManager();
    if (!g_menuclouds)
        g_menuclouds = new Clouds(g_menucloudsmgr->getRootSceneNode(),
                                  g_menucloudsmgr, -1, rand(), 100);
    g_menuclouds->update(v2f(0, 0), video::SColor(255, 200, 200, 255));
    scene::ICameraSceneNode* camera;
    camera = g_menucloudsmgr->addCameraSceneNode(0,
             v3f(0, 0, 0), v3f(0, 60, 100));
    camera->setFarValue(10000);

    /*
    	GUI stuff
    */

    ChatBackend chat_backend;

    // If an error occurs, this is set to something by menu().
    // It is then displayed before	the menu shows on the next call to menu()
    std::string error_message;

    bool first_loop = true;

    /*
    	Menu-game loop
    */
    bool retval = true;
    bool *kill = porting::signal_handler_killstatus();

    while (device->run() && !*kill && !g_gamecallback->shutdown_requested)
    {
        // Set the window caption
        const wchar_t *text = wgettext("Main Menu");
        device->setWindowCaption((narrow_to_wide("MultiCraft") + L" [" + text + L"]").c_str());
        delete[] text;

#ifdef ANDROID
        porting::handleAndroidActivityEvents();
#endif

        try {	// This is used for catching disconnects

            guienv->clear();

            /*
            	We need some kind of a root node to be able to add
            	custom gui elements directly on the screen.
            	Otherwise they won't be automatically drawn.
            */
            guiroot = guienv->addStaticText(L"", core::rect<s32>(0, 0, 10000, 10000));

            bool game_has_run = launch_game(error_message, game_params, cmd_args);

            // If skip_main_menu, we only want to startup once
            if (skip_main_menu && !first_loop)
                break;

            first_loop = false;

            if (!game_has_run) {
                if (skip_main_menu)
                    break;
                else
                    continue;
            }

            // Break out of menu-game loop to shut down cleanly
            if (!device->run() || *kill) {
                if (g_settings_path != "")
                    g_settings->updateConfigFile(g_settings_path.c_str());
                break;
            }

            if (current_playername.length() > PLAYERNAME_SIZE-1) {
                error_message = gettext("Player name too long.");
                playername = current_playername.substr(0, PLAYERNAME_SIZE-1);
                g_settings->set("name", playername);
                continue;
            }

            device->getVideoDriver()->setTextureCreationFlag(
                video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map"));

#ifdef HAVE_TOUCHSCREENGUI
            receiver->m_touchscreengui = new TouchScreenGUI(device, receiver);
            g_touchscreengui = receiver->m_touchscreengui;
#endif
            the_game(
                kill,
                random_input,
                input,
                device,
                worldspec.path,
                current_playername,
                current_password,
                current_address,
                current_port,
                error_message,
                chat_backend,
                gamespec,
                simple_singleplayer_mode
            );
            smgr->clear();

#ifdef HAVE_TOUCHSCREENGUI
            delete g_touchscreengui;
            g_touchscreengui = NULL;
            receiver->m_touchscreengui = NULL;
#endif

        } //try
        catch (con::PeerNotFoundException &e) {
            error_message = gettext("Connection error (timed out?)");
            errorstream << error_message << std::endl;
        }

#ifdef NDEBUG
        catch (std::exception &e) {
            std::string error_message = "Some exception: \"";
            error_message += e.what();
            error_message += "\"";
            errorstream << error_message << std::endl;
        }
#endif

        // If no main menu, show error and exit
        if (skip_main_menu) {
            if (!error_message.empty()) {
                verbosestream << "error_message = "
                              << error_message << std::endl;
                retval = false;
            }
            break;
        }
    } // Menu-game loop

    g_menuclouds->drop();
    g_menucloudsmgr->drop();

    return retval;
}
Esempio n. 4
0
int
Main::run(int argc, char** argv)
{
  int result = 0;

  try
  {
    CommandLineArguments args;

    try
    {
      args.parse_args(argc, argv);
      g_log_level = args.get_log_level();
    }
    catch(const std::exception& err)
    {
      std::cout << "Error: " << err.what() << std::endl;
      return EXIT_FAILURE;
    }

    PhysfsSubsystem physfs_subsystem(argv[0], args.datadir, args.userdir);
    physfs_subsystem.print_search_path();

    timelog("config");
    ConfigSubsystem config_subsystem;
    args.merge_into(*g_config);

    timelog("tinygettext");
    init_tinygettext();

    switch (args.get_action())
    {
      case CommandLineArguments::PRINT_VERSION:
        args.print_version();
        return 0;

      case CommandLineArguments::PRINT_HELP:
        args.print_help(argv[0]);
        return 0;

      case CommandLineArguments::PRINT_DATADIR:
        args.print_datadir();
        return 0;

      default:
        launch_game();
        break;
    }
  }
  catch(const std::exception& e)
  {
    log_fatal << "Unexpected exception: " << e.what() << std::endl;
    result = 1;
  }
  catch(...)
  {
    log_fatal << "Unexpected exception" << std::endl;
    result = 1;
  }

  g_dictionary_manager.reset();

  return result;
}
Esempio n. 5
0
File: main.c Progetto: plean/CPE
int	main(void)
{
  launch_game();
  return (0);
}
Esempio n. 6
0
int
Main::run(int argc, char** argv)
{
#ifdef WIN32
	//SDL is used instead of PHYSFS because both create the same path in app data
	//However, PHYSFS is not yet initizlized, and this should be run before anything is initialized
	std::string prefpath = SDL_GetPrefPath("SuperTux", "supertux2");

	std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;

	//All this conversion stuff is necessary to make this work for internationalized usernames
	std::string outpath = prefpath + u8"/console.out";
	std::wstring w_outpath = converter.from_bytes(outpath);
	_wfreopen(w_outpath.c_str(), L"a", stdout);

	std::string errpath = prefpath + u8"/console.err";
	std::wstring w_errpath = converter.from_bytes(errpath);
	_wfreopen(w_errpath.c_str(), L"a", stderr);
#endif

  // Create and install global locale
  std::locale::global(boost::locale::generator().generate(""));
  // Make boost.filesystem use it
  boost::filesystem::path::imbue(std::locale());

  int result = 0;

  try
  {
    CommandLineArguments args;

    try
    {
      args.parse_args(argc, argv);
      g_log_level = args.get_log_level();
    }
    catch(const std::exception& err)
    {
      std::cout << "Error: " << err.what() << std::endl;
      return EXIT_FAILURE;
    }

    PhysfsSubsystem physfs_subsystem(argv[0], args.datadir, args.userdir);
    physfs_subsystem.print_search_path();

    timelog("config");
    ConfigSubsystem config_subsystem;
    args.merge_into(*g_config);

    timelog("tinygettext");
    init_tinygettext();

    switch (args.get_action())
    {
      case CommandLineArguments::PRINT_VERSION:
        args.print_version();
        return 0;

      case CommandLineArguments::PRINT_HELP:
        args.print_help(argv[0]);
        return 0;

      case CommandLineArguments::PRINT_DATADIR:
        args.print_datadir();
        return 0;

      default:
        launch_game();
        break;
    }
  }
  catch(const std::exception& e)
  {
    log_fatal << "Unexpected exception: " << e.what() << std::endl;
    result = 1;
  }
  catch(...)
  {
    log_fatal << "Unexpected exception" << std::endl;
    result = 1;
  }

  g_dictionary_manager.reset();

  return result;
}
Esempio n. 7
0
/* The main installer code */
int main(int argc, char **argv)
{
    int exit_status, get_out = 0;
    int i, c;
    install_state state;
    char *xml_file = SETUP_CONFIG;
    log_level verbosity = LOG_NORMAL;
    char install_path[PATH_MAX];
    char binary_path[PATH_MAX];
	const char *product_prefix = NULL, *str;
    struct enabled_option *enabled_opt;
#if defined(darwin)
    // If we're on Mac OS, we need to make sure the current working directoy
    //  is the same directoy as the .APP is in.  With Mac OS X, running from
    //  the finder and most other places makes the current directory to root.
#define CARBON_MAX_PATH 1024
    char carbon_app_path[CARBON_MAX_PATH];
    carbon_GetAppPath(carbon_app_path, CARBON_MAX_PATH);
    chdir(carbon_app_path);
#endif
    install_path[0] = '\0';
    binary_path[0] = '\0';

    /* Set a good default umask value (022) */
    umask(DEFAULT_UMASK);

	/* Set the locale */
	setlocale (LC_ALL, "");
	bindtextdomain (PACKAGE, LOCALEDIR);
	textdomain (PACKAGE);

	DetectLocale();

    /* Parse the command-line options */
    while ( (c=getopt(argc, argv,
#ifdef RPM_SUPPORT
					  "hnc:f:r:v:Vi:b:mo:p:"
#else
					  "hnc:f:v:Vi:b:o:p:"
#endif
					  )) != EOF ) {
        switch (c) {
		case 'c':
			if ( chdir(optarg) < 0 ) {
				perror(optarg);
				exit(3);
			}
			break;
		case 'f':
			xml_file = optarg;
			break;
		case 'n':
			force_console = 1;
			break;
#ifdef RPM_SUPPORT
		case 'r':
			rpm_root = optarg;
			break;
#endif
		case 'v':
			if ( optarg ) {
				verbosity = atoi(optarg);
				if ( (verbosity < LOG_DEBUG) || (verbosity > LOG_FATAL) ){
					fprintf(stderr,
							_("Out of range value, setting verbosity level to normal.\n"));
					verbosity = LOG_NORMAL;
				}
			} else {
				verbosity = LOG_DEBUG;
			}
			break;
		case 'V':
			printf("Loki Setup version " SETUP_VERSION ", built on "__DATE__"\n");
			exit(0);
	    case 'i':
	        strncpy(install_path, optarg, sizeof(install_path));
			disable_install_path = 1;
 			break;
	    case 'b':
	        strncpy(binary_path, optarg, sizeof(binary_path));
			disable_binary_path = 1;
			break;
		case 'p':
			product_prefix = optarg;
			break;
        case 'o': /* Store the enabled options for later processing */
            enabled_opt = (struct enabled_option *)malloc(sizeof(struct enabled_option));
            enabled_opt->option = strdup(optarg);
            enabled_opt->next = enabled_options;
            enabled_options = enabled_opt;
            break;
#ifdef RPM_SUPPORT
	    case 'm':
	        force_manual = 1;
			break;
#endif
		default:
			print_usage(argv[0]);
			exit(0);
        }
    }

	InitPlugins();
	if ( verbosity == LOG_DEBUG ) {
		DumpPlugins(stderr);
	}

	log_init(verbosity);

    /* Initialize the XML setup configuration */
    info = create_install(xml_file, install_path, binary_path, product_prefix);
    if ( info == NULL ) {
        fprintf(stderr, _("Couldn't load '%s'\n"), xml_file);
        exit(3);
    }

    /* Get the appropriate setup UI */
    for ( i=0; GUI_okay[i]; ++i ) {
        if ( GUI_okay[i](&UI, &argc, &argv) ) {
            break;
        }
    }
    if ( ! GUI_okay[i] ) {
        log_debug(_("No UI drivers available\n"));
        exit(2);
    }

    /* Setup the interrupt handlers */
    state = SETUP_INIT;
    signal(SIGINT, signal_abort);
    signal(SIGQUIT, signal_abort);
    signal(SIGHUP, signal_abort);
    signal(SIGTERM, signal_abort);

    /* Run the little state machine */
    exit_status = 0;
    while ( ! get_out ) {
        char buf[1024];
        int num_cds = 0;

        switch (state) {
            case SETUP_INIT:
                num_cds = GetProductCDROMDescriptions(info);
                /* Check for the presence of a CDROM if required */
                if ( GetProductCDROMRequired(info) ) {
                    if ( ! GetProductCDROMFile(info) ) {
                        log_fatal(_("The 'cdromfile' attribute is now mandatory when using the 'cdrom' attribute."));
                    }
                    add_cdrom_entry(info, info->name, info->desc, GetProductCDROMFile(info));
					++ num_cds;
				}

                state = UI.init(info,argc,argv, enabled_options != NULL);
                if ( state == SETUP_ABORT ) {
                    exit_status = 3;
                }
				/* Check if getcwd() works now */
				if ( getcwd(buf, sizeof(buf)) == NULL ) {
					UI.prompt(_("Unable to determine the current directory.\n"
								"Please check the permissions of the parent directories.\n"), RESPONSE_OK);
					state = SETUP_EXIT;
					continue;
				}
                
				/* Check if we should be root.  Under the Mac, we'll do the standard authorization
                   stuff that most installers do at startup. */
                if ( GetProductRequireRoot(info) && geteuid()!=0 ) {
#if defined(darwin)
                carbon_AuthorizeUser();
                state = SETUP_EXIT;
                break;
#else
					UI.prompt(_("You need to run this installer as the super-user.\n"), RESPONSE_OK);
					state = SETUP_EXIT;
					continue;
#endif
                }

				if ( info->product && GetProductInstallOnce(info) ) {
					UI.prompt(_("\nThis product is already installed.\nUninstall it before running this program again.\n"), RESPONSE_OK);
					state = SETUP_EXIT;
					continue;
				}
				if ( info->product && GetProductReinstall(info) ) {
					UI.prompt(_("Warning: You are about to reinstall\non top of an existing installation.\n"), RESPONSE_OK);
					info->options.reinstalling = 1;
					/* Restore the initial environment */
					loki_put_envvars(info->product);
				}
                /* Check for the presence of the product if we install a component */
                if ( GetProductComponent(info) ) {
                    if ( GetProductNumComponents(info) > 0 ) {
                        UI.prompt(_("\nIllegal installation: do not mix components with a component installation.\n"), RESPONSE_OK);
                        state = SETUP_EXIT;
						continue;
                    } else if ( info->product ) {
                        if ( ! info->component ) {
                            snprintf(buf, sizeof(buf), _("\nThe %s component is already installed.\n"
                                                         "Please uninstall it beforehand.\n"),
                                     GetProductComponent(info));
                            UI.prompt(buf, RESPONSE_OK);
                            state = SETUP_EXIT;
							continue;
                        }
                    } else {                        
                        snprintf(buf, sizeof(buf), _("\nYou must install %s before running this\n"
													 "installation program.\n"),
                                info->desc);
                        UI.prompt(buf, RESPONSE_OK);
                        state = SETUP_EXIT;
						continue;
                    }
                }

                /* Check for the presence of a CDROM if required */
				if ( num_cds > 0) {
                    detect_cdrom(info);
                }
                if ( GetProductCDROMRequired(info) && ! get_cdrom(info, info->name) ) {
					state = SETUP_EXIT;
					break;
                }

				if ( ! CheckRequirements(info) ) {
					state = SETUP_ABORT;
					break;
				}

                if ( enabled_options ) {
                    enabled_opt = enabled_options;
                    while ( enabled_opt ) {
                        if ( enable_option(info, enabled_opt->option) == 0 ) {
                            log_warning(_("Could not enable option: %s"), enabled_opt->option);
                        }
                        enabled_opt = enabled_opt->next;
                    }
                    state = SETUP_INSTALL;
                }
                break;
	    case SETUP_CLASS:
			state = UI.pick_class(info);
		break;
            case SETUP_LICENSE:
                state = UI.license(info);
                break;
            case SETUP_README:
                state = UI.readme(info);
                break;
            case SETUP_OPTIONS:
                state = UI.setup(info);
                break;
            case SETUP_INSTALL:
                install_preinstall(info);
                state = install(info, UI.update);
                install_postinstall(info);
                break;
            case SETUP_WEBSITE:
                state = UI.website(info);
                break;
            case SETUP_COMPLETE:
                state = UI.complete(info);
				/* Check for a post-install message */
				str = GetProductPostInstallMsg(info);
				if ( str ) {
					UI.prompt(str, RESPONSE_OK);
				}
                break;
            case SETUP_PLAY:
		if ( UI.shutdown ) 
		    UI.shutdown(info);
                state = launch_game(info);
                break;
            case SETUP_ABORT:
                abort_install();
                break;
            case SETUP_EXIT:
                /* Optional cleanup */
				if ( UI.exit ) {
					UI.exit(info);
				}
				get_out = 1;
                break;
        }
    }

    /* Free enabled_options */
    while ( enabled_options ) {
        enabled_opt = enabled_options;
        enabled_options = enabled_options->next;
        free(enabled_opt->option);
        free(enabled_opt);
    }

    exit_setup(exit_status);
    return 0;
}
Esempio n. 8
0
int
Main::run(int argc, char** argv)
{
#ifdef WIN32
	//SDL is used instead of PHYSFS because both create the same path in app data
	//However, PHYSFS is not yet initizlized, and this should be run before anything is initialized
	std::string prefpath = SDL_GetPrefPath("SuperTux", "supertux2");
	freopen((prefpath + "/console.out").c_str(), "a", stdout);
	freopen((prefpath + "/console.err").c_str(), "a", stderr);
#endif
 
  int result = 0;

  try
  {
    CommandLineArguments args;

    try
    {
      args.parse_args(argc, argv);
      g_log_level = args.get_log_level();
    }
    catch(const std::exception& err)
    {
      std::cout << "Error: " << err.what() << std::endl;
      return EXIT_FAILURE;
    }

    PhysfsSubsystem physfs_subsystem(argv[0], args.datadir, args.userdir);
    physfs_subsystem.print_search_path();

    timelog("config");
    ConfigSubsystem config_subsystem;
    args.merge_into(*g_config);

    timelog("tinygettext");
    init_tinygettext();

    switch (args.get_action())
    {
      case CommandLineArguments::PRINT_VERSION:
        args.print_version();
        return 0;

      case CommandLineArguments::PRINT_HELP:
        args.print_help(argv[0]);
        return 0;

      case CommandLineArguments::PRINT_DATADIR:
        args.print_datadir();
        return 0;

      default:
        launch_game();
        break;
    }
  }
  catch(const std::exception& e)
  {
    log_fatal << "Unexpected exception: " << e.what() << std::endl;
    result = 1;
  }
  catch(...)
  {
    log_fatal << "Unexpected exception" << std::endl;
    result = 1;
  }

  g_dictionary_manager.reset();

  return result;
}