Network.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. // WARNING - AUTOGENERATED - DO NOT EDIT
  2. //
  3. // Generated using `sharpie urho`
  4. //
  5. // Network.cs
  6. //
  7. // Copyright 2015 Xamarin Inc. All rights reserved.
  8. using System;
  9. using System.Runtime.InteropServices;
  10. using System.Collections.Generic;
  11. using Urho.Urho2D;
  12. using Urho.Gui;
  13. using Urho.Resources;
  14. using Urho.IO;
  15. using Urho.Navigation;
  16. using Urho.Network;
  17. namespace Urho.Network
  18. {
  19. /// <summary>
  20. /// %Network subsystem. Manages client-server communications using the UDP protocol.
  21. /// </summary>
  22. public unsafe partial class Network : UrhoObject
  23. {
  24. unsafe partial void OnNetworkCreated ();
  25. [Preserve]
  26. public Network (IntPtr handle) : base (handle)
  27. {
  28. OnNetworkCreated ();
  29. }
  30. [Preserve]
  31. protected Network (UrhoObjectFlag emptyFlag) : base (emptyFlag)
  32. {
  33. OnNetworkCreated ();
  34. }
  35. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  36. internal static extern int Network_GetType (IntPtr handle);
  37. private StringHash UrhoGetType ()
  38. {
  39. Runtime.ValidateRefCounted (this);
  40. return new StringHash (Network_GetType (handle));
  41. }
  42. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  43. internal static extern IntPtr Network_GetTypeName (IntPtr handle);
  44. private string GetTypeName ()
  45. {
  46. Runtime.ValidateRefCounted (this);
  47. return Marshal.PtrToStringAnsi (Network_GetTypeName (handle));
  48. }
  49. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  50. internal static extern int Network_GetTypeStatic ();
  51. private static StringHash GetTypeStatic ()
  52. {
  53. Runtime.Validate (typeof(Network));
  54. return new StringHash (Network_GetTypeStatic ());
  55. }
  56. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  57. internal static extern IntPtr Network_GetTypeNameStatic ();
  58. private static string GetTypeNameStatic ()
  59. {
  60. Runtime.Validate (typeof(Network));
  61. return Marshal.PtrToStringAnsi (Network_GetTypeNameStatic ());
  62. }
  63. [Preserve]
  64. public Network () : this (Application.CurrentContext)
  65. {
  66. }
  67. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  68. internal static extern IntPtr Network_Network (IntPtr context);
  69. [Preserve]
  70. public Network (Context context) : base (UrhoObjectFlag.Empty)
  71. {
  72. Runtime.Validate (typeof(Network));
  73. handle = Network_Network ((object)context == null ? IntPtr.Zero : context.Handle);
  74. Runtime.RegisterObject (this);
  75. OnNetworkCreated ();
  76. }
  77. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  78. internal static extern void Network_Disconnect (IntPtr handle, int waitMSec);
  79. /// <summary>
  80. /// Disconnect the connection to the server. If wait time is non-zero, will block while waiting for disconnect to finish.
  81. /// </summary>
  82. public void Disconnect (int waitMSec = 0)
  83. {
  84. Runtime.ValidateRefCounted (this);
  85. Network_Disconnect (handle, waitMSec);
  86. }
  87. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  88. internal static extern bool Network_StartServer (IntPtr handle, ushort port);
  89. /// <summary>
  90. /// Start a server on a port using UDP protocol. Return true if successful.
  91. /// </summary>
  92. public bool StartServer (ushort port)
  93. {
  94. Runtime.ValidateRefCounted (this);
  95. return Network_StartServer (handle, port);
  96. }
  97. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  98. internal static extern void Network_StopServer (IntPtr handle);
  99. /// <summary>
  100. /// Stop the server.
  101. /// </summary>
  102. public void StopServer ()
  103. {
  104. Runtime.ValidateRefCounted (this);
  105. Network_StopServer (handle);
  106. }
  107. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  108. internal static extern void Network_BroadcastMessage (IntPtr handle, int msgID, bool reliable, bool inOrder, byte* data, uint numBytes, uint contentID);
  109. /// <summary>
  110. /// Broadcast a message with content ID to all client connections.
  111. /// </summary>
  112. public void BroadcastMessage (int msgID, bool reliable, bool inOrder, byte* data, uint numBytes, uint contentID = 0)
  113. {
  114. Runtime.ValidateRefCounted (this);
  115. Network_BroadcastMessage (handle, msgID, reliable, inOrder, data, numBytes, contentID);
  116. }
  117. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  118. internal static extern void Network_SetUpdateFps (IntPtr handle, int fps);
  119. /// <summary>
  120. /// Set network update FPS.
  121. /// </summary>
  122. private void SetUpdateFps (int fps)
  123. {
  124. Runtime.ValidateRefCounted (this);
  125. Network_SetUpdateFps (handle, fps);
  126. }
  127. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  128. internal static extern void Network_SetSimulatedLatency (IntPtr handle, int ms);
  129. /// <summary>
  130. /// Set simulated latency in milliseconds. This adds a fixed delay before sending each packet.
  131. /// </summary>
  132. private void SetSimulatedLatency (int ms)
  133. {
  134. Runtime.ValidateRefCounted (this);
  135. Network_SetSimulatedLatency (handle, ms);
  136. }
  137. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  138. internal static extern void Network_SetSimulatedPacketLoss (IntPtr handle, float probability);
  139. /// <summary>
  140. /// Set simulated packet loss probability between 0.0 - 1.0.
  141. /// </summary>
  142. private void SetSimulatedPacketLoss (float probability)
  143. {
  144. Runtime.ValidateRefCounted (this);
  145. Network_SetSimulatedPacketLoss (handle, probability);
  146. }
  147. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  148. internal static extern void Network_RegisterRemoteEvent (IntPtr handle, int eventType);
  149. /// <summary>
  150. /// Register a remote event as allowed to be received. There is also a fixed blacklist of events that can not be allowed in any case, such as ConsoleCommand.
  151. /// </summary>
  152. public void RegisterRemoteEvent (StringHash eventType)
  153. {
  154. Runtime.ValidateRefCounted (this);
  155. Network_RegisterRemoteEvent (handle, eventType.Code);
  156. }
  157. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  158. internal static extern void Network_UnregisterRemoteEvent (IntPtr handle, int eventType);
  159. /// <summary>
  160. /// Unregister a remote event as allowed to received.
  161. /// </summary>
  162. public void UnregisterRemoteEvent (StringHash eventType)
  163. {
  164. Runtime.ValidateRefCounted (this);
  165. Network_UnregisterRemoteEvent (handle, eventType.Code);
  166. }
  167. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  168. internal static extern void Network_UnregisterAllRemoteEvents (IntPtr handle);
  169. /// <summary>
  170. /// Unregister all remote events.
  171. /// </summary>
  172. public void UnregisterAllRemoteEvents ()
  173. {
  174. Runtime.ValidateRefCounted (this);
  175. Network_UnregisterAllRemoteEvents (handle);
  176. }
  177. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  178. internal static extern void Network_SetPackageCacheDir (IntPtr handle, string path);
  179. /// <summary>
  180. /// Set the package download cache directory.
  181. /// </summary>
  182. private void SetPackageCacheDir (string path)
  183. {
  184. Runtime.ValidateRefCounted (this);
  185. Network_SetPackageCacheDir (handle, path);
  186. }
  187. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  188. internal static extern void Network_SendPackageToClients (IntPtr handle, IntPtr scene, IntPtr package);
  189. /// <summary>
  190. /// Trigger all client connections in the specified scene to download a package file from the server. Can be used to download additional resource packages when clients are already joined in the scene. The package must have been added as a requirement to the scene, or else the eventual download will fail.
  191. /// </summary>
  192. public void SendPackageToClients (Scene scene, PackageFile package)
  193. {
  194. Runtime.ValidateRefCounted (this);
  195. Network_SendPackageToClients (handle, (object)scene == null ? IntPtr.Zero : scene.Handle, (object)package == null ? IntPtr.Zero : package.Handle);
  196. }
  197. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  198. internal static extern int Network_GetUpdateFps (IntPtr handle);
  199. /// <summary>
  200. /// Return network update FPS.
  201. /// </summary>
  202. private int GetUpdateFps ()
  203. {
  204. Runtime.ValidateRefCounted (this);
  205. return Network_GetUpdateFps (handle);
  206. }
  207. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  208. internal static extern int Network_GetSimulatedLatency (IntPtr handle);
  209. /// <summary>
  210. /// Return simulated latency in milliseconds.
  211. /// </summary>
  212. private int GetSimulatedLatency ()
  213. {
  214. Runtime.ValidateRefCounted (this);
  215. return Network_GetSimulatedLatency (handle);
  216. }
  217. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  218. internal static extern float Network_GetSimulatedPacketLoss (IntPtr handle);
  219. /// <summary>
  220. /// Return simulated packet loss probability.
  221. /// </summary>
  222. private float GetSimulatedPacketLoss ()
  223. {
  224. Runtime.ValidateRefCounted (this);
  225. return Network_GetSimulatedPacketLoss (handle);
  226. }
  227. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  228. internal static extern IntPtr Network_GetServerConnection (IntPtr handle);
  229. /// <summary>
  230. /// Return the connection to the server. Null if not connected.
  231. /// </summary>
  232. private Connection GetServerConnection ()
  233. {
  234. Runtime.ValidateRefCounted (this);
  235. return Runtime.LookupObject<Connection> (Network_GetServerConnection (handle));
  236. }
  237. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  238. internal static extern bool Network_IsServerRunning (IntPtr handle);
  239. /// <summary>
  240. /// Return whether the server is running.
  241. /// </summary>
  242. private bool IsServerRunning ()
  243. {
  244. Runtime.ValidateRefCounted (this);
  245. return Network_IsServerRunning (handle);
  246. }
  247. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  248. internal static extern bool Network_CheckRemoteEvent (IntPtr handle, int eventType);
  249. /// <summary>
  250. /// Return whether a remote event is allowed to be received.
  251. /// </summary>
  252. public bool CheckRemoteEvent (StringHash eventType)
  253. {
  254. Runtime.ValidateRefCounted (this);
  255. return Network_CheckRemoteEvent (handle, eventType.Code);
  256. }
  257. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  258. internal static extern IntPtr Network_GetPackageCacheDir (IntPtr handle);
  259. /// <summary>
  260. /// Return the package download cache directory.
  261. /// </summary>
  262. private string GetPackageCacheDir ()
  263. {
  264. Runtime.ValidateRefCounted (this);
  265. return Marshal.PtrToStringAnsi (Network_GetPackageCacheDir (handle));
  266. }
  267. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  268. internal static extern void Network_Update (IntPtr handle, float timeStep);
  269. /// <summary>
  270. /// Process incoming messages from connections. Called by HandleBeginFrame.
  271. /// </summary>
  272. public void Update (float timeStep)
  273. {
  274. Runtime.ValidateRefCounted (this);
  275. Network_Update (handle, timeStep);
  276. }
  277. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  278. internal static extern void Network_PostUpdate (IntPtr handle, float timeStep);
  279. /// <summary>
  280. /// Send outgoing messages after frame logic. Called by HandleRenderUpdate.
  281. /// </summary>
  282. public void PostUpdate (float timeStep)
  283. {
  284. Runtime.ValidateRefCounted (this);
  285. Network_PostUpdate (handle, timeStep);
  286. }
  287. public override StringHash Type {
  288. get {
  289. return UrhoGetType ();
  290. }
  291. }
  292. public override string TypeName {
  293. get {
  294. return GetTypeName ();
  295. }
  296. }
  297. [Preserve]
  298. public static StringHash TypeStatic {
  299. get {
  300. return GetTypeStatic ();
  301. }
  302. }
  303. public static string TypeNameStatic {
  304. get {
  305. return GetTypeNameStatic ();
  306. }
  307. }
  308. /// <summary>
  309. /// Return network update FPS.
  310. /// Or
  311. /// Set network update FPS.
  312. /// </summary>
  313. public int UpdateFps {
  314. get {
  315. return GetUpdateFps ();
  316. }
  317. set {
  318. SetUpdateFps (value);
  319. }
  320. }
  321. /// <summary>
  322. /// Return simulated latency in milliseconds.
  323. /// Or
  324. /// Set simulated latency in milliseconds. This adds a fixed delay before sending each packet.
  325. /// </summary>
  326. public int SimulatedLatency {
  327. get {
  328. return GetSimulatedLatency ();
  329. }
  330. set {
  331. SetSimulatedLatency (value);
  332. }
  333. }
  334. /// <summary>
  335. /// Return simulated packet loss probability.
  336. /// Or
  337. /// Set simulated packet loss probability between 0.0 - 1.0.
  338. /// </summary>
  339. public float SimulatedPacketLoss {
  340. get {
  341. return GetSimulatedPacketLoss ();
  342. }
  343. set {
  344. SetSimulatedPacketLoss (value);
  345. }
  346. }
  347. /// <summary>
  348. /// Return the package download cache directory.
  349. /// Or
  350. /// Set the package download cache directory.
  351. /// </summary>
  352. public string PackageCacheDir {
  353. get {
  354. return GetPackageCacheDir ();
  355. }
  356. set {
  357. SetPackageCacheDir (value);
  358. }
  359. }
  360. /// <summary>
  361. /// Return the connection to the server. Null if not connected.
  362. /// </summary>
  363. public Connection ServerConnection {
  364. get {
  365. return GetServerConnection ();
  366. }
  367. }
  368. /// <summary>
  369. /// Return whether the server is running.
  370. /// </summary>
  371. public bool ServerRunning {
  372. get {
  373. return IsServerRunning ();
  374. }
  375. }
  376. }
  377. }