NativeMethods.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Text;
  4. using Common.Network;
  5. namespace UNet
  6. {
  7. public static class NativeMethods
  8. {
  9. private const string LIB = "ENet";
  10. public const int ENET_PEER_PACKET_THROTTLE_SCALE = 32;
  11. public const int ENET_PEER_PACKET_THROTTLE_ACCELERATION = 2;
  12. public const int ENET_PEER_PACKET_THROTTLE_DECELERATION = 2;
  13. public const int ENET_PEER_PACKET_THROTTLE_INTERVAL = 5000;
  14. public const int ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 1;
  15. public const int ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255;
  16. public const int ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xfff;
  17. public const uint ENET_HOST_ANY = 0;
  18. public const uint ENET_HOST_BROADCAST = 0xffffffff;
  19. [DllImport(LIB, EntryPoint = "enet_address_set_host")]
  20. internal static extern int ENetAddressSetHost(ref ENetAddress address, string hostName);
  21. [DllImport(LIB, EntryPoint = "enet_address_get_host")]
  22. internal static extern int ENetAddressGetHost(
  23. ref ENetAddress address, StringBuilder hostName, uint nameLength);
  24. [DllImport(LIB, EntryPoint = "enet_address_get_host_ip")]
  25. internal static extern int ENetAddressGetHostIp(
  26. ref ENetAddress address, StringBuilder hostIp, uint ipLength);
  27. [DllImport(LIB, EntryPoint = "enet_deinitialize")]
  28. internal static extern void ENetDeinitialize();
  29. [DllImport(LIB, EntryPoint = "enet_initialize")]
  30. internal static extern int ENetInitialize();
  31. [DllImport(LIB, EntryPoint = "enet_host_create")]
  32. internal static extern IntPtr ENetHostCreate(
  33. ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth,
  34. uint outgoingBandwidth);
  35. [DllImport(LIB, EntryPoint = "enet_host_create")]
  36. internal static extern IntPtr ENetHostCreate(
  37. IntPtr address, uint peerLimit, uint channelLimit, uint incomingBandwidth,
  38. uint outgoingBandwidth);
  39. [DllImport(LIB, EntryPoint = "enet_host_destroy")]
  40. internal static extern void ENetHostDestroy(IntPtr host);
  41. [DllImport(LIB, EntryPoint = "enet_host_connect")]
  42. internal static extern IntPtr ENetHostConnect(
  43. IntPtr host, ref ENetAddress address, uint channelCount, uint data);
  44. [DllImport(LIB, EntryPoint = "enet_host_broadcast")]
  45. internal static extern void ENetHostBroadcast(IntPtr host, byte channelID, IntPtr packet);
  46. [DllImport(LIB, EntryPoint = "enet_host_compress")]
  47. internal static extern void ENetHostCompress(IntPtr host, IntPtr compressor);
  48. [DllImport(LIB, EntryPoint = "enet_host_compress_with_range_coder")]
  49. internal static extern int ENetHostCompressWithRangeCoder(IntPtr host);
  50. [DllImport(LIB, EntryPoint = "enet_host_channel_limit")]
  51. internal static extern void ENetHostChannelLimit(IntPtr host, uint channelLimit);
  52. [DllImport(LIB, EntryPoint = "enet_host_bandwidth_limit")]
  53. internal static extern void ENetHostBandwidthLimit(
  54. IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
  55. [DllImport(LIB, EntryPoint = "enet_host_flush")]
  56. internal static extern void ENetHostFlush(IntPtr host);
  57. [DllImport(LIB, EntryPoint = "enet_host_check_events")]
  58. internal static extern int ENetHostCheckEvents(IntPtr host, ENetEvent ev);
  59. [DllImport(LIB, EntryPoint = "enet_host_service")]
  60. internal static extern int ENetHostService(IntPtr host, ENetEvent ev, uint timeout);
  61. [DllImport(LIB, EntryPoint = "enet_time_get")]
  62. internal static extern uint ENetTimeGet();
  63. [DllImport(LIB, EntryPoint = "enet_time_set")]
  64. internal static extern void ENetTimeSet(uint newTimeBase);
  65. [DllImport(LIB, EntryPoint = "enet_packet_create")]
  66. internal static extern IntPtr ENetPacketCreate(byte[] data, uint dataLength, PacketFlags flags);
  67. [DllImport(LIB, EntryPoint = "enet_packet_destroy")]
  68. internal static extern void ENetPacketDestroy(IntPtr packet);
  69. [DllImport(LIB, EntryPoint = "enet_packet_resize")]
  70. internal static extern int ENetPacketResize(IntPtr packet, uint dataLength);
  71. [DllImport(LIB, EntryPoint = "enet_peer_throttle_configure")]
  72. internal static extern void ENetPeerThrottleConfigure(
  73. IntPtr peer, uint interval, uint acceleration, uint deceleration);
  74. [DllImport(LIB, EntryPoint = "enet_peer_send")]
  75. internal static extern int ENetPeerSend(IntPtr peer, byte channelID, IntPtr packet);
  76. [DllImport(LIB, EntryPoint = "enet_peer_receive")]
  77. internal static extern IntPtr ENetPeerReceive(IntPtr peer, out byte channelID);
  78. [DllImport(LIB, EntryPoint = "enet_peer_reset")]
  79. internal static extern void ENetPeerReset(IntPtr peer);
  80. [DllImport(LIB, EntryPoint = "enet_peer_ping")]
  81. internal static extern void ENetPeerPing(IntPtr peer);
  82. [DllImport(LIB, EntryPoint = "enet_peer_disconnect_now")]
  83. internal static extern void ENetPeerDisconnectNow(IntPtr peer, uint data);
  84. [DllImport(LIB, EntryPoint = "enet_peer_disconnect")]
  85. internal static extern void ENetPeerDisconnect(IntPtr peer, uint data);
  86. [DllImport(LIB, EntryPoint = "enet_peer_disconnect_later")]
  87. internal static extern void ENetPeerDisconnectLater(IntPtr peer, uint data);
  88. }
  89. }