PeersManager.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ENet
  4. {
  5. internal class PeersManager
  6. {
  7. private readonly Dictionary<IntPtr, ESocket> peersManager =
  8. new Dictionary<IntPtr, ESocket>();
  9. public void Add(IntPtr peerPtr, ESocket eSocket)
  10. {
  11. this.peersManager.Add(peerPtr, eSocket);
  12. }
  13. public void Remove(IntPtr peerPtr)
  14. {
  15. this.peersManager.Remove(peerPtr);
  16. }
  17. public bool ContainsKey(IntPtr peerPtr)
  18. {
  19. if (this.peersManager.ContainsKey(peerPtr))
  20. {
  21. return true;
  22. }
  23. return false;
  24. }
  25. public ESocket this[IntPtr peerPtr]
  26. {
  27. get
  28. {
  29. if (!this.peersManager.ContainsKey(peerPtr))
  30. {
  31. throw new KeyNotFoundException("No Peer Key");
  32. }
  33. return this.peersManager[peerPtr];
  34. }
  35. }
  36. }
  37. }