Skip to content

Instantly share code, notes, and snippets.

@JohnTube
Last active September 1, 2015 14:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnTube/d4b320c67924c9563907 to your computer and use it in GitHub Desktop.
Save JohnTube/d4b320c67924c9563907 to your computer and use it in GitHub Desktop.
[Deprecated] Draft of PlayFab's CloudScript for Webhooks v1.0
// 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
}
[...]
]
}
@archgl
Copy link

archgl commented Apr 10, 2015

Common to all Webhook

  1. AppVersion: as set by game client
  2. Region: region connected by game client
  3. GameId: sometimes also called RoomId - identifies the game instance.
  4. Type: currently only useful in GameCreate and GameClose, in all other Webhooks it is sent but there is only one value per Webhook.

Common to all EXCEPT: GameClose

  1. ActorNr: actor triggering the webhook. Note: OBSOLTE for GameClose currently always 1.
  2. UserId: userId of actor triggering the webhook.
  3. 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

  1. 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 with CreateIfNotExists=false. For Join the default is CreateIfNotExists = false, but can be set in the client.
  2. CreateIfNotExists:
    • rooms can be created through joins when CreateIfNotExists is set to true in the client. see Type = "Load" above.

GameClose Webhook

  1. ActorCount:
    • number of actors in room
    • is different from State.ActorCounter which is used for the next actor number!
  2. Type:
    • Save: game should be saved (ActorCount > 0) => State is available.
    • Close: game should be removed or flagged as deleted (ActorCount = 0)
  3. State: serialized game state, which should be saved and sent back in the CreateGame Type="Load" webhook.
    • sent when Type = "Save"
    • NOT sent when Type="Close"
  4. State2: OBSOLET instead use ActorList in State. Note:: first iterations of state where completely binary, so this was provided as a readable information.

GameJoin Webhook

No special args.

GameLeave webhook

  1. IsInactive: if true Actor can rejoin game. If false player left for good - was removed from ActorList and can't rejoin the game.
  2. Reason: IGNORE FOR NOW currently values are wrong - will be fixed with next release. And we'll update the infos.

GameEvent Webhook

  1. Data: event data
  2. State: serialized game state Note: in next version sending of state will be optional - per flag in client.

SetProperties Webhook

  1. Properties: {key:value} of changed/updated room properties
  2. State: serialized game state Note: in next version sending of state will be optional - per flag in client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment