You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
187 lines
7.5 KiB
187 lines
7.5 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
using Sog;
|
|
using ProtoCSStruct;
|
|
|
|
namespace World
|
|
{
|
|
//钻石托管处理,负责钻石(充值虚拟货币)的查询,增加,删除异步操作
|
|
public static class DiamondHolderSvc
|
|
{
|
|
//获取托管模式托管服务器的服务器id,缺省是gamedb,采用米大师的时候是httpproxyworld
|
|
public static uint GetHolderServerID(long uid)
|
|
{
|
|
return DBServerIDUtils.GetGameDBServerID(uid);
|
|
}
|
|
|
|
public static void OnPayDiamondHolderQueryReq(uint serverId, StructPacket packet)
|
|
{
|
|
long uid = packet.ObjectID;
|
|
|
|
TraceLog.Debug("DiamondHolderSvc.OnPayDiamondHolderQueryReq uid {0}", uid);
|
|
|
|
PlayerInfoWorld player = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(uid);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("DiamondHolderSvc.OnPayDiamondHolderQueryReq can not find player uid {0}", uid);
|
|
return;
|
|
}
|
|
|
|
uint holderServerId = GetHolderServerID(uid);
|
|
WorldServerUtils.GetPacketSender().SendToServerByID<SSPayDiamondHolderQueryReq>(holderServerId, packet);
|
|
}
|
|
|
|
public static void OnPayDiamondHolderQueryRes(uint serverId, StructPacket packet)
|
|
{
|
|
long uid = packet.ObjectID;
|
|
|
|
ref SSPayDiamondHolderQueryRes res = ref packet.GetMessage<SSPayDiamondHolderQueryRes>();
|
|
|
|
TraceLog.Debug("DiamondHolderSvc.OnPayDiamondHolderQueryRes uid {0} diamond {1}", uid, res.Diamond);
|
|
|
|
PlayerInfoWorld player = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(uid);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("DiamondHolderSvc.OnPayDiamondHolderQueryRes can not find player uid {0}", uid);
|
|
return;
|
|
}
|
|
|
|
//内存里保存一下,只读数据
|
|
player.roleBase.Diamond = res.Diamond;
|
|
|
|
WorldServerUtils.GetPacketSender().SendToServerByID<SSPayDiamondHolderQueryRes>(packet.ServerID, packet);
|
|
}
|
|
|
|
|
|
public static void OnPayDiamondHolderAddReq(uint serverId, StructPacket packet)
|
|
{
|
|
ref SSPayDiamondHolderAddReq req = ref packet.GetMessage<SSPayDiamondHolderAddReq>();
|
|
|
|
long uid = req.Uid;
|
|
|
|
TraceLog.Debug("DiamondHolderSvc.OnPayDiamondHolderAddReq uid {0}, orderid {1}", req.Uid, req.OrderId);
|
|
|
|
PlayerInfoWorld player = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(uid);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("DiamondHolderSvc.OnPayDiamondHolderAddReq can not find player uid {0}", uid);
|
|
return;
|
|
}
|
|
|
|
if(req.Mutex)
|
|
{
|
|
int ret = WaitAckDiamondHolderReqSender.Instance.CheckMutex(player);
|
|
if(ret != 0)
|
|
{
|
|
SSPayDiamondHolderAddRes res = new SSPayDiamondHolderAddRes();
|
|
res.OrderId = req.OrderId;
|
|
res.NewDiamond = 0;
|
|
res.Ret = -1;
|
|
res.Uid = req.Uid;
|
|
res.ReasonId = req.ReasonId;
|
|
WorldServerUtils.GetPacketSender().SendToServerByID<SSPayDiamondHolderAddRes>(player.GameServerID
|
|
, (int)SSGameMsgID.PayDiamondHolderAddRes, ref res, uid);
|
|
return;
|
|
}
|
|
}
|
|
|
|
//不管是否mutex都要加入队列
|
|
WaitAckDiamondHolderReqSender.Instance.BeginSendAdd(ref req, player);
|
|
}
|
|
|
|
public static void OnPayDiamondHolderAddRes(uint serverId, StructPacket packet)
|
|
{
|
|
ref SSPayDiamondHolderAddRes res = ref packet.GetMessage<SSPayDiamondHolderAddRes>();
|
|
|
|
long uid = res.Uid;
|
|
|
|
TraceLog.Debug("DiamondHolderSvc.OnPayDiamondHolderAddRes uid {0}, orderid {1}", res.Uid, res.OrderId);
|
|
|
|
if(res.Ret == 0)
|
|
{
|
|
WaitAckDiamondHolderReqSender.Instance.OnReceiveSuccess(uid,res.OrderId.GetString());
|
|
|
|
//发给game,不在线算了
|
|
PlayerInfoWorld player = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(uid);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("DiamondHolderSvc.OnPayDiamondHolderAddRes can not find player uid {0}", uid);
|
|
return;
|
|
}
|
|
|
|
WorldServerUtils.GetPacketSender().SendToServerByID<SSPayDiamondHolderAddRes>(player.GameServerID, packet);
|
|
}
|
|
else
|
|
{
|
|
//失败了,WaitAckDiamondHolderReqSender会重发
|
|
}
|
|
}
|
|
|
|
public static void OnPayDiamondHolderCostReq(uint serverId, StructPacket packet)
|
|
{
|
|
ref SSPayDiamondHolderCostReq req = ref packet.GetMessage<SSPayDiamondHolderCostReq>();
|
|
|
|
long uid = req.Uid;
|
|
|
|
TraceLog.Debug("DiamondHolderSvc.OnPayDiamondHolderCostReq uid {0}, orderid {1}", req.Uid, req.OrderId);
|
|
|
|
PlayerInfoWorld player = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(uid);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("DiamondHolderSvc.OnPayDiamondHolderCostReq can not find player uid {0}", uid);
|
|
return;
|
|
}
|
|
|
|
//cost是一定要mutex的
|
|
int ret = WaitAckDiamondHolderReqSender.Instance.CheckMutex(player);
|
|
if (ret != 0)
|
|
{
|
|
SSPayDiamondHolderCostRes res = new SSPayDiamondHolderCostRes();
|
|
res.OrderId = req.OrderId;
|
|
res.NewDiamond = 0;
|
|
res.Ret = -1;
|
|
res.Uid = req.Uid;
|
|
|
|
WorldServerUtils.GetPacketSender().SendToServerByID<SSPayDiamondHolderCostRes>(player.GameServerID
|
|
, (int)SSGameMsgID.PayDiamondHolderCostRes, ref res, uid);
|
|
return;
|
|
}
|
|
|
|
//加入mutex队列
|
|
WaitAckDiamondHolderReqSender.Instance.AddToMutex(uid, req.OrderId.GetString());
|
|
|
|
uint holderServerId = GetHolderServerID(uid);
|
|
WorldServerUtils.GetPacketSender().SendToServerByID<SSPayDiamondHolderCostReq>(holderServerId, packet);
|
|
}
|
|
|
|
public static void OnPayDiamondHolderCostRes(uint serverId, StructPacket packet)
|
|
{
|
|
ref SSPayDiamondHolderCostRes res = ref packet.GetMessage<SSPayDiamondHolderCostRes>();
|
|
|
|
long uid = res.Uid;
|
|
|
|
TraceLog.Debug("DiamondHolderSvc.OnPayDiamondHolderCostRes uid {0}, orderid {1}", res.Uid, res.OrderId);
|
|
|
|
//不管成功失败,需要删除mutex
|
|
WaitAckDiamondHolderReqSender.Instance.RemoveMutexOrderId(uid, res.OrderId.GetString());
|
|
//不管成功失败,发给game,也许要rollback
|
|
WorldServerUtils.GetPacketSender().SendToServerByID<SSPayDiamondHolderCostRes>(packet.ServerID, packet);
|
|
}
|
|
|
|
public static void OnPayDiamondHolderCostCancelReq(uint serverId, StructPacket packet)
|
|
{
|
|
ref SSPayDiamondHolderCostCancelReq req = ref packet.GetMessage<SSPayDiamondHolderCostCancelReq>();
|
|
|
|
long uid = req.Uid;
|
|
|
|
TraceLog.Debug("DiamondHolderSvc.OnPayDiamondHolderCostCancelReq uid {0}, orderid {1}", req.Uid, req.OrderId);
|
|
|
|
//回滚直接转给holder
|
|
uint holderServerId = GetHolderServerID(uid);
|
|
WorldServerUtils.GetPacketSender().SendToServerByID<SSPayDiamondHolderCostCancelReq>(holderServerId, packet);
|
|
}
|
|
}
|
|
}
|
|
|