just fixes

* fix battle rendering
* fix rendering glitch when following creatures
* properly throw exceptions from C++ to lua and avoid exception crashs
* fixes rendering states in framebuffer
This commit is contained in:
Eduardo Bart
2012-06-06 11:10:35 -03:00
parent 7a529d23be
commit bb1fb939c4
17 changed files with 70 additions and 90 deletions

View File

@@ -37,10 +37,12 @@ void InputMessage::reset()
void InputMessage::setBuffer(const std::string& buffer)
{
memcpy(m_buffer + MAX_HEADER_SIZE, buffer.c_str(), buffer.size());
int len = buffer.size();
checkWrite(MAX_HEADER_SIZE + len);
memcpy(m_buffer + MAX_HEADER_SIZE, buffer.c_str(), len);
m_readPos = MAX_HEADER_SIZE;
m_headerPos = MAX_HEADER_SIZE;
m_messageSize = buffer.size();
m_messageSize = len;
}
uint8 InputMessage::getU8()
@@ -92,19 +94,21 @@ void InputMessage::decryptRSA(int size, const std::string& p, const std::string&
void InputMessage::fillBuffer(uint8 *buffer, uint16 size)
{
checkWrite(m_readPos + size);
memcpy(m_buffer + m_readPos, buffer, size);
m_messageSize += size;
}
void InputMessage::setHeaderSize(uint16 size)
{
assert(MAX_HEADER_SIZE - size >= 0);
m_headerPos = MAX_HEADER_SIZE - size;
m_readPos = m_headerPos;
}
bool InputMessage::readChecksum()
{
uint32_t receivedCheck = getU32();
uint32 receivedCheck = getU32();
uint32 checksum = stdext::adler32(m_buffer + m_readPos, getUnreadSize());
return receivedCheck == checksum;
}
@@ -115,10 +119,14 @@ bool InputMessage::canRead(int bytes)
return false;
return true;
}
void InputMessage::checkRead(int bytes)
{
if(!canRead(bytes))
throw NetworkException("InputMessage eof reached");
g_lua.throwError("InputMessage eof reached");
}
void InputMessage::checkWrite(int bytes)
{
if(bytes > BUFFER_MAXSIZE)
g_lua.throwError("InputMessage max buffer size reached");
}

View File

@@ -24,7 +24,6 @@
#define INPUTMESSAGE_H
#include "declarations.h"
#include "networkexception.h"
#include <framework/luascript/luaobject.h>
class InputMessage : public LuaObject
@@ -79,6 +78,7 @@ protected:
private:
bool canRead(int bytes);
void checkRead(int bytes);
void checkWrite(int bytes);
uint16 m_headerPos;
uint16 m_readPos;

View File

@@ -1,34 +0,0 @@
/*
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef NETWORKEXCEPTION_H
#define NETWORKEXCEPTION_H
#include "declarations.h"
class NetworkException : public stdext::exception
{
public:
NetworkException(const std::string& what) : stdext::exception(what) { }
};
#endif

View File

@@ -71,7 +71,7 @@ void OutputMessage::addString(const std::string& buffer)
{
int len = buffer.length();
if(len > MAX_STRING_LENGTH)
throw NetworkException("string length > MAX_STRING_LENGTH");
g_lua.throwError(stdext::format("string length > %d", MAX_STRING_LENGTH));
checkWrite(len + 2);
addU16(len);
memcpy((char*)(m_buffer + m_writePos), buffer.c_str(), len);
@@ -91,8 +91,8 @@ void OutputMessage::addPaddingBytes(int bytes, uint8 byte)
void OutputMessage::encryptRSA(int size, const std::string& key)
{
if(m_writePos - size < 0)
throw NetworkException("writePos - size < 0");
if(m_messageSize < size)
g_lua.throwError("insufficient bytes in buffer to encrypt");
RSA::encrypt((char*)m_buffer + m_writePos - size, size, key.c_str());
}
@@ -124,5 +124,5 @@ bool OutputMessage::canWrite(int bytes)
void OutputMessage::checkWrite(int bytes)
{
if(!canWrite(bytes))
throw NetworkException("OutputMessage max buffer size reached");
g_lua.throwError("OutputMessage max buffer size reached");
}

View File

@@ -24,7 +24,6 @@
#define OUTPUTMESSAGE_H
#include "declarations.h"
#include "networkexception.h"
#include <framework/luascript/luaobject.h>
class OutputMessage : public LuaObject