9 /* xs_parselog parses a standard XonStat log and breaks it down into
10 individual requests which are then saved into files. The file format
11 is <game type>_<match_id>.txt, so one can easily identify which type
12 of request the file contains and which one it is (the match_id is the
13 'I' line in the actual request).
15 There is also the ability to extract a specific match as well as to
16 anonymize the hashkeys in the requests to prevent exposing player data
19 var fn = flag.String("file", "xonstat.log", "XonStat log file name")
20 var target_match_id = flag.String("match", "", "the specific match_id (I line) to extract from the log")
21 var anonymize = flag.Bool("anonymize", false, "whether or not to anonymize player hashkeys")
24 f, err := os.Open(*fn)
26 fmt.Println("Issue opening file")
31 r := bufio.NewReader(f)
35 var game_type_cd string
36 lines := make([]string, 0, 100)
37 hashkeys := make(map[string]int, 500)
40 line, err := r.ReadString('\n')
43 case strings.Contains(line, "BEGIN REQUEST BODY"):
45 case strings.Contains(line, "END REQUEST BODY"):
46 if *target_match_id == "" || match_id == *target_match_id {
47 // a simple heuristic to filter *most* empty games
49 create_match_file(game_type_cd, match_id, lines)
53 lines = make([]string, 0, 100)
55 if *anonymize && line[0] == 'P' {
56 if line[2:5] != "bot" && line[2:8] != "player" {
57 hashkey := line[2 : len(line)-1]
58 if _, ok := hashkeys[hashkey]; !ok {
59 hashkeys[hashkey] = max_player_id
60 max_player_id = max_player_id + 1
62 line = fmt.Sprintf("P %d\n", hashkeys[hashkey])
66 match_id = line[2 : len(line)-1]
69 game_type_cd = line[2 : len(line)-1]
71 lines = append(lines, line)
74 line, err = r.ReadString('\n')
78 func create_match_file(game_type_cd string, match_id string, body []string) {
79 fn := fmt.Sprintf("%s_%s.txt", game_type_cd, match_id)
80 f_raw, err := os.Create(fn)
82 fmt.Printf("Error creating match_id %s.\n", match_id)
86 f := bufio.NewWriter(f_raw)
87 for _, v := range body {