0
\$\begingroup\$

I am building a game in Unity and store data on a .NET server. I was wonder what the best approach to validating the game data before posting the scores to the .NET server.

The game is somewhat deterministic and I know I have to simulate the game on the server to some extent to properly validate the game. This simulated game would have to run extremely quick as well.

This is where I am having trouble. In unity I have various colliders that are used to determine things like range and when to take damage and I have no idea how to "simulate" this in a .NET enviroment. I was wondering if there are any resources out there or tutorials out there. I have tried to find one but I don't think I am using the right keywords.

I am guessing this would be similar to how games like Clash of Clans validates their attacks.

\$\endgroup\$
  • \$\begingroup\$ It's difficult for us to tell you how to simulate something when all we have to go on is that it somehow involves colliders (of which Unity has over a half dozen varieties). Try asking about one mechanic at a time, in enough detail that we can help you find formulas to calculate it. \$\endgroup\$ – DMGregory May 1 '17 at 20:13
  • \$\begingroup\$ @DMGregory I understand I am probably breaking some rules here, but I was a little desperate and just needed some info to get myself headed in the right direction. I am very new to game development. I will be posting a lot more specific questions moving forward. \$\endgroup\$ – David Lee May 1 '17 at 20:32
1
\$\begingroup\$

If you are using Unity colliders and use collisions from them to control the simulation, chances are you don't have a deterministic simulation. You have a few options to deal with that:

  • Make it deterministic. Generally this means a fixed timestep and doing all calculations with fixed-point math instead of floating-point. This probably means writing your own physics engine, so unless the simulation is really simple it's probably going to be a lot of work, but here are a few resources that might be helpful: Floating Point Determinism, Lockstep Implementation in Unity3D.
  • Minimize non-determinism and hope for the best. I don't have much experience with this, but I'm sure lots of people have tried. You'll probably need to have generous leeway to avoid false positives when trying to detect cheaters, which means some might slip through, and the butterfly effect means you'll likely never be able to prevent all false-positives.

If you do manage to solve the determinism problem, you may still be left with a server performance problem. Luckily, the solution for that is simple. Just let the server randomly decide whether to validate a particular "round" of gameplay. If you don't validate it, you can just assume that the player is honest. Some additional layers of complexity you might want to consider:

  • Increase the chance of validation for a particular player every time the server skips doing it (but it should still be mostly random to prevent hostile players being able to predict which ones will be validated).
  • If a player fails a validation, place them on probation and validate every subsequent event for that player for a certain amount of time.
  • If a player repeatedly fails validation, just permaban them.
  • Vary the chance to do a validation based on server load. During off-peak hours, you can afford to spend more server time validating.
  • Store data for unvalidated actions in a database, and provide a tool to do validation and remediation of previous results.
  • Make a tool that allows a human to replay what the player did. This helps triage reported abuse even if your simulation isn't deterministic at all; data from cheaters is probably going to look really obvious.
  • If you can't make the entire simulation deterministic, just validate the parts that are deterministic. For example, if a unit normally does 50 damage, but in the replay it does 10,000...

In the end it's up to you how much time, effort, and money you want to spend dealing with cheaters.

\$\endgroup\$
  • \$\begingroup\$ Thank you for this answer, a lot of good info here. I only use the colliders to determine range and when to deal damage. If I use some calculus to figure the range out and make damage instant instead of when the actual projectile hits the target I think I can accomplish a deterministic game. I was just hoping there was some way I could import the Unity project into my .NET web application and be able to run the same game in a fraction of the time and compare the results, but it looks like this isn't possible. Thanks again. \$\endgroup\$ – David Lee May 1 '17 at 20:01
  • 1
    \$\begingroup\$ @DavidLee it is possible to run a Unity application in a "headless" mode for servers, where rendering is skipped in order to update gameplay behaviour as fast as possible. Is this an option in your case? It may help unify your codebase, so you don't need to keep two separate projects in sync with each change to your game. \$\endgroup\$ – DMGregory May 1 '17 at 20:33
  • \$\begingroup\$ @DMGregory This sounds like something that could be very beneficial. I have never heard of this so I will research this headless mode and see if it works for my project. \$\endgroup\$ – David Lee May 1 '17 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.