Professional Documents
Culture Documents
Introduction
Why multiplayer games? People are better at most strategy than current AIs People are less predictable Can play with people, communicate in natural language Add social aspect to computer games Provides larger environments to play in, with more characters Make money as a professional game player
1 / 38
Head-to-head death-match:
Fast-pace, intense interaction/combat No persistent state Players form ad-hoc, short-lived sessions Any client can be a server Requires matchmaking service: built-in lobby or use GameSpy Examples: X/NetTrek (1980s, simulation), Doom (1990s, FPS), Counter-Strike, StarCraft, AoE, etc. (RTS-combat)
2 / 38
Basics
Outline
Basics Latency TCP/IP and UDP/IP Topology Distributed Computing and Latency
Basics
OSI Model
1 2 3 4 5 6 7
Physical Layer Data Link Layer Network Layer How we address hosts (IPv4/IPv6) Transport Layer What we build on (TCP/UDP) Session Layer Presentation Layer Where we get security (SSL/TLS) Application Layer What we develop
3 / 38
Basics
Application Layer
Direct IP connections between players Game server for connecting players together Tracker / match making service to connect players to servers Tracker aggregator (aggregator (...)) Download / patch server Store Store aggregator (aggregator (...))
We care most about 1, somewhat about 2, and just a little bit about 3.
4 / 38
Basics
In-Game vs Backend
Differentiate between in-game networking and backend infrastructure Backend infrastructure (see Yahn Berniers talk at GDC2000 rtsp://media.cmpnet.com/gamasutra/bernier.rm): Lobby where gamers meet Authentication and CD key checking Accounting and billing Ranking and ladder Reputation and black list Buddy lists, clans, and tournaments Mods and patches management Virtual economy Beware of DDoS Issues: scalability, adapting to failure, security
Mitchell Keith Bloch (University of Michigan) Networking for Games 5 / 38
Basics
Concerns
Bandwidth
Too little bandwidth means we cant get enough data per unit time
Latency
Too high latency means we cant get data in time for it to be useful
Computational cost
Too high computational cost means we cant manage enough connections Or we cant initialize connections fast enough
Which do you think were most concerned about? Hint: Everyone advertises bandwidth, and youre not creating an MMO.
6 / 38
Basics
Bandwidth Limitation
What is bandwidth? What information is sent? Depends on your computing model, distributed object or message passing Game state: coordinates, status, action, facing, damage User keystrokes Commands/moves For AoE: 1 every 1.5-2 sec, up to 3-4 commands/sec during battles (but some of these are redundant and can be ltered out) Current lower limit assumed: 56 Kbps Broadband
7 / 38
Basics
Bandwidth requirement has been HIGHLY optimized Even with audio chat, takes up at most 8 Kbps So, bandwidth is not a big issue (but note the asymmetric nature: at 8 Kbps, you can only support a total of 4 players on a 28.8 Kbps modem) Must be continually vigilant against bloat HOWEVER, with player-created objects and worlds, bandwidth becomes an issue again: use streaming, levels of details, and pre-fetching
8 / 38
Latency
Outline
Basics Latency TCP/IP and UDP/IP Topology Distributed Computing and Latency
Latency
Latency
Recall that latency is the time between when the user acts and when they see the result Latency is arguably the most important aspect of a game network
Too much latency makes the game-play harder to understand because the player cannot associate cause and effect It makes it harder to target objects (the lead becomes to large) There is signicant psychological research on this topic
9 / 38
Latency
Latency Limitation
How is latency different from bandwidth? Latency: RTS: 250 ms not noticable, 250-500 ms playable, > 500 ms noticable FPS: 150 ms preferred Car racing: < 100 ms preferred, 100-200 ms sluggish, 500 ms, car out of control Players expectation can adapt to latency It is better to be slow but smooth than to be jittery
10 / 38
Latency
Sources of Latency
Consider a client sending and receiving data from a server There are four sources of latency in a game network
Frame rate latency: Data only goes out on or comes in from the network layer once per frame, and user interaction is only sampled once per frame Network protocol latency: It takes time for the operating system to put data onto the physical network, and time to get it off a physical network and to an application Transmission latency: It takes time for data to be transmitted to the receiver Processing latency: The time taken for the server (or client) to compute a response to the input
Latency
Transmission latency:
Send less stuff less time between when the rst bit and the last bit arrive Upgrade your physical network (from dial-up to DSL, for instance)
12 / 38
Latency
Processing latency:
Make your server faster Have more servers
The sad fact is, networking researchers and practitioners are almost never concerned with latency
Most applications can handle higher latency (who else cares about latency?) When did you last hear a DSL/Cable add that promised lower latency? Possibly changing with concern over buffer bloat!
13 / 38
Latency
14 / 38
Outline
Basics Latency TCP/IP and UDP/IP Topology Distributed Computing and Latency
TCP
TCP is reliable, guaranteeing in-order delivery (or disconnection) TCP has no size limitations for how much data can be sent in one transmission TCP plays nice with the network Generally considered easier to get right
UDP
UDP is fast UDP has no built-in cost for connecting to multiple hosts UDP doesnt play nice with the network Generally considered faster
15 / 38
IP routes packet from source to destination, max IP packet size is 64 KB, may be fragmented What TCP (Transmission Control Protocol) gives you:
Reliable delivery Retransmission and reordering Congestion control
16 / 38
Which to use?
Game requirements: Late packets may not be useful anymore Lost information can sometimes be interpolated But loss statistics may be useful Use UDP in game: Can prioritize data Can perform reliability if needed Can lter out redundant data Use soft-state Send absolute values, not deltas Or if deltas are used, send baseline data periodically Must do congestion control if sending large amount of data
Mitchell Keith Bloch (University of Michigan) Networking for Games 17 / 38
TCP
Server:
1 2 3
Open a TCP port to listen on For each incoming connection, open a new TCP socket Send and receive bytes from TCP sockets, maintaining sufcient state to handle incompletely received data Possibly do a DNS lookup to learn a host IP address Open a new TCP socket to connect to a known host IP & port Send and receive bytes from TCP sockets, maintaining sufcient state to handle incompletely received data
Client:
1 2 3
Note that you may not receive all the data you need at once. If attempting to stay interactive, you have to be able to keep your game running and try to get the rest of the data later. This bookkeeping can be tricky.
Mitchell Keith Bloch (University of Michigan) Networking for Games 18 / 38
UDP
Server:
1 2
Open a UDP port to listen on For each incoming packet, decide what to do based on the IP address, port, and data Send packets to selected address/port combinations Open a UDP port to listen on For each incoming packet, decide what to do based on the IP address, port, and data Send packets to selected address/port combinations
Client:
1 2
Note that there is no longer a concept of a listener port. There is also only one socket shared between all connections. However, reliability is lost. Ensuring that data from older packets not interfere with data from newer packets requires work, and it is impossible to detectonly disconnection with certainty.
Mitchell Keith Bloch (University of Michigan) Networking for Games 19 / 38
Reliable UDP
UDP doesnt provide reliability, write your own reliable udp for moves that must be reliable, e.g., sniper shots Desirable features: Error control: do checksum Ordering: use sequence # Reliability: acknowledge packet (use cumulative ACK), retransmit if not ACKed, timeout value a function of average rtt (round-trip time) Flow control: dont send more than the target can handle; use stop-and-wait or sliding-window If you need all of these, all of the time, just use TCP. It works well.
20 / 38
Serialization
21 / 38
In-Game Networking
Networking topology: client-server vs. peer-to-peer Computing model: distributed object vs. message passing Which protocol to use? tcp, udp, reliable udp Bandwidth limitation Latency limitation Consistency Cheat proong Socket programming
22 / 38
Topology
Outline
Basics Latency TCP/IP and UDP/IP Topology Distributed Computing and Latency
Topology
Peer-to-Peer
Peer-to-peer with O(N 2 ) unicast connections: Each player is connected directly to all other players Each player simulates the whole world Advantages: reduced latency, no single point of failure Disadvantages: easier to cheat, not scalable: each client must send and receive N 1 messages Used in Age of Empire
23 / 38
Topology
Client-Server
Two avors:
Ad-hoc servers: death match Dedicated servers: MMORPG
24 / 38
Topology
Advantages: each client sends only to server, server can aggregate moves Advantages (dedicated servers): cheat-proong, server can be better provisioned, persistent states (for MMOG) Disadvantages: longer delay, server bottleneck, single point of failure, needs server management
25 / 38
Topology
MMOG Architectures
The world replicated at each server (shard); each shard contains an independent world; players go to specic shard
Most MMORPG
The world replicated at each server (mirror); all the worlds are synchronized; players see everyone across all mirrors
Mirrors must be kept consistent
The world is split up into regions, each region is hosted by a different server
Second Life is a great example Mirrors must be kept consistent
26 / 38
Topology
Usually your game company will have its preferred computing model and would provide high-level libraries to implement the model Distributed objects: Characters and environment maintained as objects Player inputs are applied to objects (at server) Changes to objects propagated to all players at end of game loop Object update usually implemented as one or more library calls
27 / 38
Topology
Message passing: Player inputs (either button pushes or higher-level movements) are sent to other players (or server) All players update their own game state Or server updates the global game state and send it out to all players
28 / 38
Outline
Basics Latency TCP/IP and UDP/IP Topology Distributed Computing and Latency
Lock-Step
Each player receives all other players moves before rendering next frame Problems: Long Internet latency Variable latencies Speed determined by the slowest player
29 / 38
Bucket Synchronization
Buffer both local and remote moves Play them in the future Each bucket is a turn, say for about 200 ms Bucket size can be adapted to measured rtt Problems: What if a move is lost or late? Game speed (bucket size) determined by slowest player
30 / 38
Consistency
For consistency ALL user input MUST pass through the synchronization module Be careful with random number generators. Isolate the one used for game-state updating from other uses (ambient noise etc.) Design for multiplayer from the start. Single-player becomes a special case of single-client multiplayer game.
31 / 38
Pessimistic Consistency
Every player must see the EXACT same world AoE/AoK/AoM: Uses bucket synchronization Each player sends moves to all other players Each player simulates its own copy of the world All the worlds must be in sync. A designated host collect measured rtt from all players and set future bucket size Problems: Variable latencies Speed determined by the slowest player
32 / 38
Dead Reckoning
Dead reckoning uses prediction to move objects about even when their positions are not precisely known, reducing the appearance of lag
Each client maintains precise state for some objects (e.g. local player) Each client receives periodic updates of the position of everyone else, along with velocity information, and maybe acceleration On each frame, the non-local objects are updated by extrapolating their most recent position using the available information
With a client-server model, each player runs their own version of the game, while the server maintains absolute authority
33 / 38
What do you do when using dead reckoning, and a new position arrives for another player?
The position that just came in will not agree with the place you have the object, due to extrapolation errors
Two options:
Jump to the correct position Interpolate the two positions over some period
Path followed will never be exact, but will match reasonably well
34 / 38
Best Practices
For smoother playback, decouple bucket size from frame rate (even AoE does this) Immediately render local moves Modify game design to allow for latency and loss, e.g.: Make players wait for elevator Teleportation takes time Require multiple hits per kill Let bullet/missile have ying time Build in inertia, dont allow sudden change in facing
36 / 38
Do area-of-interest management (a.k.a. relevance ltering): Aura: how far you can be sensed (cloaked ships have 0 aura) Nimbus: how far you can sense (use quantum-sensor to detect cloaked ships) Only perform consistency check between objects whose aura and nimbus overlap
37 / 38
Cheating
AoE doesnt need cheat-proong because each player simulates each move in lock step. All moves are simulated, not just collisions. Half-Life synchronizes only collisions, higher probability for cheating. Cheats (more at megagames.com): Superhuman cheat: auto-aim, auto-position Game-state editing: boost players prole Rule bending: see/walk through walls Sixth-sense cheat Lookahead cheat: claim to be behind slow link Suppress-correct cheat: exploit dead-reckoning claim that own moves were lost, then reconstruct advantageous moves based on others moves
Mitchell Keith Bloch (University of Michigan) Networking for Games 38 / 38