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

Implementation of GameServer() for Unity #1169

Merged

Conversation

markmandel
Copy link
Member

  • Refactored SendRequestAsync to return a AsyncResult which contains both a success bool, and the returned body text from the http call.
  • Used the swagger.json to generate the basic structure of the GameServer object, and then hand modified as needed.
  • Had to include third_party/MiniJSON because Unity doesn't natively support Dictionary, which means we can't get Label or Annotation data. Then had to manually import the MiniJSON data into GameServer and related model objects.
  • Used a set of symlinks to share the Agones Unity SDK code with the unity-simple example. Couldn't think of a better way.
  • Minor version update on the example project as that is the earliest version I could get in 2018.4.x
  • Added GameServer command to the simple-unity example as well.

Work on #927

@markmandel markmandel added kind/feature New features for Agones area/user-experience Pertaining to developers trying to use Agones, e.g. SDK, installation, etc labels Nov 4, 2019
@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: ac3ac819-075e-4233-bed6-926555391acd

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@roberthbailey
Copy link
Member

/assign @pooneh-m

(since you have a lot more c# experience than I do)

@roberthbailey
Copy link
Member

/assign @dzlier-gcp

Also Dane...

@markmandel
Copy link
Member Author

Weird this flaked - looking at the logs, it completed:

time="2019-11-04 05:17:12.715" level=info msg="checking final crash state" gs=udp-serverv658t state=Unhealthy test=TestGameServerRestartBeforeReadyCrash
time="2019-11-04 05:17:12.715" level=info msg="Unhealthy! We are done!" test=TestGameServerRestartBeforeReadyCrash
--- FAIL: TestGameServerRestartBeforeReadyCrash (269.62s)
    gameserver_test.go:303: 
        	Error Trace:	gameserver_test.go:303
        	Error:      	Could not make GameServer Ready: %v
        	Test:       	TestGameServerRestartBeforeReadyCrash
        	Messages:   	timed out waiting for the condition
FAIL

Restarting the e2e test.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: fe276dcb-f870-49d5-88f5-71ddb76b75ed

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1169/head:pr_1169 && git checkout pr_1169
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.2.0-1712048

@@ -40,6 +40,15 @@ async void SomeMethod()
}
```

To get the details on the [backing `GameServer`]({{< relref "_index.md#gameserver" >}}) call `GameServer()`.

Will return `null` if something there is an error in retrieving the `GameServer` record.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"something" -> remove?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ thank you!

@@ -73,6 +73,14 @@ async void Update()

echoBytes = Encoding.UTF8.GetBytes($"Allocate {ok}");
break;

case "GameServer":
var gameserver = await agones.GameServer();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[future nit.] the C# style guide recommends suffixing async methods with Async. e.g. GameServerAsync.

You should add "Async" as the suffix of every async method name you write.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a good thing. But we already have the rest of the SDK being async, and it wasn't written that way in the first place 😞 we probably should at least be consistent?

@@ -78,7 +81,23 @@ private void OnApplicationQuit()
/// </returns>
public async Task<bool> Ready()
{
return await SendRequestAsync("/ready", "{}");
return await SendRequestAsync("/ready", "{}").ContinueWith(task => task.Result.ok);
Copy link
Contributor

@pooneh-m pooneh-m Nov 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this? -> .ContinueWith(task => task.Result.ok)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are now no longer returning a Task<bool> but a Task<AsyncResult> from SendRequestAsync, since we needed more information from it.

/// <summary>
/// Initializes a new instance of the <see cref="GameServer" /> class.
/// </summary>
public GameServer(IReadOnlyDictionary<string, object> data)
Copy link
Contributor

@pooneh-m pooneh-m Nov 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null check for data?

public GameServer(IReadOnlyDictionary<string, object> data)
{
this.ObjectMeta = new GameServerObjectMeta((Dictionary<string,object>) data["object_meta"]);
this.Spec = new GameServerSpec((Dictionary<string,object>) data["spec"]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this requires force conversion (throw exception if not converted) while status requires soft conversion with as (null value if not converted)? If intended can you add a comment to document?

public SpecHealth(IReadOnlyDictionary<string, object> data)
{
this.Disabled = data.TryGetValue("disabled", out var disabled) && bool.Parse((string) disabled);
this.PeriodSeconds = (Int64) data["period_seconds"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use Int64.Parse for these as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an actual Int64 stored in the map, so there is no string to parse.

return null;
}

var data = Json.Deserialize(result.json) as Dictionary<string, object>;
Copy link
Contributor

@pooneh-m pooneh-m Nov 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a JSON deserializer, such as newtonsoft that accepts the predefined objects here with json names, instead of converting them to a dictionary and find the values?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish. We can't use NuGet, so we can't pull in newtonsoft. There is a Unity specific version of it, but it's huge, and seems like a massive dependency. And we can't force Users to pull things down from the asset store.

MiniJSON is lightweight, and does what we need, even though we have to do more work.

Copy link
Contributor

@pooneh-m pooneh-m Nov 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use NuGet

Why not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not something Unity supports. Also they have older / kinda hacked version of Mono running in there. It's a whole thing.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: a4e5fff8-1d52-4b4f-bedc-6f02d58a862f

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1169/head:pr_1169 && git checkout pr_1169
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.2.0-f842952

@markmandel
Copy link
Member Author

Should be ready for re-review now.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 69612b1f-f353-4d71-8485-cf7bb280710d

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1169/head:pr_1169 && git checkout pr_1169
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.2.0-ad78040

- Refactored `SendRequestAsync` to return a `AsyncResult` which contains
  both a success bool, and the returned body text from the http call.
- Used the swagger.json to generate the basic structure of the
  `GameServer` object, and then hand modified as needed.
- Had to include third_party/MiniJSON because Unity doesn't natively
  support `Dictionary`, which means we can't get Label or Annotation
  data. Then had to manually import the MiniJSON data into GameServer
  and related model objects.
- Used a set of symlinks to share the Agones Unity SDK code with the
  unity-simple example. Couldn't think of a better way.
- Minor version update on the example project as that is the earliest
  version I could get in 2018.4.x
- Added `GameServer` command to the simple-unity example as well.

Work on googleforgames#927
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: dabbb04f-25b5-46c7-b9cd-caf6876c4b10

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1169/head:pr_1169 && git checkout pr_1169
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.2.0-529c33f

@markmandel
Copy link
Member Author

Thanks for the approval @pooneh-m - would love to get @dzlier-gcp to also look, just because of their Unity experience as well.

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dzlier-gcp, markmandel, pooneh-m

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [dzlier-gcp,markmandel,pooneh-m]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@markmandel markmandel merged commit 7c50719 into googleforgames:master Nov 7, 2019
@markmandel markmandel deleted the feature/unity-sdk-gameserver branch November 7, 2019 21:09
@roberthbailey roberthbailey added this to the 1.2.0 milestone Nov 8, 2019
ilkercelikyilmaz pushed a commit to ilkercelikyilmaz/agones that referenced this pull request Oct 23, 2020
- Refactored `SendRequestAsync` to return a `AsyncResult` which contains
  both a success bool, and the returned body text from the http call.
- Used the swagger.json to generate the basic structure of the
  `GameServer` object, and then hand modified as needed.
- Had to include third_party/MiniJSON because Unity doesn't natively
  support `Dictionary`, which means we can't get Label or Annotation
  data. Then had to manually import the MiniJSON data into GameServer
  and related model objects.
- Used a set of symlinks to share the Agones Unity SDK code with the
  unity-simple example. Couldn't think of a better way.
- Minor version update on the example project as that is the earliest
  version I could get in 2018.4.x
- Added `GameServer` command to the simple-unity example as well.

Work on googleforgames#927
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved area/user-experience Pertaining to developers trying to use Agones, e.g. SDK, installation, etc kind/feature New features for Agones lgtm size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants