Esempio n. 1
0
void PacketFileWriter::WritePacket(uint16 eq_op, uint32 packlen, const unsigned char *packet, bool to_server, const struct timeval &tv) {
	if(out == NULL)
		return;

	_WriteBlock(eq_op, packet, packlen, to_server, tv);

/*
	Could log only the packets we care about, but this is most of the stream,
	so just log them all...

	switch(eq_op) {
	case OP_NewZone:
	case OP_ZoneSpawns:
	case OP_NewSpawn:
	case OP_MobUpdate:
	case OP_ClientUpdate:
	case OP_Death:
	case OP_DeleteSpawn:
	case OP_CastSpell:
	case OP_ShopRequest:
	case OP_ShopEndConfirm:
	case OP_ItemPacket:
		_WriteBlock(eq_op, packet, packlen);
	default:
		return;
	}
	*/
}
Esempio n. 2
0
void isoFile::WriteBlock(const u8* src, uint lsn)
{
	if (m_flags == ISOFLAGS_BLOCKDUMP_V2)
		_WriteBlockD(src, lsn);
	else
		_WriteBlock(src, lsn);
}
Esempio n. 3
0
	void Database::_WriteBlock(Item towrite, uint64_t blockpos) {
		backing.seekg(blockpos);
		backing.seekp(blockpos);
		uint64_t blkhdrs[4];
		if (backing.eof()) {
			blkhdrs[0] = 0;
			blkhdrs[1] = towrite.itemsize;
			blkhdrs[2] = towrite.itemsize;
			blkhdrs[3] = towrite.itemsize + (sizeof(uint64_t)*4) + 1;
			backing.write(0, 1);
			backing.write((char*)&blkhdrs, sizeof(uint64_t)*4);
			backing.write(towrite.item, towrite.itemsize);
			backing.flush();
		} else {
			_GetLock(blockpos, true);
			backing.read((char*)blkhdrs, sizeof(uint64_t)*4);
			if (towrite.itemsize + 1 + (sizeof(uint64_t)*4) <= blkhdrs[3]) {
				//Block large enough or non-existent block
				backing.write(0, 1);
				blkhdrs[0] = 0;
				blkhdrs[1] = towrite.itemsize;
				blkhdrs[2] = towrite.itemsize;
				//Keep blkhdrs[3]
				backing.write((char*)&blkhdrs, sizeof(uint64_t)*4);
				backing.write(towrite.item, towrite.itemsize);
				backing.flush();
				_ReleaseLock(blockpos, true);
			} else {
				//Have to continue to a new block, allocate or reuse
				std::streampos currentpos = backing.tellp();
				backing.seekp(0, std::ios::end);
				std::streampos endpos = backing.tellp();
				backing.seekp(currentpos, std::ios::beg);
				blkhdrs[0] = (uint64_t) endpos;

				//Keep blkhdrs[1]
				blkhdrs[2] = towrite.itemsize;
				//Keep blkhdrs[3]

				uint64_t blockcancontain = blkhdrs[3] - ((sizeof(uint64_t)*4) + 1);
				backing.write(0, 1);
				backing.write((char*)&blkhdrs, sizeof(uint64_t)*4);
				backing.write(towrite.item, blockcancontain);
				backing.flush();
				_ReleaseLock(blockpos, true);

				//Continue to next block!
				Item process;
				process.itemsize = towrite.itemsize-blockcancontain;
				process.item = towrite.item+blockcancontain;
				_WriteBlock(process, blockpos);
			}
		}
	}
Esempio n. 4
0
	uint64_t Database::AddItem(const Item item) {
		Index toadd;
		Item topmostblock = _ReadBlock(indexstore.HighestID, 0);
		uint64_t blockpos = indexstore.Indexes[indexstore.HighestID].blockoffset+topmostblock.itemsize;
		_WriteBlock(item, blockpos);

		toadd.blockoffset = blockpos;
		toadd.id = indexstore.HighestID+1;
		toadd.name = (char*)malloc(strlen(item.name));
		strcpy(toadd.name, item.name);

		indexstore.Indexes.insert(indexstore.Indexes.end(), toadd);
		indexstore.HighestID++;
		return toadd.id;
	}
Esempio n. 5
0
// _pageBlock aligns buffer to page boundaries for writing.
// and to TWI buffer size
// returns 0 = OK otherwise error
int I2C_eeprom::_pageBlock(const uint16_t memoryAddress, const uint8_t* buffer, const uint16_t length, const bool incrBuffer)
{
    uint16_t addr = memoryAddress;
    uint16_t len = length;
    int rv = 0;
    while (len > 0)		// was length
    {
        uint8_t bytesUntilPageBoundary = this->_pageSize - addr % this->_pageSize;
        uint8_t cnt = min(len, bytesUntilPageBoundary);
        cnt = min(cnt, I2C_TWIBUFFERSIZE);
		
        int rv = _WriteBlock(addr, buffer, cnt);
        if (rv != 0) return rv;

        addr += cnt;
        if (incrBuffer) buffer += cnt;
        len -= cnt;
    }
    return rv;
}
Esempio n. 6
0
int I2C_eeprom::writeByte(const uint16_t memoryAddress, const uint8_t data)
{
    int rv = _WriteBlock(memoryAddress, &data, 1);
    return rv;
}