1. Paket hatası çözümü
  2. 1) input.cpp
  3. ara:
  4. bool CInputProcessor::Process(LPDESC lpDesc, const void * c_pvOrig, int iBytes, int & r_iBytesProceed)
  5. ..............
  6. ............
  7. ......
  8. return true;
  9. }
  10. değiştir :
  11. int g_iLastPacket[2] = { -1, -1 };
  12. bool CInputProcessor::Process(LPDESC lpDesc, const void * c_pvOrig, int iBytes, int & r_iBytesProceed)
  13. {
  14. const char * c_pData = (const char *) c_pvOrig;
  15. int iPacketLen;
  16. if (!m_pPacketInfo)
  17. {
  18. sys_err("No packet info has been binded to");
  19. return true;
  20. }
  21. for (m_iBufferLeft = iBytes; m_iBufferLeft > 0;)
  22. {
  23. BYTE bHeader = (BYTE) *(c_pData);
  24. const char * c_pszName;
  25. if (bHeader == 0)
  26. iPacketLen = 1;
  27. else if (!m_pPacketInfo->Get(bHeader, &iPacketLen, &c_pszName))
  28. {
  29. lpDesc->SetPhase(PHASE_CLOSE);
  30. return true;
  31. }
  32. if (m_iBufferLeft < iPacketLen)
  33. return true;
  34. int originalPacketSize = iPacketLen;
  35. BYTE preAnalyzeSeq = *(BYTE*)(c_pData + iPacketLen - sizeof(BYTE));
  36. if (bHeader)
  37. {
  38. if (test_server && bHeader != HEADER_CG_MOVE)
  39. sys_log(0, "Packet Analyze [Header %d][bufferLeft %d] ", bHeader, m_iBufferLeft);
  40. m_pPacketInfo->Start();
  41. int iExtraPacketSize = Analyze(lpDesc, bHeader, c_pData);
  42. if (iExtraPacketSize < 0)
  43. {
  44. #ifdef ENABLE_ANTI_PACKET_FLOOD
  45. sys_err("Failed to analyze header(%u) host(%s)", bHeader, inet_ntoa(lpDesc->GetAddr().sin_addr));
  46. lpDesc->SetPhase(PHASE_CLOSE);
  47. #endif
  48. return true;
  49. }
  50. iPacketLen += iExtraPacketSize;
  51. lpDesc->Log("%s %d", c_pszName, iPacketLen);
  52. m_pPacketInfo->End();
  53. }
  54. c_pData += iPacketLen;
  55. m_iBufferLeft -= iPacketLen;
  56. r_iBytesProceed += iPacketLen;
  57. g_iLastPacket[1] = g_iLastPacket[0];
  58. g_iLastPacket[0] = bHeader;
  59. if (GetType() != lpDesc->GetInputProcessor()->GetType())
  60. return false;
  61. }
  62. return true;
  63. }
  64. client:
  65. Problem varsa:
  66. game.py ara ve sil
  67. if constInfo.SEQUENCE_PACKET_ENABLE:
  68. net.SetPacketSequenceMode()
  69. Constinfo ara ve sil
  70. SEQUENCE_PACKET_ENABLE = 1
  71. ----------------------------------------------------------------------------------------------
  72. Source Client:
  73. ara
  74. return SendSequence();
  75. değiştir
  76. // return disable;
  77. SERVERSIDE
  78. 0.1
  79. input_udp
  80. ara
  81. Set(1, sizeof(ServerStateChecker_RequestPacket), "ServerStateRequest", false);
  82. değiştir:
  83. Set(1, sizeof(ServerStateChecker_RequestPacket), "ServerStateRequest");
  84. 1) desc.cpp ve ara
  85. sil:
  86. #include "sequence.h"
  87. sil:
  88. m_iCurrentSequence = 0;
  89. hepsini sil
  90. m_seq_vector.clear();
  91. sil:
  92. BYTE DESC::GetSequence()
  93. {
  94. return gc_abSequence[m_iCurrentSequence];
  95. }
  96. void DESC::SetNextSequence()
  97. {
  98. if (++m_iCurrentSequence == SEQUENCE_MAX_NUM)
  99. m_iCurrentSequence = 0;
  100. }
  101. sil:
  102. void DESC::push_seq(BYTE hdr, BYTE seq)
  103. {
  104. if (m_seq_vector.size() >= 20)
  105. {
  106. m_seq_vector.erase(m_seq_vector.begin());
  107. }
  108. seq_t info = { hdr, seq };
  109. m_seq_vector.push_back(info);
  110. }
  111. 2) DESC.H
  112. sil:
  113. struct seq_t
  114. {
  115. BYTE hdr;
  116. BYTE seq;
  117. };
  118. typedef std::vector<seq_t> seq_vector_t;
  119. sil:
  120. BYTE GetSequence();
  121. void SetNextSequence();
  122. sil:
  123. int m_iCurrentSequence;
  124. sil:
  125. public:
  126. seq_vector_t m_seq_vector;
  127. void push_seq(BYTE hdr, BYTE seq);
  128. 3) INPUT.CPP
  129. ara:
  130. sys_log(0, "PONG! %u %u", m_pPacketInfo->IsSequence(bHeader), *(BYTE *)(c_pData + iPacketLen - sizeof(BYTE)));
  131. değiştir:
  132. sys_log(0, "PONG! %u", *(BYTE *)(c_pData + iPacketLen - sizeof(BYTE)));
  133. sil:
  134. if (m_pPacketInfo->IsSequence(bHeader))
  135. {
  136. BYTE bSeq = lpDesc->GetSequence();
  137. BYTE bSeqReceived = *(BYTE *)(c_pData + iPacketLen - sizeof(BYTE));
  138. if (bSeq != bSeqReceived)
  139. {
  140. sys_err("SEQUENCE %x mismatch 0x%x != 0x%x header %u", get_pointer(lpDesc), bSeq, bSeqReceived, bHeader);
  141. LPCHARACTER ch = lpDesc->GetCharacter();
  142. char buf[1024];
  143. int offset, len;
  144. offset = snprintf(buf, sizeof(buf), "SEQUENCE_LOG [%s]-------------\n", ch ? ch->GetName() : "UNKNOWN");
  145. if (offset < 0 || offset >= (int) sizeof(buf))
  146. offset = sizeof(buf) - 1;
  147. for (size_t i = 0; i < lpDesc->m_seq_vector.size(); ++i)
  148. {
  149. len = snprintf(buf + offset, sizeof(buf) - offset, "\t[%03d : 0x%x]\n",
  150. lpDesc->m_seq_vector[i].hdr,
  151. lpDesc->m_seq_vector[i].seq);
  152. if (len < 0 || len >= (int) sizeof(buf) - offset)
  153. offset += (sizeof(buf) - offset) - 1;
  154. else
  155. offset += len;
  156. }
  157. snprintf(buf + offset, sizeof(buf) - offset, "\t[%03d : 0x%x]\n", bHeader, bSeq);
  158. sys_err("%s", buf);
  159. lpDesc->SetPhase(PHASE_CLOSE);
  160. return true;
  161. }
  162. else
  163. {
  164. lpDesc->push_seq(bHeader, bSeq);
  165. lpDesc->SetNextSequence();
  166. //sys_err("SEQUENCE %x match %u next %u header %u", lpDesc, bSeq, lpDesc->GetSequence(), bHeader);
  167. }
  168. }
  169. sil:
  170. pkPacketInfo->SetSequence(HEADER_CG_PONG, false);
  171. 4)PACKET_INFO.CPP
  172. ara:
  173. void CPacketInfo::Set(int header, int iSize, const char * c_pszName, bool bSeq)
  174. değiştir:
  175. void CPacketInfo::Set(int header, int iSize, const char * c_pszName)
  176. sil:
  177. element->bSequencePacket = bSeq;
  178. if (element->bSequencePacket)
  179. element->iSize += sizeof(BYTE);
  180. sil:
  181. bool CPacketInfo::IsSequence(int header)
  182. {
  183. TPacketElement * pkElement = GetElement(header);
  184. return pkElement ? pkElement->bSequencePacket : false;
  185. }
  186. void CPacketInfo::SetSequence(int header, bool bSeq)
  187. {
  188. TPacketElement * pkElem = GetElement(header);
  189. if (pkElem)
  190. {
  191. if (bSeq)
  192. {
  193. if (!pkElem->bSequencePacket)
  194. pkElem->iSize++;
  195. }
  196. else
  197. {
  198. if (pkElem->bSequencePacket)
  199. pkElem->iSize--;
  200. }
  201. pkElem->bSequencePacket = bSeq;
  202. }
  203. }
  204. ara :
  205. void CPacketInfo::Log(const char * c_pszFileName)
  206. değiştir :
  207. void CPacketInfo::Log(const char * c_pszFileName)
  208. {
  209. #ifndef NO_PACKET_INFO_LOG
  210. FILE * fp;
  211. fp = fopen(c_pszFileName, "w");
  212. if (!fp)
  213. return;
  214. std::map<int, TPacketElement *>::iterator it = m_pPacketMap.begin();
  215. fprintf(fp, "Name Called Load Ratio\n");
  216. while (it != m_pPacketMap.end())
  217. {
  218. TPacketElement * p = it->second;
  219. ++it;
  220. fprintf(fp, "%-16s %-10d %-10u %.2f\n",
  221. p->stName.c_str(),
  222. p->iCalled,
  223. p->dwLoad,
  224. p->iCalled != 0 ? (float) p->dwLoad / p->iCalled : 0.0f);
  225. }
  226. fclose(fp);
  227. #endif
  228. }
  229. bul:
  230. , false");
  231. bu şekilde değiştir
  232. ");
  233. elle değiştirmek isterseniz ---> ", false" silin
  234. örnek:
  235. Set(HEADER_CG_TEXT, sizeof(TPacketCGText), "Text");
  236. 5) PACKET_INFO.H
  237. sil:
  238. bool bSequencePacket;
  239. ara:
  240. void Set(int header, int size, const char * c_pszName, bool bSeq = false);
  241. değiştir:
  242. void Set(int header, int size, const char * c_pszName);
  243. sil:
  244. bool IsSequence(int header);
  245. void SetSequence(int header, bool bSeq);
  246. 6) SEQUENCE.CPP
  247. sil
  248. const BYTE gc_abSequence[SEQUENCE_MAX_NUM] =
  249. {
  250. ..................BLA BLA
  251. ...............BLA BLA
  252. ............. BLA BLA
  253. .........BLA BLA BLA BLA
  254. };
  255. 7) SEQUENCE.H
  256. herşeyi sil
  257. CLIENTSIDE
  258. sil:
  259. m_iSequence = 0;
  260. sil tümünü:
  261. #define SEQUENCE_TABLE_SIZE 32768
  262. sil:
  263. void CNetworkStream::SetPacketSequenceMode(bool isOn)
  264. {
  265. m_bUseSequence = isOn;
  266. }
  267. ara:
  268. bool CNetworkStream::SendSequence()
  269. değiştir :
  270. bool CNetworkStream::SendSequence()
  271. {
  272. return true;
  273. }
  274. ara:
  275. static BYTE s_bSequenceTable[SEQUENCE_TABLE_SIZE] =
  276. sil:
  277. static BYTE s_bSequenceTable[SEQUENCE_TABLE_SIZE] =
  278. {
  279. ..................BLA BLA
  280. ...............BLA BLA
  281. ............. BLA BLA
  282. .........BLA BLA BLA BLA
  283. };
  284. sil:
  285. m_iSequence = 0;
  286. m_bUseSequence = false;
  287. m_kVec_bSequenceTable.resize(SEQUENCE_TABLE_SIZE);
  288. memcpy(&m_kVec_bSequenceTable[0], s_bSequenceTable, sizeof(BYTE) * SEQUENCE_TABLE_SIZE);
  289. NETSTREAM.H
  290. sil:
  291. void SetPacketSequenceMode(bool isOn);
  292. sil:
  293. DWORD m_iSequence;
  294. bool m_bUseSequence;
  295. std::vector<BYTE> m_kVec_bSequenceTable;
  296. PYTHONNETWORKSTREAMMODULE.CPP
  297. bul PyObject* netSetPacketSequenceMode(PyObject* poSelf, PyObject* poArgs)
  298. bunu sil
  299. CPythonNetworkStream& rns = CPythonNetworkStream::Instance();
  300. CAccountConnector & rkAccountConnector = CAccountConnector::Instance();
  301. rns.SetPacketSequenceMode(true);
  302. rkAccountConnector.SetPacketSequenceMode(true);
  303. ---------------------------------------------------------------------------------------------------------------
  304. 1.0 desc.cpp
  305. ara:
  306. void DESC::Packet(const void * c_pvData, int iSize)
  307. {
  308. assert(iSize > 0);
  309. değiştir:
  310. void DESC::Packet(const void * c_pvData, int iSize)
  311. {
  312. assert(NULL != c_pvData);
  313. assert(iSize > 0);
  314. ---------------------------------------------------------------------------------------------------------------
  315. ---------------------------------------------------------------------------------------------------------------
  316. 1.1) desc.cpp ara
  317. else if (!m_bEncrypted)
  318. değiştir:
  319. else if (!m_bEncrypted)
  320. {
  321. int iBytesProceed = 0;
  322. while (!m_pInputProcessor->Process(this, buffer_read_peek(m_lpInputBuffer), buffer_size(m_lpInputBuffer), iBytesProceed))
  323. {
  324. buffer_read_proceed(m_lpInputBuffer, iBytesProceed);
  325. iBytesProceed = 0;
  326. }
  327. buffer_read_proceed(m_lpInputBuffer, iBytesProceed);
  328. }
  329. else
  330. {
  331. int iSizeBuffer = buffer_size(m_lpInputBuffer);
  332. if (iSizeBuffer & 7)
  333. iSizeBuffer -= iSizeBuffer & 7;
  334. if (iSizeBuffer > 0)
  335. {
  336. TEMP_BUFFER tempbuf(8192 + 4);
  337. LPBUFFER lpBufferDecrypt = tempbuf.getptr();
  338. buffer_adjust_size(lpBufferDecrypt, iSizeBuffer);
  339. long iSizeAfter = TEA_Decrypt(reinterpret_cast<DWORD *>(buffer_write_peek(lpBufferDecrypt)),
  340. reinterpret_cast<const DWORD *>( buffer_read_peek(m_lpInputBuffer)),
  341. GetDecryptionKey(),
  342. iSizeBuffer);
  343. buffer_write_proceed(lpBufferDecrypt, iSizeAfter);
  344. int iBytesProceed = 0;
  345. while (!m_pInputProcessor->Process(this, buffer_read_peek(lpBufferDecrypt), buffer_size(lpBufferDecrypt), iBytesProceed))
  346. {
  347. if (iBytesProceed > iSizeBuffer)
  348. {
  349. buffer_read_proceed(m_lpInputBuffer, iSizeBuffer);
  350. iSizeBuffer = 0;
  351. iBytesProceed = 0;
  352. break;
  353. }
  354. buffer_read_proceed(m_lpInputBuffer, iBytesProceed);
  355. iSizeBuffer -= iBytesProceed;
  356. buffer_read_proceed(lpBufferDecrypt, iBytesProceed);
  357. iBytesProceed = 0;
  358. }
  359. buffer_read_proceed(m_lpInputBuffer, iBytesProceed);
  360. }
  361. }
  362. return (bytes_read);
  363. }
  364. ---------------------------------------------------------------------------------------------------------------
  365. ---------------------------------------------------------------------------------------------------------------
  366. 1.2) ara desc.cpp
  367. if (!m_bEncrypted)
  368. değiştir:
  369. if (!m_bEncrypted)
  370. {
  371. if (!packet_encode(m_lpOutputBuffer, c_pvData, iSize))
  372. {
  373. m_iPhase = PHASE_CLOSE;
  374. }
  375. }
  376. else
  377. {
  378. if (buffer_has_space(m_lpOutputBuffer) < iSize + 8)
  379. {
  380. buffer_adjust_size(m_lpOutputBuffer, iSize);
  381. if (buffer_has_space(m_lpOutputBuffer) < iSize + 8)
  382. {
  383. sys_err(
  384. "desc buffer mem_size overflow : ",
  385. " memsize(%u) ",
  386. " write_pos(%u)",
  387. " iSize(%d)",
  388. m_lpOutputBuffer->mem_size,
  389. m_lpOutputBuffer->write_point_pos,
  390. iSize);
  391. m_iPhase = PHASE_CLOSE;
  392. }
  393. }
  394. else
  395. {
  396. DWORD * pdwWritePoint = static_cast<DWORD *>(buffer_write_peek(m_lpOutputBuffer));
  397. if (packet_encode(m_lpOutputBuffer, c_pvData, iSize))
  398. {
  399. long iSize2 = TEA_Encrypt(pdwWritePoint, pdwWritePoint, GetEncryptionKey(), iSize);
  400. if (iSize2 > iSize)
  401. buffer_write_proceed(m_lpOutputBuffer, iSize2 - iSize);
  402. }
  403. }
  404. }
  405. SAFE_BUFFER_DELETE(m_lpBufferedOutputBuffer);
  406. }
  407. if (m_iPhase != PHASE_CLOSE)
  408. fdwatch_add_fd(m_lpFdw, m_sock, this, FDW_WRITE, true);
  409. }
  410. ---------------------------------------------------------------------------------------------------------------
  411. ---------------------------------------------------------------------------------------------------------------
  412. 1.4 protocol.h ara
  413. //buffer_adjust_size(pbuf, length);
  414. değiştir :
  415. buffer_adjust_size(pbuf, length);
  416. ---------------------------------------------------------------------------------------------------------------
  417. Anti flood sistemini aktif edelim
  418. 1) SERVICE.CPP
  419. ekle
  420. #define ENABLE_ANTI_PACKET_FLOOD
  421. 2) CHAR.CPP
  422. ara
  423. m_fAttMul = 1.0f;
  424. m_fDamMul = 1.0f;
  425. ekle
  426. #ifdef ENABLE_ANTI_PACKET_FLOOD
  427. m_dwPacketAntiFloodCount = 0;
  428. m_dwPacketAntiFloodPulse = 0;
  429. #endif
  430. 3) CHAR.H
  431. ara
  432. protected:
  433. CARDS_INFO character_cards;
  434. S_CARD randomized_cards[24];
  435. ekle
  436. #ifdef ENABLE_ANTI_PACKET_FLOOD
  437. private:
  438. int m_dwPacketAntiFloodPulse;
  439. DWORD m_dwPacketAntiFloodCount;
  440. public:
  441. int GetPacketAntiFloodPulse(){return m_dwPacketAntiFloodPulse;}
  442. DWORD GetPacketAntiFloodCount(){return m_dwPacketAntiFloodCount;}
  443. DWORD IncreasePacketAntiFloodCount(){return ++m_dwPacketAntiFloodCount;}
  444. void SetPacketAntiFloodPulse(int dwPulse){m_dwPacketAntiFloodPulse=dwPulse;}
  445. void SetPacketAntiFloodCount(DWORD dwCount){m_dwPacketAntiFloodCount=dwCount;}
  446. #endif
  447. 4) INPUT.CPP
  448. ara
  449. if (iExtraPacketSize < 0)
  450. {
  451. değiştir
  452. if (iExtraPacketSize < 0)
  453. {
  454. #ifdef ENABLE_ANTI_PACKET_FLOOD
  455. sys_err("Failed to analyze header(%u) host(%s)", bHeader, inet_ntoa(lpDesc->GetAddr().sin_addr));
  456. lpDesc->SetPhase(PHASE_CLOSE);
  457. #endif
  458. 5) INPUT_LOGIN.CPP de bul int CInputLogin::Analyze(LPDESC d, BYTE bHeader, const char * c_pData)
  459. tüm hepsini değiştir
  460. default:
  461. sys_err("login phase does not handle this packe2t! header %d", bHeader);
  462. #ifdef ENABLE_ANTI_PACKET_FLOOD
  463. return -1;
  464. #else
  465. return (0);
  466. #endif
  467. }
  468. return (iExtraLen);
  469. }
  470. 6) INPUT_MAIN.CPP
  471. ara
  472. if (!(ch = d->GetCharacter()))
  473. değiştir
  474. if (!(ch = d->GetCharacter()))
  475. {
  476. sys_err("no character on desc");
  477. d->SetPhase(PHASE_CLOSE);
  478. #ifdef ENABLE_ANTI_PACKET_FLOOD
  479. return -1;
  480. #else
  481. return (0);
  482. #endif
  483. }
  484. #ifdef ENABLE_ANTI_PACKET_FLOOD
  485. if (bHeader != HEADER_CG_ITEM_USE)
  486. {
  487. if (thecore_pulse() > ch->GetPacketAntiFloodPulse() + PASSES_PER_SEC(1))
  488. {
  489. ch->SetPacketAntiFloodCount(0);
  490. ch->SetPacketAntiFloodPulse(thecore_pulse());
  491. }
  492. if (ch->IncreasePacketAntiFloodCount() >= 250)
  493. {
  494. sys_err("<Flood packet> name(%s) header(%u) host(%s)", ch->GetName(), bHeader, inet_ntoa(d->GetAddr().sin_addr));
  495. ch->GetDesc()->DelayedDisconnect(0);
  496. return false;
  497. }
  498. }
  499. #endif
  500. ara
  501. if (!(ch = d->GetCharacter()))
  502. değiştir
  503. if (!(ch = d->GetCharacter()))
  504. {
  505. sys_err("no character on desc");
  506. #ifdef ENABLE_ANTI_PACKET_FLOOD
  507. return -1;
  508. #else
  509. return 0;
  510. #endif
  511. }
  512. int CInputDead::Analyze(LPDESC d, BYTE bHeader, const char * c_pData) da
  513. default: hepsini değiştir
  514. default: bununla
  515. #ifdef ENABLE_ANTI_PACKET_FLOOD
  516. return -1;
  517. #else
  518. return (0);
  519. #endif
  520. }
  521. return (iExtraLen);
  522. }
  523. CLIENT:
  524. 1) tüm sequence ile alakalı şeyleri silin

Sadece1.com