On this page
Start here: build and run a server and a client
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.
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 setBF2_RETAILto another folder). It is never written to. - Two source trees that are fetched once, from the repository's root:
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 menusThe 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:
cargo build --release -p bf2-server --bins
cargo build --release --manifest-path crates\bf2-client\app\Cargo.toml --target-dir targetThis 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 -File crates\bf2-server\difftest\levels\make-root.ps1 -Root analysis\scratch\<you>\serverSettings#
Copy the game's server settings and edit the copy (<server>\mods\bf2\Settings\ServerSettings.con to <server>\mysettings.con). The lines worth changing:
| Line | Meaning |
|---|---|
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 16567 | the game's port (UDP) |
sv.maxPlayers 16 | |
sv.numPlayersNeededToStart 1 | a round starts with one player (the game's default is 2) |
sv.timeLimit 0 | a round's length in seconds; 0 for none |
sv.roundsPerMap 1 | rounds before the next map of the list |
sv.ticketRatio 100 | tickets in percent |
sv.startDelay 15, sv.spawnTime 15, sv.endOfRoundDelay 15 | seconds |
sv.coopBotCount 16, sv.coopBotRatio 50, sv.coopBotDifficulty 50 | bots, 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:
mapList.append strike_at_karkand gpm_cq 16
mapList.append gulf_of_oman gpm_cq 16Every 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#
target\release\bf2_server.exe --root <server> -- +config mysettings.con +mapList mymaplist.conEverything 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#
target\release\bf2_client.exe --home <profile folder> -- +szx 1280 +szy 960--homeis where the profiles live, the game'sMy Documents\Battlefield 2. A new folder gets a profile; you can make your own in the menu.- The window starts at
+szxby+szy;+fullscreen 1for 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#
- The main menu logs in the profile.
- MULTIPLAYER, then the LAN tab: your server appears. Select it and press JOIN.
- The loading screen, then the spawn screen: an army, a kit, a spawn point, DONE.
- Play. The keys are the profile's controls with the game's defaults.
- 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.
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.
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#
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 checkoutWhat the tests and scenarios compare against is on the test rigs page.
Where to go next#
| You want to | Read |
|---|---|
| understand the engine | engine overview, the frame and the tick, the object system |
| change a weapon or a vehicle | the CON system, add a weapon, add a vehicle |
| script a game mode | the Python layer, server rules |
| build a level | level authoring, the web editor |
| find your way in the code | how the codebase is organised; docs/release/LAYOUT.md in the tree has one line a folder and crate |
| build every program, not only these two | docs/release/BUILDING.md in the tree: the table of programs and what each needs |
| one guided hour: build, play, test, read a port | your first hour |
| contribute a port or a test | how a port is made, reading the notes |
| a short answer | questions 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):
| Crate | What it is |
|---|---|
crates/bf2-gate | PROGRAM bf2_gate: the WebSocket gateway between browser clients and the backend and servers |
docs/dev/guide/start.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.