InstanceFactory::InstLoadError InstanceFactory::loadInstance(InstancePtr &inst, const QString &instDir) { auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg")); m_settings->registerSetting("InstanceType", "Legacy"); QString inst_type = m_settings->get("InstanceType").toString(); // FIXME: replace with a map lookup, where instance classes register their types if (inst_type == "OneSix" || inst_type == "Nostalgia") { inst.reset(new OneSixInstance(instDir, m_settings, this)); } else if (inst_type == "Legacy") { inst.reset(new LegacyInstance(instDir, m_settings, this)); } else if (inst_type == "LegacyFTB") { inst.reset(new LegacyFTBInstance(instDir, m_settings, this)); } else if (inst_type == "OneSixFTB") { inst.reset(new OneSixFTBInstance(instDir, m_settings, this)); } else { return InstanceFactory::UnknownLoadError; } inst->init(); return NoLoadError; }
IceObjC::StreamAcceptor::StreamAcceptor(const StreamEndpointIPtr& endpoint, const InstancePtr& instance, const string& host, int port) : _endpoint(endpoint), _instance(instance), _addr(getAddressForServer(host, port, instance->protocolSupport(), instance->preferIPv6(), true)) { #ifdef SOMAXCONN _backlog = instance->properties()->getPropertyAsIntWithDefault("Ice.TCP.Backlog", SOMAXCONN); #else _backlog = instance->properties()->getPropertyAsIntWithDefault("Ice.TCP.Backlog", 511); #endif try { _fd = createSocket(false, _addr); setBlock(_fd, false); setTcpBufSize(_fd, _instance); setReuseAddress(_fd, true); } catch(...) { _fd = INVALID_SOCKET; throw; } }
IceInternal::TcpTransceiver::TcpTransceiver(const InstancePtr& instance, SOCKET fd, bool connected) : NativeInfo(fd), _traceLevels(instance->traceLevels()), _logger(instance->initializationData().logger), _stats(instance->initializationData().stats), _state(connected ? StateConnected : StateNeedConnect), _desc(connected ? fdToString(_fd) : string()) #ifdef ICE_USE_IOCP , _read(SocketOperationRead), _write(SocketOperationWrite) #endif { setBlock(_fd, false); setTcpBufSize(_fd, instance->initializationData().properties, _logger); #ifdef ICE_USE_IOCP // // On Windows, limiting the buffer size is important to prevent // poor throughput performances when transfering large amount of // data. See Microsoft KB article KB823764. // _maxSendPacketSize = IceInternal::getSendBufferSize(fd) / 2; if(_maxSendPacketSize < 512) { _maxSendPacketSize = 0; } _maxReceivePacketSize = IceInternal::getRecvBufferSize(fd); if(_maxReceivePacketSize < 512) { _maxReceivePacketSize = 0; } #endif }
IceInternal::TcpConnector::TcpConnector(const InstancePtr& instance, const Address& addr, Ice::Int timeout, const string& connectionId) : _instance(instance), _traceLevels(instance->traceLevels()), _logger(instance->initializationData().logger), _addr(addr), _timeout(timeout), _connectionId(connectionId) { }
/// Add an instance. Triggers notifications, returns the new index int InstanceList::add(InstancePtr t) { beginInsertRows(QModelIndex(), m_instances.size(), m_instances.size()); m_instances.append(t); t->setParent(this); connect(t.data(), SIGNAL(propertiesChanged(BaseInstance*)),this, SLOT(propertiesChanged(BaseInstance*))); connect(t.data(), SIGNAL(groupChanged()),this, SLOT(groupChanged())); connect(t.data(), SIGNAL(nuked(BaseInstance*)), this, SLOT(instanceNuked(BaseInstance*))); endInsertRows(); return count() - 1; }
InstanceFactory::InstCreateError InstanceFactory::createInstance(InstancePtr &inst, BaseVersionPtr version, const QString &instDir, const InstanceFactory::InstType type) { QDir rootDir(instDir); QLOG_DEBUG() << instDir.toUtf8(); if (!rootDir.exists() && !rootDir.mkpath(".")) { return InstanceFactory::CantCreateDir; } auto mcVer = std::dynamic_pointer_cast<MinecraftVersion>(version); if (!mcVer) return InstanceFactory::NoSuchVersion; auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg")); m_settings->registerSetting("InstanceType", "Legacy"); if (type == NormalInst) { m_settings->set("InstanceType", "OneSix"); inst.reset(new OneSixInstance(instDir, m_settings, this)); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); } else if (type == FTBInstance) { if(mcVer->usesLegacyLauncher()) { m_settings->set("InstanceType", "LegacyFTB"); inst.reset(new LegacyFTBInstance(instDir, m_settings, this)); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); } else { m_settings->set("InstanceType", "OneSixFTB"); inst.reset(new OneSixFTBInstance(instDir, m_settings, this)); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); } } else { delete m_settings; return InstanceFactory::NoSuchVersion; } inst->init(); // FIXME: really, how do you even know? return InstanceFactory::NoCreateError; }
CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent) :QDialog(parent), ui(new Ui::CopyInstanceDialog), m_original(original) { MultiMCPlatform::fixWM_CLASS(this); ui->setupUi(this); resize(minimumSizeHint()); layout()->setSizeConstraint(QLayout::SetFixedSize); InstIconKey = original->iconKey(); ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey)); ui->instNameTextBox->setText(original->name()); ui->instNameTextBox->setFocus(); }
/* void MainWindow::on_instanceView_customContextMenuRequested(const QPoint &pos) { QMenu *instContextMenu = new QMenu("Instance", this); // Add the actions from the toolbar to the context menu. instContextMenu->addActions(ui->instanceToolBar->actions()); instContextMenu->exec(view->mapToGlobal(pos)); } */ void MainWindow::instanceActivated(QModelIndex index) { if (!index.isValid()) return; QString id = index.data(InstanceList::InstanceIDRole).toString(); InstancePtr inst = MMC->instances()->getInstanceById(id); if(!inst) return; NagUtils::checkJVMArgs(inst->settings().get("JvmArgs").toString(), this); doLaunch(); }
void MainWindow::on_actionCopyInstance_triggered() { if (!m_selectedInstance) return; CopyInstanceDialog copyInstDlg(m_selectedInstance, this); if (!copyInstDlg.exec()) return; QString instancesDir = MMC->settings()->get("InstanceDir").toString(); QString instDirName = DirNameFromString(copyInstDlg.instName(), instancesDir); QString instDir = PathCombine(instancesDir, instDirName); auto &loader = InstanceFactory::get(); InstancePtr newInstance; auto error = loader.copyInstance(newInstance, m_selectedInstance, instDir); QString errorMsg = tr("Failed to create instance %1: ").arg(instDirName); switch (error) { case InstanceFactory::NoCreateError: newInstance->setName(copyInstDlg.instName()); newInstance->setIconKey(copyInstDlg.iconKey()); MMC->instances()->add(newInstance); return; case InstanceFactory::InstExists: { errorMsg += tr("An instance with the given directory name already exists."); CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); break; } case InstanceFactory::CantCreateDir: { errorMsg += tr("Failed to create the instance directory."); CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); break; } default: { errorMsg += tr("Unknown instance loader error %1").arg(error); CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); break; } } }
InstancePtr InstanceList::getInstanceById(QString instId) { QListIterator<InstancePtr> iter(m_instances); InstancePtr inst; while(iter.hasNext()) { inst = iter.next(); if (inst->id() == instId) break; } if (inst->id() != instId) return InstancePtr(); else return iter.peekPrevious(); }
IceSSL::EndpointI::EndpointI(const InstancePtr& instance) : IceInternal::IPEndpointI(instance), _instance(instance), _timeout(instance->defaultTimeout()), _compress(false) { }
Glacier2::FilterManagerPtr Glacier2::FilterManager::create(const InstancePtr& instance, const string& userId, const bool allowAddUser) { PropertiesPtr props = instance->properties(); string allow = props->getProperty("Glacier2.Filter.Category.Accept"); vector<string> allowSeq; stringToSeq(allow, allowSeq); if(allowAddUser) { int addUserMode = 0; if(!props->getProperty("Glacier2.Filter.Category.AcceptUser").empty()) { addUserMode = props->getPropertyAsInt("Glacier2.Filter.Category.AcceptUser"); } if(addUserMode > 0 && !userId.empty()) { if(addUserMode == 1) { allowSeq.push_back(userId); // Add user id to allowed categories. } else if(addUserMode == 2) { allowSeq.push_back('_' + userId); // Add user id with prepended underscore to allowed categories. } } } Glacier2::StringSetIPtr categoryFilter = new Glacier2::StringSetI(allowSeq); // // TODO: refactor initialization of filters. // allow = props->getProperty("Glacier2.Filter.AdapterId.Accept"); stringToSeq(allow, allowSeq); Glacier2::StringSetIPtr adapterIdFilter = new Glacier2::StringSetI(allowSeq); // // TODO: Object id's from configurations? // IdentitySeq allowIdSeq; allow = props->getProperty("Glacier2.Filter.Identity.Accept"); stringToSeq(instance->communicator(), allow, allowIdSeq); Glacier2::IdentitySetIPtr identityFilter = new Glacier2::IdentitySetI(allowIdSeq); return new Glacier2::FilterManager(instance, categoryFilter, adapterIdFilter, identityFilter); }
NodeI::NodeI(const InstancePtr& instance, const ReplicaPtr& replica, const Ice::ObjectPrx& replicaProxy, int id, const map<int, NodePrx>& nodes) : _timer(instance->timer()), _traceLevels(instance->traceLevels()), _observers(instance->observers()), _replica(replica), _replicaProxy(replicaProxy), _id(id), _nodes(nodes), _state(NodeStateInactive), _updateCounter(0), _max(0), _generation(-1), _destroy(false) { map<int, NodePrx> oneway; for(map<int, NodePrx>::const_iterator p = _nodes.begin(); p != _nodes.end(); ++p) { oneway[p->first] = NodePrx::uncheckedCast(p->second->ice_oneway()); } const_cast<map<int, NodePrx>& >(_nodesOneway) = oneway; Ice::PropertiesPtr properties = instance->communicator()->getProperties(); const_cast<IceUtil::Time&>(_masterTimeout) = getTimeout( instance->serviceName() + ".Election.MasterTimeout", 10, properties, _traceLevels); const_cast<IceUtil::Time&>(_electionTimeout) = getTimeout( instance->serviceName() + ".Election.ElectionTimeout", 10, properties, _traceLevels); const_cast<IceUtil::Time&>(_mergeTimeout) = getTimeout( instance->serviceName() + ".Election.ResponseTimeout", 10, properties, _traceLevels); }
OutgoingAsyncBase::OutgoingAsyncBase(const CommunicatorPtr& communicator, const InstancePtr& instance, const string& operation, const CallbackBasePtr& delegate, const LocalObjectPtr& cookie) : AsyncResult(communicator, instance, operation, delegate, cookie), _os(instance.get(), Ice::currentProtocolEncoding) { }
OutgoingAsyncBase::OutgoingAsyncBase(const InstancePtr& instance) : _instance(instance), _sentSynchronously(false), _doneInSent(false), _state(0), _os(instance.get(), Ice::currentProtocolEncoding), _is(instance.get(), Ice::currentProtocolEncoding) { }
IceBT::EndpointI::EndpointI(const InstancePtr& instance) : _instance(instance), _channel(0), _timeout(instance->defaultTimeout()), _compress(false), _hashValue(0), _connectPending(false) { }
IceSSL::AcceptorI::AcceptorI(const InstancePtr& instance, const string& adapterName, const string& host, int port) : _instance(instance), _adapterName(adapterName), _logger(instance->communicator()->getLogger()), _addr(IceInternal::getAddressForServer(host, port, instance->protocolSupport())) #ifdef ICE_USE_IOCP , _acceptFd(INVALID_SOCKET), _info(IceInternal::SocketOperationRead) #endif { #ifdef SOMAXCONN _backlog = instance->communicator()->getProperties()->getPropertyAsIntWithDefault("Ice.TCP.Backlog", SOMAXCONN); #else _backlog = instance->communicator()->getProperties()->getPropertyAsIntWithDefault("Ice.TCP.Backlog", 511); #endif _fd = IceInternal::createSocket(false, _addr.ss_family); #ifdef ICE_USE_IOCP _acceptBuf.resize((sizeof(sockaddr_storage) + 16) * 2); #endif IceInternal::setBlock(_fd, false); IceInternal::setTcpBufSize(_fd, _instance->communicator()->getProperties(), _logger); #ifndef _WIN32 // // Enable SO_REUSEADDR on Unix platforms to allow re-using the // socket even if it's in the TIME_WAIT state. On Windows, // this doesn't appear to be necessary and enabling // SO_REUSEADDR would actually not be a good thing since it // allows a second process to bind to an address even it's // already bound by another process. // // TODO: using SO_EXCLUSIVEADDRUSE on Windows would probably // be better but it's only supported by recent Windows // versions (XP SP2, Windows Server 2003). // IceInternal::setReuseAddress(_fd, true); #endif if(_instance->networkTraceLevel() >= 2) { Trace out(_logger, _instance->networkTraceCategory()); out << "attempting to bind to ssl socket " << toString(); } const_cast<struct sockaddr_storage&>(_addr) = IceInternal::doBind(_fd, _addr); }
void GroupChatMsgArrivedNotify::process(InstancePtr instance, ConnectionPtr connection, const Uri& from, RequestMsg& msg) { group_messaging_server::methods::rpc::GrpChatMsgArrivedNotify notify; if (!notify.ParseFromString(msg.data())) { LOG(error, "parse error! " << DUMP_STRING(msg.data())); throw ParseException(); } data_.reset(new Data); data_->sender = UserPtID(notify.sender_ua_uri(), instance->getDomain()); data_->group_id = GroupID(from, instance->getDomain()); data_->msg_id = notify.msg_id(); data_->msg_time = notify.msg_time(); data_->content = notify.content(); data_->content_type = notify.content_type(); onNotification(instance); }
ConnectionFlushBatch::ConnectionFlushBatch(const ConnectionIPtr& connection, const CommunicatorPtr& communicator, const InstancePtr& instance, const string& operation, const CallbackBasePtr& delegate, const LocalObjectPtr& cookie) : OutgoingAsyncBase(communicator, instance, operation, delegate, cookie), _connection(connection) { _observer.attach(instance.get(), operation); }
Ice::Identity IceStormInternal::nameToIdentity(const InstancePtr& instance, const string& name) { // Identity is instanceName>/topic.<topicname> Ice::Identity id; id.category = instance->instanceName(); id.name = "topic." + name; return id; }
IceSSL::TransceiverI::TransceiverI(const InstancePtr& instance, SOCKET fd, const string& adapterName) : IceInternal::NativeInfo(fd), _instance(instance), _logger(instance->communicator()->getLogger()), _stats(instance->communicator()->getStats()), _ssl(0), _incoming(true), _adapterName(adapterName), _state(StateConnected), _desc(IceInternal::fdToString(fd)) #ifdef ICE_USE_IOCP , _iocpBio(0), _read(IceInternal::SocketOperationRead), _write(IceInternal::SocketOperationWrite) #endif { IceInternal::setBlock(fd, false); IceInternal::setTcpBufSize(fd, _instance->communicator()->getProperties(), _logger); }
SubscriberBatch::SubscriberBatch( const InstancePtr& instance, const SubscriberRecord& rec, const Ice::ObjectPrx& proxy, int retryCount, const Ice::ObjectPrx& obj) : Subscriber(instance, rec, proxy, retryCount, 1), _obj(obj), _interval(instance->flushInterval()) { assert(retryCount == 0); }
IceSSL::ConnectorI::ConnectorI(const InstancePtr& instance, const string& host, const IceInternal::Address& addr, const IceInternal::NetworkProxyPtr& proxy, Ice::Int timeout, const string& connectionId) : _instance(instance), _logger(instance->communicator()->getLogger()), _host(host), _addr(addr), _proxy(proxy), _timeout(timeout), _connectionId(connectionId) { }
IceSSL::TransceiverI::TransceiverI(const InstancePtr& instance, const IceInternal::StreamSocketPtr& stream, const string& hostOrAdapterName, bool incoming) : _instance(instance), _engine(OpenSSLEnginePtr::dynamicCast(instance->engine())), _host(incoming ? "" : hostOrAdapterName), _adapterName(incoming ? hostOrAdapterName : ""), _incoming(incoming), _stream(stream), _verified(false), _ssl(0) { }
BatchRequestQueue::BatchRequestQueue(const InstancePtr& instance, bool datagram) : _interceptor(instance->initializationData().batchRequestInterceptor), _batchStream(instance.get(), Ice::currentProtocolEncoding), _batchStreamInUse(false), _batchStreamCanFlush(false), _batchRequestNum(0) { _batchStream.writeBlob(requestBatchHdr, sizeof(requestBatchHdr)); _batchMarker = _batchStream.b.size(); _maxSize = instance->batchAutoFlushSize(); if(_maxSize > 0 && datagram) { const Ice::InitializationData& initData = instance->initializationData(); size_t udpSndSize = initData.properties->getPropertyAsIntWithDefault("Ice.UDP.SndSize", 65535 - udpOverhead); if(udpSndSize < _maxSize) { _maxSize = udpSndSize; } } }
InstanceFactory::InstCreateError InstanceFactory::copyInstance(InstancePtr &newInstance, InstancePtr &oldInstance, const QString &instDir) { QDir rootDir(instDir); QLOG_DEBUG() << instDir.toUtf8(); if (!copyPath(oldInstance->instanceRoot(), instDir)) { rootDir.removeRecursively(); return InstanceFactory::CantCreateDir; } INISettingsObject settings_obj(PathCombine(instDir, "instance.cfg")); settings_obj.registerSetting("InstanceType", "Legacy"); QString inst_type = settings_obj.get("InstanceType").toString(); if (inst_type == "OneSixFTB") settings_obj.set("InstanceType", "OneSix"); if (inst_type == "LegacyFTB") settings_obj.set("InstanceType", "Legacy"); oldInstance->copy(instDir); auto error = loadInstance(newInstance, instDir); switch (error) { case NoLoadError: return NoCreateError; case NotAnInstance: rootDir.removeRecursively(); return CantCreateDir; default: case UnknownLoadError: rootDir.removeRecursively(); return UnknownCreateError; } }
void MainWindow::updateInstance(InstancePtr instance, AuthSessionPtr session, BaseProfilerFactory *profiler) { auto updateTask = instance->doUpdate(); if (!updateTask) { launchInstance(instance, session, profiler); return; } ProgressDialog tDialog(this); connect(updateTask.get(), &Task::succeeded, [this, instance, session, profiler] { launchInstance(instance, session, profiler); }); connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); tDialog.exec(updateTask.get()); }
IceSSL::TransceiverI::TransceiverI(const InstancePtr& instance, SOCKET fd, const string& host, const IceInternal::Address& addr) : IceInternal::NativeInfo(fd), _instance(instance), _logger(instance->communicator()->getLogger()), _stats(instance->communicator()->getStats()), _ssl(0), _host(host), _incoming(false), _state(StateNeedConnect) #ifdef ICE_USE_IOCP , _iocpBio(0), _read(IceInternal::SocketOperationRead), _write(IceInternal::SocketOperationWrite) #endif { IceInternal::setBlock(fd, false); IceInternal::setTcpBufSize(fd, _instance->communicator()->getProperties(), _logger); #ifndef ICE_USE_IOCP if(IceInternal::doConnect(_fd, addr)) { _state = StateConnected; _desc = IceInternal::fdToString(_fd); if(_instance->networkTraceLevel() >= 1) { Trace out(_logger, _instance->networkTraceCategory()); out << "ssl connection established\n" << _desc; } } else { _desc = IceInternal::fdToString(_fd); } #endif _connectAddr = addr; }
void ConnectRequestHandler::setException(const Ice::LocalException& ex) { Lock sync(*this); assert(!_initialized && !_exception.get()); assert(_updateRequestHandler || _requests.empty()); _exception.reset(ex.ice_clone()); _proxy = 0; // Break cyclic reference count. _delegate = 0; // Break cyclic reference count. // // If some requests were queued, we notify them of the failure. This is done from a thread // from the client thread pool since this will result in ice_exception callbacks to be // called. // if(!_requests.empty()) { const InstancePtr instance = _reference->getInstance(); instance->clientThreadPool()->execute(new FlushRequestsWithException(instance, this, ex)); } notifyAll(); }
std::vector<double> SerialRandomTree::distributionForInstance(InstancePtr instance){ std::vector<double> result; SerialTreeNodePtr nodePtr = m_treeNodes[0]; if(nodePtr->m_Attribute != -1 && instance->missing(nodePtr->m_Attribute)) { // ---------------- missing value // TODO: Fix this function! result = std::vector<double>(m_MotherForest->m_document->getNumClassValues(),0); // split instance up for (int i = 0; i < m_Successors.size(); i++) { std::vector<double> help = m_Successors[i]->distributionForInstance(instance); for (int j = 0; j < help.size(); j++) { result[j] += m_Prop[i] * help[j]; } } } else if(false && nodePtr->m_Attribute != -1 && m_MotherForest->m_document->isNominalAttribute(nodePtr->m_Attribute)) { // ------ nominal while(nodePtr->m_Attribute != -1){ nodePtr = nodePtr->m_children[(int) instance->getValue(nodePtr->m_Attribute)]; } result = nodePtr->m_ClassProbs; } else{ // ------------------------------------------ numeric attributes while(nodePtr->m_Attribute != -1){ if(instance->getValue(nodePtr->m_Attribute) < nodePtr->m_SplitPoint) { nodePtr = nodePtr->m_children[0]; } else{ nodePtr = nodePtr->m_children[1]; } } result = nodePtr->m_ClassProbs; } return result; }