Sign In Register

How can we help you today?

Start a new topic
Answered

Real-Time Matchmaking " In normal operation this mock-response may not be needed" Tutorial Question

Hello


I have got to the section of the Real Time Matchmaking tutorial titled 'Configuring the real time session.


Its the provided code, it is this comment that has thrown me off.


// In order to create a new RT game we need a 'FindMatchResponse' // // This would usually come from the server directly after a sucessful FindMatchRequest // // However, in our case, we want the game to be created only when the first player decides using a button // // therefore, the details from the response is passed in from the gameInfo and a mock-up of a FindMatchResponse // // is passed in. In normal operation this mock-response may not be needed //


Perhaps not helped that these commentsrefer to the Deprecated 'FindMatchRequest'. The tutorial uses MatchMakingRequest within a 'FindPlayers()' method instead.


I want to know what the code would look like in normal operation without having to use the mock-response. I am also confused as to what 'normal operation' might be. Is normal operation a situation where a player does not press a button to create the game? 


Thanks


Jim


Best Answer

Hi Andreas,


Sure I'll try my best to explain how it works. Basically the StartNewRtSession above is calling the GameSparks RT Singleton like it's done in the Real Time Multiplayer tutorial. This singleton contains the Configure method below.

 

Configure(response, onPlayerConnect, onPlayerDisconnected, onRtReady, onPacketReceived);

 

The response is a MatchFoundMessage

The other four parameters are callback methods, as in methods that are injected into the configure method. These will be fired at the corresponding events. 

 

So for example the onPlayerConnect parameter expects a type bool as it's own parameter so we can write a method like below.

 

private void OnPlayerConnect(bool peerId)

{

}

 

we could then begin to call the configure method like so

 

Configure(response, OnPlayerConnect, ...)

 

Hope this helps,

 - Steve


Hi Jim,


I think the tutorial is trying to demonstrate the underlying principal of overall control the developer has when it comes to setting up a Real Time Match. Thank you for bring the deprecated call to our attention. Yes you are correct, I think the reference to normal operation means receiving a MatchFoundResponse directly from the server and acting only on this information rather than waiting for the player to click a button on top of that as well.


Under normal operation the code would look similar to the following. First I try to find a match like so.

        public void TryFindMatch(

            string matchShortCode,

            Action<MatchFoundMessage> onMatchFound,

            Action<MatchNotFoundMessage> onMatchNotFound

            )

        {

            MatchFoundMessage.Listener += onMatchFound;

            MatchNotFoundMessage.Listener += onMatchNotFound;

            TryFindAMatch(matchShortCode);

        }

       

        private void TryFindAMatch(string matchShortCode)

        {

            new GameSparks.Api.Requests.MatchmakingRequest()

                .SetMatchShortCode(matchShortCode)

                .SetSkill(0)

                .Send((response) =>

                {

                    if (response.HasErrors)

                    {

                        _logService.LogError("GameSparksMatchService: " + response.Errors.JSON.ToString());

                    }

                });

        }


Then I use a method like this to start the real time session from the match found details.


        public void StartNewRtSession(

            FindMatchResponse response,

            Action<int> onPlayerConnect,

            Action<int> onPlayerDisconnected,

            Action<bool> onRtReady,

            Action<RTPacket> onPacketReceived

            )

        {

            _gameSparksRtUnity.Configure(response, onPlayerConnect, onPlayerDisconnected, onRtReady, onPacketReceived);

            _gameSparksRtUnity.Connect();

        }


Hope this helps,

 - Steve

Hi


Thanks very much for the reply. 


I'm finding this process quite confusing, in the StartNewRTSession() method, there is a 'FindMatchResponse' parameter. I do not know where I get this response from or request this data. Searching the support documentation doesn't reveal much. Is this response part of the deprecated FindMatchRequest? 


The closest I've got is a MatchFoundMessage which is the response to new the MatchmakingRequest(). 


Thanks!


Jim

