Download

Server-only config?

I’m looking for a way to designate a config value as “dedicated server only”; that is, I want it such that when UE4 builds a client (non-dedicated server), it automatically strips the given configuration value from the build so that it is not included in the final client package.

Our plugin involves the use of a public/private key pair, and while I want the private key pair to be present during development (when you’re using the editor, so that multiplayer PIE works), I need to ensure that the private key never gets shipped with the game.

So far I haven’t been able to find anything on this topic. Does anyone have any ideas?

EDIT: Actually, I’d also settle for having a configuration item that is stripped out of all builds if server-only is not an option, since our plugin can also accept the private key as an environment variable for the dedicated server.

From Build.h



/**
 *   Whether compiling for dedicated server or not.
 */
#ifndef UE_SERVER
    #define UE_SERVER                    0
#endif


So you can likely wrap your code in



int64 GetPrivateKey() const
{
#if !defined(UE_SERVER)
 // Client
 return 0;
#else
 return MyKey; // Server
#endif
}


Hmm, that’s not quite what I’m after.

That will change the code so that it doesn’t load the value at runtime if it’s on the client. But what I actually want is for the value to not appear in the config files at all on the client. Effectively, I want the packaging process to strip out config values that are “server only” when building the game client.

Create a custom UObject and add PrivateKey as a UProperty to that object like this:



#if WITH_EDITORONLY_DATA

      UPROPERTY(config)
      FKeyType  MyPrivateKey;

#endif


Functions that manipulate the private key, strip them out of clients and builds like this:



void DoSomethingWithKey()
{
    #if WITH_SERVER_CODE
        #if WITH_EDITOR
            // Use private key value...
        #endif
    #endif
}


Neither the key nor the code that manipulates the key should be added to packaged game that way.
Only server in editor mode will be able to see it.

Note that the UObject class must specify a config = ConfigFileName in its UCLASS() declaration.

Although the private key is no longer in the code, it is still in the configuration file of the client

Don’t put the private key into the project at all.
Have your code read it from an environment variable (e g, with “getenv()”) and set that environment variable when you run the server in question.
Development workstations can use a development private key and set up their own environment variables as part of build setup.