Skip to content

Commit

Permalink
fix(#92): rcon uid may not equal to player uid but may contain
Browse files Browse the repository at this point in the history
  • Loading branch information
zaigie committed Feb 4, 2024
1 parent 146aef0 commit 80182b2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions service/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,35 @@ func PutPlayers(db *bbolt.DB, players []database.Player) error {
})
}

func isUidMatch(uid1, uid2 string) bool {
return strings.Contains(uid1, uid2) || strings.Contains(uid2, uid1)
}

func PutPlayersRcon(db *bbolt.DB, players []database.PlayerRcon) error {
return db.Update(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte("players"))
for _, p := range players {

// rcon uid may not equal to player uid but may contain
var matchedPlayerUid string
err := db.View(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte("players"))
return b.ForEach(func(k, v []byte) error {
if isUidMatch(string(k), p.PlayerUid) {
matchedPlayerUid = string(k)
return nil
}
return nil
})
})
if err != nil {
return err
}

if matchedPlayerUid != "" {
p.PlayerUid = matchedPlayerUid
}

existingPlayerData := b.Get([]byte(p.PlayerUid))
var player database.Player
if existingPlayerData == nil {
Expand Down

0 comments on commit 80182b2

Please sign in to comment.