Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since...

122
Multiplayer Game Programming

Transcript of Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since...

Page 1: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Multiplayer Game Programming

Page 2: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

David Koontz@dkoontz

dkoontz.wordpress.com

● Phoenix area game developer since 2001● Teacher at Art Institute since 2006● Worked on a variety of educational and

commercial games● Author of iTween Visual Editor and

CameraFor2D components for Unity● Currently developing Star. Ship. Story., a

co-op space faring adventure○ Slightly crazy to be making a

multiplayer game

Page 3: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

How the Internet worksSpecial considerations for gamesUsing a library vs writing your ownExisting tools for Flash, C#, HTMLQuestions

Content Packet Header

Page 4: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

How the Internet worksSpecial considerations for gamesUsing a library vs writing your ownExisting tools for Flash, C#, HTMLQuestions

Content Packet Header

Page 5: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The Problem

A B

Page 6: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The Problem

A B

Page 7: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The Problem

A B

Page 8: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The Problem

A B

?

Page 9: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The Problem

A B

Page 10: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The Problem

A B

Page 11: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The Problem

A B

Page 12: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The Problem

A B

Page 13: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The Problem

A B

Page 14: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The Problem

A B

Page 15: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The Problem

A B

Page 16: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The Problem

A B

Page 17: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The Problem

A B

Page 18: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The Problem

A B

Page 19: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The Internet functions by being able to break data (usually cats) into “packets” and then (semi)reliably delivering those packets to their destination using whatever networks are available.

IP Protocol

Destinations are numbered addresses that look like this:

127.0.0.1192.168.0.10068.105.28.11

Page 20: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The “protocol” bit of the “IP Protocol” is just the expected actions of each party participating in the exchange and an agreed upon way of interpreting data sent between the systems

What is a protocol?

Page 21: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

What is a protocol?

Shaking hands when meeting someone is a social protocol. Signalling before changing lanes is standard driving protocol. “Belay, on belay, belay on” is standard rock climbing protocol.

The “protocol” bit of the “IP Protocol” is just the expected actions of each party participating in the exchange and an agreed upon way of interpreting data sent between the systems

Page 22: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

It’s protocols all the way down

TCP

ReliableOrdered

Maintains a connectionNeeds handshake

Fetching a web siteTransferring a fileChat messages

Turn based games

UDP

UnreliableUnordered

ConnectionlessLess overhead per packet

Voice chatMost high action games

Anything severely affected by latency

IP

Page 23: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Both TCP and UDP add another element to the “where” part of delivering a packet

Ports

68.105.28.11:3724

Page 24: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Both TCP and UDP add another element to the “where” part of delivering a packet

Ports

68.105.28.11:3724

IP address Port

Page 25: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Ports allow the receiving computer to differentiate the packets coming in for one application vs another

Ports

Page 26: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Ports

Think of how many applications you have receiving data at once through the same network connection

Page 27: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Ports

Web browser AIM PandoraSkype MSN SpotifySystem updates GChat Games

Page 28: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The anatomy of an IP packetTo

tal l

engt

h, p

roto

col

num

ber,

othe

r im

porta

nt

but b

orin

g va

lues

Sou

rce

IP a

ddre

ss

Des

tinat

ion

IP a

ddre

ss

Dat

a

Por

t, H

ands

hake

info

, se

quen

ce n

umbe

r, et

c.

Header

Page 29: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The anatomy of an IP packetTo

tal l

engt

h, p

roto

col

num

ber,

othe

r im

porta

nt

but b

orin

g va

lues

Sou

rce

IP a

ddre

ss

Des

tinat

ion

IP a

ddre

ss

Dat

a

IP Protocol Your application’s protocolTCP/UDP

Por

t, H

ands

hake

info

, se

quen

ce n

umbe

r, et

c.

16 bytes 16 bytes /4 bytes

Page 30: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The data that is sent mustbe converted to a format that can be sent across the Internet.

The process of converting your data to this format is called serialization

Serialization (aka marshalling)

Dat

a

Page 31: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The serialized form of your data is always a byte array

Serialization

int

bool

float

string

serializer byte[ ]

Page 32: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Deserialization is just the opposite process, extracting specific bits of data from the byte array as an int / float / string / etc.

Deserialization

int

bool

float

string

deserializerbyte[ ]

Page 33: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

You must know the format of the data that was serialized so that you can deserialize it correctly

Deserialization

float

bool

int

string

deserializerbyte[ ]

Page 34: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

You must know the format of the data that was serialized so that you can deserialize it correctly

Deserialization

float

bool

int

string

deserializerbyte[ ]

Page 35: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

How the Internet worksSpecial considerations for gamesUsing a library vs writing your ownExisting tools for Flash, C#, HTMLQuestions

Content Packet Header

Page 36: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The game state is all the significant values needed in order for the game to operate.

Position / RotationPlayer itemsEnemy actionTime remaining

State

