Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.27 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2008-2013 TrinityCore <http://www.trinitycore.org/>
  3. * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18.  
  19. #include <algorithm>
  20. #include <openssl/md5.h>
  21.  
  22. #include "Common.h"
  23. #include "Database/DatabaseEnv.h"
  24. #include "ByteBuffer.h"
  25. #include "Configuration/Config.h"
  26. #include "Log.h"
  27. #include "RealmList.h"
  28. #include "AuthSocket.h"
  29. #include "AuthCodes.h"
  30. #include "SHA1.h"
  31. #include "openssl/crypto.h"
  32.  
  33. #define ChunkSize 2048
  34.  
  35. enum eAuthCmd
  36. {
  37. AUTH_LOGON_CHALLENGE = 0x00,
  38. AUTH_LOGON_PROOF = 0x01,
  39. AUTH_RECONNECT_CHALLENGE = 0x02,
  40. AUTH_RECONNECT_PROOF = 0x03,
  41. REALM_LIST = 0x10,
  42. XFER_INITIATE = 0x30,
  43. XFER_DATA = 0x31,
  44. XFER_ACCEPT = 0x32,
  45. XFER_RESUME = 0x33,
  46. XFER_CANCEL = 0x34
  47. };
  48.  
  49. enum eStatus
  50. {
  51. STATUS_CONNECTED = 0,
  52. STATUS_AUTHED
  53. };
  54.  
  55. // GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push, N), also any gcc version not support it at some paltform
  56. #if defined(__GNUC__)
  57. #pragma pack(1)
  58. #else
  59. #pragma pack(push, 1)
  60. #endif
  61.  
  62. typedef struct AUTH_LOGON_CHALLENGE_C
  63. {
  64. uint8 cmd;
  65. uint8 error;
  66. uint16 size;
  67. uint8 gamename[4];
  68. uint8 version1;
  69. uint8 version2;
  70. uint8 version3;
  71. uint16 build;
  72. uint8 platform[4];
  73. uint8 os[4];
  74. uint8 country[4];
  75. uint32 timezone_bias;
  76. uint32 ip;
  77. uint8 I_len;
  78. uint8 I[1];
  79. } sAuthLogonChallenge_C;
  80.  
  81. typedef struct AUTH_LOGON_PROOF_C
  82. {
  83. uint8 cmd;
  84. uint8 A[32];
  85. uint8 M1[20];
  86. uint8 crc_hash[20];
  87. uint8 number_of_keys;
  88. uint8 securityFlags; // 0x00-0x04
  89. } sAuthLogonProof_C;
  90.  
  91. typedef struct AUTH_LOGON_PROOF_S
  92. {
  93. uint8 cmd;
  94. uint8 error;
  95. uint8 M2[20];
  96. uint32 unk1;
  97. uint32 unk2;
  98. uint16 unk3;
  99. } sAuthLogonProof_S;
  100.  
  101. typedef struct AUTH_LOGON_PROOF_S_OLD
  102. {
  103. uint8 cmd;
  104. uint8 error;
  105. uint8 M2[20];
  106. uint32 unk2;
  107. } sAuthLogonProof_S_Old;
  108.  
  109. typedef struct AUTH_RECONNECT_PROOF_C
  110. {
  111. uint8 cmd;
  112. uint8 R1[16];
  113. uint8 R2[20];
  114. uint8 R3[20];
  115. uint8 number_of_keys;
  116. } sAuthReconnectProof_C;
  117.  
  118. typedef struct XFER_INIT
  119. {
  120. uint8 cmd; // XFER_INITIATE
  121. uint8 fileNameLen; // strlen(fileName);
  122. uint8 fileName[5]; // fileName[fileNameLen]
  123. uint64 file_size; // file size (bytes)
  124. uint8 md5[MD5_DIGEST_LENGTH]; // MD5
  125. } XFER_INIT;
  126.  
  127. typedef struct XFER_DATA
  128. {
  129. uint8 opcode;
  130. uint16 data_size;
  131. uint8 data[ChunkSize];
  132. } XFER_DATA_STRUCT;
  133.  
  134. typedef struct AuthHandler
  135. {
  136. eAuthCmd cmd;
  137. uint32 status;
  138. bool (AuthSocket::*handler)(void);
  139. } AuthHandler;
  140.  
  141. // GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some paltform
  142. #if defined(__GNUC__)
  143. #pragma pack()
  144. #else
  145. #pragma pack(pop)
  146. #endif
  147.  
  148. // Launch a thread to transfer a patch to the client
  149. class PatcherRunnable: public ACE_Based::Runnable
  150. {
  151. public:
  152. PatcherRunnable(class AuthSocket*);
  153. void run();
  154.  
  155. private:
  156. AuthSocket* mySocket;
  157. };
  158.  
  159. typedef struct PATCH_INFO
  160. {
  161. uint8 md5[MD5_DIGEST_LENGTH];
  162. } PATCH_INFO;
  163.  
  164. // Caches MD5 hash of client patches present on the server
  165. class Patcher
  166. {
  167. public:
  168. typedef std::map<std::string, PATCH_INFO*> Patches;
  169. ~Patcher();
  170. Patcher();
  171. Patches::const_iterator begin() const { return _patches.begin(); }
  172. Patches::const_iterator end() const { return _patches.end(); }
  173. void LoadPatchMD5(char*);
  174. bool GetHash(char * pat, uint8 mymd5[16]);
  175.  
  176. private:
  177. void LoadPatchesInfo();
  178. Patches _patches;
  179. };
  180.  
  181. const AuthHandler table[] =
  182. {
  183. { AUTH_LOGON_CHALLENGE, STATUS_CONNECTED, &AuthSocket::_HandleLogonChallenge },
  184. { AUTH_LOGON_PROOF, STATUS_CONNECTED, &AuthSocket::_HandleLogonProof },
  185. { AUTH_RECONNECT_CHALLENGE, STATUS_CONNECTED, &AuthSocket::_HandleReconnectChallenge},
  186. { AUTH_RECONNECT_PROOF, STATUS_CONNECTED, &AuthSocket::_HandleReconnectProof },
  187. { REALM_LIST, STATUS_AUTHED, &AuthSocket::_HandleRealmList },
  188. { XFER_ACCEPT, STATUS_CONNECTED, &AuthSocket::_HandleXferAccept },
  189. { XFER_RESUME, STATUS_CONNECTED, &AuthSocket::_HandleXferResume },
  190. { XFER_CANCEL, STATUS_CONNECTED, &AuthSocket::_HandleXferCancel }
  191. };
  192.  
  193. #define AUTH_TOTAL_COMMANDS 8
  194.  
  195. // Holds the MD5 hash of client patches present on the server
  196. Patcher PatchesCache;
  197.  
  198. // Constructor - set the N and g values for SRP6
  199. AuthSocket::AuthSocket(RealmSocket& socket) : pPatch(NULL), socket_(socket)
  200. {
  201. N.SetHexStr("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7");
  202. g.SetDword(7);
  203. _authed = false;
  204. _accountSecurityLevel = SEC_PLAYER;
  205. }
  206.  
  207. // Close patch file descriptor before leaving
  208. AuthSocket::~AuthSocket(void) {}
  209.  
  210. // Accept the connection and set the s random value for SRP6
  211. void AuthSocket::OnAccept(void)
  212. {
  213. TC_LOG_DEBUG("server.authserver", "'%s:%d' Accepting connection", socket().getRemoteAddress().c_str(), socket().getRemotePort());
  214. }
  215.  
  216. void AuthSocket::OnClose(void)
  217. {
  218. TC_LOG_DEBUG("server.authserver", "AuthSocket::OnClose");
  219. }
  220.  
  221. // Read the packet from the client
  222. void AuthSocket::OnRead()
  223. {
  224. #define MAX_AUTH_LOGON_CHALLENGES_IN_A_ROW 3
  225. uint32 challengesInARow = 0;
  226. uint8 _cmd;
  227. while (1)
  228. {
  229. if (!socket().recv_soft((char *)&_cmd, 1))
  230. return;
  231.  
  232. if (_cmd == AUTH_LOGON_CHALLENGE)
  233. {
  234. ++challengesInARow;
  235. if (challengesInARow == MAX_AUTH_LOGON_CHALLENGES_IN_A_ROW)
  236. {
  237. TC_LOG_WARN("server.authserver", "Got %u AUTH_LOGON_CHALLENGE in a row from '%s', possible ongoing DoS", challengesInARow, socket().getRemoteAddress().c_str());
  238. socket().shutdown();
  239. return;
  240. }
  241. }
  242.  
  243. size_t i;
  244.  
  245. // Circle through known commands and call the correct command handler
  246. for (i = 0; i < AUTH_TOTAL_COMMANDS; ++i)
  247. {
  248. if ((uint8)table[i].cmd == _cmd && (table[i].status == STATUS_CONNECTED || (_authed && table[i].status == STATUS_AUTHED)))
  249. {
  250. TC_LOG_DEBUG("server.authserver", "Got data for cmd %u recv length %u", (uint32)_cmd, (uint32)socket().recv_len());
  251.  
  252. if (!(*this.*table[i].handler)())
  253. {
  254. TC_LOG_DEBUG("server.authserver", "Command handler failed for cmd %u recv length %u", (uint32)_cmd, (uint32)socket().recv_len());
  255. return;
  256. }
  257. break;
  258. }
  259. }
  260.  
  261. // Report unknown packets in the error log
  262. if (i == AUTH_TOTAL_COMMANDS)
  263. {
  264. TC_LOG_ERROR("server.authserver", "Got unknown packet from '%s'", socket().getRemoteAddress().c_str());
  265. socket().shutdown();
  266. return;
  267. }
  268. }
  269. }
  270.  
  271. // Make the SRP6 calculation from hash in dB
  272. void AuthSocket::_SetVSFields(const std::string& rI)
  273. {
  274. s.SetRand(s_BYTE_SIZE * 8);
  275.  
  276. BigNumber I;
  277. I.SetHexStr(rI.c_str());
  278.  
  279. // In case of leading zeros in the rI hash, restore them
  280. uint8 mDigest[SHA_DIGEST_LENGTH];
  281. memset(mDigest, 0, SHA_DIGEST_LENGTH);
  282. if (I.GetNumBytes() <= SHA_DIGEST_LENGTH)
  283. memcpy(mDigest, I.AsByteArray(), I.GetNumBytes());
  284.  
  285. std::reverse(mDigest, mDigest + SHA_DIGEST_LENGTH);
  286.  
  287. SHA1Hash sha;
  288. sha.UpdateData(s.AsByteArray(), s.GetNumBytes());
  289. sha.UpdateData(mDigest, SHA_DIGEST_LENGTH);
  290. sha.Finalize();
  291. BigNumber x;
  292. x.SetBinary(sha.GetDigest(), sha.GetLength());
  293. v = g.ModExp(x, N);
  294.  
  295. // No SQL injection (username escaped)
  296. char *v_hex, *s_hex;
  297. v_hex = v.AsHexStr();
  298. s_hex = s.AsHexStr();
  299.  
  300. PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_VS);
  301. stmt->setString(0, v_hex);
  302. stmt->setString(1, s_hex);
  303. stmt->setString(2, _login);
  304. LoginDatabase.Execute(stmt);
  305.  
  306. OPENSSL_free(v_hex);
  307. OPENSSL_free(s_hex);
  308. }
  309.  
  310. // Logon Challenge command handler
  311. bool AuthSocket::_HandleLogonChallenge()
  312. {
  313. TC_LOG_DEBUG("server.authserver", "Entering _HandleLogonChallenge");
  314. if (socket().recv_len() < sizeof(sAuthLogonChallenge_C))
  315. return false;
  316.  
  317. // Read the first 4 bytes (header) to get the length of the remaining of the packet
  318. std::vector<uint8> buf;
  319. buf.resize(4);
  320.  
  321. socket().recv((char *)&buf[0], 4);
  322.  
  323. #if TRINITY_ENDIAN == TRINITY_BIGENDIAN
  324. EndianConvert(*((uint16*)(buf[0])));
  325. #endif
  326.  
  327. uint16 remaining = ((sAuthLogonChallenge_C *)&buf[0])->size;
  328. TC_LOG_DEBUG("server.authserver", "[AuthChallenge] got header, body is %#04x bytes", remaining);
  329.  
  330. if ((remaining < sizeof(sAuthLogonChallenge_C) - buf.size()) || (socket().recv_len() < remaining))
  331. return false;
  332.  
  333. //No big fear of memory outage (size is int16, i.e. < 65536)
  334. buf.resize(remaining + buf.size() + 1);
  335. buf[buf.size() - 1] = 0;
  336. sAuthLogonChallenge_C *ch = (sAuthLogonChallenge_C*)&buf[0];
  337.  
  338. // Read the remaining of the packet
  339. socket().recv((char *)&buf[4], remaining);
  340. TC_LOG_DEBUG("server.authserver", "[AuthChallenge] got full packet, %#04x bytes", ch->size);
  341. TC_LOG_DEBUG("server.authserver", "[AuthChallenge] name(%d): '%s'", ch->I_len, ch->I);
  342.  
  343. // BigEndian code, nop in little endian case
  344. // size already converted
  345. #if TRINITY_ENDIAN == TRINITY_BIGENDIAN
  346. EndianConvert(*((uint32*)(&ch->gamename[0])));
  347. EndianConvert(ch->build);
  348. EndianConvert(*((uint32*)(&ch->platform[0])));
  349. EndianConvert(*((uint32*)(&ch->os[0])));
  350. EndianConvert(*((uint32*)(&ch->country[0])));
  351. EndianConvert(ch->timezone_bias);
  352. EndianConvert(ch->ip);
  353. #endif
  354.  
  355. ByteBuffer pkt;
  356.  
  357. _login = (const char*)ch->I;
  358. _build = ch->build;
  359. _expversion = uint8(AuthHelper::IsPostBCAcceptedClientBuild(_build) ? POST_BC_EXP_FLAG : (AuthHelper::IsPreBCAcceptedClientBuild(_build) ? PRE_BC_EXP_FLAG : NO_VALID_EXP_FLAG));
  360. _os = (const char*)ch->os;
  361.  
  362. if (_os.size() > 4)
  363. return false;
  364.  
  365. // Restore string order as its byte order is reversed
  366. std::reverse(_os.begin(), _os.end());
  367.  
  368. pkt << uint8(AUTH_LOGON_CHALLENGE);
  369. pkt << uint8(0x00);
  370.  
  371. // Verify that this IP is not in the ip_banned table
  372. LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS));
  373.  
  374. std::string const& ip_address = socket().getRemoteAddress();
  375. PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED);
  376. stmt->setString(0, ip_address);
  377. PreparedQueryResult result = LoginDatabase.Query(stmt);
  378. if (result)
  379. {
  380. pkt << uint8(WOW_FAIL_BANNED);
  381. TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] Banned ip tries to login!", socket().getRemoteAddress().c_str(), socket().getRemotePort());
  382. }
  383. else
  384. {
  385. // Get the account details from the account table
  386. // No SQL injection (prepared statement)
  387. stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_LOGONCHALLENGE);
  388. stmt->setString(0, _login);
  389.  
  390. PreparedQueryResult res2 = LoginDatabase.Query(stmt);
  391. if (res2)
  392. {
  393. Field* fields = res2->Fetch();
  394.  
  395. // If the IP is 'locked', check that the player comes indeed from the correct IP address
  396. bool locked = false;
  397. if (fields[2].GetUInt8() == 1) // if ip is locked
  398. {
  399. TC_LOG_DEBUG("server.authserver", "[AuthChallenge] Account '%s' is locked to IP - '%s'", _login.c_str(), fields[3].GetCString());
  400. TC_LOG_DEBUG("server.authserver", "[AuthChallenge] Player address is '%s'", ip_address.c_str());
  401.  
  402. if (strcmp(fields[3].GetCString(), ip_address.c_str()))
  403. {
  404. TC_LOG_DEBUG("server.authserver", "[AuthChallenge] Account IP differs");
  405. pkt << (uint8) WOW_FAIL_SUSPENDED;
  406. locked = true;
  407. }
  408. else
  409. TC_LOG_DEBUG("server.authserver", "[AuthChallenge] Account IP matches");
  410. }
  411. else
  412. TC_LOG_DEBUG("server.authserver", "[AuthChallenge] Account '%s' is not locked to ip", _login.c_str());
  413.  
  414. if (!locked)
  415. {
  416. //set expired bans to inactive
  417. LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_UPD_EXPIRED_ACCOUNT_BANS));
  418.  
  419. // If the account is banned, reject the logon attempt
  420. stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BANNED);
  421. stmt->setUInt32(0, fields[1].GetUInt32());
  422. PreparedQueryResult banresult = LoginDatabase.Query(stmt);
  423. if (banresult)
  424. {
  425. if ((*banresult)[0].GetUInt32() == (*banresult)[1].GetUInt32())
  426. {
  427. pkt << uint8(WOW_FAIL_BANNED);
  428. TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] Banned account %s tried to login!", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str ());
  429. }
  430. else
  431. {
  432. pkt << uint8(WOW_FAIL_SUSPENDED);
  433. TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] Temporarily banned account %s tried to login!", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str ());
  434. }
  435. }
  436. else
  437. {
  438. // Get the password from the account table, upper it, and make the SRP6 calculation
  439. std::string rI = fields[0].GetString();
  440.  
  441. // Don't calculate (v, s) if there are already some in the database
  442. std::string databaseV = fields[5].GetString();
  443. std::string databaseS = fields[6].GetString();
  444.  
  445. TC_LOG_DEBUG("network.opcode", "database authentication values: v='%s' s='%s'", databaseV.c_str(), databaseS.c_str());
  446.  
  447. // multiply with 2 since bytes are stored as hexstring
  448. if (databaseV.size() != s_BYTE_SIZE * 2 || databaseS.size() != s_BYTE_SIZE * 2)
  449. _SetVSFields(rI);
  450. else
  451. {
  452. s.SetHexStr(databaseS.c_str());
  453. v.SetHexStr(databaseV.c_str());
  454. }
  455.  
  456. b.SetRand(19 * 8);
  457. BigNumber gmod = g.ModExp(b, N);
  458. B = ((v * 3) + gmod) % N;
  459.  
  460. ASSERT(gmod.GetNumBytes() <= 32);
  461.  
  462. BigNumber unk3;
  463. unk3.SetRand(16 * 8);
  464.  
  465. // Fill the response packet with the result
  466. if (AuthHelper::IsAcceptedClientBuild(_build))
  467. pkt << uint8(WOW_SUCCESS);
  468. else
  469. pkt << uint8(WOW_FAIL_VERSION_INVALID);
  470.  
  471. // B may be calculated < 32B so we force minimal length to 32B
  472. pkt.append(B.AsByteArray(32), 32); // 32 bytes
  473. pkt << uint8(1);
  474. pkt.append(g.AsByteArray(), 1);
  475. pkt << uint8(32);
  476. pkt.append(N.AsByteArray(32), 32);
  477. pkt.append(s.AsByteArray(), s.GetNumBytes()); // 32 bytes
  478. pkt.append(unk3.AsByteArray(16), 16);
  479. uint8 securityFlags = 0;
  480. pkt << uint8(securityFlags); // security flags (0x0...0x04)
  481.  
  482. if (securityFlags & 0x01) // PIN input
  483. {
  484. pkt << uint32(0);
  485. pkt << uint64(0) << uint64(0); // 16 bytes hash?
  486. }
  487.  
  488. if (securityFlags & 0x02) // Matrix input
  489. {
  490. pkt << uint8(0);
  491. pkt << uint8(0);
  492. pkt << uint8(0);
  493. pkt << uint8(0);
  494. pkt << uint64(0);
  495. }
  496.  
  497. if (securityFlags & 0x04) // Security token input
  498. pkt << uint8(1);
  499.  
  500. uint8 secLevel = fields[4].GetUInt8();
  501. _accountSecurityLevel = secLevel <= SEC_ADMINISTRATOR ? AccountTypes(secLevel) : SEC_ADMINISTRATOR;
  502.  
  503. _localizationName.resize(4);
  504. for (int i = 0; i < 4; ++i)
  505. _localizationName[i] = ch->country[4-i-1];
  506.  
  507. TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] account %s is using '%c%c%c%c' locale (%u)", socket().getRemoteAddress().c_str(), socket().getRemotePort(),
  508. _login.c_str (), ch->country[3], ch->country[2], ch->country[1], ch->country[0], GetLocaleByName(_localizationName)
  509. );
  510. }
  511. }
  512. }
  513. else //no account
  514. pkt << (uint8)WOW_FAIL_UNKNOWN_ACCOUNT;
  515. }
  516.  
  517. socket().send((char const*)pkt.contents(), pkt.size());
  518. return true;
  519. }
  520.  
  521. // Logon Proof command handler
  522. bool AuthSocket::_HandleLogonProof()
  523. {
  524. TC_LOG_DEBUG("server.authserver", "Entering _HandleLogonProof");
  525. // Read the packet
  526. sAuthLogonProof_C lp;
  527.  
  528. if (!socket().recv((char *)&lp, sizeof(sAuthLogonProof_C)))
  529. return false;
  530.  
  531. // If the client has no valid version
  532. if (_expversion == NO_VALID_EXP_FLAG)
  533. {
  534. // Check if we have the appropriate patch on the disk
  535. TC_LOG_DEBUG("network.opcode", "Client with invalid version, patching is not implemented");
  536. socket().shutdown();
  537. return true;
  538. }
  539.  
  540. // Continue the SRP6 calculation based on data received from the client
  541. BigNumber A;
  542.  
  543. A.SetBinary(lp.A, 32);
  544.  
  545. // SRP safeguard: abort if A == 0
  546. if ((A % N).isZero())
  547. {
  548. socket().shutdown();
  549. return true;
  550. }
  551.  
  552. SHA1Hash sha;
  553. sha.UpdateBigNumbers(&A, &B, NULL);
  554. sha.Finalize();
  555. BigNumber u;
  556. u.SetBinary(sha.GetDigest(), 20);
  557. BigNumber S = (A * (v.ModExp(u, N))).ModExp(b, N);
  558.  
  559. uint8 t[32];
  560. uint8 t1[16];
  561. uint8 vK[40];
  562. memcpy(t, S.AsByteArray(32), 32);
  563.  
  564. for (int i = 0; i < 16; ++i)
  565. t1[i] = t[i * 2];
  566.  
  567. sha.Initialize();
  568. sha.UpdateData(t1, 16);
  569. sha.Finalize();
  570.  
  571. for (int i = 0; i < 20; ++i)
  572. vK[i * 2] = sha.GetDigest()[i];
  573.  
  574. for (int i = 0; i < 16; ++i)
  575. t1[i] = t[i * 2 + 1];
  576.  
  577. sha.Initialize();
  578. sha.UpdateData(t1, 16);
  579. sha.Finalize();
  580.  
  581. for (int i = 0; i < 20; ++i)
  582. vK[i * 2 + 1] = sha.GetDigest()[i];
  583.  
  584. K.SetBinary(vK, 40);
  585.  
  586. uint8 hash[20];
  587.  
  588. sha.Initialize();
  589. sha.UpdateBigNumbers(&N, NULL);
  590. sha.Finalize();
  591. memcpy(hash, sha.GetDigest(), 20);
  592. sha.Initialize();
  593. sha.UpdateBigNumbers(&g, NULL);
  594. sha.Finalize();
  595.  
  596. for (int i = 0; i < 20; ++i)
  597. hash[i] ^= sha.GetDigest()[i];
  598.  
  599. BigNumber t3;
  600. t3.SetBinary(hash, 20);
  601.  
  602. sha.Initialize();
  603. sha.UpdateData(_login);
  604. sha.Finalize();
  605. uint8 t4[SHA_DIGEST_LENGTH];
  606. memcpy(t4, sha.GetDigest(), SHA_DIGEST_LENGTH);
  607.  
  608. sha.Initialize();
  609. sha.UpdateBigNumbers(&t3, NULL);
  610. sha.UpdateData(t4, SHA_DIGEST_LENGTH);
  611. sha.UpdateBigNumbers(&s, &A, &B, &K, NULL);
  612. sha.Finalize();
  613. BigNumber M;
  614. M.SetBinary(sha.GetDigest(), 20);
  615.  
  616. // Check if SRP6 results match (password is correct), else send an error
  617. if (!memcmp(M.AsByteArray(), lp.M1, 20))
  618. {
  619. TC_LOG_DEBUG("server.authserver", "'%s:%d' User '%s' successfully authenticated", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str());
  620.  
  621. // Update the sessionkey, last_ip, last login time and reset number of failed logins in the account table for this account
  622. // No SQL injection (escaped user name) and IP address as received by socket
  623. const char *K_hex = K.AsHexStr();
  624.  
  625. PreparedStatement *stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LOGONPROOF);
  626. stmt->setString(0, K_hex);
  627. stmt->setString(1, socket().getRemoteAddress().c_str());
  628. stmt->setUInt32(2, GetLocaleByName(_localizationName));
  629. stmt->setString(3, _os);
  630. stmt->setString(4, _login);
  631. LoginDatabase.Execute(stmt);
  632.  
  633. OPENSSL_free((void*)K_hex);
  634.  
  635. // Finish SRP6 and send the final result to the client
  636. sha.Initialize();
  637. sha.UpdateBigNumbers(&A, &M, &K, NULL);
  638. sha.Finalize();
  639.  
  640. if (_expversion & POST_BC_EXP_FLAG) // 2.x and 3.x clients
  641. {
  642. sAuthLogonProof_S proof;
  643. memcpy(proof.M2, sha.GetDigest(), 20);
  644. proof.cmd = AUTH_LOGON_PROOF;
  645. proof.error = 0;
  646. proof.unk1 = 0x00800000; // Accountflags. 0x01 = GM, 0x08 = Trial, 0x00800000 = Pro pass (arena tournament)
  647. proof.unk2 = 0x00; // SurveyId
  648. proof.unk3 = 0x00;
  649. socket().send((char *)&proof, sizeof(proof));
  650. }
  651. else
  652. {
  653. sAuthLogonProof_S_Old proof;
  654. memcpy(proof.M2, sha.GetDigest(), 20);
  655. proof.cmd = AUTH_LOGON_PROOF;
  656. proof.error = 0;
  657. proof.unk2 = 0x00;
  658. socket().send((char *)&proof, sizeof(proof));
  659. }
  660.  
  661. _authed = true;
  662. }
  663. else
  664. {
  665. char data[4] = { AUTH_LOGON_PROOF, WOW_FAIL_UNKNOWN_ACCOUNT, 3, 0 };
  666. socket().send(data, sizeof(data));
  667.  
  668. TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] account %s tried to login with invalid password!", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str ());
  669.  
  670. uint32 MaxWrongPassCount = sConfigMgr->GetIntDefault("WrongPass.MaxCount", 0);
  671. if (MaxWrongPassCount > 0)
  672. {
  673. //Increment number of failed logins by one and if it reaches the limit temporarily ban that account or IP
  674. PreparedStatement *stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_FAILEDLOGINS);
  675. stmt->setString(0, _login);
  676. LoginDatabase.Execute(stmt);
  677.  
  678. stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_FAILEDLOGINS);
  679. stmt->setString(0, _login);
  680.  
  681. if (PreparedQueryResult loginfail = LoginDatabase.Query(stmt))
  682. {
  683. uint32 failed_logins = (*loginfail)[1].GetUInt32();
  684.  
  685. if (failed_logins >= MaxWrongPassCount)
  686. {
  687. uint32 WrongPassBanTime = sConfigMgr->GetIntDefault("WrongPass.BanTime", 600);
  688. bool WrongPassBanType = sConfigMgr->GetBoolDefault("WrongPass.BanType", false);
  689.  
  690. if (WrongPassBanType)
  691. {
  692. uint32 acc_id = (*loginfail)[0].GetUInt32();
  693. stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_AUTO_BANNED);
  694. stmt->setUInt32(0, acc_id);
  695. stmt->setUInt32(1, WrongPassBanTime);
  696. LoginDatabase.Execute(stmt);
  697.  
  698. TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] account %s got banned for '%u' seconds because it failed to authenticate '%u' times",
  699. socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str(), WrongPassBanTime, failed_logins);
  700. }
  701. else
  702. {
  703. stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_IP_AUTO_BANNED);
  704. stmt->setString(0, socket().getRemoteAddress());
  705. stmt->setUInt32(1, WrongPassBanTime);
  706. LoginDatabase.Execute(stmt);
  707.  
  708. TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] IP %s got banned for '%u' seconds because account %s failed to authenticate '%u' times",
  709. socket().getRemoteAddress().c_str(), socket().getRemotePort(), socket().getRemoteAddress().c_str(), WrongPassBanTime, _login.c_str(), failed_logins);
  710. }
  711. }
  712. }
  713. }
  714. }
  715.  
  716. return true;
  717. }
  718.  
  719. // Reconnect Challenge command handler
  720. bool AuthSocket::_HandleReconnectChallenge()
  721. {
  722. TC_LOG_DEBUG("server.authserver", "Entering _HandleReconnectChallenge");
  723. if (socket().recv_len() < sizeof(sAuthLogonChallenge_C))
  724. return false;
  725.  
  726. // Read the first 4 bytes (header) to get the length of the remaining of the packet
  727. std::vector<uint8> buf;
  728. buf.resize(4);
  729.  
  730. socket().recv((char *)&buf[0], 4);
  731.  
  732. #if TRINITY_ENDIAN == TRINITY_BIGENDIAN
  733. EndianConvert(*((uint16*)(buf[0])));
  734. #endif
  735.  
  736. uint16 remaining = ((sAuthLogonChallenge_C *)&buf[0])->size;
  737. TC_LOG_DEBUG("server.authserver", "[ReconnectChallenge] got header, body is %#04x bytes", remaining);
  738.  
  739. if ((remaining < sizeof(sAuthLogonChallenge_C) - buf.size()) || (socket().recv_len() < remaining))
  740. return false;
  741.  
  742. // No big fear of memory outage (size is int16, i.e. < 65536)
  743. buf.resize(remaining + buf.size() + 1);
  744. buf[buf.size() - 1] = 0;
  745. sAuthLogonChallenge_C *ch = (sAuthLogonChallenge_C*)&buf[0];
  746.  
  747. // Read the remaining of the packet
  748. socket().recv((char *)&buf[4], remaining);
  749. TC_LOG_DEBUG("server.authserver", "[ReconnectChallenge] got full packet, %#04x bytes", ch->size);
  750. TC_LOG_DEBUG("server.authserver", "[ReconnectChallenge] name(%d): '%s'", ch->I_len, ch->I);
  751.  
  752. _login = (const char*)ch->I;
  753.  
  754. PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_SESSIONKEY);
  755. stmt->setString(0, _login);
  756. PreparedQueryResult result = LoginDatabase.Query(stmt);
  757.  
  758. // Stop if the account is not found
  759. if (!result)
  760. {
  761. TC_LOG_ERROR("server.authserver", "'%s:%d' [ERROR] user %s tried to login and we cannot find his session key in the database.", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str());
  762. socket().shutdown();
  763. return false;
  764. }
  765.  
  766. // Reinitialize build, expansion and the account securitylevel
  767. _build = ch->build;
  768. _expversion = uint8(AuthHelper::IsPostBCAcceptedClientBuild(_build) ? POST_BC_EXP_FLAG : (AuthHelper::IsPreBCAcceptedClientBuild(_build) ? PRE_BC_EXP_FLAG : NO_VALID_EXP_FLAG));
  769. _os = (const char*)ch->os;
  770.  
  771. if (_os.size() > 4)
  772. return false;
  773.  
  774. // Restore string order as its byte order is reversed
  775. std::reverse(_os.begin(), _os.end());
  776.  
  777. Field* fields = result->Fetch();
  778. uint8 secLevel = fields[2].GetUInt8();
  779. _accountSecurityLevel = secLevel <= SEC_ADMINISTRATOR ? AccountTypes(secLevel) : SEC_ADMINISTRATOR;
  780.  
  781. K.SetHexStr ((*result)[0].GetCString());
  782.  
  783. // Sending response
  784. ByteBuffer pkt;
  785. pkt << uint8(AUTH_RECONNECT_CHALLENGE);
  786. pkt << uint8(0x00);
  787. _reconnectProof.SetRand(16 * 8);
  788. pkt.append(_reconnectProof.AsByteArray(16), 16); // 16 bytes random
  789. pkt << uint64(0x00) << uint64(0x00); // 16 bytes zeros
  790. socket().send((char const*)pkt.contents(), pkt.size());
  791. return true;
  792. }
  793.  
  794. // Reconnect Proof command handler
  795. bool AuthSocket::_HandleReconnectProof()
  796. {
  797. TC_LOG_DEBUG("server.authserver", "Entering _HandleReconnectProof");
  798. // Read the packet
  799. sAuthReconnectProof_C lp;
  800. if (!socket().recv((char *)&lp, sizeof(sAuthReconnectProof_C)))
  801. return false;
  802.  
  803. if (_login.empty() || !_reconnectProof.GetNumBytes() || !K.GetNumBytes())
  804. return false;
  805.  
  806. BigNumber t1;
  807. t1.SetBinary(lp.R1, 16);
  808.  
  809. SHA1Hash sha;
  810. sha.Initialize();
  811. sha.UpdateData(_login);
  812. sha.UpdateBigNumbers(&t1, &_reconnectProof, &K, NULL);
  813. sha.Finalize();
  814.  
  815. if (!memcmp(sha.GetDigest(), lp.R2, SHA_DIGEST_LENGTH))
  816. {
  817. // Sending response
  818. ByteBuffer pkt;
  819. pkt << uint8(AUTH_RECONNECT_PROOF);
  820. pkt << uint8(0x00);
  821. pkt << uint16(0x00); // 2 bytes zeros
  822. socket().send((char const*)pkt.contents(), pkt.size());
  823. _authed = true;
  824. return true;
  825. }
  826. else
  827. {
  828. TC_LOG_ERROR("server.authserver", "'%s:%d' [ERROR] user %s tried to login, but session is invalid.", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str());
  829. socket().shutdown();
  830. return false;
  831. }
  832. }
  833.  
  834. ACE_INET_Addr const& AuthSocket::GetAddressForClient(Realm const& realm, ACE_INET_Addr const& clientAddr)
  835. {
  836. // Attempt to send best address for client
  837. if (clientAddr.is_loopback())
  838. {
  839. // Try guessing if realm is also connected locally
  840. if (realm.LocalAddress.is_loopback() || realm.ExternalAddress.is_loopback())
  841. return clientAddr;
  842.  
  843. // Assume that user connecting from the machine that authserver is located on
  844. // has all realms available in his local network
  845. return realm.LocalAddress;
  846. }
  847.  
  848. // Check if connecting client is in the same network
  849. if (IsIPAddrInNetwork(realm.LocalAddress, clientAddr, realm.LocalSubnetMask))
  850. return realm.LocalAddress;
  851.  
  852. // Return external IP
  853. return realm.ExternalAddress;
  854. }
  855.  
  856. // Realm List command handler
  857. bool AuthSocket::_HandleRealmList()
  858. {
  859. TC_LOG_DEBUG("server.authserver", "Entering _HandleRealmList");
  860. if (socket().recv_len() < 5)
  861. return false;
  862.  
  863. socket().recv_skip(5);
  864.  
  865. // Get the user id (else close the connection)
  866. // No SQL injection (prepared statement)
  867. PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_ID_BY_NAME);
  868. stmt->setString(0, _login);
  869. PreparedQueryResult result = LoginDatabase.Query(stmt);
  870. if (!result)
  871. {
  872. TC_LOG_ERROR("server.authserver", "'%s:%d' [ERROR] user %s tried to login but we cannot find him in the database.", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str());
  873. socket().shutdown();
  874. return false;
  875. }
  876.  
  877. Field* fields = result->Fetch();
  878. uint32 id = fields[0].GetUInt32();
  879.  
  880. // Update realm list if need
  881. sRealmList->UpdateIfNeed();
  882.  
  883. ACE_INET_Addr clientAddr;
  884. socket().peer().get_remote_addr(clientAddr);
  885.  
  886. // Circle through realms in the RealmList and construct the return packet (including # of user characters in each realm)
  887. ByteBuffer pkt;
  888.  
  889. size_t RealmListSize = 0;
  890. for (RealmList::RealmMap::const_iterator i = sRealmList->begin(); i != sRealmList->end(); ++i)
  891. {
  892. // don't work with realms which not compatible with the client
  893. bool okBuild = ((_expversion & POST_BC_EXP_FLAG) && i->second.gamebuild == _build) || ((_expversion & PRE_BC_EXP_FLAG) && !AuthHelper::IsPreBCAcceptedClientBuild(i->second.gamebuild));
  894.  
  895. // No SQL injection. id of realm is controlled by the database.
  896. uint32 flag = i->second.flag;
  897. RealmBuildInfo const* buildInfo = AuthHelper::GetBuildInfo(i->second.gamebuild);
  898. if (!okBuild)
  899. {
  900. if (!buildInfo)
  901. continue;
  902.  
  903. flag |= REALM_FLAG_OFFLINE | REALM_FLAG_SPECIFYBUILD; // tell the client what build the realm is for
  904. }
  905.  
  906. if (!buildInfo)
  907. flag &= ~REALM_FLAG_SPECIFYBUILD;
  908.  
  909. std::string name = i->first;
  910. if (_expversion & PRE_BC_EXP_FLAG && flag & REALM_FLAG_SPECIFYBUILD)
  911. {
  912. std::ostringstream ss;
  913. ss << name << " (" << buildInfo->MajorVersion << '.' << buildInfo->MinorVersion << '.' << buildInfo->BugfixVersion << ')';
  914. name = ss.str();
  915. }
  916.  
  917. // We don't need the port number from which client connects with but the realm's port
  918. clientAddr.set_port_number(i->second.ExternalAddress.get_port_number());
  919.  
  920. uint8 lock = (i->second.allowedSecurityLevel > _accountSecurityLevel) ? 1 : 0;
  921.  
  922. uint8 AmountOfCharacters = 0;
  923. stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_NUM_CHARS_ON_REALM);
  924. stmt->setUInt32(0, i->second.m_ID);
  925. stmt->setUInt32(1, id);
  926. result = LoginDatabase.Query(stmt);
  927. if (result)
  928. AmountOfCharacters = (*result)[0].GetUInt8();
  929.  
  930. pkt << i->second.icon; // realm type
  931. if (_expversion & POST_BC_EXP_FLAG) // only 2.x and 3.x clients
  932. pkt << lock; // if 1, then realm locked
  933. pkt << uint8(flag); // RealmFlags
  934. pkt << name;
  935. pkt << GetAddressString(GetAddressForClient(i->second, clientAddr));
  936. pkt << i->second.populationLevel;
  937. pkt << AmountOfCharacters;
  938. pkt << i->second.timezone; // realm category
  939. if (_expversion & POST_BC_EXP_FLAG) // 2.x and 3.x clients
  940. pkt << uint8(0x2C); // unk, may be realm number/id?
  941. else
  942. pkt << uint8(0x0); // 1.12.1 and 1.12.2 clients
  943.  
  944. if (_expversion & POST_BC_EXP_FLAG && flag & REALM_FLAG_SPECIFYBUILD)
  945. {
  946. pkt << uint8(buildInfo->MajorVersion);
  947. pkt << uint8(buildInfo->MinorVersion);
  948. pkt << uint8(buildInfo->BugfixVersion);
  949. pkt << uint16(buildInfo->Build);
  950. }
  951.  
  952. ++RealmListSize;
  953. }
  954.  
  955. if (_expversion & POST_BC_EXP_FLAG) // 2.x and 3.x clients
  956. {
  957. pkt << uint8(0x10);
  958. pkt << uint8(0x00);
  959. }
  960. else // 1.12.1 and 1.12.2 clients
  961. {
  962. pkt << uint8(0x00);
  963. pkt << uint8(0x02);
  964. }
  965.  
  966. // make a ByteBuffer which stores the RealmList's size
  967. ByteBuffer RealmListSizeBuffer;
  968. RealmListSizeBuffer << uint32(0);
  969. if (_expversion & POST_BC_EXP_FLAG) // only 2.x and 3.x clients
  970. RealmListSizeBuffer << uint16(RealmListSize);
  971. else
  972. RealmListSizeBuffer << uint32(RealmListSize);
  973.  
  974. ByteBuffer hdr;
  975. hdr << uint8(REALM_LIST);
  976. hdr << uint16(pkt.size() + RealmListSizeBuffer.size());
  977. hdr.append(RealmListSizeBuffer); // append RealmList's size buffer
  978. hdr.append(pkt); // append realms in the realmlist
  979.  
  980. socket().send((char const*)hdr.contents(), hdr.size());
  981.  
  982. return true;
  983. }
  984.  
  985. // Resume patch transfer
  986. bool AuthSocket::_HandleXferResume()
  987. {
  988. TC_LOG_DEBUG("server.authserver", "Entering _HandleXferResume");
  989. // Check packet length and patch existence
  990. if (socket().recv_len() < 9 || !pPatch) // FIXME: pPatch is never used
  991. {
  992. TC_LOG_ERROR("server.authserver", "Error while resuming patch transfer (wrong packet)");
  993. return false;
  994. }
  995.  
  996. // Launch a PatcherRunnable thread starting at given patch file offset
  997. uint64 start;
  998. socket().recv_skip(1);
  999. socket().recv((char*)&start, sizeof(start));
  1000. fseek(pPatch, long(start), 0);
  1001.  
  1002. ACE_Based::Thread u(new PatcherRunnable(this));
  1003. return true;
  1004. }
  1005.  
  1006. // Cancel patch transfer
  1007. bool AuthSocket::_HandleXferCancel()
  1008. {
  1009. TC_LOG_DEBUG("server.authserver", "Entering _HandleXferCancel");
  1010.  
  1011. // Close and delete the socket
  1012. socket().recv_skip(1); //clear input buffer
  1013. socket().shutdown();
  1014.  
  1015. return true;
  1016. }
  1017.  
  1018. // Accept patch transfer
  1019. bool AuthSocket::_HandleXferAccept()
  1020. {
  1021. TC_LOG_DEBUG("server.authserver", "Entering _HandleXferAccept");
  1022.  
  1023. // Check packet length and patch existence
  1024. if (!pPatch)
  1025. {
  1026. TC_LOG_ERROR("server.authserver", "Error while accepting patch transfer (wrong packet)");
  1027. return false;
  1028. }
  1029.  
  1030. // Launch a PatcherRunnable thread, starting at the beginning of the patch file
  1031. socket().recv_skip(1); // clear input buffer
  1032. fseek(pPatch, 0, 0);
  1033.  
  1034. ACE_Based::Thread u(new PatcherRunnable(this));
  1035. return true;
  1036. }
  1037.  
  1038. PatcherRunnable::PatcherRunnable(class AuthSocket* as)
  1039. {
  1040. mySocket = as;
  1041. }
  1042.  
  1043. // Send content of patch file to the client
  1044. void PatcherRunnable::run()
  1045. {
  1046. }
  1047.  
  1048. // Preload MD5 hashes of existing patch files on server
  1049. #ifndef _WIN32
  1050. #include <dirent.h>
  1051. #include <errno.h>
  1052. void Patcher::LoadPatchesInfo()
  1053. {
  1054. DIR *dirp;
  1055. struct dirent *dp;
  1056. dirp = opendir("./patches/");
  1057.  
  1058. if (!dirp)
  1059. return;
  1060.  
  1061. while (dirp)
  1062. {
  1063. errno = 0;
  1064. if ((dp = readdir(dirp)) != NULL)
  1065. {
  1066. int l = strlen(dp->d_name);
  1067.  
  1068. if (l < 8)
  1069. continue;
  1070.  
  1071. if (!memcmp(&dp->d_name[l - 4], ".mpq", 4))
  1072. LoadPatchMD5(dp->d_name);
  1073. }
  1074. else
  1075. {
  1076. if (errno != 0)
  1077. {
  1078. closedir(dirp);
  1079. return;
  1080. }
  1081. break;
  1082. }
  1083. }
  1084.  
  1085. if (dirp)
  1086. closedir(dirp);
  1087. }
  1088. #else
  1089. void Patcher::LoadPatchesInfo()
  1090. {
  1091. WIN32_FIND_DATA fil;
  1092. HANDLE hFil = FindFirstFile("./patches/*.mpq", &fil);
  1093. if (hFil == INVALID_HANDLE_VALUE)
  1094. return; // no patches were found
  1095.  
  1096. do
  1097. LoadPatchMD5(fil.cFileName);
  1098. while (FindNextFile(hFil, &fil));
  1099. }
  1100. #endif
  1101.  
  1102. // Calculate and store MD5 hash for a given patch file
  1103. void Patcher::LoadPatchMD5(char *szFileName)
  1104. {
  1105. // Try to open the patch file
  1106. std::string path = "./patches/";
  1107. path += szFileName;
  1108. FILE* pPatch = fopen(path.c_str(), "rb");
  1109. TC_LOG_DEBUG("network.opcode", "Loading patch info from %s\n", path.c_str());
  1110.  
  1111. if (!pPatch)
  1112. {
  1113. TC_LOG_ERROR("server.authserver", "Error loading patch %s\n", path.c_str());
  1114. return;
  1115. }
  1116.  
  1117. // Calculate the MD5 hash
  1118. MD5_CTX ctx;
  1119. MD5_Init(&ctx);
  1120. uint8* buf = new uint8[512 * 1024];
  1121.  
  1122. while (!feof(pPatch))
  1123. {
  1124. size_t read = fread(buf, 1, 512 * 1024, pPatch);
  1125. MD5_Update(&ctx, buf, read);
  1126. }
  1127.  
  1128. delete [] buf;
  1129. fclose(pPatch);
  1130.  
  1131. // Store the result in the internal patch hash map
  1132. _patches[path] = new PATCH_INFO;
  1133. MD5_Final((uint8 *)&_patches[path]->md5, &ctx);
  1134. }
  1135.  
  1136. // Get cached MD5 hash for a given patch file
  1137. bool Patcher::GetHash(char * pat, uint8 mymd5[16])
  1138. {
  1139. for (Patches::iterator i = _patches.begin(); i != _patches.end(); ++i)
  1140. if (!stricmp(pat, i->first.c_str()))
  1141. {
  1142. memcpy(mymd5, i->second->md5, 16);
  1143. return true;
  1144. }
  1145.  
  1146. return false;
  1147. }
  1148.  
  1149. // Launch the patch hashing mechanism on object creation
  1150. Patcher::Patcher()
  1151. {
  1152. LoadPatchesInfo();
  1153. }
  1154.  
  1155. // Empty and delete the patch map on termination
  1156. Patcher::~Patcher()
  1157. {
  1158. for (Patches::iterator i = _patches.begin(); i != _patches.end(); ++i)
  1159. delete i->second;
  1160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement