You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
770 B
Go

package game
import (
"dcg/config"
pbRoom "dcg/game/pb/room"
"errors"
)
// LivePair 直播间ID 与 游戏类型 映射关系
var (
LivePair map[int64]pbRoom.GameType
defaultGameType = pbRoom.GameType_ZHG
)
func init() {
LivePair = make(map[int64]pbRoom.GameType)
}
func CacheGameType(roomId int64, gameType pbRoom.GameType) {
LivePair[roomId] = gameType
}
//goland:noinspection GoNameStartsWithPackageName
func GameTypeByLiveRoomId(roomId int64) (pbRoom.GameType, error) {
if gameType, ok := LivePair[roomId]; ok {
return gameType, nil
} else {
modeCfg := config.Config.Game.ModeDict
if gtInt, ok := modeCfg[roomId]; ok {
return pbRoom.GameType(gtInt), nil
}
}
return defaultGameType, errors.New("该直播间未加入游戏房间")
}