Пример #1
0
 public IActionResult Create(EditLobbyViewModel lobby)
 {
     try
     {
         _service.CreateLobby(currentUserId, lobby.Name, lobby.Private);
     }
     catch (ArgumentOutOfRangeException ex1)
     {
         return(NotFound(ex1));
     }
     return(RedirectToAction("Index"));
 }
Пример #2
0
 public IActionResult CreateLobby([FromBody] LobbyCreationDto newLobby)
 {
     try
     {
         if (ModelState.IsValid)
         {
             try
             {
                 var userId      = _authorizationService.GetUserId(User);
                 var lobbyResult = _lobbyService.CreateLobby(newLobby, userId);
                 if (lobbyResult != null)
                 {
                     return(CreatedAtRoute("GetLobby", new { id = lobbyResult.Id }, lobbyResult));
                 }
             }
             catch
             { }
             return(Unauthorized());
         }
         return(BadRequest());
     }
     catch
     {
         return(Unauthorized());
     }
 }
Пример #3
0
        public Lobby Post([FromBody] Lobby lobby)
        {
            if (lobby != null)
            {
                return(lobbyService.CreateLobby(lobby));
            }

            else
            {
                return(null);
            }
        }
Пример #4
0
        public async Task CreateLobby(Lobby lobby)
        {
            if (lobby != null)
            {
                lobbyService.CreateLobby(lobby);
            }

            Groups.AddToGroupAsync(Context.ConnectionId, lobby.Id.ToString());
            await Clients.Groups(lobby.Id.ToString()).LobbyCreated(lobby);

            await Clients.Group(lobby.Id.ToString()).AddedToGroup(lobby.Id.ToString());
        }
Пример #5
0
        public void AddLobby(string name, string pass)
        {
            GameLobby        newLobby;
            PlayerModel      creator;
            List <GameLobby> lobbies;

            creator  = userService.GetByConnectionId(Context.ConnectionId);
            newLobby = new GameLobby {
                LobbyName = name, Password = pass, Creator = creator.CurrentConnectionId
            };
            newLobby.CreatorElo = creator.Elo;
            lobbyService.CreateLobby(newLobby);
            lobbies = lobbyService.GetAllLobbies().OrderByDescending(x => x.CreatorElo).ToList();
            Clients.All.getLobbies(lobbies);
        }
Пример #6
0
        public async Task CreateLobby(string lobbyName)
        {
            var joinedLobby = _lobbyService.GetJoinedLobby(Context.ConnectionId);

            if (joinedLobby != null)
            {
                throw new HubException("You can't create a lobby while you're in a lobby");
            }

            if (_lobbyService.GetLobby(lobbyName) != null)
            {
                throw new HubException($"Lobby with the name '{lobbyName}' already exists");
            }

            _lobbyService.CreateLobby(lobbyName, Context.ConnectionId);
            await JoinLobby(lobbyName);
        }