void CFileDataIO::WriteTag(const CTag& tag) { try { WriteUInt8(tag.GetType()); if (!tag.GetName().IsEmpty()) { WriteString(tag.GetName(),utf8strNone); } else { WriteUInt16(1); WriteUInt8(tag.GetNameID()); } switch (tag.GetType()) { case TAGTYPE_HASH16: // Do NOT use this to transfer any tags for at least half a year!! WriteHash(CMD4Hash(tag.GetHash())); break; case TAGTYPE_STRING: WriteString(tag.GetStr(), utf8strRaw); // Always UTF8 break; case TAGTYPE_UINT64: WriteUInt64(tag.GetInt()); break; case TAGTYPE_UINT32: WriteUInt32(tag.GetInt()); break; case TAGTYPE_FLOAT32: WriteFloat(tag.GetFloat()); break; case TAGTYPE_BSOB: WriteBsob(tag.GetBsob(), tag.GetBsobSize()); break; case TAGTYPE_UINT16: WriteUInt16(tag.GetInt()); break; case TAGTYPE_UINT8: WriteUInt8(tag.GetInt()); break; case TAGTYPE_BLOB: // NOTE: This will break backward compatibility with met files for eMule versions prior to 0.44a // and any aMule prior to SVN 26/02/2005 WriteUInt32(tag.GetBlobSize()); Write(tag.GetBlob(), tag.GetBlobSize()); break; default: //TODO: Support more tag types // With the if above, this should NEVER happen. AddLogLineNS(CFormat(wxT("CFileDataIO::WriteTag: Unknown tag: type=0x%02X")) % tag.GetType()); wxFAIL; break; } } catch (...) { AddLogLineNS(wxT("Exception in CDataIO:WriteTag")); throw; } }
void LFGuildManager::SendGuildStatus(uint32 FromZoneID, uint32 FromInstanceID, char *From, char *GuildName) { std::list<GuildLookingForPlayers>::iterator it; for(it = Guilds.begin(); it != Guilds.end(); ++it) { if(!strcasecmp((*it).Name.c_str(), GuildName)) { auto pack = new ServerPacket(ServerOP_QueryServGeneric, strlen(From) + (*it).Comments.length() + 42); pack->WriteUInt32(FromZoneID); pack->WriteUInt32(FromInstanceID); pack->WriteString(From); pack->WriteUInt32(QSG_LFGuild); pack->WriteUInt32(QSG_LFGuild_RequestGuildInfo); pack->WriteString((*it).Comments.c_str()); pack->WriteUInt32((*it).FromLevel); pack->WriteUInt32((*it).ToLevel); pack->WriteUInt32((*it).Classes); pack->WriteUInt32((*it).AACount); pack->WriteUInt32((*it).TimeZone); pack->WriteUInt32((*it).TimePosted); worldserver->SendPacket(pack); safe_delete(pack); break; } } }
void Serializer::WriteRepeatedMessageField(google::protobuf::Message const& value, google::protobuf::FieldDescriptor const* field) { google::protobuf::Reflection const* reflection = value.GetReflection(); for (int32 i = 0; i < reflection->FieldSize(value, field); ++i) { switch (field->cpp_type()) { case google::protobuf::FieldDescriptor::CPPTYPE_INT32: WriteInt32(reflection->GetRepeatedInt32(value, field, i)); break; case google::protobuf::FieldDescriptor::CPPTYPE_INT64: WriteInt64(reflection->GetRepeatedInt64(value, field, i)); break; case google::protobuf::FieldDescriptor::CPPTYPE_UINT32: WriteUInt32(reflection->GetRepeatedUInt32(value, field, i)); break; case google::protobuf::FieldDescriptor::CPPTYPE_UINT64: WriteUInt64(reflection->GetRepeatedUInt64(value, field, i)); break; case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE: WriteDouble(reflection->GetRepeatedDouble(value, field, i)); break; case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT: WriteFloat(reflection->GetRepeatedFloat(value, field, i)); break; case google::protobuf::FieldDescriptor::CPPTYPE_BOOL: WriteBool(reflection->GetRepeatedBool(value, field, i)); break; case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: WriteEnum(reflection->GetRepeatedEnum(value, field, i)); break; case google::protobuf::FieldDescriptor::CPPTYPE_STRING: { std::string strValue = reflection->GetRepeatedString(value, field, i); if (field->type() == google::protobuf::FieldDescriptor::TYPE_STRING) WriteString(strValue); else { _writer.StartArray(); for (std::size_t j = 0; j < strValue.length(); ++j) WriteUInt32(uint32(strValue[j])); _writer.EndArray(); } break; } case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: WriteMessage(reflection->GetRepeatedMessage(value, field, i)); break; default: break; } } }
void String::WriteCache(Buffer *buf, String *s) { WriteOpenTag(buf, TAG_CacheString); uint32_t id = 0; if (buf->TestSeen((uint64_t)s, &id)) { WriteUInt32(buf, id); } else { Write(buf, s); WriteUInt32(buf, id); } WriteCloseTag(buf, TAG_CacheString); }
/* * Saver for AAK files */ int SaveAAK(string filename, SkinnedModel* model, bool overwrite) { ofstream file(filename.c_str(), ios::out | ios::binary); if(!file) return 1; // write number of materials unsigned int materials_count = model->material_model_pairs.size(); WriteUInt32(materials_count, file); // write each material for(unsigned int i = 0; i < materials_count; ++i) { MaterialModelPair& mmp = model->material_model_pairs[i]; VertexBuffer* vbo = mmp.vbo; // name of material unsigned int mat_name_len = model->material_names[i].length(); WriteByte((unsigned char)mat_name_len, file); for(unsigned int j = 0; j < mat_name_len; ++j) WriteByte((unsigned char)model->material_names[i][j], file); // vbo data unsigned int vinfo_count = vbo->GetNumVerts(); WriteUInt32(vinfo_count, file); for(unsigned int j = 0; j < vinfo_count; ++j) { SkinVInfo& vinfo = GetSkinVInfo(vbo, j); WriteSingle(vinfo.x.x, file); WriteSingle(vinfo.x.y, file); WriteSingle(vinfo.x.z, file); WriteSingle(vinfo.uvw.x, file); WriteSingle(vinfo.uvw.y, file); WriteSingle(vinfo.n.x, file); WriteSingle(vinfo.n.y, file); WriteSingle(vinfo.n.z, file); for(int k = 0; k < 4; ++k) { WriteByte(vinfo.indices[k], file); WriteByte(vinfo.weights[k], file); } } } Skeleton::WriteSkeleton(file, model->skeleton); file.close(); return 0; }
void String::WriteCache(Buffer *buf, String *s) { WriteOpenTag(buf, TAG_CacheString); uint32_t id = 0; s->IncRef(buf); if (buf->TestSeen((void*)s, BufferCleanupString, &id)) { WriteUInt32(buf, id); } else { Write(buf, s); WriteUInt32(buf, id); } WriteCloseTag(buf, TAG_CacheString); }
void COutArchive::WriteLocalHeader(const CLocalItem &item) { SeekTo(m_BasePosition); bool isZip64 = m_IsZip64 || item.PackSize >= 0xFFFFFFFF || item.UnPackSize >= 0xFFFFFFFF; WriteUInt32(NSignature::kLocalFileHeader); { Byte ver = item.ExtractVersion.Version; if (isZip64 && ver < NFileHeader::NCompressionMethod::kExtractVersion_Zip64) ver = NFileHeader::NCompressionMethod::kExtractVersion_Zip64; WriteByte(ver); } WriteByte(item.ExtractVersion.HostOS); WriteUInt16(item.Flags); WriteUInt16(item.CompressionMethod); WriteUInt32(item.Time); WriteUInt32(item.FileCRC); WriteUInt32(isZip64 ? 0xFFFFFFFF: (UInt32)item.PackSize); WriteUInt32(isZip64 ? 0xFFFFFFFF: (UInt32)item.UnPackSize); WriteUInt16((UInt16)item.Name.Length()); { UInt16 localExtraSize = (UInt16)((isZip64 ? (4 + 16): 0) + item.LocalExtra.GetSize()); if (localExtraSize > m_ExtraSize) throw CSystemException(E_FAIL); } WriteUInt16((UInt16)m_ExtraSize); // test it; WriteBytes((const char *)item.Name, item.Name.Length()); UInt32 extraPos = 0; if (isZip64) { extraPos += 4 + 16; WriteUInt16(NFileHeader::NExtraID::kZip64); WriteUInt16(16); WriteUInt64(item.UnPackSize); WriteUInt64(item.PackSize); } WriteExtra(item.LocalExtra); extraPos += (UInt32)item.LocalExtra.GetSize(); for (; extraPos < m_ExtraSize; extraPos++) WriteByte(0); m_OutBuffer.FlushWithCheck(); MoveBasePosition(item.PackSize); SeekTo(m_BasePosition); }
/* * Saver for AAA files */ int SaveAAA(string filename, KeyframeAnimation& anim) { ofstream file(filename.c_str(), ios::out | ios::binary); if(!file) return 1; // write animation name unsigned char anim_name_len = anim.name.length(); WriteByte(anim_name_len, file); for(unsigned int i = 0; i < anim_name_len; ++i) WriteByte(anim.name[i], file); // write frames unsigned int frame_count = anim.frames.size(); WriteUInt32(frame_count, file); for(vector<Keyframe>::iterator iter =anim.frames.begin(); iter != anim.frames.end(); ++iter) { Keyframe& frame = *iter; WriteInt32(frame.next, file); WriteSingle(frame.duration, file); // write each bone of the frame unsigned int values_count = frame.values.size(); WriteUInt32(values_count, file); for(unordered_map<unsigned int, BoneInfluence>::iterator jter = frame.values.begin(); jter != frame.values.end(); ++jter) { // name of the bone string bone_name = Bone::string_table[jter->first]; unsigned char bone_name_len = bone_name.length(); WriteByte(bone_name_len, file); for(unsigned int i = 0; i < bone_name_len; ++i) WriteByte(bone_name[i], file); // bone influence BoneInfluence& inf = jter->second; WriteSingle(inf.ori.x, file); // orientation... WriteSingle(inf.ori.y, file); WriteSingle(inf.ori.z, file); WriteSingle(inf.pos.x, file); // position... WriteSingle(inf.pos.y, file); WriteSingle(inf.pos.z, file); } } return 0; }
void Location::Write(Buffer *buf, const Location *l) { WriteOpenTag(buf, TAG_Location); String::WriteCache(buf, l->FileName()); WriteUInt32(buf, l->Line()); WriteCloseTag(buf, TAG_Location); }
void BinaryWriter::WriteString(const wchar_t* src) { unsigned srcLen = 0; //handle empty string if (src == NULL || (srcLen = (unsigned)wcslen(src)) == 0 ) { WriteInt32(0); return; } unsigned maxmbslen = srcLen * 4 + 1; if (m_strCacheLen < maxmbslen) { delete [] m_strCache; m_strCacheLen = maxmbslen; m_strCache = new char[maxmbslen]; } int actualLen = ut_utf8_from_unicode(src, srcLen, m_strCache, m_strCacheLen); _ASSERT(actualLen >= 0); actualLen += 1; //add 1 for null character CheckResize(actualLen + sizeof(unsigned)); //write string length (number of bytes, not characters!!!) WriteUInt32(actualLen); //write actual string content to the output memcpy(m_data + m_pos, m_strCache, actualLen); m_pos += actualLen; }
// UInt128 values are stored a little weird way... // Four little-endian 32-bit numbers, stored in // big-endian order void CFileDataIO::WriteUInt128(const Kademlia::CUInt128& value) { for (int i = 0; i < 4; i++) { // Four 32bits chunks WriteUInt32(value.Get32BitChunk(i)); } }
void WriteUInt8Array(const std::vector<unsigned __int8>& arg, MemoryBuffer& buffer) { WriteUInt32((unsigned __int32)arg.size(), buffer); for each(const auto element in arg) { WriteUInt8(element, buffer); }
bool CLrpStClientImpl::Ping(const uint32 timeoutInMilliseconds) { if (INVALID_SOCKET == m_socket) { return false; } MemoryBuffer buffer(numeric_limits<uint16>::max(), numeric_limits<uint16>::max()); buffer.SetPosition(0); WriteUInt32(static_cast<uint32>(buffer.GetSize() - sizeof(uint32)), buffer); CTimeout timeout(timeoutInMilliseconds); if (!SendEx(m_socket, timeout, buffer.GetData(), buffer.GetSize())) { closesocket(m_socket); m_socket = INVALID_SOCKET; return false; } if (!ReceiveEx(m_socket, timeout, buffer)) { closesocket(m_socket); m_socket = INVALID_SOCKET; return false; } return true; }
void CBitWriter::WriteInt32(__int32 value, unsigned __int32 size) { if (size > 32) { throw overflow_error("CBitWriter::WriteInt32(): size"); } if (value >= 0) { WriteBool(false); WriteUInt32(static_cast<uint32>(value), size - 1); } else { WriteBool(true); WriteUInt32(static_cast<uint32>(-(1 + value)), size - 1); } }
void QueryServ::SendQuery(std::string Query) { auto pack = new ServerPacket(ServerOP_QSSendQuery, Query.length() + 5); pack->WriteUInt32(Query.length()); /* Pack Query String Size so it can be dynamically broken out at queryserv */ pack->WriteString(Query.c_str()); /* Query */ worldserver.SendPacket(pack); safe_delete(pack); }
void LFGuildManager::SendPlayerStatus(uint32 FromZoneID, uint32 FromInstanceID, char *From) { std::list<PlayerLookingForGuild>::iterator it; for(it = Players.begin(); it != Players.end(); ++it) { if(!strcasecmp((*it).Name.c_str(), From)) { auto pack = new ServerPacket(ServerOP_QueryServGeneric, strlen(From) + (*it).Comments.length() + 30); pack->WriteUInt32(FromZoneID); pack->WriteUInt32(FromInstanceID); pack->WriteString(From); pack->WriteUInt32(QSG_LFGuild); pack->WriteUInt32(QSG_LFGuild_RequestPlayerInfo); pack->WriteString((*it).Comments.c_str()); pack->WriteUInt32((*it).TimeZone); pack->WriteUInt32((*it).TimePosted); pack->WriteUInt32(1); worldserver->SendPacket(pack); safe_delete(pack); break; } } }
void BinaryStream::WriteBigString(std::string what) { if(mySetPos > myBuffer.size()) mySetPos = myBuffer.size(); WriteUInt32((uint32_t)what.size()); for(uint32_t i = 0; i < (uint32_t)what.size(); i++) { myBuffer.insert(myBuffer.begin()+mySetPos, what[i]); mySetPos++; } myBuffer.insert(myBuffer.begin()+mySetPos, 0); mySetPos++; }
void CFileDataIO::WriteStringCore(const char *s, EUtf8Str eEncode, uint8 SizeLen) { uint32 sLength = s ? strlen(s) : 0; uint32 real_length = 0; if (eEncode == utf8strOptBOM) { real_length = sLength + 3; // For BOM header. } else { real_length = sLength; } switch (SizeLen) { case 0: // Don't write size. break; case sizeof(uint16): // We must not allow too long strings to be written, // as this would allow for a buggy clients to "poison" // us, by sending ISO8859-1 strings that expand to a // greater than 16b length when converted as UTF-8. if (real_length > 0xFFFF) { wxFAIL_MSG(wxT("String is too long to be saved")); real_length = std::min<uint32>(real_length, 0xFFFF); if (eEncode == utf8strOptBOM) { sLength = real_length - 3; } else { sLength = real_length; } } WriteUInt16(real_length); break; case sizeof(uint32): WriteUInt32(real_length); break; default: MULE_VALIDATE_PARAMS(false, wxT("Invalid length for string-length field.")); } // The BOM header must be written even if the string is empty. if (eEncode == utf8strOptBOM) { Write(BOMHeader, 3); } // Only attempt to write non-NULL strings. if (sLength) { // No NULL terminator is written since we explicitly specify the length Write(s, sLength); } }
void COutArchive::WriteCentralDir(const CObjectVector<CItem> &items, const CByteBuffer *comment) { SeekTo(m_BasePosition); UInt64 cdOffset = GetCurrentPosition(); for(int i = 0; i < items.Size(); i++) WriteCentralHeader(items[i]); UInt64 cd64EndOffset = GetCurrentPosition(); UInt64 cdSize = cd64EndOffset - cdOffset; bool cdOffset64 = cdOffset >= 0xFFFFFFFF; bool cdSize64 = cdSize >= 0xFFFFFFFF; bool items64 = items.Size() >= 0xFFFF; bool isZip64 = (cdOffset64 || cdSize64 || items64); if (isZip64) { WriteUInt32(NSignature::kZip64EndOfCentralDir); WriteUInt64(kZip64EcdSize); // ThisDiskNumber = 0; WriteUInt16(45); // version WriteUInt16(45); // version WriteUInt32(0); // ThisDiskNumber = 0; WriteUInt32(0); // StartCentralDirectoryDiskNumber;; WriteUInt64((UInt64)items.Size()); WriteUInt64((UInt64)items.Size()); WriteUInt64((UInt64)cdSize); WriteUInt64((UInt64)cdOffset); WriteUInt32(NSignature::kZip64EndOfCentralDirLocator); WriteUInt32(0); // number of the disk with the start of the zip64 end of central directory WriteUInt64(cd64EndOffset); WriteUInt32(1); // total number of disks } WriteUInt32(NSignature::kEndOfCentralDir); WriteUInt16(0); // ThisDiskNumber = 0; WriteUInt16(0); // StartCentralDirectoryDiskNumber; WriteUInt16((UInt16)(items64 ? 0xFFFF: items.Size())); WriteUInt16((UInt16)(items64 ? 0xFFFF: items.Size())); WriteUInt32(cdSize64 ? 0xFFFFFFFF: (UInt32)cdSize); WriteUInt32(cdOffset64 ? 0xFFFFFFFF: (UInt32)cdOffset); UInt32 commentSize = (UInt32)(comment ? comment->GetCapacity() : 0); WriteUInt16((UInt16)commentSize); if (commentSize > 0) WriteBytes((const Byte *)*comment, commentSize); m_OutBuffer.FlushWithCheck(); }
bool Channel::WriteString(const std::string& value) { unsigned int length = value.length(); if (!WriteUInt32(length)) { return false; } if (length > 0) { return Write(value.c_str(), length); } return true; }
bool Channel::WriteString(const char* value) { unsigned int length = static_cast<int>(strlen(value)); if (!WriteUInt32(length)) { return false; } if (length > 0) { return Write(value, length); } return true; }
void EditSerializer::WritePersistentArray(DataField field, const CPtrArray& a) { WriteBegin(field, 0); WriteUInt32(DataField_Length, a.GetSize()); char itemName[16]; for (int i=0; i<a.GetSize(); i++) { sprintf(itemName, "[%d]", i); const Persistent_c* const p = (const Persistent_c* const)a.GetAt(i); WritePersistent(itemName, *p); } WriteEnd(); }
void LFGuildManager::SendPlayerMatches(uint32 FromZoneID, uint32 FromInstanceID, char *From, uint32 FromLevel, uint32 ToLevel, uint32 MinAA, uint32 TimeZone, uint32 Classes) { std::list<PlayerLookingForGuild>::iterator it; std::list<PlayerLookingForGuild> Matches; uint32 PacketSize = strlen(From) + 21, NumberOfMatches = 0; for(it = Players.begin(); it != Players.end(); ++it) { uint32 bitmask = 1 << (*it).Class ; if(((*it).Level >= FromLevel) && ((*it).Level <= ToLevel) && ((*it).AACount >= MinAA) && (bitmask & Classes) && ((TimeZone == 0xFFFFFFFF) || (TimeZone == (*it).TimeZone))) { ++NumberOfMatches; Matches.push_back(*it); PacketSize += (*it).Name.length() + (*it).Comments.length() + 18; } } auto pack = new ServerPacket(ServerOP_QueryServGeneric, PacketSize); pack->WriteUInt32(FromZoneID); pack->WriteUInt32(FromInstanceID); pack->WriteString(From); pack->WriteUInt32(QSG_LFGuild); pack->WriteUInt32(QSG_LFGuild_PlayerMatches); pack->WriteUInt32(NumberOfMatches); for(it = Matches.begin(); it != Matches.end(); ++it) { pack->WriteString((*it).Name.c_str()); pack->WriteString((*it).Comments.c_str()); pack->WriteUInt32((*it).Level); pack->WriteUInt32((*it).Class); pack->WriteUInt32((*it).AACount); pack->WriteUInt32((*it).TimeZone); } worldserver->SendPacket(pack); safe_delete(pack); }
void COutArchive::WriteCentralHeader(const CItem &item) { bool isUnPack64 = item.UnPackSize >= 0xFFFFFFFF; bool isPack64 = item.PackSize >= 0xFFFFFFFF; bool isPosition64 = item.LocalHeaderPosition >= 0xFFFFFFFF; bool isZip64 = isPack64 || isUnPack64 || isPosition64; WriteUInt32(NSignature::kCentralFileHeader); WriteByte(item.MadeByVersion.Version); WriteByte(item.MadeByVersion.HostOS); WriteByte(item.ExtractVersion.Version); WriteByte(item.ExtractVersion.HostOS); WriteUInt16(item.Flags); WriteUInt16(item.CompressionMethod); WriteUInt32(item.Time); WriteUInt32(item.FileCRC); WriteUInt32(isPack64 ? 0xFFFFFFFF: (UInt32)item.PackSize); WriteUInt32(isUnPack64 ? 0xFFFFFFFF: (UInt32)item.UnPackSize); WriteUInt16((UInt16)item.Name.Length()); UInt16 zip64ExtraSize = (UInt16)((isUnPack64 ? 8: 0) + (isPack64 ? 8: 0) + (isPosition64 ? 8: 0)); UInt16 centralExtraSize = (UInt16)(isZip64 ? (4 + zip64ExtraSize) : 0); centralExtraSize = (UInt16)(centralExtraSize + item.CentralExtra.GetSize()); WriteUInt16(centralExtraSize); // test it; WriteUInt16((UInt16)item.Comment.GetCapacity()); WriteUInt16(0); // DiskNumberStart; WriteUInt16(item.InternalAttributes); WriteUInt32(item.ExternalAttributes); WriteUInt32(isPosition64 ? 0xFFFFFFFF: (UInt32)item.LocalHeaderPosition); WriteBytes((const char *)item.Name, item.Name.Length()); if (isZip64) { WriteUInt16(NFileHeader::NExtraID::kZip64); WriteUInt16(zip64ExtraSize); if(isUnPack64) WriteUInt64(item.UnPackSize); if(isPack64) WriteUInt64(item.PackSize); if(isPosition64) WriteUInt64(item.LocalHeaderPosition); } WriteExtra(item.CentralExtra); if (item.Comment.GetCapacity() > 0) WriteBytes(item.Comment, (UInt32)item.Comment.GetCapacity()); }
void LFGuildManager::TogglePlayer(uint32 FromZoneID, uint32 FromInstanceID, char *From, uint32 Class, uint32 Level, uint32 AAPoints, char *Comments, uint32 Toggle, uint32 TimeZone) { for(auto it = Players.begin(); it != Players.end(); ++it) if(!strcasecmp((*it).Name.c_str(), From)) { Players.erase(it); break; } std::string query = StringFormat("DELETE FROM `lfguild` WHERE `type` = 0 AND `name` = '%s'", From); auto results = database.QueryDatabase(query); uint32 Now = time(nullptr); if(Toggle == 1) { PlayerLookingForGuild p(From, Comments, Level, Class, AAPoints, TimeZone, Now); Players.push_back(p); query = StringFormat("INSERT INTO `lfguild` " "(`type`, `name`, `comment`, `fromlevel`, `tolevel`, " "`classes`, `aacount`, `timezone`, `timeposted`) " "VALUES (0, '%s', '%s', %u, 0, %u, %u, %u, %u)", From, Comments, Level, Class, AAPoints, TimeZone, Now); auto results = database.QueryDatabase(query); } auto pack = new ServerPacket(ServerOP_QueryServGeneric, strlen(From) + strlen(Comments) + 30); pack->WriteUInt32(FromZoneID); pack->WriteUInt32(FromInstanceID); pack->WriteString(From); pack->WriteUInt32(QSG_LFGuild); pack->WriteUInt32(QSG_LFGuild_RequestPlayerInfo); pack->WriteString(Comments); pack->WriteUInt32(TimeZone); pack->WriteUInt32(Now); pack->WriteUInt32(Toggle); worldserver->SendPacket(pack); safe_delete(pack); }
void LFGuildManager::ToggleGuild(uint32 FromZoneID, uint32 FromInstanceID, char *From, char* GuildName, char *Comments, uint32 FromLevel, uint32 ToLevel, uint32 Classes, uint32 AACount, uint32 Toggle, uint32 TimeZone) { for(auto it = Guilds.begin(); it != Guilds.end(); ++it) if(!strcasecmp((*it).Name.c_str(), GuildName)) { Guilds.erase(it); break; } std::string query = StringFormat("DELETE FROM `lfguild` WHERE `type` = 1 AND `name` = '%s'", GuildName); auto results = database.QueryDatabase(query); uint32 Now = time(nullptr); if(Toggle == 1) { GuildLookingForPlayers g(GuildName, Comments, FromLevel, ToLevel, Classes, AACount, TimeZone, Now); Guilds.push_back(g); query = StringFormat("INSERT INTO `lfguild` " "(`type`, `name`, `comment`, `fromlevel`, `tolevel`, " "`classes`, `aacount`, `timezone`, `timeposted`) " "VALUES (1, '%s', '%s', %u, %u, %u, %u, %u, %u)", GuildName, Comments, FromLevel, ToLevel, Classes, AACount, TimeZone, Now); auto results = database.QueryDatabase(query); } auto pack = new ServerPacket(ServerOP_LFGuildUpdate, strlen(GuildName) + strlen(Comments) + 30); pack->WriteString(GuildName); pack->WriteString(Comments); pack->WriteUInt32(FromLevel); pack->WriteUInt32(ToLevel); pack->WriteUInt32(Classes); pack->WriteUInt32(AACount); pack->WriteUInt32(TimeZone); pack->WriteUInt32(Now); pack->WriteUInt32(Toggle); worldserver->SendPacket(pack); safe_delete(pack); }
bool Channel::WriteBool(bool value) { return WriteUInt32(value ? 1 : 0); }
void ezJSONWriter::WriteVariant(const ezVariant& value) { switch (value.GetType()) { case ezVariant::Type::Invalid: //EZ_REPORT_FAILURE("Variant of Type 'Invalid' cannot be written as JSON."); WriteNULL(); return; case ezVariant::Type::Bool: WriteBool(value.Get<bool>()); return; case ezVariant::Type::Int8: WriteInt32(value.Get<ezInt8>()); return; case ezVariant::Type::UInt8: WriteUInt32(value.Get<ezUInt8>()); return; case ezVariant::Type::Int16: WriteInt32(value.Get<ezInt16>()); return; case ezVariant::Type::UInt16: WriteUInt32(value.Get<ezUInt16>()); return; case ezVariant::Type::Int32: WriteInt32(value.Get<ezInt32>()); return; case ezVariant::Type::UInt32: WriteUInt32(value.Get<ezUInt32>()); return; case ezVariant::Type::Int64: WriteInt64(value.Get<ezInt64>()); return; case ezVariant::Type::UInt64: WriteUInt64(value.Get<ezUInt64>()); return; case ezVariant::Type::Float: WriteFloat(value.Get<float>()); return; case ezVariant::Type::Double: WriteDouble(value.Get<double>()); return; case ezVariant::Type::Color: WriteColor(value.Get<ezColor>()); return; case ezVariant::Type::Vector2: WriteVec2(value.Get<ezVec2>()); return; case ezVariant::Type::Vector3: WriteVec3(value.Get<ezVec3>()); return; case ezVariant::Type::Vector4: WriteVec4(value.Get<ezVec4>()); return; case ezVariant::Type::Quaternion: WriteQuat(value.Get<ezQuat>()); return; case ezVariant::Type::Matrix3: WriteMat3(value.Get<ezMat3>()); return; case ezVariant::Type::Matrix4: WriteMat4(value.Get<ezMat4>()); return; case ezVariant::Type::String: WriteString(value.Get<ezString>().GetData()); return; case ezVariant::Type::Time: WriteTime(value.Get<ezTime>()); return; case ezVariant::Type::Uuid: WriteUuid(value.Get<ezUuid>()); return; default: break; } EZ_REPORT_FAILURE("The Variant Type %i is not supported by ezJSONWriter::WriteVariant.", value.GetType()); }
void ezJSONWriter::AddVariableUInt32(const char* szName, ezUInt32 value) { BeginVariable(szName); WriteUInt32(value); EndVariable(); }
void NetMessage::WriteLenghtAndString(const std::string &value) { WriteUInt32(value.length()); WriteString(value); }