Game Networking CSE 191A: Seminar on Video Game Programming Lecture 9: Networking UCSD, Spring, 2003 Instructor: Steve Rotenberg Guest Lecturer: Mark Rotenberg
Maslow’s Hierarchy of Needs Self Actualization Esteem Social Safety Physiological Offline Games Online Communities Simple Online Games
Network Topology ServerClient Peer (Host) Peer Client-Server TopologyPeer-to-Peer Topology
Networking Evils Security Cheating Latency (up to ms round-trip) Bandwidth ( kbps each direction) Packet Loss (2% with 10% bursts) Jitter
Lock-Step Simulations Really easy to implement Fully synchronize everything Initial states Inputs Time steps Simulation must be deterministic Some turn-based games use this at a slower sampling rate (Age of Empires) Not suitable for fast Internet games
Simulation with Lag Compensation Server-side movement Peer/Client-side movement with Host/Server verification Varying frame rates and latencies Position history with server-side time warping (Half-Life) Interpolation - sliding and skipping Extrapolation – problematic with physics Syncing orientation, position, inputs
Networking Protocols TCP (Transport Control Protocol) Reliable, connection based protocol Ideal for matchmaking and lobbies but not real- time game play UDP (Unix Datagram Protocol) Unreliable, unordered datagram oriented Good for time-sensitive data but not
Networking Protocols, cont’d Roll-your-own Protocol Probably based on UDP Prioritize and retransmit as necessary Coalesce or reconstitute packets as necessary Compression Encryption Piggyback Acknowledgements Heartbeats / Pings / Keep Alive / Network Probes
Game-Specific Protocols Positions, Inputs, Orientations Spawning and Removing Game Events Match Configurations State Transitions Complaints, Connection Status Heartbeats (pings) Voice / Chat
Game Data Most common transmission modes Reliable Piggyback ACKs where possible Unreliable Should be numbered, may arrive out of order Other modes Most recent only Fastest / Reliable fastest May transmit multiple times without waiting for ACKs
Network Security Encryption and Digesting RSA Diffie-Hellman MD5 DES, triple-DES, AES IPSec References “Applied Cryptography,” Schneier
Network Address Translation Peer 1 sees: Peer 2 at : 1000 Peer 3 at : Peer 2 sees: Peer 1 at : 1000 Peer 3 at : 1000 Peer 3 sees: Peer 1 at : 1000 Peer 2 at : 1000 Internet NAT Peer 2Peer 3 Peer : : : : : 49155
General Programming Suggestions Always assume networking Separate cause from effect Event-based networking code Multiple levels of state machines Message passing from network layer to game code Monitor everything WAN simulation hardware/software Lots of asserts and debug messages Lots of unit tests Lots of product testing
Matchmaking and Community Matchmaking Competitions, Ladders, Leader Boards Friends, Invitations Feedback – both good and bad Content Sharing
Online Strategies – Sony vs. Microsoft PS2 Strategy 5 networking stacks to choose from!? No built-in support for voice, security, authentication Various middleware vendors Publishers or users provide servers Xbox Strategy Very well designed networking stack and APIs Connect only through Microsoft’s servers Every packet, machine, user, hard drive, DVD, user can be authenticated Gamertags work across multiple titles Consistent billing interface Strict User Interface Guidelines
Deployment Issues Patching Maintenance Who pays for bandwidth? Billing Scalability Monitoring Usage and Statistics Handling Cheaters Detecting Piracy Who “owns” users? “Policing” the Community
Massively Multiplayer Online Games Huge Development Costs Virtual Economies Community Server Scalability Keeping content new and interesting
Future Considerations IPv6 Handhelds and Cell phones Cross-Title Integration Server-side “Mods” Peer-to-Peer MMOGs? Sony “Cell” Processor
Questions? Contact me at mark [at] rockstarsandiego.com.