Top Banner
a Platform-as-a-Service company Getting Started with Cloud Script Brendan Vanous Senior Developer Success Engineer
18

Getting started with Cloud Script

Jan 22, 2018

Download

Technology

Thomas Robbins
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Getting started with Cloud Script

a Platform-as-a-Service company

Getting Started with Cloud Script

Brendan Vanous Senior Developer Success Engineer

Page 2: Getting started with Cloud Script

Overview

• Cloud Script Fundamentals

• Adding a Cloud Script

• Revision Control

• Calling a Cloud Script

• Photon Webhooks

• Debugging

• Usage Scenarios

• Limitations

• Resources

September 10, 2015 1

Page 3: Getting started with Cloud Script

Cloud Script Fundamentals

• JavaScript handlers

• Executes in the context of the user,

but with server authority

• Can call external endpoints

• Excellent tool for:

• Game updates

• Push notifications

• Cheat prevention

• Player coordination

• Cross-service coordination

September 10, 2015 2

Page 4: Getting started with Cloud Script

Adding a Cloud Script

September 10, 2015 3

Page 5: Getting started with Cloud Script

Adding a Cloud Script

September 10, 2015 4

Page 6: Getting started with Cloud Script

Revision Control

• Two revisions are active

• Test == latest

• Live == deployed

• Deploy any revision

• Note: Live immediately

• Versions

September 10, 2015 5

Page 7: Getting started with Cloud Script

Calling a Cloud Script

• Query for the active Cloud Script URLPOST /client/GetCloudScriptUrl HTTP/1.1

Host: {{TitleID}}.playfabapi.com

Content-Type: application/json

X-Authentication:{{SessionTicket}}

{

"Testing": true

}

• Response{

"code": 200,

"status": "OK",

"data": {

"Url": "https://{{TitleID}}.playfablogic.com/1/test"

}

}

September 10, 2015 6

Page 8: Getting started with Cloud Script

Calling a Cloud Script

• Launch the Cloud ScriptPOST /1/prod/client/RunCloudScript HTTP/1.1

Host: {{TitleID}}.playfablogic.com

Content-Type: application/json

X-Authentication: {{SessionTicket}}

{

"ActionId": "onLevelComplete“,

"ParamsEncoded": "{\"level\":1}"

}

• Response• Standard response code

• Handler, version, revision

• Custom response data

• Log (for debugging)

• Runtime

September 10, 2015 7

{

"code": 200,

"status": "OK",

"data": {

"ActionId": "onLevelComplete",

"Version": 1,

"Revision": 43,

"Results": {

"rewards": [

{

"PlayFabId": "14141CB68CBE4956",

"Result": false,

"ItemId": "TestItem2",

"Annotation": "Given by completing level 1",

"UnitPrice": 0

}

]

},

"ResultsEncoded":

"{\"rewards\":[{\"PlayFabId\":\"14141CB68CBE4956\",\"Result\":false,\"ItemId\":\"TestItem2\",\"Annotati

on\":\"Given by completing level 1\",\"UnitPrice\":0}]}",

"ActionLog": "",

"ExecutionTime": 0.1680013

}

}

Page 9: Getting started with Cloud Script

Photon Webhooks

• Partnership with Exit Games

• Photon Cloud free with Premium tier

• Integrated authentication

• Integrated Webhooks

• So what are Webhooks?

• Calls from Photon Cloud to PlayFab on Room actions

• RoomCreated

• RoomJoined

• RoomEventRaised

• RoomPropertyUpdated

• RoomLeft

• RoomClosed

September 10, 2015 8

Page 10: Getting started with Cloud Script

Debugging

• Basic debugging via logging

• http://cloudscript.playfab.com/classes/log.html

• debug

• error

• info

• Returned with results from script

• ActionLog

• Debugger in planning

• Let us know what you need!

September 10, 2015 9

Page 11: Getting started with Cloud Script

Scenario 1: Updates

September 10, 2015 10

• Updating a title is more than just the executable

• Changing items

• User data

• Save values

• User Internal Data to track player version

• Have an “onLogin” handler

• Calls current version handler (“updateToRevN”), passing in player version

• If not at this version, call previous version handler

• Once returned, update for latest version

• onLogin then sets player version

Page 12: Getting started with Cloud Script

Scenario 2: Player Actions

September 10, 2015 11

• For competitive games

• Resolution of player action must be server authoritative

• Player selects moves, which are sent to Cloud Script

• Evaluate moves

• Are they possible?

• Does the player have the right items?

• etc.

• On failure, write info to User Internal Data

• Use cheat tracking to have cheaters play together

Page 13: Getting started with Cloud Script

Scenario 3: Rewards

September 10, 2015 12

• Determination of rewards for player actions

• Player actions are sent to Cloud Script

• Evaluate actions

• Has enough time passed?

• Are the values reasonable?

• etc.

• On failure, write info to User Internal Data

• Use cheat tracking to decide how to manage them

Page 14: Getting started with Cloud Script

Scenario 4: Messaging

September 10, 2015 13

• Push Messages

• Require Server authority

• Player attacking another player’s base

• Player beat a friend’s score

• etc.

• Player-to-player messages

• Write them to Shared Group Data, using ID of PlayFabId

• Arbitrary messages, with arbitrary payloads

Page 15: Getting started with Cloud Script

Scenario 5: Extra Leaderboard Columns

September 10, 2015 14

• Shared Group Data

• Storage not tied to a particular player

• Readable by any player (permission set Public)

• Data value per player

• Key is the PlayFab ID of the player

• Write extra data when updating score

• One API call to read players in display

Page 16: Getting started with Cloud Script

Limitations

• An API call is an API call

• Total API calls

• Apply portion control to your data

• Total data returned

• How complex is too complex?

• Total compute time

September 10, 2015 15

Page 17: Getting started with Cloud Script

Resources

• PlayFab Cloud Script Tutorial

• https://playfab.com/?post_type=pf_docs&p=1003

• GitHub

• https://github.com/PlayFab/CloudScriptSamples

• Dave & Buster’s usage

• https://playfab.com/blog/dave-busters-goes-mobile-with-playfabs-help/

September 10, 2015 16

Page 18: Getting started with Cloud Script

QUESTIONS?Twitter @playfabnetwork