I think the problem is that you can not configure the gameSparksRTUnity class with anything other than the FindMatchResponse that is sent after a deprecated FindMatchRequest().  


FindMatchResponse response = new FindMatchResponse(mockedResponse);


  gameSparksRTUnity.Configure(response,

            (peerId) => { OnPlayerConnectedToGame(peerId); },

            (peerId) => { OnPlayerDisconnected(peerId); },

            (ready) => { OnRTReady(ready); },

            (packet) => { OnPacketRecieved(packet); }

            );



However, nothing in the example you provided requests the FindMatchResponse. I tried replacing the MatchMakingRequest with the FindMatchRequest but it does not allow match making with multiple opponents.


I'd prefer to use MatchmakingRequest() and feed in the MatchmakingResponse data to configure the gameSparksRTUnity class. But to do this, as far as I'm aware, I'd currently have to fudge it by creating a mock response?


Hope this is clear!


Thanks 


Jim

Hi Jim,


I'm not sure I fully understand what you are trying to achieve, if you could outline the flow of how you see this working for you we should be able to guide you better with this issue. I don't see why you would need to use a mocked response when using a MatchMakingRequest. The basic outline of configuring a Real Time script from the example could follow this flow.


1. Player Sends a MatchMakingRequest this can happen in the background or on a button click.

2. There is a listening method setup to trigger when a MatchFoundMessage is received.

3. When a MatchFoundMessage is received we can use _gameSparksRtUnity.Configure(); which will take the MatchFoundMessage as a parameter and configure a Real Time session.


Hope this helps,

 - Steve 

I think the confusion arose because in the first example of StartNewRtSession it is shown as having a FindMatchResponse argument passed to it, where in fact it should be a MatchFoundMessage as indicated in the post above.


I got it to work like this:-

private void TryFindAMatch(string matchShortCode) 
	{ 
		new GameSparks.Api.Requests.MatchmakingRequest() 
			.SetMatchShortCode(matchShortCode) 
			.SetSkill(0) 
			.Send((response) => 
				{ 
					if (response.HasErrors) 
					{ 
						Debug.LogError("GameSparksMatchService: " + response.Errors.JSON.ToString()); 
					} 
				}); 
	}

	public void StartNewRTSession( 
		MatchFoundMessage response, 
		System.Action<int> onPlayerConnect, 
		System.Action<int> onPlayerDisconnected, 
		System.Action<bool> onRtReady, 
		System.Action<RTPacket> onPacketReceived ) 
	{ 
		gameSparksRTUnity.Configure(response, onPlayerConnect, onPlayerDisconnected, onRtReady, onPacketReceived); 
		gameSparksRTUnity.Connect(); 
	}

 

Hope this helps :)

Hi Martin,
can you explain me how to call the "StartNewRtSession" Method with all the Parameters ?
Its a lil confusing right now, because i try to call the Method with a Button and it always gets the Error
"There is no argument given that corresponds to the required formal parameter"

thx a lot
Andi

 

Answer

Hi Andreas,


Sure I'll try my best to explain how it works. Basically the StartNewRtSession above is calling the GameSparks RT Singleton like it's done in the Real Time Multiplayer tutorial. This singleton contains the Configure method below.

 

Configure(response, onPlayerConnect, onPlayerDisconnected, onRtReady, onPacketReceived);

 

The response is a MatchFoundMessage

The other four parameters are callback methods, as in methods that are injected into the configure method. These will be fired at the corresponding events. 

 

So for example the onPlayerConnect parameter expects a type bool as it's own parameter so we can write a method like below.

 

private void OnPlayerConnect(bool peerId)

{

}

 

we could then begin to call the configure method like so

 

Configure(response, OnPlayerConnect, ...)

 

Hope this helps,

 - Steve

 Hey Steve,


thanks for the explanation. It helped me a lot.


- Andi

Hey Andreas,


Happy to help, all the best.


Kind regards,

 - Steve

Login to post a comment