Example #1
0
void
tcp_client::async_read(void) {
    boost::asio::async_read(m_socket, boost::asio::buffer(m_read_buffer.data(), READ_SIZE),
        [](const boost::system::error_code& error, std::size_t bytes) -> std::size_t {
            //! break if bytes have been received, continue otherwise
            return error or bytes ? 0 : READ_SIZE;
        },
        [=](boost::system::error_code error, std::size_t length) {
            if (error) {
                process_disconnection();
                return ;
            }

            std::lock_guard<std::mutex> lock(m_receive_handler_mutex);
            if (m_receive_handler)
                if (not m_receive_handler(*this, { m_read_buffer.begin(), m_read_buffer.begin() + length })) {
                    process_disconnection();
                    return ;
                }

            //! keep waiting for incoming bytes
            async_read();
        });
}
Example #2
0
void
tcp_client::async_write(void) {
    boost::asio::async_write(m_socket, boost::asio::buffer(m_write_buffer.data(), m_write_buffer.size()),
        [this](boost::system::error_code error, std::size_t length) {
            if (error) {
                process_disconnection();
                return ;
            }

            std::lock_guard<std::mutex> lock(m_write_buffer_mutex);
            m_write_buffer.erase(m_write_buffer.begin(), m_write_buffer.begin() + length);

            if (m_write_buffer.size())
                async_write();
        });
}
Example #3
0
/*
 * nuke
 *
 * Usage: nuke user
 *
 *   This command disconnects the user from the server.  The user is informed
 *   that she/he has been nuked by the admin named and a comment is
 *   automatically placed in the user's files (if she/he is a registered
 *   user, of course).
 */
int com_nuke(int p, param_list param)
{
	struct player *pp = &player_globals.parray[p];
	int p1, fd;

	if ((p1 = player_find_part_login(param[0].val.word)) < 0) {
		pprintf(p, "%s isn't logged in.\n", param[0].val.word);
		return COM_OK;
	}

	if (!check_admin2(p, p1)) {
		pprintf(p, "You need a higher adminlevel to nuke %s!\n", param[0].val.word);
		return COM_OK;
	}

	pprintf(p, "Nuking: %s\n", param[0].val.word);
	pprintf(p, "Please leave a comment explaining why %s was nuked.\n", player_globals.parray[p1].name);
	pprintf(p1, "\n\n**** You have been kicked out by %s! ****\n\n", pp->name);
	if (CheckPFlag(p1, PFLAG_REG)) pcommand(p, "addcomment %s Nuked\n", player_globals.parray[p1].name); /* addcomment doesnt work on guests */
	fd = player_globals.parray[p1].socket;
	process_disconnection(fd);
	net_close_connection(fd);
	return COM_OK;
}