// ---------------------------------------------------------------------------- // // Loadbalancing Framework for Photon - Copyright (C) 2018 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 || UNITY_5 || UNITY_5_3_OR_NEWER #define SUPPORTED_UNITY #endif namespace Photon.Realtime { using System.Collections.Generic; using ExitGames.Client.Photon; #if SUPPORTED_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 LoadBalancingClient.OpWebRpc.
/// 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; } /// ResultCode of the WebService that answered the WebRpc. /// /// 0 is: "OK" for WebRPCs.
/// -1 is: No ResultCode by WebRpc service (check ).
/// Other ResultCode are defined by the individual WebRpc and service. ///
public int ResultCode { get; private set; } [System.Obsolete("Use ResultCode instead")] public int ReturnCode { get { return ResultCode; } } /// Might be empty or null. public string Message { get; private set; } [System.Obsolete("Use Message instead")] public string DebugMessage { get { return Message; } } /// 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; if (response.Parameters.TryGetValue(ParameterCode.UriPath, out value)) { this.Name = value as string; } this.ResultCode = -1; if (response.Parameters.TryGetValue(ParameterCode.WebRpcReturnCode, out value)) { this.ResultCode = (byte)value; } if (response.Parameters.TryGetValue(ParameterCode.WebRpcParameters, out value)) { this.Parameters = value as Dictionary; } if (response.Parameters.TryGetValue(ParameterCode.WebRpcReturnMessage, out value)) { this.Message = 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.ResultCode, this.Message); } } /// /// 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; } } }