This wiki was in read-only mode for many years, but can now be edited again. A lot of information will need to be updated.

Network Protocol: Difference between revisions

From BZFlagWiki
Jump to navigation Jump to search
Ts (talk | contribs)
m be more verbose
Zehra (talk | contribs)
to rewrite entirely from scratch
 
(9 intermediate revisions by 7 users not shown)
Line 1: Line 1:
This page describes the used networking protocol of BZFlag.
The following is an overview of the network protocol from version 2.4.x of BZFlag.




== Platform differences ==
Information is directly read from the source code and can be easily referenced:
The network protocol is cross platform, however implementation of sockes is different on the platforms. *nix, Linux and Mac OS X use BSD sockets, Windows® uses WinSock. WinSock is not 100% compatible to the standard therefore if you use a low level language you need different code for Windows® to do the same like on other platforms.
{|{{Prettytable}}
|-
| {{Hl3}} |'''Location:''' || {{Hl3}} |'''File:'''
|-
| '''/include/''' || '''Protocol.h'''
|-
| '''/include/''' || '''Pack.h'''
|-
|}




== Connecting to a server ==
All packet codes are of the type: '''uint16_t'''. (Protocol.h)
The [http://bzflag.svn.sourceforge.net/viewvc/*checkout*/bzflag/trunk/bzflag/misc/bzfquery.php bzfquery.php script] is a nice example of how to connect to a server.


At the beginning you need to open a socket using the TCP/IP protocol. Beginning with protocol 0048 you need to send "BZFLAG\r\n\r\n" in order to get any reply. At that time you unfortunately don't know the protocol, so send it by default or your client will probably freeze.


Then you will get 9 bytes from the socket: First the string "BZFS" and then a 4 digit protocol number. If the protocol is newer or equal to 0048 your established connection is fine. If it is older than 0048 your client has been kicked, in this case you need to reconnect again without sending "BZFLAG\r\n\r\n".
Below is taken from '''Protocol.h''':
server communication protocol:
  --> incoming messages (to server)
  <-- outgoing messages to single player
  <== outgoing messages to all players


Server owners will see something like the following in the logs if their server(s) use a protocol older than 0048:
==player to server messages:==
   Player [0] sent huge packet length (len=16986), possible attack
  MsgEnter      player is joining game
   Player  [0] removed at 2007-04-11 15:52:55: large packet recvd
            --> id, type, team, name, motto
            <-- MsgReject (if rejected)
            <-- MsgAccept (if accepted)
            if accepted, new player is sent (following MsgAccept):
            <-- MsgTeamUpdate (one per team)
            <-- MsgFlagUpdate (one per existing flag)
            <-- MsgAddPlayer (one per already joined player)
            add, finally, sent to all:
            <== MsgAddPlayer (player being accepted)
  MsgExit      player is signing off
            --> /id/
            <== MsgRemovePlayer
  MsgGetWorld      request for playing field database
            --> bytes read so far
            <-- MsgGetWorld
  MsgQueryGame      request for game state
            <-- MsgQueryGame
  MsgQueryPlayers  request for player list
            <-- MsgQueryPlayers
  MsgAlive      player says he's coming alive
            --> /id,
            <== MsgAlive
  MsgKilled    player says he's been killed
            --> /id,/ killer-id, reason, killer-shot-id
            <== MsgKilled
  MsgNewRabbit      player is relinquishing rabbitship
  MsgGrabFlag      player wants to grab flag
            --> /id,/ flag
            <== MsgGrabFlag
  MsgDropFlag      player wants to drop flag
            --> /id,/ position
            <== MsgDropFlag
            <== MsgFlagUpdate
  MsgCaptureFlag    player captured flag
            --> /id,/ team (team flag was taken to)
            <== MsgCaptureFlag
            <== MsgFlagUpdate
   MsgSetVar    <== count/[name/value]*
  MsgShotBegin      player has fired a shot
            --> FiringInfo
            <== MsgShotBegin
  MsgShotEnd        shot has terminated
            --> shooter id, shot number, reason
            <== MsgShotEnd
  MsgTeleport      player has teleported
            --> /id,/ from-teleporter, to-teleporter
            <== MsgTeleport
  MsgMessage        player is sending a message
            --> /id,/ target-id/team-id, message string
            <== MsgMessage
   MsgWantWHash      (player wants md5 of world file
            -->
  MsgNegotiateFlags -->flagCount/[flagabbv]
  MsgPause      -->true or false


==server to player messages:==
  MsgSuperKill      player must disconnect from server
            <== <none>
  MsgTimeUpdate    game time left, if == 0 player is dead and can't restart
            <== time (left, in seconds)
  MsgScoreOver      score limit reached, player is dead and can't restart
            <== id (winner), team (winner)
  MsgAccept    player request is accepted
            <== <none>
  MsgReject    player request is rejected
            <== <none>
  MsgAddPlayer      notification of new tank in game
            <== id, type, team, name, motto
  MsgRemovePlayer  player has exited the server
            <== id
  MsgAdminInfo      update of players' IP addresses
            only sent to players with the PLAYERLIST permission.
            <-- count, [chunklen, id, bitfield, address]*
  MsgPlayerInfo    update of players status
            <-- count, [id, bitfield]*
  MsgFlagUpdate    update of flag info
            <== count, [flag, flag-info]*
  MsgTeamUpdate    update of team info
            <== teamcount, [team, team-info]
  MsgGetWorld      chunk of world database
            <-- bytes left, next 256 byte chunk of world database
  MsgAlive      player is alive
            <== id, position, forward-vector
  MsgKilled    player is dead
            <== id (victim id), killer-id, reason, killer-shot-id
  MsgGrabFlag      notification that flag is grabbed
            <== id (grabber), flag, flag-info
  MsgDropFlag      notification that flag is in air
            <== id (dropper), flag, flag-info
  MsgCaptureFlag    notification that flag has been captured
            <== id (capturer), flag, team
  MsgShotBegin      some player has fired a shot
            <== FiringInfo
  MsgShotEnd        shot has expired
            <== id (shooter id), shot number, reason
  MsgScore      player score has changed
            <== num-scores [id (player id), wins, losses, tks]*n
  MsgTeleport      player has teleported
            <== id, from-teleporter, to-teleporter
  MsgMessage        message to players
            <== from-id, to-id/team-id, message string
  MsgQueryGame      game status
  MsgQueryPlayers  list of players
  MsgWantWHash      md5 digest of world file
            <== temp|perm, digest
  MsgNegotiateFlags <== flagCount/[flagabbv]
  MsgNewRabbit      a new rabbit has been anointed
            <== id
  MsgPause      <== id/true or false
[[Category:Development]]
[[Category:Concepts]]
[[Category:Concepts]]

Latest revision as of 03:20, 10 November 2025

The following is an overview of the network protocol from version 2.4.x of BZFlag.


Information is directly read from the source code and can be easily referenced:

Location: File:
/include/ Protocol.h
/include/ Pack.h


All packet codes are of the type: uint16_t. (Protocol.h)


Below is taken from Protocol.h:

server communication protocol:
 --> incoming messages (to server)
 <-- outgoing messages to single player
 <== outgoing messages to all players

player to server messages:

 MsgEnter      player is joining game
           --> id, type, team, name, motto
           <-- MsgReject (if rejected)
           <-- MsgAccept (if accepted)
           if accepted, new player is sent (following MsgAccept):
           <-- MsgTeamUpdate (one per team)
           <-- MsgFlagUpdate (one per existing flag)
           <-- MsgAddPlayer (one per already joined player)
           add, finally, sent to all:
           <== MsgAddPlayer (player being accepted)
 MsgExit       player is signing off
           --> /id/
           <== MsgRemovePlayer
 MsgGetWorld       request for playing field database
           --> bytes read so far
           <-- MsgGetWorld
 MsgQueryGame      request for game state
           <-- MsgQueryGame
 MsgQueryPlayers   request for player list
           <-- MsgQueryPlayers
 MsgAlive      player says he's coming alive
           --> /id,
           <== MsgAlive
 MsgKilled     player says he's been killed
           --> /id,/ killer-id, reason, killer-shot-id
           <== MsgKilled
 MsgNewRabbit      player is relinquishing rabbitship
 MsgGrabFlag       player wants to grab flag
           --> /id,/ flag
           <== MsgGrabFlag
 MsgDropFlag       player wants to drop flag
           --> /id,/ position
           <== MsgDropFlag
           <== MsgFlagUpdate
 MsgCaptureFlag    player captured flag
           --> /id,/ team (team flag was taken to)
           <== MsgCaptureFlag
           <== MsgFlagUpdate
 MsgSetVar     <== count/[name/value]*
 MsgShotBegin      player has fired a shot
           --> FiringInfo
           <== MsgShotBegin
 MsgShotEnd        shot has terminated
           --> shooter id, shot number, reason
           <== MsgShotEnd
 MsgTeleport       player has teleported
           --> /id,/ from-teleporter, to-teleporter
           <== MsgTeleport
 MsgMessage        player is sending a message
           --> /id,/ target-id/team-id, message string
           <== MsgMessage
 MsgWantWHash      (player wants md5 of world file
           -->
 MsgNegotiateFlags -->flagCount/[flagabbv]
 MsgPause      -->true or false

server to player messages:

 MsgSuperKill      player must disconnect from server
           <== <none>
 MsgTimeUpdate     game time left, if == 0 player is dead and can't restart
           <== time (left, in seconds)
 MsgScoreOver      score limit reached, player is dead and can't restart
           <== id (winner), team (winner)
 MsgAccept     player request is accepted
           <== <none>
 MsgReject     player request is rejected
           <== <none>
 MsgAddPlayer      notification of new tank in game
           <== id, type, team, name, motto
 MsgRemovePlayer   player has exited the server
           <== id
 MsgAdminInfo      update of players' IP addresses
           only sent to players with the PLAYERLIST permission.
           <-- count, [chunklen, id, bitfield, address]*
 MsgPlayerInfo     update of players status
           <-- count, [id, bitfield]*
 MsgFlagUpdate     update of flag info
           <== count, [flag, flag-info]*
 MsgTeamUpdate     update of team info
           <== teamcount, [team, team-info]
 MsgGetWorld       chunk of world database
           <-- bytes left, next 256 byte chunk of world database
 MsgAlive      player is alive
           <== id, position, forward-vector
 MsgKilled     player is dead
           <== id (victim id), killer-id, reason, killer-shot-id
 MsgGrabFlag       notification that flag is grabbed
           <== id (grabber), flag, flag-info
 MsgDropFlag       notification that flag is in air
           <== id (dropper), flag, flag-info
 MsgCaptureFlag    notification that flag has been captured
           <== id (capturer), flag, team
 MsgShotBegin      some player has fired a shot
           <== FiringInfo
 MsgShotEnd        shot has expired
           <== id (shooter id), shot number, reason
 MsgScore      player score has changed
           <== num-scores [id (player id), wins, losses, tks]*n
 MsgTeleport       player has teleported
           <== id, from-teleporter, to-teleporter
 MsgMessage        message to players
           <== from-id, to-id/team-id, message string
 MsgQueryGame      game status
 MsgQueryPlayers   list of players
 MsgWantWHash      md5 digest of world file
           <== temp|perm, digest
 MsgNegotiateFlags <== flagCount/[flagabbv]
 MsgNewRabbit      a new rabbit has been anointed
           <== id
 MsgPause      <== id/true or false