Understanding the IOnlineSubsystem and AGameSession [C++]

Hi!

I would need some help understanding the following code:

IOnlineSubsystem* OnlineSub = IOnlineSubsystem::Get();
	if (OnlineSub)
	{
		IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface();
		if (Sessions.IsValid())
		{
		Sessions->AddOnStartSessionCompleteDelegate(OnStartSessionCompleteDelegate);
		Sessions->StartSession(GameSessionName);
		}
	}

(The code is taken from the ShooterGame example.)

From my understanding the “IOnlineSubsystem” interface is used to support communication with various services in a high level fashion, correct? At the moment I have no third party service involved so I guess there some default implementation in use? IOnlineSession and AGameSession are different things right? Are IOnlineSession used to setup servers and finding games while AGameSession handles the game server session itself? Correct me if I’m wrong.

Sessions->StartSession(GameSessionName);

What is GameSessionName? What function does it have? Does this create a AGameSession or where does that happen?

My goal is to understand how to setup a server and joining with clients in code.

You understanding of these systems seems correct. IOnlineSubsystem is our abstraction for supporting what we call “platform services”, like LIVE, PSN, Steam, etc. It handles the bookkeeping necessary to interact with their matchmaking, game advertisement, leaderboards, achievements, etc. When you aren’t associated with any of these services, there is a NULL implementation that may do some basic work, but ultimately just calls the delegates to continue the flow of the existing calls. It saves having to write custom code for when you are not associated with a platform.

The NULL implementation does have some basic LAN beacon advertisement for finding games with other players, but there is no internet wide master server for server browsing.

AGameSession is instantiated on the AGameMode and is the class meant to handle the interactions with the OnlineSubsystem as well as various other “I’m the host” kind of duties. Things like accepting login (possibly checking ban lists and server capacity), spectator permissions, voice chat push to talk requirements, starting/ending a session with the platform.

Hope that helps your understanding.

Thanks for your help! That made things more clear.

Here’s a thing I don’t understand about Sessions->StartSession though… What exactly does it do? I see it being called on both the server and the client, and the function itself is, of course, abstract and I have no idea what happens in OnlineSubsystemNull. Why is a StartSession needed on the client as well?

I have noticed this as well. There are no documentation from what I can see about calling this method on the clients. Looking at the source code it seems to be very server related things that happens. E.g. if the server should advertise through LAN or not, doesn’t sound very client related. However this is for some reason still called on the clients.

It’s a very time consuming process to setup a session if you are supposed to go through all the source code. Some documentation is needed.

I open a new question about this instead here.