Ejemplo n.º 1
0
void message_handler::read_header() {
  memset(read_msg_.data(), '\0', read_msg_.length());
  boost::asio::async_read(socket_,
      boost::asio::buffer(read_msg_.data(), message::header_size_),
      [this](boost::system::error_code ec, std::size_t) {
        if (!ec && read_msg_.decode_header()) { 
          read_body();
        } else {
            std::cout << "Error Reading message body " << ec << std::endl;
            //TODO Update the remove handler from list at EOF of disconnect
            ob.update_observer(client_id);
        }
      }
  );
}
Ejemplo n.º 2
0
void GateModule::ClientClose(const message& msg)
{
	buffer_reader buf(msg.data(), msg.size());

	std::string addr;
	buf >> addr;

	Log.trace("1.client close [socketid:{0}] [address:{1}] begin.", msg.get_socket_id().value, addr.data());
	auto pconn = m_Connections->find(msg.get_socket_id());
	if (pconn == nullptr)
	{
		Log.trace("!!client close failed can not find conn [socketid:{0}].", msg.get_socket_id().value);
		return;
	}

	auto accountID = pconn->getaccount_id();
	auto playerID = pconn->getplayer_id();

	Log.trace("3.client close [socketid:{0}] [address:{1}] find account data[accountid:{2}]  success[playerid:{3}].", msg.get_socket_id().value, addr.data(), accountID.value,playerID.value);
	
	OnClientClose(accountID, playerID);
	
	if (m_Connections->remove(msg.get_socket_id()))
	{
		Log.trace("client close [socketid:{0}] [address:{1}]  accountID[{2}] playerID[{3}] end.", msg.get_socket_id().value, addr.data(), accountID.value, playerID.value);
	}
	else
	{
		assert(0);
	}
}
Ejemplo n.º 3
0
void AdminClient::read_handler(const boost::system::error_code& error, std::size_t bytes) {
    std::cout << "Recieved " << bytes << " bytes.\n";

    // The extra parens around the first argument here are necessary 
    // to avoid g++ interpreting this as a function declaration
    //std::string s((std::istreambuf_iterator<char>(&read_buffer_)), std::istreambuf_iterator<char>());

    if (error == boost::asio::error::eof)
        close();
    else if (error == boost::asio::error::operation_aborted)
        return;
    else if (error){
        std::cout << "Throwing an error.\n";
        throw boost::system::system_error(error); // Some other error.
    }

    std::string s(read_message_.data(bytes));
    std::cout << "Built string.\n";

    read_message_.consume(bytes);
    std::cout << read_message_.buffer().size() << " bytes remaining in buffer.\n";

    std::cout << s << "-----------------------\n";

    boost::system::error_code err;
    boost::asio::async_read_until(sock_, read_message_.buffer(), '\n', 
        boost::bind(&AdminClient::read_handler, this, 
            boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
}
Ejemplo n.º 4
0
void GateModule::ClientConnect(const message& msg)
{
	buffer_reader buf(msg.data(), msg.size());

	std::string addr;
	buf >> addr;
	Log.trace("socket [socket:{0}] [address:{1}] connect", msg.get_socket_id().value,addr.data());
}
Ejemplo n.º 5
0
attachment::attachment(message& mapi_message, const uint32_t attach_num) throw(mapi_exception)
: object(mapi_message.get_session(), "attachment"), m_attach_num(attach_num), m_bin_data(NULL), m_data_size(0), m_filename("")
{
	if (OpenAttach(&mapi_message.data(), attach_num, &m_object) != MAPI_E_SUCCESS)
		throw mapi_exception(GetLastError(), "attachment::attachment : OpenAttach");

	property_container properties = get_property_container();
	properties << PR_ATTACH_FILENAME << PR_ATTACH_LONG_FILENAME << PR_ATTACH_SIZE << PR_ATTACH_DATA_BIN << PR_ATTACH_METHOD;
	properties.fetch();

	const char* filename = static_cast<const char*>(properties[PR_ATTACH_LONG_FILENAME]);
	if (!filename) {
		filename = static_cast<const char*>(properties[PR_ATTACH_FILENAME]);
	}

	if (filename)
		m_filename = filename;

	m_data_size = *(static_cast<const uint32_t*>(properties[PR_ATTACH_SIZE]));

	const Binary_r* attachment_data = static_cast<const Binary_r*>(properties[PR_ATTACH_DATA_BIN]);

	// Don't load PR_ATTACH_DATA_BIN if it's embedded in message.
	// NOTE: Use RopOpenEmbeddedMessage when it is implemented.
	const uint32_t attach_method = *static_cast<const uint32_t*>(properties[PR_ATTACH_METHOD]);
	if (attach_method != ATTACH_BY_VALUE)
		return;

	// Get Binary Data.
	if (attachment_data) {
		m_data_size = attachment_data->cb;
		m_bin_data = new uint8_t[m_data_size];
		memcpy(m_bin_data, attachment_data->lpb, attachment_data->cb);
	} else {
		mapi_object_t obj_stream;
		mapi_object_init(&obj_stream);
		if (OpenStream(&m_object, (enum MAPITAGS)PidTagAttachDataBinary, OpenStream_ReadOnly, &obj_stream) != MAPI_E_SUCCESS)
			throw mapi_exception(GetLastError(), "attachment::attachment : OpenStream");

		if (GetStreamSize(&obj_stream, &m_data_size) != MAPI_E_SUCCESS)
			throw mapi_exception(GetLastError(), "attachment::attachment : GetStreamSize");

		m_bin_data = new uint8_t[m_data_size];

		uint32_t pos = 0;
		uint16_t bytes_read = 0;
		do {
			if (ReadStream(&obj_stream, m_bin_data+pos, 1024, &bytes_read) != MAPI_E_SUCCESS)
				throw mapi_exception(GetLastError(), "attachment::attachment : ReadStream");

			pos += bytes_read;

		} while (bytes_read && pos < m_data_size);

		mapi_object_release(&obj_stream);
	}
}
Ejemplo n.º 6
0
//客户端发来的数据
void GateModule::ClientData(const message& msg)
{
	if (msg.size() == 0)
		return;

	user_id id(account_id::create(0));
	id.set_socket_id(msg.get_socket_id());

	if (DispatchMessages(id,msg,0))
	{
		return;
	}
	
	auto pconn = m_Connections->find(msg.get_socket_id());
	if (pconn == nullptr)
	{
		Log.trace("非法数据!");
		return;
	}


	uint16_t msgID = *(uint16_t*)msg.data();
	if (msgID > (uint16_t)EMsgID::MSG_MUST_HAVE_PLAYERID)
	{
		if (pconn->getplayer_id() == player_id())
		{
			Log.trace("非法数据!");
			return;
		}
	}

	UserContext ctx;
	ctx.accountid = pconn->getaccount_id();
	ctx.playerid = pconn->getplayer_id();

	msg.set_userdata((uint8_t*)&ctx,sizeof(ctx));

	if (pconn->getscene_id() != 0)
	{
		//如果在玩家在场景模块中 则发送给场景模块
	}
	else
	{
		if (m_WorldModule == 0)
		{
			m_WorldModule = GetOtherModule("world");
			assert(m_WorldModule != 0);
		}

		//否则发送给 world 模块
	}
}
// NOTE: the format of this response changed in v3 (send only code on error).
void transaction_pool::validate(server_node& node, const message& request,
    send_handler handler)
{
    transaction tx;

    if (!tx.from_data(request.data()))
    {
        handler(message(request, error::bad_stream));
        return;
    }

    node.pool().validate(tx,
        std::bind(&transaction_pool::handle_validated,
            _1, _2, _3, _4, request, handler));
}
// Broadcast a transaction with penetration subscription.
void transaction_pool::broadcast(server_node& node, const message& request,
    send_handler handler)
{
    transaction tx;

    if (!tx.from_data(request.data()))
    {
        handler(message(request, error::bad_stream));
        return;
    }

    // TODO: conditionally subscribe to penetration notifications.
    // TODO: broadcast transaction to receiving peers.
    handler(message(request, error::operation_failed));
}
bool unwrap_fetch_transaction_args(hash_digest& hash,
    const message& request)
{
    const auto& data = request.data();

    if (data.size() != hash_size)
    {
        log::error(LOG_SERVER)
            << "Invalid hash length in fetch_transaction request.";
        return false;
    }

    auto deserial = make_deserializer(data.begin(), data.end());
    hash = deserial.read_hash();
    return true;
}
Ejemplo n.º 10
0
bool ModuleBases::DispatchMessages(const user_id & userid, const message & msg, uint64_t sender_echo_id)
{
	buffer_reader br(msg.data(), msg.size());

	uint16_t msgID = 0;
	br >> msgID;

	if (msgID == uint16_t(EMsgID::MSG_S2S_ClientClose))
	{
		account_id accountID;
		player_id playerID;
		br >> accountID.value;
		br >> playerID.value;
		OnClientClose(accountID, playerID);
		return true;
	}
bool unwrap_fetch_history_args(payment_address& address,
    uint32_t& from_height, const message& request)
{
    static constexpr size_t history_args_size = sizeof(uint8_t) +
        short_hash_size + sizeof(uint32_t);

    const auto& data = request.data();

    if (data.size() != history_args_size)
    {
        log::error(LOG_SERVER)
            << "Incorrect data size for .fetch_history";
        return false;
    }

    auto deserial = make_deserializer(data.begin(), data.end());
    const auto version_byte = deserial.read_byte();
    const auto hash = deserial.read_short_hash();
    from_height = deserial.read_4_bytes_little_endian();
    BITCOIN_ASSERT(deserial.iterator() == data.end());

    address = payment_address(hash, version_byte);
    return true;
}
Ejemplo n.º 12
0
void client_socket_utils::read_data_callback(const boost::system::error_code& e, socket_session_ptr session, message& msg)
{
	LOG4CXX_DEBUG(firebird_log, "command =[" << msg.command << "],[" << msg.business_type << "],[" << msg.data() << "]");

	if (msg.command == heartbeat)
	{ //心跳
	}
	else
		if (msg.command == regist)
		{ //注册
			LOG4CXX_FATAL(firebird_log, "服务器:[" << session->get_business_type() << "]注册成功。");
		}
		else
			if (msg.command == normal)
			{ //业务数据
				handle_read_data(msg, session);
			}
			else
			{
				LOG4CXX_ERROR(firebird_log, KDS_CODE_INFO << "收到非法消息包!");
			}
}
Ejemplo n.º 13
0
	message(message& other) : _data(NULL) {
		body_reset(other.length_body());
		data()[0] = other.data()[0]; //copy header
		if (length_body() > 0)
			memcpy(data(), other.data(), length_body());
	}