|
@@ -925,85 +925,80 @@ func (p *Game) Ready(playerID int32) error {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- p.locker.Unlock()
|
|
|
-
|
|
|
if !allReady {
|
|
|
- p.locker.Lock()
|
|
|
- {
|
|
|
-
|
|
|
- p.EventInfo(playerID, "准备", fmt.Sprintf("等待房间准备:%d", roomItem.ID))
|
|
|
- }
|
|
|
+ p.EventInfo(playerID, "准备", fmt.Sprintf("等待房间准备:%d", roomItem.ID))
|
|
|
p.locker.Unlock()
|
|
|
|
|
|
p.WaitReady(roomItem)
|
|
|
-
|
|
|
- p.locker.Lock()
|
|
|
- {
|
|
|
- p.EventInfo(playerID, "准备", "等待房间完毕")
|
|
|
- }
|
|
|
+ } else {
|
|
|
p.locker.Unlock()
|
|
|
}
|
|
|
|
|
|
func() {
|
|
|
+ //TODO: 优化并发
|
|
|
p.locker.Lock()
|
|
|
defer p.locker.Unlock()
|
|
|
|
|
|
- userIDList, err = p.getRoomUserIDList(roomItem.ID)
|
|
|
+ p.EventInfo(playerID, "准备", "等待房间完毕")
|
|
|
+
|
|
|
+ //切换为准备完毕,限制进入了
|
|
|
+ roomItem.Status = RoomStatusChooseMaster
|
|
|
+ roomItem.StatusStartTime = time.Now().Unix()
|
|
|
+ p.RoomMap[roomItem.ID] = roomItem
|
|
|
+
|
|
|
+ //已经准备好的用户,生成牌
|
|
|
+ userIDList, err = p.getRoomUserIDListWithStatus(roomItem.ID, PlayerStatusReady)
|
|
|
if err != nil {
|
|
|
logrus.Error(err)
|
|
|
return
|
|
|
}
|
|
|
- }()
|
|
|
|
|
|
- err = db.GetDB().Transaction(func(tx *gorm.DB) error {
|
|
|
- for _, userID := range userIDList {
|
|
|
- openNumCardList := getOpenNumList(issue, roomItem.ID, chairID)
|
|
|
- openNumCardStrList := make([]string, 0)
|
|
|
- for _, item := range openNumCardList {
|
|
|
- openNumCardStrList = append(openNumCardStrList, fmt.Sprintf("%d", item.Num))
|
|
|
+ err = db.GetDB().Transaction(func(tx *gorm.DB) error {
|
|
|
+ for _, userID := range userIDList {
|
|
|
+ openNumCardList := getOpenNumList(issue, roomItem.ID, chairID)
|
|
|
+ openNumCardStrList := make([]string, 0)
|
|
|
+ for _, item := range openNumCardList {
|
|
|
+ openNumCardStrList = append(openNumCardStrList, fmt.Sprintf("%d", item.Num))
|
|
|
+ }
|
|
|
+
|
|
|
+ userItem := p.PlayerMap[userID]
|
|
|
+ userItem.CardList = CardList2NNCardList(openNumCardList)
|
|
|
+
|
|
|
+ p.PlayerMap[userID] = userItem
|
|
|
+
|
|
|
+ gameOrderModel := model.GameOrder{
|
|
|
+ UserID: uint(userID),
|
|
|
+ RoomID: uint(roomItem.ID),
|
|
|
+ Issue: issue,
|
|
|
+ OpenNumber: strings.Join(openNumCardStrList, ","),
|
|
|
+ BaseAmount: roomItem.BaseAmount,
|
|
|
+ IsDraw: 0,
|
|
|
+ DrawTime: nil,
|
|
|
+ IsMaster: 0,
|
|
|
+ MasterMul: 0,
|
|
|
+ Mul: 1,
|
|
|
+ IsWin: 0,
|
|
|
+ WinAmount: decimal.NewFromInt(0),
|
|
|
+ BetIP: "",
|
|
|
+ GameID: 1,
|
|
|
+ }
|
|
|
+
|
|
|
+ err = tx.Model(gameOrderModel).Create(&gameOrderModel).Error
|
|
|
+ if err != nil {
|
|
|
+ logrus.Error(err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- userItem := p.PlayerMap[userID]
|
|
|
- userItem.CardList = CardList2NNCardList(openNumCardList)
|
|
|
-
|
|
|
- p.PlayerMap[userID] = userItem
|
|
|
-
|
|
|
- gameOrderModel := model.GameOrder{
|
|
|
- UserID: uint(userID),
|
|
|
- RoomID: uint(roomItem.ID),
|
|
|
- Issue: issue,
|
|
|
- OpenNumber: strings.Join(openNumCardStrList, ","),
|
|
|
- BaseAmount: roomItem.BaseAmount,
|
|
|
- IsDraw: 0,
|
|
|
- DrawTime: nil,
|
|
|
- IsMaster: 0,
|
|
|
- MasterMul: 0,
|
|
|
- Mul: 1,
|
|
|
- IsWin: 0,
|
|
|
- WinAmount: decimal.NewFromInt(0),
|
|
|
- BetIP: "",
|
|
|
- GameID: 1,
|
|
|
- }
|
|
|
-
|
|
|
- err = tx.Model(gameOrderModel).Create(&gameOrderModel).Error
|
|
|
- if err != nil {
|
|
|
- logrus.Error(err)
|
|
|
- return err
|
|
|
- }
|
|
|
- }
|
|
|
- return nil
|
|
|
- })
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- p.locker.Lock()
|
|
|
- {
|
|
|
p.EventInfo(playerID, "准备", "生成订单成功")
|
|
|
- }
|
|
|
- p.locker.Unlock()
|
|
|
+ return nil
|
|
|
+ })
|
|
|
|
|
|
- logrus.Error(err)
|
|
|
- return
|
|
|
- }
|
|
|
+ if err != nil {
|
|
|
+ logrus.Error(err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }()
|
|
|
|
|
|
p.Run(allReady, roomItem, issue)
|
|
|
}()
|