Exemplo n.º 1
0
    //	$cms->tiny_page_err();
}
// try and resolve the country flag
if (!$server['cc'] and $server['ip']) {
    $row = $ps->db->fetch_row(1, sprintf("SELECT c.cc, c.cn " . "FROM {$ps->t_geoip_ip} ip, {$ps->t_geoip_cc} c " . "WHERE c.cc=ip.cc AND (%u BETWEEN start AND end) ", ip2long($server['ip'])));
    if ($row) {
        $server = array_merge($server, $row);
    }
} elseif ($server['cc']) {
    $row = $ps->db->fetch_row(0, sprintf("SELECT cn FROM {$ps->t_geoip_cc} WHERE cc='%s'", $ps->db->escape($server['cc'])));
    if ($row) {
        $server['cn'] = $row[0];
    }
}
// query the remote game server
$pq = PQ::create(array('ip' => $server['host'], 'port' => $server['port'], 'querytype' => $server['querytype'], 'timeout' => 1, 'retries' => 1));
$pqinfo = $pq->query(array('info', 'players', 'rules'));
if ($pqinfo === false) {
    $pqinfo = array();
}
if ($pqinfo) {
    $pqinfo['connect_url'] = $pq->connect_url($server['alt']);
    if ($pqinfo['players']) {
        usort($pqinfo['players'], 'killsort');
    }
    if ($pqinfo['rules']) {
        $pqinfo['rules'] = filter_rules($pqinfo['rules'], $rulefilters);
    }
} else {
    $pqinfo['timedout'] = 1;
}
Exemplo n.º 2
0
$form->default_modifier('trim');
$form->field('enabled');
$form->field('host', 'blank,hostname');
$form->field('port', 'blank,numeric');
$form->field('alt');
$form->field('querytype');
$form->field('rcon');
$form->field('cc');
//$form->field('idx');
if ($test and $server['id'] == $id) {
    // test the server, if asked to
    $test = $form->values();
    $result = 'success';
    $msg = '';
    // verify we can query the server
    $pq = PQ::create(array('ip' => $test['host'], 'port' => $test['port'], 'querytype' => $test['querytype'], 'timeout' => 3, 'retries' => 1));
    //	$pq->DEBUG = true;
    $in = @$pq->query_info();
    if (!$in) {
        $result = 'failure';
        $msg = $cms->trans("Unable to query server");
        if ($pq->errstr) {
            $msg .= "<br/>\n" . $pq->errstr;
        }
    } else {
        $msg = $cms->trans("Server queried successfully!");
        $msg .= "<br/>\n" . $cms->trans("Server Name") . ": " . $in['name'];
    }
    $message = $cms->message($result, array('message_title' => $cms->trans("Testing Results"), 'message' => $msg));
    // don't let the form be submitted
    unset($submit);
<?php

class PQ extends SplPriorityQueue
{
    public function compare($p1, $p2)
    {
        if ($p1 === $p2) {
            return 0;
        } else {
            // in ascending order of priority, a lower value
            // means higher priority
            return $p1 < $p2 ? 1 : -1;
        }
    }
}
$pq = new PQ();
$pq->insert('A', 4);
$pq->insert('B', 3);
$pq->insert('C', 5);
$pq->insert('D', 8);
$pq->insert('E', 2);
$pq->insert('F', 7);
$pq->insert('G', 1);
$pq->insert('H', 6);
$pq->insert('I', 0);
//$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
//$pq->setExtractFlags(SplPriorityQueue::EXTR_PRIORITY);
while ($pq->valid()) {
    print_r($pq->current());
    echo "\n";
    $pq->next();
Exemplo n.º 4
0
		Test script for the PsychoQuery PHP class.
		This will show you how to use the object to make your own queries.
*/
die("TO USE THIS SCRIPT DELETE LINE #" . __LINE__ . " FROM THIS FILE\nThis script is only usable from a prompt (not the web)\n");
define('PS_ROOTDIR', './');
include 'includes/class_PQ.php';
$opts = array('querytype' => 'halflife');
if ($GLOBALS['argv'][1]) {
    $opts['ip'] = $GLOBALS['argv'][1];
}
// get ip from command line if something is specified
if ($GLOBALS['argv'][2]) {
    $opts['querytype'] = $GLOBALS['argv'][2];
}
// create the new object ..
$pq = PQ::create($opts);
$pq->DEBUG = 1;
// disable this if you do not want to see the debug output
/**/
print "server info:\n";
//$data = $pq->query(array('info'));
#$data = $pq->query(array('info','players','rules'));
$data = $pq->query('rules');
//$data = $pq->query('info');
//$data = $pq->query_info();
//$data = $pq->query_players();
print_r($data);
/**/
/**
$time = $pq->pingserver();
if ($time !== FALSE) {
Exemplo n.º 5
0
Arquivo: pq.php Projeto: naoya/PQ
function main()
{
    $pq = new PQ();
    $pq->dsn('mysqli://*****:*****@localhost/sample?charset=utf8');
    echo $pq->query('users')->where(array('age' => array('>' => 20)))->where(array('mail' => array('-like' => '*****@*****.**')))->fields("mail, name")->order("updated desc")->offset(0)->limit(10)->exec()->map(function ($o) {
        return $o[0];
    })->map(function ($v) {
        return strtoupper($v);
    })->join("\n") . "\n";
}