Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

GAME NETWORKING

Game networking is a subset of computer networking that commonly covers transport


protocols, data replication, entity synchronization, lag compensation, client-side
prediction, server reconciliation, interest management, bandwidth optimization,
physics rollback/fast-forward simulation, anti-cheating and many other areas involved
in multiplayer online game development.
TRANSPORT PROTOCOL

Transport protocols reside on top of the IP protocol. Transport protocols run over the
best-effort IP layer to provide a mechanism for applications to communicate with each
other without directly interacting with the IP layer. In the IP protocol stack, the most
widely used two transport protocols are User Datagram Protocol (UDP) and
the Transport Control Protocol (TCP).
Data Replication

Active replication: Inputs from the players are sent to all players in the network, state is
simulated deterministically and independently on each client (also called lock-step
synchronization and state-machine synchronization).
Active- The idea behind lockstep multiplayer is simple, if every player shares their input with
every other player, the simulation can be run on everyone’s machines with identical input to
produce identical output.

Passive replication: Inputs from the players (clients) are sent to a single machine (the server)
and state updates are broadcast to all players. (also called primary backup, master-slave
replication, and client-server).
Entity Synchronization

The Entity is the Logical and Physical objects you can found in the game.
Example entity X attacks entity Y, whereas the components approach would need to send stuff
more like raw component state (which animation to play, frame, sound, etc).
There will be exchange of data and physics with one another for them to create
synchronization.
Lag Compensation

Lag compensation is a technique that tries to correct the effects of lag by adjusting the game
state on the server based on the player input.
Ping is the time it takes for a packet of data to travel from your PC or console to
the game server and then all the way back to you it's measured in milliseconds or
MS for short.
Now everyone in a match has different amounts of lag depending on that ping,
higher amounts of ping mean more lag.
Things like the amount of congestion on a player's Network or how close or far
away they are from a server they're connected to will determine that ping
No matter what, it always takes a certain amount of time for a player's game to
communicate the actions with the game.
Usually a server nowadays to decide the most accurate outcome.
in the name of fairness there's no real way to choose one player's perspective over
someone else's
what I see, what the other player sees and then what the server
The low latency player's perspective and the high latency players the same two
network setup but across different maps and lobbies.
The low ping player getting compensation over the high ping player.
This is clear due to the location of the enemy player at the time the kill appears on
screen.
Low ping players perspective is clearly out in the open and the kill looks totally fair
but at the high ping player's perspective they'd probably assume they were safe
since they made a behind cover on their screen but this isn't the case as on their
screen it appears they've been killed behind cover.
The reverse scenario a high ping player shooting at the low ping player it's worth
saying again that some of these shelter misses as we aren't exactly Pro valo players
but some of these shots should have hit and therefore led to a Kill these examples
show lag compensation doesn't just give High ping players an advantage based on
their poor Connection in fact the only way a high ping player can get compensation
is by heavily altering the gameplay.
Client-side Prediction, Server Reconciliation
When we have server authoritative code, were running into a problem where
input will not be responsive because we have to wait for the client to received
state from the server.
Client prediction is a technique used to make the Client feel more responsive while
keeping server authority.
In short, the Client will update the game state immediately after receiving Player
input and it will run the same exact code at the server is running.
To Reconcile is to restore friendly relations between, this means if we have
predicted in somehow the Client and the Server have gotten out of sync with each
other then the Server and Client need to make it up and restore that harmony.
Interest Management
Interest management is a crucial aspect of designing multiplayer game networks.
It involves determining which parts of the game world each player needs to be
aware of, and then efficiently transmitting that information to the relevant players.
This helps optimize network bandwidth and processing resources, ensuring a
smooth and responsive multiplayer gaming experience. There are several
techniques for interest management in game networks:

