$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);
// $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; }
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) {