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.

50 lines
1.3 KiB
Go

package manager
import (
"fmt"
"git.noahlan.cn/northlan/ngs"
"git.noahlan.cn/northlan/ntools-go/logger"
)
type (
// Room 游戏房间
// 游戏类型:游戏房间 = 1:n -> 适用于同一个游戏多局游戏同时直播的情况
// 游戏房间:客户端 = 1:n -> 适用于同一个游戏多个客户端实例(状态同步、帧同步?)
// 客户端:直播间 = 1:n -> 适用于同一个游戏客户端,覆盖多个游戏直播间的情况(如果允许)
Room struct {
*RoomMeta
*RoomData
*ngs.Group // 分组
}
)
func newRoom(id int64, gameType string, isDefault bool) *Room {
return &Room{
RoomMeta: &RoomMeta{
ID: id,
GameType: gameType,
IsDefault: isDefault,
},
RoomData: newRoomData(),
Group: ngs.NewGroup(fmt.Sprintf("Room-%s-%d", gameType, id)),
}
}
// 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, 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, r.GameType, err)
}
}