竞技馆房间列表变更通知

This commit is contained in:
sk 2024-08-29 16:30:08 +08:00
parent 94ca1562e5
commit 33eab3f5bc
8 changed files with 163 additions and 15 deletions

View File

@ -887,3 +887,18 @@ const (
// GameHistoryModel .
GameHistoryModel
)
type ListOpType int // 列表操作类型
const (
ListModify ListOpType = 1 // 修改
ListAdd ListOpType = 2 // 增加
ListDel ListOpType = 3 // 减少
ListFind ListOpType = 4 // 查询
)
type NotifyType int // 通知类型
const (
NotifyPrivateRoomList NotifyType = 1 // 私人房间列表
)

View File

@ -1410,6 +1410,8 @@ func CSTouchTypeHandler(s *netlib.Session, packetId int, data interface{}, sid i
return nil
}
PlayerNotifySingle.AddTime(p.SnId, common.NotifyPrivateRoomList, time.Second*15)
return nil
}

View File

@ -113,6 +113,7 @@ func (this *CacheDataManager) CacheBillNumber(billNo int, platform string) {
key := fmt.Sprintf("BillNo-%v-%v", billNo, platform)
this.addCacheData(AfterHour, key, key)
}
func (this *CacheDataManager) CacheBillCheck(billNo int, platform string) bool {
key := fmt.Sprintf("BillNo-%v-%v", billNo, platform)
if _, ok := this.HourCache.Load(key); ok {
@ -121,6 +122,7 @@ func (this *CacheDataManager) CacheBillCheck(billNo int, platform string) bool {
return false
}
}
func (this *CacheDataManager) ClearCacheBill(billNo int, platform string) {
key := fmt.Sprintf("BillNo-%v-%v", billNo, platform)
this.HourCache.Delete(key)

View File

@ -400,7 +400,7 @@ func (this *HorseRaceLampMgr) BroadcastHorseRaceLampMsg(horseRaceLamp *HorseRace
if len(horseRaceLamp.Target) == 0 {
PlayerMgrSington.BroadcastMessageToPlatform(horseRaceLamp.Platform, int(message.MSGPacketID_PACKET_SC_NOTICE), rawpack)
} else {
PlayerMgrSington.BroadcastMessageToTarget(horseRaceLamp.Platform, horseRaceLamp.Target, int(message.MSGPacketID_PACKET_SC_NOTICE), rawpack)
PlayerMgrSington.BroadcastMessageToTarget(horseRaceLamp.Target, int(message.MSGPacketID_PACKET_SC_NOTICE), rawpack)
}
}

View File

@ -426,20 +426,19 @@ func (this *PlayerMgr) BroadcastMessageToGroup(packetid int, rawpack interface{}
}
// BroadcastMessageToTarget 给某些玩家发消息
func (this *PlayerMgr) BroadcastMessageToTarget(platform string, target []int32, packetid int, rawpack interface{}) {
players := this.playerOfPlatform[platform]
func (this *PlayerMgr) BroadcastMessageToTarget(target []int32, packetid int, rawpack interface{}) {
mgs := make(map[*netlib.Session][]*srvproto.MCSessionUnion)
for _, p := range players {
if p != nil && p.gateSess != nil && p.IsOnLine() /*&& p.Platform == platform*/ {
if common.InSliceInt32(target, p.SnId) {
mgs[p.gateSess] = append(mgs[p.gateSess], &srvproto.MCSessionUnion{
for _, v := range target {
d := this.snidMap[v]
if d != nil && d.gateSess != nil && d.IsOnLine() {
mgs[d.gateSess] = append(mgs[d.gateSess], &srvproto.MCSessionUnion{
Mccs: &srvproto.MCClientSession{
SId: proto.Int64(p.sid),
SId: proto.Int64(d.sid),
},
})
}
}
}
for gateSess, v := range mgs {
if gateSess != nil && len(v) != 0 {
pack, err := common.CreateMulticastPacket(packetid, rawpack, v...)

79
worldsrv/playernotify.go Normal file
View File

@ -0,0 +1,79 @@
package main
import (
"time"
"mongo.games.com/game/common"
)
func init() {
ClockMgrSington.RegisteSinker(PlayerNotifySingle)
}
var PlayerNotifySingle = &PlayerNotify{
players: make(map[int32]map[int32]*PlayerNotifyInfo),
}
type PlayerNotifyInfo struct {
SnId int32 // 玩家id
Ts int64 // 失效时间戳
}
type PlayerNotify struct {
BaseClockSinker
players map[int32]map[int32]*PlayerNotifyInfo // 消息类型玩家id玩家信息
}
func (p *PlayerNotify) InterestClockEvent() int {
return 1 << CLOCK_EVENT_MINUTE
}
func (p *PlayerNotify) OnMiniTimer() {
now := time.Now()
for _, v := range p.players {
var ids []int32
for k, vv := range v {
if vv == nil || vv.Ts <= now.Unix() {
ids = append(ids, k)
}
}
for _, id := range ids {
delete(v, id)
}
}
}
// AddTime 延长某个类型消息的通知时间
// snid 玩家id
// tp 消息类型
// d 延长时间
func (p *PlayerNotify) AddTime(snid int32, tp common.NotifyType, d time.Duration) {
if _, ok := p.players[int32(tp)]; !ok {
p.players[int32(tp)] = make(map[int32]*PlayerNotifyInfo)
}
p.players[int32(tp)][snid] = &PlayerNotifyInfo{
SnId: snid,
Ts: time.Now().Add(d).Unix(),
}
}
// GetPlayers 获取某个类型消息的玩家id
// tp 消息类型
func (p *PlayerNotify) GetPlayers(tp common.NotifyType) []int32 {
now := time.Now()
var ret []int32
for k, v := range p.players[int32(tp)] {
if v == nil || v.Ts <= now.Unix() {
continue
}
ret = append(ret, k)
}
return ret
}
// SendToClient 发送消息给客户端
// tp 消息类型
func (p *PlayerNotify) SendToClient(tp common.NotifyType, packetId int, pack interface{}) {
ids := p.GetPlayers(tp)
PlayerMgrSington.BroadcastMessageToTarget(ids, packetId, pack)
}

View File

@ -15,6 +15,7 @@ import (
"mongo.games.com/game/gamerule/tienlen"
"mongo.games.com/game/model"
"mongo.games.com/game/proto"
"mongo.games.com/game/protocol/gamehall"
hallproto "mongo.games.com/game/protocol/gamehall"
serverproto "mongo.games.com/game/protocol/server"
"mongo.games.com/game/srvdata"
@ -923,3 +924,47 @@ func (this *Scene) CanAudience() bool {
return true
}
}
func (this *Scene) ProtoPrivateRoom() *gamehall.PrivateRoomInfo {
if !this.IsCustom() {
return nil
}
needPassword := int32(0)
if this.GetPassword() != "" {
needPassword = int32(1)
}
ret := &gamehall.PrivateRoomInfo{
GameFreeId: this.dbGameFree.GetId(),
GameId: int32(this.gameId),
RoomTypeId: this.RoomTypeId,
RoomConfigId: this.RoomConfigId,
RoomId: int32(this.sceneId),
NeedPassword: needPassword,
CurrRound: this.currRound,
MaxRound: this.totalRound,
CurrNum: int32(this.GetPlayerCnt()),
MaxPlayer: int32(this.playerNum),
CreateTs: this.createTime.Unix(),
State: this.SceneState,
}
for _, v := range this.players {
ret.Players = append(ret.Players, &gamehall.PrivatePlayerInfo{
SnId: v.SnId,
Name: v.Name,
UseRoleId: v.GetRoleId(),
})
}
return ret
}
// NotifyPrivateRoom 通知私人房列表变更
func (this *Scene) NotifyPrivateRoom(tp common.ListOpType) {
if this.IsCustom() {
pack := &gamehall.SCGetPrivateRoomList{
Tp: int32(tp),
Datas: []*gamehall.PrivateRoomInfo{this.ProtoPrivateRoom()},
}
PlayerNotifySingle.SendToClient(common.NotifyPrivateRoomList, int(gamehall.GameHallPacketID_PACKET_SC_GETPRIVATEROOMLIST), pack)
logger.Logger.Tracef("NotifyPrivateRoom: %v", pack)
}
}

View File

@ -22,10 +22,13 @@ func (spd *ScenePolicyData) Init() bool {
return true
}
func (spd *ScenePolicyData) OnStart(s *Scene) {}
func (spd *ScenePolicyData) OnStart(s *Scene) {
s.NotifyPrivateRoom(common.ListAdd)
}
// 场景关闭事件
func (spd *ScenePolicyData) OnStop(s *Scene) {
s.NotifyPrivateRoom(common.ListDel)
}
// 场景心跳事件
@ -35,12 +38,12 @@ func (spd *ScenePolicyData) OnTick(s *Scene) {
// 玩家进入事件
func (spd *ScenePolicyData) OnPlayerEnter(s *Scene, p *Player) {
s.NotifyPrivateRoom(common.ListModify)
}
// 玩家离开事件
func (spd *ScenePolicyData) OnPlayerLeave(s *Scene, p *Player) {
s.NotifyPrivateRoom(common.ListModify)
}
// 系统维护关闭事件
@ -52,8 +55,10 @@ func (spd *ScenePolicyData) OnSceneState(s *Scene, state int) {
s.SceneState = int32(state)
switch state {
case common.SceneStateWaite:
s.NotifyPrivateRoom(common.ListModify)
case common.SceneStateStart:
s.NotifyPrivateRoom(common.ListModify)
if s.IsCustom() {
for _, v := range s.players {
spd.CostPayment(s, v)
@ -61,6 +66,7 @@ func (spd *ScenePolicyData) OnSceneState(s *Scene, state int) {
}
case common.SceneStateEnd:
s.NotifyPrivateRoom(common.ListModify)
}
}