Creating a session on Dedicated Server launch?

Hello,
I was just wondering what the best approach to creating a session on a dedicated server would be? As it currently stands I have the ability to create sessions through the game client as a PlayerController can be assigned. However with dedicated servers I’m not sure where to start, or if they are even able to create a session.

Any input is good!

Thanks,
.

Hi, you need UE4 from source and add the below code into GameSessions’s Register Server function.

    UWorld* World = GetWorld();
IOnlineSessionPtr SessionInt = Online::GetSessionInterface(World);
	
FOnlineSessionSettings Settings;
Settings.NumPublicConnections = 3;
Settings.bShouldAdvertise = true;
Settings.bAllowJoinInProgress = true;
Settings.bIsLANMatch = true;
Settings.bUsesPresence = true;
Settings.bAllowJoinViaPresence = true;

SessionInt->CreateSession(0, GameSessionName, Settings);
return;

That worked so far for me for testing in LAN on Linux Server. Be aware that tools like Virtual Box can block you from finding a session on your server.

Edit: You can then find the sessions on your dedicated server like you would find them in the ShooterGame or Multiplayer Shootout example. It is not necessary anymore with this to make a bp node or code to create session manually on server.

Thanks for this. Is there a way of changing the session names? As it currently is, it uses the username.

I think you have to change this afterwards when displaying the server in a widget and assign a string to it. Either in blueprint or code of your project.

Wouldn’t that only change it for the end user and not everyone?

Yeah I think I know what u mean. U can also try modifying something about FUniqueNetId or add another argument which is passed along from the created to every found session.

Still I think its possible afterwards. Look at the MultiplayerShootout. The first client (which should maybe be the admin) who gets a found session assigns a customized unique server name to the 24digits. Then this customized server name is assigned to the 24 digits during the duration the server stays up.

You then just save this correlation between 24 digits and your customized unique servername somewhere outside on a webserver. So when the 2nd client finds a session, it checks the webserver for any given correlation and the given 24 digits can only resolve to your customized server name.

But maybe thats all wrong :slight_smile:

The solution with a webserver will work, I already have a non-steam method setup like that. I’m just trying to see if there’s an in-engine method I could use to eliminate the need for a webserver. Thanks for you replies dude!

Good Luck with that !

I am having an issue linking to OnlineSessionSettings.h
On build it through linker errors for this. I attempted to #include the .h but with no luck. Has anyone else encountered this?

I forgot I posted this. It might just help if I added the proper modules to my .Build.cs. -.-

Hey… I’m having the same problem as Retro11231…the issue with linker errors in GameSession.cpp… I have tried adding the OnlineSessionSettings.h but it does not resolve the FOnlineSessionSettings problem…Here is the error:

Module.Engine.5_of_30.cpp.obj : error LNK2019: unresolved external symbol “public: void __cdecl FVariantData::Empty(void)” (?Empty@FVariantData@@QEAAXXZ) referenced in function “public: __cdecl TPair::~TPair(void)” (??1?$TPair@VFName@@UFOnlineSessionSetting@@@@QEAA@XZ)

D:\UE4\Engine\Binaries\Win64\UE4Editor-Engine.dll : fatal error LNK1120: 1 unresolved externals

If anyone has figured this out or has an idea how to, please post your solution… thanks…

Did some searching and it seems another person had the same problem but didn’t really explain how to solve the problem…

https://answers.unrealengine.com/questions/278667/dedicated-server-session.html

K-bob, you should not be editing the parent files in the engine. I think that is what you are doing maybe. You should create your own GameSession class and then override the RegisterServer function (which is a virtual function).
I will explain a bit more if you like.
cheers
Podge

i’ve added it here, this cpp is in the engine ? do i have to recompile the engine same as the whole project?

this is what i’m getting