Esempio n. 1
0
void init_threadhelp()
{
  int res;
  res = pthread_attr_init( &create_detached_attr );
  passert_always( res == 0 );
  res = pthread_attr_setdetachstate( &create_detached_attr, PTHREAD_CREATE_DETACHED );
  passert_always( res == 0 );
}
Esempio n. 2
0
	void polsem_unlock()
	{
	  pid_t pid = getpid();
	  passert_always( locker == pid );
	  locker = 0;
	  int res = pthread_mutex_unlock( &polsem );
	  if (res != 0)
	  {
        POLLOG.Format( "pthread_mutex_unlock: res={},pid={}") << res << pid;
	  }
	  passert_always( res == 0 );
	}
Esempio n. 3
0
	void polsem_lock()
	{
	  pid_t pid = getpid();
	  int res = pthread_mutex_lock( &polsem );
	  if (res != 0 || locker != 0)
	  {
        POLLOG.Format( "pthread_mutex_lock: res={}, pid={}, locker={}\n")<< res<< pid<< locker;
	  }
	  passert_always( res == 0 );
	  passert_always( locker == 0 );
	  locker = pid;
	}
Esempio n. 4
0
int CCryptBlowfish::Receive( void* buffer, int max_expected, SOCKET socket )
{
  passert_always( max_expected >= 0 );
  passert_always( MAXBUFFER > max_expected );
  int count = recv( socket, (char*)encrypted_data, max_expected, 0 );
  if ( count > 0 )
  {
    passert( count <= max_expected );
    Decrypt( encrypted_data, buffer, count );
  }
  return count;
}
Esempio n. 5
0
void singleclick(Network::Client* client, u32 serial)
{
  passert_always(client != nullptr && client->chr != nullptr);

  if (IsCharacter(serial))
  {
    Mobile::Character* chr = nullptr;
    if (serial == client->chr->serial)
      chr = client->chr;
    else
      chr = find_character(serial);

    if (chr != nullptr && inrange(client->chr, chr) && !client->chr->is_concealed_from_me(chr))
    {
      if (chr->has_title_guild() && (settingsManager.ssopt.core_handled_tags & 0x1))
        send_nametext(client, chr, "[" + chr->title_guild() + "]");
      send_nametext(client, chr, chr->name());

      std::string tags = create_nametags(chr);
      if (!tags.empty())
        send_nametext(client, chr, tags);
    }
  }
  else // single clicked on an item
  {
    Items::Item* item = find_legal_singleclick_item(client->chr, serial);
    if (item)
    {
      send_objdesc(client, item);
    }
  }
}
Esempio n. 6
0
	void polsem_unlock()
	{
	  DWORD tid = GetCurrentThreadId();
	  passert_always( locker == tid );
	  locker = 0;
	  LeaveCriticalSection( &cs );
	}
Esempio n. 7
0
	void polsem_lock()
	{
	  DWORD tid = GetCurrentThreadId();
	  EnterCriticalSection( &cs );
	  passert_always( locker == 0 );
	  locker = tid;
	}
