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 create_match_file(game_type_cd, match_id, lines)
50 lines = make([]string, 0, 100)
52 if *anonymize && line[0] == 'P' {
53 if line[2:5] != "bot" && line[2:8] != "player" {
54 hashkey := line[2:len(line)-1]
55 if _, ok := hashkeys[hashkey]; !ok {
56 hashkeys[hashkey] = max_player_id
57 max_player_id = max_player_id + 1
59 line = fmt.Sprintf("P %d\n", hashkeys[hashkey])
63 match_id = line[2:len(line)-1]
66 game_type_cd = line[2:len(line)-1]
68 lines = append(lines, line)
71 line, err = r.ReadString('\n')
76 func create_match_file(game_type_cd string, match_id string, body []string) {
77 fn := fmt.Sprintf("%s_%s.txt", game_type_cd, match_id)
78 f_raw, err := os.Create(fn)
80 fmt.Printf("Error creating match_id %s.\n", match_id)
84 f := bufio.NewWriter(f_raw)
85 for _, v := range body {