Пример #1
0
void Client::send(const char* aMessage, size_t aLen) {
	if (!isConnected() || !sock) {
		dcassert(0);
		return;
	}
	updateActivity();
	sock->write(aMessage, aLen);
	COMMAND_DEBUG(aMessage, DebugManager::TYPE_HUB, DebugManager::OUTGOING, getIpPort());
}
Пример #2
0
void Client::send(const char* aMessage, size_t aLen) {
    if(!isReady()) {
        dcassert(0);
        return;
    }
    updateActivity();
    sock->write(aMessage, aLen);
    COMMAND_DEBUG(aMessage, DebugManager::HUB_OUT, getIpPort());
}
Пример #3
0
void UserConnection::send(const string &aString) {
    lastActivity = GET_TICK();
    COMMAND_DEBUG((Util::stricmp(getEncoding(), Text::utf8) != 0 ? Text::toUtf8(aString, getEncoding()) : aString), DebugManager::CLIENT_OUT, getRemoteIp());
#ifdef LUA_SCRIPT
    if(onUserConnectionMessageOut(this, aString)) {
        disconnect(true);
        return;
    }
#endif
    socket->write(aString);
}
Пример #4
0
void Client::send(const char* aMessage, size_t aLen)
{
	if (!isReady())
	{
		dcdebug("Send message failed, hub is disconnected!");//[+] IRainman
		dcassert(isReady()); // ѕод отладкой падаем тут. найти причину.
		return;
	}
	updateActivity();
	{
#ifdef FLYLINKDC_USE_CS_CLIENT_SOCKET
		FastLock lock(csSock); // [+] brain-ripper
#endif
		m_client_sock->write(aMessage, aLen);
	}
	if (!CompatibilityManager::isWine())
	{
		COMMAND_DEBUG(aMessage, DebugTask::HUB_OUT, getIpPort());
	}
}
Пример #5
0
void UserConnection::on(BufferedSocketListener::Line, const string& aLine) throw () {

	COMMAND_DEBUG(aLine, DebugManager::TYPE_CLIENT, DebugManager::INCOMING, getRemoteIp());
	
	if(aLine.length() < 2) {
		fire(UserConnectionListener::ProtocolError(), this, "Invalid data"); // TODO: translate
		return;
	}

	if(aLine[0] == 'C' && !isSet(FLAG_NMDC)) {
		if(!Text::validateUtf8(aLine)) {
			fire(UserConnectionListener::ProtocolError(), this, "Non-UTF-8 data in an ADC connection");  // TODO: translate
			return;
		}
		dispatch(aLine);
		return;
	} else if(aLine[0] == '$') {
		setFlag(FLAG_NMDC);
	} else {
		// We shouldn't be here?
		fire(UserConnectionListener::ProtocolError(), this, "Invalid data");  // TODO: translate
		return;
	}

	string cmd;
	string param;

	string::size_type x;
                
	if( (x = aLine.find(' ')) == string::npos) {
		cmd = aLine.substr(1);
	} else {
		cmd = aLine.substr(1, x - 1);
		param = aLine.substr(x+1);
    }
    
	if(cmd == "MyNick") {
		if(!param.empty())
			fire(UserConnectionListener::MyNick(), this, param);
	} else if(cmd == "Direction") {
		x = param.find(" ");
		if(x != string::npos) {
			fire(UserConnectionListener::Direction(), this, param.substr(0, x), param.substr(x+1));
		}
	} else if(cmd == "Error") {
		if(Util::stricmp(param.c_str(), FILE_NOT_AVAILABLE) == 0 ||
			param.rfind(/*path/file*/" no more exists") != string::npos) { 
    		fire(UserConnectionListener::FileNotAvailable(), this);
    	} else {
			fire(UserConnectionListener::ProtocolError(), this, param);
	    }
	} else if(cmd == "GetListLen") {
    	fire(UserConnectionListener::GetListLength(), this);
	} else if(cmd == "Get") {
		x = param.find('$');
		if(x != string::npos) {
			fire(UserConnectionListener::Get(), this, Text::toUtf8(param.substr(0, x), encoding), Util::toInt64(param.substr(x+1)) - (int64_t)1);
	    }
	} else if(cmd == "Key") {
		if(!param.empty())
			fire(UserConnectionListener::Key(), this, param);
	} else if(cmd == "Lock") {
		if(!param.empty()) {
			x = param.find(" Pk=");
			if(x != string::npos) {
				fire(UserConnectionListener::CLock(), this, param.substr(0, x));
			} else {
				// Workaround for faulty linux clients...
				x = param.find(' ');
				if(x != string::npos) {
					fire(UserConnectionListener::CLock(), this, param.substr(0, x));
	    		} else {
					fire(UserConnectionListener::CLock(), this, param);
    			}
	        }
       	}
	} else if(cmd == "Send") {
    	fire(UserConnectionListener::Send(), this);
	} else if(cmd == "MaxedOut") {
		fire(UserConnectionListener::MaxedOut(), this, param);
	} else if(cmd == "Supports") {
		if(!param.empty()) {
			fire(UserConnectionListener::Supports(), this, StringTokenizer<string>(param, ' ').getTokens());
	    }
	} else if(cmd.compare(0, 3, "ADC") == 0) {
    	dispatch(aLine, true);
	} else if (cmd == "ListLen") {
		if(!param.empty()) {
			fire(UserConnectionListener::ListLength(), this, param);
		}
	} else {

		
		fire(UserConnectionListener::ProtocolError(), this, "Invalid data"); // TODO: translate
	}
}
Пример #6
0
void UserConnection::send(const string& aString) {
	lastActivity = GET_TICK();
	COMMAND_DEBUG(aString, DebugManager::TYPE_CLIENT, DebugManager::OUTGOING, getRemoteIp());
	socket->write(aString);
}
Пример #7
0
void UserConnection::on(BufferedSocketListener::Line, const string& aLine) throw () {
        if(aLine.length() < 2) {
                fire(UserConnectionListener::ProtocolError(), this, _("Invalid data"));
        return;
        }

    if(aLine[0] == 'C' && !isSet(FLAG_NMDC)) {
        if(!Text::validateUtf8(aLine)) {
                        fire(UserConnectionListener::ProtocolError(), this, _("Non-UTF-8 data in an ADC connection"));
            return;
        }
        dispatch(aLine);
        return;
    } else if(aLine[0] == '$') {
        setFlag(FLAG_NMDC);
    } else {
                fire(UserConnectionListener::ProtocolError(), this, _("Invalid data"));
        return;
    }
    COMMAND_DEBUG(aLine, DebugManager::CLIENT_IN, getRemoteIp());
    string cmd;
    string param;

    string::size_type x;
#ifdef LUA_SCRIPT
    if(onUserConnectionMessageIn(this, aLine)) {
        disconnect(true);
        return;
    }
#endif

    if( (x = aLine.find(' ')) == string::npos) {
        cmd = aLine;
    } else {
        cmd = aLine.substr(0, x);
        param = aLine.substr(x+1);
    }

    if(cmd == "$MyNick") {
        if(!param.empty())
            fire(UserConnectionListener::MyNick(), this, param);
    } else if(cmd == "$Direction") {
        x = param.find(" ");
        if(x != string::npos) {
            fire(UserConnectionListener::Direction(), this, param.substr(0, x), param.substr(x+1));
        }
    } else if(cmd == "$Error") {
        if(Util::stricmp(param.c_str(), FILE_NOT_AVAILABLE) == 0 ||
            param.rfind(/*path/file*/" no more exists") != string::npos) {
            fire(UserConnectionListener::FileNotAvailable(), this);
        } else {
                        fire(UserConnectionListener::ProtocolError(), this, param);
        }
    } else if(cmd == "$GetListLen") {
        fire(UserConnectionListener::GetListLength(), this);
    } else if(cmd == "$Get") {
        x = param.find('$');
        if(x != string::npos) {
            fire(UserConnectionListener::Get(), this, Text::toUtf8(param.substr(0, x), encoding), Util::toInt64(param.substr(x+1)) - (int64_t)1);
        }
    } else if(cmd == "$Key") {
        if(!param.empty())
            fire(UserConnectionListener::Key(), this, param);
    } else if(cmd == "$Lock") {
        if(!param.empty()) {
            x = param.find(" Pk=");
            if(x != string::npos) {
                fire(UserConnectionListener::CLock(), this, param.substr(0, x), param.substr(x + 4));
            } else {
                // Workaround for faulty linux clients...
                x = param.find(' ');
                if(x != string::npos) {
                    setFlag(FLAG_INVALIDKEY);
                    fire(UserConnectionListener::CLock(), this, param.substr(0, x), Util::emptyString);
                } else {
                    fire(UserConnectionListener::CLock(), this, param, Util::emptyString);
                }
            }
        }
    } else if(cmd == "$Send") {
        fire(UserConnectionListener::Send(), this);
    } else if(cmd == "$MaxedOut") {
        fire(UserConnectionListener::MaxedOut(), this);
    } else if(cmd == "$Supports") {
        if(!param.empty()) {
            fire(UserConnectionListener::Supports(), this, StringTokenizer<string>(param, ' ').getTokens());
        }
    } else if(cmd.compare(0, 4, "$ADC") == 0) {
        dispatch(aLine, true);
    } else {
        fire(UserConnectionListener::ProtocolError(), this, _("Invalid data"));
    }
}
Пример #8
0
void UDPServer::handlePacket(uint8_t* aBuf, size_t aLen, const string& aRemoteIp) {
	string x((char*) aBuf, aLen);

	//check if this packet has been encrypted
	if (SETTING(ENABLE_SUDP) && aLen >= 32 && ((aLen & 15) == 0)) {
		SearchManager::getInstance()->decryptPacket(x, aLen, aBuf, BUFSIZE);
	}
			
	delete aBuf;
	if (x.empty())
		return;

	COMMAND_DEBUG(x, DebugManager::TYPE_CLIENT_UDP, DebugManager::INCOMING, aRemoteIp);

	if(x.compare(0, 4, "$SR ") == 0) {
		SearchManager::getInstance()->onSR(x, aRemoteIp);
	} else if(x.compare(1, 4, "RES ") == 0 && x[x.length() - 1] == 0x0a) {
		AdcCommand c(x.substr(0, x.length()-1));
		if(c.getParameters().empty())
			return;
		string cid = c.getParam(0);
		if(cid.size() != 39)
			return;

		UserPtr user = ClientManager::getInstance()->findUser(CID(cid));
		if(!user)
			return;

		// This should be handled by AdcCommand really...
		c.getParameters().erase(c.getParameters().begin());

		SearchManager::getInstance()->onRES(c, user, aRemoteIp);
	} else if (x.compare(1, 4, "PSR ") == 0 && x[x.length() - 1] == 0x0a) {
		AdcCommand c(x.substr(0, x.length()-1));
		if(c.getParameters().empty())
			return;
		string cid = c.getParam(0);
		if(cid.size() != 39)
			return;

		UserPtr user = ClientManager::getInstance()->findUser(CID(cid));
		// when user == NULL then it is probably NMDC user, check it later
			
		c.getParameters().erase(c.getParameters().begin());			
			
		SearchManager::getInstance()->onPSR(c, user, aRemoteIp);
		
	} else if (x.compare(1, 4, "PBD ") == 0 && x[x.length() - 1] == 0x0a) {
		if (!SETTING(USE_PARTIAL_SHARING)) {
			return;
		}
		//LogManager::getInstance()->message("GOT PBD UDP: " + x);
		AdcCommand c(x.substr(0, x.length()-1));
		if(c.getParameters().empty())
			return;
		string cid = c.getParam(0);
		if(cid.size() != 39)
			return;

		UserPtr user = ClientManager::getInstance()->findUser(CID(cid));
			
		c.getParameters().erase(c.getParameters().begin());			
			
		if (user)
			SearchManager::getInstance()->onPBD(c, user);
		
	} else if ((x.compare(1, 4, "UBD ") == 0 || x.compare(1, 4, "UBN ") == 0) && x[x.length() - 1] == 0x0a) {
		AdcCommand c(x.substr(0, x.length()-1));
		if(c.getParameters().empty())
			return;
			
		c.getParameters().erase(c.getParameters().begin());			
			
		if (x.compare(1, 4, "UBN ") == 0) {
			//LogManager::getInstance()->message("GOT UBN UDP: " + x);
			UploadManager::getInstance()->onUBN(c);
		} else {
			//LogManager::getInstance()->message("GOT UBD UDP: " + x);
			UploadManager::getInstance()->onUBD(c);
		}
	}
}
Пример #9
0
void Client::on(Line, const string& aLine) noexcept {
	updateActivity();
	COMMAND_DEBUG(aLine, DebugManager::TYPE_HUB, DebugManager::INCOMING, getIpPort());
}
Пример #10
0
int UDPServer::PacketProcessor::run() {
	while (true) {
		s.wait();
		if (stop)
			break;

		unique_ptr<PacketTask> t;
		if(!queue.pop(t)) {
			continue;
		}

		string x((char*)t->buf, t->len);
		string remoteIp = move(t->remoteIp);

		//check if this packet has been encrypted
		if (SETTING(ENABLE_SUDP) && t->len >= 32 && ((t->len & 15) == 0)) {
			SearchManager::getInstance()->decryptPacket(x, t->len, t->buf, BUFSIZE);
		}
			
		delete t->buf;
		if (x.empty())
			continue;

		COMMAND_DEBUG(x, DebugManager::TYPE_CLIENT_UDP, DebugManager::INCOMING, remoteIp);

		if(x.compare(0, 4, "$SR ") == 0) {
			SearchManager::getInstance()->onSR(x, remoteIp);
		} else if(x.compare(1, 4, "RES ") == 0 && x[x.length() - 1] == 0x0a) {
			AdcCommand c(x.substr(0, x.length()-1));
			if(c.getParameters().empty())
				continue;
			string cid = c.getParam(0);
			if(cid.size() != 39)
				continue;

			UserPtr user = ClientManager::getInstance()->findUser(CID(cid));
			if(!user)
				continue;

			// This should be handled by AdcCommand really...
			c.getParameters().erase(c.getParameters().begin());

			SearchManager::getInstance()->onRES(c, user, remoteIp);
		} else if(x.compare(1, 4, "DSR ") == 0 && x[x.length() - 1] == 0x0a) {
			AdcCommand c(x.substr(0, x.length()-1));
			if(c.getParameters().empty())
				continue;
			string cid = c.getParam(0);
			if(cid.size() != 39)
				continue;

			c.getParameters().erase(c.getParameters().begin());
			SearchManager::getInstance()->onDSR(c);
		} else if (x.compare(1, 4, "PSR ") == 0 && x[x.length() - 1] == 0x0a) {
			AdcCommand c(x.substr(0, x.length()-1));
			if(c.getParameters().empty())
				continue;
			string cid = c.getParam(0);
			if(cid.size() != 39)
				continue;

			UserPtr user = ClientManager::getInstance()->findUser(CID(cid));
			// when user == NULL then it is probably NMDC user, check it later
			
			c.getParameters().erase(c.getParameters().begin());			
			
			SearchManager::getInstance()->onPSR(c, user, remoteIp);
		
		} else if (x.compare(1, 4, "PBD ") == 0 && x[x.length() - 1] == 0x0a) {
			if (!SETTING(USE_PARTIAL_SHARING)) {
				continue;
			}
			//LogManager::getInstance()->message("GOT PBD UDP: " + x);
			AdcCommand c(x.substr(0, x.length()-1));
			if(c.getParameters().empty())
				continue;
			string cid = c.getParam(0);
			if(cid.size() != 39)
				continue;

			UserPtr user = ClientManager::getInstance()->findUser(CID(cid));
			
			c.getParameters().erase(c.getParameters().begin());			
			
			if (user)
				SearchManager::getInstance()->onPBD(c, user);
		
		} else if ((x.compare(1, 4, "UBD ") == 0 || x.compare(1, 4, "UBN ") == 0) && x[x.length() - 1] == 0x0a) {
			AdcCommand c(x.substr(0, x.length()-1));
			if(c.getParameters().empty())
				continue;
			
			c.getParameters().erase(c.getParameters().begin());			
			
			if (x.compare(1, 4, "UBN ") == 0) {
				//LogManager::getInstance()->message("GOT UBN UDP: " + x);
				UploadManager::getInstance()->onUBN(c);
			} else {
				//LogManager::getInstance()->message("GOT UBD UDP: " + x);
				UploadManager::getInstance()->onUBD(c);
			}
		}
	}

	return 0;

	/*else if(x.compare(1, 4, "SCH ") == 0 && x[x.length() - 1] == 0x0a) {
		try {
			respond(AdcCommand(x.substr(0, x.length()-1)));
		} catch(ParseException& ) {
		}
	}*/ // Needs further DoS investigation
}
Пример #11
0
void Client::on(Line, const string& aLine) noexcept
{
	updateActivity();
	COMMAND_DEBUG(aLine, DebugTask::HUB_IN, getIpPort());
}