3195 lines
106 KiB
Go
3195 lines
106 KiB
Go
package main
|
||
|
||
import (
|
||
"crypto/md5"
|
||
"encoding/hex"
|
||
"encoding/json"
|
||
"errors"
|
||
"fmt"
|
||
"io"
|
||
"reflect"
|
||
"slices"
|
||
"sort"
|
||
"strconv"
|
||
"strings"
|
||
"sync"
|
||
"time"
|
||
|
||
"mongo.games.com/goserver/core/basic"
|
||
"mongo.games.com/goserver/core/etcd"
|
||
"mongo.games.com/goserver/core/logger"
|
||
"mongo.games.com/goserver/core/netlib"
|
||
"mongo.games.com/goserver/core/task"
|
||
"mongo.games.com/goserver/core/transact"
|
||
|
||
"mongo.games.com/game/common"
|
||
"mongo.games.com/game/model"
|
||
"mongo.games.com/game/mq"
|
||
"mongo.games.com/game/proto"
|
||
"mongo.games.com/game/protocol/bag"
|
||
loginproto "mongo.games.com/game/protocol/login"
|
||
playerproto "mongo.games.com/game/protocol/player"
|
||
"mongo.games.com/game/protocol/server"
|
||
"mongo.games.com/game/protocol/shop"
|
||
webapiproto "mongo.games.com/game/protocol/webapi"
|
||
"mongo.games.com/game/srvdata"
|
||
"mongo.games.com/game/webapi"
|
||
)
|
||
|
||
const (
|
||
WebAPITransactParam_Path = iota
|
||
WebAPITransactParam_CreateTime
|
||
)
|
||
|
||
func init() {
|
||
transact.RegisteHandler(common.TransTypeWebApi, &WebAPITranscateHandler{})
|
||
}
|
||
|
||
var WebAPIHandlerMgrSingleton = &WebAPIHandlerMgr{wshMap: make(map[string]WebAPIHandler)}
|
||
|
||
type WebAPITranscateHandler struct {
|
||
}
|
||
|
||
var WebAPIStats = make(map[string]*model.APITransactStats)
|
||
|
||
// 返利配置
|
||
//type RebateInfos struct {
|
||
// Platform string //平台名称
|
||
// RebateSwitch bool //返利开关
|
||
// RebateManState int //返利是开启个人返利 0 关闭 1 开启
|
||
// ReceiveMode int //领取方式 0实时领取 1次日领取
|
||
// NotGiveOverdue int //0不过期 1过期不给 2过期邮件给
|
||
// RebateGameCfg []*RebateGameCfg //key为"gameid"+"gamemode"
|
||
// RebateGameThirdCfg []*RebateGameThirdCfg //第三方key
|
||
// Version int //活动版本 后台控制
|
||
//}
|
||
|
||
func (this *WebAPITranscateHandler) OnExcute(tNode *transact.TransNode, ud interface{}) transact.TransExeResult {
|
||
logger.Logger.Trace("WebAPITranscateHandler.OnExcute ")
|
||
req := &common.M2GWebApiRequest{}
|
||
err := netlib.UnmarshalPacketNoPackId(ud.([]byte), req)
|
||
if err == nil {
|
||
wsh := WebAPIHandlerMgrSingleton.GetWebAPIHandler(req.Path)
|
||
if wsh == nil {
|
||
logger.Logger.Trace("WebAPITranscateHandler no registe WebAPIHandler ", req.Path)
|
||
return transact.TransExeResult_Failed
|
||
}
|
||
|
||
tNode.TransEnv.SetField(WebAPITransactParam_Path, req.Path)
|
||
tNode.TransEnv.SetField(WebAPITransactParam_CreateTime, time.Now())
|
||
|
||
tag, msg := wsh.Handler(tNode, req.Body)
|
||
tNode.TransRep.RetFiels = msg
|
||
switch tag {
|
||
case common.ResponseTag_Ok:
|
||
return transact.TransExeResult_Success
|
||
case common.ResponseTag_TransactYield:
|
||
return transact.TransExeResult_Yield
|
||
}
|
||
}
|
||
logger.Logger.Trace("WebAPITranscateHandler.OnExcute err:", err)
|
||
return transact.TransExeResult_Failed
|
||
}
|
||
|
||
func (this *WebAPITranscateHandler) OnCommit(tNode *transact.TransNode) transact.TransExeResult {
|
||
logger.Logger.Trace("WebAPITranscateHandler.OnCommit ")
|
||
paramPath := tNode.TransEnv.GetField(WebAPITransactParam_Path)
|
||
paramCreateTime := tNode.TransEnv.GetField(WebAPITransactParam_CreateTime)
|
||
if path, ok := paramPath.(string); ok {
|
||
var stats *model.APITransactStats
|
||
var exist bool
|
||
if stats, exist = WebAPIStats[path]; !exist {
|
||
stats = &model.APITransactStats{}
|
||
WebAPIStats[path] = stats
|
||
}
|
||
|
||
if stats != nil {
|
||
stats.RunTimes++
|
||
runingTime := int64(time.Now().Sub(paramCreateTime.(time.Time)) / time.Millisecond)
|
||
if runingTime > stats.MaxRuningTime {
|
||
stats.MaxRuningTime = runingTime
|
||
}
|
||
stats.TotalRuningTime += runingTime
|
||
stats.SuccessTimes++
|
||
}
|
||
}
|
||
return transact.TransExeResult_Success
|
||
}
|
||
|
||
func (this *WebAPITranscateHandler) OnRollBack(tNode *transact.TransNode) transact.TransExeResult {
|
||
logger.Logger.Trace("WebAPITranscateHandler.OnRollBack ")
|
||
paramPath := tNode.TransEnv.GetField(WebAPITransactParam_Path)
|
||
paramCreateTime := tNode.TransEnv.GetField(WebAPITransactParam_CreateTime)
|
||
if path, ok := paramPath.(string); ok {
|
||
var stats *model.APITransactStats
|
||
var exist bool
|
||
if stats, exist = WebAPIStats[path]; !exist {
|
||
stats = &model.APITransactStats{}
|
||
WebAPIStats[path] = stats
|
||
}
|
||
|
||
if stats != nil {
|
||
stats.RunTimes++
|
||
runingTime := int64(time.Now().Sub(paramCreateTime.(time.Time)) / time.Millisecond)
|
||
if runingTime > stats.MaxRuningTime {
|
||
stats.MaxRuningTime = runingTime
|
||
}
|
||
stats.TotalRuningTime += runingTime
|
||
stats.FailedTimes++
|
||
}
|
||
}
|
||
return transact.TransExeResult_Success
|
||
}
|
||
|
||
func (this *WebAPITranscateHandler) OnChildTransRep(tNode *transact.TransNode, hChild transact.TransNodeID, retCode int,
|
||
ud interface{}) transact.TransExeResult {
|
||
logger.Logger.Trace("WebAPITranscateHandler.OnChildTransRep ")
|
||
return transact.TransExeResult_Success
|
||
}
|
||
|
||
type WebAPIHandler interface {
|
||
Handler(*transact.TransNode, []byte) (int, proto.Message)
|
||
}
|
||
|
||
type WebAPIHandlerWrapper func(*transact.TransNode, []byte) (int, proto.Message)
|
||
|
||
func (wshw WebAPIHandlerWrapper) Handler(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
return wshw(tNode, params)
|
||
}
|
||
|
||
type WebAPIHandlerMgr struct {
|
||
wshMap map[string]WebAPIHandler
|
||
DataWaitList sync.Map
|
||
}
|
||
|
||
func (this *WebAPIHandlerMgr) RegisteWebAPIHandler(name string, wsh WebAPIHandler) {
|
||
this.wshMap[name] = wsh
|
||
}
|
||
|
||
func (this *WebAPIHandlerMgr) GetWebAPIHandler(name string) WebAPIHandler {
|
||
if wsh, exist := this.wshMap[name]; exist {
|
||
return wsh
|
||
}
|
||
return nil
|
||
}
|
||
|
||
func init() {
|
||
// 后台加币加钻石
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Game/AddCoinByIdAndPT", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAAddCoinByIdAndPT{}
|
||
msg := &webapiproto.ASAddCoinByIdAndPT{}
|
||
err1 := proto.Unmarshal(params, msg)
|
||
if err1 != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err1.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
member_snid := msg.GetID()
|
||
billNo := int(msg.GetBillNo())
|
||
platform := msg.GetPlatform()
|
||
|
||
if CacheDataMgr.CacheBillCheck(billNo, platform) {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "Bill number repeated!"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
CacheDataMgr.CacheBillNumber(billNo, platform) //防止手抖点两下
|
||
player := PlayerMgrSington.GetPlayerBySnId(member_snid)
|
||
|
||
var remainNum int64
|
||
var addcoin, diamond int64 = msg.GetGold(), 0
|
||
var logtype = int32(common.GainWay_API_AddCoin)
|
||
if msg.GetLogType() == 1 {
|
||
addcoin = 0
|
||
diamond = msg.GetGold()
|
||
}
|
||
money := msg.Money
|
||
//玩家在线
|
||
if player != nil {
|
||
if msg.GetLogType() == 1 {
|
||
remainNum = player.Diamond
|
||
} else {
|
||
remainNum = player.Coin
|
||
}
|
||
//玩家在游戏内
|
||
if player.scene != nil {
|
||
CacheDataMgr.ClearCacheBill(billNo, platform)
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "Unsupported!!! because player in scene!"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
if len(platform) > 0 && player.Platform != platform {
|
||
CacheDataMgr.ClearCacheBill(billNo, platform)
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "player platform forbit!"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
if player.Coin+addcoin < 0 || player.Diamond+diamond < 0 {
|
||
CacheDataMgr.ClearCacheBill(billNo, platform)
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "coin not enough!"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
//增加帐变记录
|
||
coinlogex := model.NewCoinLogEx(&model.CoinLogParam{
|
||
Platform: player.Platform,
|
||
SnID: player.SnId,
|
||
Channel: player.Channel,
|
||
ChangeType: msg.GetLogType(),
|
||
ChangeNum: msg.GetGold(),
|
||
RemainNum: remainNum + msg.GetGold(),
|
||
Add: 0,
|
||
LogType: logtype,
|
||
GameID: 0,
|
||
GameFreeID: 0,
|
||
BaseCoin: 0,
|
||
Operator: msg.GetOper(),
|
||
Remark: msg.GetDesc(),
|
||
})
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
err := model.InsertCoinLog(coinlogex)
|
||
if err != nil {
|
||
//回滚到对账日志
|
||
model.RemoveCoinLogOne(platform, coinlogex.LogId)
|
||
logger.Logger.Errorf("model.InsertCoinLogs err:%v log:%v", err, coinlogex)
|
||
return err
|
||
}
|
||
return nil
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
CacheDataMgr.ClearCacheBill(billNo, platform)
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "success."
|
||
if data != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = data.(error).Error()
|
||
} else {
|
||
player.Coin += addcoin
|
||
player.Diamond += diamond
|
||
if addcoin+diamond > 0 {
|
||
player.UpdateShopID(msg.GetShopId())
|
||
}
|
||
if money > 0 {
|
||
player.AddMoneyPayTotal(money)
|
||
TaskSubjectSingleton.Touch(common.TaskTypePay, &TaskData{
|
||
SnId: player.SnId,
|
||
Num: money,
|
||
})
|
||
InviteTask(msg.Platform, player.PSnId, player.SnId, common.InviteScoreTypePay, money)
|
||
}
|
||
player.SendDiffData()
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}), "AddCoinByIdAndPT").Start()
|
||
} else {
|
||
//玩家不在线
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
findPlayer, _ := model.GetPlayerDataBySnId(platform, int32(member_snid), false, true)
|
||
if findPlayer != nil {
|
||
if len(platform) > 0 && findPlayer.Platform != platform {
|
||
CacheDataMgr.ClearCacheBill(billNo, platform)
|
||
pack.Msg = "player platform forbit!"
|
||
return nil
|
||
}
|
||
if findPlayer.Coin+addcoin < 0 || findPlayer.Diamond+diamond < 0 {
|
||
CacheDataMgr.ClearCacheBill(billNo, platform)
|
||
pack.Msg = "coin not enough!"
|
||
return nil
|
||
}
|
||
|
||
// 首次购买现金商品,获得翻倍;标记商品已经购买过
|
||
if addcoin+diamond > 0 {
|
||
if m := ShopMgrSington.GetConfig(platform).ShopInfos; m != nil {
|
||
if shopInfo, ok := m[msg.GetShopId()]; ok && shopInfo != nil {
|
||
if shopInfo.FirstSwitch {
|
||
if !slices.Contains(findPlayer.ShopID, int(msg.GetShopId())) {
|
||
findPlayer.ShopID = append(findPlayer.ShopID, int(msg.GetShopId()))
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if msg.GetLogType() == 1 {
|
||
remainNum = findPlayer.Diamond
|
||
} else {
|
||
remainNum = findPlayer.Coin
|
||
}
|
||
|
||
//增加帐变记录
|
||
coinlogex := model.NewCoinLogEx(&model.CoinLogParam{
|
||
Platform: findPlayer.Platform,
|
||
SnID: findPlayer.SnId,
|
||
Channel: findPlayer.Channel,
|
||
ChangeType: msg.GetLogType(),
|
||
ChangeNum: msg.GetGold(),
|
||
RemainNum: remainNum + msg.GetGold(),
|
||
Add: 0,
|
||
LogType: logtype,
|
||
GameID: 0,
|
||
GameFreeID: 0,
|
||
BaseCoin: 0,
|
||
Operator: msg.GetOper(),
|
||
Remark: msg.GetDesc(),
|
||
})
|
||
|
||
err := model.UpdatePlayerCoin(findPlayer.Platform, findPlayer.SnId, findPlayer.Coin+addcoin,
|
||
findPlayer.Diamond+diamond, findPlayer.SafeBoxCoin, findPlayer.CoinPayTs, findPlayer.SafeBoxCoinTs, findPlayer.MoneyPayTotal+money, findPlayer.ShopID)
|
||
if err != nil {
|
||
logger.Logger.Errorf("model.UpdatePlayerCoin err:%v.", err)
|
||
return nil
|
||
}
|
||
|
||
// 充值金额记录
|
||
if money > 0 {
|
||
err = model.InsertDbShopLog(model.NewDbShop(findPlayer.Platform, ShopPageBackend, nil, "", 0, 0, int32(money),
|
||
0, nil, 0, "", findPlayer.SnId, 3, "后台离线加币", nil))
|
||
if err != nil {
|
||
logger.Logger.Errorf("model.InsertDbShopLog err:%v.", err)
|
||
return nil
|
||
}
|
||
InviteTask(msg.Platform, findPlayer.PSnId, findPlayer.SnId, common.InviteScoreTypePay, money)
|
||
}
|
||
|
||
//账变记录
|
||
err = model.InsertCoinLog(coinlogex)
|
||
if err != nil {
|
||
//回滚到对账日志
|
||
model.RemoveCoinLogOne(platform, coinlogex.LogId)
|
||
logger.Logger.Errorf("model.InsertCoinLogs err:%v log:%v", err, coinlogex)
|
||
return err
|
||
}
|
||
}
|
||
return findPlayer
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
if data == nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
if pack.Msg == "" {
|
||
pack.Msg = "Player not find."
|
||
}
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "success."
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}), "AddCoinByIdAndPT").Start()
|
||
|
||
}
|
||
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
// 后台重置游戏池
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Game/ResetGamePool", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAResetGamePool{}
|
||
msg := &webapiproto.ASResetGamePool{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
if msg.GameFreeId == 0 {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "GameFreeId id zero"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
gs := GameSessMgrSington.GetGameSess(int(msg.ServerId))
|
||
if gs != nil {
|
||
msg := &server.WGResetCoinPool{
|
||
Platform: proto.String(msg.GetPlatform()),
|
||
GameFreeId: proto.Int32(msg.GameFreeId),
|
||
ServerId: proto.Int32(msg.ServerId),
|
||
GroupId: proto.Int32(msg.GroupId),
|
||
PoolType: proto.Int32(msg.PoolType),
|
||
Value: proto.Int64(msg.Value),
|
||
}
|
||
proto.SetDefaults(msg)
|
||
gs.Send(int(server.SSPacketID_PACKET_WG_RESETCOINPOOL), msg)
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "no find srvId"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "reset game pool success"
|
||
return common.ResponseTag_Ok, pack
|
||
}))
|
||
|
||
// 更新水池
|
||
// 修改本地缓存,修改数据库,同步到gamesrv
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Game/UpdateGamePool", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAUpdateGamePool{}
|
||
msg := &webapiproto.ASUpdateGamePool{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
coinPoolSetting := msg.GetCoinPoolSetting()
|
||
if coinPoolSetting == nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "GetCoinPoolSetting is nil"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
var old *model.CoinPoolSetting
|
||
cps := model.GetCoinPoolSetting(msg.GetGameFreeId(), msg.GetServerId(), msg.GetGroupId(), msg.GetPlatform())
|
||
if cps == nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "CoinPoolSettingDatas is nil"
|
||
return common.ResponseTag_NoData, pack
|
||
}
|
||
temp := *cps
|
||
old = &temp
|
||
// 修改worldsrv中的水池配置
|
||
cps.InitValue = coinPoolSetting.GetInitValue()
|
||
cps.LowerLimit = coinPoolSetting.GetLowerLimit()
|
||
cps.UpperLimit = coinPoolSetting.GetUpperLimit()
|
||
cps.QuDu = coinPoolSetting.GetQuDu()
|
||
cps.UpperOdds = coinPoolSetting.GetUpperOdds()
|
||
cps.UpperOddsMax = coinPoolSetting.GetUpperOddsMax()
|
||
cps.LowerOdds = coinPoolSetting.GetLowerOdds()
|
||
cps.LowerOddsMax = coinPoolSetting.GetLowerOddsMax()
|
||
cps.ProfitRate = coinPoolSetting.GetProfitRate()
|
||
cps.ResetTime = coinPoolSetting.GetResetTime()
|
||
cps.Switch = coinPoolSetting.GetSwitch()
|
||
cps.InitNoviceValue = coinPoolSetting.GetInitNoviceValue()
|
||
cps.CtrlRate = coinPoolSetting.GetCtrlRate()
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
// 新配置更新到user_coinpoolsetting,旧配置保存到log_coinpoolsetting
|
||
return model.UpsertCoinPoolSetting(cps, old)
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, task task.Task) {
|
||
if data != nil {
|
||
logger.Logger.Errorf("model.UpsertCoinPoolSetting cps:%v err:%v", cps, data)
|
||
}
|
||
}), "UpsertCoinPoolSetting").Start()
|
||
// 水池配置同步到gamesrv
|
||
gs := GameSessMgrSington.GetGameSess(int(cps.ServerId))
|
||
if gs != nil {
|
||
var msg = &webapiproto.CoinPoolSetting{
|
||
Platform: cps.Platform,
|
||
GroupId: cps.GroupId,
|
||
GameFreeId: cps.GameFreeId,
|
||
ServerId: cps.ServerId,
|
||
InitValue: cps.InitValue,
|
||
LowerLimit: cps.LowerLimit,
|
||
UpperLimit: cps.UpperLimit,
|
||
QuDu: cps.QuDu,
|
||
UpperOdds: cps.UpperOdds,
|
||
UpperOddsMax: cps.UpperOddsMax,
|
||
LowerOdds: cps.LowerOdds,
|
||
LowerOddsMax: cps.LowerOddsMax,
|
||
ProfitRate: cps.ProfitRate,
|
||
ResetTime: cps.ResetTime,
|
||
Switch: cps.Switch,
|
||
CtrlRate: cps.CtrlRate,
|
||
InitNoviceValue: cps.InitNoviceValue,
|
||
}
|
||
proto.SetDefaults(msg)
|
||
gs.Send(int(server.SSPacketID_PACKET_WG_COINPOOLSETTING), msg)
|
||
}
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "update game pool success"
|
||
return common.ResponseTag_Ok, pack
|
||
}))
|
||
|
||
//查询水池gameid
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Game/QueryGamePoolByGameId", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAQueryGamePoolByGameId{}
|
||
msg := &webapiproto.ASQueryGamePoolByGameId{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
StartQueryCoinPoolTransact(tNode, msg.GetGameId(), msg.GetGameMode(), msg.GetPlatform(), msg.GetGroupId())
|
||
return common.ResponseTag_TransactYield, nil
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Cache/GetRoom", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAGetRoom{}
|
||
msg := &webapiproto.ASGetRoom{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
roomId := int(msg.GetSceneId())
|
||
snid := msg.GetSnId()
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
if roomId == 0 {
|
||
if snid != 0 {
|
||
p := PlayerMgrSington.GetPlayerBySnId(snid)
|
||
if p != nil && p.scene != nil {
|
||
roomId = p.scene.sceneId
|
||
}
|
||
}
|
||
}
|
||
s := SceneMgrSingleton.GetScene(roomId)
|
||
if s == nil {
|
||
pack.Msg = "no found"
|
||
return common.ResponseTag_NoData, pack
|
||
} else {
|
||
gameFreeId := int32(0)
|
||
if s.dbGameFree != nil {
|
||
gameFreeId = s.dbGameFree.GetId()
|
||
}
|
||
si := &webapiproto.RoomInfo{
|
||
Platform: s.platform.Name,
|
||
SceneId: int32(s.sceneId),
|
||
GameId: int32(s.gameId),
|
||
GameMode: int32(s.gameMode),
|
||
SceneMode: int32(s.sceneMode),
|
||
GroupId: s.groupId,
|
||
GameFreeId: gameFreeId,
|
||
Creator: s.creator,
|
||
ReplayCode: s.replayCode,
|
||
Params: common.CopySliceInt64ToInt32(s.params),
|
||
PlayerCnt: int32(len(s.players) - s.robotNum),
|
||
RobotCnt: int32(s.robotNum),
|
||
CreateTime: s.createTime.Unix(),
|
||
BaseScore: s.dbGameFree.BaseScore,
|
||
}
|
||
if common.IsLocalGame(s.gameId) {
|
||
si.BaseScore = s.BaseScore
|
||
}
|
||
if s.starting {
|
||
si.Start = 1
|
||
} else {
|
||
si.Start = 0
|
||
}
|
||
if s.gameSess != nil {
|
||
si.SrvId = s.gameSess.GetSrvId()
|
||
}
|
||
cnt := 0
|
||
total := len(s.players)
|
||
robots := []int32{}
|
||
//优先显示玩家
|
||
for id, p := range s.players {
|
||
if !p.IsRob || total < 10 {
|
||
si.PlayerIds = append(si.PlayerIds, id)
|
||
cnt++
|
||
} else {
|
||
robots = append(robots, id)
|
||
}
|
||
if cnt > 10 {
|
||
break
|
||
}
|
||
}
|
||
//不够再显示机器人
|
||
if total > cnt && cnt < 10 && len(robots) != 0 {
|
||
for i := 0; cnt < 10 && i < len(robots); i++ {
|
||
si.PlayerIds = append(si.PlayerIds, robots[i])
|
||
cnt++
|
||
if cnt > 10 {
|
||
break
|
||
}
|
||
}
|
||
}
|
||
pack.RoomInfo = si
|
||
}
|
||
return common.ResponseTag_Ok, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Cache/ListRoom", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAListRoom{}
|
||
msg := &webapiproto.ASListRoom{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
|
||
pageNo := msg.GetPageNo()
|
||
pageSize := msg.GetPageSize()
|
||
//数据校验
|
||
if pageNo == 0 {
|
||
pageNo = 1
|
||
}
|
||
if pageSize == 0 {
|
||
pageSize = 20
|
||
}
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
start := (pageNo - 1) * pageSize
|
||
end := pageNo * pageSize
|
||
roomList, count, roomSum := SceneMgrSingleton.MarshalAllRoom(msg.GetPlatform(), int(msg.GetGroupId()), int(msg.GetGameId()),
|
||
int(msg.GetGameMode()), int(msg.GetClubId()), int(msg.GetRoomType()), int(msg.GetSceneId()),
|
||
msg.GamefreeId, msg.GetSnId(), msg.GetIsCustom() == 1, msg.GetRoomConfigId(), start, end, pageSize)
|
||
if count < pageNo {
|
||
pageNo = 1
|
||
}
|
||
pack.RoomInfo = roomList
|
||
pack.PageCount = count
|
||
pack.PageNo = pageNo
|
||
pack.TotalList = roomSum
|
||
return common.ResponseTag_Ok, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Cache/DestroyRoom", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SADestroyRoom{}
|
||
msg := &webapiproto.ASDestroyRoom{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
platform := msg.GetPlatform()
|
||
if len(platform) == 0 {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "the platform is nil"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
switch msg.DestroyType {
|
||
case 1: //删除所有空房间
|
||
for _, s := range SceneMgrSingleton.scenes {
|
||
if !s.IsPlatform(platform) {
|
||
continue
|
||
}
|
||
if s != nil && !s.deleting && len(s.players) == 0 {
|
||
logger.Logger.Warnf("WebService SpecailEmptySceneId destroyroom scene:%v", s.sceneId)
|
||
s.SendGameDestroy(false)
|
||
}
|
||
}
|
||
case 2: //删除所有未开始的房间
|
||
for _, s := range SceneMgrSingleton.scenes {
|
||
if !s.IsPlatform(platform) {
|
||
continue
|
||
}
|
||
if s != nil && !s.deleting && !s.starting && !s.IsHundredScene() {
|
||
logger.Logger.Warnf("WebService SpecailUnstartSceneId destroyroom scene:%v", s.sceneId)
|
||
s.TryForceDeleteMatchInfo()
|
||
s.SendGameDestroy(false)
|
||
}
|
||
}
|
||
default: //删除指定房间
|
||
if len(msg.SceneIds) == 0 {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "the sceneid is nil"
|
||
return common.ResponseTag_NoFindRoom, pack
|
||
}
|
||
for _, sceneId := range msg.GetSceneIds() {
|
||
s := SceneMgrSingleton.GetScene(int(sceneId))
|
||
if s == nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "the sceneid is nil"
|
||
return common.ResponseTag_NoFindRoom, pack
|
||
}
|
||
if !s.IsPlatform(platform) {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "the sceneid is not ower platform"
|
||
return common.ResponseTag_NoFindRoom, pack
|
||
}
|
||
logger.Logger.Warnf("WebService destroyroom scene:%v", s.sceneId)
|
||
s.TryForceDeleteMatchInfo()
|
||
s.SendGameDestroy(false)
|
||
}
|
||
}
|
||
return common.ResponseTag_Ok, pack
|
||
}))
|
||
|
||
///////////////////////////玩家信息///////////////////////////
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Player/PlayerData", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAGetPlayerData{}
|
||
msg := &webapiproto.ASGetPlayerData{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
id := msg.GetID()
|
||
platform := msg.GetPlatform()
|
||
player := PlayerMgrSington.GetPlayerBySnId(id)
|
||
var playerRankScore *model.PlayerRankSeason
|
||
var playerBagInfo *model.BagInfo
|
||
if player == nil {
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
data, _ := model.GetPlayerDataBySnId(platform, id, true, false)
|
||
if data == nil || data.SnId == 0 {
|
||
data = model.GetDelBackupPlayerData(platform, id)
|
||
}
|
||
ret, _ := model.FindPlayerRankSeason(&model.FindPlayerRankSeasonArgs{
|
||
Platform: platform,
|
||
Id: []int32{id},
|
||
})
|
||
if len(ret.List) > 0 {
|
||
playerRankScore = ret.List[0]
|
||
}
|
||
playerBagInfo, _ = model.GetBagInfo(id, platform)
|
||
return data
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
playerData, ok := data.(*model.PlayerData)
|
||
if !ok || playerData == nil {
|
||
pack.Msg = "no find player"
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pdfw := model.ConvertPlayerDataToWebData(getPlayerDataParam(&playerDataParam{
|
||
P: playerData,
|
||
Season: playerRankScore,
|
||
Items: playerBagInfo,
|
||
}))
|
||
|
||
pdfw.Online = false
|
||
pack.PlayerData = pdfw
|
||
}
|
||
logger.Logger.Trace("PlayerData==>", pack)
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}), "PlayerData").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
} else {
|
||
if len(platform) > 0 && player.Platform == platform {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pwdf := model.ConvertPlayerDataToWebData(getPlayerDataParam(&playerDataParam{player.PlayerData, nil, nil}))
|
||
pwdf.Online = player.IsOnLine()
|
||
if pwdf != nil {
|
||
if player.scene != nil && player.scene.sceneId != common.DgSceneId && !player.scene.IsTestScene() {
|
||
pwdf.Coin = player.sceneCoin
|
||
}
|
||
}
|
||
pack.PlayerData = pwdf
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "no find player"
|
||
}
|
||
logger.Logger.Trace("PlayerData==>", pack)
|
||
return common.ResponseTag_Ok, pack
|
||
}
|
||
}))
|
||
//多个玩家数据
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Player/MorePlayerData", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAMorePlayerData{}
|
||
msg := &webapiproto.ASMorePlayerData{}
|
||
err := proto.Unmarshal(params, msg)
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
if err != nil {
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
if len(msg.GetSnIds()) == 0 {
|
||
pack.Msg = "IDs value error!"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
if len(msg.GetSnIds()) > model.GameParamData.MorePlayerLimit {
|
||
pack.Msg = "IDs too more error!"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
var leavePlayer []int32
|
||
var playerRankScore = map[int32]*model.PlayerRankSeason{}
|
||
var playerItems = map[int32]*model.BagInfo{}
|
||
for _, snid := range msg.GetSnIds() {
|
||
player := PlayerMgrSington.GetPlayerBySnId(snid)
|
||
if player != nil {
|
||
pwdf := model.ConvertPlayerDataToWebData(getPlayerDataParam(&playerDataParam{player.PlayerData, nil, nil}))
|
||
if pwdf != nil {
|
||
pwdf.Online = true
|
||
if player.scene != nil && player.scene.sceneId != common.DgSceneId {
|
||
pwdf.Coin = player.sceneCoin
|
||
}
|
||
pack.PlayerData = append(pack.PlayerData, pwdf)
|
||
}
|
||
} else {
|
||
leavePlayer = append(leavePlayer, snid)
|
||
}
|
||
}
|
||
if len(leavePlayer) == 0 {
|
||
return common.ResponseTag_Ok, pack
|
||
}
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
ret, _ := model.FindPlayerRankSeason(&model.FindPlayerRankSeasonArgs{
|
||
Platform: msg.GetPlatform(),
|
||
Id: leavePlayer,
|
||
})
|
||
for _, v := range ret.List {
|
||
playerRankScore[v.SnId] = v
|
||
//todo 优化
|
||
items, _ := model.GetBagInfo(v.SnId, msg.GetPlatform())
|
||
playerItems[v.SnId] = items
|
||
}
|
||
|
||
return model.GetPlayerDatasBySnIds(msg.Platform, leavePlayer, false)
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
if data != nil {
|
||
playerDatas, _ := data.([]*model.PlayerData)
|
||
for _, v := range playerDatas {
|
||
pdfw := model.ConvertPlayerDataToWebData(getPlayerDataParam(&playerDataParam{v, playerRankScore[v.SnId], playerItems[v.SnId]}))
|
||
if pdfw != nil {
|
||
pdfw.Online = false
|
||
pack.PlayerData = append(pack.PlayerData, pdfw)
|
||
}
|
||
}
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}), "PlayerData").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
//更新玩家数据
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Cache/UpdatePlayerElement", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAUpdatePlayerElement{}
|
||
msg := &webapiproto.ASUpdatePlayerElement{}
|
||
uerr := proto.Unmarshal(params, msg)
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
if uerr != nil {
|
||
pack.Msg = "数据序列化失败" + uerr.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
//简单校验接收到的数据
|
||
if msg.SnId == 0 || len(msg.GetPlayerEleArgs()) == 0 {
|
||
pack.Msg = "error: ID or ElementList is nil"
|
||
return common.ResponseTag_Ok, pack
|
||
}
|
||
|
||
playerMap := make(map[string]interface{})
|
||
for _, v := range msg.GetPlayerEleArgs() {
|
||
playerMap[v.Key] = v.Val
|
||
}
|
||
listBan := [...]string{"Id", "SnId", "AccountId"}
|
||
for i := 0; i < len(listBan); i++ {
|
||
if _, exist := playerMap[listBan[i]]; exist {
|
||
delete(playerMap, listBan[i])
|
||
}
|
||
}
|
||
if len(playerMap) == 0 {
|
||
pack.Msg = "no any data"
|
||
return common.ResponseTag_Ok, pack
|
||
}
|
||
|
||
f := func(plt string, snid int32) {
|
||
var alipayAcc, alipayAccName, bankAccount, bankAccName, channelId string
|
||
if val, ok := playerMap["AlipayAccount"]; ok {
|
||
if str, ok := val.(string); ok {
|
||
alipayAcc = str
|
||
}
|
||
}
|
||
if val, ok := playerMap["AlipayAccName"]; ok {
|
||
if str, ok := val.(string); ok {
|
||
alipayAccName = str
|
||
}
|
||
}
|
||
if val, ok := playerMap["BankAccount"]; ok {
|
||
if str, ok := val.(string); ok {
|
||
bankAccount = str
|
||
}
|
||
}
|
||
if val, ok := playerMap["BankAccName"]; ok {
|
||
if str, ok := val.(string); ok {
|
||
bankAccName = str
|
||
}
|
||
}
|
||
if val, ok := playerMap["ChannelId"]; ok {
|
||
if str, ok := val.(string); ok {
|
||
channelId = str
|
||
}
|
||
}
|
||
|
||
if alipayAcc != "" || alipayAccName != "" {
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
model.NewBankBindLog(msg.SnId, msg.Platform, model.BankBindLogType_Ali,
|
||
alipayAccName, alipayAcc, 2)
|
||
return nil
|
||
}), nil, "NewBankBindLog").Start()
|
||
}
|
||
if bankAccount != "" || bankAccName != "" {
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
model.NewBankBindLog(msg.SnId, msg.Platform, model.BankBindLogType_Bank,
|
||
bankAccName, bankAccount, 2)
|
||
return nil
|
||
}), nil, "NewBankBindLog").Start()
|
||
}
|
||
if channelId != "" {
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
a, err := model.GetAccountBySnid(plt, snid)
|
||
if err != nil {
|
||
logger.Logger.Errorf("GetAccountBySnid error: %v", err)
|
||
return nil
|
||
}
|
||
a.ChannelId = channelId
|
||
if err = model.UpdateAccount(a); err != nil {
|
||
logger.Logger.Errorf("UpdateAccount error: %v", err)
|
||
}
|
||
return nil
|
||
}), nil).StartByExecutor("UpdateChannelId")
|
||
}
|
||
}
|
||
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
player := PlayerMgrSington.GetPlayerBySnId(msg.SnId)
|
||
if player != nil {
|
||
if len(msg.Platform) > 0 && player.Platform != msg.Platform {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "Platform error."
|
||
return common.ResponseTag_NoFindUser, pack
|
||
} else {
|
||
//玩家在线
|
||
//获取玩家数据
|
||
var pd *model.PlayerData
|
||
pd = player.PlayerData
|
||
SetInfo := func(u *model.PlayerData, o interface{}, playerMap map[string]interface{}) *model.PlayerData {
|
||
t := reflect.TypeOf(o)
|
||
v := reflect.ValueOf(o)
|
||
s := reflect.ValueOf(u).Elem()
|
||
for k, n := range playerMap {
|
||
if f, ok := t.FieldByName(k); ok {
|
||
if v.FieldByName(k).CanInterface() {
|
||
switch f.Type.Kind() {
|
||
case reflect.Int64, reflect.Int32:
|
||
a, _ := strconv.ParseInt(fmt.Sprintf("%v", n), 10, 64)
|
||
s.FieldByName(k).SetInt(a)
|
||
case reflect.Bool:
|
||
s.FieldByName(k).SetBool(n.(bool))
|
||
case reflect.String:
|
||
s.FieldByName(k).SetString(n.(string))
|
||
default:
|
||
logger.Logger.Warn("type not in the player !!")
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return u
|
||
}
|
||
pd = SetInfo(pd, *pd, playerMap)
|
||
player.dirty = true
|
||
player.SendDiffData()
|
||
pack.Msg = "success"
|
||
f(pd.Platform, pd.SnId)
|
||
return common.ResponseTag_Ok, pack
|
||
}
|
||
} else {
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
//玩家不在线
|
||
//先检测是否有玩家
|
||
if len(msg.Platform) > 0 {
|
||
pbi := model.GetPlayerBaseInfo(msg.Platform, msg.SnId)
|
||
if pbi == nil {
|
||
return errors.New("no player")
|
||
}
|
||
}
|
||
//直接操作数据库
|
||
err := model.UpdatePlayerElement(msg.Platform, msg.SnId, playerMap)
|
||
if err == nil {
|
||
f(msg.Platform, msg.SnId)
|
||
} else if err != nil {
|
||
logger.Logger.Error("UpdatePlayerElement task marshal data error:", err)
|
||
}
|
||
return err
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
if data == nil {
|
||
pack.Msg = "success"
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = fmt.Sprintf("%v", data)
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}), "UpdatePlayerElement").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Player/KickPlayer", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAKickPlayer{}
|
||
msg := &webapiproto.ASKickPlayer{}
|
||
err := proto.Unmarshal(params, msg)
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
if err != nil {
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
if msg.SnId == 0 {
|
||
pack.Msg = "snid is zero"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
player := PlayerMgrSington.GetPlayerBySnId(msg.SnId)
|
||
if player != nil {
|
||
if msg.Platform == "" || msg.Platform != player.Platform {
|
||
pack.Msg = "platform is dif"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
sid := player.sid
|
||
endTime := time.Now().Unix() + int64(time.Minute.Seconds())*int64(msg.Minute)
|
||
ls := LoginStateMgrSington.GetLoginStateBySid(sid)
|
||
if ls != nil {
|
||
if ls.als != nil && ls.als.acc != nil {
|
||
ls.als.acc.State = endTime
|
||
}
|
||
}
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
return model.FreezeAccount(msg.Platform, player.AccountId, int(msg.Minute))
|
||
}), nil, "FreezeAccount").Start()
|
||
player.Kick(common.KickReason_Freeze)
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "success"
|
||
} else {
|
||
pack.Msg = "the player not online or no player."
|
||
}
|
||
return common.ResponseTag_Ok, pack
|
||
}))
|
||
//获取在线统计
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Report/OnlineReportTotal", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAOnlineReportTotal{}
|
||
msg := &webapiproto.ASOnlineReportTotal{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
//inGameCnt := make(map[int]int32)
|
||
pack.OnlineReport = &webapiproto.OnlineReport{}
|
||
tNow := time.Now()
|
||
for _, p := range PlayerMgrSington.players {
|
||
if !p.IsOnLine() {
|
||
continue
|
||
}
|
||
if len(msg.Platform) != 0 && msg.Platform != "0" && p.Platform != msg.Platform {
|
||
continue
|
||
}
|
||
if len(msg.Channel) != 0 && p.Channel != msg.Channel {
|
||
continue
|
||
}
|
||
if len(msg.Promoter) != 0 && p.BeUnderAgentCode != msg.Promoter {
|
||
continue
|
||
}
|
||
pack.OnlineReport.TotalCnt++
|
||
if p.DeviceOS == common.DeviceOS_Android {
|
||
pack.OnlineReport.AndroidOnlineCnt++
|
||
} else if p.DeviceOS == common.DeviceOS_IOS {
|
||
pack.OnlineReport.IosOnlineCnt++
|
||
}
|
||
if p.scene == nil {
|
||
pack.OnlineReport.DatingPlayers++
|
||
} else {
|
||
pack.OnlineReport.OnRoomPlayers++
|
||
//inGameCnt[p.scene.gameId]++
|
||
}
|
||
if common.InSameDay(p.CreateTime, tNow) {
|
||
pack.OnlineReport.TodayRegisterOnline++
|
||
} else {
|
||
if common.DiffDay(tNow, p.CreateTime) <= 7 {
|
||
pack.OnlineReport.SevenDayRegisterOnline++
|
||
}
|
||
}
|
||
}
|
||
//var onlineGameCnt []*webapi_proto.OnlineGameCnt
|
||
//for gameId, cnt := range inGameCnt {
|
||
// onlineGameCnt = append(onlineGameCnt, &webapi_proto.OnlineGameCnt{
|
||
// GameId: int32(gameId),
|
||
// Cnt: cnt},
|
||
// )
|
||
//}
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
//pack.OnlineReport.GameCount = onlineGameCnt
|
||
return common.ResponseTag_Ok, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Report/QueryOnlineReportList", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAQueryOnlineReportList{}
|
||
msg := &webapiproto.ASQueryOnlineReportList{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
pageNo := msg.PageNo
|
||
pageSize := msg.PageSize
|
||
orderColumn := msg.OrderColumn
|
||
orderType := msg.OrderType
|
||
|
||
start := (pageNo - 1) * pageSize
|
||
end := pageNo * pageSize
|
||
count := len(PlayerMgrSington.players)
|
||
if count < int(start) || count == 0 {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
return common.ResponseTag_Ok, pack
|
||
}
|
||
var players []*Player
|
||
for _, p := range PlayerMgrSington.players {
|
||
if !p.IsOnLine() {
|
||
continue
|
||
}
|
||
if msg.GameDif != "" {
|
||
if p.scene == nil || p.scene.dbGameFree.GetGameDif() != msg.GameDif {
|
||
continue
|
||
}
|
||
}
|
||
if msg.ChannelId != "" {
|
||
if p.ChannelId != msg.ChannelId {
|
||
continue
|
||
}
|
||
}
|
||
if msg.GameFreeId > 0 {
|
||
if p.scene == nil || p.scene.GetGameFreeId() != msg.GameFreeId {
|
||
continue
|
||
}
|
||
}
|
||
if msg.GameId > 0 {
|
||
if p.scene == nil || p.scene.gameId != int(msg.GameId) {
|
||
continue
|
||
}
|
||
}
|
||
|
||
if msg.Platform != DefaultPlatform && msg.Platform != "" {
|
||
if p.Platform != msg.Platform {
|
||
continue
|
||
}
|
||
}
|
||
|
||
if msg.Channel != "" && p.Channel != msg.Channel {
|
||
continue
|
||
}
|
||
|
||
players = append(players, p)
|
||
}
|
||
// 排序
|
||
var sortFunc func(i, j int) bool
|
||
switch orderColumn {
|
||
case common.OrderColumnCoinPayTotal:
|
||
sortFunc = func(i, j int) bool {
|
||
if players[i].CoinPayTotal == players[j].CoinPayTotal {
|
||
return false
|
||
}
|
||
return players[i].CoinPayTotal > players[j].CoinPayTotal
|
||
}
|
||
case common.OrderColumnCoinExchangeTotal:
|
||
sortFunc = func(i, j int) bool {
|
||
if players[i].CoinExchangeTotal == players[j].CoinExchangeTotal {
|
||
return false
|
||
}
|
||
return players[i].CoinExchangeTotal > players[j].CoinExchangeTotal
|
||
}
|
||
case common.OrderColumnTaxTotal:
|
||
sortFunc = func(i, j int) bool {
|
||
if players[i].GameTax == players[j].GameTax {
|
||
return false
|
||
}
|
||
return players[i].GameTax > players[j].GameTax
|
||
}
|
||
case common.OrderColumnRegisterTime:
|
||
sortFunc = func(i, j int) bool {
|
||
if players[i].CreateTime.Equal(players[j].CreateTime) {
|
||
return false
|
||
}
|
||
return players[i].CreateTime.After(players[j].CreateTime)
|
||
}
|
||
case common.OrderColumnRoomNumber:
|
||
sortFunc = func(i, j int) bool {
|
||
a, b := players[i], players[j]
|
||
if a.scene == nil && b.scene == nil {
|
||
return false
|
||
}
|
||
if a.scene != nil && b.scene == nil {
|
||
return true
|
||
}
|
||
if a.scene == nil && b.scene != nil {
|
||
return false
|
||
}
|
||
if a.scene.sceneId == b.scene.sceneId {
|
||
return false
|
||
}
|
||
return a.scene.sceneId > b.scene.sceneId
|
||
}
|
||
case common.OrderColumnLose:
|
||
sortFunc = func(i, j int) bool {
|
||
if players[i].FailTimes == players[j].FailTimes {
|
||
return false
|
||
}
|
||
return players[i].FailTimes > players[j].FailTimes
|
||
}
|
||
case common.OrderColumnWin:
|
||
sortFunc = func(i, j int) bool {
|
||
if players[i].WinTimes == players[j].WinTimes {
|
||
return false
|
||
}
|
||
return players[i].WinTimes > players[j].WinTimes
|
||
}
|
||
case common.OrderColumnDraw:
|
||
sortFunc = func(i, j int) bool {
|
||
if players[i].DrawTimes == players[j].DrawTimes {
|
||
return false
|
||
}
|
||
return players[i].DrawTimes > players[j].DrawTimes
|
||
}
|
||
case common.OrderColumnWinCoin:
|
||
sortFunc = func(i, j int) bool {
|
||
if players[i].WinCoin == players[j].WinCoin {
|
||
return false
|
||
}
|
||
return players[i].WinCoin > players[j].WinCoin
|
||
}
|
||
case common.OrderColumnLoseCoin:
|
||
sortFunc = func(i, j int) bool {
|
||
if players[i].FailCoin == players[j].FailCoin {
|
||
return false
|
||
}
|
||
return players[i].FailCoin > players[j].FailCoin
|
||
}
|
||
default:
|
||
}
|
||
if sortFunc != nil {
|
||
sort.Slice(players, func(i, j int) bool {
|
||
if orderType == 0 {
|
||
return sortFunc(i, j)
|
||
}
|
||
return !sortFunc(i, j)
|
||
})
|
||
}
|
||
count = len(players)
|
||
if int(end) > count {
|
||
end = int32(count)
|
||
}
|
||
for i := start; i < end; i++ {
|
||
p := players[i]
|
||
if p != nil {
|
||
pb := model.ConvertPlayerDataToWebData(getPlayerDataParam(&playerDataParam{p.PlayerData, nil, nil}))
|
||
if p.scene != nil {
|
||
pb.GameFreeId = p.scene.dbGameFree.Id
|
||
pb.SceneId = int32(p.scene.sceneId)
|
||
}
|
||
pack.PlayerData = append(pack.PlayerData, pb)
|
||
}
|
||
}
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.PageCount = int32(count)
|
||
pack.PageNo = pageNo
|
||
pack.PageSize = pageSize
|
||
return common.ResponseTag_Ok, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Player/WhiteBlackControl", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAWhiteBlackControl{}
|
||
msg := &webapiproto.ASWhiteBlackControl{}
|
||
err := proto.Unmarshal(params, msg)
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
if err != nil {
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
//if msg.SnId == 0 {
|
||
// pack.Msg = "snid is zero"
|
||
// return common.ResponseTag_ParamError, pack
|
||
//}
|
||
idMap := make(map[int32]struct{})
|
||
if msg.SnId > 0 {
|
||
idMap[msg.SnId] = struct{}{}
|
||
}
|
||
for _, id := range msg.SnIds {
|
||
idMap[id] = struct{}{}
|
||
}
|
||
wbCoinLimit := msg.WBCoinLimit
|
||
maxNum := msg.MaxNum
|
||
resetTotalCoin := msg.ResetTotalCoin
|
||
wbState := msg.State
|
||
|
||
tNow := time.Now()
|
||
var errMsg interface{}
|
||
wg := new(sync.WaitGroup)
|
||
wg.Add(len(idMap))
|
||
for id := range idMap {
|
||
snid := id
|
||
player := PlayerMgrSington.GetPlayerBySnId(snid)
|
||
if player != nil {
|
||
if len(msg.Platform) == 0 || player.Platform == msg.Platform {
|
||
player.WBLevel = msg.WBLevel
|
||
player.WBCoinLimit = wbCoinLimit
|
||
player.WBMaxNum = maxNum
|
||
if resetTotalCoin == 1 {
|
||
player.WBCoinTotalIn = 0
|
||
player.WBCoinTotalOut = 0
|
||
}
|
||
player.WBTime = tNow
|
||
//出去比赛场
|
||
if player.scene != nil && !player.scene.IsMatchScene() {
|
||
//if !WBCtrlCfgMgr.GetRealCtrl(msg.Platform) {
|
||
// wbState = 0
|
||
//}
|
||
//同步刷到游服
|
||
wgpack := &server.WGSetPlayerBlackLevel{
|
||
SnId: proto.Int(int(snid)),
|
||
WBLevel: proto.Int32(msg.WBLevel),
|
||
WBCoinLimit: proto.Int64(wbCoinLimit),
|
||
MaxNum: proto.Int32(maxNum),
|
||
ResetTotalCoin: proto.Bool(resetTotalCoin != 0),
|
||
State: proto.Int32(wbState),
|
||
}
|
||
player.SendToGame(int(server.SSPacketID_PACKET_WG_SETPLAYERBLACKLEVEL), wgpack)
|
||
}
|
||
}
|
||
}
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
if resetTotalCoin == 1 {
|
||
//后台sql有统计这里屏蔽掉
|
||
//log := model.NewBlackWhiteCoinLog(snid, msg.WBLevel, 0, int32(resetTotalCoin), msg.Platform)
|
||
//if log != nil {
|
||
// model.InsertBlackWhiteCoinLog(log)
|
||
//}
|
||
return model.SetBlackWhiteLevel(snid, msg.WBLevel, int32(maxNum), wbState, 0, 0, wbCoinLimit, msg.Platform, tNow)
|
||
} else {
|
||
//后台sql有统计这里屏蔽掉
|
||
//log := model.NewBlackWhiteCoinLog(snid, msg.WBLevel, wbCoinLimit, int32(resetTotalCoin), msg.Platform)
|
||
//if log != nil {
|
||
// model.InsertBlackWhiteCoinLog(log)
|
||
//}
|
||
return model.SetBlackWhiteLevelUnReset(snid, msg.WBLevel, int32(maxNum), wbState, wbCoinLimit, msg.Platform, tNow)
|
||
}
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
defer wg.Done()
|
||
if data == nil {
|
||
delete(idMap, snid)
|
||
} else {
|
||
errMsg = data
|
||
}
|
||
}), "SetBlackWhiteLevel").Start()
|
||
}
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
wg.Wait()
|
||
if errMsg != nil || len(idMap) > 0 {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = fmt.Sprintf("数据库写入错误:%v , 玩家id:%v", errMsg, idMap)
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
return nil
|
||
}), nil).Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Ctrl/ListServerStates", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAListServerStates{}
|
||
msg := &webapiproto.ASListServerStates{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.ServerInfo = GameSessMgrSington.ListServerState(int(msg.SrvId), int(msg.SrvType))
|
||
return common.ResponseTag_Ok, pack
|
||
}))
|
||
|
||
//邮件
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Game/CreateShortMessage", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SACreateShortMessage{}
|
||
msg := &webapiproto.ASCreateShortMessage{}
|
||
err1 := proto.Unmarshal(params, msg)
|
||
if err1 != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err1.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
|
||
title := msg.GetNoticeTitle()
|
||
content := msg.GetNoticeContent()
|
||
platform := msg.GetPlatform()
|
||
srcSnid := msg.GetSrcSnid()
|
||
destSnid := msg.GetDestSnid()
|
||
messageType := msg.GetMessageType()
|
||
coin := msg.GetCoin()
|
||
diamond := msg.GetDiamond()
|
||
otherParams := msg.GetParams()
|
||
showId := msg.GetShowId()
|
||
channel := msg.GetOnChannelName()
|
||
if destSnid > 0 {
|
||
channel = []string{}
|
||
}
|
||
|
||
if messageType == model.MSGTYPE_ITEM && len(otherParams) != 0 && len(otherParams)%2 != 0 {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "otherParams is err"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
|
||
//由于多线程问题,次数组只能在此处和task.new 内使用,在其它地方使用会引起多线程崩溃的问题
|
||
var onlinePlayerSnid []int32
|
||
if destSnid == 0 {
|
||
for _, p := range PlayerMgrSington.snidMap {
|
||
if p.IsRob == true { //排除掉机器人
|
||
continue
|
||
}
|
||
if len(channel) > 0 && !common.InSliceString(channel, p.LastChannel) { // 渠道过滤
|
||
continue
|
||
}
|
||
if platform == "" || p.Platform == platform {
|
||
onlinePlayerSnid = append(onlinePlayerSnid, p.SnId)
|
||
}
|
||
}
|
||
}
|
||
|
||
var newMsg *model.Message
|
||
var dbMsgs []*model.Message
|
||
var err error
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
code := loginproto.OpResultCode_OPRC_Sucess
|
||
//如果不是群发则检查一下该用户snid是不是存在,不存在就返回,在这里不关心玩家帐变是否正确,不做校正
|
||
if destSnid != 0 {
|
||
playerData, _ := model.GetPlayerDataBySnId(platform, destSnid, true, false)
|
||
if playerData == nil {
|
||
code = loginproto.OpResultCode_OPRC_Error
|
||
return code
|
||
}
|
||
}
|
||
// var otherParams []int32
|
||
|
||
newMsg = model.NewMessage("", int32(srcSnid), "", int32(destSnid), int32(messageType), title, content, coin, diamond,
|
||
model.MSGSTATE_UNREAD, time.Now().Unix(), model.MSGATTACHSTATE_DEFAULT, "", common.CopySliceInt32ToInt64(otherParams), platform, showId, channel)
|
||
if newMsg != nil {
|
||
err := model.InsertMessage(platform, newMsg)
|
||
if err != nil {
|
||
code = loginproto.OpResultCode_OPRC_Error
|
||
logger.Logger.Errorf("/api/Game/CreateShortMessage,InsertMessage err:%v title:%v content:%v platform:%v srcSnid:%v destSnid:%v messageType:%v ", err, title, content, platform, srcSnid, destSnid, messageType)
|
||
return code
|
||
}
|
||
}
|
||
|
||
if destSnid == 0 {
|
||
for _, psnid := range onlinePlayerSnid {
|
||
newMsg := model.NewMessage(newMsg.Id.Hex(), newMsg.SrcId, "", psnid, newMsg.MType, newMsg.Title, newMsg.Content, newMsg.Coin, newMsg.Diamond,
|
||
newMsg.State, newMsg.CreatTs, newMsg.AttachState, newMsg.GiftId, common.CopySliceInt32ToInt64(otherParams), platform, newMsg.ShowId, channel)
|
||
if newMsg != nil {
|
||
dbMsgs = append(dbMsgs, newMsg)
|
||
}
|
||
}
|
||
if len(dbMsgs) > 0 {
|
||
err := model.InsertMessage(platform, dbMsgs...)
|
||
if err != nil {
|
||
logger.Logger.Errorf("/api/Game/CreateShortMessage,InsertMessage err:%v title:%v content:%v platform:%v srcSnid:%v destSnid:%v messageType:%v ", err, title, content, platform, srcSnid, destSnid, messageType)
|
||
}
|
||
}
|
||
}
|
||
return code
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
if code, ok := data.(loginproto.OpResultCode); ok {
|
||
if code != loginproto.OpResultCode_OPRC_Sucess {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = ""
|
||
} else {
|
||
pp := PlayerMgrSington.GetPlayerBySnId(int32(destSnid))
|
||
if pp != nil {
|
||
//单独消息
|
||
pp.AddMessage(newMsg)
|
||
} else {
|
||
if destSnid == 0 { //群发消息
|
||
MsgMgrSington.AddMsg(newMsg)
|
||
|
||
if len(platform) > 0 { //特定渠道消息
|
||
for _, m := range dbMsgs {
|
||
pp := PlayerMgrSington.GetPlayerBySnId(m.SnId)
|
||
if pp != nil && pp.Platform == platform {
|
||
pp.AddMessage(m)
|
||
}
|
||
}
|
||
} else { //全渠道消息
|
||
for _, m := range dbMsgs {
|
||
pp := PlayerMgrSington.GetPlayerBySnId(m.SnId)
|
||
if pp != nil {
|
||
pp.AddMessage(m)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = ""
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
if err != nil {
|
||
logger.Logger.Error("Marshal CreateShortMessage response data error:", err)
|
||
}
|
||
} else {
|
||
logger.Logger.Error("CreateShortMessage task result data covert failed.")
|
||
}
|
||
}), "CreateShortMessage").Start()
|
||
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
//查询邮件
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Game/QueryShortMessageList", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAQueryShortMessageList{}
|
||
msg := &webapiproto.ASQueryShortMessageList{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
startTime := msg.GetStartTime()
|
||
endTime := msg.GetEndTime()
|
||
pageNo := msg.GetPageNo()
|
||
pageSize := msg.GetPageSize()
|
||
messageType := msg.GetMessageType()
|
||
platform := msg.GetPlatform()
|
||
destSnid := msg.GetDestSnid()
|
||
if destSnid == 0 {
|
||
destSnid = -1
|
||
}
|
||
start := (pageNo - 1) * pageSize
|
||
end := pageNo * pageSize
|
||
|
||
var msgs []model.Message
|
||
var count int
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
mas := &model.MsgArgs{
|
||
Platform: platform,
|
||
StartTs: startTime,
|
||
EndTs: endTime,
|
||
ToIndex: int(end),
|
||
DestSnId: int(destSnid),
|
||
MsgType: int(messageType),
|
||
FromIndex: int(start),
|
||
}
|
||
retMsgs, err := model.GetMessageInRangeTsLimitByRange(mas)
|
||
count = retMsgs.Count
|
||
msgs = retMsgs.Msg
|
||
return err
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
if data != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = ""
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = ""
|
||
pack.Count = int32(count)
|
||
for i := 0; i < len(msgs); i++ {
|
||
giftState := int32(0)
|
||
mi := &webapiproto.MessageInfo{
|
||
Id: msgs[i].Id.Hex(),
|
||
MType: msgs[i].MType,
|
||
Title: msgs[i].Title,
|
||
Content: msgs[i].Content,
|
||
State: msgs[i].State,
|
||
CreateTime: msgs[i].CreatTs,
|
||
SrcSnid: msgs[i].SrcId,
|
||
DestSnid: msgs[i].SnId,
|
||
Coin: msgs[i].Coin,
|
||
GiftId: msgs[i].GiftId,
|
||
GiftState: giftState,
|
||
Platform: msgs[i].Platform,
|
||
}
|
||
pack.MessageInfo = append(pack.MessageInfo, mi)
|
||
}
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}), "QueryShortMessageList").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
//删除邮件
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Game/DeleteShortMessage", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SADeleteShortMessage{}
|
||
msg := &webapiproto.ASDeleteShortMessage{}
|
||
err1 := proto.Unmarshal(params, msg)
|
||
if err1 != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err1.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
msgId := msg.GetId()
|
||
platform := msg.GetPlatform()
|
||
if len(msgId) == 0 {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "not find msg id"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
var delMsg *model.Message
|
||
var err error
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
delMsg, err = model.GetMessageById(msgId, platform)
|
||
if err == nil {
|
||
if len(platform) > 0 && msg.Platform != platform {
|
||
return errors.New("Platform error.")
|
||
}
|
||
args := &model.DelMsgArgs{
|
||
Platform: platform,
|
||
Id: delMsg.Id,
|
||
}
|
||
err = model.DelMessage(args) // 真删除
|
||
}
|
||
return err
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
if data != nil || delMsg == nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "not find msg id"
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
return
|
||
}
|
||
/*if delMsg.State == model.MSGSTATE_REMOVEED {
|
||
pack.Tag = webapi_proto.TagCode_FAILED
|
||
pack.Msg = "repeate delete"
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
return
|
||
}*/
|
||
pp := PlayerMgrSington.GetPlayerBySnId(delMsg.SnId)
|
||
if pp != nil {
|
||
pp.WebDelMessage(delMsg.Id.Hex())
|
||
} else {
|
||
MsgMgrSington.RemoveMsg(delMsg)
|
||
}
|
||
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = ""
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}), "DeleteShortMessage").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
//删除玩家已经删除的邮件
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Game/DeleteAllShortMessage", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SADeleteShortMessage{}
|
||
msg := &webapiproto.ASDeleteShortMessage{}
|
||
err1 := proto.Unmarshal(params, msg)
|
||
if err1 != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err1.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
platform := msg.GetPlatform()
|
||
if len(platform) == 0 {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "platform is nil"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
return model.DelAllMessage(&model.DelAllMsgArgs{Platform: platform})
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
if data != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "del err:" + data.(error).Error()
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
return
|
||
}
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "del success."
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}), "DeleteShortMessage").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
//黑名单
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Player/BlackBySnId", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SABlackBySnId{}
|
||
msg := &webapiproto.ASBlackBySnId{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
player := PlayerMgrSington.GetPlayerBySnId(msg.SnId)
|
||
if player != nil {
|
||
if player.Platform != msg.Platform {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "Platform is dif"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
player.BlacklistType = msg.BlacklistType
|
||
player.dirty = true
|
||
player.Time2Save()
|
||
//在线需要踢掉玩家
|
||
if uint(msg.BlacklistType)&BlackState_Login != 0 {
|
||
logger.Logger.Infof("found platform:%v player:%d snid in blacklist", msg.Platform, player.SnId)
|
||
player.Kick(int32(loginproto.SSDisconnectTypeCode_SSDTC_BlackList))
|
||
}
|
||
return common.ResponseTag_Ok, pack
|
||
} else {
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
data, _ := model.GetPlayerDataBySnId(msg.Platform, msg.SnId, true, false)
|
||
if data != nil {
|
||
model.UpdatePlayerBlacklistType(msg.Platform, msg.SnId, msg.BlacklistType)
|
||
}
|
||
return data
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
playerData, ok := data.(*model.PlayerData)
|
||
if !ok || playerData == nil {
|
||
pack.Msg = "no find player"
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "success"
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}), "PlayerData").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Message/QueryHorseRaceLampList", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAQueryHorseRaceLampList{}
|
||
msg := &webapiproto.ASQueryHorseRaceLampList{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
start := (msg.PageNo - 1) * msg.PageSize
|
||
end := msg.PageNo * msg.PageSize
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
ret, erro := model.GetHorseRaceLampInRangeTsLimitByRange(msg.Platform, msg.MsgType, msg.State, start, end)
|
||
if erro != nil {
|
||
logger.Logger.Error("api GetNoticeInRangeTsLimitByRange is error", erro)
|
||
return nil
|
||
}
|
||
return ret
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
if data == nil {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "no these msg"
|
||
} else {
|
||
noticesRet := data.(*model.QueryHorseRaceLampRet)
|
||
if noticesRet != nil {
|
||
var apiNoticMsgList []*webapiproto.HorseRaceLamp
|
||
for _, notice := range noticesRet.Data {
|
||
apiNoticeMsg := &webapiproto.HorseRaceLamp{
|
||
Id: notice.Id.Hex(),
|
||
Platform: notice.Platform,
|
||
Title: notice.Title,
|
||
Content: notice.Content,
|
||
Footer: notice.Footer,
|
||
StartTime: notice.StartTime,
|
||
Frequency: notice.Interval,
|
||
State: notice.State,
|
||
CreateTime: notice.CreateTime,
|
||
Count: notice.Count,
|
||
Priority: notice.Priority,
|
||
MsgType: notice.MsgType,
|
||
Target: notice.Target,
|
||
StandSec: notice.StandSec,
|
||
}
|
||
apiNoticMsgList = append(apiNoticMsgList, apiNoticeMsg)
|
||
}
|
||
pack.PageCount = int32(noticesRet.Count)
|
||
pack.HorseRaceLamp = apiNoticMsgList
|
||
}
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
if err != nil {
|
||
logger.Logger.Error("Marshal notice msg list error:", err)
|
||
}
|
||
}), "QueryHorseRaceLampList").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
//WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Message/CreateHorseRaceLamp", WebAPIHandlerWrapper(
|
||
// func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
// pack := &webapiproto.SACreateHorseRaceLamp{}
|
||
// msg := &webapiproto.ASCreateHorseRaceLamp{}
|
||
// err := proto.Unmarshal(params, msg)
|
||
// if err != nil {
|
||
// pack.Tag = webapiproto.TagCode_FAILED
|
||
// pack.Msg = "数据序列化失败" + err.Error()
|
||
// return common.ResponseTag_ParamError, pack
|
||
// }
|
||
// platform := msg.Platform
|
||
// title := msg.Title
|
||
// content := msg.Content
|
||
// footer := msg.Footer
|
||
// count := msg.Count
|
||
// state := msg.State
|
||
// startTime := msg.StartTime
|
||
// priority := msg.Priority
|
||
// msgType := msg.MsgType
|
||
// standSec := msg.StandSec
|
||
// target := msg.Target
|
||
// var horseRaceLamp *model.HorseRaceLamp
|
||
// task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
// horseRaceLamp = model.NewHorseRaceLamp("", platform, title, content, footer, startTime, standSec, count,
|
||
// priority, state, msgType, target, standSec)
|
||
// return model.InsertHorseRaceLamp(platform, horseRaceLamp)
|
||
// }), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
// if data != nil {
|
||
// pack.Tag = webapiproto.TagCode_FAILED
|
||
// pack.Msg = data.(error).Error()
|
||
// tNode.TransRep.RetFiels = pack
|
||
// tNode.Resume()
|
||
// return
|
||
// }
|
||
// HorseRaceLampMgrSingleton.AddHorseRaceLampMsg(horseRaceLamp.Id.Hex(), "", platform, title, content, footer, startTime, standSec,
|
||
// count, msgType, state, priority, horseRaceLamp.CreateTime, target, standSec)
|
||
// pack.Tag = webapiproto.TagCode_SUCCESS
|
||
// tNode.TransRep.RetFiels = pack
|
||
// tNode.Resume()
|
||
// }), "CreateHorseRaceLamp").Start()
|
||
// return common.ResponseTag_TransactYield, pack
|
||
// }))
|
||
//
|
||
//WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Message/GetHorseRaceLampById", WebAPIHandlerWrapper(
|
||
// func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
// pack := &webapiproto.SAGetHorseRaceLampById{}
|
||
// msg := &webapiproto.ASGetHorseRaceLampById{}
|
||
// err := proto.Unmarshal(params, msg)
|
||
// if err != nil {
|
||
// pack.Tag = webapiproto.TagCode_FAILED
|
||
// pack.Msg = "数据序列化失败" + err.Error()
|
||
// return common.ResponseTag_ParamError, pack
|
||
// }
|
||
// noticeKey := msg.NoticeId
|
||
// platform := msg.Platform
|
||
// horseRaceLamp := HorseRaceLampMgrSingleton.HorseRaceLampMsgList[noticeKey]
|
||
// if horseRaceLamp == nil || (len(platform) > 0 && horseRaceLamp.Platform != platform) {
|
||
// pack.Tag = webapiproto.TagCode_FAILED
|
||
// pack.Msg = "not find data"
|
||
// } else {
|
||
// pack.HorseRaceLamp = &webapiproto.HorseRaceLamp{
|
||
// Id: noticeKey,
|
||
// Title: horseRaceLamp.Title,
|
||
// Content: horseRaceLamp.Content,
|
||
// Footer: horseRaceLamp.Footer,
|
||
// StartTime: horseRaceLamp.StartTime,
|
||
// Frequency: horseRaceLamp.Interval,
|
||
// Count: horseRaceLamp.Count,
|
||
// State: horseRaceLamp.State,
|
||
// CreateTime: horseRaceLamp.CreateTime,
|
||
// Priority: horseRaceLamp.Priority,
|
||
// MsgType: horseRaceLamp.MsgType,
|
||
// }
|
||
// pack.Tag = webapiproto.TagCode_SUCCESS
|
||
// }
|
||
// return common.ResponseTag_Ok, pack
|
||
// }))
|
||
//
|
||
//WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Message/EditHorseRaceLamp", WebAPIHandlerWrapper(
|
||
// func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
// pack := &webapiproto.SAEditHorseRaceLamp{}
|
||
// msg := &webapiproto.ASEditHorseRaceLamp{}
|
||
// err := proto.Unmarshal(params, msg)
|
||
// if err != nil {
|
||
// pack.Tag = webapiproto.TagCode_FAILED
|
||
// pack.Msg = "数据序列化失败" + err.Error()
|
||
// return common.ResponseTag_ParamError, pack
|
||
// }
|
||
// noticeKey := msg.HorseRaceLamp.Id
|
||
// if len(noticeKey) == 0 {
|
||
// pack.Tag = webapiproto.TagCode_FAILED
|
||
// pack.Msg = "NoticeMsg id is nil"
|
||
// return common.ResponseTag_ParamError, pack
|
||
// }
|
||
// hrl := msg.HorseRaceLamp
|
||
// task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
// notice, err2 := model.GetHorseRaceLamp(hrl.Platform, bson.ObjectIdHex(noticeKey))
|
||
// if err2 != nil {
|
||
// logger.Logger.Error("api GetNotice is error", err2)
|
||
// return nil
|
||
// }
|
||
// model.EditHorseRaceLamp(&model.HorseRaceLamp{
|
||
// Id: bson.ObjectIdHex(noticeKey),
|
||
// Channel: "",
|
||
// Title: hrl.Title,
|
||
// Content: hrl.Content,
|
||
// Footer: hrl.Footer,
|
||
// StartTime: hrl.StartTime,
|
||
// Interval: hrl.Frequency,
|
||
// Count: hrl.Count,
|
||
// CreateTime: hrl.CreateTime,
|
||
// Priority: hrl.Priority,
|
||
// MsgType: hrl.MsgType,
|
||
// Platform: hrl.Platform,
|
||
// State: hrl.State,
|
||
// Target: hrl.Target,
|
||
// StandSec: hrl.StandSec,
|
||
// })
|
||
// return notice
|
||
// }), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
// if data == nil {
|
||
// pack.Tag = webapiproto.TagCode_FAILED
|
||
// pack.Msg = "api GetNotice is error"
|
||
// tNode.TransRep.RetFiels = pack
|
||
// tNode.Resume()
|
||
// if err != nil {
|
||
// logger.Logger.Error("Marshal EditHorseRaceLamp response data error1:", err)
|
||
// }
|
||
// return
|
||
// } else {
|
||
// cache := HorseRaceLampMgrSingleton.EditHorseRaceLampMsg(&HorseRaceLamp{
|
||
// Key: noticeKey,
|
||
// Channel: "",
|
||
// Title: hrl.Title,
|
||
// Content: hrl.Content,
|
||
// Footer: hrl.Footer,
|
||
// StartTime: hrl.StartTime,
|
||
// Interval: hrl.Frequency,
|
||
// Count: hrl.Count,
|
||
// CreateTime: hrl.CreateTime,
|
||
// Priority: hrl.Priority,
|
||
// MsgType: hrl.MsgType,
|
||
// Platform: hrl.Platform,
|
||
// State: hrl.State,
|
||
// Target: hrl.Target,
|
||
// StandSec: hrl.StandSec,
|
||
// })
|
||
// if !cache {
|
||
// pack.Tag = webapiproto.TagCode_FAILED
|
||
// pack.Msg = "api EditNoticeMsg is error"
|
||
// tNode.TransRep.RetFiels = pack
|
||
// tNode.Resume()
|
||
// return
|
||
// }
|
||
// }
|
||
// pack.Tag = webapiproto.TagCode_SUCCESS
|
||
// tNode.TransRep.RetFiels = pack
|
||
// tNode.Resume()
|
||
// if err != nil {
|
||
// logger.Logger.Error("Marshal EditHorseRaceLamp response data error3:", err)
|
||
// }
|
||
// }), "EditHorseRaceLamp").Start()
|
||
//
|
||
// return common.ResponseTag_TransactYield, pack
|
||
// }))
|
||
//
|
||
//WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Message/RemoveHorseRaceLampById", WebAPIHandlerWrapper(
|
||
// func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
// pack := &webapiproto.SARemoveHorseRaceLampById{}
|
||
// msg := &webapiproto.ASRemoveHorseRaceLampById{}
|
||
// err := proto.Unmarshal(params, msg)
|
||
// if err != nil {
|
||
// pack.Tag = webapiproto.TagCode_FAILED
|
||
// pack.Msg = "数据序列化失败" + err.Error()
|
||
// return common.ResponseTag_ParamError, pack
|
||
// }
|
||
// noticeKey := msg.GetHorseRaceId()
|
||
// platform := msg.GetPlatform()
|
||
// notice := HorseRaceLampMgrSingleton.HorseRaceLampMsgList[noticeKey]
|
||
// if notice == nil {
|
||
// pack.Tag = webapiproto.TagCode_FAILED
|
||
// pack.Msg = "not find data"
|
||
// return common.ResponseTag_Ok, pack
|
||
// }
|
||
// if len(platform) > 0 && notice.Platform != notice.Platform {
|
||
// pack.Tag = webapiproto.TagCode_FAILED
|
||
// pack.Msg = "not find data"
|
||
// return common.ResponseTag_Ok, pack
|
||
// }
|
||
// task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
// return model.RemoveHorseRaceLamp(platform, noticeKey)
|
||
// }), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
// if data != nil {
|
||
// pack.Tag = webapiproto.TagCode_FAILED
|
||
// pack.Msg = "RemoveNotice is error" + data.(error).Error()
|
||
// tNode.TransRep.RetFiels = pack
|
||
// tNode.Resume()
|
||
// return
|
||
// }
|
||
// HorseRaceLampMgrSingleton.DelHorseRaceLampMsg(noticeKey)
|
||
// pack.Tag = webapiproto.TagCode_SUCCESS
|
||
// tNode.TransRep.RetFiels = pack
|
||
// tNode.Resume()
|
||
// }), "ResponseTag_TransactYield").Start()
|
||
// return common.ResponseTag_TransactYield, pack
|
||
// }))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Ctrl/ResetEtcdData", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAResetEtcdData{}
|
||
msg := &webapiproto.ASResetEtcdData{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
etcd.Restart()
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "Etcd Reset success"
|
||
return common.ResponseTag_Ok, nil
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Game/CreateJYB", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SACreateJYB{}
|
||
msg := &webapiproto.ASCreateJYB{}
|
||
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
if msg.CodeType == 1 && (msg.Code == "" || len(msg.Code) > 11) {
|
||
pack.Tag = webapiproto.TagCode_JYB_DATA_ERROR
|
||
pack.Msg = "CreateJYB Code failed"
|
||
return common.ResponseTag_Ok, pack
|
||
}
|
||
// (plt, name, content string, startTs, endTs int64, max int32, award *JybInfoAward)
|
||
award := &model.JybInfoAward{}
|
||
if msg.GetAward() != nil {
|
||
award.Coin = msg.GetAward().Coin
|
||
award.Diamond = msg.GetAward().Diamond
|
||
if msg.GetAward().GetItemId() != nil {
|
||
for _, item := range msg.GetAward().ItemId {
|
||
if v := srvdata.GameItemMgr.Get(msg.Platform, item.ItemId); item != nil {
|
||
if item.ItemNum == 0 {
|
||
pack.Tag = webapiproto.TagCode_JYB_DATA_ERROR
|
||
pack.Msg = "ItemNum failed"
|
||
return common.ResponseTag_Ok, pack
|
||
}
|
||
award.Item = append(award.Item, &model.Item{
|
||
ItemId: v.Id,
|
||
ItemNum: item.ItemNum,
|
||
ObtainTime: time.Now().Unix(),
|
||
})
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_JYB_DATA_ERROR
|
||
pack.Msg = "ItemId failed"
|
||
return common.ResponseTag_Ok, pack
|
||
}
|
||
}
|
||
}
|
||
}
|
||
jyb := model.NewJybInfo(msg.Platform, msg.Name, msg.Content, msg.Code, msg.StartTime, msg.EndTime, msg.Max, msg.CodeType, award)
|
||
args := &model.CreateJyb{
|
||
JybInfo: jyb,
|
||
Codelen: msg.CodeLen,
|
||
Num: uint64(msg.Max),
|
||
}
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
return model.CreateJybInfo(args)
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
if data == nil {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "CreateJYB success"
|
||
} else {
|
||
logger.Logger.Trace("err: ", data.(error))
|
||
if data.(error) == model.ErrJYBCode {
|
||
pack.Tag = webapiproto.TagCode_JYB_CODE_EXIST
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
}
|
||
pack.Msg = "CreateJYB failed"
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}), "webCreateJybInfo").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Game/UpdateJYB", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAUpdateJYB{}
|
||
msg := &webapiproto.ASUpdateJYB{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
|
||
if msg.Opration == 1 {
|
||
args := &model.GetJybInfoArgs{
|
||
Id: msg.JYBID,
|
||
Plt: msg.Platform,
|
||
}
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
return model.DelJybInfo(args)
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
if data == nil {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "UpdateJYB success"
|
||
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "UpdateJYB failed"
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}), "webDelJybInfo").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}
|
||
|
||
return common.ResponseTag_Ok, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/Customer/UpExchangeStatus", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAUpExchangeStatus{}
|
||
msg := &webapiproto.ASUpExchangeStatus{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
snid := msg.Snid
|
||
platform := msg.Platform
|
||
player := PlayerMgrSington.GetPlayerBySnId(snid)
|
||
if msg.Status != Shop_Status_Revoke {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "Status is Revoke"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
//cdata := ShopMgrSington.GetExchangeData(msg.GoodsId)
|
||
item := srvdata.GameItemMgr.Get(platform, common.ItemIDVCard)
|
||
if item == nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "item is nil"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
addvcoin := msg.NeedNum
|
||
jPrice := msg.JPrice
|
||
dPrice := msg.DPrice
|
||
var items []*model.Item
|
||
//V卡
|
||
if addvcoin > 0 {
|
||
items = append(items, &model.Item{ItemId: common.ItemIDVCard, ItemNum: int64(addvcoin)})
|
||
}
|
||
//金券
|
||
if jPrice > 0 {
|
||
items = append(items, &model.Item{ItemId: common.ItemIDJCard, ItemNum: int64(jPrice)})
|
||
}
|
||
//娃娃积分
|
||
if dPrice > 0 {
|
||
items = append(items, &model.Item{ItemId: common.ItemDollCard, ItemNum: int64(dPrice)})
|
||
}
|
||
remark := fmt.Sprintf("兑换撤单 %v-%v", msg.GoodsId, msg.Name)
|
||
if player != nil {
|
||
// 在线
|
||
if _, code, _ := BagMgrSingleton.AddItems(&model.AddItemParam{
|
||
Platform: player.Platform,
|
||
SnId: player.SnId,
|
||
Change: items,
|
||
GainWay: common.GainWay_Exchange,
|
||
Operator: "system",
|
||
Remark: remark,
|
||
}); code != bag.OpResultCode_OPRC_Sucess { // 领取失败
|
||
logger.Logger.Errorf("UpExchangeStatus AddItems err", code)
|
||
pack.Msg = "AddItems err"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "UpExchange success"
|
||
return common.ResponseTag_Ok, pack
|
||
} else {
|
||
BagMgrSingleton.AddItemsOffline(&model.AddItemParam{
|
||
Platform: platform,
|
||
SnId: snid,
|
||
Change: items,
|
||
GainWay: common.GainWay_Exchange,
|
||
Operator: "system",
|
||
Remark: remark,
|
||
}, func(err error) {
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "UpExchange failed:" + err.Error()
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "UpExchange success"
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
})
|
||
return common.ResponseTag_TransactYield, pack
|
||
}
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/pay/CallbackPayment", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
msg := &webapiproto.ASCallbackPayment{}
|
||
pack := &webapiproto.SACallbackPayment{}
|
||
err := proto.Unmarshal(params, msg)
|
||
logger.Logger.Info("api /api/pay/CallbackPayment msg = ", msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "数据序列化失败" + err.Error()
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
if msg.OrderId == "" || msg.Platform == "" {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "OrderId == nil || msg.Platform == nil"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
|
||
retFail := func(errorMsg string) {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = errorMsg
|
||
if tNode != nil {
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}
|
||
}
|
||
|
||
var info *model.DbShop
|
||
var state int32
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
info = model.GetDbShopLog(msg.Platform, msg.OrderId)
|
||
if info == nil {
|
||
return errors.New("info is nil")
|
||
}
|
||
logger.Logger.Tracef("/api/pay/CallbackPayment ShopLog %+v", *info)
|
||
if info.State != 0 {
|
||
return errors.New("the order state not 0 " + info.LogId.Hex())
|
||
}
|
||
return nil
|
||
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
|
||
if i != nil || info == nil {
|
||
logger.Logger.Errorf("CallbackPayment error %v shoplog:%#v", i, info)
|
||
retFail("购买记录查询失败")
|
||
return
|
||
}
|
||
|
||
state = msg.GetState()
|
||
player := PlayerMgrSington.GetPlayerBySnId(info.SnId)
|
||
logger.Logger.Info("CallbackPayment player", player)
|
||
if player == nil || player.IsOffline() {
|
||
if msg.State == 1 {
|
||
state = 3
|
||
}
|
||
}
|
||
logger.Logger.Info("------------CallbackPayment state----------", state)
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
err := model.UpdateDbShopState(msg.Platform, msg.OrderId, state)
|
||
if err != nil {
|
||
logger.Logger.Error("CallbackPayment UpdateDbShopState error:", err)
|
||
return err
|
||
}
|
||
return nil
|
||
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
|
||
if i != nil {
|
||
retFail("购买记录状态修改失败")
|
||
return
|
||
}
|
||
if player != nil && !player.IsOffline() {
|
||
player.DoShopInfo(info, false)
|
||
// 邀请积分
|
||
InviteTask(msg.Platform, player.PSnId, info.SnId, common.InviteScoreTypePay, int64(info.ConsumeNum))
|
||
} else {
|
||
// 邀请积分
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
psnid, err := model.GetPlayerInviteSnid(msg.Platform, info.SnId)
|
||
if err != nil {
|
||
logger.Logger.Error("CallbackPayment GetPlayerInviteSnid error:", err)
|
||
return err
|
||
}
|
||
InviteTask(msg.Platform, psnid, info.SnId, common.InviteScoreTypePay, int64(info.ConsumeNum))
|
||
|
||
return nil
|
||
}), nil, "InvitePayTask").Start()
|
||
}
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "success"
|
||
if tNode != nil {
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}
|
||
})).StartByExecutor(fmt.Sprintf("Player%v", info.SnId))
|
||
})).StartByFixExecutor("CallbackPayment")
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
//======= 资源更新通知 =======
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/game/resource", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAResource{}
|
||
msg := &webapiproto.ASResource{}
|
||
err := proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = fmt.Sprintf("err:%v", err.Error())
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
|
||
// 通知所有玩家
|
||
playerMsg := &playerproto.SCResource{
|
||
Msg: msg.GetMsg(),
|
||
}
|
||
PlayerMgrSington.BroadcastMessage(int(playerproto.PlayerPacketID_PACKET_SC_RESOURCE), playerMsg)
|
||
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = ""
|
||
return common.ResponseTag_Ok, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/player/update_tel", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAUpdateTel{}
|
||
msg := &webapiproto.ASUpdateTel{}
|
||
|
||
var err error
|
||
err = proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "参数错误"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
logger.Logger.Tracef(
|
||
"WebAPIHandlerMgrSingleton.RegisteWebAPIHandler /api/player/update_tel snid:%v, tel:%v ,platform:%v", msg.GetSnid(), msg.GetTel(), msg.GetPlatform())
|
||
|
||
p := PlayerMgrSington.GetPlayerBySnId(msg.GetSnid())
|
||
if p != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "玩家在线,只能离线修改"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
|
||
var snid int32
|
||
var a *model.Account
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
// 手机号是否已经被绑定
|
||
snid, _ = model.GetPlayerTel(msg.GetTel(), msg.GetPlatform(), 0) // tagKey没用了,给0就行
|
||
if snid != 0 {
|
||
return nil
|
||
}
|
||
|
||
a, err = model.GetAccountBySnid(msg.GetPlatform(), msg.GetSnid())
|
||
if err != nil || a == nil {
|
||
return nil
|
||
}
|
||
if a.Tel == "" {
|
||
return nil
|
||
}
|
||
|
||
// 绑定手机号
|
||
if err = model.BindTelAccount(a.AccountId.Hex(), msg.GetTel(), msg.GetPlatform()); err != nil {
|
||
logger.Logger.Errorf("BindTelAccount err: %v", err)
|
||
return nil
|
||
}
|
||
|
||
if err = model.UpdatePlayerTel(msg.GetPlatform(), msg.GetSnid(), msg.GetTel()); err != nil {
|
||
logger.Logger.Errorf("UpdatePlayerTel err: %v", err)
|
||
return nil
|
||
}
|
||
return nil
|
||
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
|
||
if err != nil {
|
||
// 修改错误
|
||
logger.Logger.Errorf("update tel %v err: %v", msg.GetSnid(), err)
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "修改失败"
|
||
} else if snid != 0 {
|
||
// 手机号已经绑定
|
||
pack.Tag = webapiproto.TagCode_TelExist
|
||
pack.Msg = "手机号已使用"
|
||
} else if a == nil {
|
||
// 手机号已经绑定
|
||
pack.Tag = webapiproto.TagCode_AccountNotFound
|
||
pack.Msg = "账号没找到"
|
||
} else if a.Tel == "" {
|
||
// 没有绑定手机号
|
||
pack.Tag = webapiproto.TagCode_TelNotBind
|
||
pack.Msg = "原账号没有绑定手机号,请自行绑定"
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "修改成功"
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
logger.Logger.Tracef("update tel %v ret: %v", msg.GetSnid(), pack)
|
||
})).StartByFixExecutor(fmt.Sprintf("Platform%v", msg.GetPlatform()))
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/player/delete", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAPlayerDelete{}
|
||
msg := &webapiproto.ASPlayerDelete{}
|
||
|
||
var err error
|
||
err = proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "参数错误"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
logger.Logger.Tracef("/api/player/delete %v", msg)
|
||
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
if msg.GetFaceBookId() != "" {
|
||
fb, err := model.GetByFaceBookId(msg.GetFaceBookId())
|
||
if err != nil {
|
||
return err
|
||
}
|
||
if fb == nil {
|
||
return nil
|
||
}
|
||
msg.Platform = fb.Platform
|
||
msg.Snid = fb.SnId
|
||
}
|
||
return nil
|
||
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
|
||
if err != nil {
|
||
logger.Logger.Errorf("player delete %v err: %v", msg, err)
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "删除失败"
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
logger.Logger.Tracef("player delete %v ret: %v", msg.GetSnid(), pack)
|
||
return
|
||
}
|
||
// 踢掉玩家
|
||
p := PlayerMgrSington.GetPlayerBySnId(msg.GetSnid())
|
||
if p != nil {
|
||
ls := LoginStateMgrSington.GetLoginStateBySid(p.sid)
|
||
if ls != nil {
|
||
if ls.als != nil && ls.als.acc != nil {
|
||
ls.als.acc.State = time.Now().AddDate(0, 0, 1).Unix()
|
||
}
|
||
}
|
||
|
||
p.Kick(common.KickReason_Freeze)
|
||
PlayerMgrSington.DelPlayer(p.SnId)
|
||
LoginStateMgrSington.DelAccountByAccid(p.AccountId)
|
||
}
|
||
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
pd, _ := model.GetPlayerDataBySnId(msg.Platform, msg.Snid, false, false)
|
||
if pd == nil || pd.SnId == 0 {
|
||
err = errors.New("player not found")
|
||
return nil
|
||
}
|
||
// 冻结
|
||
err = model.FreezeAccount(pd.Platform, pd.AccountId, 24*60)
|
||
if err != nil {
|
||
return nil
|
||
}
|
||
// 备份账号
|
||
var account *model.Account
|
||
account, err = model.GetAccount(pd.Platform, pd.AccountId)
|
||
if err != nil {
|
||
return nil
|
||
}
|
||
err = model.SaveToDelBackupAccount(account)
|
||
if err != nil {
|
||
return nil
|
||
}
|
||
//if !model.SaveDelBackupPlayerData(pd) {
|
||
// err = errors.New("SaveDelBackupPlayerData failed")
|
||
// return nil
|
||
//}
|
||
// 删除账号
|
||
err = model.RemoveAccount(pd.Platform, pd.AccountId)
|
||
if err != nil {
|
||
return nil
|
||
}
|
||
err = model.ResetPlayer(pd.Platform, pd.SnId)
|
||
if err != nil {
|
||
return nil
|
||
}
|
||
return nil
|
||
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
|
||
if err != nil {
|
||
logger.Logger.Errorf("player delete %v err: %v", msg, err)
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "删除失败"
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "删除成功"
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
logger.Logger.Tracef("player delete %v ret: %v", msg.GetSnid(), pack)
|
||
}), "player_delete").StartByExecutor(fmt.Sprint(msg.GetSnid()))
|
||
}), "player_delete").StartByExecutor(fmt.Sprint(msg.GetSnid()))
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/player/AddItem", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAAddItemById{}
|
||
msg := &webapiproto.ASAddItemById{}
|
||
|
||
var err error
|
||
err = proto.Unmarshal(params, msg)
|
||
if err != nil || msg.Snid <= 0 {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "参数错误"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
var items []*model.Item
|
||
var has bool
|
||
for _, info := range msg.ItemInfo {
|
||
items = append(items, &model.Item{
|
||
ItemId: info.ItemId, // 物品id
|
||
ItemNum: info.ItemNum, // 数量
|
||
ObtainTime: time.Now().Unix(),
|
||
})
|
||
if info.ItemNum < 0 {
|
||
has = true
|
||
}
|
||
}
|
||
p := PlayerMgrSington.GetPlayerBySnId(msg.GetSnid())
|
||
if p != nil {
|
||
if p.scene != nil && has {
|
||
logger.Logger.Warnf("游戏中不能减道具")
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "游戏中不能减道具"
|
||
return common.ResponseTag_Ok, pack
|
||
}
|
||
|
||
//获取道具Id
|
||
_, _, ok := BagMgrSingleton.AddItems(&model.AddItemParam{
|
||
Platform: p.Platform,
|
||
SnId: p.SnId,
|
||
Change: items,
|
||
GainWay: msg.GetTypeId(),
|
||
Operator: "system",
|
||
Remark: msg.GetRemark(),
|
||
})
|
||
if !ok {
|
||
logger.Logger.Errorf("player delete %v err: %v", msg, err)
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "修改道具失败"
|
||
return common.ResponseTag_Ok, pack
|
||
}
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "修改道具成功"
|
||
return common.ResponseTag_Ok, pack
|
||
} else {
|
||
BagMgrSingleton.AddItemsOffline(&model.AddItemParam{
|
||
Platform: msg.GetPlatform(),
|
||
SnId: msg.GetSnid(),
|
||
Change: items,
|
||
GainWay: msg.GetTypeId(),
|
||
Operator: "system",
|
||
Remark: msg.GetRemark(),
|
||
}, func(err error) {
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "AddItem failed:" + err.Error()
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "AddItem success"
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
})
|
||
return common.ResponseTag_TransactYield, pack
|
||
}
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/game/show_lottery", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
logger.Logger.Tracef("/api/game/show_lottery %v", params)
|
||
pack := &webapiproto.SAShowLottery{}
|
||
msg := &webapiproto.ASShowLottery{}
|
||
|
||
var err error
|
||
err = proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "参数错误"
|
||
logger.Logger.Errorf("/api/game/show_lottery Unmarshal err: %v", err)
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
err = model.UpdateLotteryMedia(msg.GetPlatform(), msg.GetLogId(), msg.GetList())
|
||
if err != nil {
|
||
logger.Logger.Errorf("/api/game/show_lottery UpdateLotteryMedia %v err: %v", msg, err)
|
||
return err
|
||
}
|
||
return nil
|
||
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
|
||
if err != nil {
|
||
logger.Logger.Errorf("/api/game/show_lottery %v err: %v", msg, err)
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "修改失败"
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "修改成功"
|
||
mq.Write(&model.LotteryLog{Platform: msg.GetPlatform()}, mq.RankLotteryLog)
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
logger.Logger.Tracef("/api/game/show_lottery ret: %v", pack)
|
||
}), "modify_show_lottery").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/game/send_sms", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
|
||
pack := &webapiproto.SASendSMSCode{}
|
||
msg := &webapiproto.ASSendSMSCode{}
|
||
|
||
var err error
|
||
err = proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "参数错误"
|
||
logger.Logger.Errorf("/api/game/send_sms Unmarshal err: %v", err)
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
logger.Logger.Tracef("/api/game/send_sms %v", msg)
|
||
|
||
msg.Tel = strings.TrimPrefix(msg.GetTel(), "0")
|
||
if !telRule.MatchString(msg.GetTel()) {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "手机号格式错误"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
|
||
telKey := common.GetTelLoginCodeKey(msg.GetPlatform(), msg.GetTel())
|
||
validTime := common.SMSCodeValidTimeTelLogin
|
||
|
||
key := fmt.Sprintf("key%s", telKey)
|
||
code := CacheMemory.Get(key) // 频率限制
|
||
if code != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "发送频率过快"
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
|
||
if model.GameParamData.FakeVerifyCode != "" {
|
||
CacheMemory.Put(telKey, model.GameParamData.FakeVerifyCode, validTime)
|
||
CacheMemory.Put(key, model.GameParamData.FakeVerifyCode, common.SMSCodeValidTime)
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "发送成功"
|
||
return common.ResponseTag_Ok, pack
|
||
}
|
||
|
||
//先设置注册码,防止多次注册
|
||
smsCode := common.RandSmsCode()
|
||
CacheMemory.Put(telKey, smsCode, validTime)
|
||
CacheMemory.Put(key, smsCode, common.SMSCodeValidTime)
|
||
logger.Logger.Trace("CSPlayerSMSCode smsCode ", smsCode)
|
||
|
||
var res []byte
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
param := &webapiproto.ASSendSms{
|
||
Phone: msg.GetTel(),
|
||
Code: smsCode,
|
||
Platform: msg.GetPlatform(),
|
||
TypeID: common.SMSCodeTelLogin,
|
||
}
|
||
res, err = webapi.ApiSendSMS(common.GetAppId(), param)
|
||
return nil
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
if err != nil || res == nil {
|
||
logger.Logger.Errorf("API_SendSms err %v", err)
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "发送失败"
|
||
} else {
|
||
var info webapiproto.SASendSms
|
||
proto.Unmarshal(res, &info)
|
||
if info.Tag == webapiproto.TagCode_SUCCESS {
|
||
CacheMemory.Put(telKey, smsCode, validTime)
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "发送成功"
|
||
} else {
|
||
if info.Tag == webapiproto.TagCode_Limit {
|
||
logger.Logger.Warnf("API_SendSms Limit tel:%s", msg.GetTel())
|
||
pack.Tag = webapiproto.TagCode_Limit
|
||
pack.Msg = "发送频率过快"
|
||
} else {
|
||
logger.Logger.Errorf("API_SendSms err %v", err)
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "发送失败"
|
||
}
|
||
}
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}), "API_SendSms").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/game/web_login", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAWebLogin{
|
||
Tag: webapiproto.TagCode_FAILED,
|
||
Msg: "未知错误",
|
||
}
|
||
msg := &webapiproto.ASWebLogin{}
|
||
|
||
var err error
|
||
err = proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "参数错误"
|
||
logger.Logger.Errorf("/api/game/web_login Unmarshal err: %v", err)
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
logger.Logger.Tracef("/api/game/web_login %v", msg)
|
||
|
||
var acc *model.Account
|
||
ls := LoginStateMgrSington.GetLoginStateByName(UserKey(msg.GetUsername(), msg.GetPlatform(), 0))
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
if ls != nil && ls.acc != nil {
|
||
if msg.GetLoginType() == 2 && ls.acc.Tel == msg.GetUsername() {
|
||
acc = ls.acc
|
||
}
|
||
if msg.GetLoginType() != 2 && ls.acc.UserName == msg.GetUsername() {
|
||
acc = ls.acc
|
||
}
|
||
}
|
||
if acc == nil {
|
||
acc, err = model.GetAccountByName(msg.GetPlatform(), msg.GetUsername())
|
||
}
|
||
return nil
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
if err != nil || acc == nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "查询账号失败"
|
||
} else {
|
||
switch msg.GetLoginType() {
|
||
case 1, 3, 4: // 账号密码登录 google登录 facebook登录
|
||
if acc.UserName == msg.GetUsername() {
|
||
raw := fmt.Sprintf("%v%v%v", acc.PassWord, common.GetAppId(), msg.GetTimestamp())
|
||
h := md5.New()
|
||
io.WriteString(h, raw)
|
||
pwd := hex.EncodeToString(h.Sum(nil))
|
||
if pwd == msg.GetPassword() {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "登录成功"
|
||
pack.Platform = ls.acc.Platform
|
||
pack.SnId = ls.acc.SnId
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "密码错误"
|
||
}
|
||
}
|
||
|
||
case 2: // 手机号验证码登录
|
||
if acc.Tel == msg.GetUsername() {
|
||
code := CacheMemory.Get(common.GetTelLoginCodeKey(msg.GetPlatform(), msg.GetUsername()))
|
||
// 验证码错误
|
||
if code != msg.GetSMSCode() {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "验证码错误"
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "登录成功"
|
||
pack.Platform = acc.Platform
|
||
pack.SnId = acc.SnId
|
||
}
|
||
}
|
||
|
||
default:
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "未知登录类型"
|
||
}
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}), "GetAccount").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/player/address", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAGetAddress{
|
||
Tag: webapiproto.TagCode_FAILED,
|
||
Msg: "未知错误",
|
||
}
|
||
msg := &webapiproto.ASGetAddress{}
|
||
|
||
var err error
|
||
err = proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "参数错误"
|
||
logger.Logger.Errorf("/api/player/address Unmarshal err: %v", err)
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
logger.Logger.Tracef("/api/player/address %v", msg)
|
||
|
||
p := PlayerMgrSington.GetPlayerBySnId(msg.GetSnId())
|
||
if p != nil {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "获取成功"
|
||
pack.List = p.Addr
|
||
return common.ResponseTag_Ok, pack
|
||
}
|
||
|
||
// 离线获取
|
||
var address []string
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
address, err = model.GetPlayerAddress(msg.GetPlatform(), msg.GetSnId())
|
||
return nil
|
||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "获取失败"
|
||
} else {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "获取成功"
|
||
pack.List = address
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}), "GetAddress").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/player/update_address", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAUpdateAddress{
|
||
Tag: webapiproto.TagCode_FAILED,
|
||
Msg: "未知错误",
|
||
}
|
||
msg := &webapiproto.ASUpdateAddress{}
|
||
|
||
var err error
|
||
err = proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
pack.Msg = "参数错误"
|
||
logger.Logger.Errorf("/api/player/update_address Unmarshal err: %v", err)
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
logger.Logger.Tracef("/api/player/update_address %v", msg)
|
||
|
||
UpdatePlayerAddress(msg.GetPlatform(), msg.GetSnId(), msg.GetOpType(), msg.GetAddr(), msg.GetId(), func(address []string) {
|
||
pack.Tag = webapiproto.TagCode_SUCCESS
|
||
pack.Msg = "修改成功"
|
||
pack.List = address
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
})
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/game/exchange_list", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAGetExchangeShop{
|
||
Tag: webapiproto.TagCode_FAILED,
|
||
}
|
||
msg := &webapiproto.ASGetExchangeShop{}
|
||
var err error
|
||
err = proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
logger.Logger.Errorf("/api/game/exchange_list Unmarshal err: %v", err)
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
|
||
logger.Logger.Tracef("/api/game/exchange_list %v", msg)
|
||
|
||
var b []byte
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
b, err = webapi.API_ExchangeList(common.GetAppId(), msg)
|
||
return nil
|
||
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
|
||
if err != nil || b == nil {
|
||
logger.Logger.Errorf("/api/game/exchange_list API_ExchangeList err: %v", err)
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
} else {
|
||
err = proto.Unmarshal(b, pack)
|
||
if err != nil {
|
||
logger.Logger.Errorf("/api/game/exchange_list Unmarshal err: %v", err)
|
||
}
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}), "/api/game/exchange_list").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/game/exchange_order", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAGetExchangeOrder{
|
||
Tag: webapiproto.TagCode_FAILED,
|
||
}
|
||
msg := &webapiproto.ASGetExchangeOrder{}
|
||
var err error
|
||
err = proto.Unmarshal(params, msg)
|
||
if err != nil {
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
logger.Logger.Errorf("/api/game/exchange_order Unmarshal err: %v", err)
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
|
||
logger.Logger.Tracef("/api/game/exchange_order %v", msg)
|
||
|
||
var b []byte
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
b, err = webapi.API_ExchangeRecord(common.GetAppId(), msg)
|
||
return nil
|
||
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
|
||
if err != nil || b == nil {
|
||
logger.Logger.Errorf("/api/game/exchange_order API_ExchangeList err: %v", err)
|
||
pack.Tag = webapiproto.TagCode_FAILED
|
||
} else {
|
||
err = proto.Unmarshal(b, pack)
|
||
if err != nil {
|
||
logger.Logger.Errorf("/api/game/exchange_order Unmarshal err: %v", err)
|
||
}
|
||
}
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
}), "/api/game/exchange_order").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/platform/debug", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
|
||
var jsonDataRsp []byte
|
||
pack := &webapiproto.ASGetAddress{
|
||
Platform: "1",
|
||
SnId: 200,
|
||
}
|
||
|
||
if !common.Config.IsDevMode {
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
|
||
var msg *webapi.DebugTestReq
|
||
err := json.Unmarshal(params, &msg)
|
||
if err != nil {
|
||
logger.Logger.Error("Unmarshal webapi.DebugTestReq error:", err)
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
|
||
jsonRet := &webapi.DebugTestRsp{
|
||
Success: false,
|
||
Code: 200,
|
||
Message: "未知错误",
|
||
}
|
||
|
||
logger.Logger.Tracef("/api/platform/debug DebugTestReq%v", msg)
|
||
|
||
player := PlayerMgrSington.GetPlayerBySnId(msg.Snid)
|
||
//玩家在线
|
||
if player != nil {
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
//b, err = webapi.API_ExchangeRecord(common.GetAppId(), msg)
|
||
return nil
|
||
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
|
||
|
||
if msg.Rpc == 1 {
|
||
addCoin, _ := strconv.ParseInt(msg.Count, 10, 64)
|
||
player.AddCoin(addCoin, 0, 5555, "platform", "debug加金币")
|
||
player.SendDiffData()
|
||
jsonRet.Data.Count = player.Coin
|
||
} else if msg.Rpc == 2 {
|
||
WelfareMgrSington.PigbankGetInfo(player)
|
||
} else if msg.Rpc == 3 {
|
||
WelfareMgrSington.PigbankTakeCoin(player)
|
||
} else if msg.Rpc == 4 {
|
||
WelfareMgrSington.DayResetPigBank(player)
|
||
} else if msg.Rpc == 5 {
|
||
WelfareMgrSington.DiamondBankGetInfo(player)
|
||
} else if msg.Rpc == 6 {
|
||
WelfareMgrSington.DiamondBankTakeCoin(player)
|
||
} else if msg.Rpc == 7 {
|
||
player.WelfData.PigBank.BankCoin = msg.Bankcoin
|
||
player.WelfData.PigBank.DayBuyTimes = msg.Daybuytimes
|
||
} else if msg.Rpc == 8 {
|
||
player.WelfData.DiamondBank.BankDiamond = float64(msg.Bankcoin)
|
||
player.WelfData.DiamondBank.DayBuyTimes = msg.Daybuytimes
|
||
} else if msg.Rpc == 9 {
|
||
addCoin, _ := strconv.ParseInt(msg.Count, 10, 64)
|
||
player.AddDiamond(addCoin, 0, 5555, "platform", "dubeg加钻石")
|
||
player.SendDiffData()
|
||
jsonRet.Data.Count = player.Diamond
|
||
}
|
||
|
||
jsonDataRsp, err = json.Marshal(jsonRet)
|
||
tNode.TransRep.RetFiels = jsonDataRsp
|
||
tNode.Resume()
|
||
}), "/api/game/debug").Start()
|
||
}
|
||
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
|
||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/game/exchange_create", WebAPIHandlerWrapper(
|
||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||
pack := &webapiproto.SAWebCreateExchange{
|
||
Tag: webapiproto.ExchangeCreateCode_OPRC_Error,
|
||
}
|
||
msg := &webapiproto.ASWebCreateExchange{}
|
||
var err error
|
||
err = proto.Unmarshal(params, msg)
|
||
if err != nil || msg.Amount <= 0 || msg.Amount > 100 {
|
||
logger.Logger.Errorf("/api/game/exchange_create Unmarshal err: %v", err)
|
||
return common.ResponseTag_ParamError, pack
|
||
}
|
||
|
||
logger.Logger.Tracef("/api/game/exchange_create %v", msg)
|
||
|
||
var pd *model.PlayerData
|
||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||
p := PlayerMgrSington.GetPlayerBySnId(msg.GetSnId())
|
||
if p == nil {
|
||
pd, _ = model.GetPlayerDataBySnId(msg.GetPlatform(), msg.GetSnId(), false, false)
|
||
} else {
|
||
pd = p.PlayerData
|
||
}
|
||
return nil
|
||
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
|
||
if pd == nil {
|
||
logger.Logger.Errorf("/api/game/exchange_create GetPlayerData err: %v", err)
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
return
|
||
}
|
||
|
||
_, f := BlackListMgrSington.CheckExchange(pd)
|
||
if !f {
|
||
logger.Logger.Errorf("/api/game/exchange_order Unmarshal err: %v", err)
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
return
|
||
}
|
||
|
||
ShopMgrSington.Exchange(&ExchangeParam{
|
||
Platform: msg.GetPlatform(),
|
||
SnId: msg.GetSnId(),
|
||
VipLevel: pd.VIP,
|
||
Tel: pd.Tel,
|
||
Name: pd.Name,
|
||
PackageId: pd.PackageID,
|
||
ExchangeTypeId: msg.GetExchangeTypeId(),
|
||
Id: msg.GetId(),
|
||
UserName: msg.GetUserName(),
|
||
Mobile: msg.GetMobile(),
|
||
Address: msg.GetComment(),
|
||
Num: msg.GetAmount(),
|
||
GiveType: msg.GetExchangeType(),
|
||
TelId: msg.GetTelId(),
|
||
CallBackFunc: func(code shop.OpResultCode) {
|
||
pack.Tag = webapiproto.ExchangeCreateCode(code)
|
||
pack.Id = msg.GetId()
|
||
logger.Logger.Tracef("/api/game/exchange_create return %v", pack)
|
||
tNode.TransRep.RetFiels = pack
|
||
tNode.Resume()
|
||
},
|
||
})
|
||
}), "exchange_create").Start()
|
||
return common.ResponseTag_TransactYield, pack
|
||
}))
|
||
}
|
||
|
||
type playerDataParam struct {
|
||
P *model.PlayerData
|
||
Season *model.PlayerRankSeason
|
||
Items *model.BagInfo
|
||
}
|
||
|
||
func getPlayerDataParam(param *playerDataParam) *model.WebPlayerDataParam {
|
||
if param.P == nil {
|
||
return nil
|
||
}
|
||
|
||
data := PlatformMgrSingleton.GetConfig(param.P.Platform).PlayerPool
|
||
|
||
rankScore := make(map[int64]int64)
|
||
if param.Season == nil {
|
||
rankScore = RankMgrSingleton.GetPlayerRankScoreInt64(param.P.SnId)
|
||
} else {
|
||
for k, v := range param.Season.RankType {
|
||
if v != nil {
|
||
rankScore[int64(k)] = v.Score
|
||
}
|
||
}
|
||
}
|
||
var long, permitScore int64
|
||
var items []*model.WebItem
|
||
if param.Items == nil {
|
||
b := BagMgrSingleton.GetBagInfo(param.P.SnId)
|
||
for _, v := range b.BagItem {
|
||
e := srvdata.GameItemMgr.Get(param.P.Platform, v.ItemId)
|
||
if e == nil || v.ItemNum <= 0 {
|
||
continue
|
||
}
|
||
items = append(items, &model.WebItem{
|
||
Id: int64(e.Id),
|
||
N: v.ItemNum,
|
||
Name: e.Name,
|
||
})
|
||
if e.Id == common.ItemIDLong {
|
||
long += v.ItemNum
|
||
}
|
||
if e.Id == common.ItemIDPermit {
|
||
permitScore += v.ItemNum
|
||
}
|
||
}
|
||
} else {
|
||
for _, v := range param.Items.BagItem {
|
||
e := srvdata.GameItemMgr.Get(param.P.Platform, v.ItemId)
|
||
if e == nil || v.ItemNum <= 0 {
|
||
continue
|
||
}
|
||
items = append(items, &model.WebItem{
|
||
Id: int64(e.Id),
|
||
N: v.ItemNum,
|
||
Name: e.Name,
|
||
})
|
||
if e.Id == common.ItemIDLong {
|
||
long += v.ItemNum
|
||
}
|
||
if e.Id == common.ItemIDPermit {
|
||
permitScore += v.ItemNum
|
||
}
|
||
}
|
||
}
|
||
|
||
//人物加成
|
||
award := int32(0)
|
||
level := param.P.Roles.ModUnlock[2000002]
|
||
if level > 0 {
|
||
roleInfo := srvdata.RolePetMgrSington.GetRoleByRoleIdAndLevel(2000002, level)
|
||
if roleInfo != nil {
|
||
award = roleInfo.Award
|
||
}
|
||
}
|
||
vipAdded := VipMgrSington.GetVipDiamondExtra(param.P.Platform, param.P.VIP)
|
||
var vipExp int64
|
||
vipConfig := VipMgrSington.GetVIPcfg(param.P.Platform)
|
||
if vipConfig != nil {
|
||
vipExp = int64(float64(param.P.MoneyPayTotal) * vipConfig.MoneyRatio)
|
||
}
|
||
ret := &model.WebPlayerDataParam{
|
||
PlayerData: param.P,
|
||
RankScore: rankScore,
|
||
PlayerPoolUpper: param.P.GetPoolUpper(data),
|
||
PlayerPoolLower: param.P.GetPoolLower(data),
|
||
PlayerPoolCurrent: param.P.GetPoolCurrent(),
|
||
PlayerPoolOdds: param.P.GetPoolOdds(data),
|
||
RoleAdded: int64(award),
|
||
VipAdded: int64(vipAdded),
|
||
VipExp: vipExp,
|
||
Items: items,
|
||
IsPermit: !param.P.Permit.IsZero(),
|
||
Long: long,
|
||
PermitScore: permitScore,
|
||
}
|
||
|
||
return ret
|
||
}
|