Beispiel #1
0
        public override async Task <GameService.GetAdvertisementRewardsReply> GetAdvertisementRewards(GetAdvertisementRewardsRequest request, ServerCallContext context)
        {
            try
            {
                var session = await context.GetSession();

                if (session == null)
                {
                    return(new GetAdvertisementRewardsReply()
                    {
                        Code = ErrorCode.LostSession
                    });
                }

                var rewards = await AdvertisementRewardQuery.Gets(session.member_no, session.user_no);

                var currentTime = DateTime.UtcNow;
                var reply       = new GetAdvertisementRewardsReply();
                reply.Code = ErrorCode.Success;
                foreach (var reward in rewards)
                {
                    var adData = ACDC.AdListData[reward.advertisement_id];
                    if (adData == null || adData == default(JAdListData))
                    {
                        continue;
                    }

                    if (core.MathHelpers.GetResetTime(adData.ResetTime, reward.occ_time) != core.MathHelpers.GetResetTime(adData.ResetTime, currentTime))
                    {
                        continue;
                    }

                    reply.AdvertisementRewards.Add(new AdvertisementRewardInfo()
                    {
                        AdvertisementId = reward.advertisement_id,
                        RewardCount     = reward.reward,
                    });
                }

                return(reply);
            }
            catch (Exception ex)
            {
                Log.Error($"GetGameEvents {ex.ToString()}");

                return(new GetAdvertisementRewardsReply()
                {
                    Code = ErrorCode.WrongParam
                });
            }
        }
Beispiel #2
0
        public override async Task <GameService.RewardAdvertisementReply> RewardAdvertisement(RewardAdvertisementRequest request, ServerCallContext context)
        {
            try
            {
                var session = await context.GetSession();

                if (session == null)
                {
                    return(new RewardAdvertisementReply()
                    {
                        Code = ErrorCode.LostSession
                    });
                }

                var adData = ACDC.AdListData[request.AdvertisementId];
                if (adData == null || adData == default(JAdListData))
                {
                    return(new RewardAdvertisementReply()
                    {
                        Code = ErrorCode.WrongParam
                    });
                }

                bool is_insert = false;

                var reply = new RewardAdvertisementReply();
                reply.AccountGoods = new Goods();
                reply.Item         = new ItemList();
                var currentTime = DateTime.UtcNow;
                int RewardCount = 0;
                await using (var mylock = await RedLock.CreateLockAsync($"lock:session:{session.session_id}"))
                {
                    var rewards = await AdvertisementRewardQuery.Gets(session.member_no, session.user_no);

                    var reward = rewards.Where(x => x.advertisement_id == request.AdvertisementId).FirstOrDefault();
                    if (reward == null || reward == default(Models.AdvertisementReward))
                    {
                        is_insert = true;
                        reward    = new AdvertisementReward()
                        {
                            user_no          = session.user_no,
                            advertisement_id = adData.Id,
                            reward           = 0,
                            occ_time         = currentTime,
                        };
                    }
                    else
                    {
                        // refresh
                        if (core.MathHelpers.GetResetTime(adData.ResetTime, reward.occ_time) != core.MathHelpers.GetResetTime(adData.ResetTime, currentTime))
                        {
                            reward.occ_time = currentTime;
                            reward.reward   = 0;
                        }
                    }

                    if (reward.reward >= adData.ViewLimit)
                    {
                        return(new RewardAdvertisementReply()
                        {
                            Code = ErrorCode.OverLimit
                        });
                    }

                    // 보상 지급
                    await using (var user = await UserCache.GetUser(session.member_no, session.user_no, true, true, false))
                        await using (var character = await CharacterCache.Instance.GetEntity(session.member_no, session.character_no, true, true, false))
                        {
                            await Inventory.Insert(session, user, character, adData.ItemId, adData.Count, new LogReason("A_AD", adData.Id.ToString()), reply.Item, null, adData.Id.ToString());

                            reply.AccountGoods.Set(user);
                        }

                    ++reward.reward;
                    RewardCount     = reward.reward;
                    reward.occ_time = currentTime;
                    if (is_insert)
                    {
                        await AdvertisementRewardQuery.Add(session.member_no, reward);
                    }
                    else
                    {
                        await AdvertisementRewardQuery.Update(session.member_no, reward);
                    }

                    _ = LogProxy.writeActionLog(session, "광고시청", "광고", adData.Id.ToString()).ConfigureAwait(false);
                }

                reply.Code            = ErrorCode.Success;
                reply.RewardCount     = RewardCount;
                reply.AdvertisementId = request.AdvertisementId;
                return(reply);
            }
            catch (Exception ex)
            {
                Log.Error($"GetRewardEvent {ex.ToString()}");

                return(new RewardAdvertisementReply()
                {
                    Code = ErrorCode.WrongParam
                });
            }
        }