public override async Task <GameService.GetGameEventsReply> GetGameEvents(GetGameEventsRequest request, ServerCallContext context) { try { var session = await context.GetSession(); if (session == null) { return(new GetGameEventsReply() { Code = ErrorCode.LostSession }); } var events = await GameEventQuery.Gets(session.member_no, session.user_no); // 이벤트 초기화 if (events.Count == 0) { var nextDate = DateTime.UtcNow.AddDays(1).Date; var endTime = new DateTime(nextDate.Year, nextDate.Month, nextDate.Day, 0, 0, 0, DateTimeKind.Utc); var game_event = new Models.GameEvent() { user_no = session.user_no, event_id = 1, reward = 0, occ_time = endTime, }; events.Add(game_event); await GameEventQuery.Add(session.member_no, game_event); } // 이벤트 목록 생성 var reply = new GetGameEventsReply(); reply.Code = ErrorCode.Success; foreach (var game_event in events) { reply.Events.Add(new EventInfo() { EventId = game_event.event_id, IsReward = (game_event.reward == 0 ? false : true), RewardStartTime = DateTime.SpecifyKind(game_event.occ_time, DateTimeKind.Utc).ToTimestamp(), RewardItemId = (int)GameItemId.OpenEventBox, }); } return(reply); } catch (Exception ex) { Log.Error($"GetGameEvents {ex.ToString()}"); return(new GetGameEventsReply() { Code = ErrorCode.WrongParam }); } }
public override async Task <GameService.GetRewardEventReply> GetRewardEvent(GetRewardEventRequest request, ServerCallContext context) { try { var session = await context.GetSession(); if (session == null) { return(new GetRewardEventReply() { Code = ErrorCode.LostSession }); } var reply = new GetRewardEventReply(); reply.AccountGoods = new Goods(); reply.Item = new ItemList(); await using (var mylock = await RedLock.CreateLockAsync($"lock:session:{session.session_id}")) { var events = await GameEventQuery.Gets(session.member_no, session.user_no); var gameEvent = events.Where(x => x.event_id == request.EventId).FirstOrDefault(); if (gameEvent == null || gameEvent == default(Models.GameEvent)) { return(new GetRewardEventReply() { Code = ErrorCode.NotExist }); } if (gameEvent.reward != 0) { return(new GetRewardEventReply() { Code = ErrorCode.AlreadyReward }); } if (gameEvent.occ_time > DateTime.UtcNow) { return(new GetRewardEventReply() { Code = ErrorCode.NotEnough }); } // 보상 지급 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, (int)GameItemId.OpenEventBox, 1, new LogReason("A_EVENT", gameEvent.event_id.ToString()), reply.Item); reply.AccountGoods.Set(user); } gameEvent.reward = 1; await GameEventQuery.Update(session.member_no, gameEvent); } reply.Code = ErrorCode.Success; return(reply); } catch (Exception ex) { Log.Error($"GetRewardEvent {ex.ToString()}"); return(new GetRewardEventReply() { Code = ErrorCode.WrongParam }); } }