forked from metin2/server
1
0
Fork 0

Fixed network handling of phase change, players can log ingame, but get disconnected after a few minutes with a sequence error.

This commit is contained in:
Exynox 2022-03-12 13:46:22 +02:00
parent 181f37cccd
commit 8c40c9f92e
5 changed files with 25 additions and 25 deletions

View File

@ -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

View File

@ -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)

View File

@ -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; }

View File

@ -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);
}
}

View File

@ -2311,4 +2311,5 @@ typedef struct SPacketGCStateCheck
} TPacketGCStateCheck;
#pragma pack()
#endif