public void ReturnUnknownErrorIfJoinRequestErrored() { var joinReq = new PlayerJoinRequest("test_op", "", "", null); joinReq.State = MatchState.Error; _memoryStoreClient.Setup(client => client.GetAsync <PlayerJoinRequest>("test_op")).ReturnsAsync(joinReq); var deleted = new List <PlayerJoinRequest>(); _transaction.Setup(tx => tx.DeleteAll(It.IsAny <IEnumerable <Entry> >())) .Callback <IEnumerable <Entry> >(requests => deleted.AddRange(requests.Select(r => (PlayerJoinRequest)r))); var context = Util.CreateFakeCallContext("test_op", Pit); var resp = _service.GetOperation(new GetOperationRequest { Name = "test_op" }, context); Assert.That(resp.IsCompletedSuccessfully); Assert.AreEqual(StatusCode.OK, context.Status.StatusCode); var op = resp.Result; Assert.That(op.Done); var joinError = op.Error; Assert.AreEqual((int)StatusCode.Unknown, joinError.Code); Assert.That(joinError.Message, Contains.Substring("join request encountered an error")); Assert.AreEqual("test_op", deleted[0].PlayerIdentity); }
public void ReturnOperationWithNotDoneIfStateRequested() { var joinReq = new PlayerJoinRequest("test_op", "", "", null); _memoryStoreClient.Setup(client => client.GetAsync <PlayerJoinRequest>("test_op")).ReturnsAsync(joinReq); var context = Util.CreateFakeCallContext("test_op", Pit); var resp = _service.GetOperation(new GetOperationRequest { Name = "test_op" }, context); Assert.That(resp.IsCompletedSuccessfully); Assert.AreEqual(StatusCode.OK, context.Status.StatusCode); var op = resp.Result; Assert.That(!op.Done); _transaction.Verify(tx => tx.DeleteAll(It.IsAny <IEnumerable <Entry> >()), Times.Never); }
private static byte[] HandleRequest(string message) { PAPIResponse response; if (message.Contains("\"requestType\":\"PAPI.Network.PlayerJoinRequest\"") || message.Contains("\"requestType\":\"PlayerJoinRequest\"")) { PlayerJoinRequest request = JsonSerializer.Deserialize <PlayerJoinRequest>(message); PendingMessages.waitingPlayers.Add(request.playerToJoin); response = new PlayerJoinResponse("PlayerJoinResponse", HttpStatusCode.OK, request.playerToJoin._name); } else { response = new UnspecifiedResponse(); } WfLogger.Log("PAPIServer", LogLevel.DEBUG, "Response: Added Player '" + ((PlayerJoinResponse)response).addedPlayerName + "', Status: " + response.statusCode); return(System.Text.Encoding.Unicode.GetBytes(JsonSerializer.Serialize((PlayerJoinResponse)response))); }
public void ReturnUnavailableErrorIfTransactionAborted() { var joinReq = new PlayerJoinRequest("test_op", "", "", null); joinReq.State = MatchState.Matched; _memoryStoreClient.Setup(client => client.GetAsync <PlayerJoinRequest>("test_op")).ReturnsAsync(joinReq); _transaction.Setup(tx => tx.DeleteAll(It.IsAny <IEnumerable <Entry> >())) .Throws <TransactionAbortedException>(); var context = Util.CreateFakeCallContext("test_op", Pit); var exception = Assert.ThrowsAsync <RpcException>(() => _service.GetOperation(new GetOperationRequest { Name = "test_op" }, context)); Assert.AreEqual(StatusCode.Unavailable, exception.StatusCode); Assert.That(exception.Message, Contains.Substring("deletion aborted")); }
public void ReturnJoinStatusWithNotDoneIfStateMatching() { var joinReq = new PlayerJoinRequest("test_op", "", "", "", "", null); joinReq.State = MatchState.Matching; _memoryStoreClient.Setup(client => client.GetAsync <PlayerJoinRequest>("test_op")).ReturnsAsync(joinReq); var context = Util.CreateFakeCallContext("test_op", Pit); var resp = _service.GetJoinStatus(new GetJoinStatusRequest { PlayerId = "test_op" }, context); Assert.That(resp.IsCompletedSuccessfully); Assert.AreEqual(StatusCode.OK, context.Status.StatusCode); var op = resp.Result; Assert.That(!op.Complete); Assert.AreEqual(GetJoinStatusResponse.Types.Status.Matching, op.Status); _transaction.Verify(tx => tx.DeleteAll(It.IsAny <IEnumerable <Entry> >()), Times.Never); }
private void OnPlayerJoinRequest(PlayerJoinRequest playerJoinRequest, Receiver receiver) { Receiver.UnsubscribeFromMessage <PlayerJoinRequest>(OnPlayerJoinRequest); if (_joined) { return; } try { _networkLobby.PlayerJoinRequest(this, playerJoinRequest.PlayerName); _joined = true; } catch (InvalidActionException exception) { Receiver.SendMessage(new LobbyActionException(exception.Message)); Receiver.SendMessage(new Disconnect()); //_receiver.Disconnect(); } }
public void ReturnAnEquivalentPlayerJoinRequest() { var playerJoinRequest = new PlayerJoinRequest("Leader", "PIT", "type", new Dictionary <string, string> { { "cmf", "cmz" } }); playerJoinRequest.AssignMatch("deployment-id", "deployment-name"); var serializedPlayerJoinRequest = JsonConvert.SerializeObject(playerJoinRequest); var deserializedPlayerJoinRequest = JsonConvert.DeserializeObject <PlayerJoinRequest>(serializedPlayerJoinRequest); Assert.AreEqual(playerJoinRequest.Id, deserializedPlayerJoinRequest.Id); Assert.AreEqual(playerJoinRequest.PlayerIdentity, deserializedPlayerJoinRequest.PlayerIdentity); Assert.AreEqual(playerJoinRequest.PlayerIdentityToken, deserializedPlayerJoinRequest.PlayerIdentityToken); Assert.AreEqual(playerJoinRequest.DeploymentName, deserializedPlayerJoinRequest.DeploymentName); Assert.AreEqual(playerJoinRequest.DeploymentId, deserializedPlayerJoinRequest.DeploymentId); Assert.AreEqual(playerJoinRequest.Type, deserializedPlayerJoinRequest.Type); Assert.AreEqual(playerJoinRequest.State, deserializedPlayerJoinRequest.State); CollectionAssert.AreEquivalent(playerJoinRequest.Metadata, deserializedPlayerJoinRequest.Metadata); }
private Any CreateJoinResponse(PlayerJoinRequest request) { try { var loginTokenResp = _playerAuthServiceClient.CreateLoginToken(new CreateLoginTokenRequest { DeploymentId = request.DeploymentId, PlayerIdentityToken = request.PlayerIdentityToken }); var response = new JoinResponse { DeploymentName = request.DeploymentName, LoginToken = loginTokenResp.LoginToken }; return(Any.Pack(response)); } catch (Exception e) { Log.Error(e, "encountered an error creating a login token"); throw new RpcException(new Status(StatusCode.Internal, "encountered an error creating a login token")); } }
public void ReturnOperationWithResultIfMatched() { var joinReq = new PlayerJoinRequest("testplayer", "test-player-token", "open_world", null); joinReq.AssignMatch("1234", "deployment1234"); _memoryStoreClient.Setup(client => client.GetAsync <PlayerJoinRequest>("test_op")).ReturnsAsync(joinReq); _authClient.Setup(client => client.CreateLoginToken(new CreateLoginTokenRequest { DeploymentId = "1234", PlayerIdentityToken = "test-player-token" }, It.IsAny <CallSettings>())).Returns(new CreateLoginTokenResponse { LoginToken = "test-login-token" }); var deleted = new List <PlayerJoinRequest>(); _transaction.Setup(tx => tx.DeleteAll(It.IsAny <IEnumerable <Entry> >())) .Callback <IEnumerable <Entry> >(requests => deleted.AddRange(requests.Select(r => (PlayerJoinRequest)r))); var context = Util.CreateFakeCallContext("test_op", Pit); var resp = _service.GetOperation(new GetOperationRequest { Name = "test_op" }, context); Assert.That(resp.IsCompletedSuccessfully); Assert.AreEqual(StatusCode.OK, context.Status.StatusCode); var op = resp.Result; Assert.That(op.Done); var joinResponse = op.Response.Unpack <JoinResponse>(); Assert.AreEqual("deployment1234", joinResponse.DeploymentName); Assert.AreEqual("test-login-token", joinResponse.LoginToken); Assert.AreEqual("testplayer", deleted[0].PlayerIdentity); Assert.AreEqual("open_world", deleted[0].Type); }