// ---------------------------------------------------------------------------- // // Loadbalancing Framework for Photon - Copyright (C) 2016 Exit Games GmbH // // // This class wraps responses of a Photon WebRPC call, coming from a // third party web service. // // developer@photonengine.com // ---------------------------------------------------------------------------- #if UNITY_4_7_OR_NEWER #define UNITY #endif namespace ExitGames.Client.Photon.LoadBalancing { using ExitGames.Client.Photon; using System.Collections.Generic; #if UNITY || NETFX_CORE using Hashtable = ExitGames.Client.Photon.Hashtable; using SupportClass = ExitGames.Client.Photon.SupportClass; #endif /// Reads an operation response of a WebRpc and provides convenient access to most common values. /// /// See method PhotonNetwork.WebRpc.
/// Create a WebRpcResponse to access common result values.
/// The operationResponse.OperationCode should be: OperationCode.WebRpc.
///
public class WebRpcResponse { /// Name of the WebRpc that was called. public string Name { get; private set; } /// ReturnCode of the WebService that answered the WebRpc. /// /// 1 is: "OK" for WebRPCs.
/// -1 is: No ReturnCode by WebRpc service (check OperationResponse.ReturnCode).
/// Other ReturnCodes are defined by the individual WebRpc and service. ///
public int ReturnCode { get; private set; } /// Might be empty or null. public string DebugMessage { get; private set; } /// Other key/values returned by the webservice that answered the WebRpc. public Dictionary Parameters { get; private set; } /// An OperationResponse for a WebRpc is needed to read it's values. public WebRpcResponse(OperationResponse response) { object value; response.Parameters.TryGetValue(ParameterCode.UriPath, out value); this.Name = value as string; response.Parameters.TryGetValue(ParameterCode.WebRpcReturnCode, out value); this.ReturnCode = (value != null) ? (byte)value : -1; response.Parameters.TryGetValue(ParameterCode.WebRpcParameters, out value); this.Parameters = value as Dictionary; response.Parameters.TryGetValue(ParameterCode.WebRpcReturnMessage, out value); this.DebugMessage = value as string; } /// Turns the response into an easier to read string. /// String resembling the result. public string ToStringFull() { return string.Format("{0}={2}: {1} \"{3}\"", this.Name, SupportClass.DictionaryToString(this.Parameters), this.ReturnCode, this.DebugMessage); } } /// /// Optional flags to be used in Photon client SDKs with Op RaiseEvent and Op SetProperties. /// Introduced mainly for webhooks 1.2 to control behavior of forwarded HTTP requests. /// public class WebFlags { public readonly static WebFlags Default = new WebFlags(0); public byte WebhookFlags; /// /// Indicates whether to forward HTTP request to web service or not. /// public bool HttpForward { get { return (WebhookFlags & HttpForwardConst) != 0; } set { if (value) { WebhookFlags |= HttpForwardConst; } else { WebhookFlags = (byte) (WebhookFlags & ~(1 << 0)); } } } public const byte HttpForwardConst = 0x01; /// /// Indicates whether to send AuthCookie of actor in the HTTP request to web service or not. /// public bool SendAuthCookie { get { return (WebhookFlags & SendAuthCookieConst) != 0; } set { if (value) { WebhookFlags |= SendAuthCookieConst; } else { WebhookFlags = (byte)(WebhookFlags & ~(1 << 1)); } } } public const byte SendAuthCookieConst = 0x02; /// /// Indicates whether to send HTTP request synchronously or asynchronously to web service. /// public bool SendSync { get { return (WebhookFlags & SendSyncConst) != 0; } set { if (value) { WebhookFlags |= SendSyncConst; } else { WebhookFlags = (byte)(WebhookFlags & ~(1 << 2)); } } } public const byte SendSyncConst = 0x04; /// /// Indicates whether to send serialized game state in HTTP request to web service or not. /// public bool SendState { get { return (WebhookFlags & SendStateConst) != 0; } set { if (value) { WebhookFlags |= SendStateConst; } else { WebhookFlags = (byte)(WebhookFlags & ~(1 << 3)); } } } public const byte SendStateConst = 0x08; public WebFlags(byte webhookFlags) { WebhookFlags = webhookFlags; } } }