コード例 #1
0
ファイル: tasker.php プロジェクト: KarlZeo/MoyOJ
    $connection->last_ping = 0;
    $connection->deadline = Timer::add(5, function () use($connection) {
        Timer::del($connection->deadline);
        $connection->deadline = 0;
        sendMsg($connection, array('action' => 'refuse'));
        $connection->close();
        p("A client timeout logging in. ( IP = {$connection->IP} )");
    });
    p("A new client has joined. ( IP = {$connection->IP} )");
};
$worker_tasker->onMessage = function ($connection, $data) {
    $data = json_decode($data, True);
    if ($connection->IP == '127.0.0.1' && isset($data['pass'], $data['task']) && $data['pass'] == sha1(DB_PASS)) {
        if (!isset($data['task']['action'])) {
            $solution = new Solution($data['task']);
            $solution->push();
            return;
        } else {
            switch ($data['task']['action']) {
                case 'kill':
                    kill_client($data['task']['cid']);
                    break;
            }
        }
    }
    if ($data == NULL || !isset($data['action'])) {
        p("Json decoding failed or in bad format. ( cid = {$connection->cid}, IP = {$connection->IP} )");
        return;
    }
    switch ($data['action']) {
        case 'heartbeat':
コード例 #2
0
ファイル: functions.php プロジェクト: KarlZeo/MoyOJ
function check_forgotten()
{
    global $db, $task;
    $sql = 'SELECT `id`, `pid`, `uid`, `code`, `state`, `language` FROM `mo_judge_solution` WHERE `state` = 0';
    $mark = $db->prepare($sql);
    $result = $db->execute($mark);
    if (!count($result)) {
        return 0;
    }
    foreach ($result as $solution) {
        if (!isset($task[(int) $solution['id']])) {
            $data = array('sid' => $solution['id'], 'pid' => $solution['pid'], 'uid' => $solution['uid'], 'lang' => $solution['language'], 'code' => $solution['code']);
            $new_solution = new Solution($data);
            $new_solution->push();
        }
    }
    return True;
}