Beispiel #1
0
<?php

require_once dirname(dirname(__FILE__)) . '/config.php';
require_once 'Fun_HHT.local.inc.php';
if (!CheckTourSession() || !isset($_REQUEST['Id']) || !isset($_REQUEST['Event']) || !isset($_REQUEST['Value'])) {
    print get_text('CrackError');
    exit;
}
$Errore = 0;
if (!(IsBlocked(BIT_BLOCK_QUAL) && IsBlocked(BIT_BLOCK_IND) && IsBlocked(BIT_BLOCK_TEAM))) {
    $select = "SELECT HeEventCode FROM HhtEvents WHERE HeEventCode=" . StrSafe_DB($_REQUEST['Event']) . " AND HeTournament=" . StrSafe_DB($_SESSION['TourId']) . " AND HeHhtId=" . StrSafe_DB($_REQUEST['Id']);
    $rs = safe_r_sql($select);
    //	echo $select;
    //debug_svela(safe_num_rows($rs));
    if (safe_num_rows($rs) == 0 && $_REQUEST['Value'] == "true") {
        list($what, $ses, $dist) = phaseDecode($_REQUEST['Event']);
        safe_w_sql("INSERT INTO HhtEvents set HeTournament=" . StrSafe_DB($_SESSION['TourId']) . ", HeEventCode=" . StrSafe_DB($_REQUEST['Event']) . ", HeHhtId=" . StrSafe_DB($_REQUEST['Id']) . ", HeSession=" . ($what == -1 ? $ses : 0) . ", HeFinSchedule=" . ($what != -1 ? strSafe_DB($ses) : '0') . ", HeTeamEvent=" . ($what == -1 ? 0 : $what));
    } else {
        if (safe_num_rows($rs) == 1 && $_REQUEST['Value'] == "false") {
            safe_w_sql("Delete From HhtEvents WHERE HeTournament=" . StrSafe_DB($_SESSION['TourId']) . " AND HeEventCode=" . StrSafe_DB($_REQUEST['Event']) . " AND HeHhtId=" . StrSafe_DB($_REQUEST['Id']));
        } else {
            $Errore = 1;
        }
    }
} else {
    $Errore = 1;
}
header('Content-Type: text/xml');
print '<response>' . "\n";
print '<error>' . $Errore . '</error>' . "\n";
print '<id>' . $_REQUEST['Id'] . '</id>' . "\n";
Beispiel #2
0
function SendHTT($HhtParams, $sentences, $sendResultArray = false, $overTO = 0)
{
    $request = array();
    $answers = array();
    if (!is_array($sentences)) {
        $request[] = $sentences;
    } else {
        $request = $sentences;
    }
    if (count($request) > 0) {
        $fp = @fsockopen($HhtParams[0], $HhtParams[1], $errno, $errstr, 1);
        if ($fp) {
            $SecondTry = false;
            stream_set_blocking($fp, 0);
            for ($i = 0; $i < count($request); $i++) {
                $tmp = "";
                $EotCounter = 0;
                $TimerTo = getmicrotime();
                fputs($fp, $request[$i]);
                while (!feof($fp)) {
                    $char = fgetc($fp);
                    if ($char != null) {
                        $TimerTo = getmicrotime();
                    }
                    $tmp .= $char;
                    if ($char == EOT) {
                        $EotCounter++;
                        if (ord(substr($request[$i], 3, 1)) == AllModule) {
                            break;
                        }
                        if ($EotCounter >= 2) {
                            break;
                        }
                    }
                    if (getmicrotime() - $TimerTo > 0.5 + $overTO) {
                        //  						echo "TIMEOUTTED";
                        if (!$SecondTry && strlen($request[$i]) < strlen($tmp)) {
                            $SecondTry = true;
                            $i--;
                        }
                        break;
                    }
                }
                //			   	echo "BACK" . OutText($tmp);
                //Elimino completamente l'echo del cavo.'
                $tmp = str_replace($request[$i], "", $tmp);
                //				echo "PULITO" . OutText($tmp);
                //			exit();
                /**
                 *  Se avevo fatto qualunque altra richiesta E NON AVEVO FATTO BROADCAST mi aspetto indietro:
                 *  1) la domanda (Eliminata precedentemente e quindi non più in $tmp
                 *  2) i bytes della risposta di tipo "Collect" relativamente ai soli pettorali Abilitati (A,B,C,D) sono presenti se ci sono dentro i nomi)
                 *  
                 *  Prima di procedere verifico che:
                 *  a) La richiesta non sia un BROADCAST
                 *  b) Ci sia STX, ACK & EOT nei posti "giusti"
                 *  c) Il checksum quadri con il teorico 
                 */
                if (ord(substr($request[$i], 3, 1)) != AllModule && strlen($tmp) == ord(substr($tmp, 1, 1)) + 2 && substr($tmp, 0, 1) == STX && substr($tmp, 2, 1) == ACK && substr($tmp, -1, 1) == EOT) {
                    //Gestione della "Collect" e della "STORE"
                    /** 
                     * Se ho fatto una richiesta di "Collect" o di "store and Collect" prendo il valore che torna e creo un array così formato:
                     * array[0]= Numero di piazzolea
                     * array[1]= Valore delle frecce
                     */
                    if (strlen($request[$i]) == 7 || strlen($request[$i]) == 12 && substr($request[$i], 5, 5) == "sTORE") {
                        $tmpTarget = intval(substr($tmp, 6, 3));
                        $tmpFirstArr = intval(substr($tmp, 9, 2));
                        $tmpLastArr = intval(substr($tmp, 11, 2));
                        $tmpPhase = substr($tmp, 15, 3);
                        $curPos = 18;
                        //Posizione dove iniziano ad esserci i risultati (Forse)
                        //Nota Bene: $curPos + "2" + $tmpLastArr - $tmpFirstArr
                        //il "2" perche è: 1 per la piazzola (A,B,C,D,) + 1 per il numero frecce ($tmpLastArr - $tmpFirstArr + 1)
                        while (strlen($tmp) - 2 >= $curPos + 2 + $tmpLastArr - $tmpFirstArr) {
                            //echo substr($tmp,$curPos,2 + $tmpLastArr - $tmpFirstArr);
                            $tmpAnswers = array("TargetNo" => 0, "ArrowString" => 0, "Dist" => 0, "FirstArr" => 0, "LastArr" => 0, "Session" => 0, "FlagWhat" => "-1");
                            $tmpAnswers["TargetNo"] = $tmpTarget . substr($tmp, $curPos, 1);
                            $tmpAnswers["ArrowString"] = substr($tmp, $curPos + 1, 1 + $tmpLastArr - $tmpFirstArr);
                            $tmpAnswers["FirstArr"] = $tmpFirstArr;
                            $tmpAnswers["LastArr"] = $tmpLastArr;
                            list($tmpAnswers["FlagWhat"], $tmpAnswers["Session"], $tmpAnswers["Dist"]) = phaseDecode($tmpPhase);
                            //Salvo solo se esiste almeno un valore di freccia.
                            if (strlen(str_replace("-", "", $tmpAnswers["ArrowString"])) != 0) {
                                $answers[] = $tmpAnswers;
                            }
                            $curPos += 2 + $tmpLastArr - $tmpFirstArr;
                        }
                    } else {
                        if (substr($request[$i], 5, 1) == ':') {
                            if (substr($request[$i], 12, 2) == '01') {
                                echo "End Of File: " . substr($tmp, 5, -2) . "\n";
                            } else {
                                echo substr($request[$i], 8, 4) . ": " . substr($tmp, 5, -2) . "\n";
                            }
                            flush();
                        } else {
                            //Preparo il numero di paglione
                            $TmpPaglione = intval(substr($tmp, 6, 3));
                            //Gestisco l'init dell'HTT - Individual Mode
                            if (strpos($request[$i], chr(211)) !== false) {
                                $answers[] = $TmpPaglione;
                            }
                            //Mette A-B-C-D sull'init dei nomi della piazzola. Verifica quali dei Valori sono stati spediti
                            if (strpos($request[$i], chr(217)) !== false) {
                                $answers[] = $TmpPaglione . "A";
                            }
                            if (strpos($request[$i], chr(218)) !== false) {
                                $answers[] = $TmpPaglione . "B";
                            }
                            if (strpos($request[$i], chr(219)) !== false) {
                                $answers[] = $TmpPaglione . "C";
                            }
                            if (strpos($request[$i], chr(220)) !== false) {
                                $answers[] = $TmpPaglione . "D";
                            }
                            //Mette A-B-C-D sull'init dei totali della piazzola. Verifica quali dei Valori sono stati spediti
                            if (strpos($request[$i], chr(216)) !== false) {
                                if (strpos(substr($request[$i], 5, -2), "A") !== false) {
                                    $answers[] = $TmpPaglione . "A";
                                }
                                if (strpos(substr($request[$i], 5, -2), "B") !== false) {
                                    $answers[] = $TmpPaglione . "B";
                                }
                                if (strpos(substr($request[$i], 5, -2), "C") !== false) {
                                    $answers[] = $TmpPaglione . "C";
                                }
                                if (strpos(substr($request[$i], 5, -2), "D") !== false) {
                                    $answers[] = $TmpPaglione . "D";
                                }
                            }
                            //Mette il flag ad "A" se ho mandato il "Game Info"
                            if (strpos($request[$i], chr(221)) !== false) {
                                $answers[] = $TmpPaglione . "A";
                            }
                            //Mette il flag ad "C" se ho mandato il "Commercial"
                            if (strpos($request[$i], chr(222)) !== false) {
                                $answers[] = $TmpPaglione . "B";
                            }
                            //Mette il flag ad "D" se ho mandato la "Sequence"
                            if (strpos($request[$i], chr(223)) !== false) {
                                $answers[] = $TmpPaglione . "D";
                            }
                            //Verifico se Chiedo la release Software
                            if (substr($tmp, 5, 3) == "SW-") {
                                $tmpAnswer = array("Target" => 0, "Terminal" => '');
                                $tmpAnswer["Target"] = ord(substr($tmp, 3, 1)) - 32;
                                $tmpAnswer["Terminal"] = substr($tmp, 5, -2);
                                $answers[] = $tmpAnswer;
                            }
                            //Verifico se Chiedo i Dati di AB o di CE
                            if (substr($request[$i], 5, 4) == "READ") {
                                $curPos = strpos(substr($tmp, 0, -2), "@", 5);
                                while ($curPos !== false) {
                                    $tmpAnswer = array("Target" => 0, "Name" => '', "Country" => '', "TotaleScore" => 0, "Distance" => 0, "Volee" => 0, "Arrows" => '');
                                    $tmpAnswer["Target"] = ord(substr($tmp, 3, 1)) - 32;
                                    $tmpAnswer["Name"] = substr($tmp, $curPos + 1, 13);
                                    $tmpAnswer["Country"] = substr($tmp, $curPos + 14, 3);
                                    $tmpAnswer["TotaleScore"] = substr($tmp, $curPos + 17, 4);
                                    $tmpAnswer["Distance"] = substr($tmp, $curPos + 21, 3);
                                    $tmpAnswer["Volee"] = substr($tmp, $curPos + 24, 2);
                                    $tmpAnswer["Arrows"] = substr($tmp, $curPos + 26, 6);
                                    $answers[] = $tmpAnswer;
                                    $curPos = strpos(substr($tmp, 0, -2), "@", $curPos + 1);
                                }
                            }
                        }
                    }
                }
                usleep(5000 + $overTO);
            }
            fclose($fp);
        } else {
            return NULL;
        }
    }
    return $answers;
}
Beispiel #3
0
$Ses = $xSession;
if (!is_numeric($xSession)) {
    $What = substr($xSession, 0, 1);
    $Ses = substr($xSession, 1);
}
$Phase = isset($_REQUEST['phase']) ? $_REQUEST['phase'] : phaseEncode($What, $Ses, $DbDistParam);
//print $Phase;exit;
/*print $ActualArr . '<br>';
	print $TotalArrs . '<br>';
	print $Dist . '<br>';
	exit;*/
$Dist = '';
if (!is_null($Command)) {
    if ($Command == 'OK') {
        if (!is_null($HTTs) && is_array($HTTs)) {
            list(, , $Dist) = phaseDecode($Phase);
            // preparo i destinatari
            $Dests = null;
            $Dests = array_values($HTTs);
            sort($Dests);
            // per essere sicuro che se c'è lo zero allora sarà all'inizio
            // la if mi elimina la check "tutti"
            if (array_search(0, $HTTs) !== false) {
                array_shift($Dests);
            }
            $Frames = array();
            // preparo la parte data dei datagram
            if (isset($_REQUEST['chkGameInfo']) && $_REQUEST['chkGameInfo'] == 1) {
                if (isset($_REQUEST['txtGameInfo'])) {
                    $GameInfo = str_pad($_REQUEST['txtGameInfo'], 21, ' ', STR_PAD_RIGHT);
                    $Data = Alpha . $InfosMapping['GameInfo'] . $GameInfo;