void config_load( ) { char file_name[512]; PData *pd, *sub; /* set to defaults */ config_check_dir(); config_reset(); /* load config */ sprintf( file_name, "%s/%s", config.dir_name, CONFIG_FILE_NAME ); if ( ( pd = parser_read_file( "config", file_name ) ) == 0 ) { fprintf( stderr, "%s\n", parser_get_error() ); return; } /* parse config */ parser_get_int( pd, "gametype", &config.gametype ); parser_get_int( pd, "starting_level", &config.starting_level ); if (config.starting_level > 9 || config.starting_level < 0) { config.starting_level = 0; } parser_get_int( pd, "preview", &config.preview ); parser_get_int( pd, "help", &config.help ); parser_get_int( pd, "expert", &config.expert ); parser_get_int( pd, "center_preview", &config.center_preview ); parser_get_int( pd, "holes", &config.holes ); parser_get_int( pd, "rand_holes", &config.rand_holes ); parser_get_int( pd, "send_all", &config.send_all ); parser_get_int( pd, "send_tetris", &config.send_tetris ); if ( parser_get_pdata( pd, "player1", &sub ) ) parse_player( sub, &config.player1 ); if ( parser_get_pdata( pd, "player2", &sub ) ) parse_player( sub, &config.player2 ); if ( parser_get_pdata( pd, "player3", &sub ) ) parse_player( sub, &config.player3 ); parser_get_int( pd, "clear_keystate", &config.clear_keystate ); parser_get_int( pd, "cpu_aggr", &config.cpu_aggr ); parser_get_int( pd, "cpu_delay", &config.cpu_delay ); parser_get_int( pd, "cpu_rot_delay", &config.cpu_rot_delay ); parser_get_int( pd, "sound", &config.sound ); parser_get_int( pd, "volume", &config.volume ); parser_get_int( pd, "transparency", &config.trp ); parser_get_int( pd, "animations", &config.anim ); parser_get_int( pd, "fullscreen", &config.fullscreen ); parser_get_int( pd, "fading", &config.fade ); parser_get_int( pd, "fps", &config.fps ); parser_get_int( pd, "background", &config.bkgnd ); parser_get_int( pd, "static_background", &config.keep_bkgnd ); parser_get_int( pd, "smooth_hori", &config.smooth_hori ); parser_get_int( pd, "hori_delay", &config.hori_delay ); parser_get_int( pd, "vert_delay", &config.vert_delay ); parser_get_int( pd, "pause_key", &config.pause_key ); parser_get_int( pd, "block_by_block", &config.block_by_block ); parser_get_int( pd, "motion_mod", &config.motion_mod ); parser_get_int( pd, "relative_motion", &config.rel_motion ); parser_get_int( pd, "grap_input", &config.grab ); parser_get_int( pd, "invert_mouse", &config.invert ); parser_get_int( pd, "quick_help", &config.quick_help ); parser_get_int( pd, "async_collision_check", &config.async_col_check ); parser_free( &pd ); }
// Pre-parse logmsg line for args and to determine some possible type of // event. // // Returns an allocated event_args_t struct, which should be freed by the // main thread after it's no longer needed. Note that this struct gets // passed to (possibly) multiple hooks. event_args_t *parse_event_args(const char *logline) { event_args_t *args; char *cp, *begin, *end; int len; // Create and init the event_args struct. args=(event_args_t *) malloc(sizeof(event_args_t)); if(!args) return(NULL); memset(args, 0, sizeof(*args)); // Make a copy of the logline, as we're going to be setting NULLs in // the string to mark ends of various substrings. args->buf=strdup(logline); if(!args->buf) return(NULL); cp=args->buf; // Grab the player name and attributes, or "world" or "team" name, ie: // Joe<15><785><CT> // World // Team "CT" args->player=parse_player(cp, &len); cp+=len; // Look for one of several pre-determined actions that we recognize. // ... triggered "some action" ... // ie: "Joe<15><785><CT>" triggered "Killed_A_Hostage" if(strnmatch(cp, "triggered ", 10)) { cp+=10; args->action=parse_quoted(cp, &len); cp+=len; } // ... killed Joe<15><785><CT> ... // ie: "Joe<15><785><CT>" killed "Sam<17><197><TERRORIST>" with "sg552" else if(strnmatch(cp, "killed ", 7)) { cp+=7; args->target=parse_player(cp, &len); if(strmatch(args->player->team, args->target->team)) { args->action="team_kill"; args->evtype=EV_TEAM_KILL; } else { args->action="kill"; } cp+=len; } // ... committed suicide ... // ie: "Joe<15><785><CT>" committed suicide with "worldspawn" else if(strnmatch(cp, "committed suicide", 17)) { cp+=17; args->action="suicide"; cp+=strspn(cp, " "); args->evtype=EV_PLAYER_SUICIDE; } // ... joined team "someteam" ... // ie: "Joe<15><785><>" joined team "CT" else if(strnmatch(cp, "joined team ", 12)) { cp+=12; args->action="join_team"; args->target=(event_player_t *) malloc(sizeof(event_player_t)); // Note: // old team is in: args->player->team // new team is in: args->target->team if(args->target) { memset(args->target, 0, sizeof(event_player_t)); args->target->team=parse_quoted(cp, &len); cp+=len; } args->evtype=EV_PLAYER_JOIN_TEAM; } // ... changed role to "something" ... // from TFC, ie: "Joe<15><785><Red>" changed role to "Pyro" else if(strnmatch(cp, "changed role to ", 16)) { cp+=16; args->action="change_role"; // Note: // new role is in: args->with args->with=parse_quoted(cp, &len); cp+=len; args->evtype=EV_PLAYER_CHANGE_ROLE; } // ... scored ... // ie: Team "CT" scored "7" with "2" players else if(strnmatch(cp, "scored ", 7)) { cp+=7; if(args->player && args->player->team && !args->player->name) { args->action="team_score"; args->evtype=EV_TEAM_SCORE; } else { args->action="score"; } cp+=strspn(cp, " "); } // anything else... // Consider any words up to a quote (") to be the 'action'. else { begin=cp; end=strchr(begin, '"')-1; len=end-begin; if(len > 0) { *end='\0'; args->action=begin; cp=end+1; cp+=strspn(cp, " "); } } // Look for associated phrases... // ... against ... // ie: "Joe<15><785><Red>" triggered "Medic_Heal" against "Bob<27><954><Red>" if(strnmatch(cp, "against ", 8)) { cp+=8; args->target=parse_player(cp, &len); cp+=len; } // ... with ... // ie: "Joe<15><785><CT>" killed "Sam<17><197><TERRORIST>" with "sg552" // or: "Joe<15><785><Blue>" triggered "Sentry_Destroyed" against "Sam<17><197><Red>" with "mirvgrenade" if(strnmatch(cp, "with ", 5)) { cp+=5; args->with=parse_quoted(cp, &len); if(strmatch(args->action, "kill")) { args->action="weapon_kill"; args->evtype=EV_WEAPON_KILL; } cp+=len; } return(args); }
int parse_data_module( DATAModule *module ) { int data_count; bool fatalError = TRUE; // if true, catch leads to exit(-1) try { data_count = module->datas_count; for ( int i = 0; i < module->datas_count; i++ ) { DataContext ctx; data_context = &ctx; const char *tagName = module->datas[i]->tag->image; const int tagId = find_tag( tagName ); if ( DATA_VERBOSE > 4 ) { printf("tagName: %s tagId: %d\n\r", tagName, tagId ); } switch ( tagId ) { case TAG_Prereq: parse_prerequisite( module->datas[i] ); break; case TAG_BrewFormula: create_brew_formula_table( module->datas_count ); parse_brew_formula( module->datas[i] ); break; case TAG_Ban: parse_ban( module->datas[i] ); break; case TAG_Command: create_command_table( module->datas_count ); parse_command( module->datas[i] ); break; case TAG_Unique: parse_unique( module->datas[i] ); break; case TAG_Disable: parse_disabled( module->datas[i] ); break; case TAG_Material: create_material_table( module->datas_count ); parse_material( module->datas[i] ); break; case TAG_Liquid: create_liquid_table( module->datas_count ); parse_liquid( module->datas[i] ); break; case TAG_God: create_god_table( module->datas_count ); parse_god( module->datas[i] ); break; case TAG_Clan: parse_clan( module->datas[i] ); break; case TAG_Faction: create_faction_table( module->datas_count, module ); parse_faction( module->datas[i] ); break; case TAG_Race: create_races_table( module->datas_count ); parse_race( module->datas[i] ); break; case TAG_PCRace: create_pcraces_table( module->datas_count ); parse_pcrace( module->datas[i] ); break; case TAG_Sphere: create_spheres_table( module->datas_count ); parse_sphere( module->datas[i] ); break; case TAG_Group: create_groups_table( module->datas_count ); parse_groups( module->datas[i] ); break; case TAG_Ability: parse_abilities( module->datas[i] ); break; case TAG_Class: create_classes_table( module->datas_count ); parse_classes( module->datas[i] ); break; case TAG_Player: fatalError = FALSE; parse_player( module->datas[i] ); fatalError = TRUE; break; case TAG_Area: parse_area( module->datas[i] ); break; case TAG_Config: if ( parse_config( module->datas[i] ) ) // once we have found the right config: skip others return data_count; break; case TAG_AreaState: parse_area_state( module->datas[i] ); break; case TAG_Time: parse_time( module->datas[i] ); break; case TAG_Hometown: create_hometown_table( module->datas_count ); parse_hometown( module->datas[i] ); break; case TAG_School: create_school_table( module->datas_count ); parse_school( module->datas[i] ); break; case TAG_Super_Race: create_super_race_table( module->datas_count ); parse_super_race( module->datas[i] ); break; default: p_error("Invalid Tag: %s", tagName ); break; } } } catch (ScriptException e) { bug("Error while parsing datas. %s", e.msg ); if ( fatalError ) { bug("FATAL error. Bye!"); exit(-1); } else return -1; } dump_GC_info(); return data_count; }