public async Task LeaveRoom(LeaveRoomRequest request) { try { var ctx = new ValidationContext(request); var results = new List <ValidationResult>(); Validator.TryValidateObject(request, ctx, results, true); if (results.Count > 0) { throw new ApplicationError("[LeaveRoom]", 4); } var response = await _roomService.LeaveRoom(request); await Groups.RemoveFromGroupAsync(Context.ConnectionId, response.roomIdentifier.ToString()); await Clients.OthersInGroup(response.roomIdentifier.ToString()).BrLeftRoom(response); //user who left the room does not care anymore about the others. response.users = null; await Clients.Caller.LeftRoom(response); } catch (Exception e) { var errorResponse = ApplicationError.GetError <JoinRoomResponse>(e, "[LeaveRoom]"); _logger.LogError(e.Message); await Clients.Caller.JoinedRoom(errorResponse); } }
public void IfTheCreatorOfALobbyLeavesTheGameIsDestroyed() { var roomId = createRoom(); // Have the host leave the lobby LeaveRoomRequest leaveRequest = new LeaveRoomRequest() { RoomId = roomId }; LeaveRoomResponse leaveResponse = client.LeaveRoom(leaveRequest); Assert.AreEqual(leaveResponse.Status.IsSuccess, true); // Ensure that the player has left the game. // View open rooms. OpenLobbiesResponse openLobbiesResponsAfterLeave = client.GetOpenLobbies(new OpenLobbiesRequest()); assertSuccessResponse(openLobbiesResponsAfterLeave.Status); Assert.AreEqual(0, openLobbiesResponsAfterLeave.Rooms.Count); // Ensure the player is not in the game. PlayerCurrentGamesResponse gamesResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); assertSuccessResponse(gamesResponse.Status); Assert.AreEqual(0, gamesResponse.Games.Count); }
public void LeaveRoomTest() { //Arrange var player = default(Player); var room = _user.CreateNewRoom(_level, _config, out player); LeaveRoomRequest request = new LeaveRoomRequest() { Player = player.GetHashCode(), UserName = _user.UserName, SecurityKey = _securityKey, }; //Act var act = _ctrl.LeaveRoom(request); var actContent = default(LeaveRoomResult); var hasContent = act.TryGetContentValue(out actContent); //Assert TestContext.WriteLine("error message: '{0}'", (actContent != null && actContent.ErrorMessage != "") ? actContent.ErrorMessage : "null"); Assert.AreEqual(HttpStatusCode.OK, act.StatusCode, "status code"); Assert.IsTrue(hasContent, "has contact"); Assert.AreEqual("", actContent.ErrorMessage, "error message"); Assert.AreEqual(true, actContent.Success, "success"); Assert.AreEqual(false, _user.Players.Contains(player, new AddressComparer <Player>())); Assert.IsNotNull(actContent.UserStatistics, "user statistics not null"); }
public override async Task <LeaveRoomResponse> LeaveRoom(LeaveRoomRequest request, ServerCallContext context) { DbUserModel dbUserModel = context.UserState["user"] as DbUserModel; if (dbUserModel == null) { return new LeaveRoomResponse() { Status = ResponseFactory.createResponse(ResponseType.UNAUTHORIZED) } } ; Room room = await Room.GetRoomFromGuid(request.RoomId); if (room == null) { return new LeaveRoomResponse() { Status = ResponseFactory.createResponse(ResponseType.ROOM_DOES_NOT_EXIST) } } ; return(new LeaveRoomResponse() { Status = await room.LeaveRoom(dbUserModel) }); }
/** * Leave a room the user is currently in. */ public async Task <LeaveRoomResponse> LeaveRoom(LeaveRoomRequest payload) { try { var response = new LeaveRoomResponse(); User user = await _userRepository.FindRoomOfUserById((Guid)payload.userIdentifier); if (user == null) { throw new ApplicationError("[RoomService.LeaveRoom]", 1); } if (user.room == null) { throw new ApplicationError("[RoomService.LeaveRoom]", 2); } var roomUsers = await _userRepository.FindAllByRoomId(user.room.id); user.room.users = roomUsers.Where(roomUser => roomUser.id != payload.userIdentifier).ToList(); response.roomIdentifier = user.room.identifier; response.users = user.room.users; await _unitOfWork.Save(); return(response); } catch (Exception e) { throw e; } }
public LeaveRoomResult LeaveRoom(LeaveRoomRequest request) { var result = new LeaveRoomResult(); try { var user = _cache.RefreshAndGet( Users, request.UserName, new UserNotFoundException(string.Format("cannot find user name: {0}, please login again.", request.UserName)) ); UserManager.SecurityCheck(request.SecurityKey, user); var player = _cache.RefreshAndGet( Players, request.Player, new PlayerNotFoundException(string.Format("player id: {0} not found, please re-enter the room.", request.Player)) ); user.ExitRoom(player); result.Success = true; result.UserStatistics = user.UserStatistics; // update cache on removal Players.Remove(player.GetHashCode()); } catch (PokerException e) { result.Success = false; result.ErrorMessage = e.Message; Logger.Error(e, this); } return(result); }
/// <summary> /// Rời khỏi phòng nào đó (Chỉ sử dụng khi JoinGame) còn lại đã tự động hết rồi. /// </summary> public void DoLeaveRoom(int zoneId, int roomId) { LeaveRoomRequest leave = new LeaveRoomRequest(); leave.ZoneId = zoneId; leave.RoomId = roomId; DoRequest(leave); }
public void IfTheCreatorOfALobbyLeavesTheGameNoPlayersAreStuckInTheLobby() { CreateRoomRequest createRequest = new CreateRoomRequest() { Anonymous = false, Goal = Goal.Domination, MaxPlayers = 5, IsRanked = false, RoomName = "My Room!", AllowedSpecialists = { "a", "b", "c" }, }; CreateRoomResponse roomResponse = client.CreateNewRoom(createRequest); Assert.AreEqual(roomResponse.Status.IsSuccess, true); Assert.IsTrue(roomResponse.CreatedRoom.RoomId != null); var roomId = roomResponse.CreatedRoom.RoomId; // Have a player join the game authHelper.loginToAccount("userTwo"); client.JoinRoom(new JoinRoomRequest() { RoomId = roomId, }); authHelper.loginToAccount("userOne"); // Have the host leave the lobby LeaveRoomRequest leaveRequest = new LeaveRoomRequest() { RoomId = roomId }; LeaveRoomResponse leaveResponse = client.LeaveRoom(leaveRequest); Assert.AreEqual(leaveResponse.Status.IsSuccess, true); // Ensure that the player has left the game. // View open rooms. OpenLobbiesResponse openLobbiesResponsAfterLeave = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponsAfterLeave.Status.IsSuccess, true); Assert.AreEqual(0, openLobbiesResponsAfterLeave.Rooms.Count); // Ensure the player is not in the game. PlayerCurrentGamesResponse gamesResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); Assert.AreEqual(gamesResponse.Status.IsSuccess, true); Assert.AreEqual(0, gamesResponse.Games.Count); authHelper.loginToAccount("userTwo"); // Ensure the player is not in the game. PlayerCurrentGamesResponse gamesTwoResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); Assert.AreEqual(gamesTwoResponse.Status.IsSuccess, true); Assert.AreEqual(0, gamesTwoResponse.Games.Count); }
public void PlayerCanLeaveAGameRoom() { CreateRoomResponse roomResponse = client.CreateNewRoom(createRoomRequest("My room!")); Assert.AreEqual(roomResponse.Status.IsSuccess, true); Assert.IsTrue(roomResponse.CreatedRoom.Id != null); var roomId = roomResponse.CreatedRoom.Id; authHelper.loginToAccount("userTwo"); // View open rooms. OpenLobbiesResponse openLobbiesResponse = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponse.Status.IsSuccess, true); Assert.AreEqual(1, openLobbiesResponse.Rooms.Count); Assert.AreEqual(roomId, openLobbiesResponse.Rooms[0].Id); // Ensure the creator is a member of the game Assert.AreEqual(1, openLobbiesResponse.Rooms[0].Players.Count); Assert.AreEqual("userOne", openLobbiesResponse.Rooms[0].Players[0].Username); JoinRoomRequest joinRequest = new JoinRoomRequest() { RoomId = roomId, }; JoinRoomResponse joinResponse = client.JoinRoom(joinRequest); Assert.AreEqual(joinResponse.Status.IsSuccess, true); // View open rooms. OpenLobbiesResponse openLobbiesResponsAfterJoin = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponsAfterJoin.Status.IsSuccess, true); Assert.AreEqual(1, openLobbiesResponsAfterJoin.Rooms.Count); Assert.AreEqual(roomId, openLobbiesResponsAfterJoin.Rooms[0].Id); Assert.AreEqual(2, openLobbiesResponsAfterJoin.Rooms[0].Players.Count); LeaveRoomRequest leaveRequest = new LeaveRoomRequest() { RoomId = roomId }; LeaveRoomResponse leaveResponse = client.LeaveRoom(leaveRequest); Assert.AreEqual(leaveResponse.Status.IsSuccess, true); // Ensure that the player has left the game. // View open rooms. OpenLobbiesResponse openLobbiesResponsAfterLeave = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponsAfterLeave.Status.IsSuccess, true); Assert.AreEqual(1, openLobbiesResponsAfterLeave.Rooms.Count); Assert.AreEqual(roomId, openLobbiesResponsAfterLeave.Rooms[0].Id); Assert.AreEqual(1, openLobbiesResponsAfterLeave.Rooms[0].Players.Count); }
public void LeaveRoomRequest_Constructs_The_Correct_Message(string room) { var a = new LeaveRoomRequest(room); var msg = a.ToByteArray(); var reader = new MessageReader <MessageCode.Server>(msg); var code = reader.ReadCode(); Assert.Equal(MessageCode.Server.LeaveRoom, code); Assert.Equal(room, reader.ReadString()); }
public async ValueTask ExecuteAsync(LeaveRoomCommand command) { var request = new LeaveRoomRequest { SessionId = command.SessionId, Room = command.Room ?? string.Empty }; await m_MessageQueueService .RequestAsync("room.leave", request.ToByteArray()) .ConfigureAwait(false); }
private void BackBTN_Click(object sender, RoutedEventArgs e) { if (app.admin) { CloseRoomRequest closeRoomRequest = new CloseRoomRequest(); app.communicator.SocketSendReceive(JsonSerializer.serializeRequest(closeRoomRequest, Constants.CLOSE_ROOM_REQUEST)).ContinueWith(task => { ResponseInfo response = task.Result; CloseRoomResponse closeRoomResponse = JsonDeserializer.deserializeResponse <CloseRoomResponse>(response.buffer); switch (closeRoomResponse.status) { case Constants.CLOSE_ROOM_SUCCESS: thr.Abort(); MyMessageQueue.Enqueue("You leaved the room successfuly."); this.Dispatcher.Invoke(() => { NavigationService ns = NavigationService.GetNavigationService(this); ns.Navigate(new Uri("Menu.xaml", UriKind.Relative)); }); break; } }); } else { LeaveRoomRequest leaveRoomRequest = new LeaveRoomRequest(); app.communicator.SocketSendReceive(JsonSerializer.serializeRequest(leaveRoomRequest, Constants.LEAVE_ROOM_REQUEST)).ContinueWith(task => { ResponseInfo response = task.Result; LeaveRoomResponse leaveRoomResponse = JsonDeserializer.deserializeResponse <LeaveRoomResponse>(response.buffer); switch (leaveRoomResponse.status) { case Constants.LEAVE_ROOM_SUCCESS: thr.Abort(); MyMessageQueue.Enqueue("You left the room successfuly."); this.Dispatcher.Invoke(() => { NavigationService ns = NavigationService.GetNavigationService(this); ns.Navigate(new Uri("Menu.xaml", UriKind.Relative)); }); break; } }); } }
public HttpResponseMessage LeaveRoom(LeaveRoomRequest request) { var result = new LeaveRoomResult(); try { result = service.LeaveRoom(request); } catch (Exception e) { result.ErrorMessage = e.Message; result.Success = false; return(Request.CreateResponse(HttpStatusCode.InternalServerError, result)); } return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public HttpResponseMessage Leave([ModelBinder(typeof(JsonNetModelBinder))] LeaveRoomRequest request) { if (!Data.HasPlayer(request.PlayerId)) { var leaveRoomFailedResponse = new LeaveRoomResponse() { Result = false }; return(new JsonNetResponseMessage(leaveRoomFailedResponse)); } var player = Data.FindPlayer(request.PlayerId); if (player == null) { var leaveRoomFailedResponse = new LeaveRoomResponse() { Result = false }; return(new JsonNetResponseMessage(leaveRoomFailedResponse)); } var roomName = player.RoomName; Room room = null; if (!Data.Rooms.TryGetValue(roomName, out room)) { var leaveRoomFailedResponse = new LeaveRoomResponse() { Result = false }; return(new JsonNetResponseMessage(leaveRoomFailedResponse)); } room.Players.Remove(player); var response = new LeaveRoomResponse() { Result = true }; return(new JsonNetResponseMessage(response)); }
public void IfTheCreatorOfALobbyLeavesTheGameNoPlayersAreStuckInTheLobby() { var roomId = createRoom(); // Have a player join the game authHelper.loginToAccount("userTwo"); client.JoinRoom(new JoinRoomRequest() { RoomId = roomId, }); authHelper.loginToAccount("userOne"); // Have the host leave the lobby LeaveRoomRequest leaveRequest = new LeaveRoomRequest() { RoomId = roomId }; LeaveRoomResponse leaveResponse = client.LeaveRoom(leaveRequest); assertSuccessResponse(leaveResponse.Status); // Ensure that the player has left the game. // View open rooms. OpenLobbiesResponse openLobbiesResponsAfterLeave = client.GetOpenLobbies(new OpenLobbiesRequest()); assertSuccessResponse(openLobbiesResponsAfterLeave.Status); Assert.AreEqual(0, openLobbiesResponsAfterLeave.Rooms.Count); // Ensure the player is not in the game. PlayerCurrentGamesResponse gamesResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); assertSuccessResponse(gamesResponse.Status); Assert.AreEqual(0, gamesResponse.Games.Count); authHelper.loginToAccount("userTwo"); // Ensure the player is not in the game. PlayerCurrentGamesResponse gamesTwoResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); assertSuccessResponse(gamesTwoResponse.Status); Assert.AreEqual(0, gamesTwoResponse.Games.Count); }
void attemptToJoinGame(AvailGame ag) { waitingMessage = "User clicked " + ag.name; removeListeners(); inLobby = false; Debug.Log("User clicked " + ag.name); // save the info about the game to be joined GameObject sharedES = GameObject.Find("SharedES"); SharedElectroServer gm = (SharedElectroServer)sharedES.GetComponent<SharedElectroServer>(); gm.gameToJoin = ag; // leave the Lobby room, but don't wait for the event about it LeaveRoomRequest lrr = new LeaveRoomRequest(); lrr.ZoneId = room.ZoneId; lrr.RoomId = room.Id; _es.Engine.Send(lrr); room = null; // Start Coroutine to jump to game scene StartCoroutine(PollGameLevelLoaded()); // Execute level load Application.LoadLevel("game"); }
void returnToLobby() { waitingMessage = "Returning to Lobby"; errorMessage = ""; showReturnToLobbyButton = false; inGame = false; Debug.Log("Returning to Lobby"); _es.Engine.JoinRoomEvent -= OnJoinRoom; _es.Engine.CreateOrJoinGameResponse -= OnCreateOrJoinGameResponse; /** * If you want to add chat in the game, you will need this line */ //_es.Engine.PublicMessageEvent -= OnPublicMessage; _es.Engine.ConnectionClosedEvent -= OnConnectionClosedEvent; _es.Engine.GenericErrorResponse -= onGenericErrorResponse; _es.Engine.PluginMessageEvent -= onPluginMessageEvent; if (null != room) { LeaveRoomRequest lrr = new LeaveRoomRequest(); lrr.RoomId = room.Id; lrr.ZoneId = room.ZoneId; _es.Engine.Send(lrr); room = null; } // Start Coroutine to jump to game scene StartCoroutine(PollGameLevelLoaded()); // Execute level load Application.LoadLevel("lobby"); }
public void LeaveRoomRequest_Instantiates_Properly(string room) { var a = new LeaveRoomRequest(room); Assert.Equal(room, a.RoomName); }
public LeaveRoomResponse LeaveRoom(LeaveRoomRequest request) { LeaveRoomResponse response = new LeaveRoomResponse(); rwLock.EnterWriteLock(); try { IPoLServerCallback channel = OperationContext.Current.GetCallbackChannel<IPoLServerCallback>(); var ply = gameLobby.GetPlayerByChannel(channel); var room = gameLobby.Rooms.Values.FirstOrDefault(r => r.Players.Contains(ply)); response.Success = room != null; if(response.Success) { room.Players.Remove(ply); } } finally { rwLock.ExitWriteLock(); } return response; }
public void PlayerCanLeaveAGameRoom() { CreateRoomRequest createRequest = new CreateRoomRequest() { Anonymous = false, Goal = Goal.Domination, MaxPlayers = 5, IsRanked = false, RoomName = "My Room!", AllowedSpecialists = { "a", "b", "c" }, }; CreateRoomResponse roomResponse = client.CreateNewRoom(createRequest); Assert.AreEqual(roomResponse.Status.IsSuccess, true); Assert.IsTrue(roomResponse.CreatedRoom.RoomId != null); var roomId = roomResponse.CreatedRoom.RoomId; authHelper.loginToAccount("userTwo"); // View open rooms. OpenLobbiesResponse openLobbiesResponse = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponse.Status.IsSuccess, true); Assert.AreEqual(1, openLobbiesResponse.Rooms.Count); Assert.AreEqual(roomId, openLobbiesResponse.Rooms[0].RoomId); // Ensure the creator is a member of the game Assert.AreEqual(1, openLobbiesResponse.Rooms[0].Players.Count); Assert.AreEqual("userOne", openLobbiesResponse.Rooms[0].Players[0].Username); JoinRoomRequest joinRequest = new JoinRoomRequest() { RoomId = roomId, }; JoinRoomResponse joinResponse = client.JoinRoom(joinRequest); Assert.AreEqual(joinResponse.Status.IsSuccess, true); // View open rooms. OpenLobbiesResponse openLobbiesResponsAfterJoin = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponsAfterJoin.Status.IsSuccess, true); Assert.AreEqual(1, openLobbiesResponsAfterJoin.Rooms.Count); Assert.AreEqual(roomId, openLobbiesResponsAfterJoin.Rooms[0].RoomId); Assert.AreEqual(2, openLobbiesResponsAfterJoin.Rooms[0].Players.Count); LeaveRoomRequest leaveRequest = new LeaveRoomRequest() { RoomId = roomId }; LeaveRoomResponse leaveResponse = client.LeaveRoom(leaveRequest); Assert.AreEqual(leaveResponse.Status.IsSuccess, true); // Ensure that the player has left the game. // View open rooms. OpenLobbiesResponse openLobbiesResponsAfterLeave = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponsAfterLeave.Status.IsSuccess, true); Assert.AreEqual(1, openLobbiesResponsAfterLeave.Rooms.Count); Assert.AreEqual(roomId, openLobbiesResponsAfterLeave.Rooms[0].RoomId); Assert.AreEqual(1, openLobbiesResponsAfterLeave.Rooms[0].Players.Count); }
public void LeaveRoom() { try { _sm.Session.RemoveHandler(typeof(MessageErrorPacket), new Session.PacketReceivedDelegate(IncomingMessage)); _sm.Session.RemoveHandler(typeof(GroupChatMessage), new Session.PacketReceivedDelegate(IncomingMessage)); _sm.Session.RemoveHandler(typeof(ChangeSubjectMessage), new Session.PacketReceivedDelegate(IncomingMessage)); _sm.Session.RemoveHandler(typeof(AvailableRequest), new Session.PacketReceivedDelegate(IncomingPresence)); _sm.Session.RemoveHandler(typeof(ErrorResponse), new Session.PacketReceivedDelegate(IncomingPresence)); _sm.Session.RemoveHandler(typeof(OccupantAvailableResponse), new Session.PacketReceivedDelegate(IncomingPresence)); _sm.Session.RemoveHandler(typeof(OccupantUnavailableResponse), new Session.PacketReceivedDelegate(IncomingPresence)); LeaveRoomRequest l = new LeaveRoomRequest(_occupant); _sm.SendAndForget(l); if (this.LeftRoom != null) this.LeftRoom(this, new EventArgs()); } catch{} }