OpenBF1942-Plus
Refractor 1, rebuilt from scratch
Loading...
Searching...
No Matches
bfnet Namespace Reference

Classes

class  BitReader

Functions

 parse (d)
 actions (r)
 soldier (r, base)
 body (r, base)
 engine (r, gears=None)
 bundle (r)
 firearm (r, mag, mags)
 spring (r)
 composite (r, base, layout)
 vehicle (r, base, end)
 control_point (r, base)
 kit (r, base)
 projectile (r, base)
 player (r, base)
 score_manager (r, base)
 spawn_manager (r, groups)
 spawn_groups (data, start, bits)
 classify (classes, nid, data, start, bits, base)
 ghosts (r, classes=None)
 _u (n)
 _range_bits (lo, hi)
 _create_object (r)
 _chat (r)
 _game_status (r)
 _score (r)
 _map (r)
 _checksum (r)
 _stats (r)
 _pb_fragment (r)
 event (r)
 events (r)
 payload (direction, data, classes=None)
 load (path)
 track_classes (classes, m)
 summary (rows)
 record (listen_port, server_ip, server_port, path, seconds)
 main (argv)

Variables

 DATA
 CONNECT_REPLY
 CONNECT_ACK
 DISCONNECT
 PING
 PONG
dict CVEC_BITS = {1: 20, 2: 16, 3: 12}
int BODY_KIT_BITS = 7
int ANIM_STATE_BITS = 11
tuple MANAGERS = ("actions", "events", "ghosts", "downloads")
dict LAYOUTS
dict TEAM_FIELDS = {0: "deaths", 6: "flag_attacks", 7: "teamkills", 8: "score", 9: "tickets", 10: "rounds_won"}
dict GHOST_READERS
 B
 STR
 VEC
dict EVENTS

Detailed Description

Battlefield 1942 game traffic (UDP game port): transport layer reader and a recording relay. Stdlib only.

Spec: docs/formats/network.md

Usage:
  bfnet.py record <listen_port> <server_ip> <server_port> <out.jsonl> <seconds>
      UDP relay: point the client at this machine (+joinServer <this ip>:<listen_port>); every datagram both
      ways is forwarded and logged as one JSON line {t, dir: c2s|s2c, client, hex}. The log holds the player's
      name and CD-key hash: keep it out of the repository.
  bfnet.py summary <in.jsonl>
      packets per direction and type, sequence gaps, acknowledgement mismatches, payload sections (stream manager
      mask), how many fully decoded payloads end in their last byte, game events by name, client frame / server tick
      range, ghost ids

Function Documentation

◆ _chat()

bfnet._chat ( r)
protected

◆ _checksum()

bfnet._checksum ( r)
protected

◆ _create_object()

bfnet._create_object ( r)
protected

◆ _game_status()

bfnet._game_status ( r)
protected

◆ _map()

bfnet._map ( r)
protected

◆ _pb_fragment()

bfnet._pb_fragment ( r)
protected

◆ _range_bits()

bfnet._range_bits ( lo,
hi )
protected
Width BitStream::readUnsigned(min, max) uses: the smallest n with 2^n - 1 >= max - min + 1.

◆ _score()

bfnet._score ( r)
protected

◆ _stats()

bfnet._stats ( r)
protected

◆ _u()

bfnet._u ( n)
protected

◆ actions()

bfnet.actions ( r)
PlayerActionManager section: u4 count, then if any a signed 32-bit first frame, then per action six u12
values and a u32 (meaning of the values open).

◆ body()

