示例#1
0
        virtual void on_async_response_received(
            error_code const & ec,
            size_t bytes_transferred,
            session_ptr sess
        )
        {
            std::cout << ec << " Response received: (" << bytes_transferred << ") ";
            sess->dump_buffer(bytes_transferred);
            std::cout << std::endl;

            if(!ec)
            {
                if(sess->data_buffer[1] == 0x5a)
                {
                    sess->handler(error_code());
                }
                else
                {
                    sess->handler(error_code(boost::asio::error::connection_refused));
                }
            }
            else
            {
                sess->handler(ec);
            }
        }
 void handle_accept(session_ptr new_session,
     const asio::error_code& error)
 {
   if (!error)
   {
     new_session->start();
     new_session.reset(new session(io_service_));
     acceptor_.async_accept(new_session->socket(),
         boost::bind(&server::handle_accept, this, new_session,
           asio::placeholders::error));
   }
 }
示例#3
0
void session_created( session_ptr session ) {
	if( ! session ) {
		LOG( "error, not connected." );
		return ;
	}

	session_handler_ptr handler(new udp_session_handler());
	session->set_handler( handler );
	session->get_filter_chain()->session_connected( session );

	client = session;
}
示例#4
0
	void handle_accept(session_ptr new_session,
		const boost::system::error_code& error)
	{
		if (!error)
		{
			new_session->start();
			new_session.reset(new session(io_service_work_pool_.get_io_service(), io_service_pool_.get_io_service()));
			acceptor_.async_accept(new_session->socket(),
				boost::bind(&server::handle_accept, this, new_session,
				boost::asio::placeholders::error));
		}
	}
示例#5
0
 virtual void on_async_request_sent(
     error_code const & ec,
     session_ptr sess
 )
 {
     if(!ec)
     {
         boost::asio::async_read(
             sess->socket.get(),
             boost::asio::buffer(sess->data_buffer),
             boost::asio::transfer_at_least(8),
             boost::bind(
                 &socks4_proxy::on_async_response_received,
                 this,
                 boost::asio::placeholders::error,
                 boost::asio::placeholders::bytes_transferred,
                 sess
             )
         );
     }
     else
     {
         sess->handler(ec);
     }
 }
示例#6
0
        /// 插入
        void insert(session_ptr sp)
        {
            if (!sp) return ;

            BOOST_INTERLOCKED_INCREMENT(&size_);
            typename lock_type::scoped_lock lock(lock_);
            list_.push_back(sp.get());
        }
示例#7
0
void Connection::handle_accept(session_ptr session, const boost::system::error_code& error)
{
	if (!error)
	{
		session->start();
		session_ptr new_session(new Session(io_service_, room_));
		acceptor_.async_accept(new_session->socket(), boost::bind(&Connection::handle_accept, this, new_session, boost::asio::placeholders::error));
	}
}
示例#8
0
void server::handle_accept(session_ptr new_session,
		const boost::system::error_code& error)
{
		if (!error)
		{
			{
				boost::mutex::scoped_lock lock(sessionsLock_);
				sessions_.push_back(new_session);

				session_ptr new_session(new session(io_service_, this, maxLength_));
				acceptor_.async_accept(new_session->socket(),
								boost::bind(&server::handle_accept, this, new_session,
										boost::asio::placeholders::error));
			}
			new_session->start();
		}
		start_accept();
}
示例#9
0
void handle_read(const session_ptr& the_session,
    handler_allocator_type& the_allocator,
    const frame_buffer_ptr& frame_buffer,
    const boost::system::error_code& error,
    std::size_t frames_transferred)
{
  print_frames(*frame_buffer, frames_transferred);

  if (boost::asio::error::eof == error)
  {
    std::cout << "Input stream was closed." \
        " But it\'s a serial port so begin read operation again...\n";

    the_session->async_read_some(frame_buffer->begin(), frame_buffer->end(),
        ma::make_custom_alloc_handler(the_allocator, ma::detail::bind(
            handle_read, the_session, ma::detail::ref(the_allocator), 
            frame_buffer, ma::detail::placeholders::_1, 
            ma::detail::placeholders::_2)));
    return;
  }

  if (error)
  {
    std::cout << "Read unsuccessful. Begin the session stop...\n";
    the_session->async_stop(ma::make_custom_alloc_handler(the_allocator,
        ma::detail::bind(handle_stop, ma::detail::placeholders::_1)));
    return;
  }

  the_session->async_read_some(frame_buffer->begin(), frame_buffer->end(),
      ma::make_custom_alloc_handler(the_allocator, ma::detail::bind(handle_read,
          the_session, ma::detail::ref(the_allocator), frame_buffer,
          ma::detail::placeholders::_1, ma::detail::placeholders::_2)));

  // Only for test of cyclic_read_session::async_write_some
  //frame_ptr frame = *(frame_buffer->begin());
  //the_session->async_write_some(boost::asio::buffer(*frame),
  //    ma::detail::bind(handle_write, the_session, frame, 
  //        ma::detail::placeholders::_1, ma::detail::placeholders::_2));
}
示例#10
0
	  void handle_accept(session_ptr new_session,
		  const boost::system::error_code& error)
	  {
		  if(!error)
		  {
			  cout << "accept connection ..." << endl;
			  new_session->start();
			  do_accept();
		  }
		  else
		  {
			  delete new_session;
		  }
	  }
