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(holderServerId, packet); } public static void OnPayDiamondHolderQueryRes(uint serverId, StructPacket packet) { long uid = packet.ObjectID; ref SSPayDiamondHolderQueryRes res = ref packet.GetMessage(); 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(packet.ServerID, packet); } public static void OnPayDiamondHolderAddReq(uint serverId, StructPacket packet) { ref SSPayDiamondHolderAddReq req = ref packet.GetMessage(); 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(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(); 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(player.GameServerID, packet); } else { //失败了,WaitAckDiamondHolderReqSender会重发 } } public static void OnPayDiamondHolderCostReq(uint serverId, StructPacket packet) { ref SSPayDiamondHolderCostReq req = ref packet.GetMessage(); 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(player.GameServerID , (int)SSGameMsgID.PayDiamondHolderCostRes, ref res, uid); return; } //加入mutex队列 WaitAckDiamondHolderReqSender.Instance.AddToMutex(uid, req.OrderId.GetString()); uint holderServerId = GetHolderServerID(uid); WorldServerUtils.GetPacketSender().SendToServerByID(holderServerId, packet); } public static void OnPayDiamondHolderCostRes(uint serverId, StructPacket packet) { ref SSPayDiamondHolderCostRes res = ref packet.GetMessage(); 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(packet.ServerID, packet); } public static void OnPayDiamondHolderCostCancelReq(uint serverId, StructPacket packet) { ref SSPayDiamondHolderCostCancelReq req = ref packet.GetMessage(); long uid = req.Uid; TraceLog.Debug("DiamondHolderSvc.OnPayDiamondHolderCostCancelReq uid {0}, orderid {1}", req.Uid, req.OrderId); //回滚直接转给holder uint holderServerId = GetHolderServerID(uid); WorldServerUtils.GetPacketSender().SendToServerByID(holderServerId, packet); } } }