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.

53 lines
1.3 KiB
Go

package manager
import (
pbRoom "dcg/game/pb/room"
"fmt"
"git.noahlan.cn/northlan/ngs"
"git.noahlan.cn/northlan/ntools-go/logger"
)
type (
// Room 游戏房间
// 一种游戏类型一个房间
// 一个房间多个客户端(此客户端可能来自于同一个直播间,没办法区分)
Room struct {
id int64 // 房间ID
gameType pbRoom.GameType // 游戏类型
*ngs.Group // 分组
}
)
func newRoom(id int64, gameType pbRoom.GameType) *Room {
return &Room{
id: id,
gameType: gameType,
Group: ngs.NewGroup(fmt.Sprintf("Room-%s", pbRoom.GameType_name[int32(gameType)])),
}
}
func (r *Room) ID() int64 {
return r.id
}
func (r *Room) GameType() pbRoom.GameType {
return r.gameType
}
// Broadcast 广播消息到该房间内所有客户端session
func (r *Room) Broadcast(route string, v interface{}) {
err := r.Group.Broadcast(route, v)
if err != nil {
logger.SLog.Errorf("推送消息到 房间[%d:%s] 失败, err:%v", r.id, pbRoom.GameType_name[int32(r.gameType)], err)
}
}
// Multicast 根据filter条件推送消息
func (r *Room) Multicast(route string, v interface{}, filter ngs.SessionFilter) {
err := r.Group.Multicast(route, v, filter)
if err != nil {
logger.SLog.Errorf("推送消息到 房间[%d:%s] 失败, err:%v", r.id, pbRoom.GameType_name[int32(r.gameType)], err)
}
}