1 Star 0 Fork 0

liuxuezhan / mylib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
CSMsgProcess.go 7.82 KB
一键复制 编辑 原始数据 按行查看 历史
liuxuezhan 提交于 2020-12-19 16:15 . 'ok'
package logic
import (
"fmt"
"strings"
"gitee.com/liuxuezhan/mylib/GameServer/CSV"
"gitee.com/liuxuezhan/mylib/GameServer/cache"
"gitee.com/liuxuezhan/mylib/GameServer/observer"
"gitee.com/liuxuezhan/mylib/GameServer/oss"
proto "gitee.com/liuxuezhan/mylib/Protocol"
"gitee.com/liuxuezhan/mylib/Utils/wlog"
"gitee.com/liuxuezhan/mylib/common"
)
func CSGMCommand(command *proto.ST_CS2GS_GMCommand) *proto.ST_GS2CS_GMCommand_Result {
respon := &proto.ST_GS2CS_GMCommand_Result{
OperatorId: proto.SetInt64(command.GetOperatorId()),
}
err, result := ExeGMCommand(command.GetCommand(), command.GetParams())
if err != nil {
respon.Status = proto.SetInt32(0)
respon.Msg = proto.SetString(strings.ReplaceAll(err.Error(), "\n", ""))
respon.Result = proto.SetString("")
} else {
respon.Status = proto.SetInt32(1)
respon.Msg = proto.SetString("")
respon.Result = proto.SetString(result)
}
return respon
}
func CSPay(payReq *proto.ST_CS2GS_Pay) *proto.ST_GS2CS_Pay {
result := Pay(payReq.GetPayType(), payReq.GetUid(), payReq.GetGiftPackageId(), payReq.GetProductId(),
payReq.GetOrderId(), payReq.GetCurPay(), payReq.GetEndTimeStamp(), payReq.GetLuckyStarItemId())
resp := &proto.ST_GS2CS_Pay{
OperatorId: proto.SetInt64(payReq.GetOperatorId()),
Msg: proto.SetString(result),
}
return resp
}
var ProducttoPrice = map[int64]int32{
1: 99,
11: 149,
7: 199,
8: 299,
2: 499,
3: 999,
12: 1499,
4: 1999,
9: 2999,
5: 4999,
6: 9999,
}
func Pay(payType uint32, uid uint64, giftPackageId int64, productId, orderId string, totalPay float64, endTimeStamp uint64, luckyStarItemId uint32) string {
wlog.Info("Pay request, Uid: ", uid, " payType: ", payType, " GiftPackageId: ", giftPackageId, " SubId: ", luckyStarItemId, " productId: ", productId,
" orderID: ", orderId, " Total: ", totalPay, " endTimeStamp: ", endTimeStamp)
userData := cache.GetCharinfo(uid)
if nil == userData {
wlog.Error("Pay err, can't found user ", uid)
return "fail"
}
if payType == 1 {
conf := CSV.Mgr.CSV_GiftList.GetEntryPtr(giftPackageId)
if conf == nil {
wlog.Error(fmt.Sprintf("Pay err, user(%v , %v) gift package id(%v) err", userData.GetUid(), userData.GetUserName(), giftPackageId))
return "fail"
}
if conf.ProductId != productId {
wlog.Error(fmt.Sprintf("Pay err, user(%v , %v) product_id id(%v) err", userData.GetUid(), userData.GetUserName(), productId))
return "fail"
}
//从毫秒转化成秒
endTimeStamp = endTimeStamp / 1000
if GiftPackPurchase(userData, uint64(giftPackageId), endTimeStamp, orderId, false) != proto.RetActionType_RAT_SUCCESS {
wlog.Error(fmt.Sprintf("Pay err, user(%v , %v) purchase giftPackageId(%v) fail", userData.GetUid(), userData.GetUserName(), giftPackageId))
return "fail"
}
userData.SetPayHistory(uint64(giftPackageId))
if false == userData.IsSamePayTime() {
day := userData.AddKeepPayDay()
CheckAllGiftSaleCondition(userData, proto.GiftConditionType_GCT_KEEP_PAY, day)
}
userData.SetGiftPackOrderId(orderId)
userData.DirtyAll()
CheckAllGiftSaleCondition(userData, proto.GiftConditionType_GCT_LABEL, int64(userData.GetCurLabel()))
return "success"
} else if payType == 2 {
return LuckyStarPurchase(userData, uid, giftPackageId, luckyStarItemId, orderId)
} else if payType == 3 {
id, name := userData.BuyOfferGift(giftPackageId, int64(luckyStarItemId))
if id != 0 {
userData.SetGiftPackOrderId(orderId)
if price, ok := ProducttoPrice[id]; ok {
giftEntry := &CSV.CF_GiftList_DataEntry{ID: int64(luckyStarItemId), PackagePrice: fmt.Sprintf("%.2f", float64(price)/100)}
observer.ObserverSingleton.AsyncNotify(observer.PurchaseItemsEvent, []interface{}{userData})
userData.AddPayHistory(uint64(price), name)
CheckAllGiftSaleCondition(userData, proto.GiftConditionType_GCT_LABEL, int64(userData.GetCurLabel()))
newOssBuyGift(userData, giftEntry, orderId)
}
CheckAllGiftSaleCondition(userData, proto.GiftConditionType_GCT_LABEL, int64(userData.GetCurLabel()))
return "success"
}
}
wlog.Error(fmt.Sprintf("Pay err, user(%v, %v), pay type %v err", uid, userData.GetUserName(), payType))
return "fail"
}
func LuckyStarPurchase(userData *cache.Info, uid uint64, giftPackageId int64, luckyStarItemId uint32, orderId string) string {
luckyStar := cache.Instance_GlobalAssetLuckyStar.GetCurLuckyStar()
if nil == luckyStar {
wlog.Error("Pay err, user(%v , %v), current luckystar is nil", uid, userData.GetUserName())
return "fail"
}
if luckyStar.GetId() != uint32(giftPackageId) {
wlog.Error(fmt.Sprintf("Pay err, user(%v , %v) purchase luckyStar giftPackageId(%v) fail", userData.GetUid(), userData.GetUserName(), giftPackageId))
return "fail"
}
var item *proto.ST_LuckyStarItem_PB
for _, v := range luckyStar.GetItems() {
if v.GetId() == luckyStarItemId {
item = v
break
}
}
if item == nil {
wlog.Error(fmt.Sprintf("Pay err, user(%v , %v) purchase luckyStar can`t find item %v err fail", userData.GetUid(), userData.GetUserName(), luckyStarItemId))
return "fail"
}
result := "fail"
userData.WithLuckyStarAsset(false, func(pbs map[uint32]*proto.ST_LuckyStar_Server_PB) bool {
tmp := pbs[luckyStar.GetId()]
if tmp == nil {
return false
}
for _, v1 := range tmp.Items {
if v1.GetId() == luckyStarItemId {
if v1.GetBuyTimes() >= item.GetCanBuyTimes() {
wlog.Error(fmt.Sprintf("Pay err, user(%v , %v) purchase luckyStar buyTimes err (%v, %v) fail", userData.GetUid(), userData.GetUserName(), v1.GetBuyTimes(), item.GetCanBuyTimes()))
return false
}
v1.BuyTimes = proto.SetUint32(v1.GetBuyTimes() + 1)
userData.SetGiftPackOrderId(orderId)
userData.DirtyAll()
result = "success"
if price, ok := proto.LuckyStarProductID_value[item.GetProductId()]; ok {
giftEntry := &CSV.CF_GiftList_DataEntry{ID: 9999999, PackagePrice: fmt.Sprintf("%.2f", float64(price)/100)}
userData.AddPayHistory(uint64(price), 0)
newOssBuyGift(userData, giftEntry, orderId)
giftEntry.ID = int64(luckyStarItemId)
newOssLuckyStar(userData, giftEntry, orderId, luckyStar.GetId())
}
return true
}
}
wlog.Error(fmt.Sprintf("Pay err, user(%v , %v) purchase luckyStar can`t find item %v err fail", userData.GetUid(), userData.GetUserName(), luckyStarItemId))
return false
})
if result == "success" {
//发个奖励邮件
v4Reward := make([]*proto.ST_Vector4Int_PB, 0)
for _, v := range item.GetItems() {
v4Reward = append(v4Reward, &proto.ST_Vector4Int_PB{
X: proto.SetInt32(2),
Y: proto.SetInt32(v.GetX()),
W: proto.SetInt32(v.GetY()),
})
}
userData.AddVec4ResourceListWithSource(v4Reward, 1, oss.AddCashScrTypeLuckyStar, uint64(76882))
rewList := &proto.ST_MailRewardList_PB{}
for _, item := range v4Reward {
rewList.Reward = append(rewList.Reward, item)
}
rewardStr := proto.Marshal(rewList)
title := common.CreateTips(76889)
content := common.CreateTips(76890)
userData.SendConfMailAssetEx(uint32(proto.MailSourceType_MST_GiftPack), uint32(proto.MailType_MT_SYSTEM), title, content, string(rewardStr), oss.MRS_LuckStar)
}
return result
}
func ChangeServerRequest(req *proto.ST_ChangeServer_Request) *proto.ST_ChangeServer_Response {
ret := ProcessChangeServerRequest(req)
respon := &proto.ST_ChangeServer_Response{
Result: proto.SetInt32(int32(ret)),
Uid: proto.SetUint64(req.GetUid()),
Sid: proto.SetInt64(req.GetSid()),
FromSid: proto.SetInt64(req.GetFromSid()),
Type: proto.SetInt32(req.GetType()),
}
return respon
}
func TBTransferServerRequest(req *proto.ST_TBTransferServer_Request) *proto.ST_TBTransferServer_Response {
ret := ProcessTBTransferServerRequest(req)
respon := &proto.ST_TBTransferServer_Response{
Result: proto.SetUint32(uint32(ret)),
Uid: proto.SetUint64(req.GetUid()),
Sid: proto.SetUint32(req.GetSid()),
FromSid: proto.SetUint32(req.GetFromSid()),
Type: proto.SetUint32(req.GetType()),
}
return respon
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liuxuezhan/mylib.git
git@gitee.com:liuxuezhan/mylib.git
liuxuezhan
mylib
mylib
v1.1.1

搜索帮助

344bd9b3 5694891 D2dac590 5694891