<?php

require_once 'services.php';
include_once 'config.php';
$res = array();
$azione = "Azione";
// SFIDA GIOCATORE
if (isset($_POST['usernameSfidato']) && isset($_POST['usernameSfidante']) && isset($_POST['numeroSfidante'])) {
    $azione = "Sfida";
    $usernameSfidato = htmlspecialchars($_POST['usernameSfidato']);
    $usernameSfidante = htmlspecialchars($_POST['usernameSfidante']);
    $numeroSfidante = htmlspecialchars($_POST['numeroSfidante']);
    $service = new Services();
    $res = $service->newMatch($usernameSfidato, $usernameSfidante, $numeroSfidante);
}
// ACCETTO SFIDA RICEVUTA
if (isset($_POST['accetta'])) {
    $azione = "Sfida";
    $username = htmlspecialchars($_POST['accetta']);
    $service = new Services();
    $res = $service->acceptMatch($username);
}
// CARICA NUMERO
if (isset($_POST['numeroscelto']) && isset($_POST['tipogiocatore']) && isset($_POST['userSfidante']) && isset($_POST['userSfidato'])) {
    $azione = 'Caricamento';
    $num = htmlspecialchars($_POST['numeroscelto']);
    $tipogiocatore = htmlspecialchars($_POST['tipogiocatore']);
    $usernameSfidante = htmlspecialchars($_POST['userSfidante']);
    $usernameSfidato = htmlspecialchars($_POST['userSfidato']);
    $Services = new Services();
    $res = $Services->setNumber($num, $tipogiocatore, $usernameSfidante, $usernameSfidato);