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

Unity SDK - Watch GameServer Functionality #1234

Merged
merged 2 commits into from
Jan 7, 2020

Conversation

markmandel
Copy link
Member

Able to use the DownloadHandlerScript to intercept streaming HTTP data from the /watch/gameserver REST endpoint.

This finishes the feature work for Unity 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 Dec 13, 2019
@markmandel
Copy link
Member Author

/assign @dzlier-gcp @pooneh-m

Please review 😄

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: f097105f-503f-4b35-86c1-b4d4d1088079

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/1234/head:pr_1234 && git checkout pr_1234
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.3.0-5c6c28e

protected override bool ReceiveData(byte[] data, int dataLength)
{
string json = Encoding.UTF8.GetString(data);
var dictionary = (Dictionary<string, object>) Json.Deserialize(json);
Copy link
Contributor

Choose a reason for hiding this comment

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

can the data contain invalid json?

Copy link
Member Author

Choose a reason for hiding this comment

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

If it did, it would be Exceptional.

🤣

{
string json = Encoding.UTF8.GetString(data);
var dictionary = (Dictionary<string, object>) Json.Deserialize(json);
var gameServer = new GameServer(dictionary["result"] as Dictionary<string, object>);
Copy link
Contributor

Choose a reason for hiding this comment

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

Check to verify "result" key exists in the dictionary?

Copy link
Member Author

Choose a reason for hiding this comment

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

If it doesn't, you will end up with an empty non-populated GameServer.

Should we throw an Exception if it didn't work as expected?

Copy link
Contributor

@pooneh-m pooneh-m Dec 18, 2019

Choose a reason for hiding this comment

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

if result is not in the dictionary, an exception will be thrown:
[System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.] at System.Collections.Generic.Dictionary.get_Item(TKey key)

If you want a non-populated GS, you should handle this with if dictionary.Contains("result")...

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmnn. Actually I don't mind if the exception occurs. It's probably a better indicator that something went horribly wrong, rather than giving a non-populated GS.

So I'm going to go with "works as intended" 👍 (unless you have an objection?)

Appreciate the explanations!

Copy link
Contributor

Choose a reason for hiding this comment

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

The exception is hard to debug without more details. However, if it is intended, LGTM.

echoBytes = Encoding.UTF8.GetBytes($"Reserve({recvTexts[1]}) {ok}");
}
else
{
echoBytes = Encoding.UTF8.GetBytes($"ERROR: Invalid Reserve command, must use 1 argument");
}
break;
case "Watch":
agones.WatchGameServer(gameServer => { Debug.Log($"Server - Watch {gameServer}"); });
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can drop parenthesis x => {y;} --> x => y

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 2147d491-729b-4b9a-9c7f-c8a7a6509db2

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/1234/head:pr_1234 && git checkout pr_1234
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.3.0-35f9017

@dzlier-gcp
Copy link
Contributor

Just noting that I have seen this - will review before EOW

{
string json = Encoding.UTF8.GetString(data);
var dictionary = (Dictionary<string, object>) Json.Deserialize(json);
var gameServer = new GameServer(dictionary["result"] as Dictionary<string, object>);
Copy link
Contributor

@pooneh-m pooneh-m Dec 18, 2019

Choose a reason for hiding this comment

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

if result is not in the dictionary, an exception will be thrown:
[System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.] at System.Collections.Generic.Dictionary.get_Item(TKey key)

If you want a non-populated GS, you should handle this with if dictionary.Contains("result")...

configuration changes.

```csharp
agones.WatchGameServer(gameServer => { Debug.Log($"Server - Watch {gameServer}"); });
Copy link
Contributor

Choose a reason for hiding this comment

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

x => {y;} to x => y here 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.

Doh! Nice pickup. Will change!

Able to use the `DownloadHandlerScript` to intercept streaming HTTP
data from the /watch/gameserver REST endpoint.

This finishes the feature work for Unity on googleforgames#927
@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 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 [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

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: a37eade6-805f-409d-baee-4426243e3a98

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/1234/head:pr_1234 && git checkout pr_1234
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.3.0-222abf0

@markmandel
Copy link
Member Author

I somehow missed this was Approved. Getting it merged!

@google-oss-robot
Copy link

New changes are detected. LGTM label has been removed.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 9b135153-5fc6-48ae-8736-c0ecc2b11446

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/1234/head:pr_1234 && git checkout pr_1234
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.3.0-ebe25b6

@markmandel markmandel merged commit 8d383b6 into googleforgames:master Jan 7, 2020
@markmandel markmandel deleted the feature/unity-watch branch January 7, 2020 20:53
@markmandel markmandel added this to the 1.3.0 milestone Jan 7, 2020
ilkercelikyilmaz pushed a commit to ilkercelikyilmaz/agones that referenced this pull request Oct 23, 2020
Able to use the `DownloadHandlerScript` to intercept streaming HTTP
data from the /watch/gameserver REST endpoint.

This finishes the feature work for Unity 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 size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants