예제 #1
0
파일: IpGuard.cpp 프로젝트: 3F/FlightSDCpp
bool IpGuard::check(const string& aIP, string& reason)
{
	Lock l(cs);
	
	if (aIP.empty() || ranges.size() == 0)
		return false;
		
	unsigned int a, b, c, d;
	if (sscanf(aIP.c_str(), "%u.%u.%u.%u", &a, &b, &c, &d) != 4 || a > 255 || b > 255 || c > 255 || d > 255)
		return false;
		
	uint32_t iIP = make_ip(a, b, c, d);
	
	if (iIP == 0)
		return false;
		
	RangeIter find;
	if ((find = range_search(ranges.begin(), ranges.end(), ip(iIP))) != ranges.end())
	{
		reason = find->name;
		return BOOLSETTING(DEFAULT_POLICY);
	}
	
	reason = STRING(IPGUARD_DEFAULT_POLICY);
	return !BOOLSETTING(DEFAULT_POLICY);
}
예제 #2
0
void UserManager::checkUser(const OnlineUserPtr& user)
{
	if (BOOLSETTING(CHECK_NEW_USERS))
	{
		if (!ClientManager::getInstance()->isMe(user))
		{
			const Client& client = user->getClient();
			if (!client.getExcludeCheck() && client.isOp() &&
			        (client.isActive() || user->getIdentity().isTcpActive()))
			{
				if (!BOOLSETTING(PROT_FAVS) || !FavoriteManager::getInstance()->isNoFavUserOrUserBanUpload(user->getUser()))   // !SMT!-opt
				{
					if (!isInProtectedUserList(user->getIdentity().getNick()))
					{
						try
						{
							QueueManager::getInstance()->addList(HintedUser(user->getUser(), client.getHubUrl()), QueueItem::FLAG_USER_CHECK);
						}
						catch (const Exception& e)
						{
							LogManager::getInstance()->message(e.getError());
						}
					}
				}
			}
		}
	}
}
void FinishedManager::on(QueueManagerListener::Finished, const QueueItem* qi, const string&, const Download* d) throw()
{
	bool isFile = !qi->isSet(QueueItem::FLAG_USER_LIST) && !qi->isSet(QueueItem::FLAG_TESTSUR);

	if(isFile && !SETTING(FINISHFILE).empty() && !BOOLSETTING(SOUNDS_DISABLED)) {
		PlaySound(Text::toT(SETTING(FINISHFILE)).c_str(), NULL, SND_FILENAME | SND_ASYNC);
	}
		
	if(isFile || (qi->isSet(QueueItem::FLAG_USER_LIST) && BOOLSETTING(LOG_FILELIST_TRANSFERS))) {
		
		FinishedItemPtr item = new FinishedItem(qi->getTarget(), d->getHintedUser(), qi->getSize(), static_cast<int64_t>(d->getAverageSpeed()), GET_TIME(), qi->getTTH().toBase32());
		{
			Lock l(cs);
			downloads.push_back(item);
		}
			
		fire(FinishedManagerListener::AddedDl(), item);
		//RSX++
		if(qi->isSet(QueueItem::FLAG_CHECK_FILE_LIST))
			return;
		//END
		size_t BUF_SIZE = STRING(FINISHED_DOWNLOAD).size() + MAX_PATH + 128;
		char* buf = new char[BUF_SIZE];
		snprintf(buf, BUF_SIZE, CSTRING(FINISHED_DOWNLOAD), Util::getFileName(qi->getTarget()).c_str(), 
			Util::toString(ClientManager::getInstance()->getNicks(d->getHintedUser())).c_str());

		LogManager::getInstance()->message(buf);
		delete[] buf;
	}
}
예제 #4
0
파일: IpGuard.cpp 프로젝트: 3F/FlightSDCpp
void IpGuard::check(uint32_t aIP, Socket* socket /*= NULL*/) throw(SocketException)
{
	Lock l(cs);
	
	if (aIP == 0 || ranges.size() == 0)
		return;
		
	RangeIter find;
	if ((find = range_search(ranges.begin(), ranges.end(), ip(htonl(aIP)))) != ranges.end())
	{
		if (BOOLSETTING(DEFAULT_POLICY))
		{
			if (socket != NULL)
				socket->disconnect();
			throw SocketException(STRING(IPGUARD) + ": " + find->name + " (" + inet_ntoa(*(in_addr*)&aIP) + ")");
		}
		
		return;
	}
	
	if (!BOOLSETTING(DEFAULT_POLICY))
	{
		if (socket != NULL)
			socket->disconnect();
		throw SocketException(STRING(IPGUARD) + ": " + STRING(IPGUARD_DEFAULT_POLICY) + " (" + inet_ntoa(*(in_addr*)&aIP) + ")");
	}
}
예제 #5
0
bool Client::allowChatMessagefromUser(const ChatMessage& message, const string& p_nick)
{
	if (!message.m_from)
	{
		if (!p_nick.empty() && UserManager::isInIgnoreList(p_nick)) // http://code.google.com/p/flylinkdc/issues/detail?id=1432
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else if (isMe(message.m_from))
	{
		return true;
	}
	else if (message.thirdPerson && BOOLSETTING(NSL_IGNORE_ME))
	{
		return false;
	}
	if (BOOLSETTING(SUPPRESS_MAIN_CHAT) && !isOp())
	{
		return false;
	}
	else if (UserManager::isInIgnoreList(message.m_from->getIdentity().getNick())) // !SMT!-S
	{
		return false;
	}
	else
	{
		return true;
	}
}
예제 #6
0
/** Download finished! */
void DownloadManager::endData(UserConnection* aSource) {
    dcassert(aSource->getState() == UserConnection::STATE_RUNNING);
    Download* d = aSource->getDownload();
    dcassert(d != NULL);

    if(d->getType() == Transfer::TYPE_TREE) {
        d->getFile()->flush();

        int64_t bl = 1024;
        while(bl * (int64_t)d->getTigerTree().getLeaves().size() < d->getTigerTree().getFileSize())
            bl *= 2;
        d->getTigerTree().setBlockSize(bl);
        d->getTigerTree().calcRoot();

        if(!(d->getTTH() == d->getTigerTree().getRoot())) {
            // This tree is for a different file, remove from queue...
            removeDownload(d);
            fire(DownloadManagerListener::Failed(), d, _("Full tree does not match TTH root"));

            QueueManager::getInstance()->removeSource(d->getPath(), aSource->getUser(), QueueItem::Source::FLAG_BAD_TREE, false);

            QueueManager::getInstance()->putDownload(d, false);

            checkDownloads(aSource);
            return;
        }
        d->setTreeValid(true);
    } else {
        // First, finish writing the file (flushing the buffers and closing the file...)
        try {
            d->getFile()->flush();
                } catch(const Exception& e) {
                        d->resetPos();
            failDownload(aSource, e.getError());
            return;
        }

        aSource->setSpeed(d->getAverageSpeed());
        aSource->updateChunkSize(d->getTigerTree().getBlockSize(), d->getSize(), GET_TICK() - d->getStart());

        dcdebug("Download finished: %s, size " I64_FMT ", downloaded " I64_FMT "\n", d->getPath().c_str(),
                static_cast<long long int>(d->getSize()), static_cast<long long int>(d->getPos()));

        if(BOOLSETTING(LOG_DOWNLOADS) && (BOOLSETTING(LOG_FILELIST_TRANSFERS) || d->getType() == Transfer::TYPE_FILE)) {
            logDownload(aSource, d);
        }
    }

    removeDownload(d);
    fire(DownloadManagerListener::Complete(), d);

    QueueManager::getInstance()->putDownload(d, true);
    checkDownloads(aSource);
}
예제 #7
0
SpyFrame::SpyFrame() : CFlyTimerAdapter(m_hWnd), CFlyTaskAdapter(m_hWnd), m_total(0), m_current(0),
	m_ignoreTTH(BOOLSETTING(SPY_FRAME_IGNORE_TTH_SEARCHES)),
	m_showNick(BOOLSETTING(SHOW_SEEKERS_IN_SPY_FRAME)),
	m_LogFile(BOOLSETTING(LOG_SEEKERS_IN_SPY_FRAME)),
	m_ignoreTTHContainer(WC_BUTTON, this, SPYFRAME_IGNORETTH_MESSAGE_MAP),
	m_ShowNickContainer(WC_BUTTON, this, SPYFRAME_SHOW_NICK),
	m_SpyLogFileContainer(WC_BUTTON, this, SPYFRAME_LOG_FILE),
	m_log(nullptr), m_needsUpdateTime(true), m_needsResort(false) //[+]IRainman refactoring SpyFrame
{
	memzero(m_perSecond, sizeof(m_perSecond));
	ClientManager::getInstance()->addListener(this);
	SettingsManager::getInstance()->addListener(this);
}
예제 #8
0
void DownloadManager::on(TimerManagerListener::Second, uint64_t aTick) noexcept {
    typedef vector<pair<string, UserPtr> > TargetList;
    TargetList dropTargets;

    {
        Lock l(cs);

        DownloadList tickList;
        // Tick each ongoing download
        for(DownloadList::iterator i = downloads.begin(); i != downloads.end(); ++i) {
            if((*i)->getPos() > 0) {
                tickList.push_back(*i);
                (*i)->tick();
            }
        }

        if(tickList.size() > 0)
            fire(DownloadManagerListener::Tick(), tickList);


        // Automatically remove or disconnect slow sources
        if((uint32_t)(aTick / 1000) % SETTING(AUTODROP_INTERVAL) == 0) {
            for(DownloadList::iterator i = downloads.begin(); i != downloads.end(); ++i) {
                Download* d = *i;
                uint64_t timeElapsed = aTick - d->getStart();
                uint64_t timeInactive = aTick - d->getUserConnection().getLastActivity();
                uint64_t bytesDownloaded = d->getPos();
                bool timeElapsedOk = timeElapsed >= (uint32_t)SETTING(AUTODROP_ELAPSED) * 1000;
                bool timeInactiveOk = timeInactive <= (uint32_t)SETTING(AUTODROP_INACTIVITY) * 1000;
                bool speedTooLow = timeElapsedOk && timeInactiveOk && bytesDownloaded > 0 ?
                    bytesDownloaded / timeElapsed * 1000 < (uint32_t)SETTING(AUTODROP_SPEED) : false;
                bool isUserList = d->getType() == Transfer::TYPE_FULL_LIST;
                bool onlineSourcesOk = isUserList ?
                    true : QueueManager::getInstance()->countOnlineSources(d->getPath()) >= SETTING(AUTODROP_MINSOURCES);
                bool filesizeOk = !isUserList && d->getSize() >= ((int64_t)SETTING(AUTODROP_FILESIZE)) * 1024;
                bool dropIt = (isUserList && BOOLSETTING(AUTODROP_FILELISTS)) ||
                    (filesizeOk && BOOLSETTING(AUTODROP_ALL));
                if(speedTooLow && onlineSourcesOk && dropIt) {
                    if(BOOLSETTING(AUTODROP_DISCONNECT) && isUserList) {
                        d->getUserConnection().disconnect();
                    } else {
                        dropTargets.push_back(make_pair(d->getPath(), d->getUser()));
                    }
                }
            }
        }
    }
    for(TargetList::iterator i = dropTargets.begin(); i != dropTargets.end(); ++i) {
        QueueManager::getInstance()->removeSource(i->first, i->second, QueueItem::Source::FLAG_SLOW_SOURCE);
    }
}
예제 #9
0
string Client::getLocalIp() const
{
	// [!] IRainman fix:
	// [!] If possible, always return the hub that IP, which he identified with us when you connect.
	// [!] This saves the user from a variety of configuration problems.
	const string& myUserIp = getMyIdentity().getIpAsString(); // [!] opt, and fix done: [4] https://www.box.net/shared/c497f50da28f3dfcc60a
	if (!myUserIp.empty())
	{
		return myUserIp; // [!] Best case - the server detected it.
	}
	// Favorite hub Ip
	if (!getFavIp().empty())
	{
		return Socket::resolve(getFavIp());
	}
	const auto& settingIp = SETTING(EXTERNAL_IP);
	if (!BOOLSETTING(NO_IP_OVERRIDE) && !settingIp.empty() &&
	        SETTING(INCOMING_CONNECTIONS) != SettingsManager::INCOMING_DIRECT)   // !SMT!-F
	{
		return Socket::resolve(settingIp);
	}
	
	{
#ifdef FLYLINKDC_USE_CS_CLIENT_SOCKET
		FastLock lock(csSock); // [+] brain-ripper
#endif
		if (m_client_sock)
		{
			return m_client_sock->getLocalIp();
		}
	}
	return Util::getLocalOrBindIp(false);
	// [~] IRainman fix.
}
예제 #10
0
	/*
	 * Limits a traffic and writes a packet to the network
	 * We must handle this a little bit differently than downloads, because of that stupidity in OpenSSL
	 */		
	int ThrottleManager::write(Socket* sock, void* buffer, size_t& len)
	{
		size_t ups = UploadManager::getInstance()->getUploadCount();
		if(!BOOLSETTING(THROTTLE_ENABLE) || upLimit == 0 || ups == 0)
			return sock->write(buffer, len);
		
		boost::unique_lock<boost::mutex> lock(upMutex);
		
		if(upTokens > 0)
		{
			size_t slice = getUploadLimit() / ups;
			len = min(slice, min(len, upTokens));
			upTokens -= len;

			// next code can't be in critical section, so we must unlock here
			lock.unlock();

			// write to socket			
			int sent = sock->write(buffer, len);

			// give a chance to other transfers to get a token
			boost::thread::yield();
			return sent;
		}
		
		// no tokens, wait for them
		upCond.timed_wait(lock, boost::posix_time::millisec(CONDWAIT_TIMEOUT));
		return 0;	// from BufferedSocket: -1 = failed, 0 = retry
	}
예제 #11
0
	/*
	 * Limits a traffic and reads a packet from the network
	 */
	int ThrottleManager::read(Socket* sock, void* buffer, size_t len)
	{
		size_t downs = DownloadManager::getInstance()->getDownloadCount();
		if(!BOOLSETTING(THROTTLE_ENABLE) || downLimit == 0 || downs == 0)
			return sock->read(buffer, len);

		boost::unique_lock<boost::mutex> lock(downMutex);


		if(downTokens > 0)
		{
			size_t slice = getDownloadLimit() / downs;
			size_t readSize = min(slice, min(len, downTokens));
				
			// read from socket
			readSize = sock->read(buffer, readSize);
				
			if(readSize > 0)
				downTokens -= readSize;

			// next code can't be in critical section, so we must unlock here
			lock.unlock();

			// give a chance to other transfers to get a token
			boost::thread::yield();
			return readSize;
		}

		// no tokens, wait for them
		downCond.timed_wait(lock, boost::posix_time::millisec(CONDWAIT_TIMEOUT));
		return -1;	// from BufferedSocket: -1 = retry, 0 = connection close
	}
예제 #12
0
LRESULT EmoticonsDlg::onEmoticonClick(WORD /*wNotifyCode*/, WORD /*wID*/, HWND hWndCtl, BOOL& /*bHandled*/)
{
	WinUtil::GetWindowText(result, hWndCtl);
	// pro ucely testovani emoticon packu...
	if (WinUtil::isShift() && WinUtil::isCtrl())
	{
		const CAGEmotion::Array& Emoticons = CAGEmotionSetup::g_pEmotionsSetup->getEmoticonsArray();
		result.clear();
		string lastEmotionPath, lastAnimEmotionPath;
		int l_count_emotion = 0;
		bool bUseAnimation = BOOLSETTING(SMILE_SELECT_WND_ANIM_SMILES);
		
		for (auto pEmotion = Emoticons.cbegin();
		        pEmotion != Emoticons.cend() && l_count_emotion < CAGEmotionSetup::g_pEmotionsSetup->m_CountSelEmotions;
		        ++pEmotion, ++l_count_emotion)
		{
			if (bUseAnimation)
			{
				if (lastEmotionPath != (*pEmotion)->getEmotionBmpPath() || lastAnimEmotionPath != (*pEmotion)->getEmotionGifPath())
					result += (*pEmotion)->getEmotionText() + _T(' ');
					
				lastEmotionPath = (*pEmotion)->getEmotionBmpPath();
				lastAnimEmotionPath = (*pEmotion)->getEmotionGifPath();
			}
			else
			{
				if (lastEmotionPath != (*pEmotion)->getEmotionBmpPath())
					result += (*pEmotion)->getEmotionText() + _T(' ');
				lastEmotionPath = (*pEmotion)->getEmotionBmpPath();
			}
		}
	}
	PostMessage(WM_CLOSE);
	return 0;
}
예제 #13
0
bool PGLoader::check(uint32_t p_ip4)
{
#ifdef _DEBUG
	//boost::system::error_code ec;
	//const auto l_ip_boost = boost::asio::ip::address_v4::from_string("10.91.2.180", ec);
	//p_ip4 = l_ip_boost.to_ulong();
	static boost::atomic_int g_count(0);
	dcdebug("PGLoader::check  count = %d\n", int(++g_count));
#endif
	if (BOOLSETTING(ENABLE_IPTRUST))
	{
		CFlyFastLock(g_cs);
		if (!g_ipTrustListBlock.empty())
		{
			if (g_ipTrustListBlock.checkIp(p_ip4))
			{
				return true;
			}
		}
		if (!g_ipTrustListAllow.empty())
		{
			const auto l_ipguard = g_ipTrustListAllow.checkIp(p_ip4);
			return !l_ipguard;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}
예제 #14
0
void Client::connect() {
	if(socket)
		BufferedSocket::putSocket(socket);

	setAutoReconnect(true);
	setReconnDelay(120 + Util::rand(0, 60));
	reloadSettings(true);
	setRegistered(false);
	setMyIdentity(Identity(ClientManager::getInstance()->getMe(), 0));
	setHubIdentity(Identity());

	try {
		socket = BufferedSocket::getSocket(separator);
		socket->addListener(this);
		socket->connect(address, port, secure, BOOLSETTING(ALLOW_UNTRUSTED_HUBS), true);
	} catch(const Exception& e) {
		if(socket) {
			BufferedSocket::putSocket(socket);
			socket = 0;
		}
		fire(ClientListener::Failed(), this, e.getError());
	}
	updateActivity();
	state = STATE_CONNECTING;
}
예제 #15
0
파일: OMenu.cpp 프로젝트: inetra/peers1
LRESULT OMenu::onDrawItem(HWND /*hWnd*/, UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
	bHandled = FALSE;
	if (wParam == NULL) {
		DRAWITEMSTRUCT dis = *(DRAWITEMSTRUCT*)lParam;
		if (dis.CtlType == ODT_MENU) {
			OMenuItem* mi = (OMenuItem*)dis.itemData;
			if (mi) {
				bHandled = TRUE;
				CRect rc(dis.rcItem);
				//rc.top += 2;
				rc.bottom -= 2;

				CDC dc;
				dc.Attach(dis.hDC);

				if (BOOLSETTING(MENUBAR_TWO_COLORS))
					OperaColors::FloodFill(dc, rc.left, rc.top, rc.right, rc.bottom, SETTING(MENUBAR_LEFT_COLOR), SETTING(MENUBAR_RIGHT_COLOR), BOOLSETTING(MENUBAR_BUMPED));
				else
					dc.FillSolidRect(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SETTING(MENUBAR_LEFT_COLOR));

				dc.SetBkMode(TRANSPARENT);
				dc.SetTextColor(OperaColors::TextFromBackground(SETTING(MENUBAR_LEFT_COLOR)));
				HFONT oldFont = dc.SelectFont(WinUtil::boldFont);
				tstring buf = mi->text;
				dc.DrawText(buf.c_str(), _tcslen(buf.c_str()), rc, DT_CENTER | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER);
				dc.SelectFont(oldFont);

				dc.Detach();
				return TRUE;
			}
		}
	}
	return S_OK;
}
예제 #16
0
AdcCommand Download::getCommand(bool zlib) {
    AdcCommand cmd(AdcCommand::CMD_GET);

    cmd.addParam(Transfer::names[getType()]);

    if(getType() == TYPE_PARTIAL_LIST) {
        cmd.addParam(Util::toAdcFile(getPath()));
    } else if(getType() == TYPE_FULL_LIST) {
        if(isSet(Download::FLAG_XML_BZ_LIST)) {
            cmd.addParam(USER_LIST_NAME_BZ);
        } else {
            cmd.addParam(USER_LIST_NAME);
        }
    } else {
        cmd.addParam("TTH/" + getTTH().toBase32());
    }

    cmd.addParam(Util::toString(getStartPos()));
    cmd.addParam(Util::toString(getSize()));

    if(zlib && BOOLSETTING(COMPRESS_TRANSFERS)) {
        cmd.addParam("ZL1");
    }

    return cmd;
}
예제 #17
0
void UploadManager::on(UserConnectionListener::TransmitDone, UserConnection* aSource) throw() {
	dcassert(aSource->getState() == UserConnection::STATE_RUNNING);
	Upload* u = aSource->getUpload();
	dcassert(u != NULL);

	aSource->setState(UserConnection::STATE_GET);

	if(BOOLSETTING(LOG_UPLOADS) && !u->isSet(Upload::FLAG_TTH_LEAVES) && (BOOLSETTING(LOG_FILELIST_TRANSFERS) || !u->isSet(Upload::FLAG_USER_LIST))) {
		StringMap params;
		u->getParams(*aSource, params);
		LOG(LogManager::UPLOAD, params);
	}

	fire(UploadManagerListener::Complete(), u);
	removeUpload(u);
}
void ConnectivityManager::set(SettingsManager::StrSetting setting, const string& str) {
    if(BOOLSETTING(AUTO_DETECT_CONNECTION)) {
        autoSettings[setting] = str;
    } else {
        SettingsManager::getInstance()->set(setting, str);
    }
}
예제 #19
0
LRESULT MessagesChatPage::onInitDialog_chat(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	PropPage::read(*this, g_items_chat, g_listItems_chat, GetDlgItem(IDC_MESSAGES_CHAT_BOOLEANS));
	
	ctrlList_chat.Attach(GetDlgItem(IDC_MESSAGES_CHAT_BOOLEANS)); // [+] IRainman
	
	tooltip_messageschat.Create(m_hWnd, rcDefault, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP /*| TTS_BALLOON*/, WS_EX_TOPMOST);
	tooltip_messageschat.SetDelayTime(TTDT_AUTOPOP, 15000);
	ATLASSERT(tooltip_messageschat.IsWindow());
	ctrlSee.Attach(GetDlgItem(IDC_PROTECT_PRIVATE_SAY));
	tooltip_messageschat.AddTool(ctrlSee, ResourceManager::PROTECT_PRIVATE_SAY_TOOLTIP);
	ctrlProtect.Attach(GetDlgItem(IDC_PROTECT_PRIVATE));
	tooltip_messageschat.AddTool(ctrlProtect, ResourceManager::PROTECT_PRIVATE_TOOLTIP);
	ctrlRnd.Attach(GetDlgItem(IDC_PROTECT_PRIVATE_RND));
	tooltip_messageschat.AddTool(ctrlRnd, ResourceManager::PROTECT_PRIVATE_RND_TOOLTIP);
	tooltip_messageschat.SetMaxTipWidth(256);   //[+] SCALOlaz: activate tooltips
	if (!BOOLSETTING(POPUPS_DISABLED))
	{
		tooltip_messageschat.Activate(TRUE);
	}
	
	PropPage::translate((HWND)(*this), g_texts_chat);
	fixControls();
	// Do specialized reading here
	return TRUE;
}
예제 #20
0
void ConnectivityManager::test_all_ports()
{
	if (SETTING(INCOMING_CONNECTIONS) != SettingsManager::INCOMING_FIREWALL_PASSIVE && !ClientManager::isBeforeShutdown())
	{
		// Test Port
		string l_external_ip;
		std::vector<unsigned short> l_udp_port, l_tcp_port;
		l_udp_port.push_back(SETTING(UDP_PORT));
#ifdef STRONG_USE_DHT
		l_udp_port.push_back(SETTING(DHT_PORT));
#endif
		l_tcp_port.push_back(SETTING(TCP_PORT));
		l_tcp_port.push_back(SETTING(TLS_PORT));
		if (CFlyServerJSON::pushTestPort(l_udp_port, l_tcp_port, l_external_ip, 0,
#ifdef STRONG_USE_DHT
		                                 "UDP+DHT+TCP+TLS"
#else
		                                 "UDP+TCP+TLS"
#endif
		                                ))
		{
			if (!l_external_ip.empty())
			{
				if (!BOOLSETTING(WAN_IP_MANUAL))
				{
					SET_SETTING(EXTERNAL_IP, l_external_ip);
				}
			}
		}
	}
}
예제 #21
0
void UserConnection::connect(const string& aServer, uint16_t aPort, uint16_t localPort, BufferedSocket::NatRoles natRole) throw(SocketException, ThreadException) {
    dcassert(!socket);

    socket = BufferedSocket::getSocket(0);
    socket->addListener(this);
    socket->connect(aServer, aPort, localPort, natRole, isSet(FLAG_SECURE), BOOLSETTING(ALLOW_UNTRUSTED_CLIENTS), true);
}
void ConnectionManager::on(UserConnectionListener::CLock, UserConnection* aSource, const string& aLock, const string& aPk) throw() {
	if(aSource->getState() != UserConnection::STATE_LOCK) {
		dcdebug("CM::onLock %p received lock twice, ignoring\n", aSource);
		return;
	}
	
	if( CryptoManager::getInstance()->isExtended(aLock) ) {
		// Alright, we have an extended protocol, set a user flag for this user and refresh his info...
		if( (aPk.find("DCPLUSPLUS") != string::npos) && aSource->getUser()) {
			aSource->getUser()->setFlag(User::DCPLUSPLUS);
			User::updated(aSource->getUser());
		}
		StringList defFeatures = features;
		if(BOOLSETTING(COMPRESS_TRANSFERS)) {
			defFeatures.push_back(UserConnection::FEATURE_GET_ZBLOCK);
			defFeatures.push_back(UserConnection::FEATURE_ZLIB_GET);
		}

		aSource->supports(defFeatures);
	}

	aSource->setState(UserConnection::STATE_DIRECTION);
	aSource->direction(aSource->getDirectionString(), aSource->getNumber());
	aSource->key(CryptoManager::getInstance()->makeKey(aLock));
}
예제 #23
0
void UserConnection::connect(const string& aServer, const string& aPort, const string& localPort, BufferedSocket::NatRoles natRole, UserPtr) {
    dcassert(!socket);

    port = aPort;
    socket = BufferedSocket::getSocket(0);
    socket->addListener(this);
    socket->connect(aServer, aPort, localPort, natRole, isSet(FLAG_SECURE), BOOLSETTING(ALLOW_UNTRUSTED_CLIENTS), true, Socket::PROTO_DEFAULT);
}
void ConnectivityManager::log(const string& message) {
   if(BOOLSETTING(AUTO_DETECT_CONNECTION)) {
       LogManager::getInstance()->message(_("Connectivity: ") + message);
       fire(ConnectivityManagerListener::Message(), message);
   } else {
       LogManager::getInstance()->message(message);
   }
}
예제 #25
0
void LuaManager::LuaError(lua_State* L, const char* fmt, bool fatal /*= true*/, ...) {
	if(fatal || BOOLSETTING(LuaDebug)) {
		va_list argp;
		va_start(argp, fatal);
		luaL_error(L, fmt, argp);
		va_end(argp);
	}
}
예제 #26
0
void HttpConnection::on(BufferedSocketListener::ModeChange) throw() {
	socket->removeListener(this);
	socket->disconnect();
	BufferedSocket::putSocket(socket);
	socket = NULL;
	fire(HttpConnectionListener::Complete(), this, currentUrl, BOOLSETTING(CORAL) && coralizeState != CST_NOCORALIZE);
	coralizeState = CST_DEFAULT;
}
예제 #27
0
LRESULT SystemFrame::onSpeaker(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
	auto_ptr<pair<time_t, tstring> > msg((pair<time_t, tstring>*)wParam);

	addLine(msg->first, msg->second);
	if(BOOLSETTING(BOLD_SYSTEM_LOG))
		setDirty();
	return 0;
}
예제 #28
0
void PopupManager::on(TimerManagerListener::Second /*type*/, time_t /*tick*/ ) {
	if(!BOOLSETTING(REMOVE_POPUPS))
		return;

	//post a message and let the main window thread take care of the window
	::PostMessage(WinUtil::mainWnd, WM_SPEAKER, MainFrame::REMOVE_POPUP, 0);

}
예제 #29
0
LRESULT RecentHubsFrame::onCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
	ctrlHubs.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
	                WS_HSCROLL | WS_VSCROLL | LVS_REPORT | LVS_SHOWSELALWAYS, WS_EX_CLIENTEDGE, IDC_RECENTS);
	                
	SET_EXTENDENT_LIST_VIEW_STYLE(ctrlHubs);
	SET_LIST_COLOR(ctrlHubs);
	
	// Create listview columns
	WinUtil::splitTokens(columnIndexes, SETTING(RECENTFRAME_ORDER), COLUMN_LAST);
	WinUtil::splitTokensWidth(columnSizes, SETTING(RECENTFRAME_WIDTHS), COLUMN_LAST);
	
	BOOST_STATIC_ASSERT(_countof(columnSizes) == COLUMN_LAST);
	BOOST_STATIC_ASSERT(_countof(columnNames) == COLUMN_LAST);
	for (int j = 0; j < COLUMN_LAST; j++)
	{
		const int fmt = LVCFMT_LEFT;
		ctrlHubs.InsertColumn(j, CTSTRING_I(columnNames[j]), fmt, columnSizes[j], j);
	}
	
	ctrlHubs.SetColumnOrderArray(COLUMN_LAST, columnIndexes);
	ctrlConnect.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
	                   BS_PUSHBUTTON , 0, IDC_CONNECT);
	ctrlConnect.SetWindowText(CTSTRING(CONNECT));
	ctrlConnect.SetFont(Fonts::g_systemFont); // [~] Sergey Shuhskanov
	
	ctrlRemove.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
	                  BS_PUSHBUTTON , 0, IDC_REMOVE);
	ctrlRemove.SetWindowText(CTSTRING(REMOVE));
	ctrlRemove.SetFont(Fonts::g_systemFont); // [~] Sergey Shuhskanov
	
	ctrlRemoveAll.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
	                     BS_PUSHBUTTON , 0, IDC_REMOVE_ALL);
	ctrlRemoveAll.SetWindowText(CTSTRING(REMOVE_ALL));
	ctrlRemoveAll.SetFont(Fonts::g_systemFont); // [~] Sergey Shuhskanov
	
	FavoriteManager::getInstance()->addListener(this);
	SettingsManager::getInstance()->addListener(this);
	updateList(FavoriteManager::getInstance()->getRecentHubs());
	
	const int l_sort = SETTING(HUBS_RECENTS_COLUMNS_SORT);
	int l_sort_type = ExListViewCtrl::SORT_STRING_NOCASE;
	if (l_sort == 2 || l_sort == 3)
		l_sort_type = ExListViewCtrl::SORT_INT;
	ctrlHubs.setSort(SETTING(HUBS_RECENTS_COLUMNS_SORT), l_sort_type , BOOLSETTING(HUBS_RECENTS_COLUMNS_SORT_ASC));
	
	hubsMenu.CreatePopupMenu();
	hubsMenu.AppendMenu(MF_STRING, IDC_CONNECT, CTSTRING(CONNECT));
	hubsMenu.AppendMenu(MF_STRING, IDC_ADD, CTSTRING(ADD_TO_FAVORITES_HUBS));
	hubsMenu.AppendMenu(MF_STRING, IDC_REM_AS_FAVORITE, CTSTRING(REMOVE_FROM_FAVORITES_HUBS));
	hubsMenu.AppendMenu(MF_STRING, IDC_EDIT, CTSTRING(PROPERTIES));
	hubsMenu.AppendMenu(MF_STRING, IDC_REMOVE, CTSTRING(REMOVE));
	hubsMenu.AppendMenu(MF_STRING, IDC_REMOVE_ALL, CTSTRING(REMOVE_ALL));
	hubsMenu.SetMenuDefaultItem(IDC_CONNECT);
	
	bHandled = FALSE;
	return TRUE;
}
LRESULT FavoriteHubsFrame::onRemove(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
	int i = -1;
	if(!BOOLSETTING(CONFIRM_HUB_REMOVAL) || MessageBox(CTSTRING(REALLY_REMOVE), _T(APPNAME) _T(" ") _T(VERSIONSTRING), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) == IDYES) {
		while( (i = ctrlHubs.GetNextItem(-1, LVNI_SELECTED)) != -1) {
			FavoriteManager::getInstance()->removeFavorite((FavoriteHubEntry*)ctrlHubs.GetItemData(i));
		}
	}
	return 0;
}