겨울팥죽 여름빙수

 게임 서비스를 운영하다보면, 핸드폰 기기 시간을 수정해, 이익을 보려는 유저들이 많다.

 

보통 일정 시간 주기로 보상을 주는 기능이 들어간 경우, 그 시간값을 서버가 아닌 클라이언트에서 한다면, 유저는 기기시간 조절하는 것만으로도 보상을 빠르게 받을 수 있다.

 

 서버에서 시간을 확인해 막으면 좋지만, 그렇게하기 여의치 않을 경우,

 

  • Resume 시
  • 보상을 받기 위한 버튼을 눌렀을 때

 

 구글 표준시간과 비교해 처리하면 좋다.

 

<c++ />
//구글 시간 가져오기 public async Task<DateTimeOffset?> GetCurrentTime() { using (var client = new HttpClient()) { try { var result = await client.GetAsync("https://google.com", HttpCompletionOption.ResponseHeadersRead); return result.Headers.Date; } catch { return null; } } } //가져와서 내 기기시간과 비교 private async Task<bool> checkInternetTime() { try { DateTimeOffset? google_time = await GetCurrentTime(); if (google_time != null) { TimeSpan time_span = DateTime.UtcNow - google_time.Value.UtcDateTime; m_google_time = google_time.Value.UtcDateTime; //1시간 이상 이나면 false if (Math.Abs(time_span.TotalHours) > 1) { return false; } else return true; } else { return false; LogManager.Debug("fail google_time"); } } catch (Exception e) { return false; } }

 

 위 코드는 구글 시간과 내 기기 시간을 비교해, 1시간 내이면 true, 아니면 false를 리턴하게 했다. 위 코드를 아래와 같이 처리해, 시간을 확인해야하는 곳곳에 사용하면 된다.

 

<c++ />
public void CheckInternetTime(UnityAction action) { Task<bool> result_time = checkInternetTime(); PopupManager.Instance.ShowPopup(PopupType.POPUP_WAIT); result_time.ContinueWith((p) => { //비동기 작업이 끝났을 때 실행된다. if (p.Result) { // 시간이 맞을 경우 처리 action(); //보통 람다로 받아서 처리해버림 } else { //시간이 안맞을 경우 처리 } }, TaskContinuationOptions.ExecuteSynchronously); }

 

 

profile

겨울팥죽 여름빙수

@여름빙수

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!