diff --git a/service/player.go b/service/player.go index 332d08e..a99f6ab 100644 --- a/service/player.go +++ b/service/player.go @@ -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 {