From f4205e72ac514b8bb78318bf6a6338d7e937eef7 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Mon, 29 Apr 2024 18:12:04 +0800 Subject: [PATCH] no message --- gamesrv/action/action_game.go | 109 +++++++++++------------- gamesrv/base/config.go | 29 ------- gamesrv/base/constant.go | 13 --- gamesrv/base/data.go | 13 --- gamesrv/base/elementproducer.go | 145 -------------------------------- 5 files changed, 49 insertions(+), 260 deletions(-) delete mode 100644 gamesrv/base/config.go delete mode 100644 gamesrv/base/constant.go delete mode 100644 gamesrv/base/data.go delete mode 100644 gamesrv/base/elementproducer.go diff --git a/gamesrv/action/action_game.go b/gamesrv/action/action_game.go index 76c9900..1c99fec 100644 --- a/gamesrv/action/action_game.go +++ b/gamesrv/action/action_game.go @@ -178,63 +178,52 @@ func (this *CSForceStartHandler) Process(s *netlib.Session, packetid int, data i return nil } -//type CSPlayerSwitchFlagPacketFactory struct { -//} -//type CSPlayerSwitchFlagHandler struct { -//} -// -//func (this *CSPlayerSwitchFlagPacketFactory) CreatePacket() interface{} { -// pack := &gamehall.CSPlayerSwithFlag{} -// return pack -//} -// -//func (this *CSPlayerSwitchFlagHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { -// logger.Logger.Trace("CSPlayerSwitchFlagHandler Process recv ", data) -// if msg, ok := data.(*gamehall.CSPlayerSwithFlag); ok { -// p := base.PlayerMgrSington.GetPlayer(sid) -// if p == nil { -// logger.Logger.Warn("CSPlayerSwitchFlagHandler p == nil") -// return nil -// } -// flag := int(msg.GetFlag()) -// //flag = 1 << uint(flag) -// //if msg.Mark != nil { -// logger.Logger.Trace("CSPlayerSwitchFlagHandler Process recv SnId(%v) Mark is %v", p.SnId, msg.GetMark()) -// if msg.GetMark() == 0 { //0取消状态 1设置状态 -// oldFlag := p.GetFlag() -// if p.IsMarkFlag(flag) { -// p.UnmarkFlag(flag) -// } -// if flag == base.PlayerState_Leave { -// if p.GetScene() != nil { -// //重置下房间状态 -// p.GetScene().PlayerReturn(p, true) -// } -// } -// if oldFlag != p.GetFlag() { -// p.SyncFlag() -// } -// } else { //设置状态 -// if flag == base.PlayerState_Leave { -// p.ActiveLeave = false //被动暂离 -// if p.GetScene() != nil { -// //todo dev fish 字游戏暂时被删除了 所以这里先注释掉 -// //if p.GetScene().gameId == common.GameId_HFishing || p.GetScene().gameId == common.GameId_LFishing || -// // p.GetScene().gameId == common.GameId_RFishing || p.GetScene().gameId == common.GameId_DFishing || -// // p.GetScene().gameId == common.GameId_NFishing || p.GetScene().gameId == common.GameId_TFishing { -// // p.GetScene().sp.OnPlayerOp(p.GetScene(), p, FishingPlayerOpLeave, []int64{}) -// //} -// } -// } -// if !p.IsMarkFlag(flag) { -// p.MarkFlag(flag) -// p.SyncFlag() -// } -// } -// //} -// } -// return nil -//} +type CSPlayerSwitchFlagPacketFactory struct { +} +type CSPlayerSwitchFlagHandler struct { +} + +func (this *CSPlayerSwitchFlagPacketFactory) CreatePacket() interface{} { + pack := &gamehall.CSPlayerSwithFlag{} + return pack +} + +func (this *CSPlayerSwitchFlagHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { + logger.Logger.Trace("CSPlayerSwitchFlagHandler Process recv ", data) + if msg, ok := data.(*gamehall.CSPlayerSwithFlag); ok { + p := base.PlayerMgrSington.GetPlayer(sid) + if p == nil { + logger.Logger.Warn("CSPlayerSwitchFlagHandler p == nil") + return nil + } + flag := int(msg.GetFlag()) + logger.Logger.Trace("CSPlayerSwitchFlagHandler Process recv SnId(%v) Mark is %v", p.SnId, msg.GetMark()) + if msg.GetMark() == 0 { //0取消状态 1设置状态 + oldFlag := p.GetFlag() + if p.IsMarkFlag(flag) { + p.UnmarkFlag(flag) + } + if flag == base.PlayerState_Leave { + if p.GetScene() != nil { + //重置下房间状态 + p.GetScene().PlayerReturn(p, true) + } + } + if oldFlag != p.GetFlag() { + p.SyncFlag() + } + } else { //设置状态 + if flag == base.PlayerState_Leave { + p.ActiveLeave = false //被动暂离 + } + if !p.IsMarkFlag(flag) { + p.MarkFlag(flag) + p.SyncFlag() + } + } + } + return nil +} func CSRoomEvent(s *netlib.Session, packetid int, data interface{}, sid int64) error { logger.Logger.Tracef("CSRoomEvent %v", data) @@ -315,9 +304,9 @@ func init() { common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_FORCESTART), &CSForceStartHandler{}) netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_FORCESTART), &CSForceStartPacketFactory{}) - // 同步玩家状态 - //common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_PLAYER_SWITCHFLAG), &CSPlayerSwitchFlagHandler{}) - //netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_PLAYER_SWITCHFLAG), &CSPlayerSwitchFlagPacketFactory{}) + // 同步玩家状态,如暂离状态取消 + common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_PLAYER_SWITCHFLAG), &CSPlayerSwitchFlagHandler{}) + netlib.RegisterFactory(int(gamehall.GameHallPacketID_PACKET_CS_PLAYER_SWITCHFLAG), &CSPlayerSwitchFlagPacketFactory{}) // 房间事件 common.Register(int(gamehall.GameHallPacketID_PACKET_CSRoomEvent), gamehall.CSRoomEvent{}, CSRoomEvent) diff --git a/gamesrv/base/config.go b/gamesrv/base/config.go deleted file mode 100644 index b402665..0000000 --- a/gamesrv/base/config.go +++ /dev/null @@ -1,29 +0,0 @@ -package base - -import ( - "mongo.games.com/goserver/core" -) - -var ( - ForwardConfig = ForwardConfiguration{} -) - -type ForwardConfiguration struct { - ForwardMakeCards bool -} - -func (this *ForwardConfiguration) Name() string { - return "forward" -} - -func (this *ForwardConfiguration) Init() error { - return nil -} - -func (this *ForwardConfiguration) Close() error { - return nil -} - -func init() { - core.RegistePackage(&ForwardConfig) -} diff --git a/gamesrv/base/constant.go b/gamesrv/base/constant.go deleted file mode 100644 index 7617082..0000000 --- a/gamesrv/base/constant.go +++ /dev/null @@ -1,13 +0,0 @@ -package base - -import ( - "mongo.games.com/game/common" -) - -var BroadJackpotGame = []int{ - common.GameId_IceAge, - common.GameId_TamQuoc, - common.GameId_CaiShen, - common.GameId_Avengers, - common.GameId_EasterIsland, -} diff --git a/gamesrv/base/data.go b/gamesrv/base/data.go deleted file mode 100644 index d4b8c8b..0000000 --- a/gamesrv/base/data.go +++ /dev/null @@ -1,13 +0,0 @@ -package base - -type InterventionData struct { - Webuser string - Flag int32 - NumOfGames int32 -} - -type InterventionResults struct { - Key string - Webuser string - Results string -} diff --git a/gamesrv/base/elementproducer.go b/gamesrv/base/elementproducer.go deleted file mode 100644 index eea2f8f..0000000 --- a/gamesrv/base/elementproducer.go +++ /dev/null @@ -1,145 +0,0 @@ -package base - -import ( - "mongo.games.com/goserver/core/logger" - "mongo.games.com/goserver/core/utils" - "sync/atomic" - "time" -) - -type ElementPool struct { - key int32 - pool chan interface{} -} - -type ElementProducer struct { - times int64 - cnt int32 - max int32 - pool []*ElementPool - nf ProduceFunc //正常的生产函数 - bf ProduceFunc //保底的生产函数 - quit bool -} - -type ProduceFunc func() (interface{}, int32) - -type ElementProducerMgr struct { - producer map[int32]*ElementProducer -} - -var ElementProducerMgrSington = &ElementProducerMgr{ - producer: make(map[int32]*ElementProducer), -} - -func CreateElementProducer(max int32, nf, bf ProduceFunc) *ElementProducer { - ep := &ElementProducer{ - max: max, - nf: nf, - bf: bf, - pool: make([]*ElementPool, max, max), - } - return ep -} - -func (ep *ElementProducer) Start() { - go _start_produce_routine(ep) -} - -func (ep *ElementProducer) Stop() { - ep.quit = true -} - -func (ep *ElementProducer) FetchOneElement(key int32) interface{} { - if key < 0 || key >= int32(len(ep.pool)) { - return nil - } - pool := ep.pool[key] - if pool != nil { - select { - case d, ok := <-pool.pool: - if ok { - atomic.AddInt32(&ep.cnt, -1) - return d - } else { - //向下取一个结果 - for i := key - 1; i >= 0; i-- { - if ep.pool[i] != nil && len(ep.pool[i].pool) != 0 { - return ep.FetchOneElement(i) - } - } - d, _ := ep.bf() - return d - } - default: - } - } - //向下取一个结果 - for i := key - 1; i >= 0; i-- { - if ep.pool[i] != nil && len(ep.pool[i].pool) != 0 { - return ep.FetchOneElement(i) - } - } - d, _ := ep.bf() - return d -} - -func (ep *ElementProducer) Dump() { - logger.Logger.Tracef("[[[[[[[[[[[[[[[total=%v, calcu=%v]]]]]]]]]]]]]]]", ep.cnt, ep.times) - for i := 0; i < len(ep.pool); i++ { - epp := ep.pool[i] - if epp != nil && len(epp.pool) != 0 { - logger.Logger.Tracef("[key=%v] [count=%v]", i, len(epp.pool)) - } - } -} - -func _start_produce_routine(ep *ElementProducer) { - defer utils.DumpStackIfPanic("_start_produce_routine") - var idle = 0 - for !ep.quit { - val, key := ep.nf() - atomic.AddInt64(&ep.times, 1) - if key >= 0 && key < int32(len(ep.pool)) { - epp := ep.pool[key] - if epp == nil { - epp = &ElementPool{key: key, pool: make(chan interface{}, 128)} - ep.pool[key] = epp - } - select { - case epp.pool <- val: - atomic.AddInt32(&ep.cnt, 1) - case <-time.After(time.Millisecond): - idle++ - } - } - if idle >= 10000 { - idle = 0 - //ep.Dump() - } - } -} - -func (this *ElementProducerMgr) GetProducer(id int32) *ElementProducer { - if p, exist := this.producer[id]; exist { - return p - } - return nil -} - -func (this *ElementProducerMgr) SetProducer(id int32, p *ElementProducer) { - if op, exist := this.producer[id]; exist { - if op != nil { - op.Stop() - } - } - this.producer[id] = p -} - -func (this *ElementProducerMgr) StopAll() { - for _, p := range this.producer { - if p != nil { - p.Stop() - } - } -}