Example #1
0
function zkgetattendance($self)
{
    $command = CMD_ATTLOG_RRQ;
    $command_string = '';
    $chksum = 0;
    $session_id = $self->session_id;
    $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr($self->data_recv, 0, 8));
    $reply_id = hexdec($u['h8'] . $u['h7']);
    $buf = $self->createHeader($command, $chksum, $session_id, $reply_id, $command_string);
    socket_sendto($self->zkclient, $buf, strlen($buf), 0, $self->ip, $self->port);
    //try {
    socket_recvfrom($self->zkclient, $self->data_recv, 1024, 0, $self->ip, $self->port);
    if (getSizeAttendance($self)) {
        $bytes = getSizeAttendance($self);
        while ($bytes > 0) {
            socket_recvfrom($self->zkclient, $data_recv, 1032, 0, $self->ip, $self->port);
            array_push($self->attendancedata, $data_recv);
            $bytes -= 1024;
        }
        $self->session_id = hexdec($u['h6'] . $u['h5']);
        socket_recvfrom($self->zkclient, $data_recv, 1024, 0, $self->ip, $self->port);
    }
    $attendance = array();
    if (count($self->attendancedata) > 0) {
        # The first 4 bytes don't seem to be related to the user
        for ($x = 0; $x < count($self->attendancedata); $x++) {
            if ($x > 0) {
                $self->attendancedata[$x] = substr($self->attendancedata[$x], 8);
            }
        }
        $attendancedata = implode('', $self->attendancedata);
        $attendancedata = substr($attendancedata, 10);
        while (strlen($attendancedata) > 40) {
            $u = unpack('H78', substr($attendancedata, 0, 39));
            //24s1s4s11s
            //print_r($u);
            $uid = hexdec(substr($u[1], 0, 6));
            $uid = explode(chr(0), $uid);
            $uid = intval($uid[0]);
            $id = intval(str_replace("", '', hex2bin(substr($u[1], 6, 8))));
            $state = hexdec(substr($u[1], 66, 2));
            $ver = hexdec(substr($u[1], 56, 2));
            $timestamp = decode_time(hexdec(reverseHex(substr($u[1], 58, 8))));
            # Clean up some messy characters from the user name
            #uid = unicode(uid.strip('\x00|\x01\x10x'), errors='ignore')
            #uid = uid.split('\x00', 1)[0]
            #print "%s, %s, %s" % (uid, state, decode_time( int( reverseHex( timestamp.encode('hex') ), 16 ) ) )
            array_push($attendance, array($uid, $id, $state, $timestamp, $ver));
            $attendancedata = substr($attendancedata, 40);
        }
    }
    return $attendance;
    //} catch(exception $e) {
    //return False;
    //}
}
Example #2
0
function zkgettime($self)
{
    $command = CMD_GET_TIME;
    $command_string = '';
    $chksum = 0;
    $session_id = $self->session_id;
    $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr($self->data_recv, 0, 8));
    $reply_id = hexdec($u['h8'] . $u['h7']);
    $buf = $self->createHeader($command, $chksum, $session_id, $reply_id, $command_string);
    socket_sendto($self->zkclient, $buf, strlen($buf), 0, $self->ip, $self->port);
    try {
        socket_recvfrom($self->zkclient, $self->data_recv, 1024, 0, $self->ip, $self->port);
        $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6', substr($self->data_recv, 0, 8));
        $self->session_id = hexdec($u['h6'] . $u['h5']);
        return decode_time(hexdec(reverseHex(bin2hex(substr($self->data_recv, 8)))));
    } catch (ErrorException $e) {
        return FALSE;
    } catch (exception $e) {
        return False;
    }
}
Example #3
0
function extract_bets_foratotal(&$tournir_node, $html, $sport_sign, $tournir_id, $category_id)
{
    $i = 0;
    $filename_headers = "phrases/bwin/{$sport_sign}.headers.txt";
    $filename_labels = "phrases/bwin/{$sport_sign}.labels.txt";
    $phrases_headers = file_get_hash($filename_headers);
    $phrases_labels = file_get_hash($filename_labels);
    $html = kill_space($html);
    $html = numbering_tag($html, 'tr');
    $table_rows = extract_all_numbered_tags($html, 'tr', 'class');
    //  file_put_contents("lines/bwin/$tournir_id.Total.html", $html);
    foreach ($table_rows as $row) {
        $row = kill_property($row, 'TagNo');
        $header = copy_be($row, '<tr', '>');
        $row_class_name = extract_property_values($header, 'class', null);
        if ($row_class_name == 'topbar') {
            // разбираем дату
            $row = copy_between($row, '<h3>', '</h3>');
            list($day_no, $month_no, $year_no) = decode_date($row);
        } elseif (in_array($row_class_name, array('def', 'alt'))) {
            // игроки + время
            if (preg_match('/<td.*>(<h4>)*?(.+) - (.+) - (\\d{1,2}:\\d\\d (PM|AM))(.*?)(<\\/h4>)*?</Ui', $row, $matches)) {
                $gamer1_name = utf8_to_ansi_ce($matches[2]);
                $gamer2_name = utf8_to_ansi_ce($matches[3]);
                list($hour, $minute) = decode_time($matches[4]);
            } elseif (preg_match('/<td.*>(<h5>)*?(.+)(<\\/h5>)*?</iU', $row, $matches)) {
                $phrase = utf8_to_ansi_ce($matches[2]);
                unset($bettype);
                $phrase = str_ireplace($gamer1_name, 'Gamer1', $phrase);
                $phrase = str_ireplace($gamer2_name, 'Gamer2', $phrase);
                $bettype_str = $phrases_headers[$phrase];
                if ($bettype_str) {
                    foreach (explode(';', $bettype_str) as $bet_pair) {
                        list($key, $value) = explode('=', $bet_pair);
                        $bettype[$key] = $value;
                    }
                } else {
                    $bettype['Modifier'] = 'Unknown';
                    $phrases_headers[$phrase] = 'Modifier=Unknown';
                    $phrases_headers_modified = true;
                }
            }
        } elseif ($row_class_name == 'normal' and $bettype) {
            // основная ставка
            if (!in_array($bettype['Modifier'], array('Ignore', 'Unknown'))) {
                $tables = extract_all_tags($row, '<table', '</table>');
                foreach ($tables as $table) {
                    list($label, $koef) = extract_label_koef($table);
                    $label = str_ireplace($gamer1_name, 'Gamer1', $label);
                    $label = str_ireplace($gamer2_name, 'Gamer2', $label);
                    // подбираем формат фразы метки
                    $modifier = $phrases_labels[$label];
                    if ($modifier) {
                        foreach (explode(';', $modifier) as $bet_pair) {
                            list($key, $value) = explode('=', $bet_pair);
                            $bettype[$key] = $value;
                        }
                    } else {
                        $bettype['Modifier'] = 'Unknown';
                        $phrases_labels[$label] = 'Modifier=Unknown';
                        $phrases_labels_modified = true;
                    }
                    if (!in_array($bettype['Modifier'], array('Ignore', 'Unknown'))) {
                        $event_node = event_find_or_create($tournir_node, mktime($hour, $minute, 0, $month_no, $day_no, $year_no), $gamer1_name, $gamer2_name);
                        $bet_node = $event_node->addChild('Bet');
                        foreach ($bettype as $key => $value) {
                            $bet_node->addAttribute($key, $value);
                        }
                        $bet_node->addAttribute('Koef', $koef);
                    }
                    unset($bettype['Modifier']);
                }
            }
        }
        $i++;
    }
    // отбираем новые и складываем их в новый файл
    if ($phrases_headers_modified) {
        $file_hash = file_get_hash($filename_headers);
        foreach ($file_hash as $key => $value) {
            unset($phrases_headers[$key]);
        }
        file_put_hash($filename_headers . '.new', $phrases_headers + file_get_hash($filename_headers . '.new'));
    }
    if ($phrases_labels_modified) {
        $file_hash = file_get_hash($filename_labels);
        foreach ($file_hash as $key => $value) {
            unset($phrases_labels[$key]);
        }
        file_put_hash($filename_labels . '.new', $phrases_labels + file_get_hash($filename_labels . '.new'));
    }
}