GoldSrc Networking, Part 1: The High-Level Overview
A tour of the GoldSrc (Half-Life / Counter-Strike 1.6) networking stack -- its QuakeWorld remains, the client-server model, and the five layers that carry world state from server to clients. Part 1 of a four-part reverse-engineering series.
This is the first part of a series on the networking side of GoldSrc. I previously tried to document the networking in another article, but I plan to make this series much more detailed. I plan to write in great detail how the engine moves an entire game world between a server and dozens of clients, dozens of times a second, over the unreliable internet of the late 90s.
- 👉 (this article) Part 1 -- The High-Level Overview: history, the client-server model, and the five-layer stack.
- Part 2 -- Transmission: how bytes actually cross the wire -- UDP and
SPLITPACKET, the NetChannel's one-bit reliability, bit serialization, and the delta encoder. - Part 3 -- The Server: Lag Compensation, Client Movement, Speedhacking: entity snapshots, PVS culling, baselines, usercmd processing, and rewinding the world for hit registration.
- Part 4 -- The Client: Prediction & Interpolation: reconstructing snapshots, predicting movement, and interpolating other players.
In this first part of the series I tried not to go into much detail about the code and technicalities. However, I tried to share some interesting facts about the history and the general overview of the networking stack.
The other parts of the series should cover some of the more complex topic such as delta updates, prediction, interpolation/extrapolation, compression, lag compensation, and more, in more detail.
Enjoy reading! ☕
Overview¶
Counter-Strike 1.6 is a game based on the GoldSrc engine. The GoldSrc engine is the engine powering many games from the 90's and early 2000's you might know such as Half-Life, DoD, and hundreds of mods. While the modding community in GoldSrc is big, not necessarily all mods use the networking stack GoldSrc provides -- since they're mostly single-player only.

