public void PlayerCanStartAGameEarlyIfTwoPlayersAreInTheLobby() { CreateRoomResponse roomResponse = authHelper.CreateGameRoom("room1"); var roomId = roomResponse.CreatedRoom.RoomId; authHelper.loginToAccount("userTwo"); JoinRoomResponse joinResponse = client.JoinRoom(new JoinRoomRequest() { RoomId = roomId, }); Assert.AreEqual(joinResponse.Status.IsSuccess, true); authHelper.loginToAccount("userOne"); StartGameEarlyResponse startGameEarlyResponse = client.StartGameEarly(new StartGameEarlyRequest() { RoomId = roomId, }); Assert.AreEqual(startGameEarlyResponse.Status.IsSuccess, true); // Ensure game cannot be seen in open lobbies. // View open rooms. OpenLobbiesResponse openLobbiesResponse = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponse.Status.IsSuccess, true); Assert.AreEqual(0, openLobbiesResponse.Rooms.Count); }
public void BeingTheLastPlayerToJoinAGameWillStartTheGame() { CreateRoomResponse roomResponse = client.CreateNewRoom(createRoomRequest("My room!", maxPlayers: 2)); Assert.AreEqual(roomResponse.Status.IsSuccess, true); Assert.IsTrue(roomResponse.CreatedRoom.Id != null); var roomId = roomResponse.CreatedRoom.Id; authHelper.loginToAccount("userTwo"); JoinRoomRequest joinRequest = new JoinRoomRequest() { RoomId = roomId, }; JoinRoomResponse joinResponse = client.JoinRoom(joinRequest); Assert.AreEqual(joinResponse.Status.IsSuccess, true); // Check to see the room is not visible. OpenLobbiesResponse openLobbiesResponseAfterJoin = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponseAfterJoin.Status.IsSuccess, true); Assert.AreEqual(0, openLobbiesResponseAfterJoin.Rooms.Count); // Check to see the player can see the game because they are a member. PlayerCurrentGamesResponse playerGamesResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); Assert.AreEqual(playerGamesResponse.Status.IsSuccess, true); Assert.AreEqual(1, playerGamesResponse.Games.Count); }
public CreateRoomResponse CreateRoom(CreateRoomRequest request) { CreateRoomResponse response = new CreateRoomResponse(); Room room = new Room(); room.RoomName = request.RoomName; room.Address = request.Address; room.PhoneNumber = request.PhoneNumber; room.Users = request.Users.ConvertToUsers(); if (room.GetBrokenRules().Count() > 0) { response.Errors = room.GetBrokenRules().ToList(); } else { try { _roomRepository.Add(room); _uow.Commit(); response.Errors = new List <BusinessRule>(); } catch (Exception ex) { List <BusinessRule> errors = new List <BusinessRule>(); do { errors.Add(new BusinessRule("DAL", "DAL_ERROR: " + ex.Message)); ex = ex.InnerException; } while (ex != null); response.Errors = errors; } } return(response); }
public void PlayerCannotJoinAGameThatHasAlreadyStarted() { CreateRoomRequest createRequest = new CreateRoomRequest() { Anonymous = false, Goal = Goal.Domination, MaxPlayers = 2, 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"); JoinRoomRequest joinRequest = new JoinRoomRequest() { RoomId = roomId, }; JoinRoomResponse joinResponse = client.JoinRoom(joinRequest); Assert.AreEqual(joinResponse.Status.IsSuccess, true); authHelper.loginToAccount("userThree"); var exception = client.JoinRoom(joinRequest); Assert.AreEqual(exception.Status.IsSuccess, false); Assert.AreEqual(exception.Status.Detail, ResponseType.ROOM_IS_FULL.ToString()); }
public void CreateRoomClick() { ShowMessagePanel("正在创建房间..."); //创建房间 Debug.Log("create room click"); ResponseHandle createRoom = delegate(string jsonString){ Debug.Log("CreateRoomResponse: " + jsonString); HideMessagePanel(); //加入玩家已经游戏了,那么跳转到Gameplay Scene。否则什么都不需要坐。 CreateRoomResponse resp = JsonConvert.DeserializeObject <CreateRoomResponse>(jsonString); Dictionary <string, string> parameters = new Dictionary <string, string>(); if (resp.status == 0) { parameters["roomNo"] = resp.roomNo; parameters["serverUrl"] = resp.serverUrl; Scenes.Load("Gameplay", parameters); } }; Debug.Log("createRoomUrl: " + ServerUtils.GetCreateRoomUrl()); var req = new { userId = Player.Me.userId, jushu = int.Parse(GetGameProperty("gameproperty_jushu")), fangfei = GetGameProperty("gameproperty_fangfei"), fengshu = GetGameProperty("gameproperty_fs"), qz = GetGameProperty("gameproperty_qz"), wanfa = GetGameProperty("gameproperty_wanfa"), clientInfo = Utils.GetClientInfo(), userInfo = Utils.GetUserInfo() }; StartCoroutine(PostRequest(ServerUtils.GetCreateRoomUrl(), JsonConvert.SerializeObject(req), createRoom)); }
public void PlayerWhoCreatesALobbyIsAMemberOfThatLobby() { var roomName = "My Room!"; var anon = false; var isRanked = false; var goal = Goal.Domination; CreateRoomRequest createRequest = new CreateRoomRequest() { Anonymous = anon, Goal = goal, MaxPlayers = 5, IsRanked = isRanked, RoomName = roomName, AllowedSpecialists = { "a", "b", "c" }, }; CreateRoomResponse roomResponse = client.CreateNewRoom(createRequest); Assert.AreEqual(roomResponse.Status.IsSuccess, true); var roomId = roomResponse.CreatedRoom.RoomId; // 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); Assert.AreEqual(authHelper.getAccountId("userOne"), openLobbiesResponse.Rooms[0].Creator.Id); Assert.AreEqual("userOne", openLobbiesResponse.Rooms[0].Creator.Username); Assert.AreEqual(1, openLobbiesResponse.Rooms[0].Players.Count); Assert.AreEqual("userOne", openLobbiesResponse.Rooms[0].Players[0].Username); }
void CreateRes(CreateRoomResponse createRoomResponse) { int roomId = createRoomResponse.RoomId; Debug.Log("createRoom OK:" + roomId); GoRoomScene(roomId); }
private string createRoom(int maxPlayers = 5) { CreateRoomResponse roomResponse = client.CreateNewRoom(createRoomRequest("My room!", maxPlayers: maxPlayers)); Assert.AreEqual(roomResponse.Status.IsSuccess, true); Assert.IsTrue(roomResponse.CreatedRoom.Id != null); return(roomResponse.CreatedRoom.Id); }
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 AdminsCanViewAnyOngoingGameTheyAreNotIn() { CreateRoomRequest createRequest = new CreateRoomRequest() { Anonymous = false, Goal = Goal.Domination, MaxPlayers = 2, 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"); JoinRoomRequest joinRequest = new JoinRoomRequest() { RoomId = roomId, }; JoinRoomResponse joinResponse = client.JoinRoom(joinRequest); Assert.AreEqual(joinResponse.Status.IsSuccess, true); // Check to see the room is not visible. OpenLobbiesResponse openLobbiesResponseAfterJoin = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponseAfterJoin.Status.IsSuccess, true); Assert.AreEqual(0, openLobbiesResponseAfterJoin.Rooms.Count); // Check to see the player can see the game because they are a member. PlayerCurrentGamesResponse playerGamesResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); Assert.AreEqual(playerGamesResponse.Status.IsSuccess, true); Assert.AreEqual(1, playerGamesResponse.Games.Count); SuperUser superUser = authHelper.CreateSuperUser(); client.Login(new AuthorizationRequest() { Password = superUser.password, Username = superUser.userModel.UserModel.Username, }); PlayerCurrentGamesResponse adminGamesResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); Assert.AreEqual(adminGamesResponse.Status.IsSuccess, true); Assert.AreEqual(1, adminGamesResponse.Games.Count); }
public JsonResult Create(RoomDetailView vm) { CreateRoomRequest request = new CreateRoomRequest(); request.RoomName = vm.RoomName; request.Address = vm.Address; request.PhoneNumber = vm.PhoneNumber; CreateRoomResponse response = _roomService.CreateRoom(request); return(Json(response)); }
public static CreateRoomResponse Unmarshall(UnmarshallerContext context) { CreateRoomResponse createRoomResponse = new CreateRoomResponse(); createRoomResponse.HttpResponse = context.HttpResponse; createRoomResponse.RequestId = context.StringValue("CreateRoom.RequestId"); createRoomResponse.AppId = context.StringValue("CreateRoom.AppId"); createRoomResponse.RoomId = context.StringValue("CreateRoom.RoomId"); createRoomResponse.AnchorId = context.StringValue("CreateRoom.AnchorId"); return(createRoomResponse); }
public override async Task <ActionResult <CreateRoomResponse> > HandleAsync(CreateRoomRequest request, CancellationToken cancellationToken) { var response = new CreateRoomResponse(request.CorrelationId); var toAdd = _mapper.Map <Room>(request); toAdd = await _repository.AddAsync(toAdd); var dto = _mapper.Map <RoomDto>(toAdd); response.Room = dto; return(Ok(response)); }
public void PlayerCanJoinAGameRoom() { 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); OpenLobbiesResponse openLobbiesResponseAfterJoin = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponseAfterJoin.Status.IsSuccess, true); Assert.AreEqual(1, openLobbiesResponseAfterJoin.Rooms.Count); Assert.AreEqual(roomId, openLobbiesResponseAfterJoin.Rooms[0].RoomId); Assert.AreEqual(2, openLobbiesResponseAfterJoin.Rooms[0].Players.Count); Assert.IsTrue(openLobbiesResponseAfterJoin.Rooms[0].Players.Any(it => it.Id == authHelper.getAccountId("userTwo"))); }
public void PlayersWhoRegisterWithTheSameDeviceIdCannotJoinTheSameGame() { string one = "DeviceOne"; string two = "DeviceTwo"; client.RegisterAccount(new AccountRegistrationRequest() { Username = one, Password = one, Email = one, DeviceIdentifier = one, }); client.RegisterAccount(new AccountRegistrationRequest() { Username = two, Password = two, Email = two, DeviceIdentifier = one, }); CreateRoomResponse createResponse = client.CreateNewRoom(new CreateRoomRequest() { RoomName = "Room", MaxPlayers = 4, Goal = Goal.Domination, }); Assert.AreEqual(createResponse.Status.IsSuccess, true); var roomId = createResponse.CreatedRoom.RoomId; client.Login(new AuthorizationRequest() { Username = one, Password = one, }); var exception = client.JoinRoom(new JoinRoomRequest() { RoomId = roomId }); Assert.AreEqual(exception.Status.IsSuccess, false); Assert.AreEqual(exception.Status.Detail, ResponseType.PERMISSION_DENIED.ToString()); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { CreateRoomResponse response = new CreateRoomResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("RoomArn", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.RoomArn = unmarshaller.Unmarshall(context); continue; } } return(response); }
public void PlayerCannotStartAGameEarlyWithNobodyInTheLobby() { CreateRoomResponse roomResponse = authHelper.CreateGameRoom("room1"); var roomId = roomResponse.CreatedRoom.RoomId; StartGameEarlyResponse startGameEarlyResponse = client.StartGameEarly(new StartGameEarlyRequest() { RoomId = roomId, }); Assert.AreEqual(startGameEarlyResponse.Status.IsSuccess, false); // Ensure game is still open // View open rooms. OpenLobbiesResponse openLobbiesResponse = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponse.Status.IsSuccess, true); Assert.AreEqual(1, openLobbiesResponse.Rooms.Count); }
public async Task <ActionResult> CreateRoom() { //Request.Body.Position = 0; var input = await Request.GetRawBodyBytesAsync(); var request = _serializer.DeserializeAs <CreateRoomRequest>(input); CreateRoomResponse response = new CreateRoomResponse(); try { response.RoomId = _gameServerApi.CreateRoom(request.Properties, request.Players, request.RoomId); } catch (Exception ex) { _logger.Error($"Create room error: {ex}"); response.ResultCode = ResultCode.RequestProcessingError; } return(new FileContentResult(_serializer.Serialize(response), "text/html")); }
public void BeingTheLastPlayerToJoinAGameWillStartTheGame() { CreateRoomRequest createRequest = new CreateRoomRequest() { Anonymous = false, Goal = Goal.Domination, MaxPlayers = 2, 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"); JoinRoomRequest joinRequest = new JoinRoomRequest() { RoomId = roomId, }; JoinRoomResponse joinResponse = client.JoinRoom(joinRequest); Assert.AreEqual(joinResponse.Status.IsSuccess, true); // Check to see the room is not visible. OpenLobbiesResponse openLobbiesResponseAfterJoin = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponseAfterJoin.Status.IsSuccess, true); Assert.AreEqual(0, openLobbiesResponseAfterJoin.Rooms.Count); // Check to see the player can see the game because they are a member. PlayerCurrentGamesResponse playerGamesResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); Assert.AreEqual(playerGamesResponse.Status.IsSuccess, true); Assert.AreEqual(1, playerGamesResponse.Games.Count); }
public async Task <ActionResult <CreateRoomResponse> > CreateRoom(CreateRoomRequest request) { var user = new User { Username = request.Username }; await _unitOfWork.UserRepository.AddAsync(user); await _unitOfWork.CommitAsync(); var room = new Room { Description = request.RoomDescription, CreatorId = user.Id }; await _unitOfWork.RoomRepository.CreateAsync(room); await _unitOfWork.CommitAsync(); user.RoomId = room.Id; _unitOfWork.UserRepository.Update(user); await _unitOfWork.CommitAsync(); var token = user.GenerateToken( key: _config["Jwt:Key"], issuer: _config["Jwt:Issuer"], audience: _config["Jwt:Audience"] ); var roomDto = _mapper.Map <RoomDto>(room); var response = new CreateRoomResponse { Room = roomDto, Token = token }; return(CreatedAtRoute(nameof(GetRoomById), new { Id = room.Id }, response)); }
public void PlayerCanCreateAGameRoom() { var roomName = "My Room!"; var anon = false; var isRanked = false; var goal = Goal.Domination; CreateRoomRequest createRequest = new CreateRoomRequest() { Anonymous = anon, Goal = goal, MaxPlayers = 5, IsRanked = isRanked, RoomName = roomName, 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; // 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); Assert.AreEqual(authHelper.getAccountId("userOne"), openLobbiesResponse.Rooms[0].Creator.Id); Assert.AreEqual("userOne", openLobbiesResponse.Rooms[0].Creator.Username); Assert.AreEqual(roomName, openLobbiesResponse.Rooms[0].RoomName); Assert.AreEqual(RoomStatus.Open, openLobbiesResponse.Rooms[0].RoomStatus); // Assert.AreEqual(isRanked,roomDataResponse.Rooms[0].RankedInformation.IsRanked); Assert.AreEqual(anon, openLobbiesResponse.Rooms[0].Anonymous); Assert.AreEqual(goal, openLobbiesResponse.Rooms[0].Goal); Assert.AreEqual(1, openLobbiesResponse.Rooms[0].Players.Count); Assert.AreEqual("userOne", openLobbiesResponse.Rooms[0].Players[0].Username); }
public void PlayerCannotJoinAGameThatHasAlreadyStarted() { CreateRoomResponse roomResponse = client.CreateNewRoom(createRoomRequest("My room!", maxPlayers: 2)); Assert.AreEqual(roomResponse.Status.IsSuccess, true); Assert.IsTrue(roomResponse.CreatedRoom.Id != null); var roomId = roomResponse.CreatedRoom.Id; authHelper.loginToAccount("userTwo"); JoinRoomRequest joinRequest = new JoinRoomRequest() { RoomId = roomId, }; JoinRoomResponse joinResponse = client.JoinRoom(joinRequest); assertSuccessResponse(joinResponse.Status); authHelper.loginToAccount("userThree"); var exception = client.JoinRoom(joinRequest); assertResponseFailure(exception.Status, ResponseType.ROOM_IS_FULL); }
public void PlayerCannotJoinTheSameGameTwice() { 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"); JoinRoomRequest joinRequest = new JoinRoomRequest() { RoomId = roomId, }; JoinRoomResponse joinResponse = client.JoinRoom(joinRequest); Assert.AreEqual(joinResponse.Status.IsSuccess, true); var exception = client.JoinRoom(joinRequest); Assert.AreEqual(exception.Status.IsSuccess, false); Assert.AreEqual(exception.Status.Detail, ResponseType.DUPLICATE.ToString()); }
private static void GotMessage(object state) { NetIncomingMessage incomingMessage; while ((incomingMessage = Client.ReadMessage()) != null) { // handle incoming message switch (incomingMessage.MessageType) { case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.ErrorMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.VerboseDebugMessage: var text = incomingMessage.ReadString(); Console.WriteLine($"{incomingMessage.MessageType}: {text}"); break; case NetIncomingMessageType.StatusChanged: var status = (NetConnectionStatus)incomingMessage.ReadByte(); var reason = incomingMessage.ReadString(); Console.WriteLine($"{status}, Reason: {reason}"); switch (status) { case NetConnectionStatus.Connected: Connected?.Invoke(null, EventArgs.Empty); break; case NetConnectionStatus.Disconnected: Disconnected?.Invoke(null, EventArgs.Empty); break; } break; case NetIncomingMessageType.Data: var messageType = (PacketType)incomingMessage.ReadInt16(); switch (messageType) { case PacketType.SPacketJoinRoom: JoinRoomResponse?.Invoke(null, incomingMessage.ReadStruct <SPacketJoinRoom>()); break; case PacketType.SPacketCreateRoom: CreateRoomResponse?.Invoke(null, incomingMessage.ReadStruct <SPacketCreateRoom>()); break; case PacketType.SPacketSyncRoom: { var packet = incomingMessage.ReadClass <SPacketSyncRoom>(); if (Room == null || Room.Id != packet.RoomId) { Room = new Room(packet.RoomId); } Player = packet.Players[packet.YourPlayer]; Room.Players.Clear(); Room.Players.AddRange(packet.Players); Room.Board.Clear(); Room.Board.AddRange(packet.Board); if (Room.CurrentPlayer != Player.Id && packet.CurrentPlayer == Player.Id) { TurnStarted?.Invoke(null, EventArgs.Empty); } Room.CurrentPlayer = packet.CurrentPlayer; SyncRoom?.Invoke(null, packet); break; } case PacketType.SPacketFloatingPiece: FloatingPiece?.Invoke(null, incomingMessage.ReadStruct <SPacketFloatingPiece>()); break; } break; default: Console.WriteLine($"Unhandled type: {incomingMessage.MessageType} {incomingMessage.LengthBytes} bytes"); break; } Client.FlushSendQueue(); Client.Recycle(incomingMessage); } }