Dedicated server code split from client code

The key to this is the Server and Client code configuration. So to build a cooked client that doesn’t have access to dedicated server code you can build “Development Client”, which is almost the same as “Development” but with server-only code disabled. What this does is set the WITH_SERVER_CODE define to false. When this is false various things like server-side networking are compiled out in the engine. There is no client-only configuration with editor functionality enabled, so this only works with cooked builds. And you can then use this same feature to disable any game-specific server-side code. You have two options:

  1. Place #if WITH_SERVER_CODE around the bodies of individual server side functions. This is really useful if you only want to disable a function or 2 in a class that otherwise should exist on the client, but is very cumbersome if you want to hide an entire class from clients.
  2. Make a server side module. For instance on fortnite we have a FortniteServer module that has most of the GameMode classes defined in it, as well as other support code. You make a server module very similar to how you make a game-specific editor module. You’ll then have to add a conditional module dependency on your server module to your *Game.build.cs file. Here’s the relevant lines from ours, which is right after you declare the normal public and private module depdendencies:

if (UEBuildConfiguration.bWithServerCode == true)		
{
	PublicDependencyModuleNames.Add("FortniteServer");
	CircularlyReferencedDependentModules.Add("FortniteServer");
}

This will link in the module, but only when it’s not a Client configuration. Then you can use those classes from your main game module, as long as you wrap the usage in WITH_SERVER_CODE. We did this by adding this to our game pch file:


#if WITH_SERVER_CODE
#include "FortniteServerClasses.h"
#endif // WITH_SERVER_CODE


Then if we want to use a server class, we wrap the usage in WITH_SERVER_CODE as well.

3 Likes