diff options
| author | Nidboj132 <lol2s@vp.plm> | 2023-07-12 17:58:23 +0200 |
|---|---|---|
| committer | Nidboj132 <lol2s@vp.plm> | 2023-07-12 17:58:23 +0200 |
| commit | 781289455037431d8adbaa0b293b755c88169747 (patch) | |
| tree | 773824f97c3b21d353b9066afdbde30bee2da4c5 /backend/parser/parser.go | |
| parent | summary (diff) | |
| parent | fix: 0 score count / showcase not required (#47) (diff) | |
| download | lphub-781289455037431d8adbaa0b293b755c88169747.tar.gz lphub-781289455037431d8adbaa0b293b755c88169747.tar.bz2 lphub-781289455037431d8adbaa0b293b755c88169747.zip | |
Merge branch 'main' of https://github.com/pektezol/LeastPortals
Former-commit-id: af8d8680aafc3d662f8b53a4f50f0ea356b26c26
Diffstat (limited to 'backend/parser/parser.go')
| -rw-r--r-- | backend/parser/parser.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/backend/parser/parser.go b/backend/parser/parser.go new file mode 100644 index 0000000..562b8c0 --- /dev/null +++ b/backend/parser/parser.go | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | package parser | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "bufio" | ||
| 5 | "fmt" | ||
| 6 | "log" | ||
| 7 | "os/exec" | ||
| 8 | "strconv" | ||
| 9 | "strings" | ||
| 10 | ) | ||
| 11 | |||
| 12 | func ProcessDemo(demoPath string) (int, int, error) { | ||
| 13 | cmd := exec.Command("bash", "-c", fmt.Sprintf(`echo "FEXBash" && ./backend/parser/parser %s`, demoPath)) | ||
| 14 | stdout, err := cmd.StdoutPipe() | ||
| 15 | if err != nil { | ||
| 16 | log.Println(err) | ||
| 17 | return 0, 0, err | ||
| 18 | } | ||
| 19 | cmd.Start() | ||
| 20 | scanner := bufio.NewScanner(stdout) | ||
| 21 | var cmTicks, portalCount int | ||
| 22 | for scanner.Scan() { | ||
| 23 | line := scanner.Text() | ||
| 24 | if strings.Contains(line, "CM ticks") { | ||
| 25 | cmTicksStr := strings.TrimSpace(strings.Split(line, ":")[1]) | ||
| 26 | cmTicks, err = strconv.Atoi(cmTicksStr) | ||
| 27 | if err != nil { | ||
| 28 | return 0, 0, err | ||
| 29 | } | ||
| 30 | } | ||
| 31 | if strings.Contains(line, "Portal count") { | ||
| 32 | portalCountStr := strings.TrimSpace(strings.Split(line, ":")[1]) | ||
| 33 | portalCount, err = strconv.Atoi(portalCountStr) | ||
| 34 | if err != nil { | ||
| 35 | return 0, 0, err | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | ||
| 39 | cmd.Wait() | ||
| 40 | // We don't check for error in wait, since FEXBash always gives segmentation fault | ||
| 41 | // Wanted output is retrieved, so it's okay (i think) | ||
| 42 | return portalCount, cmTicks, nil | ||
| 43 | } | ||