s&box
RustCounter-Strike 2s&boxDeadlock
Wiki
Get s&box on Steam
Browse
OverviewGetting StartedCreating GamesEngine & ToolsDocumentationCommunity GamesResources
s&boxDocumentationNetworkingDedicated ServersServerside Code
SOURCE 2 · C#
Build and play games with s&box.

Facepunch's game engine and creation platform — make games in C#, or jump straight into community games.

Get s&box on Steam

s&box Wiki

  • Overview
  • Getting Started
  • Creating Games
  • Engine & Tools
  • Documentation
  • Community Games
  • Resources

Tools & Community

  • Getting Started
  • Creating Games
  • Engine & Tools
  • Resources

Platforms

  • RustBattle
  • CSBattle
  • Rust Game Wiki
  • CS2 Skins Wiki
  • Deadlock Wiki

About

  • Official Site
  • Developer Wiki
  • GitHub
  • Get on Steam
NOT AFFILIATED WITH FACEPUNCH STUDIOS · © 2026 s&box Wiki (community)
Docs/Networking
Networking

Serverside Code

:::info Serverside Code only works when running local projects - please read that page first.

:::

When compiling a project, if we're a dedicated server, we can run code in if #SERVER blocks.

protected override void OnUpdate()
{
#if SERVER
  Log.Info( $"This is a server update!" );
#else
  Log.Info( $"This is a client update!" );
#endif
}

If we're running on a dedicated server, we'll get This is a server update! spamming our console.

This is especially useful for omitting potentially sensitive code from client builds, like contacting an API server, or a database.

Say you have a GameManager.cs file, which has a partial class, you can accompany it with a GameManager.Server.cs file which is safely omitted from client builds and wraps the whole file in an #if SERVER block - it's a nice bit of sugar that saves you having a bunch of preprocessor blocks in your code.

All serverside code is stripped out of published games by default - so there's no worries there.

Source: Facepunch/sbox-docs (CC-BY-4.0) · updated 2025-07-09. Read it rendered on the official docs.

More in Networking

Connection Permissions
Custom Snapshot Data
Dedicated Servers
Http Requests
Network Events
Network Helper
Network Visibility
Networked Objects
← All documentation

Community wiki — not affiliated with Facepunch Studios. For the latest and most authoritative information, see the official developer wiki.