Guest User

Untitled

a guest
May 16th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. BOOL md2bs::MCPReceiveIntercept(BYTE* data, DWORD length)
  2. {
  3. MCPheader* MCPh = (MCPheader*)data;
  4. if(!MCPh)
  5. return FALSE;
  6.  
  7. if(myFLAG(_CFG_bMCPDebug))
  8. {
  9. char t[1024], _prefix[64];
  10. _snprintf_s(_prefix, sizeof(_prefix), _TRUNCATE, "MCP RECV %02X", MCPh->identifier);
  11. FormatDataPkt(t, sizeof(t), _prefix, data, length);
  12. PrintDebug(t);
  13. }
  14.  
  15. switch(MCPh->identifier)
  16. {
  17. case 0x01:
  18. {
  19. DWORD dwResult = *(DWORD*)&data[1];
  20. switch(dwResult)
  21. {
  22. case 0x7e:
  23. PrintLog("Your CD-Key is disabled from playing realm games.");
  24. SetFlag(BS_FLAG_CDKEY_BANNED, TRUE);
  25. SetFlag(BS_FLAG_REALM_DOWN, TRUE);
  26. #ifdef PLUGIN_SUPPORT
  27. ProcessCallBack(EVENT_BUILDUP_ERROR, (LPVOID)BUILDUP_ERROR_CDKEY_BANNED);
  28. #endif
  29. CloseConnection();
  30. break;
  31. case 0x7f:
  32. PrintLog("You have a temporary IP ban on this realm server.");
  33. SetFlag(BS_FLAG_REALM_DOWN, TRUE);
  34. #ifdef PLUGIN_SUPPORT
  35. ProcessCallBack(EVENT_BUILDUP_ERROR, (LPVOID)BUILDUP_ERROR_IP_BANNED);
  36. #endif
  37. CloseConnection();
  38. break;
  39. case 0x02:
  40. case 0x0a:
  41. case 0x0b:
  42. case 0x0c:
  43. case 0x0d:
  44. PrintLog("Realm is unavailable. No Battle.net connection detected.");
  45. SetFlag(BS_FLAG_REALM_DOWN, TRUE);
  46. #ifdef PLUGIN_SUPPORT
  47. ProcessCallBack(EVENT_BUILDUP_ERROR, (LPVOID)BUILDUP_ERROR_REALM_DEAD);
  48. #endif
  49. CloseConnection();
  50. break;
  51. default: //success
  52. {
  53. SetConnectionState(CONN_STATE_ACCOUNT);
  54.  
  55. InitRealmHandler();
  56. if(GetFlag(BS_FLAG_REALM_LOGON_FROM_GAME))
  57. {
  58. SetHandlerState(HANDLER_REALM,REALM_STATE_CLOSE_THREAD,REALM_STATE_CHOOSE_CHAR);
  59. }
  60. else
  61. SetHandlerState(HANDLER_REALM,REALM_STATE_CLOSE_THREAD,REALM_STATE_CHARLIST_SEND);
  62. }
  63. }
  64. break;
  65. }
  66.  
  67.  
  68. #define MCP_CREATE_CHAR_SUCCESS 0x00
  69. #define MCP_CREATE_CHAR_EXISTS 0x14
  70. #define MCP_CREATE_CHAR_INVALID 0x15
  71.  
  72. case 0x02:
  73. {
  74. DWORD dwStatus = *(DWORD*)&data[1];
  75. PrintLog("Received create char status: %s",
  76. GetCreateCharStatus(dwStatus));
  77. SetHandlerState(HANDLER_REALM,REALM_STATE_CHARLIST_SEND);
  78. return TRUE;
  79. }
  80.  
  81. #define MCP_CREATE_GAME_SUCCESS 0x00
  82. case 0x03: //CREATE GAME
  83. PrintLog("Received create game status: %s", MCPh->status == MCP_CREATE_GAME_SUCCESS ? "SUCCESS" : "FAILED");
  84. curr_game.requestid = MCPh->cookie;
  85. *(DWORD*)lib->GetCoreVarAddr(HCONN_SERVER_TOKEN) = *(DWORD*)&data[3];
  86. if(MCPh->status == MCP_CREATE_GAME_SUCCESS)
  87. curr_game.bCreateGameFlag = TRUE;
  88. else
  89. {
  90. SendCoreMessage(GetID(), EVENT_ERR_CREATEGAME_FAILED, NULL);
  91. }
  92. return TRUE;
  93.  
  94. #define MCP_JOIN_GAME_SUCCESS 0x00
  95. case 0x04: //JOIN GAME
  96. {
  97. *(DWORD*)lib->GetCoreVarAddr(HCONN_SERVER_TOKEN) = *(DWORD*)&data[3];
  98. *(WORD*)D2GETMEM(hClient, client, &client->wServerToken, WORD) = (WORD)lib->GetCoreVar(HCONN_SERVER_TOKEN);
  99. *(DWORD*)D2GETMEM(hClient, client, &client->dwGameHash, DWORD) = *(DWORD*)&data[11];
  100.  
  101. DWORD dwStatus = *(DWORD*)&data[15];
  102. if(dwStatus == MCP_JOIN_GAME_SUCCESS)
  103. {
  104. #ifdef MCP_DEBUG_FLAG
  105. PrintLog("Connected to game server: %d.%d.%d.%d",
  106. MCPh->D2GS_IP[0],MCPh->D2GS_IP[1],MCPh->D2GS_IP[2],MCPh->D2GS_IP[3]
  107. );
  108. #endif
  109. strcpy(D2GETMEM(hClient, client, client->gameip, char), lib->FOG_GetIPStringFromByteOrder(*(DWORD*)&MCPh->D2GS_IP[0]));
  110. strcpy(D2GETMEM(hClient, client, client->gamename, char), curr_game.name);
  111. strcpy(D2GETMEM(hClient, client, client->gamepass, char), curr_game.pass);
  112. strcpy(D2GETMEM(hClient, client, client->gamedesc, char), curr_game.desc);
  113. SetHandlerState(HANDLER_BNET,BNET_STATE_JOIN_GAME);
  114. }
  115. else
  116. {
  117. PrintLog("Failed to join game: %s",
  118. GetJoinGameStatus(dwStatus)
  119. );
  120. DisconnectGame(TRUE, TRUE);
  121. SendCoreMessage(GetID(), EVENT_ERR_JOINGAME_FAILED, NULL);
  122. }
  123. return TRUE;
  124. }
  125.  
  126. case 0x05: //GAMELIST REQUEST
  127. EnumGames(MCPh);
  128. return FALSE;
  129.  
  130. case 0x06: //GAMEINFO REQUEST
  131. ParseGameInfo(MCPh,length);
  132. return TRUE;
  133.  
  134. case 0x07:
  135. switch(*(DWORD*)data)
  136. {
  137. case 0x46: //not found
  138. PrintLog("Error: Player not found");
  139. break;
  140. case 0x7A: //logon failed
  141. PrintLog("Error: Logon failed");
  142. break;
  143. case 0x7B: //char expired
  144. PrintLog("Error: Character expired");
  145. break;
  146. default:
  147. {
  148. PrintLog("Character logon success");
  149. m_ChooseCharRetries = 0;
  150. return TRUE;
  151. }
  152. }
  153.  
  154. //retry to choose character
  155. if(++m_ChooseCharRetries >= MAX_CHOOSE_CHAR_RETRIES)
  156. {
  157. m_ChooseCharRetries = 0;
  158. CloseConnection();
  159. }
  160. else
  161. {
  162. PrintLog("Failed to choose character. Retrying..");
  163. SetHandlerState(HANDLER_REALM,REALM_STATE_CHARLIST_SEND,REALM_STATE_IDLE);
  164. }
  165. return TRUE;
  166.  
  167. case 0x19: //CHARLIST REQUEST
  168. #ifdef MCP_DEBUG_FLAG
  169. PrintLog("Received account charlist");
  170. #endif
  171. InitPlayers();
  172. GameList.RemoveAll();
  173. EnumPlayers((PMCPheader2)MCPh);
  174. return TRUE;
  175. default:;
  176. }
  177. return FALSE;
  178. }
Add Comment
Please, Sign In to add comment