Exemple #1
0
////////////////////////////////////////////////////
// Locks onto a specific client port (for session tracking)
void EQPacket::lockOnClient(in_port_t serverPort, in_port_t clientPort)
{
  m_serverPort = serverPort;
  m_clientPort = clientPort;

  if (!m_playbackPackets)
  {
    if (m_mac.length() == 17)
    {
      m_packetCapture->setFilter(m_device, 
				 m_mac,
				 m_realtime, 
				 MAC_ADDRESS_TYPE, 0, 
				 m_clientPort);
      emit filterChanged();
      seqInfo("EQPacket: SEQStart detected, pcap filter: EQ Client %s, Client port %d",
	      (const char*)m_mac, 
	      m_clientPort);
    }
    else
    {
      m_packetCapture->setFilter(m_device, 
				 m_ip,
				 m_realtime, 
				 IP_ADDRESS_TYPE, 0, 
				 m_clientPort);
      emit filterChanged();
      seqInfo("EQPacket: SEQStart detected, pcap filter: EQ Client %s, Client port %d",
	      (const char*)m_ip, 
	      m_clientPort);
    }
  }
  
  emit clientPortLatched(m_clientPort);
}
Exemple #2
0
void SpellShell::spellMessage(QString &str)
{
   QString spell = str.right(str.length() - 7); // drop 'Spell: '
   bool b = false;
   // Your xxx has worn off.
   // Your target resisted the xxx spell.
   // Your spell fizzles.
   seqInfo("*** spellMessage *** %s", spell.latin1());
   if (spell.left(25) == QString("Your target resisted the ")) {
      spell = spell.right(spell.length() - 25);
      spell = spell.left(spell.length() - 7);
      seqInfo("RESIST: '%s'", spell.latin1());
      b = true;
   } else if (spell.right(20) == QString(" spell has worn off.")) {
      spell = spell.right(spell.length() - 5);
      spell = spell.left(spell.length() - 20);
      seqInfo("WORE OFF: '%s'", spell.latin1());
      b = true;
   }

   if (b) {
      // Can't really tell which spell/target, so just delete the last one
      for(QValueList<SpellItem*>::Iterator it = m_spellList.begin();
         it != m_spellList.end(); it++) {
         if ((*it)->spellName() == spell) {
            (*it)->setDuration(0);
            break;
         }
      }
   }
}
Exemple #3
0
///////////////////////////////////////////
// Monitor for packets on the specified device
void EQPacket::monitorDevice(const QString& dev)
{
  // set the device to use
  m_device = dev;

  // make sure we aren't playing back packets
  if (m_playbackPackets != PLAYBACK_OFF)
    return;

  // stop the current packet capture
  m_packetCapture->stop();

  // setup for capture on new device
  if (!m_ip.isEmpty())
  {
    struct hostent *he;
    struct in_addr  ia;

    /* Substitute "special" IP which is interpreted 
       to set up a different filter for picking up new sessions */
    
    if (m_ip == "auto")
      inet_aton (AUTOMATIC_CLIENT_IP, &ia);
    else if (inet_aton (m_ip, &ia) == 0)
    {
      he = gethostbyname(m_ip);
      if (!he)
	seqFatal("Invalid address; %s", (const char*)m_ip);

      memcpy (&ia, he->h_addr_list[0], he->h_length);
    }
    m_client_addr = ia.s_addr;
    m_ip = inet_ntoa(ia);
    
    if (m_ip ==  AUTOMATIC_CLIENT_IP)
    {
      m_detectingClient = true;
      seqInfo("Listening for first client seen.");
    }
    else
    {
      m_detectingClient = false;
      seqInfo("Listening for client: %s",
	     (const char*)m_ip);
    }
  }
 
  resetEQPacket();

  // restart packet capture
  if (m_mac.length() == 17)
    m_packetCapture->start(m_device, 
			   m_mac, 
			   m_realtime, MAC_ADDRESS_TYPE );
  else
    m_packetCapture->start(m_device, m_ip, 
			   m_realtime, IP_ADDRESS_TYPE );
  emit filterChanged();
}
Exemple #4
0
void EQPacketTypeDB::list(void) const
{
  seqInfo("EQPacketTypeDB contains %d types (in %d buckets)",
	  m_typeSizeDict.count(), m_typeSizeDict.size());

  QAsciiDictIterator<size_t> it(m_typeSizeDict);

  while (it.current())
  {
    seqInfo("\t%s = %d", it.currentKey(), *(it.current()));
    ++it;
  }
}
Exemple #5
0
void EQPacketOPCodeDB::list(void) const
{
  m_opcodes.statistics();

  seqInfo("EQPacketOPCodeDB contains %d opcodes (in %d buckets)",
	  m_opcodes.count(), m_opcodes.size());

  EQPacketOPCode* current;
  EQPacketPayload* currentPayload;

  // iterate over all the opcodes
  QIntDictIterator<EQPacketOPCode> it(m_opcodes);
  while ((current = it.current()) != NULL)
  {
    fprintf(stderr, "\tkey=%04lx opcode=%04x",
	    it.currentKey(), current->opcode());
    if (!current->name().isNull())
      fprintf(stderr, " name='%s'", current->name().latin1());

    if (current->implicitLen())
      fprintf(stderr, " implicitlen='%d'", current->implicitLen());
    
    if (!current->updated().isNull())
      fprintf(stderr, " updated='%s'", current->updated().latin1());

    fputc('\n', stderr);

    QStringList comments = current->comments();
    
    fprintf(stderr, "\t\t%d comment(s)\n", comments.count());

    for (QStringList::Iterator cit = comments.begin(); 
	 cit != comments.end(); ++cit)
      fprintf(stderr, "\t\t\t'%s'\n", (*cit).latin1());
    
    fprintf(stderr, "\t\t%d payload(s)\n", current->count());
    
    QPtrListIterator<EQPacketPayload> pit(*current);
    while ((currentPayload = pit.current()) != 0)
    {
      seqInfo("\t\t\tdir=%d typename=%s size=%d sizechecktype=%d",
	      currentPayload->dir(), (const char*)currentPayload->typeName(),
	      currentPayload->typeSize(), currentPayload->sizeCheckType());

      ++pit;
    }

    ++it;
  }
}
Exemple #6
0
void GuildMgr::readGuildList()
{
  QFile guildsfile(guildsFileName);

  m_guildMap.clear();
  if (guildsfile.open(IO_ReadOnly))
  {
    worldGuildListStruct tmp;
     if (guildsfile.size() != sizeof(tmp.guilds))
     {
	seqWarn("GuildMgr: Guildsfile not loaded, expected size %d got %ld",
                sizeof(worldGuildListStruct), guildsfile.size()); 
	return;
     }

     struct guildListStruct gl;
     
     while (!guildsfile.atEnd())
     {
         guildsfile.readBlock(reinterpret_cast<char*>(&gl), sizeof(gl));
        // Commented out until verified that this needs to actually be 
		// removed. -- Ratt 
		// if (strlen(gl.guildName) > 0)
            m_guildMap.push_back(QString::fromUtf8(gl.guildName));
     }
     
    guildsfile.close();
    seqInfo("GuildMgr: Guildsfile loaded");
  }
  else
    seqWarn("GuildMgr: Could not load guildsfile, %s", (const char*)guildsFileName);
}
Exemple #7
0
std::vector<READ> vecStrToReadObjs(const VecStr & strs, const std::string & stubName){
	std::vector<READ> ans;
	for(const auto & strPos : iter::range(strs.size())){
		ans.emplace_back(READ(seqInfo(stubName + "." + leftPadNumStr(strPos, strs.size()), strs[strPos])));
	}
	return ans;
}
Exemple #8
0
void SpellShell::timeout()
{
  SpellItem* spell;

  QValueList<SpellItem*>::Iterator it = m_spellList.begin();
  while (it != m_spellList.end()) 
  {
    spell = *it;

    int d = spell->duration() -
      pSEQPrefs->getPrefInt("SpellTimer", "SpellList", 6);
    if (d > -6) 
    {
      spell->setDuration(d);
      emit changeSpell(spell);
      it++;
    } 
    else 
    {
      seqInfo("SpellItem '%s' finished.", (*it)->spellName().latin1());
      if (m_lastPlayerSpell == spell)
	m_lastPlayerSpell = 0;
      emit delSpell(spell);
      it = m_spellList.remove(it);
      delete spell;
    }
   }

  if (m_spellList.count() == 0)
    m_timer->stop();
}
Exemple #9
0
void ZoneMgr::restoreZoneState(void)
{
  QString fileName = showeq_params->saveRestoreBaseFilename + "Zone.dat";
  QFile keyFile(fileName);
  if (keyFile.open(IO_ReadOnly))
  {
    QDataStream d(&keyFile);

    // check the magic string
    uint32_t magicTest;
    d >> magicTest;

    if (magicTest != *magic)
    {
      seqWarn("Failure loading %s: Bad magic string!",
	      (const char*)fileName);
      return;
    }

    d >> m_longZoneName;
    d >> m_shortZoneName;

    seqInfo("Restored Zone: %s (%s)!",
	    (const char*)m_shortZoneName,
	    (const char*)m_longZoneName);
  }
Exemple #10
0
////////////////////////////////////////////////////
// Handle zone2client stream closing
void EQPacket::closeStream(uint32_t sessionId, EQStreamID streamId)
{
  // If this is the zone server session closing, reset the pcap filter to
  // a non-exclusive form
  if ((streamId == zone2client || streamId == client2zone) &&
         (m_playbackPackets == PLAYBACK_OFF || 
          m_playbackPackets == PLAYBACK_FORMAT_TCPDUMP))
  {
    m_packetCapture->setFilter(m_device, m_ip,
			       m_realtime, IP_ADDRESS_TYPE, 0, 0);
    emit filterChanged();
  }

  // Pass the close onto the streams
  m_client2WorldStream->close(sessionId, streamId, m_session_tracking);
  m_world2ClientStream->close(sessionId, streamId, m_session_tracking);
  m_client2ZoneStream->close(sessionId, streamId, m_session_tracking);
  m_zone2ClientStream->close(sessionId, streamId, m_session_tracking);

  // If we just closed the zone server session, unlatch the client port
  if (streamId == zone2client || streamId == client2zone)
  {
    m_clientPort = 0;
    m_serverPort = 0;

    emit clientPortLatched(m_clientPort);

    seqInfo("EQPacket: SessionDisconnect detected, awaiting next zone session,  pcap filter: EQ Client %s",
	  (const char*)m_ip);
  }
}
Exemple #11
0
void SpawnListWindow3::doubleClicked(const QModelIndex& index)
{
	const Item* item = m_spawnModel->item(index);
	if (item != NULL)
	{
		seqInfo("%s", (const char*)m_spawnModel->filterString(item));
	}
}
Exemple #12
0
void GuildMgr::listGuildInfo()
{
   for (unsigned int i = 0; i < m_guildMap.size(); i++) 
   {
     if (m_guildMap[i])
       seqInfo("%d\t%s", i, (const char*)m_guildMap[i]);
   }
}
Exemple #13
0
void Filters::list(void) const
{
  FilterMap::const_iterator it;

  seqInfo("Filters from file '%s':",
	 (const char*)m_file);
  // iterate over the filters
  for (it = m_filters.begin(); it != m_filters.end(); it++)
  {
    // print the header
    seqInfo("Filter Type '%s':", 
	   (const char*)m_types.name(it->first));

    // list off the actual filters
    it->second->listFilters();
  }
}
Exemple #14
0
static std::vector<readObject> createCondensedObjects(std::vector<T> reads) {
  std::vector<readObject> ans;
  readVec::allSetCondensedSeq(reads);
  for (const auto& read : reads) {
    ans.emplace_back(readObject(seqInfo(read.seqBase_.name_, read.condensedSeq,
                                        read.condensedSeqQual)));
  }
  return ans;
}
Exemple #15
0
void
Filter::listFilters(void)
{
  FilterItem *re;

#ifdef DEBUG_FILTER
//  seqDebug("Filter::listFilters");
#endif

  FilterListIterator it(m_filterItems);
  for (re = it.toFirst(); re != NULL; re = ++it)
  {
    if (re->minLevel() || re->maxLevel())
      seqInfo("\t'%s' (%d, %d)", 
	     (const char*)re->name().utf8(), re->minLevel(), re->maxLevel());
    else
      seqInfo("\t'%s'", (const char*)re->name().utf8());
  }
}
Exemple #16
0
////////////////////////////////////////////////////
// Locks onto a specific client port (for session tracking)
void EQPacket::lockOnClient(in_port_t serverPort, in_port_t clientPort)
{
  m_serverPort = serverPort;
  m_clientPort = clientPort;

  if (m_playbackPackets == PLAYBACK_OFF || 
          m_playbackPackets == PLAYBACK_FORMAT_TCPDUMP)
  {
    if (m_mac.length() == 17)
    {
      m_packetCapture->setFilter(m_device, 
				 m_mac,
				 m_realtime, 
				 MAC_ADDRESS_TYPE, 0, 
				 m_clientPort);
      emit filterChanged();
    }
    else
    {
      m_packetCapture->setFilter(m_device, 
				 m_ip,
				 m_realtime, 
				 IP_ADDRESS_TYPE, 0, 
				 m_clientPort);
      emit filterChanged();
    }
  }

  // Wanted this message even if we're running on playback...
  if (m_mac.length() == 17)
  {
    seqInfo("EQPacket: SessionRequest detected, pcap filter: EQ Client %s, Client port %d. Server port %d",
      (const char*)m_mac, m_clientPort, m_serverPort);
  }
  else
  {
    seqInfo("EQPacket: SessionRequest detected, pcap filter: EQ Client %s, Client port %d. Server port %d",
      (const char*)m_ip, m_clientPort, m_serverPort);
  }
  
  emit clientPortLatched(m_clientPort);
}
Exemple #17
0
std::vector<baseReadObject> alignToSeq(const std::vector<READ>& reads,
                                       const REF& reference, aligner& alignObj,
                                       bool local, bool usingQuality) {
  std::vector<baseReadObject> output;
  output.emplace_back(baseReadObject(reference));
  for (const auto& read : reads) {
    alignObj.alignCache(reference, read, local);
    output.emplace_back(baseReadObject(seqInfo(
        read.seqBase_.name_ + "_score:" + std::to_string(alignObj.parts_.score_),
        alignObj.alignObjectB_.seqBase_.seq_,
        alignObj.alignObjectB_.seqBase_.qual_)));
  }
  return output;
}
Exemple #18
0
void ExperienceWindow::calculateZEM(long xp_gained, int mob_level) 
{
   float gbonus=1.00;
   int penalty; 
   int myLevel = m_player->level();
   int group_ag;
   gbonus = m_group->groupBonus();
   group_ag = m_group->totalLevels();
   if (m_group->groupSize())
   {
     seqInfo("MY Level: %d GroupTot: %d BONUS   :%d", 
	     myLevel, group_ag, gbonus * 100);
   }
   // WAR and ROG are at 10 since thier EXP is not scaled to compensate
   // for thier bonus
   switch (m_player->classVal())
   {
      case 1 : penalty = 10; break; // WAR
      case 2 : penalty = 10; break; // CLR
      case 3 : penalty = 14; break; // PAL
      case 4 : penalty = 14; break; // RNG
      case 5 : penalty = 14; break; // SHD
      case 6 : penalty = 10; break; // DRU
      case 7 : penalty = 12; break; // MNK
      case 8 : penalty = 14; break; // BRD
      case 9 : penalty = 10; break; // ROG
      case 10: penalty = 10; break; // SHM
      case 11: penalty = 11; break; // NEC
      case 12: penalty = 11; break; // MAG
      case 13: penalty = 11; break; // ENC
      default: /* why are we here? */
         penalty = 10; break; 
   }
   unsigned char ZEM = (unsigned char) ((float)xp_gained*((float)((float)group_ag/(float)myLevel)*(float)((float)1.0/(float)gbonus))*((float)1/(float)(mob_level*mob_level))*((float)10/(float)penalty));
   seqInfo("xpgained: %ld group_ag: %d myLevel: %d gbonus: %d mob_level: %d penalty: %d ", xp_gained, group_ag, myLevel, gbonus, mob_level, penalty);
   seqInfo("ZEM - ZEM - ZEM ===== %d ", ZEM);
}
Exemple #19
0
///////////////////////////////////////////////////////////////
// Process a session disconnect if it is for us
void EQPacketStream::close(uint32_t sessionId, EQStreamID /*streamId*/,
  uint8_t sessionTracking)
{
  if (sessionId == m_sessionId)
  {
     // Close is for us
     reset();
     setSessionTracking(sessionTracking);

#ifdef PACKET_SESSION_DIAG
     seqInfo("EQPacket: SessionDisconnected received on stream %s (%d). Closing session %u on stream %s (%d).",
       EQStreamStr[streamId], streamId, sessionId,
       EQStreamStr[m_streamid], m_streamid);
#endif
  }
}
Exemple #20
0
////////////////////////////////////////////////////
// Handle zone2client stream closing
void EQPacket::closeStream()
{
  // reseting the pcap filter to a non-exclusive form allows us to beat 
  // the race condition between timer and processing the zoneServerInfo
  if(!m_playbackPackets) 
  {
    m_packetCapture->setFilter(m_device, m_ip,
			       m_realtime, IP_ADDRESS_TYPE, 0, 0);
    emit filterChanged();
  }

  seqInfo("EQPacket: SEQClosing detected, awaiting next zone session,  pcap filter: EQ Client %s",
	  (const char*)m_ip);
  
  // we'll be waiting for a new SEQStart for ALL streams
  // it seems we only ever see a proper closing sequence from the zone server
  // so reset all packet sequence caches 
  resetEQPacket();
}
Exemple #21
0
///////////////////////////////////////////
// Set the IP address of the client to monitor
void EQPacket::monitorIPClient(const QString& ip)
{
  m_ip = ip;
  struct in_addr  ia;
  inet_aton (m_ip, &ia);
  m_client_addr = ia.s_addr;
  emit clientChanged(m_client_addr);
  
  resetEQPacket();
  
  seqInfo("Listening for IP client: %s", (const char*)m_ip);
  if (!m_playbackPackets)
  {
    m_packetCapture->setFilter(m_device, m_ip,
			       m_realtime, 
			       IP_ADDRESS_TYPE, 0, 0);
    emit filterChanged();
  }
}
Exemple #22
0
void CategoryMgr::reloadCategories(void)
{
  clearCategories();
  m_changed = false;
  
  QString section = "CategoryMgr";
  int i = 0;
  QString prefBaseName;
  QString tempStr;
  for(i = 1; i <= tMaxNumCategories; i++)
  {
    prefBaseName.sprintf("Category%d_", i);
    
    // attempt to pull a button title from the preferences
    tempStr = prefBaseName + "Name";
    if (pSEQPrefs->isPreference(tempStr, section))
    {
      QString name = pSEQPrefs->getPrefString(tempStr, section);
      QString filter =
	pSEQPrefs->getPrefString(prefBaseName + "Filter", section);
      QColor color = pSEQPrefs->getPrefColor(prefBaseName + "Color", 
					     section, QColor("black"));
      tempStr = prefBaseName + "FilterOut";
      QString filterout;
      if (pSEQPrefs->isPreference(tempStr, section))
	filterout = pSEQPrefs->getPrefString(tempStr, section);
	
      //seqDebug("%d: Got '%s' '%s' '%s'", i, name, filter, color);
      if (!name.isEmpty() && !filter.isEmpty())
      {
        Category* newcat = new Category(name, filter, filterout, color);
	
        m_categories.append(newcat);
      }
    }
  }
  
   // signal that the categories have been loaded
   emit loadedCategories();

   seqInfo("Categories Reloaded");
}
Exemple #23
0
///////////////////////////////////////////
// Monitor the next client seen
void EQPacket::monitorNextClient()
{
  m_detectingClient = true;
  m_ip = AUTOMATIC_CLIENT_IP;
  struct in_addr  ia;
  inet_aton (m_ip, &ia);
  m_client_addr = ia.s_addr;
  emit clientChanged(m_client_addr);

  resetEQPacket();

  seqInfo("Listening for next client seen. (you must zone for this to work!)");

  if (!m_playbackPackets)
  {
    m_packetCapture->setFilter(m_device, NULL,
			       m_realtime, 
			       DEFAULT_ADDRESS_TYPE, 0, 0);
    emit filterChanged();
  }
}
Exemple #24
0
///////////////////////////////////////////
// Set the MAC address of the client to monitor
void EQPacket::monitorMACClient(const QString& mac)
{
  m_mac = mac;
  m_detectingClient = true;
  struct in_addr  ia;
  inet_aton (AUTOMATIC_CLIENT_IP, &ia);
  m_client_addr = ia.s_addr;
  emit clientChanged(m_client_addr);

  resetEQPacket();

  seqInfo("Listening for MAC client: %s", 
	 (const char*)m_mac);

  if (!m_playbackPackets)
  {
    m_packetCapture->setFilter(m_device, m_ip,
			       m_realtime, 
			       IP_ADDRESS_TYPE, 0, 0);
    emit filterChanged();
  }
}
Exemple #25
0
void GuildMgr::readGuildList()
{
	QFile guildsfile(guildsFileName);

	m_guildMap.clear();
	if (guildsfile.open(QIODevice::ReadOnly))
	{
		while (!guildsfile.atEnd())
		{
			char szGuildName[64] = {0};
			
			guildsfile.readBlock(szGuildName, sizeof(szGuildName));
			
			// seqDebug("GuildMgr::readGuildList - read guild '%s'", szGuildName);
			m_guildMap.push_back(QString::fromUtf8(szGuildName));
		}

		guildsfile.close();
		seqInfo("GuildMgr: Guildsfile loaded");
	}
	else
		seqWarn("GuildMgr: Could not load guildsfile, %s", (const char*)guildsFileName);
}
Exemple #26
0
void GuildMgr::writeGuildList(const worldGuildListStruct* gls, size_t len)
{
  QFile guildsfile(guildsFileName);

  if (guildsfile.exists()) {
     if (!guildsfile.remove()) {
       seqWarn("GuildMgr: Could not remove old %s, unable to replace with server data!"
,
                guildsFileName.latin1());
        return;
     }
  }

  if(!guildsfile.open(IO_WriteOnly))
    seqWarn("GuildMgr: Could not open %s for writing, unable to replace with server data!",
             guildsFileName.latin1());

  QDataStream guildDataStream(&guildsfile);

  guildDataStream.writeRawBytes((char *)gls->guilds, sizeof(gls->guilds));

  guildsfile.close();
  seqInfo("GuildMgr: New guildsfile written");
}
Exemple #27
0
void SpawnShell::newSpawn(const spawnStruct& s)
{
#ifdef SPAWNSHELL_DIAG
   seqDebug("SpawnShell::newSpawn(spawnStruct *(name='%s'))", s.name);
#endif
   // if this is the SPAWN_SELF it's the player
   if (s.NPC == SPAWN_SELF)
     return;

   // not the player, so check if it's a recently deleted spawn
   for (int i =0; i < m_cntDeadSpawnIDs; i++)
   {
     if ((m_deadSpawnID[i] != 0) && (m_deadSpawnID[i] == s.spawnId))
     {
       // found a match, remove it from the deleted spawn list
       m_deadSpawnID[i] = 0;

       // let the user know what's going on
       seqInfo("%s(%d) has already been removed from the zone before we processed it.", 
	      s.name, s.spawnId);
       
       // and stop the attempt to add the spawn.
       return;
     }
   }

   Item* item = m_spawns.find(s.spawnId);
   if (item != NULL)
   {
     Spawn* spawn = (Spawn*)item;
     spawn->update(&s);
     updateFilterFlags(spawn);
     updateRuntimeFilterFlags(spawn);
     item->updateLastChanged();

     if (spawn->guildID() < MAX_GUILDS)
        spawn->setGuildTag(m_guildMgr->guildIdToName(spawn->guildID()));
     else
        spawn->setGuildTag("");
     if (!showeq_params->fast_machine)
        item->setDistanceToPlayer(m_player->calcDist2DInt(*item));
     else
        item->setDistanceToPlayer(m_player->calcDist(*item));

     emit changeItem(item, tSpawnChangedALL);
   }
   else
   {
     item = new Spawn(&s);
     Spawn* spawn = (Spawn*)item;
     updateFilterFlags(spawn);
     updateRuntimeFilterFlags(spawn);
     m_spawns.insert(s.spawnId, item);

     if (spawn->guildID() < MAX_GUILDS)
        spawn->setGuildTag(m_guildMgr->guildIdToName(spawn->guildID()));
     else
        spawn->setGuildTag("");
     if (!showeq_params->fast_machine)
        item->setDistanceToPlayer(m_player->calcDist2DInt(*item));
     else
        item->setDistanceToPlayer(m_player->calcDist(*item));

     emit addItem(item);

     // send notification of new spawn count
     emit numSpawns(m_spawns.count());
   }
}
Exemple #28
0
void SpawnMonitor::loadSpawnPoints()
{
  QString fileName;
  
  fileName = m_zoneName + ".sp";

  QFileInfo fileInfo = 
    m_dataLocMgr->findExistingFile("spawnpoints", fileName, false);

  if (!fileInfo.exists())
  {
    seqWarn("Can't find spawn point file %s", 
	   (const char*)fileInfo.absFilePath());
    return;
  }
  
  fileName = fileInfo.absFilePath();

  QFile spFile(fileName);
  
  if (!spFile.open(IO_ReadOnly))
  {
    seqWarn( "Can't open spawn point file %s", (const char*)fileName );
    return;
  }
  
  QTextStream input( &spFile );
  
  int16_t x, y, z;
  unsigned long diffTime;
  uint32_t count;
  QString name;

  while (!input.atEnd())
  {
    input >> x;
    input >> y;
    input >> z;
    input >> diffTime;
    input >> count;
    name = input.readLine();
    name = name.stripWhiteSpace();
    
    EQPoint	loc(x, y, z);
    SpawnPoint*	p = new SpawnPoint( 0, loc, name, diffTime, count );
    if (p)
    {
      QString key = p->key();
      
      if (!m_points.find(key))
      {
	m_points.insert(key, p);
	emit newSpawnPoint(p);
      }
      else
      {
	seqWarn("Warning: spawn point key already in use!");
	delete p;
      }
    }
  }

  seqInfo("Loaded spawn points: %s", (const char*)fileName);
  m_modified = false;
}
Exemple #29
0
void SpawnMonitor::saveSpawnPoints()
{
  // only save if modified
  if (!m_modified)
    return;

  if ( !m_zoneName.length() )
  {
    seqWarn("Zone name not set in 'SpawnMonitor::saveSpawnPoints'!" );
    return;
  }
  
  QString fileName;
  
  fileName = m_zoneName + ".sp";

  QFileInfo fileInfo = 
    m_dataLocMgr->findWriteFile("spawnpoints", fileName, false);

  fileName = fileInfo.absFilePath();

  QString newName = fileName + ".new";
  QFile spFile( newName );
  
  if (!spFile.open(IO_WriteOnly))
  {
    seqWarn("Failed to open %s for writing", (const char*)newName);
    return;
  }
  
  QTextStream output(&spFile);
  
  QAsciiDictIterator<SpawnPoint> it( m_points );
  SpawnPoint* sp;
  
  while ((sp = it.current()))
  {
    ++it;
    output	<< sp->x()
		<< " "
		<< sp->y()
		<< " "
		<< sp->z()
		<< " "
		<< (unsigned long)sp->diffTime()
		<< " "
		<< sp->count()
		<< " "
		<< sp->name()
		<< '\n';
  }
  
  spFile.close();
  
  QFileInfo fi( spFile );
  QFile old( fileName );
  QDir dir( fi.dir() );
  QString backupName = fileName + ".bak";
  
  if (old.exists())
  {
    if (dir.rename( fileName, backupName))
    {
      if (!dir.rename( newName, fileName))
	seqWarn( "Failed to rename %s to %s", 
		(const char*)newName, (const char*)fileName);
    }
  }
  else
  {
    if (!dir.rename(newName, fileName))
      seqWarn("Failed to rename %s to %s", 
	     (const char*)newName, (const char*)fileName);
  }
  m_modified = false;
  seqInfo("Saved spawn points: %s", (const char*)fileName);
}
Exemple #30
0
bool EQStr::load(const QString& fileName)
{
  // clear out any existing contents
  m_messageStrings.clear();

  // create a QFile on the file
  QFile formatFile(fileName);

  // open the file read only
  if (!formatFile.open(IO_ReadOnly))
  {
    seqWarn("EQStr: Failed to open '%s'",
	    fileName.latin1());
    return false;
  }

  // allocate a QCString large enough to hold the entire file
  QCString textData(formatFile.size() + 1);
  
  // read in the entire file
  formatFile.readBlock(textData.data(), textData.size());
  
  // construct a regex to deal with either style line termination
  QRegExp lineTerm("[\r\n]{1,2}");
  
  // split the data into lines at the line termination
  QStringList lines = QStringList::split(lineTerm, 
					 QString::fromUtf8(textData), false);
  
  // start iterating over the lines
  QStringList::Iterator it = lines.begin();
  
  // first is the magic id string
  QString magicString = (*it++);
  int spc;
  uint32_t formatId;
  QString formatString;
  uint32_t maxFormatId = 0;
  
  // next skip over the count, etc...
  it++;
  
  // now iterate over the format lines
  for (; it != lines.end(); ++it)
  {
    // find the beginning space
    spc = (*it).find(' ');
    
    // convert the beginnign of the string to a ULong
    formatId = (*it).left(spc).toULong();
    
    if (formatId > maxFormatId) 
      maxFormatId = formatId;
    
    // insert the format string into the dictionary.
    m_messageStrings.insert(formatId, new QString((*it).mid(spc+1)));    
  }

  // note that strings are loaded
  m_loaded = true;

  seqInfo("Loaded %d message strings from '%s' maxFormat=%d",
	  m_messageStrings.count(), fileName.latin1(),
	  maxFormatId);
  
  return true;
}