# Dedicated server code split from client code

**URL:** <https://forums.unrealengine.com/t/dedicated-server-code-split-from-client-code/7446>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [July 11, 2014, 11:31pm UTC](https://forums.unrealengine.com/t/dedicated-server-code-split-from-client-code/7446 "2014-07-11T23:31:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Etapaa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Etapaa](https://forums.unrealengine.com/u/Etapaa)\
**Post date:** [July 11, 2014, 11:31pm UTC](https://forums.unrealengine.com/t/dedicated-server-code-split-from-client-code/7446/1 "2014-07-11T23:31:25Z")

</div>

Ok, my question is basically, how can i split code that needs to be in the game, but basically server side only from my build?, for instance i will have a persistent database per game, but i do not want clients to be able to host games, i want them to be ran on dedicated servers only, so how can i exclude say, my C++ database code, amung other things from my builds when it comes to compile/testing

---

<div class="post-metadata">

**Author:** ![Ben\_Zeigler](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ben\_Zeigler](https://forums.unrealengine.com/u/Ben_Zeigler)\
**Post date:** [July 14, 2014, 5:00pm UTC](https://forums.unrealengine.com/t/dedicated-server-code-split-from-client-code/7446/2 "2014-07-14T17:00:59Z")

</div>

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:

```auto

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:

```auto

#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.

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [July 14, 2014, 5:28pm UTC](https://forums.unrealengine.com/t/dedicated-server-code-split-from-client-code/7446/3 "2014-07-14T17:28:21Z")

</div>

Thanks for this info Ben!

🙂

Rama

---

<div class="post-metadata">

**Author:** ![Etapaa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Etapaa](https://forums.unrealengine.com/u/Etapaa)\
**Post date:** [July 14, 2014, 9:55pm UTC](https://forums.unrealengine.com/t/dedicated-server-code-split-from-client-code/7446/4 "2014-07-14T21:55:36Z")

</div>

Thanks a lot for all that info Ben! that is exactly the kind of thing i was looking for

---

<div class="post-metadata">

**Author:** ![Etapaa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Etapaa](https://forums.unrealengine.com/u/Etapaa)\
**Post date:** [July 16, 2014, 8:01pm UTC](https://forums.unrealengine.com/t/dedicated-server-code-split-from-client-code/7446/5 "2014-07-16T20:01:13Z")

</div>

More then likely a silly/dumb question 😕 but is there any information how how i can go about creating the second module to go along with my current project?, the docs seem to be down for me ( i allways get 404 errors ), and once again thank you for the help in solveing my issue

---

<div class="post-metadata">

**Author:** ![Etapaa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Etapaa](https://forums.unrealengine.com/u/Etapaa)\
**Post date:** [July 16, 2014, 10:23pm UTC](https://forums.unrealengine.com/t/dedicated-server-code-split-from-client-code/7446/6 "2014-07-16T22:23:41Z")

</div>

After some digging through Shootergame example, i found a example with the loading screen extra module it uses, so that and the information from Ben has solved my issues, so thank you a lot Ben! the information has finally allowed me to push on forward in my game.

---

<div class="post-metadata">

**Author:** ![dictateurfou](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dictateurfou](https://forums.unrealengine.com/u/dictateurfou)\
**Post date:** [June 27, 2024, 6:12am UTC](https://forums.unrealengine.com/t/dedicated-server-code-split-from-client-code/7446/7 "2024-06-27T06:12:54Z")

</div>

2024 update change  
UEBuildConfiguration.bWithServerCode  
To  
if (Target.bWithServerCode == true)
