basic protocol 953 support, logging in real tibia!

This commit is contained in:
Eduardo Bart
2012-05-12 01:52:16 -03:00
parent abbd15b1c2
commit fa9c942471
18 changed files with 163 additions and 68 deletions

View File

@@ -223,6 +223,32 @@ uint64 FileStream::getU64()
return v;
}
std::string FileStream::getString()
{
std::string str;
int len = getU16();
if(len > 0 && len < 8192) {
char buffer[8192];
if(m_fileHandle) {
if(PHYSFS_read(m_fileHandle, buffer, 1, len) == 0)
logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError());
else
str = std::string(buffer, len);
} else {
if(m_cacheReadPos+len > m_cacheBuffer.size()) {
logTraceError("operation failed on '", m_name, "': reached file eof");
return 0;
}
str = std::string((char*)&m_cacheBuffer[m_cacheReadPos], len);
m_cacheReadPos += len;
}
} else {
logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError());
}
return str;
}
void FileStream::addU8(uint8 v)
{
if(PHYSFS_write(m_fileHandle, &v, 1, 1) != 1)

View File

@@ -53,6 +53,7 @@ public:
uint16 getU16();
uint32 getU32();
uint64 getU64();
std::string getString();
void addU8(uint8 v);
void addU16(uint8 v);
void addU32(uint8 v);

View File

@@ -124,9 +124,17 @@ void Protocol::internalRecvData(uint8* buffer, uint16 size)
return;
}
if(m_xteaEncryptionEnabled && !xteaDecrypt(m_inputMessage)) {
logTraceError("failed to decrypt message");
return;
if(m_xteaEncryptionEnabled) {
if(!xteaDecrypt(m_inputMessage)) {
logTraceError("failed to decrypt message");
return;
}
} else {
int size = m_inputMessage.getU16();
if(size != m_inputMessage.getUnreadSize()) {
logTraceError("invalid message size");
return;
}
}
onRecv(m_inputMessage);