aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/shared')
-rw-r--r--src/server/shared/Cryptography/Authentication/PacketCrypt.cpp39
-rw-r--r--src/server/shared/Cryptography/Authentication/PacketCrypt.h (renamed from src/server/shared/Cryptography/Authentication/AuthCrypt.h)21
-rw-r--r--src/server/shared/Cryptography/Authentication/WorldPacketCrypt.cpp (renamed from src/server/shared/Cryptography/Authentication/AuthCrypt.cpp)38
-rw-r--r--src/server/shared/Cryptography/Authentication/WorldPacketCrypt.h34
-rw-r--r--src/server/shared/Cryptography/BigNumber.cpp14
-rw-r--r--src/server/shared/Cryptography/BigNumber.h5
-rw-r--r--src/server/shared/Cryptography/HMACSHA1.cpp57
-rw-r--r--src/server/shared/Cryptography/HmacHash.cpp66
-rw-r--r--src/server/shared/Cryptography/HmacHash.h (renamed from src/server/shared/Cryptography/HMACSHA1.h)22
-rw-r--r--src/server/shared/Cryptography/SHA256.cpp66
-rw-r--r--src/server/shared/Cryptography/SHA256.h49
-rw-r--r--src/server/shared/Database/Implementation/LoginDatabase.cpp21
-rw-r--r--src/server/shared/Database/Implementation/LoginDatabase.h18
-rw-r--r--src/server/shared/Utilities/Util.cpp36
-rw-r--r--src/server/shared/Utilities/Util.h2
15 files changed, 375 insertions, 113 deletions
diff --git a/src/server/shared/Cryptography/Authentication/PacketCrypt.cpp b/src/server/shared/Cryptography/Authentication/PacketCrypt.cpp
new file mode 100644
index 00000000000..7fac311b8a2
--- /dev/null
+++ b/src/server/shared/Cryptography/Authentication/PacketCrypt.cpp
@@ -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);
+}
diff --git a/src/server/shared/Cryptography/Authentication/AuthCrypt.h b/src/server/shared/Cryptography/Authentication/PacketCrypt.h
index 8fa150068a2..36f3b81fb53 100644
--- a/src/server/shared/Cryptography/Authentication/AuthCrypt.h
+++ b/src/server/shared/Cryptography/Authentication/PacketCrypt.h
@@ -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
diff --git a/src/server/shared/Cryptography/Authentication/AuthCrypt.cpp b/src/server/shared/Cryptography/Authentication/WorldPacketCrypt.cpp
index ff94f307254..10403b84a1f 100644
--- a/src/server/shared/Cryptography/Authentication/AuthCrypt.cpp
+++ b/src/server/shared/Cryptography/Authentication/WorldPacketCrypt.cpp
@@ -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);
-}
-
diff --git a/src/server/shared/Cryptography/Authentication/WorldPacketCrypt.h b/src/server/shared/Cryptography/Authentication/WorldPacketCrypt.h
new file mode 100644
index 00000000000..7ccca11f09d
--- /dev/null
+++ b/src/server/shared/Cryptography/Authentication/WorldPacketCrypt.h
@@ -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
diff --git a/src/server/shared/Cryptography/BigNumber.cpp b/src/server/shared/Cryptography/BigNumber.cpp
index 1f3fc96e28d..1c82314bdba 100644
--- a/src/server/shared/Cryptography/BigNumber.cpp
+++ b/src/server/shared/Cryptography/BigNumber.cpp
@@ -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;
}
diff --git a/src/server/shared/Cryptography/BigNumber.h b/src/server/shared/Cryptography/BigNumber.h
index dc553babec9..7de53b442ae 100644
--- a/src/server/shared/Cryptography/BigNumber.h
+++ b/src/server/shared/Cryptography/BigNumber.h
@@ -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;
diff --git a/src/server/shared/Cryptography/HMACSHA1.cpp b/src/server/shared/Cryptography/HMACSHA1.cpp
deleted file mode 100644
index 2148a3b8a7b..00000000000
--- a/src/server/shared/Cryptography/HMACSHA1.cpp
+++ /dev/null
@@ -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;
-}
diff --git a/src/server/shared/Cryptography/HmacHash.cpp b/src/server/shared/Cryptography/HmacHash.cpp
new file mode 100644
index 00000000000..2913b9fa79a
--- /dev/null
+++ b/src/server/shared/Cryptography/HmacHash.cpp
@@ -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>;
diff --git a/src/server/shared/Cryptography/HMACSHA1.h b/src/server/shared/Cryptography/HmacHash.h
index de1556d3c98..56ee55edda2 100644
--- a/src/server/shared/Cryptography/HMACSHA1.h
+++ b/src/server/shared/Cryptography/HmacHash.h
@@ -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
diff --git a/src/server/shared/Cryptography/SHA256.cpp b/src/server/shared/Cryptography/SHA256.cpp
new file mode 100644
index 00000000000..b58c7db40c6
--- /dev/null
+++ b/src/server/shared/Cryptography/SHA256.cpp
@@ -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);
+}
diff --git a/src/server/shared/Cryptography/SHA256.h b/src/server/shared/Cryptography/SHA256.h
new file mode 100644
index 00000000000..78b3666dca8
--- /dev/null
+++ b/src/server/shared/Cryptography/SHA256.h
@@ -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__
diff --git a/src/server/shared/Database/Implementation/LoginDatabase.cpp b/src/server/shared/Database/Implementation/LoginDatabase.cpp
index de1e5b992e6..bccbe41a6ec 100644
--- a/src/server/shared/Database/Implementation/LoginDatabase.cpp
+++ b/src/server/shared/Database/Implementation/LoginDatabase.cpp
@@ -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);
}
diff --git a/src/server/shared/Database/Implementation/LoginDatabase.h b/src/server/shared/Database/Implementation/LoginDatabase.h
index 01f9fd973b6..64264984e29 100644
--- a/src/server/shared/Database/Implementation/LoginDatabase.h
+++ b/src/server/shared/Database/Implementation/LoginDatabase.h
@@ -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
};
diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp
index f2a6f1b7622..c26b981dab9 100644
--- a/src/server/shared/Utilities/Util.cpp
+++ b/src/server/shared/Utilities/Util.cpp
@@ -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);
+ }
+}
diff --git a/src/server/shared/Utilities/Util.h b/src/server/shared/Utilities/Util.h
index 4d7a37d77cf..bf70bdf406a 100644
--- a/src/server/shared/Utilities/Util.h
+++ b/src/server/shared/Utilities/Util.h
@@ -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