示例#11
0
 void handle_accept(session_ptr new_session,
                    const boost::system::error_code & error)
 {
     if (!error)
     {
         std::cout << "New connection accepted" << std::endl;
         new_session->start();
         start_accept();
     }
     else if (error != boost::asio::error::operation_aborted)
     {
         // 'operation_aborted' error occurs on server stoppage
         handle_error(error);
     }
 }
示例#12
0
void server::join(const session_ptr& _user, user_id_type& uid)
{
	if (closing)
		return;
	std::lock_guard<std::mutex> lock(session_mutex);
	user_id_type newID = nextID;
	nextID++;
	sessions.emplace(newID, _user);
	uid = newID;

	misc_iosrv.post([this, newID, _user]() {
		try { on_join(newID, _user->get_key()); }
		catch (std::exception &ex) { on_exception(ex); }
		catch (...) {}
	});
}
示例#13
0
void handle_start(const session_ptr& the_session,
    handler_allocator_type& the_allocator,
    const frame_buffer_ptr& frame_buffer,
    const boost::system::error_code& error)
{
  if (error)
  {
    std::cout << "Start unsuccessful. The error is: "
        << error.message() << '\n';
    return;
  }

  std::cout << "Session started successfully. Begin read...\n";

  the_session->async_read_some(frame_buffer->begin(), frame_buffer->end(),
      ma::make_custom_alloc_handler(the_allocator, boost::bind(handle_read,
          the_session, boost::ref(the_allocator), frame_buffer, _1, _2)));
}
void	run_script( session_ptr session, std::string fileName, mission_id inMissionID )
{
	user_session_ptr	loginInfo = session->find_sessiondata<user_session>(USER_SESSION_DATA_ID);		
	if( !loginInfo || (loginInfo->my_user_flags() & USER_FLAG_SERVER_OWNER) == 0 )
	{
		session->printf( "/!not_permitted\r\n" );
		return;
	}
	
	if( fileName.size() == 0 || fileName.find("..") != std::string::npos )
	{
		session->printf( "/!no_such_file\r\n" );
		return;
	}
	std::string	filePath( sSettingsFolderPath );
	filePath.append( "/scripts/" );
	filePath.append( fileName );
	filePath.append( ".lua" );
	
	// ===== LUA CODE START: =====
	lua_State *L = luaL_newstate();	// Create a context.
	
	luaL_openlibs(L);	// Load Lua standard library.
	
	// Load the file:
	int s = luaL_loadfile( L, filePath.c_str() );

	if( s == 0 )
	{
		// Run it, with 0 params, accepting an arbitrary number of return values.
		//	Last 0 is error handler Lua function's stack index, or 0 to ignore.
		s = lua_pcall(L, 0, LUA_MULTRET, 0);	// Create all the functions and objects.
	}
	
	// Create a C-backed Lua object:
	lua_newtable( L );	// Create a new object & push it on the stack.
	
	lua_newtable( L );	// Create a new 'mission' object & push it on the stack.
	lua_pushlightuserdata( L, &session );	// session object in case we need it.
	lua_pushinteger( L, inMissionID );	// mission ID.
	lua_pushcclosure( L, mission_add_objective, 2 );// Create the method.
	lua_setfield( L, -2, "add_objective" );	// Attach it to the object with a name.
	lua_pushlightuserdata( L, &session );	// session object in case we need it.
	lua_pushcclosure( L, mission_load, 1 );// Create the method.
	lua_setfield( L, -2, "load" );	// Attach it to the object with a name.
	lua_setglobal( L, "mission" );	// Register the object as name "mission".

	if( s == 0 )
	{
		lua_getglobal(L,"main");	// Push the function we want to call.
		s = lua_pcall(L, 0, LUA_MULTRET, 0);
	}

	// Was an error? Get error message off the stack and send it back:
	if( s != 0 )
	{
		session->printf( "/!script_error %s\r\n", lua_tostring(L, -1) );
		lua_pop(L, 1); // remove error message
	}
	else
		session->printf( "/ran_script\r\n" );	// Send back indication of success.
	lua_close(L);	// Dispose of the script context.
	
	// ===== LUA CODE END. =====
}
示例#15
0
void handle_console_close(const session_ptr& session)
{
  std::cout << "User console close detected. Begin stop the session...\n";
  session->async_stop(boost::bind(handle_stop, _1));
}
示例#16
0
void handle_console_close(const session_ptr& session)
{
  std::cout << "User console close detected. Begin stop the session...\n";
  session->async_stop(
      ma::detail::bind(handle_stop, ma::detail::placeholders::_1));
}