QList<MessagePtr> BlankCanvasLoader::loadInitCommands() { QList<MessagePtr> msgs; msgs.append(MessagePtr(new protocol::CanvasResize(1, 0, _size.width(), _size.height(), 0))); msgs.append(MessagePtr(new protocol::LayerCreate(1, 1, 0, _color.rgba(), 0, QGuiApplication::tr("Background")))); msgs.append(MessagePtr(new protocol::LayerCreate(1, 2, 0, 0, 0, QGuiApplication::tr("Foreground")))); return msgs; }
QList<MessagePtr> ImageCanvasLoader::loadInitCommands() { if(m_filename.endsWith(".ora", Qt::CaseInsensitive)) { // Load OpenRaster image // TODO identify by filetype magic? openraster::OraResult ora = openraster::loadOpenRaster(m_filename); if(!ora.error.isEmpty()) { m_error = ora.error; return QList<MessagePtr>(); } if(ora.warnings != openraster::OraResult::NO_WARNINGS) { QString text = QGuiApplication::tr("Drawpile does not support all the features used in this OpenRaster file. Saving this file may result in data loss.\n"); if((ora.warnings & openraster::OraResult::ORA_EXTENDED)) text += "\n- " + QGuiApplication::tr("Application specific extensions are used"); if((ora.warnings & openraster::OraResult::ORA_NESTED)) text += "\n- " + QGuiApplication::tr("Nested layers are not fully supported."); m_warning = text; } return ora.commands; } else { // Load an image using Qt's image loader. // If the image is animated, each frame is loaded as a layer QList<MessagePtr> msgs; QImageReader ir(m_filename); int layerId = 1; while(true) { QImage image = ir.read(); if(image.isNull()) { if(layerId>1) break; m_error = ir.errorString(); return QList<MessagePtr>(); } if(layerId==1) { msgs << MessagePtr(new protocol::CanvasResize(1, 0, image.size().width(), image.size().height(), 0)); } image = image.convertToFormat(QImage::Format_ARGB32); msgs << MessagePtr(new protocol::LayerCreate(1, layerId, 0, 0, 0, QStringLiteral("Layer %1").arg(layerId))); msgs << net::command::putQImage(1, layerId, 0, 0, image, paintcore::BlendMode::MODE_REPLACE); ++layerId; } return msgs; } }
QList<MessagePtr> QImageCanvasLoader::loadInitCommands() { QList<MessagePtr> msgs; QImage image = _image.convertToFormat(QImage::Format_ARGB32); msgs.append(MessagePtr(new protocol::CanvasResize(1, 0, image.size().width(), image.size().height(), 0))); msgs.append(MessagePtr(new protocol::LayerCreate(1, 1, 0, 0, 0, "Background"))); msgs.append(net::command::putQImage(1, 1, 0, 0, image, paintcore::BlendMode::MODE_REPLACE)); return msgs; }
void GoGoClient::OnCharList() { using protocol::Match_ResponseAccountCharList; typedef SmallVector<CharacterEntry, 4> CharList; if(!myAccount.isValid) return transmitter->disconnect("Tried to get a char list without first logging in."); CharList charList = database->GetCharacterList(myAccount); blob charBlob(charList.size(), 34); if (charList.size() == 0) { charBlob.add_param(packet::zeros(32)); } else { for (CharList::iterator i = charList.begin(), e = charList.end(); i != e; ++i) { charBlob .add_param(blob_string(i->name.c_str(), 32)) .add_param(uint8(i->index)) .add_param(uint8(i->level)) ; } } transmitter->send(Match_ResponseAccountCharList(charBlob)); myPlace = gunz::MP_CHARACTER; }
void fullnode::start() { // Subscribe to new connections. protocol_.subscribe_channel( std::bind(&fullnode::connection_started, this, _1, _2)); // Start blockchain. Must finish before any operations // are performed on the database (or they will fail). std::promise<std::error_code> ec_promise; auto blockchain_started = [&ec_promise](const std::error_code& ec) { ec_promise.set_value(ec); }; chain_.start("blockchain", blockchain_started); std::error_code ec = ec_promise.get_future().get(); if (ec) { log_error() << "Problem starting blockchain: " << ec.message(); return; } // Start transaction pool txpool_.start(); // Fire off app. auto handle_start = std::bind(&fullnode::handle_start, this, _1); session_.start(handle_start); }
void Session::removeUser(Client *user) { Q_ASSERT(m_clients.contains(user)); if(user->id() == m_initUser && m_state == Reset) { // Whoops, the resetter left before the job was done! // We simply cancel the reset in that case and go on m_initUser = 0; m_resetstream.clear(); switchState(Running); } m_clients.removeOne(user); addToCommandStream(MessagePtr(new protocol::UserLeave(user->id()))); ensureOperatorExists(); // Reopen the session when the last user leaves if(m_clients.isEmpty()) { setClosed(false); } user->deleteLater(); m_lastEventTime = QDateTime::currentDateTime(); emit userDisconnected(this); }
void Client::sendSystemChat(const QString &message) { protocol::ServerReply msg { protocol::ServerReply::MESSAGE, message, QJsonObject() }; d->msgqueue->send(MessagePtr(new protocol::Command(0, msg.toJson()))); }
void connection_started(const std::error_code& ec, channel_ptr node, protocol& prot) { if (ec) { log_warning() << "Couldn't start connection: " << ec.message(); return; } log_info() << "Connection established."; // Resubscribe to new nodes. prot.subscribe_channel( std::bind(connection_started, _1, _2, std::ref(prot))); }
void fullnode::connection_started(const std::error_code& ec, channel_ptr node) { if (ec) { log_warning() << "Couldn't start connection: " << ec.message(); return; } // Subscribe to transaction messages from this node. node->subscribe_transaction( std::bind(&fullnode::recv_tx, this, _1, _2, node)); // Stay subscribed to new connections. protocol_.subscribe_channel( std::bind(&fullnode::connection_started, this, _1, _2)); }
QList<MessagePtr> SnapshotLoader::loadInitCommands() { QList<MessagePtr> msgs; // Most important bit first: canvas initialization const QSize imgsize = m_layers->size(); msgs.append(MessagePtr(new protocol::CanvasResize(m_contextId, 0, imgsize.width(), imgsize.height(), 0))); // Preset default layer if(m_session && m_session->layerlist()->defaultLayer()>0) msgs.append(MessagePtr(new protocol::DefaultLayer(m_contextId, m_session->layerlist()->defaultLayer()))); // Create layers for(int i=0;i<m_layers->layerCount();++i) { const paintcore::Layer *layer = m_layers->getLayerByIndex(i); const QColor fill = layer->isSolidColor(); msgs.append(MessagePtr(new protocol::LayerCreate(m_contextId, layer->id(), 0, fill.isValid() ? fill.rgba() : 0, 0, layer->title()))); msgs.append(MessagePtr(new protocol::LayerAttributes(m_contextId, layer->id(), layer->opacity(), 1))); if(!fill.isValid()) msgs.append(net::command::putQImage(m_contextId, layer->id(), 0, 0, layer->toImage(), paintcore::BlendMode::MODE_REPLACE)); if(m_session && m_session->stateTracker()->isLayerLocked(layer->id())) msgs.append(MessagePtr(new protocol::LayerACL(m_contextId, layer->id(), true, QList<uint8_t>()))); } // Create annotations for(const paintcore::Annotation &a : m_layers->annotations()->getAnnotations()) { const QRect g = a.rect; msgs.append(MessagePtr(new protocol::AnnotationCreate(m_contextId, a.id, g.x(), g.y(), g.width(), g.height()))); msgs.append((MessagePtr(new protocol::AnnotationEdit(m_contextId, a.id, a.background.rgba(), 0, 0, a.text)))); } // User tool changes if(m_session) { QHashIterator<int, canvas::DrawingContext> iter(m_session->stateTracker()->drawingContexts()); while(iter.hasNext()) { iter.next(); msgs.append(net::command::brushToToolChange( iter.key(), iter.value().tool.layer_id, iter.value().tool.brush )); } } return msgs; }
void connection_started(const std::error_code& ec, channel_ptr node, protocol& prot, tx_watch& watch) { if (ec) { log_warning() << "Couldn't start connection: " << ec.message(); return; } log_info() << "Connection established."; // Subscribe to inventory packets. node->subscribe_inventory( std::bind(inventory_received, _1, _2, node, std::ref(watch))); // Resubscribe to new nodes. prot.subscribe_channel( std::bind(connection_started, _1, _2, std::ref(prot), std::ref(watch))); }
void send_tx(const std::error_code& ec, channel_ptr node, protocol& prot, transaction_type& tx) { check_error(ec); std::cout << "sendtx-p2p: Sending " << hash_transaction(tx) << std::endl; auto handle_send = [](const std::error_code& ec) { if (ec) log_warning() << "Send failed: " << ec.message(); else std::cout << "sendtx-p2p: Sent " << time(nullptr) << std::endl; }; node->send(tx, handle_send); prot.subscribe_channel( std::bind(send_tx, _1, _2, std::ref(prot), std::ref(tx))); }
QList<MessagePtr> SnapshotLoader::loadInitCommands() { QList<MessagePtr> msgs; // Most important bit first: canvas initialization const QSize imgsize = _session->image()->size(); msgs.append(MessagePtr(new protocol::CanvasResize(1, 0, imgsize.width(), imgsize.height(), 0))); // Less important, but it's nice to see it straight away if(!_session->title().isEmpty()) msgs.append((MessagePtr(new protocol::SessionTitle(1, _session->title())))); // Create layers for(int i=0;i<_session->image()->layers();++i) { const paintcore::Layer *layer = _session->image()->getLayerByIndex(i); msgs.append(MessagePtr(new protocol::LayerCreate(1, layer->id(), 0, 0, 0, layer->title()))); msgs.append(MessagePtr(new protocol::LayerAttributes(1, layer->id(), layer->opacity(), 1))); msgs.append(net::putQImage(1, layer->id(), 0, 0, layer->toImage(), paintcore::BlendMode::MODE_REPLACE)); if(_session->isLayerLocked(layer->id())) msgs.append(MessagePtr(new protocol::LayerACL(1, layer->id(), true, QList<uint8_t>()))); } // Create annotations foreach(const paintcore::Annotation *a, _session->image()->annotations()) { const QRect g = a->rect(); msgs.append(MessagePtr(new protocol::AnnotationCreate(1, a->id(), g.x(), g.y(), g.width(), g.height()))); msgs.append((MessagePtr(new protocol::AnnotationEdit(1, a->id(), a->backgroundColor().rgba(), a->text())))); } // User tool changes QHashIterator<int, drawingboard::DrawingContext> iter(_session->drawingContexts()); while(iter.hasNext()) { iter.next(); msgs.append(net::brushToToolChange( iter.key(), iter.value().tool.layer_id, iter.value().tool.brush )); } return msgs; }
void Client::sendChat(const QString &message, bool announce, bool action) { _server->sendMessage(MessagePtr(new protocol::Chat(m_myId, message, announce, action))); }
QList<MessagePtr> ImageCanvasLoader::loadInitCommands() { if(_filename.endsWith(".ora", Qt::CaseInsensitive)) { // Load OpenRaster image using openraster::Reader; // TODO identify by filetype magic? Reader reader; if(reader.load(_filename) == false) { _error = reader.error(); return QList<MessagePtr>(); } if(reader.warnings() != Reader::NO_WARNINGS) { QString text = QApplication::tr("Drawpile does not support all the features used in this OpenRaster file. Saving this file may result in data loss.\n"); if((reader.warnings() & Reader::ORA_EXTENDED)) text += "\n- " + QApplication::tr("Application specific extensions are used"); if((reader.warnings() & Reader::ORA_NESTED)) text += "\n- " + QApplication::tr("Nested layers are not fully supported."); QMessageBox::warning(0, QApplication::tr("Partially supported OpenRaster"), text); } return reader.initCommands(); } else if(_filename.endsWith(".dptxt", Qt::CaseInsensitive)) { TextCommandLoader txt(filename()); if(!txt.load()) { _error = txt.errorMessage(); return QList<MessagePtr>(); } return txt.loadInitCommands(); } else { // Load an image using Qt's image loader. // If the image is animated, each frame is loaded as a layer QList<MessagePtr> msgs; QImageReader ir(_filename); int layerId = 1; while(true) { QImage image = ir.read(); if(image.isNull()) { if(layerId>1) break; _error = ir.errorString(); return QList<MessagePtr>(); } if(layerId==1) { msgs << MessagePtr(new protocol::CanvasResize(1, 0, image.size().width(), image.size().height(), 0)); } image = image.convertToFormat(QImage::Format_ARGB32); msgs << MessagePtr(new protocol::LayerCreate(1, layerId, 0, 0, 0, QStringLiteral("Layer %1").arg(layerId))); msgs << net::putQImage(1, layerId, 0, 0, image, paintcore::BlendMode::MODE_REPLACE); ++layerId; } return msgs; } }