game_sync/worldsrv/action_welfare.go

651 lines
19 KiB
Go

package main
import (
"errors"
"fmt"
"time"
"mongo.games.com/goserver/core/basic"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/netlib"
"mongo.games.com/goserver/core/task"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/proto"
webapi_proto "mongo.games.com/game/protocol/webapi"
"mongo.games.com/game/protocol/welfare"
"mongo.games.com/game/srvdata"
"mongo.games.com/game/webapi"
)
// 救济金
type CSGetReliefFundPacketFactory struct {
}
type CSGetReliefFundHandler struct {
}
func (this *CSGetReliefFundPacketFactory) CreatePacket() interface{} {
pack := &welfare.CSGetReliefFund{}
return pack
}
func (this *CSGetReliefFundHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSGetReliefFund Process recv ", data)
if msg, ok := data.(*welfare.CSGetReliefFund); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSGetReliefFundHandler p == nil")
return nil
}
WelfareMgrSington.GetReliefFund(p, msg.GetIsVideo())
}
return nil
}
// 转动转盘
type CSGetTurnplatePacketFactory struct {
}
type CSGetTurnplateHandler struct {
}
func (this *CSGetTurnplatePacketFactory) CreatePacket() interface{} {
pack := &welfare.CSGetTurnplate{}
return pack
}
func (this *CSGetTurnplateHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSGetTurnplate Process recv ", data)
if msg, ok := data.(*welfare.CSGetTurnplate); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSGetTurnplateHandler p == nil")
return nil
}
if msg.GetIsVideo() {
// 看视频可以再领一次
WelfareMgrSington.GetTurnplteVideo(p)
return nil
}
WelfareMgrSington.GetTurnplate(p)
}
return nil
}
// 累计签到
type CSGetAddupSignPacketFactory struct {
}
type CSGetAddupSignHandler struct {
}
func (this *CSGetAddupSignPacketFactory) CreatePacket() interface{} {
pack := &welfare.CSGetAddupSign{}
return pack
}
func (this *CSGetAddupSignHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSGetAddupSign Process recv ", data)
if msg, ok := data.(*welfare.CSGetAddupSign); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSGetAddupSignHandler p == nil")
return nil
}
WelfareMgrSington.GetAddupSign(p, msg.GetAddUpDay())
WelfareMgrSington.UpdateAddUp2Date(p, 0, msg.GetAddUpDay(), time.Now().Unix()+3600)
}
return nil
}
// 福利信息
type CSWelfaredInfoPacketFactory struct {
}
type CSWelfaredInfoHandler struct {
}
func (this *CSWelfaredInfoPacketFactory) CreatePacket() interface{} {
pack := &welfare.CSWelfaredInfo{}
return pack
}
func (this *CSWelfaredInfoHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSWelfaredInfo Process recv ", data)
if _, ok := data.(*welfare.CSWelfaredInfo); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSWelfaredInfoHandler p == nil")
return nil
}
WelfareMgrSington.WelfaredInfo(p)
}
return nil
}
// 查看盲盒
type CSBlindBoxInfoPacketFactory struct {
}
type CSBlindBoxInfoHandler struct {
}
func (this *CSBlindBoxInfoPacketFactory) CreatePacket() interface{} {
pack := &welfare.CSBlindBoxInfo{}
return pack
}
func (this *CSBlindBoxInfoHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSBlindBoxInfo Process recv ", data)
if msg, ok := data.(*welfare.CSBlindBoxInfo); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSBlindBoxInfoHandler p == nil")
return nil
}
WelfareMgrSington.BlindBoxInfo(p, msg.GetId())
}
return nil
}
// 购买盲盒
type CSBuyBlindBoxPacketFactory struct {
}
type CSBuyBlindBoxHandler struct {
}
func (this *CSBuyBlindBoxPacketFactory) CreatePacket() interface{} {
pack := &welfare.CSGetBlindBox{}
return pack
}
func (this *CSBuyBlindBoxHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSGetBlindBox Process recv ", data)
if _, ok := data.(*welfare.CSGetBlindBox); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSBuyBlindBoxHandler p == nil")
return nil
}
//WelfareMgrSington.BuyBlindBox(p, msg.GetId(), msg.ConfigPayId)
}
return nil
}
// 查看首充
type CSFirstPayInfoPacketFactory struct {
}
type CSFirstPayInfoHandler struct {
}
func (this *CSFirstPayInfoPacketFactory) CreatePacket() interface{} {
pack := &welfare.CSWelfareFirstPayData{}
return pack
}
func (this *CSFirstPayInfoHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSWelfareFirstPayData Process recv ", data)
if _, ok := data.(*welfare.CSWelfareFirstPayData); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSFirstPayInfoHandler p == nil")
return nil
}
WelfareMgrSington.FirstPayInfo(p)
}
return nil
}
// 领取首充
type CSBuyFirstPayPacketFactory struct {
}
type CSBuyFirstPayHandler struct {
}
func (this *CSBuyFirstPayPacketFactory) CreatePacket() interface{} {
pack := &welfare.CSWelfareFirstPay{}
return pack
}
func (this *CSBuyFirstPayHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSWelfareFirstPay Process recv ", data)
if _, ok := data.(*welfare.CSWelfareFirstPay); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSBuyFirstPayHandler p == nil")
return nil
}
//WelfareMgrSington.BuyFirstPay(p, msg.ConfigPayId)
}
return nil
}
// 查看连续充值
type CSContinuousPayInfoPacketFactory struct {
}
type CSContinuousPayInfoHandler struct {
}
func (this *CSContinuousPayInfoPacketFactory) CreatePacket() interface{} {
pack := &welfare.CSWelfareContinuousPayData{}
return pack
}
func (this *CSContinuousPayInfoHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSWelfareContinuousPayData Process recv ", data)
if _, ok := data.(*welfare.CSWelfareContinuousPayData); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSContinuousPayInfoHandler p == nil")
return nil
}
WelfareMgrSington.ContinuousPayInfo(p)
}
return nil
}
// 领取连续充值
type CSBuyContinuousPayPacketFactory struct {
}
type CSBuyContinuousPayHandler struct {
}
func (this *CSBuyContinuousPayPacketFactory) CreatePacket() interface{} {
pack := &welfare.CSWelfareContinuousPay{}
return pack
}
func (this *CSBuyContinuousPayHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSWelfareContinuousPay Process recv ", data)
if _, ok := data.(*welfare.CSWelfareContinuousPay); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSBuyContinuousPayHandler p == nil")
return nil
}
//WelfareMgrSington.BuyContinuousPay(p, msg.ConfigPayId)
}
return nil
}
func CSWelfRelief(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Tracef("CSWelfRelief Process recv %v", data)
_, ok := data.(*welfare.CSWelfareRelief)
if !ok {
return nil
}
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
return nil
}
conf := srvdata.PBDB_GameSubsidyMgr.GetData(GameSubsidyid)
ret := &welfare.SCWelfareRelief{
LimitNum: conf.GetLimitNum(),
Get: conf.GetGet(),
Times: conf.GetTimes(),
}
p.SendToClient(int(welfare.SPacketID_PACKET_SCWelfRelief), ret)
logger.Logger.Tracef("SCWelfRelief %v", ret)
return nil
}
func CSInviteInfo(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Tracef("CSInviteInfo Process recv %v", data)
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
return nil
}
link := model.GameParamData.InviteUrl
f := func() string {
return fmt.Sprintf("%s?user=%s", link, p.ICode)
}
var res []byte
var err error
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
req := &webapi_proto.ASPlayerInviteLink{
Platform: p.Platform,
SnId: p.SnId,
}
res, err = webapi.ApiGetInviteLink(common.GetAppId(), req)
return nil
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
info := webapi_proto.SAPlayerInviteLink{}
if err != nil || res == nil {
logger.Logger.Errorf("ApiGetInviteLink err %v or not return", err)
} else {
proto.Unmarshal(res, &info)
logger.Logger.Infof("ApiGetInviteLink info %v", info.String())
link = info.Link
}
ret := &welfare.SCInviteInfo{
Num: int32(p.INum),
Code: p.ICode,
InviteUrl: f(),
Score: p.IScore,
OtherCode: p.PCode,
}
cfg := PlatformMgrSingleton.GetConfig(p.Platform).ActInviteConfig
if cfg != nil {
ret.BindScore = cfg.GetBindScore()
ret.RechargeScore = cfg.GetRechargeScore()
ret.PayScore = cfg.GetPayScore()
for _, v := range cfg.GetAwards1() {
ret.Awards1 = append(ret.Awards1, &welfare.RankAward{
Start: v.GetStart(),
End: v.GetEnd(),
Num: v.GetNum(),
})
}
for _, v := range cfg.GetAwards2() {
ret.Awards2 = append(ret.Awards2, &welfare.RankAward{
Start: v.GetStart(),
End: v.GetEnd(),
Num: v.GetNum(),
})
}
for _, v := range cfg.GetAwards3() {
ret.Awards3 = append(ret.Awards3, &welfare.RankAward{
Start: v.GetStart(),
End: v.GetEnd(),
Num: v.GetNum(),
})
}
ret.Rates = cfg.GetRates()
}
p.SendToClient(int(welfare.SPacketID_PACKET_SCInviteInfo), ret)
logger.Logger.Tracef("SCInviteInfo %v", ret)
})).Start()
return nil
}
func CSBindInvite(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Tracef("CSBindInvite Process recv %v", data)
msg, ok := data.(*welfare.CSBindInvite)
if !ok {
return nil
}
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
return nil
}
ret := &welfare.SCBindInvite{
OpRetCode: welfare.OpResultCode_OPRC_Error,
}
var inviteSnId int32
var err error
now := time.Now()
cfg := PlatformMgrSingleton.GetConfig(p.Platform).ActInviteConfig
send := func() {
p.SendToClient(int(welfare.SPacketID_PACKET_SCBindInvite), ret)
logger.Logger.Tracef("SCBindInvite %v", ret)
if ret.OpRetCode == welfare.OpResultCode_OPRC_Sucess {
// 玩家自己的绑定任务
TaskSubjectSingleton.Touch(common.TaskTypeBindInviter, &TaskData{SnId: p.SnId, Num: 1})
}
}
if p.PSnId != 0 || p.PCode != "" {
ret.OpRetCode = welfare.OpResultCode_OPRC_AlreadyBind
send()
return nil
}
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
inviteSnId, err = model.GetSnIdByCode(p.Platform, msg.GetCode())
return nil
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
if err != nil || inviteSnId == 0 {
logger.Logger.Tracef("GetSnIdByCode not found %v %v", err, msg.GetCode())
ret.OpRetCode = welfare.OpResultCode_OPRC_NotExist
send()
return
}
// 3级父级不能是自己
var err error
tmpSnId := inviteSnId
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
// todo 优化查找顶级代理
for i := 0; i < 10000; i++ {
if tmpSnId == p.SnId {
ret.OpRetCode = welfare.OpResultCode_OPRC_BindSelf
err = errors.New("bind error")
return nil
}
tmpSnId, err = model.GetPlayerInviteSnid(p.Platform, tmpSnId)
if err != nil {
ret.OpRetCode = welfare.OpResultCode_OPRC_Error
return nil
}
if tmpSnId == 0 {
break
}
}
if err == nil {
err = model.BindInviteSnId(p.Platform, p.SnId, inviteSnId, msg.Code)
}
if err == nil {
SaveInviteScore(&model.InviteScore{
Platform: p.Platform,
SnId: p.SnId,
InviteSnId: inviteSnId,
Tp: common.InviteScoreTypeBind,
Score: cfg.GetBindScore(),
Ts: now.Unix(),
Money: 0,
})
}
return nil
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
if err != nil {
send()
return
}
p.PSnId = inviteSnId
p.PCode = msg.GetCode()
ret.OpRetCode = welfare.OpResultCode_OPRC_Sucess
send()
})).StartByFixExecutor("invite_score")
})).Start()
return nil
}
// ------------------------------------------------
type CSPigBankGetInfoPacketFactory struct {
}
type CSPigBankGetInfoHandler struct {
}
func (this *CSPigBankGetInfoPacketFactory) CreatePacket() interface{} {
pack := &welfare.CSPigbankGetInfo{}
return pack
}
func (this *CSPigBankGetInfoHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSPigbankGetInfo Process recv ", data)
if _, ok := data.(*welfare.CSPigbankGetInfo); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSPigBankGetInfoHandler p == nil")
return nil
}
WelfareMgrSington.PigbankGetInfo(p)
}
return nil
}
// ------------------------------------------------
type CSPigBankTakeCoinPacketFactory struct {
}
type CSPigBankTakeCoinHandler struct {
}
func (this *CSPigBankTakeCoinPacketFactory) CreatePacket() interface{} {
pack := &welfare.CSPigbankTakeCoin{}
return pack
}
func (this *CSPigBankTakeCoinHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSPigbankTakeCoin Process recv ", data)
if _, ok := data.(*welfare.CSPigbankTakeCoin); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSPigBankTakeCoinHandler p == nil")
return nil
}
WelfareMgrSington.PigbankTakeCoin(p)
}
return nil
}
// GetAddUp2Award
type CSSignDayAddup2AwardPacketFactory struct {
}
type CSSignDayAddup2AwardHandler struct {
}
func (this *CSSignDayAddup2AwardPacketFactory) CreatePacket() interface{} {
pack := &welfare.CSSignDayAddup2Award{}
return pack
}
func (this *CSSignDayAddup2AwardHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSSignDayAddup2Award Process recv ", data)
if msg, ok := data.(*welfare.CSSignDayAddup2Award); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSPigBankTakeCoinHandler p == nil")
return nil
}
WelfareMgrSington.GetAddUp2Award(p, msg.Day)
}
return nil
}
type CSDiamondBankGetInfoPacketFactory struct {
}
type CSDiamondBankGetInfoHandler struct {
}
func (this *CSDiamondBankGetInfoPacketFactory) CreatePacket() interface{} {
pack := &welfare.CSDiamondBankGetInfo{}
return pack
}
func (this *CSDiamondBankGetInfoHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSDiamondBankGetInfo Process recv ", data)
if _, ok := data.(*welfare.CSDiamondBankGetInfo); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSPigBankTakeCoinHandler p == nil")
return nil
}
WelfareMgrSington.DiamondBankGetInfo(p)
}
return nil
}
/*// 钻石储存罐
type CSDiamondBankTakeDiamondPacketFactory struct {
}
type CSDiamondBankTakeDiamondHandler struct {
}
func (this *CSDiamondBankTakeDiamondPacketFactory) CreatePacket() interface{} {
pack := &welfare.CSDiamondBankTakeDiamond{}
return pack
}
func (this *CSDiamondBankTakeDiamondHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSDiamondBankGetInfo Process recv ", data)
if _, ok := data.(*welfare.CSDiamondBankTakeDiamond); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSPigBankTakeCoinHandler p == nil")
return nil
}
WelfareMgrSington.DiamondBankTakeCoin(p)
}
return nil
}*/
func init() {
// 领取救济金
common.RegisterHandler(int(welfare.SPacketID_PACKET_CS_WELF_GETRELIEFFUND), &CSGetReliefFundHandler{})
netlib.RegisterFactory(int(welfare.SPacketID_PACKET_CS_WELF_GETRELIEFFUND), &CSGetReliefFundPacketFactory{})
//转动转盘
common.RegisterHandler(int(welfare.SPacketID_PACKET_CS_WELF_GETTURNPLATE), &CSGetTurnplateHandler{})
netlib.RegisterFactory(int(welfare.SPacketID_PACKET_CS_WELF_GETTURNPLATE), &CSGetTurnplatePacketFactory{})
//累计签到
common.RegisterHandler(int(welfare.SPacketID_PACKET_CS_WELF_GETADDUPSIGN), &CSGetAddupSignHandler{})
netlib.RegisterFactory(int(welfare.SPacketID_PACKET_CS_WELF_GETADDUPSIGN), &CSGetAddupSignPacketFactory{})
//福利信息
common.RegisterHandler(int(welfare.SPacketID_PACKET_CS_WELF_WELFAREINFO), &CSWelfaredInfoHandler{})
netlib.RegisterFactory(int(welfare.SPacketID_PACKET_CS_WELF_WELFAREINFO), &CSWelfaredInfoPacketFactory{})
//查看盲盒
common.RegisterHandler(int(welfare.SPacketID_PACKET_CS_WELF_BLINBOXINFO), &CSBlindBoxInfoHandler{})
netlib.RegisterFactory(int(welfare.SPacketID_PACKET_CS_WELF_BLINBOXINFO), &CSBlindBoxInfoPacketFactory{})
//购买盲盒
common.RegisterHandler(int(welfare.SPacketID_PACKET_CS_WELF_GETBLINBOX), &CSBuyBlindBoxHandler{})
netlib.RegisterFactory(int(welfare.SPacketID_PACKET_CS_WELF_GETBLINBOX), &CSBuyBlindBoxPacketFactory{})
//查看首充
common.RegisterHandler(int(welfare.SPacketID_PACKET_CS_WELF_FIRSTPAYINFO), &CSFirstPayInfoHandler{})
netlib.RegisterFactory(int(welfare.SPacketID_PACKET_CS_WELF_FIRSTPAYINFO), &CSFirstPayInfoPacketFactory{})
//领取首充
common.RegisterHandler(int(welfare.SPacketID_PACKET_CS_WELF_FIRSTPAY), &CSBuyFirstPayHandler{})
netlib.RegisterFactory(int(welfare.SPacketID_PACKET_CS_WELF_FIRSTPAY), &CSBuyFirstPayPacketFactory{})
//查看连续充值
common.RegisterHandler(int(welfare.SPacketID_PACKET_CS_WELF_CONTINPAYINFO), &CSContinuousPayInfoHandler{})
netlib.RegisterFactory(int(welfare.SPacketID_PACKET_CS_WELF_CONTINPAYINFO), &CSContinuousPayInfoPacketFactory{})
//领取连续充值
common.RegisterHandler(int(welfare.SPacketID_PACKET_CS_WELF_CONTINPAY), &CSBuyContinuousPayHandler{})
netlib.RegisterFactory(int(welfare.SPacketID_PACKET_CS_WELF_CONTINPAY), &CSBuyContinuousPayPacketFactory{})
// 破产补助信息
common.Register(int(welfare.SPacketID_PACKET_CSWelfRelief), welfare.CSWelfareRelief{}, CSWelfRelief)
// 邀请信息
common.Register(int(welfare.SPacketID_PACKET_CSInviteInfo), welfare.CSInviteInfo{}, CSInviteInfo)
// 绑定信息
common.Register(int(welfare.SPacketID_PACKET_CSBindInvite), welfare.CSBindInvite{}, CSBindInvite)
//获取存钱罐数据
common.RegisterHandler(int(welfare.SPacketID_PACKET_CSPigbankGetInfo), &CSPigBankGetInfoHandler{})
netlib.RegisterFactory(int(welfare.SPacketID_PACKET_CSPigbankGetInfo), &CSPigBankGetInfoPacketFactory{})
//领取存钱罐金币
common.RegisterHandler(int(welfare.SPacketID_PACKET_CSPigbankTakeCoin), &CSPigBankTakeCoinHandler{})
netlib.RegisterFactory(int(welfare.SPacketID_PACKET_CSPigbankTakeCoin), &CSPigBankTakeCoinPacketFactory{})
//领取七日签到进阶奖励
common.RegisterHandler(int(welfare.SPacketID_PACKET_CS_SignDay_Addup2Award), &CSSignDayAddup2AwardHandler{})
netlib.RegisterFactory(int(welfare.SPacketID_PACKET_CS_SignDay_Addup2Award), &CSSignDayAddup2AwardPacketFactory{})
//钻石储存罐信息
common.RegisterHandler(int(welfare.SPacketID_PACKET_CSDiamondBankGetInfo), &CSDiamondBankGetInfoHandler{})
netlib.RegisterFactory(int(welfare.SPacketID_PACKET_CSDiamondBankGetInfo), &CSDiamondBankGetInfoPacketFactory{})
//领取钻石储存罐
/* common.RegisterHandler(int(welfare.SPacketID_PACKET_CSDiamondBankTakeDiamond), &CSDiamondBankTakeDiamondHandler{})
netlib.RegisterFactory(int(welfare.SPacketID_PACKET_CSDiamondBankTakeDiamond), &CSDiamondBankTakeDiamondPacketFactory{})*/
}