示例#1
0
QByteArray TableItem::getDataPackage()
{
    QByteArray message;
    QDataStream messageStream(&message, QIODevice::WriteOnly);
    messageStream << name;
    messageStream << pos();
    messageStream << fileHash;
    messageStream << id;
    messageStream << teamsHidden;
    messageStream << teamsLocked;
    messageStream << rotation;
    messageStream << currentZPosition;
    messageStream << ownerID;
    addDataToStream(messageStream);
    return message;
}
示例#2
0
void connection_thread( void* c ) {
  connection_info* info = (connection_info*) c;

  indri::net::NetworkMessageStream messageStream( info->stream );
  indri::net::NetworkServerStub stub( info->server, &messageStream );
  std::string peer = info->stream->peer();

  log_message( peer.c_str(), "connected" );
  
  while( messageStream.alive() ) {
    log_message( peer.c_str(), "received request" );
    messageStream.read( stub ); 
    log_message( peer.c_str(), "sent response" );
  }

  info->active = false;
  log_message( peer.c_str(), "disconnected" );
}
示例#3
0
void TableItem::setDataPackage(QByteArray message)
{
    QPoint position;
    QDataStream messageStream(message);
    messageStream >> name;
    messageStream >> position;
    messageStream >> fileHash;
    messageStream >> id;
    messageStream >> teamsHidden;
    messageStream >> teamsLocked;
    messageStream >> rotation;
    messageStream >> currentZPosition;
    messageStream >> ownerID;

    move(position);
    useDataFromStream(messageStream);
    emit dataUpdated();
}
示例#4
0
void JudgingThread::specialJudge(const QString &fileName)
{
    if (! QFileInfo(inputFile).exists()) {
        score = 0;
        result = FileError;
        message = tr("Cannot find standard input file");
        return;
    }
    
    if (! QFileInfo(fileName).exists()) {
        score = 0;
        result = FileError;
        message = tr("Cannot find contestant\'s output file");
        return;
    }
    
    if (! QFileInfo(outputFile).exists()) {
        score = 0;
        result = FileError;
        message = tr("Cannot find standard output file");
        return;
    }
    
    QProcess *judge = new QProcess(this);
    QStringList arguments;
    arguments << inputFile << fileName << outputFile << QString("%1").arg(fullScore);
    arguments << workingDirectory + "_score";
    arguments << workingDirectory + "_message";
    judge->start(Settings::dataPath() + task->getSpecialJudge(), arguments);
    if (! judge->waitForStarted(-1)) {
        score = 0;
        result = InvalidSpecialJudge;
        delete judge;
        return;
    }
    
    QElapsedTimer timer;
    timer.start();
    bool flag = false;
    while (timer.elapsed() < specialJudgeTimeLimit) {
        if (judge->state() != QProcess::Running) {
            flag = true;
            break;
        }
        QCoreApplication::processEvents();
        if (stopJudging) {
            judge->kill();
            delete judge;
            return;
        }
        msleep(10);
    }
    if (! flag) {
        judge->kill();
        score = 0;
        result = SpecialJudgeTimeLimitExceeded;
        delete judge;
        return;
    } else
        if (judge->exitCode() != 0) {
            score = 0;
            result = SpecialJudgeRunTimeError;
            delete judge;
            return;
        }
    delete judge;
    
    QFile scoreFile(workingDirectory + "_score");
    if (! scoreFile.open(QFile::ReadOnly)) {
        score = 0;
        result = InvalidSpecialJudge;
        return;
    }
    
    QTextStream scoreStream(&scoreFile);
    scoreStream >> score;
    if (scoreStream.status() == QTextStream::ReadCorruptData) {
        score = 0;
        result = InvalidSpecialJudge;
        return;
    }
    scoreFile.close();
    
    if (score < 0) {
        score = 0;
        result = InvalidSpecialJudge;
        return;
    }
    
    QFile messageFile(workingDirectory + "_message");
    if (messageFile.open(QFile::ReadOnly)) {
        QTextStream messageStream(&messageFile);
        message = messageStream.readAll();
        messageFile.close();
    }
    
    if (score == 0) result = WrongAnswer;
    if (0 < score && score < fullScore) result = PartlyCorrect;
    if (score >= fullScore) result = CorrectAnswer;
    
    scoreFile.remove();
    messageFile.remove();
}