Event.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #region License
  2. /*
  3. ENet for C#
  4. Copyright (c) 2011 James F. Bellinger <jfb@zer7.com>
  5. Permission to use, copy, modify, and/or distribute this software for any
  6. purpose with or without fee is hereby granted, provided that the above
  7. copyright notice and this permission notice appear in all copies.
  8. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #endregion
  17. using ELog;
  18. namespace ENet
  19. {
  20. public unsafe struct Event
  21. {
  22. private readonly Host host;
  23. private Native.ENetEvent e;
  24. public Event(Host host, Native.ENetEvent e)
  25. {
  26. this.e = e;
  27. this.host = host;
  28. }
  29. public byte ChannelID
  30. {
  31. get
  32. {
  33. return this.e.channelID;
  34. }
  35. }
  36. public uint Data
  37. {
  38. get
  39. {
  40. return this.e.data;
  41. }
  42. }
  43. public Native.ENetEvent NativeData
  44. {
  45. get
  46. {
  47. return this.e;
  48. }
  49. set
  50. {
  51. this.e = value;
  52. }
  53. }
  54. public Packet Packet
  55. {
  56. get
  57. {
  58. if (this.e.packet == null)
  59. {
  60. return null;
  61. }
  62. return new Packet(this.e.packet);
  63. }
  64. }
  65. public Peer Peer
  66. {
  67. get
  68. {
  69. if (this.e.peer == null)
  70. {
  71. return null;
  72. }
  73. var data = (int)e.peer->data;
  74. if (!this.host.Peers.ContainsKey(data))
  75. {
  76. return null;
  77. }
  78. return this.host.Peers[data];
  79. }
  80. }
  81. public EventType Type
  82. {
  83. get
  84. {
  85. return this.e.type;
  86. }
  87. }
  88. }
  89. }