Seven is the number.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
6.3 KiB

4 years ago
  1. // ----------------------------------------------------------------------------
  2. // <copyright file="WebRpc.cs" company="Exit Games GmbH">
  3. // Loadbalancing Framework for Photon - Copyright (C) 2018 Exit Games GmbH
  4. // </copyright>
  5. // <summary>
  6. // This class wraps responses of a Photon WebRPC call, coming from a
  7. // third party web service.
  8. // </summary>
  9. // <author>developer@photonengine.com</author>
  10. // ----------------------------------------------------------------------------
  11. #if UNITY_4_7 || UNITY_5 || UNITY_5_3_OR_NEWER
  12. #define SUPPORTED_UNITY
  13. #endif
  14. namespace Photon.Realtime
  15. {
  16. using System.Collections.Generic;
  17. using ExitGames.Client.Photon;
  18. #if SUPPORTED_UNITY || NETFX_CORE
  19. using Hashtable = ExitGames.Client.Photon.Hashtable;
  20. using SupportClass = ExitGames.Client.Photon.SupportClass;
  21. #endif
  22. /// <summary>Reads an operation response of a WebRpc and provides convenient access to most common values.</summary>
  23. /// <remarks>
  24. /// See LoadBalancingClient.OpWebRpc.<br/>
  25. /// Create a WebRpcResponse to access common result values.<br/>
  26. /// The operationResponse.OperationCode should be: OperationCode.WebRpc.<br/>
  27. /// </remarks>
  28. public class WebRpcResponse
  29. {
  30. /// <summary>Name of the WebRpc that was called.</summary>
  31. public string Name { get; private set; }
  32. /// <summary>ResultCode of the WebService that answered the WebRpc.</summary>
  33. /// <remarks>
  34. /// 0 is: "OK" for WebRPCs.<br/>
  35. /// -1 is: No ResultCode by WebRpc service (check <see cref="OperationResponse.ReturnCode"/>).<br/>
  36. /// Other ResultCode are defined by the individual WebRpc and service.
  37. /// </remarks>
  38. public int ResultCode { get; private set; }
  39. [System.Obsolete("Use ResultCode instead")]
  40. public int ReturnCode
  41. {
  42. get { return ResultCode; }
  43. }
  44. /// <summary>Might be empty or null.</summary>
  45. public string Message { get; private set; }
  46. [System.Obsolete("Use Message instead")]
  47. public string DebugMessage
  48. {
  49. get { return Message; }
  50. }
  51. /// <summary>Other key/values returned by the webservice that answered the WebRpc.</summary>
  52. public Dictionary<string, object> Parameters { get; private set; }
  53. /// <summary>An OperationResponse for a WebRpc is needed to read it's values.</summary>
  54. public WebRpcResponse(OperationResponse response)
  55. {
  56. object value;
  57. if (response.Parameters.TryGetValue(ParameterCode.UriPath, out value))
  58. {
  59. this.Name = value as string;
  60. }
  61. this.ResultCode = -1;
  62. if (response.Parameters.TryGetValue(ParameterCode.WebRpcReturnCode, out value))
  63. {
  64. this.ResultCode = (byte)value;
  65. }
  66. if (response.Parameters.TryGetValue(ParameterCode.WebRpcParameters, out value))
  67. {
  68. this.Parameters = value as Dictionary<string, object>;
  69. }
  70. if (response.Parameters.TryGetValue(ParameterCode.WebRpcReturnMessage, out value))
  71. {
  72. this.Message = value as string;
  73. }
  74. }
  75. /// <summary>Turns the response into an easier to read string.</summary>
  76. /// <returns>String resembling the result.</returns>
  77. public string ToStringFull()
  78. {
  79. return string.Format("{0}={2}: {1} \"{3}\"", this.Name, SupportClass.DictionaryToString(this.Parameters), this.ResultCode, this.Message);
  80. }
  81. }
  82. /// <summary>
  83. /// Optional flags to be used in Photon client SDKs with Op RaiseEvent and Op SetProperties.
  84. /// Introduced mainly for webhooks 1.2 to control behavior of forwarded HTTP requests.
  85. /// </summary>
  86. public class WebFlags
  87. {
  88. public readonly static WebFlags Default = new WebFlags(0);
  89. public byte WebhookFlags;
  90. /// <summary>
  91. /// Indicates whether to forward HTTP request to web service or not.
  92. /// </summary>
  93. public bool HttpForward
  94. {
  95. get { return (WebhookFlags & HttpForwardConst) != 0; }
  96. set {
  97. if (value)
  98. {
  99. WebhookFlags |= HttpForwardConst;
  100. }
  101. else
  102. {
  103. WebhookFlags = (byte) (WebhookFlags & ~(1 << 0));
  104. }
  105. }
  106. }
  107. public const byte HttpForwardConst = 0x01;
  108. /// <summary>
  109. /// Indicates whether to send AuthCookie of actor in the HTTP request to web service or not.
  110. /// </summary>
  111. public bool SendAuthCookie
  112. {
  113. get { return (WebhookFlags & SendAuthCookieConst) != 0; }
  114. set {
  115. if (value)
  116. {
  117. WebhookFlags |= SendAuthCookieConst;
  118. }
  119. else
  120. {
  121. WebhookFlags = (byte)(WebhookFlags & ~(1 << 1));
  122. }
  123. }
  124. }
  125. public const byte SendAuthCookieConst = 0x02;
  126. /// <summary>
  127. /// Indicates whether to send HTTP request synchronously or asynchronously to web service.
  128. /// </summary>
  129. public bool SendSync
  130. {
  131. get { return (WebhookFlags & SendSyncConst) != 0; }
  132. set {
  133. if (value)
  134. {
  135. WebhookFlags |= SendSyncConst;
  136. }
  137. else
  138. {
  139. WebhookFlags = (byte)(WebhookFlags & ~(1 << 2));
  140. }
  141. }
  142. }
  143. public const byte SendSyncConst = 0x04;
  144. /// <summary>
  145. /// Indicates whether to send serialized game state in HTTP request to web service or not.
  146. /// </summary>
  147. public bool SendState
  148. {
  149. get { return (WebhookFlags & SendStateConst) != 0; }
  150. set {
  151. if (value)
  152. {
  153. WebhookFlags |= SendStateConst;
  154. }
  155. else
  156. {
  157. WebhookFlags = (byte)(WebhookFlags & ~(1 << 3));
  158. }
  159. }
  160. }
  161. public const byte SendStateConst = 0x08;
  162. public WebFlags(byte webhookFlags)
  163. {
  164. WebhookFlags = webhookFlags;
  165. }
  166. }
  167. }