Exemplo n.º 1
0
        public async Task <IActionResult> ResumeRequest(string id)
        {
            string   email    = User.FindFirstValue("email");
            Korisnik korisnik = await KorisnikProvider.GetKorisnik(db, email);

            Igra game = await GameProvider.NadjiIgru(db, id);

            if (game.kreatorIgre.ID != korisnik.ID)
            {
                return(BadRequest());
            }
            if (game.status != statusIgre.pauzirana)
            {
                return(Forbid());
            }
            game.status = statusIgre.cekanjeIgracaPause;
            await GameProvider.AzurirajIgru(db, game);

            return(await this.RejoinGame(id));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PridruziSeIgri(Boja boja, string accessCode)
        {
            string   email    = User.FindFirstValue("email");
            Korisnik korisnik = await KorisnikProvider.GetKorisnik(db, email);

            if (korisnik == null)
            {
                return(BadRequest());
            }
            Igra joinGame = await GameProvider.NadjiIgru(db, accessCode);

            if (joinGame == null)
            {
                return(NotFound());
            }
            if (joinGame.status != statusIgre.cekanjeIgraca)
            {
                return(BadRequest());
            }

            if (joinGame.slobodnaBoja(boja))
            {
                joinGame.dodajIgraca(boja, korisnik);
                if (joinGame.sviPrisutni())
                {
                    joinGame.status = statusIgre.uToku;
                }
                await GameProvider.AzurirajIgru(db, joinGame);

                return(Ok(new { token = JWTGenerator.GenerateGameToken(korisnik, joinGame, boja), username = korisnik.username, slika = korisnik.slika, igraciImena = joinGame.vratiIgrace(), igraciSlike = await GameProvider.slikeIgraca(db, joinGame) }));
            }
            else
            {
                return new ObjectResult(joinGame.zauzeteBoje())
                       {
                           StatusCode = 403
                       }
            };
        }
Exemplo n.º 3
0
        public async Task <IActionResult> NovaIgra(Boja boja, bool privateGame)
        {
            string   email    = User.FindFirstValue("email");
            Korisnik korisnik = await KorisnikProvider.GetKorisnik(db, email);

            if (korisnik == null)
            {
                return(BadRequest());
            }
            Igra novaIgra = new Igra(korisnik);

            novaIgra.privateGame = privateGame;
            await GameProvider.dodajIgru(db, novaIgra);

            IActionResult res = (await this.PridruziSeIgri(boja, novaIgra.accessCode));

            if (res is OkObjectResult)
            {
                OkObjectResult result = (OkObjectResult)res;
                dynamic        val    = result.Value;
                return(Ok(new { token = val.token, accessCode = novaIgra.accessCode, username = korisnik.username, slika = korisnik.slika }));
            }
            return(BadRequest());
        }
Exemplo n.º 4
0
        public async Task SendMessage(string message)
        {
            Korisnik korisnik = await KorisnikProvider.GetKorisnik(db, Context.User.FindFirstValue("email"));

            await Clients.GroupExcept(Context.User.FindFirstValue("sub"), Context.ConnectionId).SendAsync("userSentMessage", message, korisnik.username);
        }