示例#1
0
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();
}
示例#2
0
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());
}
示例#3
0
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());
}
示例#4
0
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());
}