agones.dev/agones@v1.53.0/sdks/unity/model/GameServerStatus.cs (about) 1 // Copyright 2019 Google LLC 2 // All Rights Reserved. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 using System; 17 using System.Collections.Generic; 18 using System.Linq; 19 using System.Text; 20 21 namespace Agones.Model 22 { 23 /// <summary> 24 /// GameServerStatus 25 /// </summary> 26 public class GameServerStatus : IEquatable<GameServerStatus> 27 { 28 /// <summary> 29 /// Initializes a new instance of the <see cref="GameServerStatus" /> class. 30 /// </summary> 31 public GameServerStatus(IReadOnlyDictionary<string, object> data) 32 { 33 if (data == null) return; 34 35 this.State = (string) data["state"]; 36 this.Address = (string) data["address"]; 37 38 this.Addresses = new List<StatusAddresses>(); 39 var addressItems = (IReadOnlyList<object>) data["addresses"]; 40 foreach (var i in addressItems) 41 { 42 var address = new StatusAddresses((Dictionary<string, object>) i); 43 this.Addresses.Add(address); 44 } 45 46 this.Ports = new List<StatusPort>(); 47 var portItems = (IReadOnlyList<object>) data["ports"]; 48 foreach (var i in portItems) 49 { 50 var port = new StatusPort((Dictionary<string, object>) i); 51 this.Ports.Add(port); 52 } 53 } 54 55 public string State { get; } 56 public string Address { get; } 57 public List<StatusAddresses> Addresses { get; } 58 public List<StatusPort> Ports { get; } 59 60 /// <summary> 61 /// Returns the string presentation of the object 62 /// </summary> 63 /// <returns>String presentation of the object</returns> 64 public override string ToString() 65 { 66 var sb = new StringBuilder(); 67 sb.Append("class GameServerStatus {\n"); 68 sb.Append(" State: ").Append(State).Append("\n"); 69 sb.Append(" Address: ").Append(Address).Append("\n"); 70 sb.Append(" Addresses: ").Append(string.Join(";", Addresses)).Append("\n"); 71 sb.Append(" Ports: ").Append(string.Join(";", Ports)).Append("\n"); 72 sb.Append("}\n"); 73 return sb.ToString(); 74 } 75 76 /// <summary> 77 /// Returns true if objects are equal 78 /// </summary> 79 /// <param name="input">Object to be compared</param> 80 /// <returns>Boolean</returns> 81 public override bool Equals(object input) 82 { 83 return this.Equals(input as GameServerStatus); 84 } 85 86 /// <summary> 87 /// Returns true if GameServerStatus instances are equal 88 /// </summary> 89 /// <param name="input">Instance of GameServerStatus to be compared</param> 90 /// <returns>Boolean</returns> 91 public bool Equals(GameServerStatus input) 92 { 93 if (input == null) 94 return false; 95 96 return 97 ( 98 this.State == input.State || 99 (this.State != null && 100 this.State.Equals(input.State)) 101 ) && 102 ( 103 this.Address == input.Address || 104 (this.Address != null && 105 this.Address.Equals(input.Address)) 106 ) && 107 ( 108 this.Addresses == input.Addresses || 109 this.Addresses != null && 110 this.Addresses.SequenceEqual(input.Addresses) 111 ) && 112 ( 113 this.Ports == input.Ports || 114 this.Ports != null && 115 this.Ports.SequenceEqual(input.Ports) 116 ); 117 } 118 119 /// <summary> 120 /// Gets the hash code 121 /// </summary> 122 /// <returns>Hash code</returns> 123 public override int GetHashCode() 124 { 125 unchecked // Overflow is fine, just wrap 126 { 127 int hashCode = 41; 128 if (this.State != null) 129 hashCode = hashCode * 59 + this.State.GetHashCode(); 130 if (this.Address != null) 131 hashCode = hashCode * 59 + this.Address.GetHashCode(); 132 if (this.Addresses != null) 133 hashCode = hashCode * 59 + this.Addresses.GetHashCode(); 134 if (this.Ports != null) 135 hashCode = hashCode * 59 + this.Ports.GetHashCode(); 136 return hashCode; 137 } 138 } 139 } 140 }