Exemplo n.º 1
0
        public IActionResult CreateLobby([FromServices] GameServerService gameServer, string id = "", string playerName = "")
        {
            ViewData["playerName"] = playerName;
            ViewData["lobbyId"]    = id;

            string errorMessage = IsValid(id, playerName);

            if (!errorMessage.Equals(string.Empty))
            {
                ViewData["ErrorMessage"] = errorMessage;
                return(View());
            }

            bool success = gameServer.TryCreateLobby(id, playerName, gameServer);

            if (success)
            {
                SetCookie("PlayerName", playerName);
                SetCookie("LobbyId", id);
                ViewData["IsHost"] = true;
                return(View("Views/Lobby/Index.cshtml"));
            }

            ViewData["ErrorMessage"] = $"Lobby with {id} already exists. Please enter different name";
            //return View("Views/Lobby/CreateLobby.cshtml");
            return(View());
        }