bfnet.body ( r,
base )
SimpleObjectNetworkable update (a vehicle's body): u11 mask, then the fields whose bit is set.

◆ bundle()

bfnet.bundle ( r)
RotationalBundleNetworkable update: u7 mask, then a 16-bit signed float per set bit (angles x180, speeds,
the last x41; raw value kept).

◆ classify()

bfnet.classify ( classes,
nid,
data,
start,
bits,
base )
Give an object no event named a class from its update: a LAYOUTS entry that reads it exactly (with the body,
if it has a position, within 5 m of the CreateObject position); else a vehicle when it decodes as body and engine
near that position; else a control point when it is 7 bits or less and fits.

◆ composite()

bfnet.composite ( r,
base,
layout )
Read an object's update as the components of a LAYOUTS entry, in order.

◆ control_point()

bfnet.control_point ( r,
base )
ControlPointNetworkable update: u2 mask; 0x1 a 4-bit signed value, 0x2 a flag.

◆ engine()

bfnet.engine ( r,
gears = None )
EngineNetworkable update: u10 mask, fields by bit, then a u32 that rises by one per update.

◆ event()

bfnet.event ( r)
One game event: 7-bit id, then its fields. Raises ValueError on an unknown id.

◆ events()

bfnet.events ( r)
GameEventManager section: u8 count, u5 block index, a flag, then the events.

◆ firearm()

bfnet.firearm ( r,
mag,
mags )
FireArmsNetworkable update: u2 mask; 0x1 range 0..magSize+1, 0x2 range 0..numOfMag+1 (template values).

◆ ghosts()

bfnet.ghosts ( r,
classes = None )
GhostManager section: u32 server tick, u8 entry count, a flag, the player's control object state when the
flag is set, then the entries. Each entry is a u2 kind and a u16 networkable id; kind 1 carries a flag and an
u11 bit length of its update (skipped here), kind 3 removes the ghost, kind 2 is an error.

◆ kit()

bfnet.kit ( r,
base )
KitNetworkable update: u4 mask; 0x1 position (full vector), 0x2 range 0-256, 0x4 flag, 0x8 range 0-8.

◆ load()

bfnet.load ( path)

◆ main()

bfnet.main ( argv)

◆ parse()

bfnet.parse ( d)
One datagram -> dict. Raises ValueError on a malformed packet.

◆ payload()

bfnet.payload ( direction,
data,
classes = None )
Data payload -> {"mask", section name: decoded, "end": bit position where decoding stopped, "open": name of
the first section not decodable yet (downloads) or None}. A 6-bit mask names the stream managers that wrote into
the packet; their sections follow in id order. `classes` maps networkable ids to a GHOST_READERS name; their
ghost updates are decoded with it (see `track_classes`).

◆ player()

bfnet.player ( r,
base )
BFPlayer update: u24 mask, ranged fields by bit, then always a flag. Names are those matched against the
recording's events and server log; the others keep their bit.

◆ projectile()

bfnet.projectile ( r,
base )
ProjectileNetworkable update: u8 mask; position and velocity at scale 0.01, a 12-bit quaternion.

◆ record()

bfnet.record ( listen_port,
server_ip,
server_port,
path,
seconds )

◆ score_manager()

bfnet.score_manager ( r,
base )
ScoreManager update: u24 mask; bits 0-10 team 1 and 11-21 team 2 (signed 18-bit each), 22 and 23 signed
3-bit round-end values.

◆ soldier()

bfnet.soldier ( r,
base )
BFSoldierNetworkable update: u14 mask, a flag, then the fields whose mask bit is set.

◆ spawn_groups()

bfnet.spawn_groups ( data,
start,
bits )
The spawn manager's group count, found as the mask width that makes an update end exactly at its length.

◆ spawn_manager()

bfnet.spawn_manager ( r,
groups )
BFSpawnPointManager update: a mask with one bit per spawn group of the level, then per set bit u4 team, a
flag (active), and the group's x / 8 and z / 8 as bytes.

◆ spring()

bfnet.spring ( r)
SpringNetworkable update: u1; when set, two vectors in the 'high' compression table (widths unknown).

◆ summary()

bfnet.summary ( rows)

◆ track_classes()

bfnet.track_classes ( classes,
m )
Update `classes` (networkable id -> ghost reader) from a decoded payload's events and ghost entries:
CreatePlayer names a player, DataBaseComplete the spawn and score managers, SetDefaultVehicle the player's soldier, SetVehicle a vehicle, HandlePickup a kit, CreateMultipleObjects
projectiles; other CreateObject ids are left for `classify`. DestroyObject forgets an id (ids are reused).

◆ vehicle()

bfnet.vehicle ( r,
base,
end )
A vehicle's update: body, engine, then the other components (springs, turrets, weapons; not decoded).

Variable Documentation

◆ ANIM_STATE_BITS

int bfnet.ANIM_STATE_BITS = 11

◆ B

bfnet.B

◆ BODY_KIT_BITS

int bfnet.BODY_KIT_BITS = 7

◆ CONNECT_ACK

bfnet.CONNECT_ACK

◆ CONNECT_REPLY

bfnet.CONNECT_REPLY

◆ CVEC_BITS

dict bfnet.CVEC_BITS = {1: 20, 2: 16, 3: 12}

◆ DATA

bfnet.DATA

◆ DISCONNECT

bfnet.DISCONNECT

◆ EVENTS

dict bfnet.EVENTS
Initial value:
1= {
2 2: ("Ack", [_u(32)]), 3: ("Debug", [("s", 32)]), 4: ("Simulation", [B, ("raw", 4)]),
3 5: ("CreateMultipleObjects", [_u(32), _u(16), _u(4)]), 6: ("DestroyObject", [_u(16)]),
4 7: ("CreateObject", _create_object),
5 8: ("CreatePlayer", [_u(3), _u(4), B, _u(8), _u(16), _u(16), _u(16), _u(16), B, ("raw", 32)]),
6 9: ("SetDefaultVehicle", [_u(8), _u(16)]), 10: ("SetVehicle", [_u(8), _u(16)]), 11: ("ExitVehicle", [B, _u(8)]),
7 12: ("DestroyPlayer", [_u(8)]), 13: ("SetPlayerName", [STR, _u(8)]), 14: ("SetTempCamera", [_u(16)]),
8 15: ("ConnectionType", [_u(_range_bits(0, 6))]), 16: ("UpdateRate", [_u(8)]), 17: ("CreatePlayerAck", [_u(8)]),
9 18: ("Vote", [_u(8)] * 5 + [("raw", 4), _u(_range_bits(0, 4)), _u(_range_bits(0, 3))]), 19: ("Map", _map),
10 20: ("Challenge", [("raw", 10), ("s", 32), STR, ("raw", 8)]),
11 21: ("ChallengeResponse", [("raw", 73), _u(32), _u(32), _u(32), ("s", 32), ("raw", 32), B]),
12 22: ("GameRules", [("raw", 4), B, B, ("raw", 4), _u(32), _u(32), B]), 23: ("WelcomeMsg", [STR, ("s", 8)]),
13 24: ("ResetMap", [_u(32)]), 25: ("CheckSum", _checksum), 26: ("ServerInfo", [STR, STR, STR]),
14 27: ("ServerInfo2", [STR]), 30: ("FlagHolder", [B, _u(8)]), 35: ("HandlePickup", [_u(8), _u(16)]),
15 36: ("GameStatus", _game_status), 37: ("ControlPointCaptured", [_u(8), _u(8)]),
16 38: ("ReqScoutCamera", [_u(8), _u(16)]), 39: ("SpecialGame", [_u(2)]), 40: ("ChatFragment", _chat),
17 41: ("TimerSync", [_u(32), _u(32)]), 42: ("ScoreMsg", _score),
18 43: ("PBFragment", None), 47: ("SpawnRequest", [_u(8), _u(8)]),
19 48: ("StatsKills", _stats), 49: ("StatsShots", _stats), 50: ("StatsHits", _stats), 51: ("Suicide", []),
20 52: ("DataBaseComplete", [_u(16), _u(16)]), 53: ("DatabaseCompleteAck", []),
21 54: ("SetLevel", [("raw", 64), ("raw", 64), _u(8), _u(8), _u(16), _u(8), _u(16), _u(16), _u(8), _u(32), _u(32)]),
22 55: ("SessionId", [("raw", 64)]), 57: ("SetTeam", [_u(8), _u(8)]), 58: ("RadioMessage", [_u(16), B, _u(8)]),
23 59: ("TriggerObjectSpawner", [_u(8)]), 60: ("HitFromPos", [_u(3), _u(8)]),
24 61: ("RemoteCommand", [("raw", 9), ("raw", 64)]), 62: ("ChangeKit", [_u(8)]),
25}

◆ GHOST_READERS

dict bfnet.GHOST_READERS
Initial value:
1= {"player": player, "score_manager": score_manager, "soldier": soldier, "vehicle": None, "control_point": control_point, "kit": kit,
2 "projectile": projectile}

◆ LAYOUTS

dict bfnet.LAYOUTS
Initial value:
1= {
2 "t34-85": [("body", 7), ("engine", 5), ("spring",), ("spring",), ("spring",), ("spring",), ("bundle",), ("bundle",),
3 ("firearm", 30, 1), ("firearm", 400, 1)],
4 "hanomag": [("body", 7), ("engine", 4), ("spring",), ("spring",), ("spring",), ("spring",), ("bundle",)],
5 "stationary_mg": [("body", 5), ("bundle",), ("bundle",)],
6 "vehicle_mg_seat": [("bundle",), ("bundle",), ("firearm", 500, 1)],
7}

◆ MANAGERS

tuple bfnet.MANAGERS = ("actions", "events", "ghosts", "downloads")

◆ PING

bfnet.PING

◆ PONG

bfnet.PONG

◆ STR

bfnet.STR

◆ TEAM_FIELDS

dict bfnet.TEAM_FIELDS = {0: "deaths", 6: "flag_attacks", 7: "teamkills", 8: "score", 9: "tickets", 10: "rounds_won"}

◆ VEC

bfnet.VEC