Page 37: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

All input can be processed on the same frame/update

There is only one game state

Cheating is handled by the players themselves

Input arrives inconsistently from clients

There are (# of player) game states

Cheating must be handled by the game

Local vs Internet multiplayer

Page 38: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Unlike local multiplayer, each client has a unique but similar game state

Mostly synched game states

Page 39: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Each player’s game must simulate the actions of the other players

Mostly synched game states

Page 40: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Sometimes these simulations are wrong

Mostly synched game states

Page 41: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Life on the Internet == Latency (Lag)

Page 42: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The difficulty of keeping all the various clients synched up is directly related to the time sensitivity of your game.

Time sensitivity

Page 43: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

The difficulty of keeping all the various clients synched up is directly related to the time sensitivity of your game.

Time sensitivity

Async TurnBased Game

Twitch FPS

Egads, are you daft?

A worthy challenge my lad

RTS Diablo / Torchlight

Tactical FPSMMORPG

Parlor games, chess, poker

I doff my hat do thee

Page 44: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game statesPart 1

This seems pretty straightforward

Page 45: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

Page 46: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

Page 47: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

Page 48: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

Page 49: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

Page 50: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

Page 51: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game statesPart 2

Or so I thought

Page 52: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

Page 53: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

Page 54: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

Page 55: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

Character moved, shot missed

Character was shot, movement is ignored

Page 56: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game statesPart 3

A wild solution appears(It’s super effective)

Page 57: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

Page 58: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

Page 59: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

Page 60: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

Page 61: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

Page 62: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game statesFin

Ok, maybe not super effective

Page 63: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

60ms

Page 64: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

60ms

60ms

Page 65: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

A tale of two game states

Page 66: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Waiting 120ms for your key press to be registered is a bad user experience

People expect immediate response times, especially in an action oriented game

Delayed input

Page 67: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Extrapolation

Page 68: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Extrapolation

Page 69: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Extrapolation

Page 70: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

This technique allows the local machine to feel responsive, while still allowing the server to be authoritative

It may lead to snapping or “rubber banding” if the server’s version of the player’s position is different from what the local simulation predicted

Extrapolation

Page 71: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Interpolation

Page 72: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Interpolation

Page 73: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Interpolation

Page 74: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Allows the client to fix errors over a short time, largely hiding the error

When combined with extrapolation, can result in very smooth looking gameplay, even under higher lag conditions

Interpolation

Page 75: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Extrapolating other clients

Page 76: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Extrapolating other clients

Page 77: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Extrapolating other clients

Page 78: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Extrapolating other clients

Page 79: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Extrapolating other clients

Page 80: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Extrapolating other clients

Page 81: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Extrapolating other clients

Page 82: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Example videos

Page 83: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

ClientImmediate processing of input

Easy to cheat

Can result in inconsistent states

ServerMust wait for server to acknowledge input

Client are told the result of their own input

Server must be able to simulate the game

Client vs server authority

Page 84: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● This means you can not trust ANYTHING the client sends you

● Clients are generally not allowed to communicate directly

● Clients make requests to the server to perform an action which the server carries out if that is ok○ Is it ok for this client to be requesting this action?○ Client A using item owned by Client B

The authoritative server

Page 85: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Keep the server game logic isolated from the server “network” logic.

Allows you to upgrade these parts in isolation from each other

Suggestion

Page 86: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

One approach to server logic

Server network logic

A

B

C

Server game logic

byte[]

Player “Ub3r1337”

wants to jump

Page 87: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

One approach to server logic

Server network logic

A

B

C

Server game logic

Ok

OkPlayer “Ub3r1337”

jumped

Player “Ub3r1337”

jumped

Page 88: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Depending on your game’s needs, that server might be a web server (http get/post), a socket server (real time communication) or some mixture of the two

It all depends

Page 89: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Depending on your game’s needs, that server might be a web server (http get/post), a socket server (real time communication) or some mixture of the two

It all depends

Async TurnBased Game

Twitch FPS

UDP, socket server

HTTP over TCPPHP, Ruby on Rails, MVC.NET

RTS Diablo / Torchlight

Tactical FPSMMORPG

Parlor games, chess, poker

Socket server over TCP or UDP

Page 90: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Depending on your game’s needs, that server might be a web server (http GET/POST), a socket server (real time communication) or some mixture of the two

It all depends

Async TurnBased Game

Twitch FPS

UDP, socket server

HTTP over TCPPHP, Ruby on Rails, MVC.NET

RTS Diablo / Torchlight

Tactical FPSMMORPG

Parlor games, chess, poker

Socket server over TCP or UDP

More off the shelf solutions Need custom solution

Page 91: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

How the Internet worksSpecial considerations for gamesUsing a library vs writing your ownExisting tools for Flash, C#, HTMLQuestions

Content Packet Header

Page 92: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Structure!

What does a library do for you?

Page 93: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Structure!● Message protocol

What does a library do for you?

Page 94: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Structure!● Message protocol● Serialization & deserialization

What does a library do for you?

Page 95: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Structure!● Message protocol● Serialization & deserialization● A structure for client lifecycle events

What does a library do for you?

Page 96: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Structure!● Message protocol● Serialization & deserialization● A structure for client lifecycle events

○ Connection / disconnection○ Authentication○ Chat○ Saving / retrieving user data○ Payments

What does a library do for you?

Page 97: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Structure!● Message protocol● Serialization & deserialization● A structure for client lifecycle events

○ Connection / disconnection○ Authentication○ Chat○ Saving / retrieving user data○ Payments

● Can provide a tie-in to hosting solutions

What does a library do for you?

Page 98: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● You need to use their server and client libraries○ Both ends must be able to speak the same

protocol

What does a library impose on you?

Page 99: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● You need to use their server and client libraries○ Both ends must be able to speak the same

protocol● May only be available for certain

languages or platforms

What does a library impose on you?

Page 100: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● You need to use their server and client libraries○ Both ends must be able to speak the same

protocol● May only be available for certain

languages or platforms● May be closed source and / or commercial

What does a library impose on you?

Page 101: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● You need to use their server and client libraries○ Both ends must be able to speak the same

protocol● May only be available for certain

languages or platforms● May be closed source and / or commercial● May impose limitations on how you deploy

or structure your server

What does a library impose on you?

Page 102: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Requires more familiarity with lower level network concepts (sockets, etc.)

Rolling your own

Page 103: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Requires more familiarity with lower level network concepts (sockets, etc.)

● Requires you to put in place a structure for your server and client

Rolling your own

Page 104: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Requires more familiarity with lower level network concepts (sockets, etc.)

● Requires you to put in place a structure for your server and client

● Requires you to develop your own message protocol and serialization / deserialization procedures

Rolling your own

Page 105: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

It depends!

So which is better?

Page 106: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

It depends!

No really, that’s my entire answer

So which is better?

Page 107: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

How the Internet worksSpecial considerations for gamesUsing a library vs writing your ownExisting tools for Flash, C#, HTMLQuestions

Content Packet Header

Page 108: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Server as standalone

SmartFox (Java)Photon (C#)ElectroServer (Java)Player.IO (C#)Lidgren (C#)Flash Media ServerRed5 (Java)

Server as special client

uLink (Unity)Built in UnityBadumna (Unity)

Two types of solutions

Page 109: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Can be written in a language more appropriate for writing a server

Standalone server

Page 110: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Can be written in a language more appropriate for writing a server

● Can be used with any language / platform there is a client library for (or that you’re willing to develop a client library for)

Standalone server

Page 111: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Can be written in a language more appropriate for writing a server

● Can be used with any language / platform there is a client library for (or that you’re willing to develop a client library for)

● Needs to implement all the important logic of your game, and may not be able to reuse the same code from your client

Standalone server

Page 112: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Can be written in a language more appropriate for writing a server

● Can be used with any language / platform there is a client library for (or that you’re willing to develop a client library for)

● Needs to implement all the important logic of your game, and may not be able to reuse the same code from your client

● Can be as light or heavy weight as you need

Standalone server

Page 113: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Only one place to put the logic

Client as server

Page 114: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Only one place to put the logic● Both client and server are the same app

and can share logic

Client as server

Page 115: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Only one place to put the logic● Both client and server are the same app

and can share logic● Allows players to host games easily as

well as running dedicated hosts

Client as server

Page 116: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Only one place to put the logic● Both client and server are the same app

and can share logic● Allows players to host games easily as

well as running dedicated hosts● Must interface with some sort of front end

to manage user sessions

Client as server

Page 117: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Only one place to put the logic● Both client and server are the same app

and can share logic● Allows players to host games easily as

well as running dedicated hosts● Must interface with some sort of front end

to manage user sessions● Might have high overhead of running your

game client when not all of it is needed

Client as server

Page 118: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● Only one place to put the logic● Both client and server are the same app

and can share logic● Allows players to host games easily as

well as running dedicated hosts● Must interface with some sort of front end

to manage user sessions● Might have high overhead of running your

game client when not all of it is needed● Keeping client and server code separate

can be tricky

Client as server

Page 119: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

Family Guy Online

Hybrid

A

B

C

Photon

Unity

Unity

D

Page 120: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

● The Internet is a modern marvel, but is not a panacea

● Internet multiplayer is a good way to make your game 10x more complex

● There are no general solutions, only specific answers to specific problems

Summary

Page 121: Programming Multiplayer Game - WordPress.com · 2013-10-10 · Phoenix area game developer since 2001 Teacher at Art Institute since 2006 Worked on a variety of educational and commercial

How the Internet worksSpecial considerations for gamesUsing a library vs writing your ownExisting tools for Flash, C#, HTMLQuestions

Content Packet Header