Skip to content

Commit 853a7d1

Browse files
committed
fix: players list not properly calculated
Signed-off-by: Neko Ayaka <neko@ayaka.moe>
1 parent 8314b03 commit 853a7d1

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
| Factorio RCON API | Factorio Server |
1010
|-------------------|-----------------|
11-
| 1.1.0 (`/api/v1`) | 1.x |
12-
| 2.0.0 (`/api/v2`) | 2.x |
11+
| `/api/v1` | 1.x |
12+
| `/api/v2` | 2.x |
1313

1414
## Features
1515

pkg/utils/factorio.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@ func StringListToPlayers(list string) ([]*v1.Player, error) {
2020
for _, line := range split {
2121
line = strings.TrimSpace(line)
2222
parts := strings.Split(line, " ")
23-
if len(parts) != 2 {
23+
if len(parts) > 2 {
2424
return nil, apierrors.NewErrBadRequest().WithDetailf("failed to parse admins: %s due to parts not equals 2", line).AsStatus()
2525
}
2626

27-
players = append(players, &v1.Player{
27+
player := &v1.Player{
2828
Username: parts[0],
29-
Online: parts[1] == "(online)",
30-
})
29+
}
30+
if len(parts) == 2 {
31+
player.Online = parts[1] == "(online)"
32+
}
33+
34+
players = append(players, player)
3135
}
3236

3337
return players, nil

pkg/utils/factorio_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func TestStringListToPlayers(t *testing.T) {
10-
players, err := StringListToPlayers(" NekoMeow (online)\n NekoMeow2 (offline)\n")
10+
players, err := StringListToPlayers(" NekoMeow (online)\n NekoMeow2\n")
1111
require.NoError(t, err)
1212
require.Len(t, players, 2)
1313
}

0 commit comments

Comments
 (0)