/* test a level until all balls got lost */ void client_game_test_level( Level *level ) { stk_display_fade( STK_FADE_IN, STK_FADE_DEFAULT_TIME ); client_game_init_testing( level ); client_game_run(); client_game_finalize(); stk_display_fade( STK_FADE_OUT, STK_FADE_DEFAULT_TIME ); }
/* ==================================================================== Handle confirmation/cancelling of confirmation dialogue. ==================================================================== */ void client_confirm( GuiWidget *widget, GuiEvent *event ) { #ifdef NETWORK_ENABLED if ( event->type != GUI_CLICKED ) return; gui_widget_hide( dlg_confirm ); msg_begin_writing( msgbuf, &msglen, MAX_MSG_SIZE ); switch ( client_state ) { case CLIENT_ANSWER: msg_write_int8( MSG_ACCEPT_CHALLENGE ); client_transmit( CODE_BLUE, msglen, msgbuf ); /* play */ gui_disable_event_filter(); if ( client_game_init_network( mp_peer_name, mp_diff ) ) client_game_run(); client_game_finalize(); gui_enable_event_filter(); gui_widget_draw( dlg_chatroom ); stk_display_fade( STK_FADE_IN, STK_FADE_DEFAULT_TIME ); break; } #endif }
int main(int argc, char *argv[]) { int result = ACTION_NONE; int leave = 0; char *editor_file = 0; char path[512]; SDL_Surface *loading; #ifdef __unix__ gid_t realgid; hi_dir_chart_file = fopen(HI_DIR "/" CHART_FILE_NAME, "r+"); /* This is where we drop our setuid/setgid privileges. */ realgid = getgid(); if (setresgid(-1, realgid, realgid) != 0) { perror("Could not drop setgid privileges. Aborting."); exit(1); } #endif /* i18n */ #ifdef ENABLE_NLS setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); #endif #ifdef _WIN32 /* Get Windows to open files in binary mode instead of default text mode */ _fmode = _O_BINARY; #endif /* lbreakout info */ printf( "LBreakout2 %s\nCopyright 2001-2010 Michael Speck\nPublished under GNU GPL\n---\n", VERSION ); printf( "Looking up data in: %s\n", SRC_DIR ); printf( "Looking up highscores in: %s\n", HI_DIR ); printf( "Looking up custom levels in: %s/%s/lbreakout2-levels\n", (getenv( "HOME" )?getenv( "HOME" ):"."), CONFIG_DIR_NAME ); #ifndef AUDIO_ENABLED printf( "Compiled without sound and music\n" ); #endif set_random_seed(); /* set random seed */ config_load(); stk_init( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK ); if ( config.fullscreen ) stk_display_open( SDL_SWSURFACE | SDL_FULLSCREEN, 640, 480, 16 ); else stk_display_open( SDL_SWSURFACE, 640, 480, 16 ); stk_audio_open( 0,0,0,config.audio_buffer_size ); SDL_WM_SetCaption( "LBreakout2", 0 ); SDL_SetEventFilter( event_filter ); stk_audio_enable_sound( config.sound ); stk_audio_set_sound_volume( config.volume * 16 ); /* load a little loading pic */ stk_surface_set_path( SRC_DIR "/gfx" ); loading = stk_surface_load( SDL_SWSURFACE, "loading.png" ); stk_surface_blit( loading, 0,0,-1,-1, stk_display, (stk_display->w-loading->w)/2, (stk_display->h-loading->h)/2 ); stk_display_update( STK_UPDATE_ALL ); /* load the GUI graphics from SRC_DIR/gui_theme */ stk_surface_set_path( SRC_DIR ); stk_audio_set_path( SRC_DIR ); gui_init( "gui_theme" ); stk_surface_set_path( SRC_DIR "/gfx" ); stk_audio_set_path( SRC_DIR "/sounds" ); /* load resources */ /* for simplicity all functions are kept but anything * that is now themeable is loaded in * theme_load instead of the original function * (deleting resources works analouge) */ theme_get_list(); if ( config.theme_count != theme_count ) { if ( config.theme_id >= theme_count ) config.theme_id = 0; config.theme_count = theme_count; } theme_load( theme_names[config.theme_id] ); /* old functions still with initialzations of * lists or variables */ client_game_create(); hint_load_res(); chart_load(); manager_create(); client_create(); exp_load(); editor_create(); help_create(); /* run game */ manager_fade( STK_FADE_IN ); while( !leave && !stk_quit_request ) { result = manager_run(); switch( result ) { case ACTION_QUIT: leave = 1; break; case ACTION_RESUME_0: manager_fade( STK_FADE_OUT ); if ( client_game_resume_local( 0 ) ) client_game_run(); client_game_finalize(); manager_fade( STK_FADE_IN ); break; case ACTION_PLAY_LBR: manager_fade( STK_FADE_OUT ); gameSeed = rand(); /* set random seed for next FREAKOUT/BonusLevels */ if ( client_game_init_local( "LBreakout2" ) ) client_game_run(); client_game_finalize(); manager_fade( STK_FADE_IN ); break; case ACTION_PLAY_CUSTOM: manager_fade( STK_FADE_OUT ); gameSeed = rand(); /* set random seed for next FREAKOUT/BonusLevels */ if (gameSeed==0) gameSeed=1; /* not allowed because.... A HACK!!! 0 means to have no bonus levels to save a parameter */ if ( client_game_init_local( levelset_names_local[config.levelset_id_local] ) ) client_game_run(); client_game_finalize(); manager_fade( STK_FADE_IN ); break; case ACTION_EDIT: /* new set? */ if ( strequal( NEW_SET, edit_set ) ) { editor_file = calloc( 16, sizeof( char ) ); snprintf( path, sizeof(path)-1, "%s/%s/lbreakout2-levels", getenv( "HOME" )? getenv("HOME"):".", CONFIG_DIR_NAME ); if ( !enter_string( font, _("Set Name:"), editor_file, 12 ) || !file_check( path, editor_file, "w" ) ) { free( editor_file ); break; } else manager_update_set_list(); } else editor_file = strdup( edit_set ); if ( editor_init( editor_file ) ) { manager_fade( STK_FADE_OUT ); editor_run(); editor_clear(); manager_fade( STK_FADE_IN ); } free( editor_file ); editor_file = 0; break; case ACTION_QUICK_HELP: help_run(); break; case ACTION_CLIENT: manager_fade( STK_FADE_OUT ); client_run(); manager_fade( STK_FADE_IN ); break; default: break; } } manager_fade( STK_FADE_OUT ); /* delete stuff */ help_delete(); manager_delete(); chart_save(); chart_delete(); editor_delete(); exp_delete(); client_game_delete(); hint_delete_res(); theme_delete(); theme_delete_list(); stk_surface_free( &loading ); config_save(); if (hi_dir_chart_file) fclose(hi_dir_chart_file); return EXIT_SUCCESS; }
static void client_parse_packet() { int i, num; char name[16]; unsigned char type; int handled; while ( 1 ) { type = (unsigned)msg_read_int8(); handled = 0; if ( msg_read_failed() ) break; /* no more messages */ switch ( type ) { case MSG_PREPARE_FULL_UPDATE: /* do only clear users as channels and * levelsets are fixed */ list_clear( client_users ); client_user = 0; handled = 1; break; case MSG_ERROR: client_printf_chatter( 1, _("ERROR: %s"), msg_read_string() ); handled = 1; break; case MSG_BUSY: if ( client_state == CLIENT_AWAIT_ANSWER || client_state == CLIENT_AWAIT_TRANSFER_CONFIRMATION ) client_popup_info( _("%s is busy at the moment."), mp_peer_name ); handled = 1; break; case MSG_DISCONNECT: client_disconnect(); handled = 1; break; case MSG_SET_COMM_DELAY: client_comm_delay = msg_read_int16(); printf( _("comm_delay set to %i\n"), client_comm_delay ); handled = 1; break; /* chatter */ case MSG_SERVER_INFO: client_add_chatter( msg_read_string(), 1 ); handled = 1; break; case MSG_CHATTER: client_add_chatter( msg_read_string(), 0 ); handled = 1; break; /* users */ case MSG_ADD_USER: num = msg_read_int32(); snprintf( name, 16, "%s", msg_read_string() ); name[15] = 0; if ( msg_read_failed() ) break; client_add_user( num, name ); gui_list_update( list_users, client_users->count ); /* re-select current entry */ if ( client_user ) { num = list_check( client_users, client_user ); if ( num != -1 ) gui_list_select( list_users, 0, num, 1 ); } handled = 1; break; case MSG_REMOVE_USER: num = msg_read_int32(); if ( msg_read_failed() ) break; client_remove_user( num ); gui_list_update( list_users, client_users->count ); /* re-select current entry */ if ( client_user ) { num = list_check( client_users, client_user ); if ( num != -1 ) gui_list_select( list_users, 0, num, 1 ); } handled = 1; break; case MSG_CHANNEL_LIST: list_clear( client_channels ); num = msg_read_int8(); for ( i = 0; i < num; i++ ) list_add( client_channels, strdup(msg_read_string()) ); handled = 1; break; case MSG_LEVELSET_LIST: list_clear( client_levelsets ); num = msg_read_int8(); for ( i = 0; i < num; i++ ) list_add( client_levelsets, strdup(msg_read_string()) ); gui_list_update( list_levels, client_levelsets->count ); handled = 1; break; case MSG_ADD_LEVELSET: list_add( client_levelsets, strdup(msg_read_string()) ); gui_list_update( list_levels, client_levelsets->count ); handled = 1; break; case MSG_SET_CHANNEL: /* we only need to update the name */ gui_label_set_text( label_channel, msg_read_string() ); handled = 1; break; /* challenge */ case MSG_CHALLENGE: /* the user may only be challenged if client state is NONE because otherwise he is doing something that shouldn't be interrupted */ if ( client_state != CLIENT_NONE ) { msg_begin_writing( msgbuf, &msglen, 128 ); msg_write_int8( MSG_BUSY ); msg_write_int32( msg_read_int32() ); client_transmit( CODE_BLUE, msglen, msgbuf ); break; } snprintf( mp_peer_name, 15, "%s", msg_read_string() ); snprintf( mp_levelset, 16, "%s", msg_read_string() ); mp_diff = msg_read_int8(); mp_rounds = msg_read_int8(); mp_frags = msg_read_int8(); mp_balls = msg_read_int8(); if ( msg_read_failed() ) break; client_popup_confirm( _(" You have been challenged!##"\ " Challenger: %13s#"\ " Levelset: %13s#"\ " Difficulty: %13s#"\ " Rounds: %13i#"\ " Frag Limit: %13i#"\ " Balls: %13i"), mp_peer_name, mp_levelset, mp_diff_names[mp_diff], mp_rounds, mp_frags, mp_balls ); client_state = CLIENT_ANSWER; handled = 1; break; case MSG_REJECT_CHALLENGE: handled = 1; if ( client_state != CLIENT_AWAIT_ANSWER ) break; client_popup_info( _("%s is too scared to accept your challenge."), mp_peer_name ); break; case MSG_CANCEL_GAME: handled = 1; if ( client_state != CLIENT_ANSWER ) break; gui_widget_hide( dlg_confirm ); client_popup_info( _("%s got cold feet."), mp_peer_name ); break; case MSG_ACCEPT_CHALLENGE: handled = 1; if ( client_state != CLIENT_AWAIT_ANSWER ) break; gui_widget_hide( dlg_info ); /* play */ gui_disable_event_filter(); if ( client_game_init_network( mp_peer_name, mp_diff ) ) client_game_run(); client_game_finalize(); gui_enable_event_filter(); gui_widget_draw( dlg_chatroom ); stk_display_fade( STK_FADE_IN, STK_FADE_DEFAULT_TIME ); break; /* dummy parse game packets that may arrive after the QUIT_GAME * message was sent because ADD_USER commands may be in the * package and these we should get. */ case MSG_PADDLE_STATE: comm_unpack_paddle_dummy( net_buffer, &msg_read_pos ); handled = 1; break; case MSG_SHOT_POSITIONS: comm_unpack_shots_dummy( net_buffer, &msg_read_pos ); handled = 1; break; case MSG_BALL_POSITIONS: comm_unpack_balls_dummy( net_buffer, &msg_read_pos ); handled = 1; break; case MSG_SCORES: comm_unpack_scores_dummy( net_buffer, &msg_read_pos ); handled = 1; break; case MSG_BRICK_HITS: comm_unpack_brick_hits_dummy( net_buffer, &msg_read_pos ); handled = 1; break; case MSG_NEW_EXTRAS: comm_unpack_collected_extras_dummy( net_buffer, &msg_read_pos ); handled = 1; break; case MSG_ROUND_OVER: i = msg_read_int8(); handled = 1; break; case MSG_LAST_ROUND_OVER: i = msg_read_int8(); handled = 1; break; } if ( !handled ) { printf( _("chat: state %i: invalid message %x: skipping %i bytes\n"), client_state, type, net_buffer_cur_size - msg_read_pos ); msg_read_pos = net_buffer_cur_size; } } }