Search Unity

(Mobile) How can I make hourly and daily rewards but without the player being able to cheat? (C#)

Discussion in 'Scripting' started by Gametide, Aug 21, 2018.

  1. Gametide

    Gametide

    Joined:
    Jul 17, 2018
    Posts:
    3
    Hello,
    I currently have a system that rewards the player hourly and daily on a mobile game but the problem is, the user can change tjhe phone's time/date settings and cheat to get rewards. How can I make it so that the user can't cheat but I don't want to require internet from the user. I work with C#.

    - Thanks.
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    You should consider using option of play time, rather than relay on OS time, to get datetime.
     
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    You need to connect to a server and check the time there, saving the player's data in the server should help with that (last time login, last time received reward, etc.)
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
     
  5. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Yeah i saw that, but i don't think there's another option where players can't cheat.

    you can save the data locally like you said but it's not secure as having a server checking to see you're not cheating.

    i assume you do that for a game where you have IAP, so you gotta have the interwebz for that, and most players today can login to the internet atleast once a day
     
  6. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    338
  7. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    While this makes sense from application logical point of view, I would be highly discouraging having ruing anything in background, while game is off. Specially on mobile devices. People my eventually find out running background process, and raise concerns on suspicious activities, resulting in app bad reviews.

    Just out of interest on the side note, Fallout Shelter is one of bad examples, of having OS daytime dependency, where changing OS time, can shift game time forward. But don't recognizes OS time moving backwards, when user changes it.
    Thats even during game play.
     
  8. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    338
    You're right, it's possible, but not the best thing to do.
    Anti-cheating in general is a hard thing to do that should be avoided if the game is not online and there is no real need for.
     
    SparrowGS likes this.
  9. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    This would be true, back days, before whole micro translation idiocracy came to light.

    Mentioned by me Follut Sheltter example, uses cheap dirty tricks, which "ask" players to buy stuff, to accelerate the game. It don't store game status on the server, but locally. Only connect to server, when you want spend real money. Players not aware of this, tends to spend money, as they are inpatient, to wait 1 2 hours, or 10 days.

    So my point is, devs/studios/publisher makes cheap dirty move, to not having server handling cost, for player data, while player technically plays strictly offline game. And yet, they want players to not to cheat. Therefore, here is a need for anti hack methods for offline gaming. And I am not supporting such methods in general.

    For me, if you play strictly offline, it should not be matter, whether you cheat, or not. players should be able to make fun play as they want. While online competitive gaming is completely opposite story.
     
  10. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,420
    I think you can use GPS LocationServices without Internet. (GPS itself doesn't need it but the phone APIs might demand it for "accuracy.") If this is true, LocationInfo includes a UTC timestamp which is unrelated to your device's time settings. Give it a try.
     
  11. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Providing GPS service is running. Many turning it off, for battery saving. Then game is stuffed. Not the ideal solution.
     
  12. TSC

    TSC

    Joined:
    Oct 15, 2012
    Posts:
    271
    Would it be too much to setup an in game timer with "elapsed time tracker" and a "time it takes to counter" and if "elapsed time" is not greater than the "time it takes to" continue, if it is greater reward player and reset "elapsed time tracker" ????
     
  13. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    What you exactly mean by elapsed time tracker, other than what has been already mentioned?
     
  14. TSC

    TSC

    Joined:
    Oct 15, 2012
    Posts:
    271
    Maybe something like this, change the countdown function to Hourly countdown and add reward and add a function for daily or etc.. ??? will something like this work?


    Code (CSharp):
    1. // this is a script from a build of mine, maybe something like this but further customized and optimized
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5. using UnityEngine.UI;
    6. public class TurnTimmer : MonoBehaviour {
    7.     public float TimeRemaining = 0;
    8.     public float TurnTime = 0;
    9.     public float income;
    10.     public int TimeModifier;
    11.     public  UnityEngine.UI.Text TURS_LEFT_TimeText;
    12.     public GameObject TURS_LEFT_Timetext;
    13.     public GameObject AudioTriggerSound;
    14.     public int framesBeforeNextShot = 2;
    15.     public int currentShotFrame = 0;
    16.  
    17.     void CountDown(){
    18.         if(TimeRemaining <= 0){
    19.             TimeRemaining = TurnTime;
    20. // Add reward here
    21.             ResetTimmer();
    22.         }      
    23.         ShowTime();
    24.         if(TimeRemaining > 0){      
    25.             TimeRemaining = TimeRemaining - Time.deltaTime;          
    26.         }
    27.     }
    28.     void ResetTimmer(){
    29.         //GameObject.FindGameObjectWithTag("MoneyS").GetComponent(MoneySystem).curMoney = GameObject.FindGameObjectWithTag("MoneyS").GetComponent(MoneySystem).curMoney += income;      
    30.         if(currentShotFrame == 0){
    31.             GameObject audioTriggerSound;
    32.             audioTriggerSound =  (GameObject)Instantiate( AudioTriggerSound,this.transform.position, this.transform.rotation);
    33.             audioTriggerSound.transform.parent = this.transform;
    34.         }else{
    35.             currentShotFrame--;
    36.         }
    37.     }
    38.     void ShowTime(){
    39.  
    40.         float mintues = TimeRemaining/60;
    41.         float seconds = TimeRemaining%60;
    42.         string timeString = mintues.ToString ("00") + ":" + seconds.ToString("00");
    43.         TURS_LEFT_TimeText.text = timeString;
    44.     }
    45.     // Use this for initialization
    46.     void Start () {
    47.    
    48.     }
    49.     // Update is called once per frame
    50.     void Update () {
    51.         CountDown();
    52.     }
    53. }
    54.  
     
  15. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Yes, this looks like something I have mentioned earlier.

     
  16. TSC

    TSC

    Joined:
    Oct 15, 2012
    Posts:
    271
    yup, I guess play time / run time/ internal elapsed time means the same for us just from two different perspectives
     
  17. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    +1 to if it doesn't hurt you financially and the game is not online PVP you shouldn't care if players "cheat"
     
  18. Kapton_

    Kapton_

    Joined:
    Aug 3, 2018
    Posts:
    4
  19. Kapton_

    Kapton_

    Joined:
    Aug 3, 2018
    Posts:
    4
    I tried cheating by changing the time, but turning off the phone and getting out the battery and all of it with the internet and GPS off and I couldn't cheat.
     
  20. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    It is not possible to prevent cheating entirely on a single player game that does everything on the user's device. All you can do is make it more difficult. In the end though the people who go through the trouble of figuring out how to cheat in your game were not going to give you money anyway, so I don't see why going through a lot of trouble here is worth while.

    What you don't want to do though is punish your users who are not cheating. For example, don't run a background process to track time which will kill their battery life. Don't turn on their GPS just to get better time when your game isn't a location based game, which again will kill battery life. All you will do is really piss off the people who actually might have paid you some money.