GameSparks

4 min. read

Website:
https://www.gamesparks.com/

Docs:
https://docs.gamesparks.com/

Tutorials:
https://docs.gamesparks.com/tutorials/

Video Tutorials

80lv (3 videos)
https://www.youtube.com/watch?v=Vbx-pyTVdhI
https://www.youtube.com/watch?v=AikKTf722yc
https://www.youtube.com/watch?v=00GYRTXGG8g

https://www.youtube.com/watch?v=fwDOUWvu4AI

https://vimeo.com/80602164

Tic-Tac-Toe video:
https://www.youtube.com/watch?v=7QNSRHfBkvU

Tic-Tac-Toe series:
https://www.youtube.com/playlist?list=PLh5wixGXKP8wfZI0szQoQY9Bd_r0iYoGt

Challenges
Create a challenge in the Portal

Facebook
FB.LogInWithReadPermissions(new List() { “public_profile”, “email”, “user_friends” }, cb);

{“matchShortCode”:”NOT_FOUND”}
Must set a Threshold on a match

AuthWith Facebook in Harness
“accessToken”: “”,
“doNotLinkToCurrentPlayer”: true,
“errorOnSwitch”: false

Matchmaking

If a user goes offline, the pendingMatch is deleted
Set drop in/out, with timer values to avoid a match being deleted.

Player 1: matchmakingRequest
Player 2: matchmakingRequest
Server: UserMessage->MatchFoundMessage
Server: UserMessage->ChallengeIssuedMessage
Server: UserMessage->ChallengeStartedMessage

To get the nextPlayer, use: Spark.getData().challenge.nextPlayer

New User
RegistrationReponse

Realtime
A match should be setup as Real-time.
Request a Match (MatchmakingRequest)
Once a match has been found, MatchFoundMessage will be sent to the client, containing:
Port number
Access Token
Host Server
Once the RT session has been configured, you need to start the session
The SDK has 4 events
OnReady is triggered when the client is connected to the session.
OnData is triggered when a new packet is received.
OnPlayerConnect and OnPlayerDisconnect are triggered when players join or leave the session.
And these functions:
Start and Stop functions establish or end the connection to the real-time session.
GetActivePeers returns an array of ints corresponding to the active peers sharing the session.
Send allows the client to send packets of data to the server or other peers. These packets will be intercepted using OnData Event.
Clients can
Active clients in the Real-Time session can send packets to any one of their peers.
Clients can also send the packets directly to the server for it to be processed through Cloud Code.
Packet Data:
OpCode - Mandatory. Helps distinguish the packet.
Intent - Mandatory. The Intent options we offer are:
Reliable - Makes sure that packets sent are received.
Unreliable - Doesn’t ensure packets are received but can discard packets if the bandwidth cannot support them (ideal for cosmetic purposes).
Unreliable_Sequenced - Similar to Unreliable but packets will be discarded if not received in the correct sequence.
Data - Optional. Sometimes it’s enough to send a packet without data to act as a trigger. The data in packets can be a string, int, vector, float, and nested data. Each piece of data is saved in an index that you must set.
Peers - Mandatory. An int array of which peers to send to. Peer ID 0 is the peer address of the server. The other peers are those sharing the session with the client.

Uses RealtimeSession
https://docs.gamesparks.com/api-documentation/realtime-api/rtsession.html

CloudCode
Send Push to All Players

//get all the players
var allPlayers = Spark.systemCollection(“player”).find({}).toArray();

//array with all the player ids
var playerIds = []

//the the jackpot config
var jackpotConfig = Spark.getProperties().getProperty(“JACKPOT_CONFIG”);

//loop through all the players
for(var i = 0; i < allPlayers.length; i++){

//get the player id
var playerId = allPlayers[i]._id.$oid;

//add the id to the array
playerIds.push(playerId);

}

//TODO: The message title is not correct on iOS.

var payload = {“badge”:1,”summary”:”Jackpot Ready”, “message”:”New daily Jackpot Is Ready”, “alert”:”Jackpot Ready”};

var message = Spark.message(“DailyJackpotMessage”);
message.setSendAsPush(true);
message.setSendViaSocket(false);
message.setMessageData(payload);
message.setPlayerIds(playerIds);
message.send();