-
Notifications
You must be signed in to change notification settings - Fork 820
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
Supports Rust Alpha SDK #1717
Merged
Merged
Supports Rust Alpha SDK #1717
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c357d8d
Supports Rust Alpha SDK
yoshd 8b4c100
Fix typo in Rust SDK Test
yoshd 96ab468
Fix Rust SDK tests to run both with and without feature flags
yoshd c2a3600
Fix Rust SDK PlayerTracking test to run when FEATURE_GATES environmen…
yoshd 4c8e95f
Merge branch 'master' into rust-alpha-sdk
markmandel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright 2020 Google LLC All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::sync::Arc; | ||
|
||
use grpcio; | ||
|
||
use errors::*; | ||
use grpc::alpha; | ||
use grpc::alpha_grpc; | ||
|
||
/// Alpha is an instance of the Agones Alpha SDK | ||
pub struct Alpha { | ||
client: Arc<alpha_grpc::SdkClient>, | ||
} | ||
|
||
impl Alpha { | ||
/// new creates a new instance of the Alpha SDK | ||
pub fn new(ch: grpcio::Channel) -> Alpha { | ||
let cli = alpha_grpc::SdkClient::new(ch); | ||
Alpha { | ||
client: Arc::new(cli), | ||
} | ||
} | ||
|
||
/// This returns the last player capacity that was set through the SDK. | ||
/// If the player capacity is set from outside the SDK, use sdk.get_gameserver() instead. | ||
pub fn get_player_capacity(&self) -> Result<i64> { | ||
let req = alpha::Empty::new(); | ||
let count = self.client.get_player_capacity(&req).map(|c| c.count)?; | ||
Ok(count) | ||
} | ||
|
||
/// This changes the player capacity to a new value. | ||
pub fn set_player_capacity(&self, capacity: i64) -> Result<()> { | ||
let mut c = alpha::Count::new(); | ||
c.set_count(capacity); | ||
let res = self.client.set_player_capacity(&c).map(|_| ())?; | ||
Ok(res) | ||
markmandel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/// This function increases the SDK’s stored player count by one, and appends this playerID to GameServer.status.players.ids. | ||
/// Returns true and adds the playerID to the list of playerIDs if the playerIDs was not already in the list of connected playerIDs. | ||
pub fn player_connect<S>(&self, id: S) -> Result<bool> | ||
where | ||
S: Into<String>, | ||
{ | ||
let mut p = alpha::PlayerID::new(); | ||
p.set_playerID(id.into()); | ||
let res = self.client.player_connect(&p).map(|b| b.bool)?; | ||
Ok(res) | ||
} | ||
|
||
/// This function decreases the SDK’s stored player count by one, and removes the playerID from GameServer.status.players.ids. | ||
/// Will return true and remove the supplied playerID from the list of connected playerIDs if the playerID value exists within the list. | ||
pub fn player_disconnect<S>(&self, id: S) -> Result<bool> | ||
where | ||
S: Into<String>, | ||
{ | ||
let mut p = alpha::PlayerID::new(); | ||
p.set_playerID(id.into()); | ||
let res = self.client.player_disconnect(&p).map(|b| b.bool)?; | ||
Ok(res) | ||
} | ||
|
||
/// Returns the current player count. | ||
pub fn get_player_count(&self) -> Result<i64> { | ||
let req = alpha::Empty::new(); | ||
let count = self.client.get_player_count(&req).map(|c| c.count)?; | ||
Ok(count) | ||
} | ||
|
||
/// This returns if the playerID is currently connected to the GameServer. | ||
/// This is always accurate, even if the value hasn’t been updated to the GameServer status yet. | ||
pub fn is_player_connected<S>(&self, id: S) -> Result<bool> | ||
where | ||
S: Into<String>, | ||
{ | ||
let mut p = alpha::PlayerID::new(); | ||
p.set_playerID(id.into()); | ||
let res = self.client.is_player_connected(&p).map(|b| b.bool)?; | ||
Ok(res) | ||
} | ||
|
||
/// This returns the list of the currently connected player ids. | ||
/// This is always accurate, even if the value has not been updated to the Game Server status yet. | ||
pub fn get_connected_players(&self) -> Result<Vec<String>> { | ||
let req = alpha::Empty::new(); | ||
let res = self | ||
.client | ||
.get_connected_players(&req) | ||
.map(|pl| pl.list.into())?; | ||
Ok(res) | ||
} | ||
} | ||
|
||
impl Clone for Alpha { | ||
fn clone(&self) -> Self { | ||
Self { | ||
client: Arc::clone(&self.client), | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably follow what Go is doing - which is running one without the flag, and then one with:
agones/build/includes/sdk.mk
Line 163 in 8b4c100
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review.
OK. As far as I can see, it seems better not to duplicate ports between tests in each language.
I'll fix it like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it.