1. Spatial Partitioning:
• Grids/Cells: Divide the game world into a grid or cells. Players are only informed
about events or entities within their own grid cell or neighboring cells.
• Quadtree/Octree: Use hierarchical data structures to partition the game world
dynamically, allowing more detailed information about nearby areas and less
detailed information about distant areas.
2. View Frustum Culling:
• Discard objects that fall outside a player's viewing frustum, the portion of 3D
space visible on the screen. This helps reduce the amount of unnecessary data sent
to clients.
3. Distance-Based Filtering:
• Send detailed information about nearby objects and less detailed information
about distant objects. The level of detail can be adjusted dynamically based on the
player's proximity to the objects.
4. Interest Regions:
• Define interest regions within the game world. Players receive updates only for
events or entities within their current interest region, reducing unnecessary data
transfer.
5. Object Priority and Relevance:
• Assign priorities to game objects and transmit updates based on importance.
For example, a player might receive immediate updates about a nearby enemy,
but delayed or less frequent updates about a distant, less relevant object.
6. Dynamic Adaptation:
• Adjust the level of detail and the range of information dynamically based on
the player's behavior, focus, or the current state of the game.
7. Message Filtering and Compression:
• Optimize data transmission by filtering out unnecessary information and
compressing data packets to reduce bandwidth usage.
8. Server-Side Authority:
• The server retains authority over critical game elements to prevent cheating or
unauthorized modifications. Clients receive updates based on their current
knowledge and view.
9. Asynchronous Updates:
• Send updates to players asynchronously, allowing for more flexibility in
managing network traffic and reducing the impact of latency.
10. Predictive Rendering:
• Use prediction algorithms to anticipate a player's actions and render relevant
content in advance, reducing the perceived impact of latency.

Implementing a combination of these techniques based on the specific


requirements of your game can help achieve efficient interest management in a
multiplayer game network, leading to a more responsive and immersive gaming
experience.
Bandwidth Optimization
To optimize network bandwidth, one must minimize the amount and frequency of
data sent and received.
Compression and encoding can help reduce the size of data packets, while delta
compression allows you to send only the changes in data instead of the whole
data.
Physics Rollback/fast-forward Simulations
Rollback and fast-forward simulations are techniques used in networked
multiplayer games to handle discrepancies between the game state on the client
and server due to latency, packet loss, or other network issues. These techniques
help maintain a consistent game experience for all players involved.
Physics Rollback:
In a physics rollback system, when a player performs an action (e.g., shooting a
projectile), the action is immediately acknowledged locally on the client. The client
then sends this action to the server, which validates it and broadcasts the result to
all clients. However, due to network latency, the acknowledgment from the server
may take some time.
If the server receives the action and validates it, everything proceeds as expected.
However, if the server receives the action and determines that the local client's
version of the game state was incorrect (e.g., another player's position has
changed), it may initiate a rollback. The server instructs all clients to revert to a
previous, correct state, and then it reapplies the actions leading up to the current
state.
Advantages:
- Provides a consistent game state across all clients.
- Corrects discrepancies caused by latency or other network issues.

Challenges:
- Requires careful synchronization and handling of various game elements.
- Can be computationally expensive, especially in complex physics simulations.
Fast-Forward Simulation:
Fast-forward simulation is another approach to deal with network latency. Instead
of rolling back to correct discrepancies, the server continues to simulate the game
ahead of the current state. When updates from the client arrive, the server may
need to adjust its simulation based on the new information.

Advantages:
- Avoids the need for rollbacks, reducing computational overhead.
- Can provide a smoother experience for players.

Challenges:
- Requires prediction algorithms to simulate future states accurately.
- Can introduce discrepancies if predictions are incorrect.
Hybrid Approaches:
Some game architectures use a combination of rollback and fast-forward
techniques to strike a balance between accuracy and performance. For example,
critical game elements might use rollback for precise synchronization, while non-
critical elements may rely on fast-forward simulation.
Anti-cheating
measures are essential in online multiplayer games to ensure fair play and
maintain a positive gaming experience for all players. Cheating can take various
forms, including exploiting vulnerabilities, using third-party software, or
manipulating game data. Here are several strategies and techniques for
implementing anti-cheating measures in a game network:

You might also like