void cb_broadcast(AuthServer_Private& client) { DS::FifoMessage bcast = client.m_broadcast.getMessage(); DS::BufferStream* msg = reinterpret_cast<DS::BufferStream*>(bcast.m_payload); START_REPLY(bcast.m_messageType); client.m_buffer.writeBytes(msg->buffer(), msg->size()); msg->unref(); SEND_REPLY(); }
DS::Blob gen_default_sdl(const DS::String& filename) { SDL::StateDescriptor* desc = SDL::DescriptorDb::FindDescriptor(filename, -1); if (!desc) { fprintf(stderr, "[Vault] Warning: Could not find SDL descriptor for %s\n", filename.c_str()); return DS::Blob(); } SDL::State state(desc); DS::BufferStream stream; state.write(&stream); return DS::Blob(stream.buffer(), stream.size()); }
DS::Blob SDL::State::toBlob() const { if (!m_data) return DS::Blob(); DS::BufferStream buffer; // Stream header (see ::Create) uint16_t hflags = 0x8000; if (!m_data->m_object.isNull()) hflags |= e_HFlagVolatile; buffer.write<uint16_t>(hflags); buffer.writeSafeString(m_data->m_desc->m_name); buffer.write<int16_t>(m_data->m_desc->m_version); if (!m_data->m_object.isNull()) m_data->m_object.write(&buffer); write(&buffer); return DS::Blob(buffer.buffer(), buffer.size()); }
void MOUL::CreatableList::read(DS::Stream* stream) { clear(); m_flags = stream->read<uint8_t>(); uint32_t bufSz = stream->read<uint32_t>(); uint8_t* buf = new uint8_t[bufSz]; if (m_flags & e_Compressed) { uint32_t zBufSz = stream->read<uint32_t>(); uint8_t* zBuf = new uint8_t[zBufSz]; stream->readBytes(zBuf, zBufSz); uLongf zLen; int result = uncompress(buf, &zLen, zBuf, zBufSz); delete[] zBuf; if (result != Z_OK) { delete[] buf; DS_PASSERT(0); } DS_PASSERT(zLen == bufSz); m_flags &= ~e_Compressed; } else { stream->readBytes(buf, bufSz); } DS::BufferStream ram; ram.steal(buf, bufSz); uint16_t numItems = ram.read<uint16_t>(); for (uint16_t i = 0; i < numItems; i++) { uint16_t id = ram.read<uint16_t>(); uint16_t type = ram.read<uint16_t>(); Creatable* cre = Factory::Create(type); DS_PASSERT(cre); cre->read(&ram); m_items[id] = cre; } }
void MOUL::CreatableList::write(DS::Stream* stream) const { DS::BufferStream ram; uint16_t numItems = m_items.size(); ram.write<uint16_t>(numItems); for (auto& it : m_items) { uint16_t id = it.first; Creatable* item = it.second; uint16_t type = item->type(); ram.write<uint16_t>(id); ram.write<uint16_t>(type); item->write(&ram); } uint32_t bufSz = ram.tell(); ram.seek(0, SEEK_SET); uint8_t* buf = new uint8_t[bufSz]; ram.readBytes(buf, bufSz); uLongf zBufSz; uint8_t flags = m_flags & ~e_Compressed; if (flags & e_WantCompression && bufSz > COMPRESSION_THRESHOLD) { uint8_t* zBuf = new uint8_t[bufSz]; int result = compress(zBuf, &zBufSz, buf, bufSz); if (result != Z_OK) { delete[] buf; delete[] zBuf; DS_PASSERT(0); } memcpy(buf, zBuf, zBufSz); delete[] zBuf; flags |= e_Compressed; } ram.truncate(); ram.write<uint8_t>(flags); ram.write<uint32_t>(bufSz); if (flags & e_Compressed) { bufSz = zBufSz; ram.write<uint32_t>(bufSz); } ram.writeBytes(buf, bufSz); delete[] buf; stream->writeBytes(ram.buffer(), ram.tell()); }