Upload
thomas-robbins
View
650
Download
1
Embed Size (px)
Citation preview
a Platform-as-a-Service company
Getting Started with Cloud Script
Brendan Vanous Senior Developer Success Engineer
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
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
Revision Control
• Two revisions are active
• Test == latest
• Live == deployed
• Deploy any revision
• Note: Live immediately
• Versions
September 10, 2015 5
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
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
}
}
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
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
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
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
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
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
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
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
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