Hello,
I come to share my knowledge on what I discovered recently on the encryption of packets. Some may tell me, but this has already been shared by MartySama. In reality, this one is not complete, it has forgotten a very important factor which I will present to you subsequently.
But suddenly, you have to wonder what is happening if we disable the encryption of packets, by the way he shared it? Well, we may have an overload at the buffers, which may cause crashes game without error, or rather strange bugs.
I could see different strange bugs. The most common was the fact that we can no longer perform an action that requires an agreement with the game. Example, after 15 minutes of play with a few connected players, some can no longer click on an item, or others will not be able to talk, etc ...
There was a lot of debate about this, I took advice left and right and I pulled a problem.
Why these bugs were not present before the encryption of packets?
Simply because the structure was edited.
Indeed, we can see that in the protocol.h Game, the function buffer_adjust_size was commented.
Also, in the desc.cpp, they completely removed the condition in the function:
But why ? Simply because it is no longer useful, the new system no longer requires a size adjuster for buffers (it seems to me)
Or, they coded something else that automatically adjusts the size of the buffers but I have not watched yet.
Why would I disable this system?
ZitatConnection time LARGELY decreased (as we no longer use Cipher)
Loading time also decreased
Better fluidity (personal opinion)
Size of the game enormously diminished as well as that of the launcher
Here is a small preview video:
Bitte melden Sie sich an, um dieses Medienelement zu sehen.
Server side changes:
A. Service.h file (Common)
Look for this line:
And comment or delete the line like this:
B. Protocol.h file (Game)
Look for this line:
Uncomment it like this:
C. desc.cpp file (Game)
Look for this line:
Replace the entire function with this:
- void DESC::Packet(const void * c_pvData, int iSize)
- {
- assert(iSize > 0);
- if (m_iPhase == PHASE_CLOSE) // 끊는 상태면 보내지 않는다.
- return;
- if (m_stRelayName.length() != 0)
- {
- // Relay 패킷은 암호화하지 않는다.
- TPacketGGRelay p;
- p.bHeader = HEADER_GG_RELAY;
- strlcpy(p.szName, m_stRelayName.c_str(), sizeof(p.szName));
- p.lSize = iSize;
- if (!packet_encode(m_lpOutputBuffer, &p, sizeof(p)))
- {
- m_iPhase = PHASE_CLOSE;
- return;
- }
- m_stRelayName.clear();
- if (!packet_encode(m_lpOutputBuffer, c_pvData, iSize))
- {
- m_iPhase = PHASE_CLOSE;
- return;
- }
- }
- else
- {
- if (m_lpBufferedOutputBuffer)
- {
- buffer_write(m_lpBufferedOutputBuffer, c_pvData, iSize);
- c_pvData = buffer_read_peek(m_lpBufferedOutputBuffer);
- iSize = buffer_size(m_lpBufferedOutputBuffer);
- }
- // TRAFFIC_PROFILE
- if (g_bTrafficProfileOn)
- TrafficProfiler::instance().Report(TrafficProfiler::IODIR_OUTPUT, *(BYTE *) c_pvData, iSize);
- // END_OF_TRAFFIC_PROFILER
- #ifdef _IMPROVED_PACKET_ENCRYPTION_
- void* buf = buffer_write_peek(m_lpOutputBuffer);
- if (packet_encode(m_lpOutputBuffer, c_pvData, iSize))
- {
- if (cipher_.activated()) {
- cipher_.Encrypt(buf, iSize);
- }
- }
- else
- {
- m_iPhase = PHASE_CLOSE;
- }
- #else
- if (!m_bEncrypted)
- {
- if (!packet_encode(m_lpOutputBuffer, c_pvData, iSize))
- {
- m_iPhase = PHASE_CLOSE;
- }
- }
- else
- {
- if (buffer_has_space(m_lpOutputBuffer) < iSize + 8)
- {
- buffer_adjust_size(m_lpOutputBuffer, iSize);
- if (buffer_has_space(m_lpOutputBuffer) < iSize + 8)
- {
- sys_err(
- "desc buffer mem_size overflow : ",
- " memsize(%u) ",
- " write_pos(%u)",
- " iSize(%d)", m_lpOutputBuffer->mem_size,
- m_lpOutputBuffer->write_point_pos,
- iSize);
- m_iPhase = PHASE_CLOSE;
- }
- }
- else
- {
- // 암호화에 필요한 충분한 버퍼 크기를 확보한다.
- /* buffer_adjust_size(m_lpOutputBuffer, iSize + 8); */
- DWORD * pdwWritePoint = (DWORD *) buffer_write_peek(m_lpOutputBuffer);
- if (packet_encode(m_lpOutputBuffer, c_pvData, iSize))
- {
- int iSize2 = TEA_Encrypt(pdwWritePoint, pdwWritePoint, GetEncryptionKey(), iSize);
- if (iSize2 > iSize)
- buffer_write_proceed(m_lpOutputBuffer, iSize2 - iSize);
- }
- }
- }
- #endif // _IMPROVED_PACKET_ENCRYPTION_
- SAFE_BUFFER_DELETE(m_lpBufferedOutputBuffer);
- }
- //sys_log(0, "%d bytes written (first byte %d)", iSize, *(BYTE *) c_pvData);
- if (m_iPhase != PHASE_CLOSE)
- fdwatch_add_fd(m_lpFdw, m_sock, this, FDW_WRITE, true);
- }
Warning ! Do not forget to compile your Game & your DB
Client side change:
D. ServiceDefs file (Eterpack)
Look for this line:
Comment or delete like this:
E. Locale.cpp file (Userinterface)
Look for this line:
Edit like this:
If you want to share this tutorial elsewhere, please quote the source.
Kuroro