PHPackages                             allejo/bzflag-networking.php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. allejo/bzflag-networking.php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

allejo/bzflag-networking.php
============================

A library for unpacking BZFlag network packets

v1.1.2(4y ago)079211MITPHPPHP &gt;=7.1CI failing

Since May 19Pushed 4y ago1 watchersCompare

[ Source](https://github.com/allejo/bzflag-networking.php)[ Packagist](https://packagist.org/packages/allejo/bzflag-networking.php)[ Fund](https://www.buymeacoffee.com/allejo)[ GitHub Sponsors](https://github.com/allejo)[ RSS](/packages/allejo-bzflag-networkingphp/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (8)Versions (18)Used By (1)

BZFlag Networking
=================

[](#bzflag-networking)

[![Packagist](https://camo.githubusercontent.com/3a63752053aad45c85c79934c46a34b0725a26aab804f75934a7d85d4f6decc8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c6c656a6f2f627a666c61672d6e6574776f726b696e672e7068702e737667)](https://packagist.org/packages/allejo/bzflag-networking.php)[![Code coverage](https://camo.githubusercontent.com/0a52638ec4a88063a930b98c86f59afc232eacc244ef4ee53b02f36227759207/68747470733a2f2f636f6465636f762e696f2f67682f616c6c656a6f2f627a666c61672d6e6574776f726b696e672e7068702f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d47474e33323342314b47)](https://codecov.io/gh/allejo/bzflag-networking.php)[![License](https://camo.githubusercontent.com/e7581dc65d3d398124d7260df642042c5986c8ee174fd40037c634f7a7da953b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f616c6c656a6f2f627a666c61672d6e6574776f726b696e672e7068702e737667)](https://github.com/allejo/bzflag-networking.php/blob/master/LICENSE.md)

A PHP 7.1+ library for reading and handling BZFlag network packets.

BZFlag Replay files are simply the raw packets stored in a file together, so this library will let you read replay files and unpack them into PHP classes that can be serialized into JSON.

Installation
------------

[](#installation)

This project is available via [Composer](https://getcomposer.org).

```
composer require allejo/bzflag-networking.php
```

### Related Libraries

[](#related-libraries)

- [`allejo/bzflag-rendering.php`](https://github.com/allejo/bzflag-rendering.php): a library for drawing radar images of BZFlag worlds from the classes provided in this package

Usage
-----

[](#usage)

This library has all of the utilities for unpacking BZFlag network packets and world packets. However, the only convenience methods available in this library is reading those packets from replay files.

### Analyzing Replay Packets

[](#analyzing-replay-packets)

The recommended use of this library is to "stream" the replays in your code with the `getPacketsIterable()` method, which reads and yields a packet at a time. This allows for you to iterate through a replay file once and not have to store the entire replay in memory as you're working with it.

```
use allejo\bzflag\replays\Replay;

$replay = new Replay(__DIR__ . '/my-bz-replay.rec');

foreach ($replay->getPacketsIterable() as $packet) {
    // do something with $packet
}
```

If you'd like to get all of a replay file's packets as an array, use the `getPacketsAsArray()` method. Keep in mind, that this will incur high-memory usage as the entire replay will be stored in an expanded format in memory. Additionally, all of the packets are read and if your code would like to perform any type of analysis, you will need to iterate through **all** of the packets again.

```
use allejo\bzflag\networking\Packets\GamePacket;

/** @var GamePacket[] $packets */
$packets = $replay->getPacketsAsArray();
```

### Embedded Worlds in Replays

[](#embedded-worlds-in-replays)

As of version 1.1+, this library supports extracting the world data that's embedded inside of replay files. The BZFlag World Database is not an easy object to navigate and contains a lot of "managers" that have an inventory of textures, obstacles, world weapons, etc.

Take a look at the [`allejo/bzflag-rendering.php`](https://github.com/allejo/bzflag-rendering.php) library for example usage of how to navigate the World Database.

```
use allejo\bzflag\replays\Replay;
use allejo\bzflag\world\WorldDatabase;

$replay = new Replay(__DIR__ . '/my-bz-replay.rec');

/** @var WorldDatabase $worldDB */
$worldDB = $replay->getHeader()->getWorldDatabase();

// or an convenience method exists too
$worldDB = $replay->getWorldDatabase();
```

### Exporting to JSON

[](#exporting-to-json)

> ⚠️ **High Memory Usage**
>
> The built-in `json_encode` function PHP will not be able to handle writing large JSON files from replays. At this point, it's necessary to stream your JSON using something like [`streaming-json-encoder`](https://github.com/violet-php/streaming-json-encoder). See the [PHP port of `rrlog`](https://github.com/allejo/rrlog/blob/master/src/allejo/rrlog/Writer/JsonWriter.php) for sample usage.

```
use allejo\bzflag\replays\Replay;

$replay = new Replay(__DIR__ . '/my-bz-replay.rec');

$json = json_encode($replay, JSON_PRETTY_PRINT);
file_put_contents(__DIR__ . '/my-bz-replay.rec.json', $json);
```

In Other Languages
------------------

[](#in-other-languages)

This library was originally written a few times in other languages with less features. However, those other projects are now end-of-life and this project has taken their place.

- [Go](https://github.com/allejo/bzflag-networking.go)
- [Python](https://github.com/allejo/bzflag-networking.py)

License
-------

[](#license)

[MIT](./LICENSE.md)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 98% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~66 days

Recently: every ~167 days

Total

17

Last Release

1487d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d66778910a0fa5d2df6f837ebcb61c9b2385767450d7e7325b4afa637b205988?d=identicon)[allejo](/maintainers/allejo)

---

Top Contributors

[![allejo](https://avatars.githubusercontent.com/u/1246453?v=4)](https://github.com/allejo "allejo (148 commits)")[![Adwitiya-Singh](https://avatars.githubusercontent.com/u/27353874?v=4)](https://github.com/Adwitiya-Singh "Adwitiya-Singh (3 commits)")

---

Tags

bzflagnetworkingphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/allejo-bzflag-networkingphp/health.svg)

```
[![Health](https://phpackages.com/badges/allejo-bzflag-networkingphp/health.svg)](https://phpackages.com/packages/allejo-bzflag-networkingphp)
```

###  Alternatives

[symfony/config

Helps you find, load, combine, autofill and validate configuration values of any kind

4.3k455.2M6.6k](/packages/symfony-config)[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k431.1M7.5k](/packages/symfony-dependency-injection)[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M568](/packages/symfony-maker-bundle)[symfony/service-contracts

Generic abstractions related to writing services

2.6k860.1M360](/packages/symfony-service-contracts)[fakerphp/faker

Faker is a PHP library that generates fake data for you.

3.9k358.5M3.5k](/packages/fakerphp-faker)[symfony/options-resolver

Provides an improved replacement for the array\_replace PHP function

3.2k493.9M1.6k](/packages/symfony-options-resolver)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
