diff --git a/common/length.h b/common/length.h index d8f2dc9..689d37b 100644 --- a/common/length.h +++ b/common/length.h @@ -699,7 +699,7 @@ enum EMisc2 INVENTORY_AND_EQUIP_SLOT_MAX = BELT_INVENTORY_SLOT_END, }; -#pragma pack(push, 1) +#pragma pack(1) typedef struct SItemPos { @@ -778,6 +778,6 @@ typedef enum SHOP_COIN_TYPE_SECONDARY_COIN, } EShopCoinType; -#pragma pack(pop) +#pragma pack() #endif diff --git a/game/src/desc.cpp b/game/src/desc.cpp index d1a39ba..73d6a1b 100644 --- a/game/src/desc.cpp +++ b/game/src/desc.cpp @@ -37,7 +37,7 @@ void DescReadHandler(bufferevent *bev, void *ctx) { d->SetPhase(PHASE_CLOSE); } } - else if (d->ProcessInput() < 0) + else if (!d->ProcessInput()) { d->SetPhase(PHASE_CLOSE); } @@ -277,42 +277,41 @@ bool DESC::Setup(event_base * evbase, evutil_socket_t fd, const sockaddr * c_rSo return true; } -int DESC::ProcessInput() +bool DESC::ProcessInput() { evbuffer *input = bufferevent_get_input(m_bufevent); if (input == nullptr) { sys_err("DESC::ProcessInput : nil input buffer"); - return -1; + return false; } - size_t bytes_read = evbuffer_get_length(input); + if (!m_pInputProcessor) { + sys_err("no input processor"); + return false; + } - if (bytes_read < 0) - return -1; - else if (bytes_read == 0) - return 0; + // If CInputProcessor::Process returns false, then we switched to another phase, and we can continue reading + bool doContinue = true; - if (!m_pInputProcessor) - sys_err("no input processor"); + do { + size_t bytes_read = evbuffer_get_length(input); + // No data to read, we can continue + if (bytes_read == 0) + return true; - // Get the received data - void * data = evbuffer_pullup(input, bytes_read); + // Get the received data + void * data = evbuffer_pullup(input, bytes_read); - int iBytesProceed = 0; + int iBytesProceed = 0; // The number of bytes that have been processed + doContinue = m_pInputProcessor->Process(this, data, bytes_read, iBytesProceed); - // false°¡ ¸®ÅÏ µÇ¸é ´Ù¸¥ phase·Î ¹Ù²ï °ÍÀ̹ǷΠ´Ù½Ã ÇÁ·Î¼¼½º·Î µ¹ÀÔÇÑ´Ù! - while (!m_pInputProcessor->Process(this, data, bytes_read, iBytesProceed)) - { // Flush the read bytes from the network buffer evbuffer_drain(input, iBytesProceed); iBytesProceed = 0; - } + } while(!doContinue); - // Flush the read bytes from the network buffer - evbuffer_drain(input, iBytesProceed); - - return bytes_read; + return true; } bool DESC::RawPacket(const void * c_pvData, int iSize) diff --git a/game/src/desc.h b/game/src/desc.h index 577ec5e..d179595 100644 --- a/game/src/desc.h +++ b/game/src/desc.h @@ -95,7 +95,7 @@ class DESC bool RawPacket(const void * c_pvData, int iSize); void Packet(const void * c_pvData, int iSize); - int ProcessInput(); // returns -1 if error + bool ProcessInput(); // returns false if error CInputProcessor * GetInputProcessor() { return m_pInputProcessor; } diff --git a/game/src/input.cpp b/game/src/input.cpp index 7ad3c85..b7c524c 100644 --- a/game/src/input.cpp +++ b/game/src/input.cpp @@ -153,7 +153,7 @@ bool CInputProcessor::Process(LPDESC lpDesc, const void * c_pvOrig, int iBytes, { lpDesc->push_seq(bHeader, bSeq); lpDesc->SetNextSequence(); - //sys_err("SEQUENCE %x match %u next %u header %u", lpDesc, bSeq, lpDesc->GetSequence(), bHeader); + sys_err("SEQUENCE %x match %u next %u header %u", lpDesc, bSeq, lpDesc->GetSequence(), bHeader); } } diff --git a/game/src/packet.h b/game/src/packet.h index 2c45949..3463fbc 100644 --- a/game/src/packet.h +++ b/game/src/packet.h @@ -2311,4 +2311,5 @@ typedef struct SPacketGCStateCheck } TPacketGCStateCheck; #pragma pack() + #endif