From bc483c819fb624c17031d5610b564a800831801e Mon Sep 17 00:00:00 2001 From: 王家文 Date: Sun, 28 Apr 2024 19:13:02 +0800 Subject: [PATCH] fix🐛:id算法优化 --- go.mod | 1 + go.sum | 2 ++ service/roomrank/player.go | 5 +++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 1374aca..c24ea7b 100644 --- a/go.mod +++ b/go.mod @@ -26,6 +26,7 @@ require ( github.com/go-logfmt/logfmt v0.5.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.4.2 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect diff --git a/go.sum b/go.sum index 71a17db..9c764b9 100644 --- a/go.sum +++ b/go.sum @@ -177,6 +177,8 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= diff --git a/service/roomrank/player.go b/service/roomrank/player.go index 877503a..6c2ebb1 100644 --- a/service/roomrank/player.go +++ b/service/roomrank/player.go @@ -8,7 +8,7 @@ import ( "apigame/util/util-lx/lxalilog" "apigame/util/util-lx/lxtime" "apigame/util/utstring" - "math/rand" + "github.com/google/uuid" ) func tryInitPlayer(gameId string, player *Player) { @@ -48,7 +48,8 @@ func LoadPlayer(gameId string, playerUid int64, topType int) (player *Player) { // NewRoomRobot 新建房间机器人 func NewRoomRobot(gameId string, robotConfigId int, userType int) *RoomPlayer { d := &RoomPlayer{ - Uid: rand.Int63(), + //Uid: rand.Int63(), + Uid: int64(uuid.New().ID()), Name: svcommon.GetName(gameId), Icon: svcommon.GetAvatar(gameId), Score: 0, -- libgit2 0.21.0