Counter-Strike 1.6 Steam build 8684 on a public server on the de_dust2 map.
While GoldSrc is the veteran of the game engines, one might think that the code powering it would be simple and uncomplicated. However, fortunately, that's not the case!
Now, just to give an idea, and I honestly agree that LOC (Lines-Of-Code) isn't a good metric to rate a codebase. Also the fact that less code = better1 is a wildly known fact. But still, we have a rough estimate on how big the engine is. Given the Hardware engine2, the estimated LOC based on DWARF information is ~150k lines spanning across ~287 files (not counting the assembly and Windows-only files of course). The Windows/Asm files then add approximately ~15 source files and 10k lines.
Quake and GoldSrc¶
GoldSrc engine is a reminiscence of Quake engine. In fact, many of the parts in GoldSrc resemble the original 1996 Quake engine. The code style, the file names, much of the code, as well as inherited netcode from QuakeWorld. QuakeWorld is an official multiplayer source port made by id Software for Quake that was released in December of 1996 and updates the multiplayer source code.
Valve licensed the id's Quake / Quake II technology around early 1997 and started building Half-Life on top of it. They added a lot of new features such as AI, animations, scripting, rendering features, modding, studio models, etc. GoldSrc also used code from Quake II in a form of small updates / improvements, and bug fixes3.
After the two years of Half-Life development, Valve published the title in November 19, 1998. After that between the years 1999 - 2003 Valve invested heavily into the engine, adding bug fixes, releasing patches, improving the networking and so on. This is also the time when the networking code changed a lot where Valve was experimenting with the protocol and such.
After 2003 we can see a shift towards a new engine -- Source. And GoldSrc wasn't updated internally that much from then on.
Around this time, 2002+, Valve was also experimenting with VAC1 -- the first iteration of the Valve Anti Cheat, and they were implementing some other anti-reverse-engineering techniques such as encrypting the engine DLL on disk, and decrypting it at runtime. I wrote a simple decryptor that can decrypt these DLLs.
Valve also tried to make their own engine out of the "borrowed" Quake engine after realizing that they'd go for a second Half-Life title. They started by rewriting the engine heavily and shifting from C towards C++ only, rewriting some of the core subsystems. However, some of the Quake code survived all the way to CS:GO, and may have survived even to Source2. For example this comment from Quake in common.cpp in the CS:GO leak from 2020; See it in Quake source code
What Networking Changes did Valve bring¶
GoldSrc's netcode is a direct descendant of QuakeWorld. John Carmack's QuakeWorld introduced client-side prediction, delta compression, and a rate-limited unreliable-datagram model. Valve took that architecture and built on top of it. They added:
- delta system
- entity interpolation with position history
- server-side lag compensation
- file fragmentation transfer over the channel
- BZIP2 compression of transmitted file data
- packet splitting at the socket level -- also called
SPLITPACKET4
Actually, to give the Quake developers credit, the networking stack in the QuakeWoeld port is quite impressive. You've got a minimal-latency, lag-compensating (sort of), real-time shooter game from the 90s. I mean how cool is that? This really shows how skilled the devs behind Quake (and upcomming games) were. These people were really curious about the technology, and they wanted to make it as best as possible.
The basic idea behind Quake networking is this:
a) Client sends input b) Servers (as an authority, to eliminate cheating) processes inputs c) Meanwhile client predicts movement client-side (a lot of space if the ping (or also known as RTT - Round Trip Time) is high) d) Server corrects client when needed
Visually, the loop looks roughly like this:
flowchart LR
C1["<b>Client</b><br/>sends input"]
S["<b>Server</b><br/><i>the authority</i><br/>processes inputs"]
C2["<b>Client</b><br/>predicts movement<br/>while it waits"]
C3["<b>Client</b><br/>gets corrected<br/>if it guessed wrong"]
C1 --> S --> C3
C1 --> C2 --> C3
C3 -.->|next frame| C1
classDef srv fill:#2d3b52,stroke:#5a7db0,color:#eef2f7;
classDef cli fill:#22303f,stroke:#3d5a80,color:#e0e6ed;
class S srv
class C1,C2,C3 cli
The client-server communication model in GoldSrc
At the time, this was a novel architecture, and it was a backbone for all of the later-developed multiplayer games. A little quote from John Carmack when he was planning to work on the netcode rewrite for QuakeWorld in August 1996:
The big difference is in the net code. While I can remember and justify
all of my decisions about networking from DOOM through Quake, the bottom
line is that I was working with the wrong basic assumptions for doing a
good internet game. My original design was targeted at <200ms connection
latencies. People that have a digital connection to the internet through
a good provider get a pretty good game experience. Unfortunately, 99% of
the world gets on with a slip or ppp connection over a modem, often through
a crappy overcrowded ISP. This gives 300+ ms latencies, minimum. Client.
User's modem. ISP's modem. Server. ISP's modem. User's modem. Client.
God, that sucks.
The Layers of the Netcode¶
In short, the networking stack has 5 layers.
flowchart LR
L5["<b>Layer 5</b><br/>Game protocol<br/><i>svc_* / clc_*</i>"]
L4["<b>Layer 4</b><br/>Delta compression<br/><i>delta.c</i>"]
L3["<b>Layer 3</b><br/>Bit serialization<br/><i>common.c</i>"]
L2["<b>Layer 2</b><br/>NetChannel<br/><i>net_chan.c</i>"]
L1["<b>Layer 1</b><br/>UDP socket<br/><i>net_ws.c</i>"]
L5 --> L4 --> L3 --> L2 --> L1
classDef app fill:#2d3b52,stroke:#5a7db0,color:#eef2f7;
classDef mid fill:#22303f,stroke:#3d5a80,color:#e0e6ed;
class L5 app
class L4,L3,L2,L1 mid
The five layers of the GoldSrc netcode stack.
Layer 1 -- UDP Socket (net_ws.c)¶
The first layer is the UDP socket layer (referred to as the net_ws.c layer). It is responsible for the usermode data-on-socket transmission, and uses the classic Berkeley sockets API -- socket, bind, sendto, recvfrom, etc.
Layer 2 -- The NetChannel (net_chan.c)¶
The second layer, the modified Quake NetChannel (the net_chan.c code), is a lightweight TCP stack built on top of UDP. It reimplements the useful parts of TCP -- ordered, guaranteed delivery -- without actually being TCP, so the engine can send both unreliable and reliable data over the same channel. It also fragments oversized payloads (e.g. files), rate-limits the outgoing flow, and obfuscates the payload with munge xorring (COM_Munge), plus BZIP2 compression for fragments.
Layer 3 -- Bit Serialization (common.c)¶
The third layer is bit serialization. GoldSrc followed the Quake style, and they left all of the functions in common.c -- the MSG_ functions such as MSG_WriteBits or MSG_ReadBits, and others. This layer also handles byte-order conversion, so the protocol works the same across architectures and is endian-friendly.
Layer 4 -- Delta Compression (delta.c)¶
Then comes the fourth layer, the delta compression. Each update made to an entity is carried out through something called a delta update. The engine doesn't send everything it knows about an entity, only the fields that have actually changed since a reference frame. When it needs to, it can send the complete state known as a full update. This code is in delta.c. The idea comes from Quake -- but GoldSrc turns it into a runtime, self-describing table system, as part of the modding efforts. Mods can describe their custom delta descriptors via a delta.lst file.
To give a concrete idea: say a player moves a bit. Instead of re-sending the whole entity state -- position, angles, animation frame, current weapon, health, and a bunch of other fields -- the server diffs it against a reference frame and sends only what changed. If just the origin moved, that's roughly what gets send to the clients, resulting in a handful of bytes instead of the full struct. Now multiply that across every entity, every server update, for dozens of players. You can probably see why this is the single biggest bandwidth optimization in the whole stack.
Layer 5 -- Game Protocol (svc_* / clc_*)¶
The final layer is the actual game protocol (currently at version 48), is the actual data exchanged between server->client (and vice versa). Most of this stream isn't delta-compressed. The delta compression is not used here; it's only used for entities.
This stream is just a sequence of messages, each identified by a ID (one byte). The server->client ones are the svc_* messages (svc_print, svc_sound, svc_temp_entity, and so on), and the client->server ones are clc_*. So when the server wants to play a sound or print something to your console, it writes the matching svc_ byte followed by whatever that message expects, and the client reads the byte, looks up the handler, and parses the rest. This is one type of server-client communication.
Putting it together¶
As you can see, the foundation -- sockets, the channel, bit packing, and the delta concept -- comes directly from Quake, and Valve just built on top of it. Which again shows how mature the Quake engine already was at the time. The additions Valve made to these systems include lag compensation, the self-describing delta tables, and reliable file transfer via fragmentation.
How the Netcode Evolved¶
GoldSrc's protocol was quickly evolving after the initial Sierra/WON release of the game. Between 1999 and 2005 Valve iterated on it heavily, and you can still see the remains in the code today. Protocol 48 is the latest version and it appeared around build 4554 (2009) and more than a decade later, even though the engine itself roughly doubled in size, the protocol is kind of unchanged.
The early 1999/2000 builds are even more compelling. They contains a -protocol launch option that allows to change the version all the way back to 35. In this version there were also no self-describing delta tables (delta.lst). The oldest engine DLLs still delta-encode entities the hardcoded Quake way.
Fun fact, from build 9xx to 1792 (1999-2001) the protocol version jumped from 35 to 45.
After around 2003-2005 Valve's attention moved primarily to the Source engine and GoldSrc's netcode largely stopped changing. Valve built Source on top of GoldSrc, and so many of the things GoldSrc used can still be found in CS:GO and even Source2 engines. Notable the Source2 engine still uses the Delta system (kind of, heavily modified and interated over, of course), in a form of schemas, flattened serializers, and field path traversal.
Conclusion¶
And that's the high-level overview. I didn't mention a single line of disassembly, but you should now have a mental map of the whole thing; where GoldSrc came from (QuakeWorld, and a whole lot of id's original code), the client-server model that keeps the game responsive, and the five layers the current world state travels through from the server to the client.
The next parts go into each layer on its own. Part 2 -- Transmission starts at the bottom of the stack -- the UDP socket and the NetChannel -- and looks at how the bytes actually get on the wire, and how the channel pulls off reliable delivery over plain UDP with basically a single bit.
See you in the next one! ☕
-
Even though I've notoriously used LOC as a core metric to brag about in one of my biggest projects -- Read the first sentence in the project's readme 😅. Although I have to admit that, a) that project was built before LLMs, and indeed everything was written by hand, and b) I've since learnt that less LOC = better (that project was built over 3 years ago!). ↩
-
The engine being the OpenGL engine (not the Software-renderer engine) --
hw.dll, as it's known. The SW engine houses many more thousands lines of code, and is not that different to the IdTech's Quake SW renderer (with some upgrades and improvements). ↩ -
This can be seen all throughout the engine. One of the biggest being the Aureal3d sound system, which was implemented for many quake-based games at the time, therefore being easily implementable into the existing codebases. ↩
-
Only on the server->client path because this path is write-heavy. The client alone will never send as much data to the server as the server does to all of the clients each tick. The threshold is 1400 bytes, after that the packet gets split. ↩