no message

This commit is contained in:
sk 2024-04-29 18:12:04 +08:00
parent bd92567666
commit f4205e72ac
5 changed files with 49 additions and 260 deletions

View File

@ -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)

View File

@ -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)
}

View File

@ -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,
}

View File

@ -1,13 +0,0 @@
package base
type InterventionData struct {
Webuser string
Flag int32
NumOfGames int32
}
type InterventionResults struct {
Key string
Webuser string
Results string
}

View File

@ -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()
}
}
}