コード例 #1
0
        public async Task <ResultDto> GameStatus(string matchId, string username, bool isTwitterUser, Action <ResultDto> gameListener)
        {
            var request = new GameStatusRequest()
            {
                MatchId       = matchId,
                Username      = username,
                TwitterLogged = isTwitterUser
            };

            var channel = GrpcChannel.ForAddress(_serverUrl);
            var client  = new MultiplayerGameManager.MultiplayerGameManagerClient(channel);

            using var stream = client.GameStatus(request, GetRequestMetadata());
            ResultDto resultDto = null;

            while (await stream.ResponseStream.MoveNext(CancellationToken.None))
            {
                var response = stream.ResponseStream.Current;
                resultDto = new ResultDto
                {
                    Challenger      = response.Challenger,
                    ChallengerPick  = response.ChallengerPick,
                    User            = response.User,
                    UserPick        = response.UserPick,
                    Result          = (int)response.Result,
                    IsValid         = true,
                    IsFinished      = response.IsFinished,
                    IsGameInitiator = response.IsMaster
                };

                gameListener(resultDto);
            }

            return(resultDto);
        }
コード例 #2
0
 public async Task Pick(string matchId, string username, bool isTwitterUser, int pick)
 {
     var request = new PickRequest()
     {
         MatchId       = matchId,
         Username      = username,
         TwitterLogged = isTwitterUser,
         Pick          = pick
     };
     var channel = GrpcChannel.ForAddress(_serverUrl);
     var client  = new MultiplayerGameManager.MultiplayerGameManagerClient(channel);
     await client.PickAsync(request, GetRequestMetadata());
 }
コード例 #3
0
        public async Task <LeaderboardDto> GetLeaderboard()
        {
            var channel     = GrpcChannel.ForAddress(_serverUrl);
            var client      = new MultiplayerGameManager.MultiplayerGameManagerClient(channel);
            var leaderboard = await client.LeaderboardAsync(new Empty());

            return(new LeaderboardDto()
            {
                Players = leaderboard.Players.Select(
                    p => new LeaderboardEntryDto {
                    Username = p.Username, Score = p.Score
                })
            });
        }
コード例 #4
0
        public async Task <string> JoinPairing(string username, bool isTwitterUser, string token)
        {
            var request = new JoinPairingRequest()
            {
                Username = username, Token = token, TwitterLogged = isTwitterUser
            };
            var channel = GrpcChannel.ForAddress(_serverUrl);
            var client  = new MultiplayerGameManager.MultiplayerGameManagerClient(channel);

            using var stream = client.JoinPairing(request, GetRequestMetadata());
            PairingStatusResponse response = null;

            while (await stream.ResponseStream.MoveNext(CancellationToken.None))
            {
                response = stream.ResponseStream.Current;
            }

            return(response.MatchId);
        }
コード例 #5
0
        public async Task <bool> Rematch(string matchId, string username, bool isTwitterUser)
        {
            var request = new RematchRequest()
            {
                MatchId       = matchId,
                Username      = username,
                TwitterLogged = isTwitterUser
            };

            var channel = GrpcChannel.ForAddress(_serverUrl);
            var client  = new MultiplayerGameManager.MultiplayerGameManagerClient(channel);

            using var stream = client.Rematch(request);
            while (await stream.ResponseStream.MoveNext(CancellationToken.None))
            {
                var response = stream.ResponseStream.Current;
                if (response.HasStarted)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #6
0
 public MultiplayerGameManagerClient(MultiplayerGameManager.MultiplayerGameManagerClient multiplayerGameManagerClient)
 {
     _multiplayerGameManagerClient = multiplayerGameManagerClient;
 }