Esempio n. 8
0
void load_attributes_cfg()
{
  load_packaged_cfgs( "attributes.cfg", "Attribute", load_attribute_entry );
  Core::gamestate.numAttributes = static_cast<unsigned int>( Core::gamestate.attributes.size() );

  Core::gamestate.pAttrStrength = Attribute::FindAttribute( "Strength" );
  Core::gamestate.pAttrIntelligence = Attribute::FindAttribute( "Intelligence" );
  Core::gamestate.pAttrDexterity = Attribute::FindAttribute( "Dexterity" );

  Core::gamestate.pAttrParry = Attribute::FindAttribute( "Parry" );
  Core::gamestate.pAttrTactics = Attribute::FindAttribute( "Tactics" );

  passert_always( Core::gamestate.pAttrStrength );
  passert_always( Core::gamestate.pAttrIntelligence );
  passert_always( Core::gamestate.pAttrDexterity );
  passert_always( Core::gamestate.pAttrParry );
  passert_always( Core::gamestate.pAttrTactics );
}
Esempio n. 9
0
void load_vitals_cfg()
{
  checkpoint( "load_vitals_cfg: load_packed_cfgs" );
  load_packaged_cfgs( "vitals.cfg", "Vital", load_vital_entry );

  gamestate.numVitals = static_cast<unsigned int>( gamestate.vitals.size() );

  checkpoint( "load_vitals_cfg: find Life vital" );
  gamestate.pVitalLife = FindVital( "Life" );
  checkpoint( "load_vitals_cfg: find Stamina vital" );
  gamestate.pVitalStamina = FindVital( "Stamina" );
  checkpoint( "load_vitals_cfg: find Mana vital" );
  gamestate.pVitalMana = FindVital( "Mana" );

  checkpoint( "load_vitals_cfg: verify vital vitals" );
  passert_always( gamestate.pVitalLife );
  passert_always( gamestate.pVitalStamina );
  passert_always( gamestate.pVitalMana );
}
Esempio n. 10
0
	void init_ipc_vars()
	{
	  int res;
	  res = pthread_mutexattr_init( &polsem_attr );
	  passert_always( res == 0 );

	  /*
		  res = pthread_mutexattr_setkind_np( &polsem_attr, PTHREAD_MUTEX_ERRORCHECK_NP );
		  passert_always( res == 0 );

		  res = pthread_mutexattr_settype( &polsem_attr, PTHREAD_MUTEX_ERRORCHECK );
		  passert_always( res == 0 );
		  */

	  res = pthread_mutex_init( &polsem, &polsem_attr );
	  passert_always( res == 0 );

	  pthread_attr_init( &thread_attr );
	  pthread_attr_setdetachstate( &thread_attr, PTHREAD_CREATE_DETACHED );
	}
Esempio n. 11
0
bool run_script_to_completion( const char *filename, BObjectImp* parameter )
{
    passert_always( parameter );
    BObject bobj( parameter );
    ref_ptr<EScriptProgram> program = find_script( filename );
	if (program.get() == NULL)
	{
        cerr << "Error reading script " << filename << endl;
        return false;
	}

    UOExecutor ex;
    if (program->haveProgram)
    {
        ex.pushArg( parameter );
    }
    return run_script_to_completion_worker( ex, program.get()  );
}
Esempio n. 12
0
    bool newstat_dont_add( vector<Plib::STATIC_ENTRY>& vec, USTRUCT_STATIC* pstat )
    {
      char pheight = tileheight( pstat->graphic );

      for ( unsigned i = 0; i < vec.size(); ++i )
      {
        Plib::STATIC_ENTRY& prec = vec[i];
        passert_always( prec.objtype <= config.max_tile_id );
        char height = tileheight( prec.objtype ); // TODO read from itemdesc?
        unsigned char xy = ( pstat->x_offset << 4 ) | pstat->y_offset;
        if (// flags == pflags &&
             prec.objtype == pstat->graphic && // TODO map objtype->graphic from itemdesc
             height == pheight &&
             prec.xy == xy &&
             prec.z == pstat->z &&
             prec.hue == pstat->hue )
        {
          return true;
        }
      }
      return false;
    }
Esempio n. 13
0
unsigned long landtile_uoflags( unsigned short landtile )
{
    passert_always( landtile < N_LANDTILEDATA );
    return landtile_flags_arr[ landtile ];
}
Esempio n. 14
0
/* NOTE: If this changes, code in client.cpp must change - pause() and restart() use
   pre-encrypted values of 33 00 and 33 01.
   */
