PeersManager.cs 746 B

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