BF2.US bf2-rsdeveloper wiki Parity Discord bf2.us
On this page

Start here: build and run a server and a client

BF22142Heroes

bf2-rs is an engine, not a game: it reads the data of your own install of Battlefield 2, 2142 or Heroes and ships none of it. This page takes you from a checkout to a round on your own PC: build two programs, make a server folder, start the server, start the client, join.

From a checkout and your own install to a round your install (retail\) read only: archives, scripts, levels make-root.ps1 copies what a server reads a server folder its own settings, map list, logs the checkout cargo build --release bf2_client.exe --home <profiles> -- +szx 1280 bf2_server.exe --root <server> -- +config .. +mapList .. UDP 16567: actions up, ghosts and events down The client reads the same install for its meshes, textures, sounds and menus; nothing of the game is in the repository. The same two programs run Battlefield 2, 2142 and Heroes: the server folder's game decides. crates/bf2-server, crates/bf2-client/app, crates/bf2-server/difftest/levels/make-root.ps1
What reads what. Your install is only ever read; the server works in a copy of its own.

1. What you need#

  • Windows 10 or 11 with a current Vulkan or DirectX 12 graphics driver.
  • The Rust toolchain stable-x86_64-pc-windows-gnu.
  • Your own install of the game. The repository expects it under retail\ (for Battlefield 2: retail\battlefield2, or set BF2_RETAIL to another folder). It is never written to.
  • Two source trees that are fetched once, from the repository's root:
powershell
powershell -File crates\bf2-python\fetch-cpython.ps1      # CPython 2.3.4 and zlib, for the server's Python
powershell -File crates\bf2-ui\vendor\ruffle\setup.ps1     # the patched Ruffle checkout, for the menus

The first is the interpreter the game's own Python scripts run in (the Python layer); the second is the player of the Flash menus (the Flash layer).

2. Build#

From the repository's root, one target folder for both:

powershell
cargo build --release -p bf2-server --bins
cargo build --release --manifest-path crates\bf2-client\app\Cargo.toml --target-dir target

This gives target\release\bf2_server.exe and target\release\bf2_client.exe. Build release: a debug build is too slow to play.

3. A server folder#

The server needs a folder of its own with the files it reads. The game's Python writes compiled files beside its scripts and the server writes settings and logs, so never point the server at your install. One script makes the copy (both mods, every level, about 300 MB):

powershell
powershell -File crates\bf2-server\difftest\levels\make-root.ps1 -Root analysis\scratch\<you>\server

Settings#

Copy the game's server settings and edit the copy (<server>\mods\bf2\Settings\ServerSettings.con to <server>\mysettings.con). The lines worth changing:

LineMeaning
sv.serverName "My server"the name in the LAN browser
sv.serverIP "", sv.interfaceIP ""empty for every interface; "127.0.0.1" for this PC only
sv.serverPort 16567the game's port (UDP)
sv.maxPlayers 16
sv.numPlayersNeededToStart 1a round starts with one player (the game's default is 2)
sv.timeLimit 0a round's length in seconds; 0 for none
sv.roundsPerMap 1rounds before the next map of the list
sv.ticketRatio 100tickets in percent
sv.startDelay 15, sv.spawnTime 15, sv.endOfRoundDelay 15seconds
sv.coopBotCount 16, sv.coopBotRatio 50, sv.coopBotDifficulty 50bots, on co-op maps only

What these do in the rules is on the server rules page.

The map list#

A text file with one line a map, for example <server>\mymaplist.con:

con
mapList.append strike_at_karkand gpm_cq 16
mapList.append gulf_of_oman gpm_cq 16

Every entry must have the game mode of the first; the game refuses the others. Map names are the folders under mods\bf2\Levels; the sizes are 16, 32 or 64 as the level offers them. Bots exist only in co-op: mapList.append strike_at_karkand gpm_coop 16, with the three sv.coopBot* settings.

4. Start the server#

powershell
target\release\bf2_server.exe --root <server> -- +config mysettings.con +mapList mymaplist.con

Everything behind -- is the game's own command line. The window shows the load and then a status line with the port, the map and the players. Ctrl+C stops it; --seconds N stops it after N seconds. How the server ended is written to <server>\_home\bf2_server_exit.txt.

5. Start the client#

powershell
target\release\bf2_client.exe --home <profile folder> -- +szx 1280 +szy 960
  • --home is where the profiles live, the game's My Documents\Battlefield 2. A new folder gets a profile; you can make your own in the menu.
  • The window starts at +szx by +szy; +fullscreen 1 for full screen. Once a profile is logged in, the window takes the resolution of that profile's video options, as in the original.

6. Join and play#

  1. The main menu logs in the profile.
  2. MULTIPLAYER, then the LAN tab: your server appears. Select it and press JOIN.
  3. The loading screen, then the spawn screen: an army, a kit, a spawn point, DONE.
  4. Play. The keys are the profile's controls with the game's defaults.
  5. Escape opens the menu over the game; DISCONNECT leaves the server.

To host and join with one command there is play.ps1, and bf2_launcher is a window that starts the client, the server and their options from an installed build; both are described in notes/play-guide.md.

Battlefield 2142 and Heroes#

The same two programs run all three games; the server's root decides which.

2142
Battlefield 2142

A root made from a 2142 install runs 2142. The port is younger than Battlefield 2's; what is proven is on the parity page.

Heroes
Battlefield Heroes

A Heroes root is made by its own script from your Heroes install:

python tools\bfheroes\make_root.py server --out <dir> --src <your Heroes install>

Heroes pages of this wiki: abilities, classes, the HUD, widgets.

In a browser#

The client also builds to WebAssembly with WebGPU and talks to servers through a relay (bf2-gate), because a page cannot open a UDP socket. The public builds are on bf2.us/play.

Check your build#

powershell
cargo test -p bf2-net                              # one crate's tests
python tools\scenarios\scn.py run <name>            # one scenario: a real server and a real client
python tools\devwiki\build.py --serve 26060         # this wiki, built from your checkout

What the tests and scenarios compare against is on the test rigs page.

Where to go next#

You want toRead
understand the engineengine overview, the frame and the tick, the object system
change a weapon or a vehiclethe CON system, add a weapon, add a vehicle
script a game modethe Python layer, server rules
build a levellevel authoring, the web editor
find your way in the codehow the codebase is organised; docs/release/LAYOUT.md in the tree has one line a folder and crate
build every program, not only these twodocs/release/BUILDING.md in the tree: the table of programs and what each needs
one guided hour: build, play, test, read a portyour first hour
contribute a port or a testhow a port is made, reading the notes
a short answerquestions people ask

Notes: notes/play-guide.md (every detail of this page and more).

How it is tested#

The commands on this page are the tree's own (README.md, docs/release/BUILDING.md, notes/play-guide.md); the wiki's worker runs no compiler, so they are not run by the wiki's test. The play guide records how it was tested by its writers. Your first hour marks each command as checked or as the tree's docs give it. The wiki's test checks that every link and anchor on it leads to a page of the build and that its diagrams are the ones the script draws.

In the code#

The crates this page names, each with its line of docs/release/LAYOUT.md (the list is gathered by the wiki's build from the page itself):

CrateWhat it is
crates/bf2-gatePROGRAM bf2_gate: the WebSocket gateway between browser clients and the backend and servers
Source: docs/dev/guide/start.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.