Exemple #1
0
int main(int argc, char *argv[])
{
    float tick;

    /* Server defaults */
    server.port = DEFAULT_PORT;
    server.fps = DEFAULT_FPS;
    server.max_clients = DEFAULT_MAXCLIENTS;
    server.clients = 0;
    server.exit_when_empty = 0;
    strncpy(server.name, "Chickens With Attitude", 32);

    /* Game defaults */
    game.changelevel = 0;
    game.fraglimit = 0;
    game.timelimit = 0;
    game.mode = HOLYWAR;
    game.objective = GAME_EXIT_LEVEL;
    strncpy(game.map_name, "unfinished_sympathy.map", NETMSG_STRLEN);

    /* Command line arguments */
    if( argc > 1 )
	handle_cl_args(argc, argv);

    calc_lookup_tables(DEGREES);
    entity_init();
    weapon_init();

    /* Initilaise networking. TRY to use server.port, but return the actual
       port we manage to get */
    if( (server.port = sv_net_init(server.port)) >= 0 )
	printf("Waiting for connections on port %d\n", server.port);
    else {
	printf("Unable to initialise network. Exiting.\n");
	return EXIT_FAILURE;
    }

    if( sv_map_changelevel(game.map_name, game.mode) < 0 ) {
	printf("Error, unable to load map\n");
	return EXIT_FAILURE;
    }

    tick = 1.0 / server.fps;
    server.quit = 0;

    /* Server main loop */
    while( !server.quit ) {
	/*
	  printf("Press to continue.....\n");
	  fflush(NULL);
	  getchar();
	*/

	server.now = gettime();
	sv_net_get_client_input();
	world_update( tick );
	game_update();
	sv_net_send_start_frames(); /* Begin each clients frames */
	sv_net_update_clients();
	cap_fps(server.fps);
    }

    return EXIT_SUCCESS;

}
Exemple #2
0
int main(int argc, char *argv[])
{
    byte keypress;

    client_init();

    if( argc > 1 )    /* Command line arguments */
	handle_cl_args(argc, argv);

    srand( time(NULL) );
    calc_lookup_tables(DEGREES);
    win_init();
    entity_init();
    if( (ent_img_loaded = (char *)malloc(num_entity_types)) == NULL ) {
	perror("Malloc");
	ERR_QUIT("Error allocating ent_img_loaded array", 1);
    } else {
	memset(ent_img_loaded, 0, num_entity_types);
    }

    /* Load client preferences from file */
    read_config_file( &client );
    /* Set view dimensions, which are calculated by tile width & heights */
    client.view_w = client.x_tiles * TILE_W;
    client.view_h = client.y_tiles * TILE_H;
    /* What the client WISHES their dimensions were (this may not be what
       it actually is, ie in demo's etc */
    client.desired_w = client.view_w;
    client.desired_h = client.view_h;

    weapon_type_init();
    particle_init();
    menu_init();

    cl_network_init();

    client.state = MENU;

    if( client.demo == DEMO_PLAY ) {
	cl_network_connect(NULL, 42);
	client.state = GAME_LOAD;
    }

    for( ; ; ) {
	switch( client.state ) {
	case MENU:
	    win_ungrab_pointer();
	    menu_driver();
	    break;

	case GAME_LOAD:
	    win_set_properties(VERSION, client.view_w, client.view_h+STATUS_H);
	    wait_till_expose(5);

	    /* Finished loading, we are ready to play */
	    cl_change_map(client.map, client.gamemode);
	    break;

	case GAME_RESUME: /* Resume game from menu */
	    win_set_properties(VERSION, client.view_w, client.view_h+STATUS_H);
	    wait_till_expose(5);
	    input_clear();
	    draw_status_bar();
	    cl_netmsg_send_ready(); /* Tell server new details */
	    cl_net_finish(); /* Send the NETMSG_READY to the server */
	    client.state = GAME_JOIN;

	    break;

	case GAME_JOIN:

        win_set_cursor( client.mousemode!=MOUSEMODE_ROTATE );
        win_set_cursor( 1 );


	    if( client.mousemode ) {
		win_grab_pointer();
	    }

	    text_buf_clear();
	    particle_clear();

	case GAME_PLAY:
	    cl_net_update();

	    if( client.state == GAME_PLAY ) { /* Maybe changed in net_update */
		draw_crosshair( my_entity );
		if( client.map_target_active )
		    draw_map_target( my_entity );

		text_buf_update();
		if( client.netstats )
		    cl_net_stats();

		win_update();

		/* Keyboard Input */
		client.dir = my_entity.dir;
		keypress = get_input();
		cl_netmsg_send_cl_update(keypress, client.dir);
	    }

	    cl_net_finish(); /* Send things that need sending */
	    cap_fps(client.fps);
	    break;

	case QUIT:
	    game_close();
	    image_close(); /* Free all the images */
	    win_close();
	    write_config_file(&client);
	    if( ent_img_loaded != NULL )
		free(ent_img_loaded);
	    exit(EXIT_SUCCESS);
	    break;
	}

    }

    return EXIT_SUCCESS;

}