RealmGateAddressComponent.cs 799 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.Collections.Generic;
  2. using Base;
  3. namespace Model
  4. {
  5. [ObjectEvent]
  6. public class RealmGateAddressComponentEvent : ObjectEvent<RealmGateAddressComponent>, IAwake
  7. {
  8. public void Awake()
  9. {
  10. this.GetValue().Awake();
  11. }
  12. }
  13. public class RealmGateAddressComponent : Component
  14. {
  15. private readonly List<string> GateAddress = new List<string>();
  16. public void Awake()
  17. {
  18. CommandLines commandLines = this.GetComponent<OptionsComponent>().AllOptions;
  19. foreach (Options options in commandLines.Options)
  20. {
  21. if (options.AppType != "Gate")
  22. {
  23. continue;
  24. }
  25. this.GateAddress.Add($"{options.Host}:{options.Port}");
  26. }
  27. }
  28. public string GetAddress()
  29. {
  30. int n = RandomHelper.RandomNumber(0, this.GateAddress.Count);
  31. return this.GateAddress[n];
  32. }
  33. }
  34. }