void Client::transmit_encrypted( const void* data, int len )
{
  THREAD_CHECKPOINT( active_client, 100 );
  const unsigned char* cdata = (const unsigned char*)data;
  unsigned char* pch;
  int i;
  int bidx;  // Offset in output byte
  EncryptedPktBuffer* outbuffer =
      PktHelper::RequestPacket<EncryptedPktBuffer>( ENCRYPTEDPKTBUFFER );
  pch = reinterpret_cast<unsigned char*>( outbuffer->getBuffer() );
  bidx = 0;
  THREAD_CHECKPOINT( active_client, 101 );
  for ( i = 0; i < len; i++ )
  {
    THREAD_CHECKPOINT( active_client, 102 );
    unsigned char ch = cdata[i];
    int nbits = Core::keydesc[ch].nbits;
    unsigned short inval = Core::keydesc[ch].bits_reversed;

    THREAD_CHECKPOINT( active_client, 103 );

    while ( nbits-- )
    {
      THREAD_CHECKPOINT( active_client, 104 );
      *pch <<= 1;
      if ( inval & 1 )
        *pch |= 1;
      bidx++;
      if ( bidx == 8 )
      {
        THREAD_CHECKPOINT( active_client, 105 );
        pch++;
        bidx = 0;
      }
      THREAD_CHECKPOINT( active_client, 106 );

      inval >>= 1;
    }
    THREAD_CHECKPOINT( active_client, 107 );
  }
  THREAD_CHECKPOINT( active_client, 108 );

  {
    int nbits = Core::keydesc[0x100].nbits;
    unsigned short inval = Core::keydesc[0x100].bits_reversed;

    THREAD_CHECKPOINT( active_client, 109 );

    while ( nbits-- )
    {
      THREAD_CHECKPOINT( active_client, 110 );
      *pch <<= 1;
      if ( inval & 1 )
        *pch |= 1;
      bidx++;
      THREAD_CHECKPOINT( active_client, 111 );
      if ( bidx == 8 )
      {
        pch++;
        bidx = 0;
      }
      THREAD_CHECKPOINT( active_client, 112 );

      inval >>= 1;
    }
  }
  THREAD_CHECKPOINT( active_client, 113 );

  if ( bidx == 0 )
  {
    pch--;
  }
  else
  {
    *pch <<= ( 8 - bidx );
  }
  THREAD_CHECKPOINT( active_client, 114 );

  passert_always( pch - reinterpret_cast<unsigned char*>( outbuffer->buffer ) + 1 <=
                  int( sizeof outbuffer->buffer ) );
  THREAD_CHECKPOINT( active_client, 115 );
  xmit( &outbuffer->buffer, static_cast<unsigned short>(
                                pch - reinterpret_cast<unsigned char*>( outbuffer->buffer ) + 1 ) );
  PktHelper::ReAddPacket( outbuffer );
  THREAD_CHECKPOINT( active_client, 116 );
}
Esempio n. 15
0
	void ProcessSolidBlock( unsigned short x_base, unsigned short y_base, MapWriter& mapwriter )
	{
	  unsigned int idx2_offset = 0;
	  SOLIDX2_ELEM idx2_elem;
	  memset( &idx2_elem, 0, sizeof idx2_elem );
	  idx2_elem.baseindex = mapwriter.NextSolidIndex();

	  unsigned short x_add_max = SOLIDX_X_SIZE, y_add_max = SOLIDX_Y_SIZE;
	  if ( x_base + x_add_max > uo_map_width )
		x_add_max = uo_map_width - x_base;
	  if ( y_base + y_add_max > uo_map_height )
		y_add_max = uo_map_height - y_base;

	  for ( unsigned short x_add = 0; x_add < x_add_max; ++x_add )
	  {
		for ( unsigned short y_add = 0; y_add < y_add_max; ++y_add )
		{
		  unsigned short x = x_base + x_add;
		  unsigned short y = y_base + y_add;

		  StaticList statics;

		  // read the map, and treat it like a static.
		  short z;
		  USTRUCT_MAPINFO mi;

		  safe_getmapinfo( x, y, &z, &mi );

          if ( mi.landtile > 0x3FFF )
            INFO_PRINT.Format( "Tile 0x{:X} at ({},{},{}) is an invalid ID!\n" ) << mi.landtile << x << y << z;

		  // for water, don't average with surrounding tiles.
		  if ( landtile_uoflags( mi.landtile ) & USTRUCT_TILE::FLAG_LIQUID )
			z = mi.z;
		  short low_z = get_lowestadjacentz( x, y, z );

		  short lt_height = z - low_z;
		  z = low_z;

          if ( mi.landtile > 0x3FFF )
            INFO_PRINT.Format( "Tile 0x{:X} at ({},{},{}) is an invalid ID!\n" ) << mi.landtile << x << y << z;

		  unsigned int lt_flags = landtile_uoflags( mi.landtile );
		  if ( ~lt_flags & USTRUCT_TILE::FLAG_BLOCKING )
		  { // this seems to be the default.
			lt_flags |= USTRUCT_TILE::FLAG_PLATFORM;
		  }
		  lt_flags |= USTRUCT_TILE::FLAG_NO_SHOOT;    // added to make sure people using noshoot will have shapes
		  // generated by this tile in future block LOS, shouldn't
		  // affect people using old LOS method one way or another.
		  lt_flags |= USTRUCT_TILE::FLAG_FLOOR;
		  lt_flags |= USTRUCT_TILE::FLAG_HALF_HEIGHT; // the entire map is this way

		  if ( lt_flags & USTRUCT_TILE::FLAG_WALL )
			lt_height = 20;

		  readstatics( statics, x, y,
					   USTRUCT_TILE::FLAG_BLOCKING |
					   USTRUCT_TILE::FLAG_PLATFORM |
					   USTRUCT_TILE::FLAG_HALF_HEIGHT |
					   USTRUCT_TILE::FLAG_LIQUID |
					   USTRUCT_TILE::FLAG_HOVEROVER
					   //USTRUCT_TILE::FLAG__WALK
					   );

		  for ( unsigned i = 0; i < statics.size(); ++i )
		  {
			StaticRec srec = statics[i];

			unsigned int polflags = polflags_from_tileflags( srec.graphic, srec.flags, cfg_use_no_shoot, cfg_LOS_through_windows );

			if ( ( ~polflags & FLAG::MOVELAND ) &&
				 ( ~polflags & FLAG::MOVESEA ) &&
				 ( ~polflags & FLAG::BLOCKSIGHT ) &&
				 ( ~polflags & FLAG::BLOCKING ) &&
				 ( ~polflags & FLAG::OVERFLIGHT ) )
			{
			  // remove it.  we'll re-sort later.
			  statics.erase( statics.begin() + i );
			  --i; // do-over
			}
			if ( ( ~srec.flags & USTRUCT_TILE::FLAG_BLOCKING ) &&
				 ( ~srec.flags & USTRUCT_TILE::FLAG_PLATFORM ) &&
				 ( ~srec.flags & USTRUCT_TILE::FLAG_HALF_HEIGHT ) &&
				 ( ~srec.flags & USTRUCT_TILE::FLAG_LIQUID ) &&
				 ( ~srec.flags & USTRUCT_TILE::FLAG_HOVEROVER ) )
				 /*(~srec.flags & USTRUCT_TILE::FLAG__WALK)*/
			{
			  // remove it.  we'll re-sort later.
			  statics.erase( statics.begin() + i );
			  --i; // do-over
			}
		  }

		  bool addMap = true;

		  for ( const auto &srec : statics )
		  {
			// Look for water tiles.  If there are any, discard the map (which is usually at -15 anyway)
			if ( z + lt_height <= srec.z && ( ( srec.z - ( z + lt_height ) ) <= 10 ) && // only where the map is below or same Z as the static
				 srec.graphic >= 0x1796 && srec.graphic <= 0x17B2 ) // FIXME hardcoded
			{
			  // arr, there be water here
			  addMap = false;
			}

			// if there's a static on top of one of these "wall" landtiles, make it override.
			if ( ( lt_flags & USTRUCT_TILE::FLAG_WALL ) && // wall?
				 z <= srec.z &&
				 srec.z - z <= lt_height )
			{

			  lt_height = srec.z - z;
			}
		  }
		  // shadows above caves
		  if ( is_cave_shadow( mi ) && !statics.empty() )
		  {
			addMap = false;
		  }



		  // If the map is a NODRAW tile, and there are statics, discard the map tile
		  if ( mi.landtile == 2 && !statics.empty() )
			addMap = false;

		  if ( addMap )
			statics.push_back( StaticRec( 0, static_cast<signed char>( z ), lt_flags, static_cast<char>( lt_height ) ) );

		  sort( statics.begin(), statics.end(), StaticsByZ() );
		  reverse( statics.begin(), statics.end() );

          std::vector<MapShape> shapes;

		  // try to consolidate like shapes, and discard ones we don't care about.
		  while ( !statics.empty() )
		  {
			StaticRec srec = statics.back();
			statics.pop_back();

			unsigned int polflags = polflags_from_tileflags( srec.graphic, srec.flags, cfg_use_no_shoot, cfg_LOS_through_windows );
			if ( ( ~polflags & FLAG::MOVELAND ) &&
				 ( ~polflags & FLAG::MOVESEA ) &&
				 ( ~polflags & FLAG::BLOCKSIGHT ) &&
				 ( ~polflags & FLAG::BLOCKING ) &&
				 ( ~polflags & FLAG::OVERFLIGHT ) )
			{
			  passert_always( 0 );
			  continue;
			}
			if ( ( ~srec.flags & USTRUCT_TILE::FLAG_BLOCKING ) &&
				 ( ~srec.flags & USTRUCT_TILE::FLAG_PLATFORM ) &&
				 ( ~srec.flags & USTRUCT_TILE::FLAG_HALF_HEIGHT ) &&
				 ( ~srec.flags & USTRUCT_TILE::FLAG_LIQUID ) &&
				 ( ~srec.flags & USTRUCT_TILE::FLAG_HOVEROVER ) )
				 /*(~srec.flags & USTRUCT_TILE::FLAG__WALK)*/
			{
			  passert_always( 0 );
			  continue;
			}

			if ( shapes.empty() )
			{
			  // this, whatever it is, is the map base.
			  //TODO: look for water statics and use THOSE as the map.
			  MapShape shape;
			  shape.z = srec.z;      //these will be converted below to
			  shape.height = 0;      //make the map "solid"
			  shape.flags = static_cast<unsigned char>( polflags );
			  // no matter what, the lowest level is gradual
			  shape.flags |= FLAG::GRADUAL;
			  shapes.push_back( shape );

			  //for wall flag - map tile always height 0, at bottom. if map tile has height, add it as a static
			  if ( srec.height != 0 )
			  {
				MapShape _shape;
				_shape.z = srec.z;
				_shape.height = srec.height;
				_shape.flags = polflags;
				shapes.push_back( _shape );

			  }
			  continue;
			}

			MapShape& prev = shapes.back();
			// we're adding it.
			MapShape shape;
			shape.z = srec.z;
			shape.height = srec.height;
			shape.flags = polflags;

			//always add the map shape seperately
			if ( shapes.size() == 1 )
			{
			  shapes.push_back( shape );
			  continue;
			}

			if ( shape.z < prev.z + prev.height )
			{
			  // things can't exist in the same place.
			  // shrink the bottom part of this shape.
			  // if that would give it negative height, then skip it.
			  short height_remove = prev.z + prev.height - shape.z;
			  if ( height_remove <= shape.height )
			  {
				shape.z += height_remove;
				shape.height -= height_remove;
			  }
			  else
			  { // example: 5530, 14
				continue;
			  }
			}

			// sometimes water has "sand" a couple z-coords above it.
			// We'll try to detect this (really, anything that is up to 4 dist from water)
			// and extend the thing above downward.
			if ( ( prev.flags & FLAG::MOVESEA ) &&
				 ( shape.z > prev.z + prev.height ) &&
				 ( shape.z <= prev.z + prev.height + 4 ) )
			{
			  short height_add = shape.z - prev.z - prev.height;
			  shape.z -= height_add;
			  shape.height += height_add;
			}
			if ( ( prev.flags & FLAG::MOVESEA ) &&
				 ( prev.z + prev.height == -5 ) &&
				 ( shape.flags & FLAG::MOVESEA ) &&
				 ( shape.z == 25 ) )
			{
			  // oddly, there are some water tiles at z=25 in some places...I don't get it
			  continue;
			}

			//string prevflags_s = flagstr(prev.flags);
			//const char* prevflags = prevflags_s.c_str();
			//string shapeflags_s = flagstr(shape.flags);
			//const char* shapeflags = shapeflags_s.c_str();

			if ( shape.z > prev.z + prev.height )
			{
			  //
			  // elevated above what's below, must include separately
			  //

			  shapes.push_back( shape );
			  continue;
			}

			passert_always( shape.z == prev.z + prev.height );

			if ( shape.z == prev.z + prev.height )
			{
			  //
			  // sitting right on top of the previous solid
			  //

			  // standable atop non-standable: standable
			  // nonstandable atop standable: nonstandable
			  // etc
			  bool can_combine = flags_match( prev.flags, shape.flags, FLAG::BLOCKSIGHT | FLAG::BLOCKING );
			  if ( prev.flags & FLAG::MOVELAND &&
				   ~shape.flags & FLAG::BLOCKING &&
				   ~shape.flags & FLAG::MOVELAND )
			  {
				can_combine = false;
			  }

			  if ( can_combine )
			  {
				prev.flags = shape.flags;
				prev.height += shape.height;
			  }
			  else // if one blocks LOS, but not the other, they can't be combined this way.
			  {
				shapes.push_back( shape );
				continue;
			  }
			}
		  }

		  // the first StaticShape is the map base.
		  MapShape base = shapes[0];
		  shapes.erase( shapes.begin() );
		  MAPCELL cell;
		  passert_always( base.height == 0 );
		  cell.z = static_cast<signed char>( base.z ); //assume now map has height=1. a static was already added if it was >0
		  cell.flags = static_cast<u8>( base.flags );
		  if ( !shapes.empty() )
			cell.flags |= FLAG::MORE_SOLIDS;

		  mapwriter.SetMapCell( x, y, cell );

		  if ( !shapes.empty() )
		  {
			++with_more_solids;
			total_statics += static_cast<unsigned int>( shapes.size() );
			if ( idx2_offset == 0 )
			  idx2_offset = mapwriter.NextSolidx2Offset();

			unsigned int addindex = mapwriter.NextSolidIndex() - idx2_elem.baseindex;
			if ( addindex > std::numeric_limits<unsigned short>::max() )
                throw std::runtime_error("addoffset overflow");
			idx2_elem.addindex[x_add][y_add] = static_cast<unsigned short>( addindex );
			int count = static_cast<int>( shapes.size() );
			for ( int j = 0; j < count; ++j )
			{
			  MapShape shape = shapes[j];
			  char _z, height, flags;
			  _z = static_cast<char>( shapes[j].z );
			  height = static_cast<char>( shape.height );
			  flags = static_cast<u8>( shape.flags );
			  if ( !height )//make 0 height solid
			  {
				--_z;
				++height;
			  }

			  if ( j != count - 1 )
				flags |= FLAG::MORE_SOLIDS;
			  SOLIDS_ELEM solid;
			  solid.z = _z;
			  solid.height = height;
			  solid.flags = flags;
			  mapwriter.AppendSolid( solid );
			}
		  }
		}
	  }
	  if ( idx2_offset )
	  {
		++nonempty;
		mapwriter.AppendSolidx2Elem( idx2_elem );
	  }
	  else
	  {
		++empty;
	  }
	  mapwriter.SetSolidx2Offset( x_base, y_base, idx2_offset );
	}