Networking


This is part of a series on how this game was implemented technically, as part of the Game Jam it was developed for. It is recommended to read them roughly in-order as later blog entries may refer to earlier ones.

Technical:

  1. State Machine
  2. Pathfinding/Movement
  3. Isometric Rendering
  4. API
  5. Control Sources
  6. AI
  7. Networking
  8. Fog of War
  9. Bit Packing
  10. Palette Shifting

Other:

-----

Networking is done using Peer JS.

This is a peer-to-peer browser-based networking library that uses WebRTC behind the scenes. There's no dedicated game server, which is useful when running a game jam with limited resources. 

As mentioned in the "control source" blog post, networking happens at the API layer.

If a player has a network connection, when they make an API call to commit their character's movement, the API layer automatically sends a packet saying "move to, from, targeting" and when this is received from the remote player,  it's played back and the game is updated to remain in sync.

Because the game is only sync'ed once initially, this means all players have a full copy of the game's data. 

In theory someone could cheat by peeking at the code's internal state to see where the opponent's units are, despite being obscured by fog. Considering this is a game jam entry, no effort was made to combat this, but it's interesting to think about.

Option 1)

When you move a character, ask the other player "can I move here". 

This would block the current player from seeing their opponent's units, but the opponent would be able to listen in to these queries and determine where the player's units are.

Option 2)

The current player is sent their opponent's data and queries locally when it's their turn. This means at the start of each turn, the player would get a copy of their opponent's units. 


So either case, it's possible to cheat. The theoretically more robust approach would be to use option1, but have a game server in the middle. The server would validate requests and only return units that can be seen by the current player. 

Leave a comment

Log in with itch.io to leave a comment.