public static function events($array)
 {
     return implode(" ", check_player_events($_SESSION['cid'], true, true)['js']);
 }
Example #2
0
if (isset($GLOBALS['modules'])) {
    foreach ($GLOBALS['modules'] as $module) {
        if (!file_exists(MODS_ROOT . SEPARATOR . $module . SEPARATOR . "global.php")) {
            continue;
        }
        @(include_once MODS_ROOT . SEPARATOR . $module . SEPARATOR . "global.php");
    }
}
if (!defined("NOT_CLIENT_USE") and defined("CLIENT_USE")) {
    if (isset($_SESSION['cid'])) {
        if (is_object($_SESSION['cid'])) {
            $_SESSION['cid'] = __toString($_SESSION['cid']);
        }
        $GLOBALS['chars'][$_SESSION['cid']] = new Char($_SESSION['cid']);
        $GLOBALS['chars'][$_SESSION['cid']]->setOnline();
        $ev = check_player_events($_SESSION['cid'], false, true);
        if (!empty($ev['eval'])) {
            eval(implode(" ", $ev['eval']));
        }
    }
    if (isset($_SESSION['id'])) {
        if (is_object($_SESSION['id'])) {
            $_SESSION['id'] = __toString($_SESSION['id']);
        }
        global $player;
        $player = new Player($_SESSION['id']);
    }
    eval(getScript('main'));
    call_user_func("scriptEngineInit");
    checkTimers();
}
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;
    }
}