Last active
September 1, 2015 14:33
-
-
Save JohnTube/d4b320c67924c9563907 to your computer and use it in GitHub Desktop.
[Deprecated] Draft of PlayFab's CloudScript for Webhooks v1.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GameCreate webhook | |
handlers.RoomCreated = function(args){ | |
/** Common/shared args between all the (6) webhooks **/ | |
var appId = args.AppId, | |
appVersion = args.AppVersion, | |
region = args.Region, | |
gameId = args.GameId, | |
type = args.Type, // type could be "Load" when rejoining or "Create" | |
actorNr = args.ActorNr, | |
/** Common/shared args between all the (6) webhooks **/ | |
userId = args.UserId, | |
username = args.Username, | |
createIfNotExist = args.CreateIfNotExists, // only if type == "Load" | |
createOptions = args.CreateOptions; // see details below | |
} | |
// GameClose webhook | |
handlers.RoomClosed = function(args){ | |
/** Common/shared args between all the (6) webhooks **/ | |
var appId = args.AppId, | |
appVersion = args.AppVersion, | |
region = args.Region, | |
gameId = args.GameId, | |
type = args.Type, // type == "Save" or "Close" | |
actorNr = args.ActorNr, // always == 1 for GameClose webhook | |
/** Common/shared args between all the (6) webhooks **/ | |
actorCount = args.ActorCount, // == 0 when type == "Close", this is different from State.ActorCounter | |
state = args.State, // see details below, should be there when type == "Save" | |
state2 = args.State2; // see details below, but why ? | |
} | |
// GameLeave webhook | |
handlers.RoomLeft = function(args){ | |
/** Common/shared args between all the (6) webhooks **/ | |
var appId = args.AppId, | |
appVersion = args.AppVersion, | |
region = args.Region, | |
gameId = args.GameId, | |
type = args.Type, // type = "Leave" | |
actorNr = args.ActorNr, | |
/** Common/shared args between all the (6) webhooks **/ | |
userId = args.UserId, | |
username = args.Username, | |
isInactive = args.IsInactive, | |
reason = args.Reason; // investigate its use, can be {"0", "100", "ManagedDisconnect"} ? | |
} | |
// GameEvent webhook | |
handlers.RoomEventRaised = function(args){ | |
/** Common/shared args between all the (6) webhooks **/ | |
var appId = args.AppId, | |
appVersion = args.AppVersion, | |
region = args.Region, | |
gameId = args.GameId, | |
type = args.Type, // type == "Event" | |
actorNr = args.ActorNr, | |
/** Common/shared args between all the (6) webhooks **/ | |
userId = args.UserId, | |
username = args.Username, | |
state = args.State, | |
eventData = args.Data; | |
} | |
// GameJoin webhook | |
handlers.RoomJoined = function(args){ | |
/** Common/shared args between all the (6) webhooks **/ | |
var appId = args.AppId, | |
appVersion = args.AppVersion, | |
region = args.Region, | |
gameId = args.GameId, | |
type = args.Type, // type == "Join" | |
actorNr = args.ActorNr, | |
/** Common/shared args between all the (6) webhooks **/ | |
userId = args.UserId, | |
username = args.Username; | |
} | |
// GameProperty webhook | |
// fired when Room or Player properties are updated | |
// (changed, removed or added) and "web forwareded" when joined to a Room ! | |
handlers.RoomPropertyUpdated = function(args){ | |
/** Common/shared args between all the (6) webhooks **/ | |
var appId = args.AppId, | |
appVersion = args.AppVersion, | |
region = args.Region, | |
gameId = args.GameId, | |
type = args.Type, // type == "Properties" | |
actorNr = args.ActorNr, | |
/** Common/shared args between all the (6) webhooks **/ | |
state = args.State, | |
properties = args.Properties; // {<key:value>} of changed/updated or newly added room properties | |
} | |
/** Utilities **/ | |
function PhotonFail(errorCode, webhookName, errorMessage){ | |
var fullMessage = "webhook " + webhookName + " error: " + errorMessage + " (" + errorCode + ")"; | |
var res = {ResultCode:errorCode, Message:fullMessage}; | |
return res; | |
} | |
function PhotonSuccess(){ | |
var res = {ResultCode:0, Message:""}; | |
return res; | |
} | |
function GetUtcTimestamp(){ | |
var now = Date.now(); | |
var timestamp = new Date(now).toUTCString(); | |
return timestamp; | |
} | |
// Temporary workaround until the Logs tab is available from the GameManager. | |
function LogWebhook(webhookName, webhookArgs){ | |
// Logs can be retrieved from GameManager/Properties/TitleData | |
server.SetTitleData({ | |
Key:GetUtcTimestamp(), | |
Value:webhookName+" "+JSON.stringify(webhookArgs) | |
}); | |
} | |
"CreateOptions":{ | |
"MaxPlayers":int, | |
"LobbyId":string, | |
"LobbyType":int, | |
"CustomProperties":{}, // {key:value} of custom properties THAT ARE VISIBLE TO THE LOBBY ! | |
"EmptyRoomTTL":int, | |
"PlayerTTL":int, | |
"CheckUserOnJoin":bool, // must be true for photon turnbased | |
"DeleteCacheOnLeave":bool, | |
"SuppressRoomEvents":bool | |
} | |
"State": { | |
"ActorCounter": int, // confusion, link = http://forum.exitgames.com/viewtopic.php?f=25&t=5789 | |
"ActorList": [ | |
{ | |
"ActorNr": int, | |
"UserId": string, // PlayFab Id | |
"Username": string, // should be PlayFab Username or DisplayName | |
"Binary": "", // binary blob as base64 ? | |
"DEBUG_BINARY": { // how to disable this ? | |
"1": { // 1 == ALL PlayerProperties : default (username) + custom | |
"255": "" // 255 = "Username" | |
[<key:value> of custom player properties] | |
} | |
} | |
} | |
[...] | |
], | |
"CheckUserOnJoin": bool, | |
"DeleteCacheOnLeave": bool, // vs. SuppressRoomEvents, link http://forum.exitgames.com/viewtopic.php?f=25&t=5714#p21881 | |
"CustomProperties": {}, // {key:value} of custom properties THAT ARE VISIBLE TO THE LOBBY ! | |
"EmptyRoomTTL": bool, | |
"IsOpen": bool, | |
"IsVisible": bool, | |
"LobbyId": string, | |
"LobbyType": int, | |
"LobbyProperties": [ | |
[string] | |
], | |
"MaxPlayers": int, | |
"PlayerTTL": int, | |
"SuppressRoomEvents": bool, | |
"Slice": int, | |
"Binary": { | |
"18": "" // 18 = ALL RoomProperties : binary blob as base64 ? | |
}, | |
"DEBUG_PROPERTIES_18": { // how to disable this ? | |
"250": [], // 250 = "LobbyProperties" = [subset keys (string) of custom properties that should be visible to the lobby] | |
"253": bool,// 253 = "IsOpen" | |
"254": bool,// 254 = "IsVisible" | |
"255": int// 255 = "MaxPlayers" | |
[<Key:Value> of custom properties] | |
}, | |
"DEBUG_EVENTS_19":{ | |
<customEventCode:string> : [ | |
[ | |
<actorNr:int>, // actorNr that raised this event | |
<customEventCode:int>, | |
{<key:value>} // event data | |
] | |
] | |
} | |
} | |
"State2":{ // deprecated/obsolete | |
"ActorList":[ | |
{ | |
"ActorNr":int, | |
"UserId":string | |
} | |
[...] | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Common to all Webhook
AppVersion
: as set by game clientRegion
: region connected by game clientGameId
: sometimes also called RoomId - identifies the game instance.Type
: currently only useful inGameCreate
andGameClose
, in all other Webhooks it is sent but there is only one value per Webhook.Common to all EXCEPT: GameClose
ActorNr
: actor triggering the webhook. Note: OBSOLTE forGameClose
currently always 1.UserId
: userId of actor triggering the webhook.Username
: Username (called Playername in client SDK's) of actor triggering the webhook. Note: this will be renamed to Nickname and step by step all sdk's will follow the renaming.Reason: GameClose is Actor/User agnostic - if interested which actor left last use the
GameLeave
Webhook.GameCreate Webhook
Type
:Create
: try create room if room already exists should return error.Load
: should return a state. If none found should return an error unless CreateIfNotExists = true. In which case the webhook should create the room and return OK without a State. Rejoin and Join can trigger a Load. Rejoin always withCreateIfNotExists=false
. For Join the default isCreateIfNotExists = false
, but can be set in the client.CreateIfNotExists
:CreateIfNotExists
is set to true in the client. see Type = "Load" above.GameClose Webhook
ActorCount
:State.ActorCounter
which is used for the next actor number!Type
:Save
: game should be saved (ActorCount > 0
) =>State
is available.Close
: game should be removed or flagged as deleted (ActorCount = 0
)State
: serialized game state, which should be saved and sent back in theCreateGame Type="Load"
webhook.GameJoin Webhook
No special args.
GameLeave webhook
IsInactive
: if true Actor can rejoin game. If false player left for good - was removed from ActorList and can't rejoin the game.Reason
: IGNORE FOR NOW currently values are wrong - will be fixed with next release. And we'll update the infos.GameEvent Webhook
Data
: event dataState
: serialized game state Note: in next version sending of state will be optional - per flag in client.SetProperties Webhook
Properties
: {key:value} of changed/updated room propertiesState
: serialized game state Note: in next version sending of state will be optional - per flag in client.