Ejemplo n.º 1
0
	void Client::transmitmore( const void *data, int len )
	{
	  if ( !fpLog.empty() )
	  {
        fmt::Writer tmp;
        tmp << "Server -> Client (" << len << " bytes)\n";
        Clib::fdump( tmp, data, len );
        FLEXLOG( fpLog ) << tmp.c_str() << "\n";
	  }

	  if ( encrypt_server_stream )
	  {
		pause();
		transmit_encrypted( data, len );
	  }
	  else
	  {
		xmit( data, static_cast<unsigned short>( len ) );
		// _xmit( client->csocket, data, len );
	  }
	}
Ejemplo n.º 2
0
void Client::transmit( const void* data, int len, bool needslock )
{
  ref_ptr<Core::BPacket> p;
  bool handled = false;
  // see if the outgoing packet has a SendFunction installed. If so call it. It may or may not
  // want us to continue sending the packet. If it does, handled will be false, and data, len, and p
  // will be altered. data has the new packet data to send, len the new length, and p, a ref counted
  // pointer to the packet object.
  //
  // If there is no outgoing packet script, handled will be false, and the passed params will be
  // unchanged.
  {
    PacketHookData* phd = nullptr;
    handled = GetAndCheckPacketHooked( this, data, phd );
    if ( handled )
    {
      if ( needslock )
      {
        Core::PolLock lock;
        std::lock_guard<std::mutex> guard( _SocketMutex );
        CallOutgoingPacketExportedFunction( this, data, len, p, phd, handled );
      }
      else
      {
        std::lock_guard<std::mutex> guard( _SocketMutex );
        CallOutgoingPacketExportedFunction( this, data, len, p, phd, handled );
      }
    }
  }

  if ( handled )
    return;

  unsigned char msgtype = *(const char*)data;

  {
    Clib::SpinLockGuard guard( _fpLog_lock );
    if ( !fpLog.empty() )
    {
      fmt::Writer tmp;
      tmp << "Server -> Client: 0x" << fmt::hexu( msgtype ) << ", " << len << " bytes\n";
      Clib::fdump( tmp, data, len );
      FLEXLOG( fpLog ) << tmp.str() << "\n";
    }
  }

  std::lock_guard<std::mutex> guard( _SocketMutex );
  if ( disconnect )
  {
    POLLOG_INFO << "Warning: Trying to send to a disconnected client! \n";
    fmt::Writer tmp;
    tmp << "Server -> Client: 0x" << fmt::hexu( msgtype ) << ", " << len << " bytes\n";
    Clib::fdump( tmp, data, len );
    POLLOG_INFO << tmp.str() << "\n";
    return;
  }

  if ( last_xmit_buffer )
  {
    Core::networkManager.queuedmode_iostats.sent[msgtype].count++;
    Core::networkManager.queuedmode_iostats.sent[msgtype].bytes += len;
  }
  Core::networkManager.iostats.sent[msgtype].count++;
  Core::networkManager.iostats.sent[msgtype].bytes += len;

  if ( encrypt_server_stream )
  {
    pause();
    transmit_encrypted( data, len );
  }
  else
  {
    xmit( data, static_cast<unsigned short>( len ) );
    // _xmit( client->csocket, data, len );
  }
}