Saturday, May 18, 2024
HomeGame Developmentunity - Checking combat on the server to prevent cheating - how...

unity – Checking combat on the server to prevent cheating – how to keep two codebases in sync?


I’m making an idle game with semi-multiplayer.
My game uses Unity as a client and as a server Unity Gaming Services (UGS) C# Cloud Code Modules with UGS Cloud Save.

Players click “start” which then starts idle/automated combat on the client. Players get experience and items from combat.
I want this to happen real-time on the client, it takes too long to pre-generate all the combat and loot on the server.
But I want my server to check everything so there’s no cheating.

I want to prevent cheating because trading items between players will be a big part of the game.

My plan at the moment is the following:

  1. player starts the game and sends a request to the server for a Random Number Seed (RNS)
  2. server generates the RNS and stores it in Cloud Save then sends it back to the player
  3. player clicks “start” and combat is processed real-time using the RNS, items are also generated using this
  4. on significant events, for example level up, every 10 seconds or on an item drop, the client pings the server to let it know something important happened
  5. the server then re-calculates all the combat up to that point and if everything checks out it saves all the rewards to Cloud Save
  6. the server then generates a new RNS that will be used after the next event (to
    prevent players calculating rewards a long time up front)
  7. on the next event the client pings the server again and then starts using the new RNS
  8. repeat from 5

My main concern with this is that I have duplicate combat code, not exactly, but I need to ensure the combat logic is exactly the same on client & server.
Is there any way to manage this sort of thing? I have no clue.
The code won’t be identical either, because the client is showing lots of visuals that the server won’t have to for example.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments