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

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

            if (game.status != statusIgre.cekanjeIgracaPause && (game.crveniIgracId != korisnik.ID && game.zeleniIgracId != korisnik.ID && game.zutiIgracId != korisnik.ID && game.plaviIgracId != korisnik.ID))
            {
                return(Forbid());
            }
            Boja bojaKorisnika = Boja.crveni;

            foreach (Boja b in Enum.GetValues(typeof(Boja)))
            {
                if ((int)game.GetType().GetProperty(b.ToString() + "IgracId").GetValue(game) == korisnik.ID)
                {
                    bojaKorisnika = b;
                }
            }
            if (korisnik.ID == game.kreatorIgre.ID)
            {
                return(Ok(new { naPotezu = game.naPotezu.ToString(), boja = bojaKorisnika.ToString(), accessCode = game.accessCode, figure = game.figure, token = JWTGenerator.GenerateGameToken(korisnik, game, bojaKorisnika), username = korisnik.username, slika = korisnik.slika, igraciImena = game.vratiIgrace(), igraciSlike = await GameProvider.slikeIgraca(db, game) }));
            }
            else
            {
                return(Ok(new { naPotezu = game.naPotezu.ToString(), boja = bojaKorisnika.ToString(), figure = game.figure, token = JWTGenerator.GenerateGameToken(korisnik, game, bojaKorisnika), username = korisnik.username, slika = korisnik.slika, igraciImena = game.vratiIgrace(), igraciSlike = await GameProvider.slikeIgraca(db, game) }));
            }
        }
Ejemplo n.º 2
0
        public bool slobodnaBoja(Boja boja)
        {
            string username = (string)this.GetType().GetProperty(boja.ToString() + "Username").GetValue(this);
            int    id       = (int)this.GetType().GetProperty(boja.ToString() + "IgracId").GetValue(this);

            if (username == null && id == 0)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public static async Task <Igra> NadjiJavnuIgru(DontGetSpicyContext db, Boja boja, IConfiguration config)
        {
            Igra igraRet;

            SqlConnection conn           = new SqlConnection(config.GetConnectionString("DontGetSpicyCS"));
            string        availableQuery = $"select top 1 id from Igra where {boja.ToString()}Username is NULL and {boja.ToString()}IgracId=0 and privateGame=0 and Status=2";
            SqlCommand    command        = new SqlCommand(availableQuery, conn);
            SqlDataReader dataReader;

            conn.Open();
            dataReader = await command.ExecuteReaderAsync();

            dataReader.Read();
            if (dataReader.HasRows)
            {
                int id = dataReader.GetInt32(0);
                igraRet = db.Igre.Find(id);
            }
            else
            {
                igraRet = null;
            }
            command.Dispose();
            conn.Close();
            return(igraRet);
        }
Ejemplo n.º 4
0
        public static async Task <bool> slobodnaBoja(IConfiguration config, Boja boja, Igra igra)
        {
            SqlConnection conn           = new SqlConnection(config.GetConnectionString("DontGetSpicyCS"));
            string        availableQuery = $"select ISNULL(Igra.{boja.ToString()}Username,-1),ISNULL(Igra.{boja.ToString()}IgracId,-1)  from Igra where Igra.ID={igra.ID}";
            SqlCommand    command        = new SqlCommand(availableQuery, conn);
            SqlDataReader dataReader;

            conn.Open();
            dataReader = await command.ExecuteReaderAsync();

            dataReader.Read();
            string bool1 = dataReader.GetString(0); //-1
            int    bool2 = dataReader.GetInt32(1);  //0

            command.Dispose();
            conn.Close();

            if (bool1.CompareTo("-1") == 0 && bool2 == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 5
0
 public static async Task dodajIgraca(DontGetSpicyContext db, IConfiguration config, Korisnik pridruzi, Boja boja, Igra igra)
 {
     SqlConnection conn = new SqlConnection(config.GetConnectionString("DontGetSpicyCS"));
     string        updateQuery = $"UPDATE Igra SET {boja.ToString()}Username='******',{boja.ToString()}IgracId={pridruzi.ID} WHERE Igra.ID={igra.ID}";
     SqlCommand    command = new SqlCommand(updateQuery, conn); SqlDataAdapter dataAdapter = new SqlDataAdapter(); conn.Open(); dataAdapter.UpdateCommand = new SqlCommand(updateQuery, conn);
     await dataAdapter.UpdateCommand.ExecuteNonQueryAsync();  command.Dispose(); conn.Close();
 }
Ejemplo n.º 6
0
      public static string GenerateGameToken(Korisnik korisnik, Igra igra, Boja boja)
      {
          Claim[] claims = new Claim[] {
              new Claim(JwtRegisteredClaimNames.Email, korisnik.email),
              new Claim(JwtRegisteredClaimNames.Sub, igra.groupNameGUID),
              new Claim("Boja", boja.ToString())
              //new Claim("kreatorIgre?",(igra.kreatorIgre.ID==korisnik.ID).ToString(), ClaimValueTypes.Boolean/*na klijentu se ocitava kao bool*/)
          };

          return(GenerateToken(claims));
      }
Ejemplo n.º 7
0
 public void dodajIgraca(Boja boja, Korisnik dodaj)
 {
     this.GetType().GetProperty(boja.ToString() + "IgracId").SetValue(this, dodaj.ID);
     this.GetType().GetProperty(boja.ToString() + "Username").SetValue(this, dodaj.username);
 }