PeerManager.cs 643 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ENet
  4. {
  5. public class PeerManager
  6. {
  7. private int num = 0;
  8. private readonly Dictionary<int, Peer> peers = new Dictionary<int, Peer>();
  9. public void Add(Peer peer)
  10. {
  11. ++num;
  12. unsafe
  13. {
  14. peer.NativeData->data = (IntPtr)num;
  15. }
  16. peers[num] = peer;
  17. }
  18. public void Remove(int key)
  19. {
  20. peers.Remove(key);
  21. }
  22. public bool ContainsKey(int key)
  23. {
  24. if (peers.ContainsKey(key))
  25. {
  26. return true;
  27. }
  28. return false;
  29. }
  30. public Peer this[int key]
  31. {
  32. get
  33. {
  34. return this.peers[key];
  35. }
  36. set
  37. {
  38. this.peers[key] = value;
  39. }
  40. }
  41. }
  42. }