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.

49 lines
947 B
Go

package manager
var GameManager *gameManager
type (
gameManager struct {
RoomManager *RoomManager // 房间管理器
DataManager *DataManager // 数据管理器(Session)
}
)
func init() {
GameManager = newGameManager()
}
func newGameManager() *gameManager {
return &gameManager{
RoomManager: NewRoomManager(),
}
}
func (m *gameManager) BattleIdByLiveRoomId(liveRoomId int64) int64 {
sess, err := m.RoomManager.SessionByLiveRoomId(liveRoomId)
if err != nil {
return 0
}
data, err := m.DataManager.SessionData(sess)
if err != nil {
return 0
}
return data.BattleId()
}
func (m *gameManager) LiveRoomIdByBattleId(battleId int64) int64 {
for _, session := range m.RoomManager.Sessions() {
data, err := m.DataManager.SessionData(session)
if err != nil {
continue
}
if data.BattleId() == battleId {
if !session.HasKey(LiveRoomIdKey) {
continue
}
return session.Int64(LiveRoomIdKey)
}
}
return 0
}