Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handling for StatusAddresses in GameServerStatus for the Unity SDK #3739

Merged
merged 1 commit into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading