=== Enet === Forsaken rides on top of Enet library. "ENet's purpose is to provide a relatively thin, simple and robust network communication layer on top of UDP (User Datagram Protocol). The primary feature it provides is optional reliable, in-order delivery of packets." For more information please check out it's web site or jump into #enet @ irc.freenode.net http://enet.bespin.org http://enet.bespin.org/Features.html === Peer 2 Peer Protocol Layer === On top of Enet is a small p2p protocol developed by Methods with some inspiration from Zico's work on Descent. == Protocol Description == (negotiate) when a new connection is made send my id/name/port > < acknowledge receipt < send my id/name/port acknowledge receipt > negotiation complete new player connects to host 1. host and newplayer negotiate (except the newplayer doesn't have an id yet to send the host will generate one for him after this) 2. host assigns and gives newplayer his id 3. newplayer acknowledges receiving his id 4. host tells existingplayers to connect to newplayer + hislocalport note: based on these steps if your the FIRST player in the game then the host will always tell you to connect to newplayers there will never be anyone that initiates a connection to you hence you do not need to have your port open (synching faze) 5. existingplayers connect and negotiate with newplayer a. if anyone fails 1. tell the host that I failed to connect 2. host kicks newplayer 3. host tells everyone to kick newplayer b. if all succeed 1. host sends a newplayerevent to everyone 2. existingplayers now see the newplayer join 3. host sends newplayerevent to the newplayer for all existingplayers 4. the newplayer now sees everyone else join the game someone receives/loses a connection 1. tell the host a. if the host is connected to them 1. host tells him to reconnect b. if the host is not connected to them 2. host tells him to drop that connection host leaves the game player with the lowest id becomes host this happens locally on everyone's computers there is no messages about it ==== Forsaken Packets ==== Below is a table listing the sizes and flags used to send various Forsaken messages. Basic principles: 1. main game data is marked as reliable - important game state data needs to be reliable - anything to do with pickups, joining the game, changing levels, stats etc. 2. primary/secondary/position updates are on their own channel and set to sequenced | unreliable - this creates a sub stream that will drop late pkts +-------------------------------------------------------------------------+ | NAME | BYTES | GUARANTEED | UNICAST | CHANNEL | +--------------------------------------------------------------+----------+ | BIKENUMMSG | 3 | X | | MAIN | - | BGOUPDATEMSG | 12 | X | | MAIN | - | NETSETTINGS | 20 | X | | MAIN | - | DROPPICKUPMSG | 56 | X | | MAIN | - | FUPDATEMSG | 68 | | | BIKES | - | GROUPONLY_VERYSHORTFUPDATEMSG | 28 | | | BIKES | - | HEREIAMMSG | 3 | X | | MAIN | -8 | INITMSG | 408 | X | X | MAIN | -72 | KILLPICKUPMSG | 8 | X | | MAIN | - | LONGSTATUSMSG | 64 | X | | MAIN | - | PRIMBULLPOSDIRMSG | 72 | | | MAIN | - | REQTIMEMSG | 2 | X | | MAIN | - | SECBULLPOSDIRMSG | 76 | X | | MAIN | - | SHIPHITMSG | 56 | X | X | MAIN | - | SHORTSHIPHITMSG | 36 | X | X | MAIN | - | SHOCKWAVEMSG | 28 | | | MAIN | - | SHIPDIEDMSG | 20 | X | | MAIN | - | STATUSMSG | 24 | X | | MAIN | - | SETTIMEMSG | 8 | X | | MAIN | - | SHORTPICKUPMSG | 264 | X | X | MAIN | - | SHORTREGENSLOTMSG | 244 | X | X | MAIN | - | SHORTTRIGGERMSG | 244 | X | X | MAIN | - | SHORTTRIGVARMSG | 244 | X | X | MAIN | - | SHORTMINEMSG | 232 | X | X | MAIN | - | TITANBITSMSG | 184 | X | | MAIN | - | TEAMGOALSMSG | 10 | X | | MAIN | - | TEXTMSG | 515 | | | MAIN | - | UPDATEMSG | 72 | | | BIKES | - | VERYSHORTUPDATEMSG | 40 | | | BIKES | - | VERYSHORTFUPDATEMSG | 44 | | | BIKES | - | VERYSHORTDROPPICKUPMSG | 36 | X | | MAIN | - | YOUQUITMSG | 3 | X | | MAIN | - +-------------------------------------------------------------------------+ +------------------------------------------------------+ | TEXT MSG NAME | GUARANTEED | UNICAST | +------------------------------------------------------+ | TEXTMSGTYPE_SpeechTaunt | | X | | TEXTMSGTYPE_ScoredWithFlag | X | | +------------------------------------------------------+ === Bandwidth === The formula to calculate bandwidth for a single direction (downstream vs upstream) on a single player is: Where N is number of players Bytes is the size of the packet Rate is the packets per second sent bw = (N-1) * Bytes * Rate For the entire network is sending: N * bw And for a single client bidirectional bw is: 2 * bw Position updates (VERYSHORTUPDATEMSG) are 40 bytes using short packets. A game with 4 people at stand still would require (not including udp/enet overhead): 2 * (4-1) * 40B * 30pps = 7,200Bps 2 * (4-1) * 40B * 15pps = 3,600Bps 56k can handle 7000Bps So if you want to figure out pps to set you would use: pps = 7,000Bps / ( 2 * (N-1) * 40B ) If you had 4 people in the game the result would be: 29pps = 7,000Bps / ( 2 * (4-1) * 40B ) But don't forget that you need some breathing room on in there for other types of pkts. Bullet, stats, pickups, bg objects everything has a pkt and they are much larger.