game_sync/worldsrv/action_hundredscene.go

209 lines
6.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/netlib"
"mongo.games.com/game/common"
"mongo.games.com/game/proto"
"mongo.games.com/game/protocol/gamehall"
"mongo.games.com/game/srvdata"
)
type CSHundredSceneGetPlayerNumPacketFactory struct {
}
type CSHundredSceneGetPlayerNumHandler struct {
}
func (this *CSHundredSceneGetPlayerNumPacketFactory) CreatePacket() interface{} {
pack := &gamehall.CSHundredSceneGetPlayerNum{}
return pack
}
func (this *CSHundredSceneGetPlayerNumHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSHundredSceneGetPlayerNumHandler Process recv ", data)
if msg, ok := data.(*gamehall.CSHundredSceneGetPlayerNum); ok {
p := PlayerMgrSington.GetOnlinePlayer(sid)
if p != nil {
nums := HundredSceneMgrSingleton.GetPlayerNums(p, msg.GetGameId(), msg.GetGameModel())
pack := &gamehall.SCHundredSceneGetPlayerNum{
Nums: nums,
}
proto.SetDefaults(pack)
p.SendToClient(int(gamehall.HundredScenePacketID_PACKET_SC_HUNDREDSCENE_GETPLAYERNUM), pack)
logger.Logger.Trace("SCHundredSceneGetPlayerNum:", pack)
}
}
return nil
}
type CSHundredSceneOpPacketFactory struct {
}
type CSHundredSceneOpHandler struct {
}
func (this *CSHundredSceneOpPacketFactory) CreatePacket() interface{} {
pack := &gamehall.CSHundredSceneOp{}
return pack
}
func (this *CSHundredSceneOpHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSHundredSceneOpHandler Process recv ", data)
if msg, ok := data.(*gamehall.CSHundredSceneOp); ok {
p := PlayerMgrSington.GetOnlinePlayer(sid)
if p != nil {
var ret gamehall.OpResultCode_Hundred
pack := &gamehall.SCHundredSceneOp{
Id: msg.Id,
OpType: msg.OpType,
}
oldPlatform := p.Platform
switch msg.GetOpType() {
case HundredSceneOPEnter:
//pt := PlatformMgrSingleton.GetPackageTag(p.PackageID)
//if pt != nil && pt.IsForceBind == 1 {
// if p.BeUnderAgentCode == "" || p.BeUnderAgentCode == "0" {
// ret = gamehall.OpResultCode_Hundred_OPRC_MustBindPromoter_Hundred
// goto done
// }
//}
if p.scene != nil {
logger.Logger.Warnf("CSHundredSceneOpHandler CoinSceneOp_Enter found snid:%v had in scene:%v gameid:%v", p.SnId, p.scene.sceneId, p.scene.gameId)
p.ReturnScene(false)
return nil
}
dbGameFree := srvdata.PBDB_GameFreeMgr.GetData(msg.GetId())
gameId := dbGameFree.GetGameId()
var roomId int32
params := msg.GetOpParams()
if len(params) != 0 {
roomId = params[0]
platform := SceneMgrSingleton.GetPlatformBySceneId(int(roomId))
if p.IsRob {
//机器人先伪装成对应平台的用户
if platform != "" {
p.Platform = platform
}
} else if p.GMLevel > 0 && p.Platform == platform { //允许GM直接按房间ID进场
roomId = params[0]
}
}
//检测房间状态是否开启
gps := PlatformMgrSingleton.GetGameFree(p.Platform, msg.GetId())
if gps == nil {
ret = gamehall.OpResultCode_Hundred_OPRC_RoomHadClosed_Hundred
goto done
}
dbGameFree = gps.DbGameFree
if len(params) != 0 && p.GMLevel > 0 { //允许GM直接按房间ID进场
s := SceneMgrSingleton.GetScene(int(params[0]))
if s != nil {
if s.platform.IdStr == p.Platform || (gps.GroupId != 0 && s.groupId == gps.GroupId) {
roomId = params[0]
}
}
}
if dbGameFree == nil {
ret = gamehall.OpResultCode_Hundred_OPRC_RoomHadClosed_Hundred
goto done
}
if dbGameFree.GetLimitCoin() != 0 && int64(dbGameFree.GetLimitCoin()) > p.Coin {
ret = gamehall.OpResultCode_Hundred_OPRC_CoinNotEnough_Hundred
goto done
}
if dbGameFree.GetMaxCoinLimit() != 0 && int64(dbGameFree.GetMaxCoinLimit()) < p.Coin && !p.IsRob {
ret = gamehall.OpResultCode_Hundred_OPRC_CoinTooMore_Hundred
goto done
}
//检查游戏次数限制
if !p.IsRob {
//todayData, _ := p.GetDaliyGameData(int(dbGameFree.GetId()))
//if dbGameFree.GetPlayNumLimit() != 0 &&
// todayData != nil &&
// todayData.GameTimes >= int64(dbGameFree.GetPlayNumLimit()) {
// ret = gamehall.OpResultCode_Hundred_OPRC_RoomGameTimes_Hundred
// goto done
//}
}
gameVers := srvdata.GetGameVers(p.PackageID)
if gameVers != nil {
if ver, ok := gameVers[fmt.Sprintf("%v,%v", gameId, p.Channel)]; ok {
pack.MinApkVer = proto.Int32(ver.MinApkVer)
pack.MinResVer = proto.Int32(ver.MinResVer)
pack.LatestApkVer = proto.Int32(ver.LatestApkVer)
pack.LatestResVer = proto.Int32(ver.LatestResVer)
if msg.GetApkVer() < ver.MinApkVer {
ret = gamehall.OpResultCode_Hundred_OPRC_YourAppVerIsLow_Hundred
goto done
}
if msg.GetResVer() < ver.MinResVer {
ret = gamehall.OpResultCode_Hundred_OPRC_YourResVerIsLow_Hundred
goto done
}
}
}
ret = HundredSceneMgrSingleton.PlayerEnter(p, msg.GetId())
if p.scene != nil {
pack.OpParams = append(pack.OpParams, msg.GetId())
//TODO 有房间还进入失败尝试returnroom
if ret != gamehall.OpResultCode_Hundred_OPRC_Sucess_Hundred {
p.ReturnScene(false)
return nil
}
}
case HundredSceneOPLeave:
ret = HundredSceneMgrSingleton.PlayerTryLeave(p)
case HundredSceneOPChange:
/*var exclude int32
if p.scene != nil {
exclude = int32(p.scene.sceneId)
}
params := msg.GetOpParams()
if len(params) != 0 {
exclude = params[0]
}
if HundredSceneMgrSingleton.PlayerInChanging(p) { //换桌中
return nil
}
ret = HundredSceneMgrSingleton.PlayerTryChange(p, msg.GetId(), exclude)*/
}
done:
//机器人要避免身上的平台标记被污染
if p.IsRob {
if ret != gamehall.OpResultCode_Hundred_OPRC_Sucess_Hundred {
p.Platform = oldPlatform
}
}
pack.OpCode = ret
proto.SetDefaults(pack)
p.SendToClient(int(gamehall.HundredScenePacketID_PACKET_SC_HUNDREDSCENE_OP), pack)
//}
//if msg.GetOpType() == common.CoinSceneOp_Enter && ret == gamehall.OpResultCode_Hundred_OPRC_Sucess_Hundred && p.scene != nil {
// gameName := p.scene.dbGameFree.GetName() + p.scene.dbGameFree.GetTitle()
// ActMonitorMgrSington.SendActMonitorEvent(ActState_Game, p.SnId, p.Name, p.Platform,
// 0, 0, gameName, 0)
//}
}
}
return nil
}
func init() {
common.RegisterHandler(int(gamehall.HundredScenePacketID_PACKET_CS_HUNDREDSCENE_GETPLAYERNUM), &CSHundredSceneGetPlayerNumHandler{})
netlib.RegisterFactory(int(gamehall.HundredScenePacketID_PACKET_CS_HUNDREDSCENE_GETPLAYERNUM), &CSHundredSceneGetPlayerNumPacketFactory{})
common.RegisterHandler(int(gamehall.HundredScenePacketID_PACKET_CS_HUNDREDSCENE_OP), &CSHundredSceneOpHandler{})
netlib.RegisterFactory(int(gamehall.HundredScenePacketID_PACKET_CS_HUNDREDSCENE_OP), &CSHundredSceneOpPacketFactory{})
}