Merge branch 'battle.net' into 4.3.4

This commit is contained in:
Shauren committed 2014-06-08 16:14:24 +02:00
commit 7dd552c826
63 files changed
+4346 -259

No files matched your search

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PacketCrypt.h"
PacketCrypt::PacketCrypt(uint32 rc4InitSize)
: _clientDecrypt(rc4InitSize), _serverEncrypt(rc4InitSize), _initialized(false)
{
}
void PacketCrypt::DecryptRecv(uint8* data, size_t len)
{
if (!_initialized)
return;
_clientDecrypt.UpdateData(len, data);
}
void PacketCrypt::EncryptSend(uint8* data, size_t len)
{
if (!_initialized)
return;
_serverEncrypt.UpdateData(len, data);
}
@@ -1,6 +1,5 @@
/*
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -16,27 +15,29 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AUTHCRYPT_H
#define _AUTHCRYPT_H
#ifndef _PACKETCRYPT_H
#define _PACKETCRYPT_H
#include "Cryptography/ARC4.h"
class BigNumber;
class AuthCrypt
class PacketCrypt
{
public:
AuthCrypt();
PacketCrypt(uint32 rc4InitSize);
virtual ~PacketCrypt() { }
void Init(BigNumber* K);
void DecryptRecv(uint8 *, size_t);
void EncryptSend(uint8 *, size_t);
virtual void Init(BigNumber* K) = 0;
void DecryptRecv(uint8* data, size_t length);
void EncryptSend(uint8* data, size_t length);
bool IsInitialized() const { return _initialized; }
private:
protected:
ARC4 _clientDecrypt;
ARC4 _serverEncrypt;
bool _initialized;
};
#endif
#endif // _PACKETCRYPT_H
@@ -16,58 +16,36 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AuthCrypt.h"
#include "Cryptography/HMACSHA1.h"
#include "WorldPacketCrypt.h"
#include "Cryptography/HmacHash.h"
#include "Cryptography/BigNumber.h"
AuthCrypt::AuthCrypt() :
_clientDecrypt(SHA_DIGEST_LENGTH), _serverEncrypt(SHA_DIGEST_LENGTH),
_initialized(false)
{ }
WorldPacketCrypt::WorldPacketCrypt() : PacketCrypt(SHA_DIGEST_LENGTH)
{
}
void AuthCrypt::Init(BigNumber* K)
void WorldPacketCrypt::Init(BigNumber* K)
{
uint8 ServerEncryptionKey[SEED_KEY_SIZE] = { 0xCC, 0x98, 0xAE, 0x04, 0xE8, 0x97, 0xEA, 0xCA, 0x12, 0xDD, 0xC0, 0x93, 0x42, 0x91, 0x53, 0x57 };
HmacHash serverEncryptHmac(SEED_KEY_SIZE, (uint8*)ServerEncryptionKey);
HmacSha1 serverEncryptHmac(SEED_KEY_SIZE, (uint8*)ServerEncryptionKey);
uint8 *encryptHash = serverEncryptHmac.ComputeHash(K);
uint8 ServerDecryptionKey[SEED_KEY_SIZE] = { 0xC2, 0xB3, 0x72, 0x3C, 0xC6, 0xAE, 0xD9, 0xB5, 0x34, 0x3C, 0x53, 0xEE, 0x2F, 0x43, 0x67, 0xCE };
HmacHash clientDecryptHmac(SEED_KEY_SIZE, (uint8*)ServerDecryptionKey);
HmacSha1 clientDecryptHmac(SEED_KEY_SIZE, (uint8*)ServerDecryptionKey);
uint8 *decryptHash = clientDecryptHmac.ComputeHash(K);
//ARC4 _serverDecrypt(encryptHash);
_clientDecrypt.Init(decryptHash);
_serverEncrypt.Init(encryptHash);
//ARC4 _clientEncrypt(decryptHash);
// Drop first 1024 bytes, as WoW uses ARC4-drop1024.
uint8 syncBuf[1024];
memset(syncBuf, 0, 1024);
_serverEncrypt.UpdateData(1024, syncBuf);
//_clientEncrypt.UpdateData(1024, syncBuf);
memset(syncBuf, 0, 1024);
//_serverDecrypt.UpdateData(1024, syncBuf);
_clientDecrypt.UpdateData(1024, syncBuf);
_initialized = true;
}
void AuthCrypt::DecryptRecv(uint8 *data, size_t len)
{
if (!_initialized)
return;
_clientDecrypt.UpdateData(len, data);
}
void AuthCrypt::EncryptSend(uint8 *data, size_t len)
{
if (!_initialized)
return;
_serverEncrypt.UpdateData(len, data);
}
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _WORLDPACKETCRYPT_H
#define _WORLDPACKETCRYPT_H
#include "PacketCrypt.h"
class BigNumber;
class WorldPacketCrypt : public PacketCrypt
{
public:
WorldPacketCrypt();
void Init(BigNumber* K) override;
};
#endif // _WORLDPACKETCRYPT_H
+10 -4
View File
@@ -190,13 +190,19 @@ ACE_Auto_Array_Ptr<uint8> BigNumber::AsByteArray(int32 minSize, bool littleEndia
return ret;
}
char * BigNumber::AsHexStr() const
std::string BigNumber::AsHexStr() const
{
return BN_bn2hex(_bn);
char* ch = BN_bn2hex(_bn);
std::string ret = ch;
OPENSSL_free(ch);
return ret;
}
char * BigNumber::AsDecStr() const
std::string BigNumber::AsDecStr() const
{
return BN_bn2dec(_bn);
char* ch = BN_bn2dec(_bn);
std::string ret = ch;
OPENSSL_free(ch);
return ret;
}
+3 -2
View File
@@ -21,6 +21,7 @@
#include "Define.h"
#include <ace/Auto_Ptr.h>
#include <string>
struct bignum_st;
@@ -89,8 +90,8 @@ class BigNumber
ACE_Auto_Array_Ptr<uint8> AsByteArray(int32 minSize = 0, bool littleEndian = true);
char * AsHexStr() const;
char * AsDecStr() const;
std::string AsHexStr() const;
std::string AsDecStr() const;
private:
struct bignum_st *_bn;
@@ -1,57 +0,0 @@
/*
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "HMACSHA1.h"
#include "BigNumber.h"
#include "Common.h"
HmacHash::HmacHash(uint32 len, uint8 *seed)
{
HMAC_CTX_init(&m_ctx);
HMAC_Init_ex(&m_ctx, seed, len, EVP_sha1(), NULL);
memset(m_digest, 0, sizeof(m_digest));
}
HmacHash::~HmacHash()
{
HMAC_CTX_cleanup(&m_ctx);
}
void HmacHash::UpdateData(const std::string &str)
{
HMAC_Update(&m_ctx, (uint8 const*)str.c_str(), str.length());
}
void HmacHash::UpdateData(const uint8* data, size_t len)
{
HMAC_Update(&m_ctx, data, len);
}
void HmacHash::Finalize()
{
uint32 length = 0;
HMAC_Final(&m_ctx, (uint8*)m_digest, &length);
ASSERT(length == SHA_DIGEST_LENGTH);
}
uint8 *HmacHash::ComputeHash(BigNumber* bn)
{
HMAC_Update(&m_ctx, bn->AsByteArray().get(), bn->GetNumBytes());
Finalize();
return (uint8*)m_digest;
}
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "HmacHash.h"
#include "BigNumber.h"
#include "Common.h"
template<HashCreateFn HashCreator, uint32 DigestLength>
HmacHash<HashCreator, DigestLength>::HmacHash(uint32 len, uint8 *seed)
{
HMAC_CTX_init(&_ctx);
HMAC_Init_ex(&_ctx, seed, len, HashCreator(), NULL);
memset(_digest, 0, DigestLength);
}
template<HashCreateFn HashCreator, uint32 DigestLength>
HmacHash<HashCreator, DigestLength>::~HmacHash()
{
HMAC_CTX_cleanup(&_ctx);
}
template<HashCreateFn HashCreator, uint32 DigestLength>
void HmacHash<HashCreator, DigestLength>::UpdateData(const std::string &str)
{
HMAC_Update(&_ctx, (uint8 const*)str.c_str(), str.length());
}
template<HashCreateFn HashCreator, uint32 DigestLength>
void HmacHash<HashCreator, DigestLength>::UpdateData(const uint8* data, size_t len)
{
HMAC_Update(&_ctx, data, len);
}
template<HashCreateFn HashCreator, uint32 DigestLength>
void HmacHash<HashCreator, DigestLength>::Finalize()
{
uint32 length = 0;
HMAC_Final(&_ctx, _digest, &length);
ASSERT(length == DigestLength);
}
template<HashCreateFn HashCreator, uint32 DigestLength>
uint8* HmacHash<HashCreator, DigestLength>::ComputeHash(BigNumber* bn)
{
HMAC_Update(&_ctx, bn->AsByteArray().get(), bn->GetNumBytes());
Finalize();
return _digest;
}
template class HmacHash<EVP_sha1, SHA_DIGEST_LENGTH>;
template class HmacHash<EVP_sha256, SHA256_DIGEST_LENGTH>;
@@ -28,20 +28,26 @@ class BigNumber;
#define SEED_KEY_SIZE 16
typedef EVP_MD const* (*HashCreateFn)();
template<HashCreateFn HashCreator, uint32 DigestLength>
class HmacHash
{
public:
HmacHash(uint32 len, uint8 *seed);
~HmacHash();
void UpdateData(const std::string &str);
void UpdateData(const uint8* data, size_t len);
void UpdateData(std::string const& str);
void UpdateData(uint8 const* data, size_t len);
void Finalize();
uint8 *ComputeHash(BigNumber* bn);
uint8 *GetDigest() { return (uint8*)m_digest; }
int GetLength() const { return SHA_DIGEST_LENGTH; }
uint8* ComputeHash(BigNumber* bn);
uint8* GetDigest() { return _digest; }
uint32 GetLength() const { return DigestLength; }
private:
HMAC_CTX m_ctx;
uint8 m_digest[SHA_DIGEST_LENGTH];
HMAC_CTX _ctx;
uint8 _digest[DigestLength];
};
#endif
typedef HmacHash<EVP_sha1, SHA_DIGEST_LENGTH> HmacSha1;
typedef HmacHash<EVP_sha256, SHA256_DIGEST_LENGTH> HmacSha256;
#endif
+66
View File
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SHA256.h"
#include "BigNumber.h"
#include <stdarg.h>
SHA256Hash::SHA256Hash()
{
SHA256_Init(&mC);
memset(mDigest, 0, SHA256_DIGEST_LENGTH * sizeof(uint8));
}
SHA256Hash::~SHA256Hash()
{
SHA256_Init(&mC);
}
void SHA256Hash::UpdateData(const uint8 *dta, int len)
{
SHA256_Update(&mC, dta, len);
}
void SHA256Hash::UpdateData(const std::string &str)
{
UpdateData((uint8 const*)str.c_str(), str.length());
}
void SHA256Hash::UpdateBigNumbers(BigNumber* bn0, ...)
{
va_list v;
BigNumber* bn;
va_start(v, bn0);
bn = bn0;
while (bn)
{
UpdateData(bn->AsByteArray().get(), bn->GetNumBytes());
bn = va_arg(v, BigNumber*);
}
va_end(v);
}
void SHA256Hash::Initialize()
{
SHA256_Init(&mC);
}
void SHA256Hash::Finalize(void)
{
SHA256_Final(mDigest, &mC);
}
+49
View File
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SHA256_h__
#define SHA256_h__
#include "Define.h"
#include <string>
#include <openssl/sha.h>
class BigNumber;
class SHA256Hash
{
public:
SHA256Hash();
~SHA256Hash();
void UpdateBigNumbers(BigNumber* bn0, ...);
void UpdateData(const uint8 *dta, int len);
void UpdateData(const std::string &str);
void Initialize();
void Finalize();
uint8 *GetDigest(void) { return mDigest; };
int GetLength(void) const { return SHA256_DIGEST_LENGTH; };
private:
SHA256_CTX mC;
uint8 mDigest[SHA256_DIGEST_LENGTH];
};
#endif // SHA256_h__
@@ -22,7 +22,7 @@ void LoginDatabaseConnection::DoPrepareStatements()
if (!m_reconnecting)
m_stmts.resize(MAX_LOGINDATABASE_STATEMENTS);
PrepareStatement(LOGIN_SEL_REALMLIST, "SELECT id, name, address, localAddress, localSubnetMask, port, icon, flag, timezone, allowedSecurityLevel, population, gamebuild FROM realmlist WHERE flag <> 3 ORDER BY name", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_REALMLIST, "SELECT id, name, address, localAddress, localSubnetMask, port, icon, flag, timezone, allowedSecurityLevel, population, gamebuild, Region, Battlegroup FROM realmlist WHERE flag <> 3 ORDER BY name", CONNECTION_SYNCH);
PrepareStatement(LOGIN_DEL_EXPIRED_IP_BANS, "DELETE FROM ip_banned WHERE unbandate<>bandate AND unbandate<=UNIX_TIMESTAMP()", CONNECTION_ASYNC);
PrepareStatement(LOGIN_UPD_EXPIRED_ACCOUNT_BANS, "UPDATE account_banned SET active = 0 WHERE active = 1 AND unbandate<>bandate AND unbandate<=UNIX_TIMESTAMP()", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_IP_BANNED, "SELECT * FROM ip_banned WHERE ip = ?", CONNECTION_SYNCH);
@@ -37,13 +37,14 @@ void LoginDatabaseConnection::DoPrepareStatements()
PrepareStatement(LOGIN_SEL_SESSIONKEY, "SELECT a.sessionkey, a.id, aa.gmlevel FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_UPD_VS, "UPDATE account SET v = ?, s = ? WHERE username = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_UPD_LOGONPROOF, "UPDATE account SET sessionkey = ?, last_ip = ?, last_login = NOW(), locale = ?, failed_logins = 0, os = ? WHERE username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_LOGONCHALLENGE, "SELECT a.sha_pass_hash, a.id, a.locked, a.lock_country, a.last_ip, aa.gmlevel, a.v, a.s, a.token_key FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE a.username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_LOGONCHALLENGE, "SELECT a.sha_pass_hash, a.id, a.locked, a.lock_country, a.last_ip, aa.gmlevel, a.v, a.s, a.token_key, a.battlenet_account FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE a.username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_LOGON_COUNTRY, "SELECT country FROM ip2nation WHERE ip < ? ORDER BY ip DESC LIMIT 0,1", CONNECTION_SYNCH);
PrepareStatement(LOGIN_UPD_FAILEDLOGINS, "UPDATE account SET failed_logins = failed_logins + 1 WHERE username = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_SEL_FAILEDLOGINS, "SELECT id, failed_logins FROM account WHERE username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_ID_BY_NAME, "SELECT id FROM account WHERE username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_LIST_BY_NAME, "SELECT id, username FROM account WHERE username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_INFO_BY_NAME, "SELECT id, sessionkey, last_ip, locked, expansion, mutetime, locale, recruiter, os FROM account WHERE username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_INFO_BY_BNET, "SELECT id, sessionkey, last_ip, locked, expansion, mutetime, locale, recruiter, os FROM account WHERE battlenet_account = ? AND battlenet_index = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_LIST_BY_EMAIL, "SELECT id, username FROM account WHERE email = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_NUM_CHARS_ON_REALM, "SELECT numchars FROM realmcharacters WHERE realmid = ? AND acctid= ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_BY_IP, "SELECT id, username FROM account WHERE last_ip = ?", CONNECTION_SYNCH);
@@ -101,4 +102,20 @@ void LoginDatabaseConnection::DoPrepareStatements()
PrepareStatement(LOGIN_SEL_RBAC_ACCOUNT_PERMISSIONS, "SELECT permissionId, granted FROM rbac_account_permissions WHERE accountId = ? AND (realmId = ? OR realmId = -1) ORDER BY permissionId, realmId", CONNECTION_SYNCH);
PrepareStatement(LOGIN_INS_RBAC_ACCOUNT_PERMISSION, "INSERT INTO rbac_account_permissions (accountId, permissionId, granted, realmId) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE granted = VALUES(granted)", CONNECTION_ASYNC);
PrepareStatement(LOGIN_DEL_RBAC_ACCOUNT_PERMISSION, "DELETE FROM rbac_account_permissions WHERE accountId = ? AND permissionId = ? AND (realmId = ? OR realmId = -1)", CONNECTION_ASYNC);
PrepareStatement(LOGIN_SEL_BNET_ACCOUNT_INFO, "SELECT sha_pass_hash, id, locked, lock_country, last_ip, v, s FROM battlenet_accounts WHERE email = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_DEL_BNET_EXPIRED_BANS, "UPDATE battlenet_account_bans SET active = 0 WHERE active = 1 AND unbandate <> bandate AND unbandate <= UNIX_TIMESTAMP()", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_BNET_ACTIVE_ACCOUNT_BAN, "SELECT bandate, unbandate FROM battlenet_account_bans WHERE id = ? AND active = 1", CONNECTION_SYNCH);
PrepareStatement(LOGIN_UPD_BNET_VS_FIELDS, "UPDATE battlenet_accounts SET v = ?, s = ? WHERE email = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_UPD_BNET_SESSION_KEY, "UPDATE battlenet_accounts SET sessionKey = ? WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_SEL_BNET_RECONNECT_INFO, "SELECT ba.id, ba.sessionKey, a.id FROM battlenet_accounts ba LEFT JOIN account a ON ba.id = a.battlenet_account WHERE ba.email = ? AND a.battlenet_index = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_BNET_GAME_ACCOUNTS, "SELECT a.battlenet_index, a.id, ab.bandate, ab.unbandate, ab.active FROM account a LEFT JOIN account_banned ab ON a.id = ab.id WHERE battlenet_account = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_BNET_GAME_ACCOUNT, "SELECT a.id, ab.bandate, ab.unbandate, ab.active FROM account a LEFT JOIN account_banned ab ON a.id = ab.id WHERE battlenet_index = ? AND battlenet_account = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_UPD_BNET_LAST_LOGIN_INFO, "UPDATE battlenet_accounts SET last_ip = ?, last_login = NOW(), locale = ?, failed_logins = 0, os = ? WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_SEL_BNET_CHARACTER_COUNTS, "SELECT rc.numchars, r.id, r.Region, r.Battlegroup, r.gamebuild FROM realmcharacters rc INNER JOIN realmlist r ON rc.realmid = r.id WHERE rc.acctid = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_INS_BNET_ACCOUNT, "INSERT INTO battlenet_accounts (`email`,`sha_pass_hash`) VALUES (?, ?)", CONNECTION_ASYNC);
PrepareStatement(LOGIN_SEL_BNET_ACCOUNT_EMAIL_BY_ID, "SELECT email FROM battlenet_accounts WHERE id = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_BNET_ACCOUNT_ID_BY_EMAIL, "SELECT id FROM battlenet_accounts WHERE email = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_UPD_BNET_PASSWORD, "UPDATE account SET v = '', s = '', username = ?, sha_pass_hash = ? WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_SEL_BNET_CHECK_PASSWORD, "SELECT 1 FROM battlenet_accounts WHERE id = ? AND sha_pass_hash = ?", CONNECTION_ASYNC);
}
@@ -62,6 +62,7 @@ enum LoginDatabaseStatements
LOGIN_SEL_ACCOUNT_ID_BY_NAME,
LOGIN_SEL_ACCOUNT_LIST_BY_NAME,
LOGIN_SEL_ACCOUNT_INFO_BY_NAME,
LOGIN_SEL_ACCOUNT_INFO_BY_BNET,
LOGIN_SEL_ACCOUNT_LIST_BY_EMAIL,
LOGIN_SEL_NUM_CHARS_ON_REALM,
LOGIN_SEL_ACCOUNT_BY_IP,
@@ -120,6 +121,23 @@ enum LoginDatabaseStatements
LOGIN_SEL_RBAC_ACCOUNT_PERMISSIONS,
LOGIN_INS_RBAC_ACCOUNT_PERMISSION,
LOGIN_DEL_RBAC_ACCOUNT_PERMISSION,
LOGIN_SEL_BNET_ACCOUNT_INFO,
LOGIN_DEL_BNET_EXPIRED_BANS,
LOGIN_SEL_BNET_ACTIVE_ACCOUNT_BAN,
LOGIN_UPD_BNET_VS_FIELDS,
LOGIN_UPD_BNET_SESSION_KEY,
LOGIN_SEL_BNET_RECONNECT_INFO,
LOGIN_SEL_BNET_GAME_ACCOUNTS,
LOGIN_SEL_BNET_GAME_ACCOUNT,
LOGIN_UPD_BNET_LAST_LOGIN_INFO,
LOGIN_SEL_BNET_CHARACTER_COUNTS,
LOGIN_INS_BNET_ACCOUNT,
LOGIN_SEL_BNET_ACCOUNT_EMAIL_BY_ID,
LOGIN_SEL_BNET_ACCOUNT_ID_BY_EMAIL,
LOGIN_UPD_BNET_PASSWORD,
LOGIN_SEL_BNET_CHECK_PASSWORD,
MAX_LOGINDATABASE_STATEMENTS
};
+36
View File
@@ -524,6 +524,17 @@ void vutf8printf(FILE* out, const char *str, va_list* ap)
#endif
}
bool Utf8ToUpperOnlyLatin(std::string& utf8String)
{
std::wstring wstr;
if (!Utf8toWStr(utf8String, wstr))
return false;
std::transform(wstr.begin(), wstr.end(), wstr.begin(), wcharToUpperOnlyLatin);
return WStrToUtf8(wstr, utf8String);
}
std::string ByteArrayToHexStr(uint8 const* bytes, uint32 arrayLen, bool reverse /* = false */)
{
int32 init = 0;
@@ -547,3 +558,28 @@ std::string ByteArrayToHexStr(uint8 const* bytes, uint32 arrayLen, bool reverse
return ss.str();
}
void HexStrToByteArray(std::string const& str, uint8* out, bool reverse /*= false*/)
{
// string must have even number of characters
if (str.length() & 1)
return;
int32 init = 0;
int32 end = str.length();
int8 op = 1;
if (reverse)
{
init = str.length() - 2;
end = -2;
op = -1;
}
uint32 j = 0;
for (int32 i = init; i != end; i += 2 * op)
{
char buffer[3] = { str[i], str[i + 1], '\0' };
out[j++] = strtoul(buffer, NULL, 16);
}
}
+2
View File
@@ -344,6 +344,7 @@ bool consoleToUtf8(const std::string& conStr, std::string& utf8str);
bool Utf8FitTo(const std::string& str, std::wstring search);
void utf8printf(FILE* out, const char *str, ...);
void vutf8printf(FILE* out, const char *str, va_list* ap);
bool Utf8ToUpperOnlyLatin(std::string& utf8String);
bool IsIPAddress(char const* ipaddress);
@@ -356,6 +357,7 @@ std::string GetAddressString(ACE_INET_Addr const& addr);
uint32 CreatePIDFile(const std::string& filename);
std::string ByteArrayToHexStr(uint8 const* bytes, uint32 length, bool reverse = false);
void HexStrToByteArray(std::string const& str, uint8* out, bool reverse = false);
#endif
//handler for operations on large flags