776 lines
22 KiB
Go
776 lines
22 KiB
Go
package main
|
||
|
||
import (
|
||
"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"
|
||
"mongo.games.com/game/protocol/shop"
|
||
"mongo.games.com/game/srvdata"
|
||
)
|
||
|
||
type CSShopInfoPacketFactory struct {
|
||
}
|
||
|
||
type CSShopInfoHandler struct {
|
||
}
|
||
|
||
func (this *CSShopInfoPacketFactory) CreatePacket() interface{} {
|
||
pack := &shop.CSShopInfo{}
|
||
return pack
|
||
}
|
||
|
||
func (this *CSShopInfoHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
|
||
logger.Logger.Trace("CSShopInfoHandler Process recv ", data)
|
||
if msg, ok := data.(*shop.CSShopInfo); ok {
|
||
p := PlayerMgrSington.GetOnlinePlayer(sid)
|
||
if p == nil {
|
||
logger.Logger.Warn("CSShopInfoHandler p == nil")
|
||
return nil
|
||
}
|
||
platform := p.GetPlatform()
|
||
if platform == nil {
|
||
return nil
|
||
}
|
||
shopInfos := ShopMgrSington.GetShopInfos(p, int(msg.NowLocation-1))
|
||
pack := &shop.SCShopInfo{
|
||
Infos: shopInfos,
|
||
}
|
||
logger.Logger.Trace("SCShopInfo:", pack, len(shopInfos))
|
||
p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_INFO), pack)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
type CSAdLookedPacketFactory struct {
|
||
}
|
||
|
||
type CSAdLookedHandler struct {
|
||
}
|
||
|
||
func (this *CSAdLookedPacketFactory) CreatePacket() interface{} {
|
||
pack := &shop.CSAdLooked{}
|
||
return pack
|
||
}
|
||
|
||
func (this *CSAdLookedHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
|
||
logger.Logger.Trace("CSAdLookedHandler Process recv ", data)
|
||
if msg, ok := data.(*shop.CSAdLooked); ok {
|
||
p := PlayerMgrSington.GetOnlinePlayer(sid)
|
||
if p == nil {
|
||
logger.Logger.Warn("CSAdLookedHandler p == nil")
|
||
return nil
|
||
}
|
||
platform := p.GetPlatform()
|
||
if platform == nil {
|
||
return nil
|
||
}
|
||
pack := &shop.SCAdLooked{
|
||
RetCode: shop.OpResultCode_OPRC_Error,
|
||
}
|
||
shopInfo := ShopMgrSington.GetShopInfo(msg.ShopId, p)
|
||
if shopInfo == nil {
|
||
return nil
|
||
}
|
||
if shopInfo.Ad == 0 {
|
||
p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_ADLOOKED), pack)
|
||
logger.Logger.Warnf("CSAdLookedHandler shopId(%v) Ad(%v)", msg.ShopId, shopInfo.Ad == 0)
|
||
return nil
|
||
}
|
||
if shopInfo.RemainingTime >= 5 { // 冷却时间大于5秒
|
||
p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_ADLOOKED), pack)
|
||
logger.Logger.Warn("冷却中ing RemainingTime", shopInfo.RemainingTime)
|
||
return nil
|
||
}
|
||
if shopTotal, ok1 := p.ShopTotal[msg.ShopId]; ok1 {
|
||
if shopInfo.RepeatTimes <= shopTotal.AdReceiveNum {
|
||
p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_ADLOOKED), pack)
|
||
logger.Logger.Warn("次数已满 已经领取的次数AdReceiveNum", shopInfo.AdReceiveNum)
|
||
return nil
|
||
}
|
||
shopTotal.AdLookedNum++
|
||
} else {
|
||
p.ShopTotal[msg.ShopId] = &model.ShopTotal{AdLookedNum: 1}
|
||
}
|
||
b := ShopMgrSington.LookAdReceive(msg.ShopId, p, msg.GetPosition())
|
||
pack.RetCode = b
|
||
if b == shop.OpResultCode_OPRC_Sucess {
|
||
p.ShopLastLookTime[msg.ShopId] = time.Now().Unix()
|
||
}
|
||
|
||
si := ShopMgrSington.GetShopInfo(msg.ShopId, p)
|
||
if si != nil {
|
||
pack.ShopInfo = ShopMgrSington.GetShopInfoProto(si, p, 0)
|
||
}
|
||
logger.Logger.Trace("ShopTotal:", p.ShopTotal[msg.ShopId])
|
||
logger.Logger.Trace("SCAdLooked:", pack)
|
||
p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_ADLOOKED), pack)
|
||
|
||
if pack.RetCode == shop.OpResultCode_OPRC_Sucess {
|
||
ShopMgrSington.ShopCheckShowRed(p)
|
||
ShopMgrSington.StartTimer(p.SnId, si.RemainingTime)
|
||
}
|
||
}
|
||
return nil
|
||
}
|
||
|
||
type CSVCPayShopPacketFactory struct {
|
||
}
|
||
|
||
type CSVCPayShopHandler struct {
|
||
}
|
||
|
||
func (this *CSVCPayShopPacketFactory) CreatePacket() interface{} {
|
||
pack := &shop.CSVCPayShop{}
|
||
return pack
|
||
}
|
||
|
||
func (this *CSVCPayShopHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
|
||
logger.Logger.Trace("CSVCPayShopHandler Process recv ", data)
|
||
if msg, ok := data.(*shop.CSVCPayShop); ok {
|
||
p := PlayerMgrSington.GetOnlinePlayer(sid)
|
||
if p == nil {
|
||
logger.Logger.Warn("CSVCPayShopHandler p == nil")
|
||
return nil
|
||
}
|
||
|
||
platform := p.GetPlatform()
|
||
if platform == nil {
|
||
return nil
|
||
}
|
||
|
||
shopInfo := ShopMgrSington.GetShopInfo(msg.ShopId, p)
|
||
if shopInfo == nil {
|
||
return nil
|
||
}
|
||
|
||
// 看广告不走这里
|
||
if shopInfo.Ad > 0 {
|
||
return nil
|
||
}
|
||
|
||
var pack = &shop.SCVCPayShop{}
|
||
SendClient := func(ret shop.OpResultCode) {
|
||
pack.RetCode = ret
|
||
if ret == shop.OpResultCode_OPRC_Sucess {
|
||
si := ShopMgrSington.GetShopInfo(msg.ShopId, p)
|
||
if si != nil {
|
||
pack.ShopInfo = ShopMgrSington.GetShopInfoProto(si, p, msg.VipShopId)
|
||
}
|
||
pack.ShopInfo.VipShopId = msg.VipShopId
|
||
}
|
||
p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_VCPAYSHOP), pack)
|
||
logger.Logger.Trace("SCVCPayShop:", pack)
|
||
}
|
||
|
||
if p.VIP < shopInfo.VipLevel {
|
||
logger.Logger.Errorf("VIP等级不足!snid = %v,Vip = %v,shopInfo.VipLevel = %v,Id = %v", p.SnId, p.VIP, shopInfo.VipLevel, shopInfo.Id)
|
||
SendClient(shop.OpResultCode_OPRC_VipLevelNotEnough)
|
||
return nil
|
||
}
|
||
|
||
// 购买检查
|
||
switch shopInfo.Page {
|
||
case ShopPageVip:
|
||
if p.VipShopData[msg.VipShopId] == nil || p.VipShopData[msg.VipShopId].IsBuy {
|
||
SendClient(shop.OpResultCode_OPRC_ExchangeLimit)
|
||
logger.Logger.Tracef("玩家VIP商城购买 当前物品无法购买! snid = %v,p.VipShopData[shopInfo.Id] = %v", p.SnId, p.GetVipShopData(shopInfo.Id, msg.VipShopId))
|
||
return nil
|
||
}
|
||
|
||
case ShopPageGift:
|
||
if !p.CheckWeekCard(shopInfo.Id) {
|
||
SendClient(shop.OpResultCode_OPRC_Error)
|
||
return nil
|
||
}
|
||
default:
|
||
}
|
||
|
||
// 消耗检查
|
||
costNum := ShopMgrSington.GetCostNum(p, shopInfo, msg.GetVipShopId())
|
||
switch shopInfo.ConstType {
|
||
case ShopConsumeCoin:
|
||
//金币
|
||
if costNum > p.Coin {
|
||
SendClient(shop.OpResultCode_OPRC_Error)
|
||
return nil
|
||
}
|
||
case ShopConsumeDiamond:
|
||
//钻石
|
||
if costNum > p.Diamond {
|
||
SendClient(shop.OpResultCode_OPRC_Error)
|
||
return nil
|
||
}
|
||
case ShopConsumeMoney:
|
||
SendClient(shop.OpResultCode_OPRC_Error)
|
||
return nil
|
||
case ShopConsumePhoneScore:
|
||
if costNum > p.PhoneScore {
|
||
SendClient(shop.OpResultCode_OPRC_Error)
|
||
return nil
|
||
}
|
||
case ShopConsumeDiamondScore:
|
||
item := BagMgrSingleton.GetItem(p.SnId, common.ItemDiamondScore)
|
||
if item == nil || costNum > item.ItemNum {
|
||
SendClient(shop.OpResultCode_OPRC_Error)
|
||
return nil
|
||
}
|
||
default:
|
||
SendClient(shop.OpResultCode_OPRC_Error)
|
||
return nil
|
||
}
|
||
|
||
op := ShopMgrSington.GainShop(shopInfo, p, msg.VipShopId, msg.GetPosition())
|
||
SendClient(op)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
type CSShopExchangeRecordPacketFactory struct {
|
||
}
|
||
|
||
type CSShopExchangeRecordHandler struct {
|
||
}
|
||
|
||
func (this *CSShopExchangeRecordPacketFactory) CreatePacket() interface{} {
|
||
pack := &shop.CSShopExchangeRecord{}
|
||
return pack
|
||
}
|
||
|
||
func (this *CSShopExchangeRecordHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
|
||
logger.Logger.Trace("CSShopExchangeRecordHandler Process recv ", data)
|
||
if msg, ok := data.(*shop.CSShopExchangeRecord); ok {
|
||
p := PlayerMgrSington.GetOnlinePlayer(sid)
|
||
if p == nil {
|
||
logger.Logger.Warn("CSShopExchangeRecordHandler p == nil")
|
||
return nil
|
||
}
|
||
platform := p.GetPlatform()
|
||
if platform == nil {
|
||
return nil
|
||
}
|
||
ShopMgrSington.GetExchangeRecord(p, msg.PageNo)
|
||
|
||
}
|
||
return nil
|
||
}
|
||
|
||
type CSShopExchangePacketFactory struct {
|
||
}
|
||
|
||
type CSShopExchangeHandler struct {
|
||
}
|
||
|
||
func (this *CSShopExchangePacketFactory) CreatePacket() interface{} {
|
||
pack := &shop.CSShopExchange{}
|
||
return pack
|
||
}
|
||
|
||
func (this *CSShopExchangeHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
|
||
logger.Logger.Trace("CSShopExchangeHandler Process recv ", data)
|
||
msg, ok := data.(*shop.CSShopExchange)
|
||
if !ok {
|
||
return nil
|
||
}
|
||
|
||
p := PlayerMgrSington.GetOnlinePlayer(sid)
|
||
if p == nil {
|
||
logger.Logger.Warn("CSShopExchangeHandler p == nil")
|
||
return nil
|
||
}
|
||
|
||
if !PlatformMgrSingleton.IsOn(p.Platform, common.ChannelSwitchExchange, p.LastChannel) {
|
||
return nil
|
||
}
|
||
|
||
/* switch msg.ExchangeType {
|
||
case 1: // 自提
|
||
//自提 直接增加道具到背包
|
||
cdata := ShopMgrSington.GetExchangeData(p.Platform, msg.GoodsId)
|
||
if cdata == nil || cdata.ItemId == 0 {
|
||
return nil
|
||
}
|
||
//获取道具Id
|
||
var items []*Item
|
||
items = append(items, &Item{
|
||
ItemId: cdata.ItemId, // 物品id
|
||
ItemNum: 1, // 数量
|
||
ObtainTime: time.Now().Unix(),
|
||
})
|
||
BagMgrSingleton.AddItems(p, items, 0, common.GainWay_Exchange, "system", "商城兑换", 0, 0, false)
|
||
default:
|
||
}*/
|
||
|
||
_, f := BlackListMgrSington.CheckExchange(p.PlayerData)
|
||
if !f {
|
||
pack := &shop.SCShopExchange{
|
||
RetCode: shop.OpResultCode_OPRC_ExchangeLimitAcc,
|
||
GoodsId: msg.GetGoodsId(),
|
||
}
|
||
p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_EXCHANGE), pack)
|
||
return nil
|
||
}
|
||
if msg.Amount <= 0 || msg.Amount > 100 {
|
||
return nil
|
||
}
|
||
|
||
ShopMgrSington.Exchange(&ExchangeParam{
|
||
Platform: p.Platform,
|
||
SnId: p.SnId,
|
||
VipLevel: p.VIP,
|
||
Tel: p.Tel,
|
||
Name: p.Name,
|
||
PackageId: p.PackageID,
|
||
ExchangeTypeId: msg.GetId(),
|
||
Id: msg.GetGoodsId(),
|
||
UserName: msg.GetUserName(),
|
||
Mobile: msg.GetMobile(),
|
||
Address: msg.GetComment(),
|
||
Num: msg.GetAmount(),
|
||
GiveType: msg.GetExchangeType(),
|
||
TelId: msg.GetTelId(),
|
||
CallBackFunc: func(code shop.OpResultCode) {
|
||
pack := &shop.SCShopExchange{
|
||
RetCode: code,
|
||
GoodsId: msg.GetGoodsId(),
|
||
}
|
||
p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_EXCHANGE), pack)
|
||
logger.Logger.Tracef("SCShopExchange:%v", pack)
|
||
},
|
||
})
|
||
return nil
|
||
}
|
||
|
||
// 兑换列表
|
||
type CSShopExchangeListPacketFactory struct {
|
||
}
|
||
|
||
type CSShopExchangeListHandler struct {
|
||
}
|
||
|
||
func (this *CSShopExchangeListPacketFactory) CreatePacket() interface{} {
|
||
pack := &shop.CSShopExchangeList{}
|
||
return pack
|
||
}
|
||
|
||
func (this *CSShopExchangeListHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
|
||
logger.Logger.Trace("CSShopExchangeListHandler Process recv ", data)
|
||
if _, ok := data.(*shop.CSShopExchangeList); ok {
|
||
p := PlayerMgrSington.GetOnlinePlayer(sid)
|
||
if p == nil {
|
||
logger.Logger.Warn("CSShopExchangeListHandler p == nil")
|
||
return nil
|
||
}
|
||
|
||
ShopMgrSington.ExchangeList(p)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// 充值
|
||
type CSPayInfoPacketFactory struct {
|
||
}
|
||
|
||
type CSPayInfoHandler struct {
|
||
}
|
||
|
||
func (this *CSPayInfoPacketFactory) CreatePacket() interface{} {
|
||
pack := &shop.CSPayInfo{}
|
||
return pack
|
||
}
|
||
|
||
func (this *CSPayInfoHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
|
||
logger.Logger.Trace("CSPayInfoHandler Process recv ", data)
|
||
if msg, ok := data.(*shop.CSPayInfo); ok {
|
||
p := PlayerMgrSington.GetOnlinePlayer(sid)
|
||
if p == nil {
|
||
logger.Logger.Warn("CSPayInfoHandler p == nil")
|
||
return nil
|
||
}
|
||
|
||
SendClient := func(ret shop.OpResultCode) {
|
||
pack := &shop.SCPayInfo{
|
||
RetCode: ret,
|
||
}
|
||
p.SendToClient(int(shop.SPacketID_PACKET_SCPAYINFO), pack)
|
||
}
|
||
//充值限制
|
||
_, f := BlackListMgrSington.CheckRecharge(p.PlayerData)
|
||
if !f {
|
||
SendClient(shop.OpResultCode_OPRC_ExchangeLimitAcc)
|
||
return nil
|
||
}
|
||
if msg.GoodsId >= ShopTypeStart {
|
||
//商城id
|
||
shopInfo := ShopMgrSington.GetShopInfo(msg.GoodsId, p)
|
||
if shopInfo == nil {
|
||
SendClient(shop.OpResultCode_OPRC_ExchangeSoldOut)
|
||
return nil
|
||
}
|
||
if shopInfo.ConstType != ShopConsumeMoney {
|
||
SendClient(shop.OpResultCode_OPRC_Error)
|
||
return nil
|
||
}
|
||
if shopInfo.Page == ShopPageGift {
|
||
if !p.CheckWeekCard(shopInfo.Id) {
|
||
SendClient(shop.OpResultCode_OPRC_Error)
|
||
return nil
|
||
}
|
||
}
|
||
if shopInfo.Page == ShopPageDiamondBank {
|
||
// 检查每日领取次数
|
||
fGetPropValue := func(propName string) int32 {
|
||
pool := srvdata.PBDB_Pigbank_PropMgr.Datas.GetArr()
|
||
for _, PropItem := range pool {
|
||
if PropItem.PorpName == propName {
|
||
return PropItem.PropValue
|
||
}
|
||
}
|
||
return 0
|
||
}
|
||
DayBuyMaxCnt := fGetPropValue("DayBuyMaxCnt")
|
||
if p.WelfData.DiamondBank.DayBuyTimes >= DayBuyMaxCnt {
|
||
SendClient(shop.OpResultCode_OPRC_Error)
|
||
return nil
|
||
}
|
||
}
|
||
if shopInfo.Page == ShopPageVip {
|
||
//判断是否购买过了
|
||
vipLevel := p.VIP
|
||
if shopInfo.Type == 1 {
|
||
vipCfg := VipMgrSington.GetVipCfg(p.Platform, p.VIP)
|
||
if vipCfg == nil || vipCfg.ShopId2 != msg.GoodsId {
|
||
SendClient(shop.OpResultCode_OPRC_Error)
|
||
return nil
|
||
}
|
||
} else {
|
||
vipLevel = shopInfo.VipLevel
|
||
}
|
||
if p.GetPlayerVipBagStatus(shopInfo.Id, vipLevel) == 1 {
|
||
logger.Logger.Error("充值购买VIP礼包失败!!!!!!!!!!!!!")
|
||
SendClient(shop.OpResultCode_OPRC_Error)
|
||
return nil
|
||
}
|
||
/* //VIP金币礼包 判断当前vip等级的礼包是否领取过
|
||
if p.WelfData.VIPBag == nil {
|
||
p.WelfData.VIPBag = make(map[int32]map[int32]int32)
|
||
}
|
||
if p.WelfData.VIPBag[vipLevel] != nil && p.WelfData.VIPBag[vipLevel][msg.GoodsId] == shopInfo.Type {
|
||
logger.Logger.Error("充值购买VIP礼包失败!!!!!!!!!!!!!")
|
||
SendClient(shop.OpResultCode_OPRC_Error)
|
||
return nil
|
||
}*/
|
||
}
|
||
if shopInfo.Page == ShopPagePermit {
|
||
if p.GetIsPermit() {
|
||
logger.Logger.Error("已购买典藏通行证")
|
||
SendClient(shop.OpResultCode_OPRC_Error)
|
||
return nil
|
||
}
|
||
}
|
||
ShopMgrSington.SendAPICreateOrder(p, msg.ConfigPayId, shopInfo, "shop_goods_xj")
|
||
|
||
} else {
|
||
//活动
|
||
switch msg.GoodsId {
|
||
case BlindBox:
|
||
WelfareMgrSington.BuyBlindBox(p, msg.BuyId, msg.ConfigPayId)
|
||
case FirstPay:
|
||
WelfareMgrSington.BuyFirstPay(p, msg.ConfigPayId)
|
||
case ContinuousPay:
|
||
WelfareMgrSington.BuyContinuousPay(p, msg.ConfigPayId)
|
||
case Exchange:
|
||
cdata := ShopMgrSington.GetExchangeData(p.Platform, msg.BuyId)
|
||
if cdata == nil {
|
||
SendClient(shop.OpResultCode_OPRC_ExchangeSoldOut)
|
||
return nil
|
||
}
|
||
if msg.ExchangeNum <= 0 {
|
||
return nil
|
||
}
|
||
cdata.OrderId = msg.ExchangeOrderId
|
||
cdata.ExchangeTypeId = msg.ExchangeId
|
||
cdata.ExchangeNum = msg.ExchangeNum
|
||
ShopMgrSington.SendAPICreateOrder(p, msg.ConfigPayId, cdata, "shop_exchange")
|
||
}
|
||
}
|
||
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// 获取充值记录
|
||
type CSGetPayInfoListPacketFactory struct {
|
||
}
|
||
|
||
type CSGetPayInfoListHandler struct {
|
||
}
|
||
|
||
func (this *CSGetPayInfoListPacketFactory) CreatePacket() interface{} {
|
||
pack := &shop.CSGetPayInfoList{}
|
||
return pack
|
||
}
|
||
|
||
func (this *CSGetPayInfoListHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
|
||
logger.Logger.Trace("CSGetPayInfoListHandler Process recv ", data)
|
||
if msg, ok := data.(*shop.CSGetPayInfoList); ok {
|
||
p := PlayerMgrSington.GetOnlinePlayer(sid)
|
||
if p == nil {
|
||
logger.Logger.Warn("CSGetPayInfoListHandler p == nil")
|
||
return nil
|
||
}
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
return model.GetDbShopLogsByPage(p.Platform, p.SnId, msg.OpType)
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
logger.Logger.Trace("model.GetDbShopLogsByPage", data)
|
||
pack := &shop.SCGetPayInfoList{}
|
||
if data != nil {
|
||
info := data.([]*model.DbShop)
|
||
for _, dbShop := range info {
|
||
var itemInfo []*shop.ItemInfo
|
||
for _, i2 := range dbShop.ItemInfo {
|
||
itemInfo = append(itemInfo, &shop.ItemInfo{
|
||
ItemId: i2.ItemId,
|
||
ItemNum: i2.ItemNum,
|
||
})
|
||
}
|
||
pack.Info = append(pack.Info, &shop.PayInfoList{
|
||
OrderId: dbShop.LogId.Hex(),
|
||
ConsumeType: dbShop.Consume,
|
||
ConsumeNum: dbShop.ConsumeNum,
|
||
Amount: dbShop.Amount,
|
||
ItemInfo: itemInfo,
|
||
State: dbShop.State,
|
||
Ts: dbShop.CreateTs.Unix(),
|
||
})
|
||
}
|
||
|
||
}
|
||
proto.SetDefaults(pack)
|
||
p.SendToClient(int(shop.SPacketID_PACKET_SCGETPAYINFOLIST), pack)
|
||
logger.Logger.Tracef("SCGetPayInfoListHandler sid:%v", pack)
|
||
}), "model.GetDbShopLogsByPage").Start()
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// 1.增加 2.查询 3.删除
|
||
const (
|
||
AddAddr int32 = 1
|
||
SelectAddr int32 = 2
|
||
DelAddr int32 = 3
|
||
UpdateAddr int32 = 4
|
||
)
|
||
|
||
func UpdatePlayerAddress(plt string, snid int32, op int32, addr string, id int32, callback func([]string)) {
|
||
f := func(address []string) []string {
|
||
switch op {
|
||
case AddAddr:
|
||
if len(addr) > 200 {
|
||
logger.Logger.Warnf("玩家添加地址 地址长度过长len = %v,SnId = &v,addr = %v", len(addr), snid, addr)
|
||
return address
|
||
}
|
||
if len(address) >= 3 {
|
||
logger.Logger.Warn("最多添加3条地址!")
|
||
return address
|
||
}
|
||
logger.Logger.Trace("添加的地址:", addr)
|
||
|
||
address = append(address, addr)
|
||
case DelAddr:
|
||
if id >= 3 {
|
||
return address
|
||
}
|
||
address = append(address[:id], address[id+1:]...)
|
||
case UpdateAddr:
|
||
if id >= 3 {
|
||
return address
|
||
}
|
||
if len(address) != 0 && len(address) < int(id) {
|
||
return address
|
||
}
|
||
address[id] = addr
|
||
}
|
||
return address
|
||
}
|
||
|
||
p := PlayerMgrSington.GetPlayerBySnId(snid)
|
||
if p != nil {
|
||
p.PlayerData.Addr = f(p.PlayerData.Addr)
|
||
callback(p.PlayerData.Addr)
|
||
return
|
||
}
|
||
|
||
var address []string
|
||
var err error
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
address, err = model.GetPlayerAddress(plt, snid)
|
||
if err != nil {
|
||
return nil
|
||
}
|
||
address = f(address)
|
||
model.UpdatePlayerAddress(plt, snid, address)
|
||
return nil
|
||
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
|
||
callback(address)
|
||
}), "GetAddress").Start()
|
||
}
|
||
|
||
// 添加玩家地址
|
||
type CSPlayerAddrPacketFactory struct {
|
||
}
|
||
|
||
type CSPlayerAddrHandler struct {
|
||
}
|
||
|
||
func (this *CSPlayerAddrPacketFactory) CreatePacket() interface{} {
|
||
pack := &shop.CSPlayerAddr{}
|
||
return pack
|
||
}
|
||
|
||
func (this *CSPlayerAddrHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
|
||
logger.Logger.Trace("CSPlayerAddr Process recv ", data)
|
||
if msg, ok := data.(*shop.CSPlayerAddr); ok {
|
||
p := PlayerMgrSington.GetOnlinePlayer(sid)
|
||
if p == nil {
|
||
logger.Logger.Warn("CSPlayerAddr p == nil")
|
||
return nil
|
||
}
|
||
UpdatePlayerAddress(p.Platform, p.SnId, msg.GetOpType(), msg.GetAddr(), msg.GetId(), func(addr []string) {
|
||
// 返回消息
|
||
pack := &shop.SCGetPlayerAddrs{}
|
||
for k, v := range p.PlayerData.Addr {
|
||
pack.Addrs = append(pack.Addrs, &shop.AddrData{
|
||
Id: int32(k),
|
||
Addr: v,
|
||
})
|
||
}
|
||
p.SendToClient(int(shop.SPacketID_PACKET_SCPLAYERADDR), pack)
|
||
logger.Logger.Trace("SCGetPlayerAddrs:", pack)
|
||
})
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// 添加玩家地址
|
||
type CSUpdateVipShopPacketFactory struct {
|
||
}
|
||
|
||
type CSUpdateVipShopHandler struct {
|
||
}
|
||
|
||
func (this *CSUpdateVipShopPacketFactory) CreatePacket() interface{} {
|
||
pack := &shop.CSUpdateVipShop{}
|
||
return pack
|
||
}
|
||
|
||
func (this *CSUpdateVipShopHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
|
||
p := PlayerMgrSington.GetOnlinePlayer(sid)
|
||
if p == nil {
|
||
logger.Logger.Warn("CSPayInfoHandler p == nil")
|
||
return nil
|
||
}
|
||
if p.VIP == 0 {
|
||
return nil
|
||
}
|
||
vipConfig := VipMgrSington.GetVIPLevelCfg(p.Platform, p.VIP)
|
||
if vipConfig == nil {
|
||
return nil
|
||
}
|
||
|
||
if p.VipShopRefreshCount >= vipConfig.Privilege3[0] {
|
||
logger.Logger.Error("玩家VIP商城刷新次数不足 snid = ", p.SnId)
|
||
return nil
|
||
}
|
||
ShopMgrSington.UpdateVipShopData(p)
|
||
p.VipShopRefreshCount += 1
|
||
pack := &shop.SCUpdateVipShop{
|
||
RefreshCount: p.VipShopRefreshCount, //玩家当前刷新次数
|
||
}
|
||
for i, info := range p.VipShopData {
|
||
si := ShopMgrSington.GetConfig(p.Platform).ShopInfos[info.Id]
|
||
if si == nil {
|
||
continue
|
||
}
|
||
data := &shop.ShopInfo{
|
||
Id: info.Id,
|
||
AdLookedNum: si.AdLookedNum,
|
||
AdReceiveNum: si.AdReceiveNum,
|
||
LastLookTime: si.LastLookTime,
|
||
RoleAdded: si.RoleAdded,
|
||
PetAdded: si.PetAdded,
|
||
ItemId: si.ItemId,
|
||
Order: si.Order,
|
||
Page: si.Page,
|
||
Type: si.Type,
|
||
Location: si.Location,
|
||
Picture: si.Picture,
|
||
Name: si.Name,
|
||
Ad: si.Ad,
|
||
AdTime: si.AdTime,
|
||
RepeatTimes: si.RepeatTimes,
|
||
CoolingTime: si.CoolingTime,
|
||
Label: si.Label,
|
||
Added: info.AddArea,
|
||
Amount: si.Amount * int64(info.CostArea),
|
||
Consume: si.ConstType,
|
||
ConsumptionAmount: info.CostArea,
|
||
AddItemInfo: si.AddItemInfo,
|
||
VipLevel: si.VipLevel,
|
||
EndTime: si.EndTime,
|
||
IsBuy: info.IsBuy,
|
||
VipShopId: i,
|
||
AmountFinal: ShopMgrSington.GetAmountFinal(p, si.Id, i),
|
||
}
|
||
|
||
pack.Info = append(pack.Info, data)
|
||
}
|
||
p.SendToClient(int(shop.SPacketID_PACKET_SC_UPDATE_VIP_SHOP), pack)
|
||
return nil
|
||
}
|
||
func init() {
|
||
// 商城接口
|
||
|
||
// 获取商城商品信息列表
|
||
common.RegisterHandler(int(shop.SPacketID_PACKET_CS_SHOP_INFO), &CSShopInfoHandler{})
|
||
netlib.RegisterFactory(int(shop.SPacketID_PACKET_CS_SHOP_INFO), &CSShopInfoPacketFactory{})
|
||
// 看广告领取商品,校验冷却时间和领取次数(免费)
|
||
common.RegisterHandler(int(shop.SPacketID_PACKET_CS_SHOP_ADLOOKED), &CSAdLookedHandler{})
|
||
netlib.RegisterFactory(int(shop.SPacketID_PACKET_CS_SHOP_ADLOOKED), &CSAdLookedPacketFactory{})
|
||
// 购买商品不看广告
|
||
common.RegisterHandler(int(shop.SPacketID_PACKET_CS_SHOP_VCPAYSHOP), &CSVCPayShopHandler{})
|
||
netlib.RegisterFactory(int(shop.SPacketID_PACKET_CS_SHOP_VCPAYSHOP), &CSVCPayShopPacketFactory{})
|
||
// 获取订单记录(非现金:金币,道具;现金的走透传后台获取)
|
||
common.RegisterHandler(int(shop.SPacketID_PACKET_CSGETPAYINFOLIST), &CSGetPayInfoListHandler{})
|
||
netlib.RegisterFactory(int(shop.SPacketID_PACKET_CSGETPAYINFOLIST), &CSGetPayInfoListPacketFactory{})
|
||
|
||
// 兑换商城接口
|
||
|
||
// 获取商城商品兑换列表
|
||
common.RegisterHandler(int(shop.SPacketID_PACKET_CS_SHOP_EXCHANGELIST), &CSShopExchangeListHandler{})
|
||
netlib.RegisterFactory(int(shop.SPacketID_PACKET_CS_SHOP_EXCHANGELIST), &CSShopExchangeListPacketFactory{})
|
||
// 兑换商品(非现金)
|
||
common.RegisterHandler(int(shop.SPacketID_PACKET_CS_SHOP_EXCHANGE), &CSShopExchangeHandler{})
|
||
netlib.RegisterFactory(int(shop.SPacketID_PACKET_CS_SHOP_EXCHANGE), &CSShopExchangePacketFactory{})
|
||
// 获取兑换记录
|
||
common.RegisterHandler(int(shop.SPacketID_PACKET_CS_SHOP_EXCHANGERECORD), &CSShopExchangeRecordHandler{})
|
||
netlib.RegisterFactory(int(shop.SPacketID_PACKET_CS_SHOP_EXCHANGERECORD), &CSShopExchangeRecordPacketFactory{})
|
||
|
||
// 现金,创建订单(所有现金订单)
|
||
common.RegisterHandler(int(shop.SPacketID_PACKET_CSPAYINFO), &CSPayInfoHandler{})
|
||
netlib.RegisterFactory(int(shop.SPacketID_PACKET_CSPAYINFO), &CSPayInfoPacketFactory{})
|
||
|
||
//玩家地址操作
|
||
common.RegisterHandler(int(shop.SPacketID_PACKET_CSPLAYERADDR), &CSPlayerAddrHandler{})
|
||
netlib.RegisterFactory(int(shop.SPacketID_PACKET_CSPLAYERADDR), &CSPlayerAddrPacketFactory{})
|
||
//VIP商城刷新
|
||
common.RegisterHandler(int(shop.SPacketID_PACKET_CS_UPDATE_VIP_SHOP), &CSUpdateVipShopHandler{})
|
||
netlib.RegisterFactory(int(shop.SPacketID_PACKET_CS_UPDATE_VIP_SHOP), &CSUpdateVipShopPacketFactory{})
|
||
}
|