isteamgameserverhttp.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. // This file is provided under The MIT License as part of Steamworks.NET.
  2. // Copyright (c) 2013-2019 Riley Labrecque
  3. // Please see the included LICENSE.txt for additional information.
  4. // This file is automatically generated.
  5. // Changes to this file will be reverted when you update Steamworks.NET
  6. #if UNITY_ANDROID || UNITY_IOS || UNITY_TIZEN || UNITY_TVOS || UNITY_WEBGL || UNITY_WSA || UNITY_PS4 || UNITY_WII || UNITY_XBOXONE || UNITY_SWITCH
  7. #define DISABLESTEAMWORKS
  8. #endif
  9. #if !DISABLESTEAMWORKS
  10. using System.Runtime.InteropServices;
  11. using IntPtr = System.IntPtr;
  12. namespace Steamworks {
  13. public static class SteamGameServerHTTP {
  14. /// <summary>
  15. /// <para> Initializes a new HTTP request, returning a handle to use in further operations on it. Requires</para>
  16. /// <para> the method (GET or POST) and the absolute URL for the request. Both http and https are supported,</para>
  17. /// <para> so this string must start with http:// or https:// and should look like http://store.steampowered.com/app/250/</para>
  18. /// <para> or such.</para>
  19. /// </summary>
  20. public static HTTPRequestHandle CreateHTTPRequest(EHTTPMethod eHTTPRequestMethod, string pchAbsoluteURL) {
  21. InteropHelp.TestIfAvailableGameServer();
  22. using (var pchAbsoluteURL2 = new InteropHelp.UTF8StringHandle(pchAbsoluteURL)) {
  23. return (HTTPRequestHandle)NativeMethods.ISteamHTTP_CreateHTTPRequest(CSteamGameServerAPIContext.GetSteamHTTP(), eHTTPRequestMethod, pchAbsoluteURL2);
  24. }
  25. }
  26. /// <summary>
  27. /// <para> Set a context value for the request, which will be returned in the HTTPRequestCompleted_t callback after</para>
  28. /// <para> sending the request. This is just so the caller can easily keep track of which callbacks go with which request data.</para>
  29. /// </summary>
  30. public static bool SetHTTPRequestContextValue(HTTPRequestHandle hRequest, ulong ulContextValue) {
  31. InteropHelp.TestIfAvailableGameServer();
  32. return NativeMethods.ISteamHTTP_SetHTTPRequestContextValue(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, ulContextValue);
  33. }
  34. /// <summary>
  35. /// <para> Set a timeout in seconds for the HTTP request, must be called prior to sending the request. Default</para>
  36. /// <para> timeout is 60 seconds if you don't call this. Returns false if the handle is invalid, or the request</para>
  37. /// <para> has already been sent.</para>
  38. /// </summary>
  39. public static bool SetHTTPRequestNetworkActivityTimeout(HTTPRequestHandle hRequest, uint unTimeoutSeconds) {
  40. InteropHelp.TestIfAvailableGameServer();
  41. return NativeMethods.ISteamHTTP_SetHTTPRequestNetworkActivityTimeout(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, unTimeoutSeconds);
  42. }
  43. /// <summary>
  44. /// <para> Set a request header value for the request, must be called prior to sending the request. Will</para>
  45. /// <para> return false if the handle is invalid or the request is already sent.</para>
  46. /// </summary>
  47. public static bool SetHTTPRequestHeaderValue(HTTPRequestHandle hRequest, string pchHeaderName, string pchHeaderValue) {
  48. InteropHelp.TestIfAvailableGameServer();
  49. using (var pchHeaderName2 = new InteropHelp.UTF8StringHandle(pchHeaderName))
  50. using (var pchHeaderValue2 = new InteropHelp.UTF8StringHandle(pchHeaderValue)) {
  51. return NativeMethods.ISteamHTTP_SetHTTPRequestHeaderValue(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, pchHeaderName2, pchHeaderValue2);
  52. }
  53. }
  54. /// <summary>
  55. /// <para> Set a GET or POST parameter value on the request, which is set will depend on the EHTTPMethod specified</para>
  56. /// <para> when creating the request. Must be called prior to sending the request. Will return false if the</para>
  57. /// <para> handle is invalid or the request is already sent.</para>
  58. /// </summary>
  59. public static bool SetHTTPRequestGetOrPostParameter(HTTPRequestHandle hRequest, string pchParamName, string pchParamValue) {
  60. InteropHelp.TestIfAvailableGameServer();
  61. using (var pchParamName2 = new InteropHelp.UTF8StringHandle(pchParamName))
  62. using (var pchParamValue2 = new InteropHelp.UTF8StringHandle(pchParamValue)) {
  63. return NativeMethods.ISteamHTTP_SetHTTPRequestGetOrPostParameter(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, pchParamName2, pchParamValue2);
  64. }
  65. }
  66. /// <summary>
  67. /// <para> Sends the HTTP request, will return false on a bad handle, otherwise use SteamCallHandle to wait on</para>
  68. /// <para> asynchronous response via callback.</para>
  69. /// <para> Note: If the user is in offline mode in Steam, then this will add a only-if-cached cache-control</para>
  70. /// <para> header and only do a local cache lookup rather than sending any actual remote request.</para>
  71. /// </summary>
  72. public static bool SendHTTPRequest(HTTPRequestHandle hRequest, out SteamAPICall_t pCallHandle) {
  73. InteropHelp.TestIfAvailableGameServer();
  74. return NativeMethods.ISteamHTTP_SendHTTPRequest(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, out pCallHandle);
  75. }
  76. /// <summary>
  77. /// <para> Sends the HTTP request, will return false on a bad handle, otherwise use SteamCallHandle to wait on</para>
  78. /// <para> asynchronous response via callback for completion, and listen for HTTPRequestHeadersReceived_t and</para>
  79. /// <para> HTTPRequestDataReceived_t callbacks while streaming.</para>
  80. /// </summary>
  81. public static bool SendHTTPRequestAndStreamResponse(HTTPRequestHandle hRequest, out SteamAPICall_t pCallHandle) {
  82. InteropHelp.TestIfAvailableGameServer();
  83. return NativeMethods.ISteamHTTP_SendHTTPRequestAndStreamResponse(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, out pCallHandle);
  84. }
  85. /// <summary>
  86. /// <para> Defers a request you have sent, the actual HTTP client code may have many requests queued, and this will move</para>
  87. /// <para> the specified request to the tail of the queue. Returns false on invalid handle, or if the request is not yet sent.</para>
  88. /// </summary>
  89. public static bool DeferHTTPRequest(HTTPRequestHandle hRequest) {
  90. InteropHelp.TestIfAvailableGameServer();
  91. return NativeMethods.ISteamHTTP_DeferHTTPRequest(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest);
  92. }
  93. /// <summary>
  94. /// <para> Prioritizes a request you have sent, the actual HTTP client code may have many requests queued, and this will move</para>
  95. /// <para> the specified request to the head of the queue. Returns false on invalid handle, or if the request is not yet sent.</para>
  96. /// </summary>
  97. public static bool PrioritizeHTTPRequest(HTTPRequestHandle hRequest) {
  98. InteropHelp.TestIfAvailableGameServer();
  99. return NativeMethods.ISteamHTTP_PrioritizeHTTPRequest(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest);
  100. }
  101. /// <summary>
  102. /// <para> Checks if a response header is present in a HTTP response given a handle from HTTPRequestCompleted_t, also</para>
  103. /// <para> returns the size of the header value if present so the caller and allocate a correctly sized buffer for</para>
  104. /// <para> GetHTTPResponseHeaderValue.</para>
  105. /// </summary>
  106. public static bool GetHTTPResponseHeaderSize(HTTPRequestHandle hRequest, string pchHeaderName, out uint unResponseHeaderSize) {
  107. InteropHelp.TestIfAvailableGameServer();
  108. using (var pchHeaderName2 = new InteropHelp.UTF8StringHandle(pchHeaderName)) {
  109. return NativeMethods.ISteamHTTP_GetHTTPResponseHeaderSize(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, pchHeaderName2, out unResponseHeaderSize);
  110. }
  111. }
  112. /// <summary>
  113. /// <para> Gets header values from a HTTP response given a handle from HTTPRequestCompleted_t, will return false if the</para>
  114. /// <para> header is not present or if your buffer is too small to contain it's value. You should first call</para>
  115. /// <para> BGetHTTPResponseHeaderSize to check for the presence of the header and to find out the size buffer needed.</para>
  116. /// </summary>
  117. public static bool GetHTTPResponseHeaderValue(HTTPRequestHandle hRequest, string pchHeaderName, byte[] pHeaderValueBuffer, uint unBufferSize) {
  118. InteropHelp.TestIfAvailableGameServer();
  119. using (var pchHeaderName2 = new InteropHelp.UTF8StringHandle(pchHeaderName)) {
  120. return NativeMethods.ISteamHTTP_GetHTTPResponseHeaderValue(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, pchHeaderName2, pHeaderValueBuffer, unBufferSize);
  121. }
  122. }
  123. /// <summary>
  124. /// <para> Gets the size of the body data from a HTTP response given a handle from HTTPRequestCompleted_t, will return false if the</para>
  125. /// <para> handle is invalid.</para>
  126. /// </summary>
  127. public static bool GetHTTPResponseBodySize(HTTPRequestHandle hRequest, out uint unBodySize) {
  128. InteropHelp.TestIfAvailableGameServer();
  129. return NativeMethods.ISteamHTTP_GetHTTPResponseBodySize(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, out unBodySize);
  130. }
  131. /// <summary>
  132. /// <para> Gets the body data from a HTTP response given a handle from HTTPRequestCompleted_t, will return false if the</para>
  133. /// <para> handle is invalid or is to a streaming response, or if the provided buffer is not the correct size. Use BGetHTTPResponseBodySize first to find out</para>
  134. /// <para> the correct buffer size to use.</para>
  135. /// </summary>
  136. public static bool GetHTTPResponseBodyData(HTTPRequestHandle hRequest, byte[] pBodyDataBuffer, uint unBufferSize) {
  137. InteropHelp.TestIfAvailableGameServer();
  138. return NativeMethods.ISteamHTTP_GetHTTPResponseBodyData(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, pBodyDataBuffer, unBufferSize);
  139. }
  140. /// <summary>
  141. /// <para> Gets the body data from a streaming HTTP response given a handle from HTTPRequestDataReceived_t. Will return false if the</para>
  142. /// <para> handle is invalid or is to a non-streaming response (meaning it wasn't sent with SendHTTPRequestAndStreamResponse), or if the buffer size and offset</para>
  143. /// <para> do not match the size and offset sent in HTTPRequestDataReceived_t.</para>
  144. /// </summary>
  145. public static bool GetHTTPStreamingResponseBodyData(HTTPRequestHandle hRequest, uint cOffset, byte[] pBodyDataBuffer, uint unBufferSize) {
  146. InteropHelp.TestIfAvailableGameServer();
  147. return NativeMethods.ISteamHTTP_GetHTTPStreamingResponseBodyData(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, cOffset, pBodyDataBuffer, unBufferSize);
  148. }
  149. /// <summary>
  150. /// <para> Releases an HTTP response handle, should always be called to free resources after receiving a HTTPRequestCompleted_t</para>
  151. /// <para> callback and finishing using the response.</para>
  152. /// </summary>
  153. public static bool ReleaseHTTPRequest(HTTPRequestHandle hRequest) {
  154. InteropHelp.TestIfAvailableGameServer();
  155. return NativeMethods.ISteamHTTP_ReleaseHTTPRequest(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest);
  156. }
  157. /// <summary>
  158. /// <para> Gets progress on downloading the body for the request. This will be zero unless a response header has already been</para>
  159. /// <para> received which included a content-length field. For responses that contain no content-length it will report</para>
  160. /// <para> zero for the duration of the request as the size is unknown until the connection closes.</para>
  161. /// </summary>
  162. public static bool GetHTTPDownloadProgressPct(HTTPRequestHandle hRequest, out float pflPercentOut) {
  163. InteropHelp.TestIfAvailableGameServer();
  164. return NativeMethods.ISteamHTTP_GetHTTPDownloadProgressPct(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, out pflPercentOut);
  165. }
  166. /// <summary>
  167. /// <para> Sets the body for an HTTP Post request. Will fail and return false on a GET request, and will fail if POST params</para>
  168. /// <para> have already been set for the request. Setting this raw body makes it the only contents for the post, the pchContentType</para>
  169. /// <para> parameter will set the content-type header for the request so the server may know how to interpret the body.</para>
  170. /// </summary>
  171. public static bool SetHTTPRequestRawPostBody(HTTPRequestHandle hRequest, string pchContentType, byte[] pubBody, uint unBodyLen) {
  172. InteropHelp.TestIfAvailableGameServer();
  173. using (var pchContentType2 = new InteropHelp.UTF8StringHandle(pchContentType)) {
  174. return NativeMethods.ISteamHTTP_SetHTTPRequestRawPostBody(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, pchContentType2, pubBody, unBodyLen);
  175. }
  176. }
  177. /// <summary>
  178. /// <para> Creates a cookie container handle which you must later free with ReleaseCookieContainer(). If bAllowResponsesToModify=true</para>
  179. /// <para> than any response to your requests using this cookie container may add new cookies which may be transmitted with</para>
  180. /// <para> future requests. If bAllowResponsesToModify=false than only cookies you explicitly set will be sent. This API is just for</para>
  181. /// <para> during process lifetime, after steam restarts no cookies are persisted and you have no way to access the cookie container across</para>
  182. /// <para> repeat executions of your process.</para>
  183. /// </summary>
  184. public static HTTPCookieContainerHandle CreateCookieContainer(bool bAllowResponsesToModify) {
  185. InteropHelp.TestIfAvailableGameServer();
  186. return (HTTPCookieContainerHandle)NativeMethods.ISteamHTTP_CreateCookieContainer(CSteamGameServerAPIContext.GetSteamHTTP(), bAllowResponsesToModify);
  187. }
  188. /// <summary>
  189. /// <para> Release a cookie container you are finished using, freeing it's memory</para>
  190. /// </summary>
  191. public static bool ReleaseCookieContainer(HTTPCookieContainerHandle hCookieContainer) {
  192. InteropHelp.TestIfAvailableGameServer();
  193. return NativeMethods.ISteamHTTP_ReleaseCookieContainer(CSteamGameServerAPIContext.GetSteamHTTP(), hCookieContainer);
  194. }
  195. /// <summary>
  196. /// <para> Adds a cookie to the specified cookie container that will be used with future requests.</para>
  197. /// </summary>
  198. public static bool SetCookie(HTTPCookieContainerHandle hCookieContainer, string pchHost, string pchUrl, string pchCookie) {
  199. InteropHelp.TestIfAvailableGameServer();
  200. using (var pchHost2 = new InteropHelp.UTF8StringHandle(pchHost))
  201. using (var pchUrl2 = new InteropHelp.UTF8StringHandle(pchUrl))
  202. using (var pchCookie2 = new InteropHelp.UTF8StringHandle(pchCookie)) {
  203. return NativeMethods.ISteamHTTP_SetCookie(CSteamGameServerAPIContext.GetSteamHTTP(), hCookieContainer, pchHost2, pchUrl2, pchCookie2);
  204. }
  205. }
  206. /// <summary>
  207. /// <para> Set the cookie container to use for a HTTP request</para>
  208. /// </summary>
  209. public static bool SetHTTPRequestCookieContainer(HTTPRequestHandle hRequest, HTTPCookieContainerHandle hCookieContainer) {
  210. InteropHelp.TestIfAvailableGameServer();
  211. return NativeMethods.ISteamHTTP_SetHTTPRequestCookieContainer(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, hCookieContainer);
  212. }
  213. /// <summary>
  214. /// <para> Set the extra user agent info for a request, this doesn't clobber the normal user agent, it just adds the extra info on the end</para>
  215. /// </summary>
  216. public static bool SetHTTPRequestUserAgentInfo(HTTPRequestHandle hRequest, string pchUserAgentInfo) {
  217. InteropHelp.TestIfAvailableGameServer();
  218. using (var pchUserAgentInfo2 = new InteropHelp.UTF8StringHandle(pchUserAgentInfo)) {
  219. return NativeMethods.ISteamHTTP_SetHTTPRequestUserAgentInfo(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, pchUserAgentInfo2);
  220. }
  221. }
  222. /// <summary>
  223. /// <para> Disable or re-enable verification of SSL/TLS certificates.</para>
  224. /// <para> By default, certificates are checked for all HTTPS requests.</para>
  225. /// </summary>
  226. public static bool SetHTTPRequestRequiresVerifiedCertificate(HTTPRequestHandle hRequest, bool bRequireVerifiedCertificate) {
  227. InteropHelp.TestIfAvailableGameServer();
  228. return NativeMethods.ISteamHTTP_SetHTTPRequestRequiresVerifiedCertificate(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, bRequireVerifiedCertificate);
  229. }
  230. /// <summary>
  231. /// <para> Set an absolute timeout on the HTTP request, this is just a total time timeout different than the network activity timeout</para>
  232. /// <para> which can bump everytime we get more data</para>
  233. /// </summary>
  234. public static bool SetHTTPRequestAbsoluteTimeoutMS(HTTPRequestHandle hRequest, uint unMilliseconds) {
  235. InteropHelp.TestIfAvailableGameServer();
  236. return NativeMethods.ISteamHTTP_SetHTTPRequestAbsoluteTimeoutMS(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, unMilliseconds);
  237. }
  238. /// <summary>
  239. /// <para> Check if the reason the request failed was because we timed it out (rather than some harder failure)</para>
  240. /// </summary>
  241. public static bool GetHTTPRequestWasTimedOut(HTTPRequestHandle hRequest, out bool pbWasTimedOut) {
  242. InteropHelp.TestIfAvailableGameServer();
  243. return NativeMethods.ISteamHTTP_GetHTTPRequestWasTimedOut(CSteamGameServerAPIContext.GetSteamHTTP(), hRequest, out pbWasTimedOut);
  244. }
  245. }
  246. }
  247. #endif // !DISABLESTEAMWORKS