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"); }
void GuildMgr::writeGuildList(const uint8_t* data, 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(QIODevice::WriteOnly)) seqWarn("GuildMgr: Could not open %s for writing, unable to replace with server data!", guildsFileName.latin1()); QDataStream guildDataStream(&guildsfile); NetStream netStream(data, len); QString guildName; uint32_t size = 0; // to keep track of how much we're reading from the packet uint32_t guildId = 0; /* 0x48 in the packet starts the serialized list. See guildListStruct * and worldGuildListStruct in everquest.h */ // Skip the first guild in the list netStream.skipBytes(0x44); size += 0x44; while (!netStream.end()) { guildId = netStream.readUInt32NC(); guildName = netStream.readText(); size += 4; if (guildName.length()) { m_guildList[guildId] = guildName; // add guild name length, plus one for the null character size += guildName.length() + 1; } // theres an extra zero at the end of the packet if (size + 1 == len) break; } std::map<uint32_t, QString>::const_iterator it; for (it = m_guildList.begin(); it != m_guildList.end(); it++) { char szGuildName[64] = {0}; strcpy(szGuildName, it->second.latin1()); // seqDebug("GuildMgr::writeGuildList - add guild '%s' (%d)", szGuildName, it->first); guildDataStream.writeRawBytes(szGuildName, sizeof(szGuildName)); } guildsfile.close(); seqInfo("GuildMgr: New guildsfile written"); }