void HairyBrush::paintParticle(QPointF pos, const KoColor& color, qreal weight) { // opacity top left, right, bottom left, right quint8 opacity = color.opacityU8(); opacity *= weight; int ipx = int (pos.x()); int ipy = int (pos.y()); qreal fx = pos.x() - ipx; qreal fy = pos.y() - ipy; quint8 btl = qRound((1.0 - fx) * (1.0 - fy) * opacity); quint8 btr = qRound((fx) * (1.0 - fy) * opacity); quint8 bbl = qRound((1.0 - fx) * (fy) * opacity); quint8 bbr = qRound((fx) * (fy) * opacity); const KoColorSpace * cs = m_dab->colorSpace(); m_dabAccessor->moveTo(ipx , ipy); btl = quint8(qBound<quint16>(OPACITY_TRANSPARENT_U8, btl + cs->opacityU8(m_dabAccessor->rawData()), OPACITY_OPAQUE_U8)); memcpy(m_dabAccessor->rawData(), color.data(), cs->pixelSize()); cs->setOpacity(m_dabAccessor->rawData(), btl, 1); m_dabAccessor->moveTo(ipx + 1, ipy); btr = quint8(qBound<quint16>(OPACITY_TRANSPARENT_U8, btr + cs->opacityU8(m_dabAccessor->rawData()), OPACITY_OPAQUE_U8)); memcpy(m_dabAccessor->rawData(), color.data(), cs->pixelSize()); cs->setOpacity(m_dabAccessor->rawData(), btr, 1); m_dabAccessor->moveTo(ipx, ipy + 1); bbl = quint8(qBound<quint16>(OPACITY_TRANSPARENT_U8, bbl + cs->opacityU8(m_dabAccessor->rawData()), OPACITY_OPAQUE_U8)); memcpy(m_dabAccessor->rawData(), color.data(), cs->pixelSize()); cs->setOpacity(m_dabAccessor->rawData(), bbl, 1); m_dabAccessor->moveTo(ipx + 1, ipy + 1); bbr = quint8(qBound<quint16>(OPACITY_TRANSPARENT_U8, bbr + cs->opacityU8(m_dabAccessor->rawData()), OPACITY_OPAQUE_U8)); memcpy(m_dabAccessor->rawData(), color.data(), cs->pixelSize()); cs->setOpacity(m_dabAccessor->rawData(), bbr, 1); }
/*! * Создание транспортного пакета. * * \param stream output stream. * \param packets raw virtual packets. * \param sequence packet sequence. * \param timestamp отметка времени. * \param options packet options. * \param type packet type. * \param subversion packet subversion. */ TransportWriter::TransportWriter(QDataStream *stream, const QList<QByteArray> &packets, quint64 sequence, qint64 timestamp, quint8 options, quint8 type, quint8 subversion) : m_device(stream->device()), m_size(16) { m_device->seek(0); quint32 size = packets.size(); bool huge = options & Protocol::HugePackets; // Расчёт размера пакета и составление карты размеров виртуальных пакетов. if (huge) m_size += (size * 4); else m_size += (size * 2); quint32 *map = new quint32[size]; quint32 s = 0; for (quint32 i = 0; i < size; ++i) { s = packets.at(i).size(); map[i] = s; m_size += s; } if (timestamp != 0) { options |= Protocol::TimeStamp; m_size += 8; } // Запись заголовка пакета. *stream << m_size << type << quint8(Protocol::V4) << subversion << options << sequence; if (timestamp != 0) *stream << timestamp; *stream << size; // Запись карты размеров виртуальных пакетов. if (huge) { for (quint32 i = 0; i < size; ++i) *stream << map[i]; } else { for (quint32 i = 0; i < size; ++i) *stream << quint16(map[i]); } // Запись тел виртуальных пакетов. for (quint32 i = 0; i < size; ++i) { stream->writeRawData(packets.at(i).constData(), map[i]); } delete [] map; }
void PlayerSocket::sendEnemyConnectionInf(const QSharedPointer<PlayerSocket>& enemy, bool serverFlag) { QByteArray bytes; QDataStream request(&bytes, QIODevice::ReadWrite); request.setVersion(Protocol::QDataStreamVersion); request << quint16(0) << quint8(Protocol::GAME_FOUND) << serverFlag; request << enemy->getServerPort() << enemy->getHostName().toLatin1().data(); request.device()->seek(0); request << quint16(bytes.size()); socket->write(bytes); socket->flush(); }
QDataStream &operator<<(QDataStream &stream, const QEasingCurve &easing) { stream << quint8(easing.d_ptr->type); stream << quint64(quintptr(easing.d_ptr->func)); bool hasConfig = easing.d_ptr->config; stream << hasConfig; if (hasConfig) { stream << easing.d_ptr->config->_p; stream << easing.d_ptr->config->_a; stream << easing.d_ptr->config->_o; } return stream; }
void ChatServer::startServer(const QBluetoothAddress& localAdapter) { if (rfcommServer) return; rfcommServer = new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol, this); connect(rfcommServer, SIGNAL(newConnection()), this, SLOT(clientConnected())); bool result = rfcommServer->listen(localAdapter); if (!result) { qWarning() << "Cannot bind chat server to" << localAdapter.toString(); return; } //serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceRecordHandle, (uint)0x00010010); QBluetoothServiceInfo::Sequence classId; classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort)); serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList, classId); classId.prepend(QVariant::fromValue(QBluetoothUuid(serviceUuid))); serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId); serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList,classId); serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceName, tr("Bt Chat Server")); serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceDescription, tr("Example bluetooth chat server")); serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceProvider, tr("qt-project.org")); serviceInfo.setServiceUuid(QBluetoothUuid(serviceUuid)); serviceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList, QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup)); QBluetoothServiceInfo::Sequence protocolDescriptorList; QBluetoothServiceInfo::Sequence protocol; protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap)); protocolDescriptorList.append(QVariant::fromValue(protocol)); protocol.clear(); protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm)) << QVariant::fromValue(quint8(rfcommServer->serverPort())); protocolDescriptorList.append(QVariant::fromValue(protocol)); serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList); serviceInfo.registerService(localAdapter); }
Shred::~Shred() { QByteArray * const shred_data = new QByteArray(); shred_data->reserve(30000); QDataStream outstr(shred_data, QIODevice::WriteOnly); outstr << CURRENT_SHRED_FORMAT_VERSION; outstr.setVersion(DATASTREAM_VERSION); outstr << quint8(GetTypeOfShred()) << quint8(weather); for (int x=0; x<SHRED_WIDTH; ++x) for (int y=0; y<SHRED_WIDTH; ++y) { int height = HEIGHT-2; for ( ; blocks[x][y][height]->Sub()==AIR; --height); for (int z=1; z <= height; ++z) { Block * const block = blocks[x][y][z]; if ( block == Normal(block->Sub()) ) { block->SaveNormalToFile(outstr); } else { block->SaveToFile(outstr); delete block; // without unregistering. } } blocks[x][y][HEIGHT-1]->SaveNormalToFile(outstr); } GetWorld()->SetShredData(shred_data, longitude, latitude); }
void Client::sendRegistration() { QByteArray datagram; QDataStream out(&datagram, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_4_7); out << quint16(0) << quint8('R'); out << DeviceManager::getDeviceMac() << DeviceManager::getDeviceIP(); out << 0xFFFF; //out.device()->seek(0); //out << quint16(block->size() - sizeof(quint16)); udpSocket.writeDatagram(datagram, QHostAddress::Broadcast, 6178); }
void Client::sendSearchInfo(){ QByteArray block; QDataStream out(&block, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_4_1); //if(!userLineEdit->text().isEmpty()){ out << quint16(0) << quint8('S') << userLineEdit->text(); out.device()->seek(0); out << quint16(block.size() - sizeof(quint16)); tcpSocket->write(block); //}else{ // statusLabel->setText("Please enter a file to search for"); //} //ui.label->setText(tr("Sending request...")); //printf("Sending Request...\n"); }
void tst_QAsn1Element::octetString() { QFETCH(QByteArray, encoded); QFETCH(QByteArray, value); // read QAsn1Element elem; QVERIFY(elem.read(encoded)); QCOMPARE(elem.type(), quint8(QAsn1Element::OctetStringType)); QCOMPARE(elem.value(), value); // write QByteArray buffer; QDataStream stream(&buffer, QIODevice::WriteOnly); elem.write(stream); QCOMPARE(buffer, encoded); }
QModbusResponse QModbusServerPrivate::processGetCommEventLogRequest(const QModbusRequest &request) { CHECK_SIZE_EQUALS(request); const QVariant tmp = q_func()->value(QModbusServer::DeviceBusy); if (tmp.isNull() || (!tmp.isValid())) { return QModbusExceptionResponse(request.functionCode(), QModbusExceptionResponse::ServerDeviceFailure); } const quint16 deviceBusy = tmp.value<quint16>(); QVector<quint8> eventLog(int(m_commEventLog.size())); std::copy(m_commEventLog.cbegin(), m_commEventLog.cend(), eventLog.begin()); // 6 -> 3 x 2 Bytes (Status, Event Count and Message Count) return QModbusResponse(request.functionCode(), quint8(eventLog.size() + 6), deviceBusy, m_counters[Counter::CommEvent], m_counters[Counter::BusMessage], eventLog); }
void QDirectFBWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) { QWidget *win = window(); if (!win) return; #if !defined(QT_NO_QWS_PROXYSCREEN) && !defined(QT_NO_GRAPHICSVIEW) QWExtra *extra = qt_widget_private(widget)->extraData(); if (extra && extra->proxyWidget) return; #else Q_UNUSED(widget); #endif const quint8 windowOpacity = quint8(win->windowOpacity() * 0xff); const QRect windowGeometry = geometry(); #ifdef QT_DIRECTFB_WM quint8 currentOpacity; Q_ASSERT(dfbWindow); dfbWindow->GetOpacity(dfbWindow, ¤tOpacity); if (currentOpacity != windowOpacity) { dfbWindow->SetOpacity(dfbWindow, windowOpacity); } screen->flipSurface(dfbSurface, flipFlags, region, offset); #else setOpaque(windowOpacity == 0xff); if (mode == Offscreen) { screen->exposeRegion(region.translated(offset + geometry().topLeft()), 0); } else { screen->flipSurface(dfbSurface, flipFlags, region, offset); } #endif #ifdef QT_DIRECTFB_TIMING enum { Secs = 3 }; ++frames; if (timer.elapsed() >= Secs * 1000) { qDebug("%d fps", int(double(frames) / double(Secs))); frames = 0; timer.restart(); } #endif flushPending = false; }
void KisColor::initHSX(Type type, float h, float s, float x, float a) { // an offset that is added to the m_coreData buffer to make sure // the struct created with the placement new operator is aligned at 16 bytes // this is required by Eigen for vectorization m_offset = quint8(16 - (reinterpret_cast<size_t>(m_coreData) % 16)) % 16; switch(type) { case HSY: { new (m_coreData + m_offset) CoreImpl<HSYType>; } break; case HSV: { new (m_coreData + m_offset) CoreImpl<HSVType>; } break; case HSL: { new (m_coreData + m_offset) CoreImpl<HSLType>; } break; case HSI: { new (m_coreData + m_offset) CoreImpl<HSIType>; } break; } core()->type = type; core()->setHSX(h, s, x, a); }
void tst_QAsn1Element::integer() { QFETCH(QByteArray, encoded); QFETCH(int, value); // read bool ok; QAsn1Element elem; QVERIFY(elem.read(encoded)); QCOMPARE(elem.type(), quint8(QAsn1Element::IntegerType)); QCOMPARE(elem.toInteger(&ok), value); QVERIFY(ok); // write QByteArray buffer; QDataStream stream(&buffer, QIODevice::WriteOnly); QAsn1Element::fromInteger(value).write(stream); QCOMPARE(buffer, encoded); }
void Client::sendFile(){ QByteArray block; //QFile *file = new QFile(userLineEdit->text()); //file->open(QIODevice::ReadOnly); QDataStream out(&block, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_4_1); QString file = userLineEdit->text(); if(!userLineEdit->text().isEmpty()){ //printf("File from edit: %s\n", qPrintable(file)); out << quint16(0) << quint8('F') << userLineEdit->text(); out.device()->seek(0); out << quint16(block.size() - sizeof(quint16)); tcpSocket->write(block); }else{ statusLabel->setText("Please choose a file to move to the server"); } //ui.label->setText(tr("Sending request...")); //printf("Sending Request...\n"); }
void WorldSession::SendCoachInformation() { Coach* coach = new Coach(this); if (!coach->LoadFromDB()) { delete coach; OnClose(); return; } WorldPacket data(SMSG_COACH_INFORMATIONS); // unserializeIdAndName data << coach->GetGuid(); data.WriteString(coach->GetName()); // unserializeLook data << coach->GetSkinColorIndex(); data << coach->GetHairColorIndex(); data << coach->GetGender(); // unserializeEquipment data << quint16(0); // length // todo // unserializeCardInventory data << quint16(0); // length // todo // unserializeLockedSet data << quint16(0); // length // unserializeLaddersStrength data << quint8(0); // count // todo SendPacket(data); // World login SendEnterInstance(); }
QModbusResponse QModbusServerPrivate::readBytes(const QModbusPdu &request, QModbusDataUnit::RegisterType unitType) { CHECK_SIZE_EQUALS(request); quint16 address, count; request.decodeData(&address, &count); if ((count < 0x0001) || (count > 0x007D)) { return QModbusExceptionResponse(request.functionCode(), QModbusExceptionResponse::IllegalDataValue); } // Get the requested range out of the registers. QModbusDataUnit unit(unitType, address, count); if (!q_func()->data(&unit)) { return QModbusExceptionResponse(request.functionCode(), QModbusExceptionResponse::IllegalDataAddress); } return QModbusResponse(request.functionCode(), quint8(count * 2), unit.values()); }
void DonationManager::donate(int index) { if (index < 0 || index >= m_coinsInTier.size()) return; const quint16 numCoins = m_coinsInTier.at(index); const QString sku = QString("TAOT%1COINS").arg(numCoins); QVariantMap extra; extra.insert("numCoins", numCoins); QByteArray data; QDataStream stream(&data, QIODevice::WriteOnly); stream << quint8(1); // Metadata version stream << numCoins; m_paymentManager->requestPurchase(QString(), sku, QString(), QString::fromLatin1(data.toBase64()), extra); }
void testQOfonoCallVolume() { QSignalSpy mutedChanged(m, SIGNAL(mutedChanged(const bool))); QSignalSpy speakerVolumeChanged(m, SIGNAL(speakerVolumeChanged(const quint8))); QSignalSpy microphoneVolumeChanged(m, SIGNAL(microphoneVolumeChanged(const quint8))); QSignalSpy spfail(m, SIGNAL(setSpeakerVolumeFailed())); QSignalSpy mvfail(m, SIGNAL(setMicrophoneVolumeFailed())); QOfonoModem modem; modem.setModemPath(m->modemPath()); modem.setPowered(false); QTest::qWait(5000); modem.setPowered(true); QTest::qWait(5000); modem.setOnline(true); QTest::qWait(5000); m->setMuted(true); QTest::qWait(2000); QCOMPARE(mutedChanged.count(), 1); QVERIFY(mutedChanged.takeFirst().at(0).toBool()==bool(true)); QVERIFY(m->muted()==bool(true)); m->setMuted(false); QTest::qWait(2000); QCOMPARE(mutedChanged.count(), 1); QVERIFY(mutedChanged.takeFirst().at(0).toBool()==bool(false)); QVERIFY(m->muted()==bool(false)); m->setSpeakerVolume(quint8(15)); QTest::qWait(2000); QCOMPARE(speakerVolumeChanged.count(), 1); QCOMPARE(quint8(speakerVolumeChanged.takeFirst().at(0).toUInt()), quint8(15)); QCOMPARE(m->speakerVolume(),quint8(15)); m->setSpeakerVolume(quint8(250)); QTest::qWait(2000); QCOMPARE(spfail.count(), 1); m->setMicrophoneVolume(quint8(10)); QTest::qWait(2000); QCOMPARE(mvfail.count(), 1); }
void Client::sendOrder() { quint16 seatNO = getSeatNO(); block = new QByteArray(); QDataStream out(block, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_4_7); out << quint16(0) << quint8('O'); QSqlQuery query; query.exec("SELECT * FROM unsentModel"); quint32 orderNO = 0; QString name = ""; QString image = ""; float price = 0; quint16 num = 0; while (query.next()) { if (orderNO == 0) { orderNO = query.value(0).toUInt(); out << quint32(orderNO) << quint16(seatNO) << DeviceManager::getDeviceMac(); } name = query.value(1).toString(); image = query.value(2).toString(); price = query.value(3).toFloat(); num = query.value(4).toUInt(); out << 0x1111 << name << price << num; } query.exec("DELETE FROM unsentModel"); out << 0xFFFF; out.device()->seek(0); out << quint16(block->size() - sizeof(quint16)); QString serverIP = DeviceManager::getServerIP(); connectToServer(serverIP); emit sendOrderComplete(); }
void VoxelFile::save_fp(QFile & fp) { QDataStream stream(&fp); stream.setByteOrder(QDataStream::LittleEndian); stream << x_size; stream << y_size; stream << z_size; stream << x_offset; stream << y_offset; stream << z_offset; stream.writeRawData((char*)data, x_size * y_size * z_size); stream.writeRawData((char*)global_palette, 256 * 3); stream << quint8(points.size()); ReferencePoints::const_iterator it; for (it = points.begin(); it != points.end(); it++) { const ReferencePoint & point = *it; write_cstring(stream, point.name); stream << point.x; stream << point.y; stream << point.z; } save_palette(); }
void DiscoverClient::updateListEndpoints() { m_address_list.clear(); for (const QHostAddress &address : QNetworkInterface::allAddresses()) { if (address.protocol() == QAbstractSocket::IPv4Protocol) { quint32 ip = address.toIPv4Address(); quint8 octets[4]; quint32 parts[4]; for (int i = 1; i <= 4; i++) { quint32 num = (ip / quint32(qPow(256, 4 - i))); ip = (ip - num * quint32(qPow(256, 4 - i))); octets[i - 1] = quint8(num); } for (int i = 1; i <= 4; i++) { parts[i - 1] = (octets[i - 1] * quint32(qPow(256, 4 - i))); } parts[4 - 1] = 255; quint32 new_ip = (parts[0] + parts[1] + parts[2] + parts[3]); QHostAddress address(ip); QHostAddress address_broadcast(new_ip); m_address_list.append(address_broadcast); } } }
QString operationStr(char op) { QString str; switch (quint8(op)) { case quint8(WILL): str = "WILL"; break; case quint8(WONT): str = "WONT"; break; case quint8(DO): str = "DO"; break; case quint8(DONT): str = "DONT"; break; case quint8(SB): str = "SB"; break; default: str = QString("Unknown operation (%1)").arg(quint8(op)); } return str; }
bool AkaiFileHandler::writePgmFileMPC1000( QStringList sampleNames, const QString fileBaseName, const QString outputDirPath, const QString tempDirPath, const SamplerAudioSource::EnvelopeSettings& envelopes, const bool isOverwriteEnabled ) { const QString fileName = fileBaseName + getFileExtension(); if ( QDir( outputDirPath ).exists( fileName ) && ! isOverwriteEnabled ) { return false; } while ( sampleNames.size() > MPC1000_Profile::NUM_PADS ) { sampleNames.removeLast(); } QByteArray pgmData( MPC1000_PGM::FILE_SIZE, PADDING ); bool isSuccessful = getTemplateDataMPC1000( pgmData ); if ( isSuccessful ) { quint8 noteNum = Midi::MIDDLE_C; for ( quint8 padNum = 0; padNum < sampleNames.size(); padNum++ ) { // Add sample name to PGM data { QByteArray sampleName = sampleNames.at( padNum ).toLatin1().leftJustified( MPC1000_PGM::SAMPLE_NAME_SIZE, PADDING, true ); const int pos = MPC1000_PGM::PAD_DATA_START + ( padNum * MPC1000_PGM::PAD_DATA_SIZE ); pgmData.replace( pos, MPC1000_PGM::SAMPLE_NAME_SIZE, sampleName ); } // Add sample volume level { const int pos = MPC1000_PGM::PAD_DATA_START + ( padNum * MPC1000_PGM::PAD_DATA_SIZE ) + MPC1000_PGM::LEVEL_OFFSET; QByteArray level; level += quint8( 100 ); pgmData.replace( pos, 1, level ); } // Add play mode { const int pos = MPC1000_PGM::PAD_DATA_START + ( padNum * MPC1000_PGM::PAD_DATA_SIZE ) + MPC1000_PGM::PLAY_MODE_OFFSET; QByteArray playMode; playMode += envelopes.oneShotSettings.at( padNum ) ? (char) 0x0 // 0 - One shot is set : quint8( 1 ); // 1 - One shot is not set pgmData.replace( pos, 1, playMode ); } // Add attack { const int pos = MPC1000_PGM::PAD_DATA_START + ( padNum * MPC1000_PGM::PAD_DATA_SIZE ) + MPC1000_PGM::ATTACK_OFFSET; QByteArray attack; attack += quint8( envelopes.attackValues.at( padNum ) * 100 ); pgmData.replace( pos, 1, attack ); } // Add decay { const int pos = MPC1000_PGM::PAD_DATA_START + ( padNum * MPC1000_PGM::PAD_DATA_SIZE ) + MPC1000_PGM::DECAY_OFFSET; QByteArray decay; decay += quint8( envelopes.releaseValues.at( padNum ) * 100 ); pgmData.replace( pos, 1, decay ); } // Add decay mode { const int pos = MPC1000_PGM::PAD_DATA_START + ( padNum * MPC1000_PGM::PAD_DATA_SIZE ) + MPC1000_PGM::DECAY_MODE_OFFSET; QByteArray decayMode; decayMode += (char) 0x0; pgmData.replace( pos, 1, decayMode ); } // Add "pad" -> "MIDI note" mapping { const int pos = MPC1000_PGM::PAD_MIDI_DATA_START + padNum; QByteArray value; value += noteNum; pgmData.replace( pos, 1, value ); } // Add "MIDI note" -> "pad" mapping { const int pos = MPC1000_PGM::MIDI_NOTE_DATA_START + noteNum; QByteArray value; value += padNum; pgmData.replace( pos, 1, value ); } noteNum++; } // Write PGM data to file const QString tempFilePath = QDir( tempDirPath ).absoluteFilePath( fileName ); QFile tempFile( tempFilePath ); isSuccessful = tempFile.open( QIODevice::WriteOnly ); if ( isSuccessful ) { QDataStream outStream( &tempFile ); const int numBytesWritten = outStream.writeRawData( pgmData.data(), MPC1000_PGM::FILE_SIZE ); if ( numBytesWritten != MPC1000_PGM::FILE_SIZE ) { isSuccessful = false; } else { const QString outputFilePath = QDir( outputDirPath ).absoluteFilePath( fileName ); QFile::remove( outputFilePath ); tempFile.copy( outputFilePath ); } tempFile.remove(); } } return isSuccessful; }
QMimeMagicRule::QMimeMagicRule(const QString &typeStr, const QByteArray &theValue, const QString &offsets, const QByteArray &theMask, QString *errorString) : d(new QMimeMagicRulePrivate) { d->value = theValue; d->mask = theMask; d->matchFunction = 0; d->type = QMimeMagicRule::type(typeStr.toLatin1()); if (d->type == Invalid) { *errorString = QStringLiteral("Type %s is not supported").arg(typeStr); } // Parse for offset as "1" or "1:10" const int colonIndex = offsets.indexOf(QLatin1Char(':')); const QString startPosStr = colonIndex == -1 ? offsets : offsets.mid(0, colonIndex); const QString endPosStr = colonIndex == -1 ? offsets : offsets.mid(colonIndex + 1); if (!QMimeTypeParserBase::parseNumber(startPosStr, &d->startPos, errorString) || !QMimeTypeParserBase::parseNumber(endPosStr, &d->endPos, errorString)) { d->type = Invalid; return; } if (d->value.isEmpty()) { d->type = Invalid; if (errorString) *errorString = QLatin1String("Invalid empty magic rule value"); return; } if (d->type >= Host16 && d->type <= Byte) { bool ok; d->number = d->value.toUInt(&ok, 0); // autodetect if (!ok) { d->type = Invalid; if (errorString) *errorString = QString::fromLatin1("Invalid magic rule value \"%1\"").arg( QString::fromLatin1(d->value)); return; } d->numberMask = !d->mask.isEmpty() ? d->mask.toUInt(&ok, 0) : 0; // autodetect } switch (d->type) { case String: d->pattern = makePattern(d->value); d->pattern.squeeze(); if (!d->mask.isEmpty()) { if (d->mask.size() < 4 || !d->mask.startsWith("0x")) { d->type = Invalid; if (errorString) *errorString = QString::fromLatin1("Invalid magic rule mask \"%1\"").arg( QString::fromLatin1(d->mask)); return; } const QByteArray &tempMask = QByteArray::fromHex(QByteArray::fromRawData( d->mask.constData() + 2, d->mask.size() - 2)); if (tempMask.size() != d->pattern.size()) { d->type = Invalid; if (errorString) *errorString = QString::fromLatin1("Invalid magic rule mask size \"%1\"").arg( QString::fromLatin1(d->mask)); return; } d->mask = tempMask; } else { d->mask.fill(char(-1), d->pattern.size()); } d->mask.squeeze(); d->matchFunction = matchString; break; case Byte: if (d->number <= quint8(-1)) { if (d->numberMask == 0) d->numberMask = quint8(-1); d->matchFunction = matchNumber<quint8>; } break; case Big16: case Host16: case Little16: if (d->number <= quint16(-1)) { d->number = d->type == Little16 ? qFromLittleEndian<quint16>(d->number) : qFromBigEndian<quint16>(d->number); if (d->numberMask == 0) d->numberMask = quint16(-1); d->matchFunction = matchNumber<quint16>; } break; case Big32: case Host32: case Little32: if (d->number <= quint32(-1)) { d->number = d->type == Little32 ? qFromLittleEndian<quint32>(d->number) : qFromBigEndian<quint32>(d->number); if (d->numberMask == 0) d->numberMask = quint32(-1); d->matchFunction = matchNumber<quint32>; } break; default: break; } }
/*! Creates the RFCOMM server and starts to listen for the incoming connections. Returns true if the server was started successfully, false otherwise. */ bool BluetoothServer::startServer() { qDebug() << "Bluetoothserver::startServer(): =>"; if (mServiceUuid == 0) { qDebug() << "BluetoothServer::startServer(): No service information set!"; return false; } if (mRfcommServer) { qDebug() << "BluetoothServer::startServer(): Already started!"; return false; } mSockets.clear(); mLastErrorString = ""; Common::resetBuffer(); qDebug() << "Bluetoothserver::startServer(): Creating a server"; // Create the server mRfcommServer = new QRfcommServer(this); connect(mRfcommServer, SIGNAL(newConnection()), this, SLOT(onNewConnection())); qDebug() << "Bluetoothserver::startServer(): Server created"; #ifdef Q_WS_HARMATTAN if (!mRfcommServer->listen(QBluetoothAddress(), 11)) #else if (!mRfcommServer->listen()) #endif { qDebug() << "BluetoothServer::startServer():" << "Error: mRfcommServer is not listening!"; delete mRfcommServer; mRfcommServer = 0; return false; } qDebug() << "BluetoothServer::startServer(): Server is using port" << mRfcommServer->serverPort(); mServiceInfo.setAttribute(QBluetoothServiceInfo::ServiceRecordHandle, (uint)0x00010010); #if !defined(Q_WS_SIMULATOR) && !defined(DISABLE_BLUETOOTH) // Class Uuuid must contain at least one entry QBluetoothServiceInfo::Sequence classId; classId << QVariant::fromValue(QBluetoothUuid(mServiceUuid)); mServiceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId); #endif mServiceInfo.setServiceAvailability(1); qDebug() << "BluetoothServer::startServer(): Using service info:" << mServiceInfo.attribute(QBluetoothServiceInfo::ServiceName).toString() << mServiceInfo.attribute(QBluetoothServiceInfo::ServiceProvider).toString(); // Set the Service UUID set mServiceInfo.setServiceUuid(QBluetoothUuid(mServiceUuid)); // Set service discoverability mServiceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList, QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup)); #if !defined(Q_WS_SIMULATOR) && !defined(DISABLE_BLUETOOTH) // Protocol descriptor list QBluetoothServiceInfo::Sequence protocolDescriptorList; QBluetoothServiceInfo::Sequence protocol; protocol.clear(); protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm)) << QVariant::fromValue(quint8(mRfcommServer->serverPort())); protocolDescriptorList.append(QVariant::fromValue(protocol)); mServiceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList); #endif // Register the service if (mServiceInfo.registerService()) { qDebug() << "BluetoothServer::startServer():" << "Service registered. Waiting for clients to connect."; } else { qDebug() << "BluetoothServer::startServer():" << "Failed to register the service!"; delete mRfcommServer; mRfcommServer = 0; return false; } qDebug() << "Bluetoothserver::startServer(): <="; return true; }
void QDeclarativeBluetoothService::setRegistered(bool registered) { d->m_needsRegistration = registered; if(!d->m_componentComplete){ return; } if(!registered) { if(!d->m_service) return; d->m_service->unregisterService(); emit registeredChanged(); } if(!d->m_service){ d->m_service = new QBluetoothServiceInfo(); } delete d->m_listen; d->m_listen = 0; d->listen(); connect(d->m_listen, SIGNAL(newConnection()), this, SLOT(new_connection())); d->m_service->setAttribute(QBluetoothServiceInfo::ServiceRecordHandle, (uint)0x00010010); // QBluetoothServiceInfo::Sequence classId; //// classId << QVariant::fromVhttp://theunderstatement.com/alue(QBluetoothUuid(serviceUuid)); // classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort)); // d->m_service->setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId); d->m_service->setAttribute(QBluetoothServiceInfo::ServiceName, d->m_name); d->m_service->setAttribute(QBluetoothServiceInfo::ServiceDescription, d->m_description); d->m_service->setServiceUuid(QBluetoothUuid(d->m_uuid)); qDebug() << "name/uuid" << d->m_name << d->m_uuid << d->m_port; d->m_service->setAttribute(QBluetoothServiceInfo::BrowseGroupList, QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup)); QBluetoothServiceInfo::Sequence protocolDescriptorList; QBluetoothServiceInfo::Sequence protocol; qDebug() << "Port" << d->m_port; if(d->m_protocol == "l2cap"){ protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap)) << QVariant::fromValue(quint16(d->m_port)); protocolDescriptorList.append(QVariant::fromValue(protocol)); } else if(d->m_protocol == "rfcomm"){ protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm)) << QVariant::fromValue(quint8(d->m_port)); protocolDescriptorList.append(QVariant::fromValue(protocol)); } else { qWarning() << "No protocol specified for bluetooth service"; } d->m_service->setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList); if(d->m_service->registerService()) { qDebug() << "registered"; emit registeredChanged(); } else { qDebug() << "Failed"; } }
void WorldSession::SendUpdateObject() { Character* character = GetCharacter(); if (!character) return; WorldPacket data(SMSG_UPDATE_OBJECT); data << quint8(0); data << quint8(1); data << quint8(0); data << character->GetGuid(); data.StartBlock<quint16>(); { data << quint8(7); data << character->GetGuid(); data << quint8(0); data << GetAccountInfos().id; data.WriteString(character->GetName(), true); data << character->GetBreed(); data << character->GetPositionX(); data << character->GetPositionY(); data << character->GetPositionZ(); data << character->GetInstanceId(); data << character->GetDirection(); // *** Skin data << character->GetGender(); data << character->GetSkinColor(); data << character->GetHairColor(); data << character->GetPupilColor(); data << character->GetSkinColorFactor(); data << character->GetHairColorFactor(); data << character->GetClothIndex(); data << character->GetFaceIndex(); data << qint16(-1); // Titles // PUBLIC_CHARACTERISTICS data << quint16(0); // size // FIGHT_PROPERTIES data << quint8(0); // hasProperties // FIGHT data << qint32(-1); // currentFightId data << quint8(0); // isKo data << quint8(0); // isDead data << quint8(0); // isSummonned data << quint8(0); // isFleeing data << qint8(-1); // obstacleId data << quint8(0); // hasSummon // EQUIPMENT_APPEARANCE data << quint16(0); // Views size // RUNNING_EFFECTS data << quint8(0); // hasInFightData data << quint8(0); // hasOutFightData // CURRENT_MOVEMENT_PATH data << quint8(0); // hasCurrentPath // WORLD_PROPERTIES data << quint8(0); // hasProperties // GROUP data << quint64(0); // partyId // TEMPLATE data << quint16(0); // sightRadius data << quint16(0); // aggroRadius // COLLECT data << quint16(0); // unavailableActions size // OCCUPATION data << quint8(0); // hasOccupation // XP data << character->GetXP(); // XP_CHARACTERISTICS data << character->GetXPFreePoints(); data << quint16(0); // xpBonusPoints size data << quint16(0); // characteristicBonusPoints size data << character->GetXPGauge(); // Should be named WakfuGauge... // CITIZEN_POINT data << quint16(0); // nationCitizenScores data << quint16(0); // offendedNations // GUILD_REMOTE_INFO data << character->GetGuildId(); data << quint64(0); // Blazon data << quint16(0); // Level data << quint16(0); // GuildName // NATION_ID data << quint32(0); // NationId // NATION_SYNCHRO data << quint64(0); // rank data << quint64(0); // jobs data << quint64(0); // vote data << quint8(0); // governmentOpinion data << quint8(0); // isCandidate // SOCIAL_STATES data << quint8(0); // afkState data << quint8(0); // dndState // PET data << quint8(0); // hasPet // ACCOUNT_INFORMATION_REMOTE data << quint32(0); // subscriptionLevel data << quint16(0); // additionalRights size // COMPANION_CONTROLLER_ID data << quint64(0); // controllerId data << quint64(0); // companionId } data.EndBlock<quint16>(); SendPacket(data); }
bool Parser::parseBCON(QVariant &res, QString* key) { char c = read<quint8>(); if (c & 0x80) { qint32 len; len = c & 0x3F; char buf[len]; for (int i = 0; i < len; i++) { buf[i] = read<quint8>(); } res = (c & 0x40) ? QString::fromUtf8(buf, len) : QByteArray(buf, len); } else if (c & 0xF0) { qint32 len; len = c & 0x0F; switch (c & 0x30) { case 0x10: len |= read<quint8>() << 4; break; case 0x20: len |= (read<quint8>() << 4) | (read<quint8>() << 12); break; case 0x30: len |= (read<quint8>() << 4) | (read<quint8>() << 12) | (read<quint8>() << 20); break; default: throw ParserException("Invalid " + QString((c & 0x40) ? "BCON_TOKEN_STRING" : "BCON_TOKEN_DATA") + " type " + QString::number(quint8(c & 0x30), 16)); } char buf[len]; for (int i = 0; i < len; i++) { buf[i] = read<quint8>(); } res = (c & 0x40) ? QString::fromUtf8(buf, len) : QByteArray(buf, len); } else { switch (c) { case BCON_TOKEN_END: return false; case BCON_TOKEN_NULL: res = QVariant(); break; case BCON_TOKEN_TRUE: res = QVariant(true); break; case BCON_TOKEN_FALSE: res = QVariant(false); break; case BCON_TOKEN_BYTE: res = QVariant(read<quint8>()); break; case BCON_TOKEN_INT16: res = QVariant(read<qint16>()); break; case BCON_TOKEN_UINT16: res = QVariant(read<quint16>()); break; case BCON_TOKEN_INT32: res = QVariant(read<qint32>()); break; case BCON_TOKEN_UINT32: res = QVariant(read<quint32>()); break; case BCON_TOKEN_INT64: res = QVariant(read<qlonglong>()); break; case BCON_TOKEN_UINT64: res = QVariant(read<qulonglong>()); break; case BCON_TOKEN_DOUBLE: res = QVariant(read<double>()); break; case BCON_TOKEN_DATETIME: res = QVariant(QDateTime::fromMSecsSinceEpoch(read<qlonglong>())); break; case BCON_TOKEN_LIST: { QVariantList list; while (true) { QVariant value; if (!parseBCON(value, NULL)) break; list.append(value); } res = list; break; } case BCON_TOKEN_MAP: { QVariantMap map; while (true) { QString key; QVariant value; if (!parseBCON(value, &key)) break; map[key] = value; } res = map; break; } default: throw ParserException("Invalid token " + c); } } if (key) { while ((c = read<quint8>()) != '\0') { key->append(c); } } return true; }
void OnActive(Character* character, InteractiveElementType /*type*/) { // Seuelement une instance du script ou bien ? Du coup va poser des problèmes // si plusieurs joueurs en même temps ? Du coup gérer la création de nouvelles instances de scripts ? m_char = character; // Envoie comme quoi l'élémentId n'est plus "usable" (différence avec le paquet de spawn 200) WorldPacket data(SMSG_INTERACTIVE_ELEMENT_UPDATE); data << quint64(20114); // Instance ElementId data.StartBlock<quint16>(); { data << quint8(1); // BlockCount data << quint8(2); // blockId data << quint32(6); // offset data << quint8(2); // BlockId data << quint16(1); // ? data << quint8(1); // isVisible data << quint8(0); // isUsable data << quint8(0); // ? data << quint8(0); // ? data << quint8(0); // ? data << quint32(0); // ? } data.EndBlock<quint16>(); character->GetSession()->SendPacket(data); // Spawn Wapin WorldPacket data2(SMSG_UPDATE_OBJECT); data2 << quint8(0); data2 << quint8(1); data2 << quint8(1); data2 << qint64(-1706442045669898); data2.StartBlock<quint16>(); { data2 << quint8(7); // GUID data2 << qint64(-1706442045669898); // IDENTITY data2 << quint8(1); data2 << qint64(-1); // NAME data2 << quint16(0); // BREED data2 << quint16(2644); // POSITION data2 << qint32(0); // X data2 << qint32(-17); // Y data2 << qint16(0); // Z data2 << quint16(-1); // InstanceId data2 << quint8(3); // Direction // APPEARANCE data2 << quint8(1); // Show // PUBLIC_CHARACTERISTICS data2 << quint16(1); // Level data2 << quint16(0); // States size // FIGHT_PROPERTIES data2 << quint8(0); // hasProperties // FIGHT data2 << qint32(-1); // currentFightId data2 << quint8(0); // isKo data2 << quint8(0); // isDead data2 << quint8(0); // isSummoned data2 << quint8(0); // isFleeing data2 << qint8(-1); // obstacleId data2 << quint8(0); // hasSummon // EQUIPMENT_APPEARANCE data2 << quint8(0); // size // RUNNING_EFFECTS data2 << quint8(1); // hasInFightData data2 << quint16(1); // data size data2 << quint8(13); // data data2 << quint8(1); // hasOutFightData data2 << quint16(0); // size // CURRENT_MOVEMENT_PATH data2 << quint8(0); // hasCurrentPath // WORLD_PROPERTIES data2 << quint8(0); // hasProperties // GROUP data2 << quint64(79645873605204); // PartyId data2 << quint16(1); // Members size data2 << qint16(-1); // breedId data2 << qint16(-1); // Level // TEMPLATE data2 << quint16(0); // sightRadius data2 << quint16(0); // aggroRadius // COLLECT data2 << quint16(0); // OCCUPATION data2 << quint8(0); // XP data2 << quint64(0); // XP_CHARACTERISTICS data2 << quint16(0); data2 << quint16(0); //data2 << quint16(0); //data2 << quint32(0); // Pourquoi sniff size 110 et la on est déjà à 117 ?? } data2.EndBlock<quint16>(); character->GetSession()->SendPacket(data2); // Activation du script (mouvement de la fenêtre entre autre) // Root aussi le joueur ? WorldPacket data3(SMSG_SCENARIO_SCRIPT); data3 << quint8(0); // Event data3 << quint32(12603); // Function data3 << quint32(1611); // ScenarioId data3 << quint8(1); // Long size? data3 << qint64(-1706442045669898); // Param character->GetSession()->SendPacket(data3); // Spawn Kano WorldPacket data4(SMSG_UPDATE_OBJECT); data4 << quint8(0); data4 << quint8(1); data4 << quint8(1); data4 << qint64(-1706442045669878); data4.StartBlock<quint16>(); { data4 << quint8(7); // GUID data4 << qint64(-1706442045669878); // IDENTITY data4 << quint8(1); data4 << qint64(-1); // NAME data4 << quint16(0); // BREED data4 << quint16(2694); // POSITION data4 << qint32(0); // X data4 << qint32(-21); // Y data4 << qint16(3); // Z data4 << quint16(-1); // InstanceId data4 << quint8(3); // Direction // APPEARANCE data4 << quint8(1); // Show // PUBLIC_CHARACTERISTICS data4 << quint16(100); // Level data4 << quint16(0); // States size // FIGHT_PROPERTIES data4 << quint8(0); // hasProperties // FIGHT data4 << qint32(-1); // currentFightId data4 << quint8(0); // isKo data4 << quint8(0); // isDead data4 << quint8(0); // isSummoned data4 << quint8(0); // isFleeing data4 << qint8(-1); // obstacleId data4 << quint8(0); // hasSummon // EQUIPMENT_APPEARANCE data4 << quint8(0); // size // RUNNING_EFFECTS should be wrong data4 << quint8(1); // hasInFightData data4 << quint16(1); // data size data4 << quint8(13); // data data4 << quint8(1); // hasOutFightData data4 << quint16(0); // size // CURRENT_MOVEMENT_PATH data4 << quint8(0); // hasCurrentPath // WORLD_PROPERTIES data4 << quint8(0); // hasProperties // GROUP data4 << quint64(79645873605204); // PartyId data4 << quint16(1); // Members size data4 << qint16(-1); // breedId data4 << qint16(-1); // Level // TEMPLATE data4 << quint16(0); // sightRadius data4 << quint16(0); // aggroRadius // COLLECT data4 << quint16(0); // OCCUPATION data4 << quint8(0); // XP data4 << quint64(0); // XP_CHARACTERISTICS data4 << quint16(0); data4 << quint16(0); //data4 << quint16(0); //data4 << quint32(0); // Pourquoi sniff size 110 et la on est déjà à 117 ?? } data4.EndBlock<quint16>(); character->GetSession()->SendPacket(data4); // Texte : "Hé toi le nouveau" etc. WorldPacket data5(SMSG_SCENARIO_SCRIPT); data5 << quint8(0); // Event data5 << quint32(12687); // Function data5 << quint32(1611); // ScenarioId data5 << quint8(1); // Params size? data5 << qint64(-1706442045669878); // Param character->GetSession()->SendPacket(data5); // Flèche sur le wapin WorldPacket data6(SMSG_SCENARIO_SCRIPT); data6 << quint8(0); // Event data6 << quint32(12691); // Function data6 << quint32(1611); // ScenarioId data6 << quint8(1); // Long size? data6 << qint64(-1706442045669898); // Param character->GetSession()->SendPacket(data6); m_spawned = true; }
void UdpServerThread::processPendingDatarams() { QByteArray data; do{ data.resize(m_udpServer.pendingDatagramSize()); m_udpServer.readDatagram(data.data(),data.size()); }while(m_udpServer.hasPendingDatagrams()); QDataStream in(&data,QIODevice::ReadOnly); in.setVersion(QDataStream::Qt_4_8); AzSocketInfo sockInfo; AzIrisInfo irisInfo; //quint16 cmdHead; //qint8 command; //quint16 datasize; ConfigSettings *settings; QByteArray qbaHostAddress; QByteArray qbaDeviceSN; in>>sockInfo.commandHead>>sockInfo.command>>sockInfo.dataSize; QT_TRY{ if(QString::number(sockInfo.commandHead,16)=="ccff") { switch(sockInfo.command) { case 0x01://setting settings= new ConfigSettings(); in>>settings->pid>>qbaDeviceSN>>qbaHostAddress>>settings->port>>settings->seriesId>>settings->mode>>settings->allowSwitchMode >>settings->allowEnroll; settings->deviceSN=QString::fromAscii(qbaDeviceSN); settings->hostAddress=QString::fromAscii(qbaHostAddress); emit updateSettings(settings); qDebug()<<"CC-FF-01"; break; case 0x02://personinfo irisInfo.command = sockInfo.command; irisInfo.dataSize = sockInfo.dataSize; in>>irisInfo.personId>>irisInfo.if_UserNo>>irisInfo.leftIrisTemplate >>irisInfo.rightIrisTemplate; irisInfo.commandHead = QString::number(sockInfo.commandHead,16).toUpper(); qDebug()<<irisInfo.commandHead<<quint8(0x02); emit readingDatagrams(irisInfo); break; case 0x03: //Enroll 注册人员 dzrun.enrollMode = true; in>>irisInfo.pid>>irisInfo.personId>>irisInfo.if_UserNo; dzrun.enrollPerson->personId = irisInfo.personId; dzrun.enrollPerson->if_UserNo = irisInfo.if_UserNo; qDebug()<<"Enroll person "<<irisInfo.personId; emit enrollPerson(irisInfo); break; case 0x04://delete in>>irisInfo.personId; qDebug()<<"CC-FF-04"; emit deletePerson(irisInfo.personId); break; default: break; } } if(QString::number(sockInfo.commandHead,16)=="ccaa") //answer { switch(sockInfo.command) { case 0x01: qint32 nums; in>>nums; emit deleteRecord(nums); break; default: break; } } }QT_CATCH(...){ } in.device()->close(); }