Example #1
0
<?php

include "databaseName.php";
$con = connect($address, $username, $password, $database);
if (isset($_POST['MatchNumber']) && isset($_POST['TeamNumber'])) {
    $postKeys = array_keys($_POST);
    fillPosts($posts);
    sendAll($postKeys, $posts, $con);
    print "Submission received!<br><br> <a href='http://xbotsrobotics.com/Scouting'> Click here to return to the scouting page.</a>";
} else {
    //display graphical data here
}
disconnect($con);
function sendAll($keys, $values)
{
    $keyString = '';
    $valString = '';
    for ($i = 0; $i < sizeof($keys); $i++) {
        $keyString .= $keys[$i];
        $valString .= "'" . $values[$i] . "'";
        if ($i + 1 < sizeof($keys)) {
            $keyString .= ',';
            $valString .= ',';
        }
    }
    sendQuery($keyString, $valString);
}
function sendQuery($column, $value)
{
    $insert_query = "INSERT INTO MatchDatabase ({$column}) VALUES ({$value});";
    mysql_query($insert_query);
function apply_ws_query($connect, $sess_id, $q)
{
    if ($sess_id != '0' and $GLOBALS['sess_data'][$sess_id]['online'] < time()) {
        $GLOBALS['sess_data'][$sess_id]['online'] = time() + 120;
    }
    switch ($q[0]) {
        case 'sid':
            return array('type' => 'sid', 'answer' => $sess_id);
            break;
        case "uniqid":
            return array('type' => 'uniqid', 'answer' => uniqid());
        case 'test':
            return array('answer' => '1');
            break;
        case 'teleport':
            $GLOBALS['sess_data'][$sess_id]['x'] = $q[1];
            $GLOBALS['sess_data'][$sess_id]['y'] = $q[2];
            $GLOBALS['sess_data'][$sess_id]['dir'] = $q[3];
            sendAll(array('type' => 'teleport', 'char' => $GLOBALS['sess_data'][$sess_id]['cid'], 'x' => $q[1], 'y' => $q[2], 'dir' => $q[3]));
            return array('type' => 'default', 'answer' => '1');
            break;
        case 'clientjs':
            return array('type' => 'clientjs', 'answer' => rpgjs_getcmd($q[1]));
            break;
        case 'getposition':
            if (!isset($GLOBALS['sess_data'][$sess_id]['x']) or !isset($GLOBALS['sess_data'][$sess_id]['y']) or !isset($GLOBALS['sess_data'][$sess_id]['dir'])) {
                $GLOBALS['sess_data'][$sess_id]['x'] = char($GLOBALS['sess_data'][$sess_id]['cid'])->pos_x;
                $GLOBALS['sess_data'][$sess_id]['y'] = char($GLOBALS['sess_data'][$sess_id]['cid'])->pos_y;
                $GLOBALS['sess_data'][$sess_id]['dir'] = char($GLOBALS['sess_data'][$sess_id]['cid'])->dir;
                $GLOBALS['sess_data'][$sess_id]['loc'] = char($GLOBALS['sess_data'][$sess_id]['cid'])->map;
            }
            return array('type' => 'getposition', 'x' => $GLOBALS['sess_data'][$sess_id]['x'], 'y' => $GLOBALS['sess_data'][$sess_id]['y'], 'loc' => $GLOBALS['sess_data'][$sess_id]['map'], 'dir' => $GLOBALS['sess_data'][$sess_id]['dir']);
            break;
        case 'online':
            $array = array('type' => 'online');
            foreach ($GLOBALS['sess_data'] as $key => $value) {
                if ($value['online'] < time()) {
                    continue;
                }
                $array[$value['_id']]['id'] = $value['_id'];
                $array[$value['_id']]['x'] = $value['x'];
                $array[$value['_id']]['y'] = $value['y'];
                $array[$value['_id']]['dir'] = $value['dir'];
                $array[$value['_id']]['name'] = $value['name'];
                $array[$value['_id']]['online'] = $value['online'];
                $array[$value['_id']]['map'] = $value['map'];
                $array[$value['_id']]['skin'] = $value['skin'];
            }
            return $array;
            break;
        case 'events':
            return array('type' => 'events', 'answer' => implode(" ", array_values(check_player_events($GLOBALS['sess_data'][$sess_id]['cid'], true, true)['js'])));
            break;
        case 'mapchars':
            $array = array('type' => 'mapchars');
            foreach ($GLOBALS['sess_data'] as $key => $value) {
                if ($value['map'] != $q[1] or $GLOBALS['sess_data'][$sess_id]['cid'] == $value['_id']) {
                    continue;
                }
                $array[$value['_id']]['id'] = $value['_id'];
                $array[$value['_id']]['x'] = $value['x'];
                $array[$value['_id']]['y'] = $value['y'];
                $array[$value['_id']]['dir'] = $value['dir'];
                $array[$value['_id']]['name'] = $value['name'];
                $array[$value['_id']]['online'] = $value['online'];
                $array[$value['_id']]['map'] = $value['map'];
                $array[$value['_id']]['skin'] = $value['skin'];
            }
            return $array;
            break;
        case 'exists':
            return array('type' => 'default', 'error' => 'Deprecated method. Use API.');
            break;
        default:
            return array('type' => 'default', 'error' => 'Bad query ID (' . $q[0] . ')');
            break;
    }
}