Skip to content

Commit

Permalink
Add handling for StatusAddresses in GameServerStatus for the Unity SDK (
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesvien authored Apr 6, 2024
1 parent 0e6d2d8 commit 8c56546
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 2 deletions.
21 changes: 19 additions & 2 deletions sdks/unity/model/GameServerStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,17 @@ public GameServerStatus(IReadOnlyDictionary<string, object> data)
this.State = (string) data["state"];
this.Address = (string) data["address"];

this.Addresses = new List<StatusAddresses>();
var addressItems = (IReadOnlyList<object>) data["addresses"];
foreach (var i in addressItems)
{
var address = new StatusAddresses((Dictionary<string, object>) i);
this.Addresses.Add(address);
}

this.Ports = new List<StatusPort>();
var items = (IReadOnlyList<object>) data["ports"];
foreach (var i in items)
var portItems = (IReadOnlyList<object>) data["ports"];
foreach (var i in portItems)
{
var port = new StatusPort((Dictionary<string, object>) i);
this.Ports.Add(port);
Expand All @@ -46,6 +54,7 @@ public GameServerStatus(IReadOnlyDictionary<string, object> data)

public string State { get; }
public string Address { get; }
public List<StatusAddresses> Addresses { get; }
public List<StatusPort> Ports { get; }

/// <summary>
Expand All @@ -58,6 +67,7 @@ public override string ToString()
sb.Append("class GameServerStatus {\n");
sb.Append(" State: ").Append(State).Append("\n");
sb.Append(" Address: ").Append(Address).Append("\n");
sb.Append(" Addresses: ").Append(string.Join(";", Addresses)).Append("\n");
sb.Append(" Ports: ").Append(string.Join(";", Ports)).Append("\n");
sb.Append("}\n");
return sb.ToString();
Expand Down Expand Up @@ -94,6 +104,11 @@ public bool Equals(GameServerStatus input)
(this.Address != null &&
this.Address.Equals(input.Address))
) &&
(
this.Addresses == input.Addresses ||
this.Addresses != null &&
this.Addresses.SequenceEqual(input.Addresses)
) &&
(
this.Ports == input.Ports ||
this.Ports != null &&
Expand All @@ -114,6 +129,8 @@ public override int GetHashCode()
hashCode = hashCode * 59 + this.State.GetHashCode();
if (this.Address != null)
hashCode = hashCode * 59 + this.Address.GetHashCode();
if (this.Addresses != null)
hashCode = hashCode * 59 + this.Addresses.GetHashCode();
if (this.Ports != null)
hashCode = hashCode * 59 + this.Ports.GetHashCode();
return hashCode;
Expand Down
89 changes: 89 additions & 0 deletions sdks/unity/model/StatusAddresses.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Agones.Model
{
/// <summary>
/// StatusAddresses represents an address with a specific type.
/// </summary>
public class StatusAddresses : IEquatable<StatusAddresses>
{
/// <summary>
/// Initializes a new instance of the <see cref="StatusAddresses" /> class.
/// </summary>
/// <param name="data">The data dictionary containing the address and type.</param>
public StatusAddresses(IReadOnlyDictionary<string, object> data)
{
this.Address = (string)data["address"];
this.Type = (string)data["type"];
}

public string Address { get; }
public string Type { get; }

/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("class StatusAddresses {\n");
sb.Append(" Address: ").Append(Address).Append("\n");
sb.Append(" Type: ").Append(Type).Append("\n");
sb.Append("}\n");
return sb.ToString();
}

/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="input">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object input)
{
return this.Equals(input as StatusAddresses);
}

/// <summary>
/// Returns true if StatusAddresses instances are equal
/// </summary>
/// <param name="input">Instance of StatusAddresses to be compared</param>
/// <returns>Boolean</returns>
public bool Equals(StatusAddresses input)
{
if (input == null)
return false;

return
(
this.Address == input.Address ||
(this.Address != null &&
this.Address.Equals(input.Address))
) &&
(
this.Type == input.Type ||
(this.Type != null &&
this.Type.Equals(input.Type))
);
}

/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.Address != null)
hashCode = hashCode * 59 + this.Address.GetHashCode();
if (this.Type != null)
hashCode = hashCode * 59 + this.Type.GetHashCode();
return hashCode;
}
}
}
}
11 changes: 11 additions & 0 deletions sdks/unity/model/StatusAddresses.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8c56546

Please sign in to comment.