QString ConnectionTester::Private::findDefaultDNS() const { // Inspiration: https://github.com/xbmc/xbmc/blob/8edff7ead55f1a31e55425d47885dc96d3d55105/xbmc/network/linux/NetworkLinux.cpp#L411 #if defined(Q_OS_ANDROID) return propHelper("net.dns1"); #elif defined(Q_OS_LINUX) res_init(); for (int i = 0; i < _res.nscount; ++i) { return QString::fromLatin1(inet_ntoa(((sockaddr_in *)&_res.nsaddr_list[0])->sin_addr)); } return QString(); #elif defined(Q_OS_WIN) QString dns; IP_ADAPTER_ADDRESSES *addresses = NULL; ULONG bufferSize = 0; if (::GetAdaptersAddresses(AF_INET, 0, NULL, addresses, &bufferSize) == ERROR_BUFFER_OVERFLOW) { addresses = (IP_ADAPTER_ADDRESSES *)malloc(bufferSize); if (::GetAdaptersAddresses(AF_INET, 0, NULL, addresses, &bufferSize) == NO_ERROR) { IP_ADAPTER_ADDRESSES *addr = addresses; while (addr) { if (addr->OperStatus == IfOperStatusUp) { IP_ADAPTER_DNS_SERVER_ADDRESS *p = addr->FirstDnsServerAddress; while (p) { if (dns.isEmpty()) { dns = QHostAddress(p->Address.lpSockaddr).toString(); } p = p->Next; } } addr = addr->Next; } } } free(addresses); return dns; #elif defined(Q_OS_MAC) return scutilHelper("show State:/Network/Global/DNS", "0"); #else #error Platform dns code missing! return QString(); #endif }
/** * Called when cloned to clear the cloned links. */ void EditorChunkItemLinkable::clearAllLinks() { // Clear from managers lists WorldManager::instance().linkerManager().removeFromLists(this); // Iterate through the properties of this linker int propCounter = propHelper()->propCount(); for (int i=0; i < propCounter; i++) { DataDescription* pDD = propHelper()->pType()->property( i ); if (!pDD->editable()) continue; // If this property is a linkable property if (propHelper()->isUserDataObjectLink( i )) { propHelper()->propSetToDefault(i); } // If this property is an array of linkable properties else if (propHelper()->isUserDataObjectLinkArray( i )) { PyObjectPtr ob ( propHelper()->propGetPy( i ), PyObjectPtr::STEAL_REFERENCE ); SequenceDataType* dataType = static_cast<SequenceDataType*>( pDD->dataType() ); ArrayPropertiesHelper propArray; propArray.init(chunkItem(), &(dataType->getElemType()), ob.getObject()); // Iterate through the array of links while (propArray.propCount()) { // Delete the link propArray.delItem(0); } } } // Save changes chunkItem()->edSave( chunkItem()->pOwnSect() ); if ( chunkItem()->chunk() != NULL ) WorldManager::instance().changedChunk( chunkItem()->chunk() ); }
/** * This method returns true if the linker has links to the linker identified * by "guid"/"chunkId". * * @param guid GUID of the linker to search in this linker's properties. * @param chunkId Chunk if the linker to search in this linker's properties. * @return true if this linker has links to "guid" */ bool EditorChunkItemLinkable::hasLinksTo(const UniqueID& guid, const std::string& chunkId) { // look for more links to "guid" int propCounter = propHelper()->propCount(); for (int i=0; i < propCounter; i++) { DataDescription* pDD = propHelper()->pType()->property( i ); if (!pDD->editable()) continue; // Is this property a user data object link if (propHelper()->isUserDataObjectLink( i )) { PyObjectPtr ob( propHelper()->propGetPy( i ), PyObjectPtr::STEAL_REFERENCE ); std::string propId = PyString_AsString( PyTuple_GetItem( ob.getObject(), 0 ) ); std::string propChunkId = PyString_AsString( PyTuple_GetItem( ob.getObject(), 1 ) ); if ( propId == guid.toString() && propChunkId == chunkId ) return true; } // Is this property an array of user data object links else if (propHelper()->isUserDataObjectLinkArray( i )) { PyObjectPtr ob( propHelper()->propGetPy( i ), PyObjectPtr::STEAL_REFERENCE ); SequenceDataType* dataType = static_cast<SequenceDataType*>( pDD->dataType() ); ArrayPropertiesHelper propArray; propArray.init(this->chunkItem(),&(dataType->getElemType()), ob.getObject()); // Iterate through the array of links for(int j = 0; j < propArray.propCount(); j++) { PyObjectPtr aob( propArray.propGetPy( j ), PyObjectPtr::STEAL_REFERENCE ); std::string propId = PyString_AsString( PyTuple_GetItem( aob.getObject(), 0 ) ); std::string propChunkId = PyString_AsString( PyTuple_GetItem( aob.getObject(), 1 ) ); if ( propId == guid.toString() && propChunkId == chunkId ) return true; } } } return false; }
/** * Method indicating whether this item's chunk is writable. * * @return True if writable, false otherwise. */ bool EditorChunkItemLinkable::linkedChunksWriteable() { ChunkDirMapping* dirMap = WorldManager::instance().chunkDirMapping(); int16 gridX, gridZ; // process forward links int propCounter = propHelper()->propCount(); for (int i=0; i < propCounter; i++) { DataDescription* pDD = propHelper()->pType()->property( i ); if (!pDD->editable()) continue; // Is this property a user data object link if (propHelper()->isUserDataObjectLink( i )) { PyObjectPtr ob( propHelper()->propGetPy( i ), PyObjectPtr::STEAL_REFERENCE ); std::string id = PyString_AsString( PyTuple_GetItem( ob.getObject(), 0 ) ); std::string chunkId = PyString_AsString( PyTuple_GetItem( ob.getObject(), 1 ) ); if ( id == "" || chunkId == "" ) continue; // Force load the linker since we need to examine its parent chunk EditorChunkItemLinkable* linkableUDO = WorldManager::instance().linkerManager().forceLoad( id, chunkId ); // If the chunk is not an outside chunk, see if it's writeable if (linkableUDO && linkableUDO->chunkItem()->chunk()) { if (!EditorChunkCache::instance( *linkableUDO->chunkItem()->chunk() ).edIsWriteable()) { return false; } } else { //ERROR_MSG( // "EditorChunkItemLinkable::linkedChunksWriteable : " // "Need access to parent chunk!\n" ); if (!dirMap->gridFromChunkName( chunkId, gridX, gridZ ) || !EditorChunk::outsideChunkWriteable( gridX, gridZ, false ) ) { return false; } } } // Is this property an array of user data object links else if (propHelper()->isUserDataObjectLinkArray( i )) { PyObjectPtr ob( propHelper()->propGetPy( i ), PyObjectPtr::STEAL_REFERENCE ); SequenceDataType* dataType = static_cast<SequenceDataType*>( pDD->dataType() ); ArrayPropertiesHelper propArray; propArray.init(this->chunkItem(),&(dataType->getElemType()), ob.getObject()); // Iterate through the array of links for(int j = 0; j < propArray.propCount(); j++) { PyObjectPtr aob( propArray.propGetPy( j ), PyObjectPtr::STEAL_REFERENCE ); std::string id = PyString_AsString( PyTuple_GetItem( aob.getObject(), 0 ) ); std::string chunkId = PyString_AsString( PyTuple_GetItem( aob.getObject(), 1 ) ); if ( id == "" || chunkId == "" ) continue; // Force load the linker since we need to examine its parent chunk EditorChunkItemLinkable* linkableUDO = WorldManager::instance().linkerManager().forceLoad( id, chunkId ); // If the chunk is not an outside chunk, see if it's writeable if (linkableUDO && linkableUDO->chunkItem()->chunk()) { if (!EditorChunkCache::instance( *linkableUDO->chunkItem()->chunk() ).edIsWriteable()) { return false; } } else { //ERROR_MSG( // "EditorChunkItemLinkable::linkedChunksWriteable : " // "Need access to parent chunk!\n" ); if (!dirMap->gridFromChunkName( chunkId, gridX, gridZ ) || !EditorChunk::outsideChunkWriteable( gridX, gridZ, false ) ) { return false; } } } } } // process back links for ( LinksConstIter it = getBackLinksBegin(); it != getBackLinksEnd(); ++it ) { // Force load the linker since we need to examine its parent chunk EditorChunkItemLinkable* linkableUDO = WorldManager::instance().linkerManager().forceLoad( (*it).UID_, (*it).CID_ ); // If the chunk is not an outside chunk, see if it's writeable if (linkableUDO && linkableUDO->chunkItem()->chunk()) { if (!EditorChunkCache::instance( *linkableUDO->chunkItem()->chunk() ).edIsWriteable()) { return false; } } else { //ERROR_MSG( // "EditorChunkItemLinkable::linkedChunksWriteable : " // "Need access to parent chunk!\n" ); if (!dirMap->gridFromChunkName( (*it).CID_, gridX, gridZ ) || !EditorChunk::outsideChunkWriteable( gridX, gridZ, false ) ) { return false; } } } return true; }