Core/NetworkIO: implement 2nd connection

This commit is contained in:
Ovahlord committed 2019-10-03 22:32:24 +02:00
1 parent 0299e10945
commit 8bec6af24a
28 files changed
+2049 -1000

No files matched your search

@@ -29,12 +29,17 @@ WorldPacketCrypt::WorldPacketCrypt() : PacketCrypt(SHA_DIGEST_LENGTH)
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 };
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 };
HmacSha1 clientDecryptHmac(SEED_KEY_SIZE, (uint8*)ServerDecryptionKey);
uint8 *decryptHash = clientDecryptHmac.ComputeHash(K);
Init(K, ServerEncryptionKey, ServerDecryptionKey);
}
void WorldPacketCrypt::Init(BigNumber* k, uint8 const* serverKey, uint8 const* clientKey)
{
HmacSha1 serverEncryptHmac(SEED_KEY_SIZE, (uint8*)serverKey);
uint8* encryptHash = serverEncryptHmac.ComputeHash(k);
HmacSha1 clientDecryptHmac(SEED_KEY_SIZE, (uint8*)clientKey);
uint8* decryptHash = clientDecryptHmac.ComputeHash(k);
_clientDecrypt.Init(decryptHash);
_serverEncrypt.Init(encryptHash);
@@ -29,6 +29,7 @@ class TC_COMMON_API WorldPacketCrypt : public PacketCrypt
WorldPacketCrypt();
void Init(BigNumber* K) override;
void Init(BigNumber* k, uint8 const* serverKey, uint8 const* clientKey);
};
#endif // _WORLDPACKETCRYPT_H
@@ -34,6 +34,7 @@ void LoginDatabaseConnection::DoPrepareStatements()
PrepareStatement(LOGIN_SEL_ACCOUNT_BANNED_BY_USERNAME, "SELECT account.id, username FROM account, account_banned WHERE account.id = account_banned.id AND active = 1 AND username LIKE CONCAT('%%', ?, '%%') GROUP BY account.id", CONNECTION_SYNCH);
PrepareStatement(LOGIN_INS_ACCOUNT_AUTO_BANNED, "INSERT INTO account_banned (id, bandate, unbandate, bannedby, banreason, active) VALUES (?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()+?, 'Trinity Auth', 'Failed login autoban', 1)", CONNECTION_ASYNC);
PrepareStatement(LOGIN_DEL_ACCOUNT_BANNED, "DELETE FROM account_banned WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_SEL_ACCOUNT_INFO_CONTINUED_SESSION, "SELECT username, sessionkey FROM account WHERE id = ?", CONNECTION_ASYNC);
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.id, a.username, a.locked, a.lock_country, a.last_ip, a.failed_logins, ab.unbandate > UNIX_TIMESTAMP() OR ab.unbandate = ab.bandate, "
@@ -37,6 +37,7 @@ enum LoginDatabaseStatements : uint32
LOGIN_SEL_ACCOUNT_BANNED_BY_USERNAME,
LOGIN_INS_ACCOUNT_AUTO_BANNED,
LOGIN_DEL_ACCOUNT_BANNED,
LOGIN_SEL_ACCOUNT_INFO_CONTINUED_SESSION,
LOGIN_UPD_VS,
LOGIN_UPD_LOGONPROOF,
LOGIN_SEL_LOGONCHALLENGE,
+1 -1
View File
@@ -21929,7 +21929,7 @@ template TC_GAME_API void Player::ApplySpellMod(uint32 spellId, SpellModOp op, f
void Player::AddSpellMod(SpellModifier* mod, bool apply)
{
TC_LOG_DEBUG("spells", "Player::AddSpellMod: Player '%s' (%s), SpellID: %d", GetName().c_str(), GetGUID().ToString().c_str(), mod->spellId);
Opcodes opcode = Opcodes((mod->type == SPELLMOD_FLAT) ? SMSG_SET_FLAT_SPELL_MODIFIER : SMSG_SET_PCT_SPELL_MODIFIER);
OpcodeServer opcode = OpcodeServer((mod->type == SPELLMOD_FLAT) ? SMSG_SET_FLAT_SPELL_MODIFIER : SMSG_SET_PCT_SPELL_MODIFIER);
int i = 0;
flag96 _mask = 0;
+1 -1
View File
@@ -9117,7 +9117,7 @@ void Unit::SetSpeedRate(UnitMoveType mtype, float rate)
PropagateSpeedChange();
static Opcodes const moveTypeToOpcode[MAX_MOVE_TYPE][3] =
static OpcodeServer const moveTypeToOpcode[MAX_MOVE_TYPE][3] =
{
{SMSG_SPLINE_MOVE_SET_WALK_SPEED, SMSG_MOVE_SET_WALK_SPEED, SMSG_MOVE_UPDATE_WALK_SPEED },
{SMSG_SPLINE_MOVE_SET_RUN_SPEED, SMSG_MOVE_SET_RUN_SPEED, SMSG_MOVE_UPDATE_RUN_SPEED },
+20 -6
View File
@@ -17,6 +17,7 @@
*/
#include "WorldSession.h"
#include "AuthenticationPackets.h"
#include "AccountMgr.h"
#include "ArenaTeam.h"
#include "ArenaTeamMgr.h"
@@ -54,6 +55,7 @@
#include "Transport.h"
#include "World.h"
#include "WorldPacket.h"
#include "boost/asio/ip/address.hpp"
class LoginQueryHolder : public SQLQueryHolder
{
@@ -732,7 +734,6 @@ void WorldSession::HandlePlayerLoginOpcode(WorldPacket& recvData)
return;
}
m_playerLoading = true;
ObjectGuid playerGuid;
TC_LOG_DEBUG("network", "WORLD: Recvd Player Logon Message");
@@ -754,7 +755,7 @@ void WorldSession::HandlePlayerLoginOpcode(WorldPacket& recvData)
recvData.ReadByteSeq(playerGuid[1]);
recvData.ReadByteSeq(playerGuid[4]);
TC_LOG_DEBUG("network", "Character %s logging in", playerGuid.ToString().c_str());
m_playerLoading = playerGuid;
if (!IsLegitCharacterForAccount(playerGuid))
{
@@ -763,14 +764,27 @@ void WorldSession::HandlePlayerLoginOpcode(WorldPacket& recvData)
return;
}
LoginQueryHolder *holder = new LoginQueryHolder(GetAccountId(), playerGuid);
SendConnectToInstance(WorldPackets::Auth::ConnectToSerial::Realm);
}
void WorldSession::HandleContinuePlayerLogin()
{
if (!PlayerLoading() || GetPlayer())
{
KickPlayer();
return;
}
LoginQueryHolder* holder = new LoginQueryHolder(GetAccountId(), m_playerLoading);
if (!holder->Initialize())
{
delete holder; // delete all unprocessed queries
m_playerLoading = false;
m_playerLoading.Clear();
return;
}
SendPacket(WorldPackets::Auth::ResumeComms(CONNECTION_TYPE_INSTANCE).Write());
_charLoginCallback = CharacterDatabase.DelayQueryHolder(holder);
}
@@ -800,7 +814,7 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder)
KickPlayer(); // disconnect client, player no set to session and it will not deleted or saved at kick
delete pCurrChar; // delete it manually
delete holder; // delete all unprocessed queries
m_playerLoading = false;
m_playerLoading.Clear();
return;
}
@@ -1161,7 +1175,7 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder)
if (!pCurrChar->IsStandState() && !pCurrChar->HasUnitState(UNIT_STATE_STUNNED))
pCurrChar->SetStandState(UNIT_STAND_STATE_STAND);
m_playerLoading = false;
m_playerLoading.Clear();
// Handle Login-Achievements (should be handled after loading)
_player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_ON_LOGIN, 1);
@@ -5656,7 +5656,7 @@ void Movement::PacketSender::Send() const
}
}
MovementStatusElements const* GetMovementStatusElementsSequence(Opcodes opcode)
MovementStatusElements const* GetMovementStatusElementsSequence(uint32 opcode)
{
switch (opcode)
{
@@ -153,6 +153,6 @@ namespace Movement
bool PrintInvalidSequenceElement(MovementStatusElements element, char const* function);
}
MovementStatusElements const* GetMovementStatusElementsSequence(Opcodes opcode);
MovementStatusElements const* GetMovementStatusElementsSequence(uint32 opcode);
#endif
+2 -5
View File
@@ -18,11 +18,8 @@
#include "Packet.h"
#include "Errors.h"
WorldPackets::Packet::Packet(WorldPacket&& worldPacket) : _worldPacket(std::move(worldPacket))
{
}
WorldPackets::ServerPacket::ServerPacket(OpcodeServer opcode, size_t initialSize /*= 200*/) : Packet(WorldPacket(opcode, initialSize))
WorldPackets::Packet::Packet(WorldPacket&& worldPacket)
: _worldPacket(std::move(worldPacket))
{
}
+2 -1
View File
@@ -38,6 +38,7 @@ namespace WorldPackets
WorldPacket const* GetRawPacket() const { return &_worldPacket; }
size_t GetSize() const { return _worldPacket.size(); }
ConnectionType GetConnection() const { return _worldPacket.GetConnection(); }
protected:
WorldPacket _worldPacket;
@@ -46,7 +47,7 @@ namespace WorldPackets
class TC_GAME_API ServerPacket : public Packet
{
public:
ServerPacket(OpcodeServer opcode, size_t initialSize = 200);
ServerPacket(OpcodeServer opcode, size_t initialSize = 200, ConnectionType connection = CONNECTION_TYPE_DEFAULT) : Packet(WorldPacket(opcode, initialSize, connection)) { }
void Read() override final;
@@ -18,6 +18,7 @@
#ifndef AllPackets_h__
#define AllPackets_h__
#include "AuthenticationPackets.h"
#include "LFGPackets.h"
#include "GuildPackets.h"
@@ -0,0 +1,553 @@
/*
* Copyright (C) 2008-2019 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 "AuthenticationPackets.h"
#include "HmacHash.h"
void WorldPackets::Auth::AuthSession::Read()
{
uint32 addonDataSize;
_worldPacket >> LoginServerID;
_worldPacket >> BattlegroupID;
_worldPacket >> LoginServerType;
_worldPacket >> Digest[10];
_worldPacket >> Digest[18];
_worldPacket >> Digest[12];
_worldPacket >> Digest[5];
_worldPacket >> DosResponse;
_worldPacket >> Digest[15];
_worldPacket >> Digest[9];
_worldPacket >> Digest[19];
_worldPacket >> Digest[4];
_worldPacket >> Digest[7];
_worldPacket >> Digest[16];
_worldPacket >> Digest[3];
_worldPacket >> Build;
_worldPacket >> Digest[8];
_worldPacket >> RealmID;
_worldPacket >> BuildType;
_worldPacket >> Digest[17];
_worldPacket >> Digest[6];
_worldPacket >> Digest[0];
_worldPacket >> Digest[1];
_worldPacket >> Digest[11];
_worldPacket >> LocalChallenge;
_worldPacket >> Digest[2];
_worldPacket >> RegionID;
_worldPacket >> Digest[14];
_worldPacket >> Digest[13];
_worldPacket >> addonDataSize;
if (addonDataSize)
{
AddonInfo.resize(addonDataSize);
_worldPacket.read(AddonInfo.contents(), addonDataSize);
}
UseIPv6 = _worldPacket.ReadBit(); // UseIPv6
uint8 accountNameLength = _worldPacket.ReadBits(12);
Account = _worldPacket.ReadString(accountNameLength);
}
void WorldPackets::Auth::AuthContinuedSession::Read()
{
_worldPacket >> Key;
_worldPacket >> DosResponse;
_worldPacket >> Digest[5];
_worldPacket >> Digest[2];
_worldPacket >> Digest[6];
_worldPacket >> Digest[10];
_worldPacket >> Digest[8];
_worldPacket >> Digest[17];
_worldPacket >> Digest[11];
_worldPacket >> Digest[15];
_worldPacket >> Digest[7];
_worldPacket >> Digest[1];
_worldPacket >> Digest[4];
_worldPacket >> Digest[16];
_worldPacket >> Digest[0];
_worldPacket >> Digest[12];
_worldPacket >> Digest[14];
_worldPacket >> Digest[13];
_worldPacket >> Digest[18];
_worldPacket >> Digest[9];
_worldPacket >> Digest[19];
_worldPacket >> Digest[3];
}
std::string const WorldPackets::Auth::ConnectTo::Haiku("World torn asunder\nDarkness descends on the land\nDeathwing has returned\n\0\0", 73);
uint8 const WorldPackets::Auth::ConnectTo::PiDigits[142] =
{
0x31, 0x41, 0x59, 0x26, 0x53, 0x58, 0x97, 0x93, 0x23, 0x84,
0x62, 0x64, 0x33, 0x83, 0x27, 0x95, 0x02, 0x88, 0x41, 0x97,
0x16, 0x93, 0x99, 0x37, 0x51, 0x05, 0x82, 0x09, 0x74, 0x94,
0x45, 0x92, 0x30, 0x78, 0x16, 0x40, 0x62, 0x86, 0x20, 0x89,
0x98, 0x62, 0x80, 0x34, 0x82, 0x53, 0x42, 0x11, 0x70, 0x67,
0x98, 0x21, 0x48, 0x08, 0x65, 0x13, 0x28, 0x23, 0x06, 0x64,
0x70, 0x93, 0x84, 0x46, 0x09, 0x55, 0x05, 0x82, 0x23, 0x17,
0x25, 0x35, 0x94, 0x08, 0x12, 0x84, 0x81, 0x11, 0x74, 0x50,
0x28, 0x41, 0x02, 0x70, 0x19, 0x38, 0x52, 0x11, 0x05, 0x55,
0x96, 0x44, 0x62, 0x29, 0x48, 0x95, 0x49, 0x30, 0x38, 0x19,
0x64, 0x42, 0x88, 0x10, 0x97, 0x56, 0x65, 0x93, 0x34, 0x46,
0x12, 0x84, 0x75, 0x64, 0x82, 0x33, 0x78, 0x67, 0x83, 0x16,
0x52, 0x71, 0x20, 0x19, 0x09, 0x14, 0x56, 0x48, 0x56, 0x69,
0x23, 0x46, 0x03, 0x48, 0x61, 0x04, 0x54, 0x32, 0x66, 0x48,
0x21, 0x33
};
/*
RSA key values
uint8 const Modulus[] =
{
0x5F, 0xD6, 0x80, 0x0B, 0xA7, 0xFF, 0x01, 0x40, 0xC7, 0xBC, 0x8E, 0xF5, 0x6B, 0x27, 0xB0, 0xBF,
0xF0, 0x1D, 0x1B, 0xFE, 0xDD, 0x0B, 0x1F, 0x3D, 0xB6, 0x6F, 0x1A, 0x48, 0x0D, 0xFB, 0x51, 0x08,
0x65, 0x58, 0x4F, 0xDB, 0x5C, 0x6E, 0xCF, 0x64, 0xCB, 0xC1, 0x6B, 0x2E, 0xB8, 0x0F, 0x5D, 0x08,
0x5D, 0x89, 0x06, 0xA9, 0x77, 0x8B, 0x9E, 0xAA, 0x04, 0xB0, 0x83, 0x10, 0xE2, 0x15, 0x4D, 0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 0x47, 0xA3, 0xEB, 0xCF, 0x6D, 0xC8, 0x96, 0x3A, 0x1B, 0x02, 0x52
};
uint8 const WherePacketHmac[] =
{
0x2C, 0x1F, 0x1D, 0x80, 0xC3, 0x8C, 0x23, 0x64, 0xDA, 0x90, 0xCA, 0x8E, 0x2C, 0xFC, 0x0C, 0xCE,
0x09, 0xD3, 0x62, 0xF9, 0xF3, 0x8B, 0xBE, 0x9F, 0x19, 0xEF, 0x58, 0xA1, 0x1C, 0x34, 0x14, 0x41,
0x3F, 0x23, 0xFD, 0xD3, 0xE8, 0x14, 0xEC, 0x2A, 0xFD, 0x4F, 0x95, 0xBA, 0x30, 0x7E, 0x56, 0x5D,
0x83, 0x95, 0x81, 0x69, 0xB0, 0x5A, 0xB4, 0x9D, 0xA8, 0x55, 0xFF, 0xFC, 0xEE, 0x58, 0x0A, 0x2F
};
WorldPackets::Auth::ConnectTo::ConnectTo() : ServerPacket(SMSG_REDIRECT_CLIENT, 8 + 4 + 256 + 1)
{
Payload.Adler32 = 0xA0A66C10;
p.SetBinary(P, 128);
q.SetBinary(Q, 128);
dmp1.SetBinary(DP, 128);
dmq1.SetBinary(DQ, 128);
iqmp.SetBinary(InverseQ, 128);
}
WorldPacket const* WorldPackets::Auth::ConnectTo::Write()
{
ByteBuffer payload;
uint16 port = Payload.Where.port();
uint8 address[16] = { 0 };
uint32 addressType = 3;
if (Payload.Where.address().is_v4())
{
memcpy(address, Payload.Where.address().to_v4().to_bytes().data(), 4);
addressType = 1;
}
else
{
memcpy(address, Payload.Where.address().to_v6().to_bytes().data(), 16);
addressType = 2;
}
HmacSha1 hmacHash(64, WherePacketHmac);
hmacHash.UpdateData(address, 16);
hmacHash.UpdateData((uint8* const)&addressType, 4);
hmacHash.UpdateData((uint8* const)&port, 2);
hmacHash.UpdateData((uint8* const)Haiku.c_str(), 73);
hmacHash.UpdateData(PiDigits, 142);
hmacHash.UpdateData(&Payload.XorMagic, 1);
hmacHash.Finalize();
uint8* hmac = hmacHash.GetDigest();
payload << uint8(PiDigits[30]);
payload << uint8(Haiku[31]);
payload << uint8(PiDigits[21]);
payload << uint8(PiDigits[26]);
payload << uint8(Haiku[3]);
payload << uint8(PiDigits[78]);
payload << uint8(Haiku[16]);
payload << uint8(Haiku[55]);
payload << uint8(Haiku[54]);
payload << uint8(PiDigits[68]);
payload << uint8(PiDigits[59]);
payload << uint8(PiDigits[115]);
payload << uint8(Haiku[65]);
payload << uint8(hmac[15]);
payload << uint8(Haiku[25]);
payload << uint8(PiDigits[32]);
payload << uint8(PiDigits[101]);
payload << uint8(Haiku[37]);
payload << uint8(Haiku[20]);
payload << uint8(Haiku[29]);
payload << uint8(PiDigits[88]);
payload << uint8(Haiku[9]);
payload << uint8(Haiku[63]);
payload << uint8(PiDigits[3]);
payload << uint8(PiDigits[22]);
payload << uint8(Haiku[14]);
payload << uint8(PiDigits[38]);
payload << uint8(PiDigits[46]);
payload << uint8(address[1]);
payload << uint8(PiDigits[94]);
payload << uint8(PiDigits[96]);
payload << uint8(PiDigits[137]);
payload << uint8(Haiku[42]);
payload << uint8(Haiku[21]);
payload << uint8(PiDigits[13]);
payload << uint8(hmac[14]);
payload << uint8(PiDigits[63]);
payload << uint8(PiDigits[16]);
payload << uint8(Haiku[5]);
payload << uint8(PiDigits[58]);
payload << uint8(Haiku[67]);
payload << uint8(Haiku[53]);
payload << uint8(PiDigits[79]);
payload << uint8(address[14]);
payload << uint8(address[9]);
payload << uint8(PiDigits[125]);
payload << uint8(Haiku[24]);
payload << uint8(Haiku[6]);
payload << uint8(PiDigits[140]);
payload << uint8(Haiku[8]);
payload << uint8(PiDigits[112]);
payload << uint8(PiDigits[133]);
payload << uint8(PiDigits[74]);
payload << uint8(PiDigits[135]);
payload << uint8(PiDigits[50]);
payload << uint8(PiDigits[14]);
payload << uint8(PiDigits[85]);
payload << uint8(hmac[19]);
payload << uint8(PiDigits[52]);
payload << uint8(hmac[17]);
payload << uint8(PiDigits[136]);
payload << uint8(PiDigits[71]);
payload << uint8(address[6]);
payload << uint8(PiDigits[87]);
payload << uint8(PiDigits[28]);
payload << uint8(PiDigits[105]);
payload << uint8(Haiku[32]);
payload << uint8(PiDigits[75]);
payload << uint8(Haiku[46]);
payload << uint8(PiDigits[5]);
payload << uint8(PiDigits[104]);
payload << uint8(Haiku[17]);
payload << uint8(PiDigits[64]);
payload << uint8(Haiku[22]);
payload << uint8(address[3]);
payload << uint8(port & 0xFF);
payload << uint8(Haiku[23]);
payload << uint8(PiDigits[0]);
payload << uint8(address[5]);
payload << uint8(PiDigits[110]);
payload << uint8(PiDigits[109]);
payload << uint8(PiDigits[93]);
payload << uint8(Haiku[10]);
payload << uint8(Payload.XorMagic);
payload << uint8(Haiku[26]);
payload << uint8(Haiku[13]);
payload << uint8(PiDigits[90]);
payload << uint8(PiDigits[72]);
payload << uint8(PiDigits[6]);
payload << uint8(PiDigits[54]);
payload << uint8(address[0]);
payload << uint8(PiDigits[23]);
payload << uint8(PiDigits[100]);
payload << uint8(Haiku[39]);
payload << uint8(PiDigits[86]);
payload << uint8(PiDigits[82]);
payload << uint8(Haiku[56]);
payload << uint8(PiDigits[95]);
payload << uint8(hmac[18]);
payload << uint8(PiDigits[113]);
payload << uint8(Haiku[38]);
payload << uint8(hmac[8]);
payload << uint8(PiDigits[92]);
payload << uint8(PiDigits[42]);
payload << uint8(PiDigits[120]);
payload << uint8(PiDigits[55]);
payload << uint8(PiDigits[124]);
payload << uint8(Haiku[30]);
payload << uint8(PiDigits[4]);
payload << uint8(Haiku[18]);
payload << uint8(PiDigits[123]);
payload << uint8(address[8]);
payload << uint8(PiDigits[61]);
payload << uint8(PiDigits[122]);
payload << uint8(Haiku[19]);
payload << uint8(PiDigits[53]);
payload << uint8(address[2]);
payload << uint8(hmac[11]);
payload << uint8(PiDigits[31]);
payload << uint8(PiDigits[36]);
payload << uint8(Haiku[2]);
payload << uint8(Haiku[57]);
payload << uint8(Haiku[40]);
payload << uint8(PiDigits[70]);
payload << uint8(Haiku[34]);
payload << uint8(PiDigits[132]);
payload << uint8(PiDigits[20]);
payload << uint8(PiDigits[107]);
payload << uint8(PiDigits[141]);
payload << uint8(PiDigits[97]);
payload << uint8(hmac[2]);
payload << uint8(Haiku[60]);
payload << uint8(PiDigits[102]);
payload << uint8(PiDigits[116]);
payload << uint8(PiDigits[49]);
payload << uint8(PiDigits[37]);
payload << uint8(PiDigits[48]);
payload << uint8(PiDigits[18]);
payload << uint8(Haiku[69]);
payload << uint8(hmac[12]);
payload << uint8(PiDigits[65]);
payload << uint8(hmac[3]);
payload << uint8(Haiku[27]);
payload << uint8(PiDigits[118]);
payload << uint8(PiDigits[44]);
payload << uint8(Haiku[50]);
payload << uint8(Haiku[59]);
payload << uint8(PiDigits[81]);
payload << uint8(PiDigits[51]);
payload << uint8(address[4]);
payload << uint8(PiDigits[12]);
payload << uint8(PiDigits[27]);
payload << uint8(address[11]);
payload << uint8(PiDigits[40]);
payload << uint8(PiDigits[139]);
payload << uint8(Haiku[51]);
payload << uint8(Haiku[64]);
payload << uint8(PiDigits[111]);
payload << uint8(PiDigits[131]);
payload << uint8(Haiku[1]);
payload << uint8(Haiku[49]);
payload << uint8(PiDigits[41]);
payload << uint8(Haiku[28]);
payload << uint8(PiDigits[77]);
payload << uint8(PiDigits[76]);
payload << uint8(PiDigits[8]);
payload << uint8(address[12]);
payload << uint8(Haiku[62]);
payload << uint8(PiDigits[19]);
payload << uint8(PiDigits[17]);
payload << uint8(PiDigits[24]);
payload << uint8(Haiku[72]);
payload << uint8(hmac[13]);
payload << uint8(Haiku[61]);
payload << uint8(PiDigits[29]);
payload << uint8(PiDigits[15]);
payload << uint8(address[7]);
payload << uint8(PiDigits[121]);
payload << uint8(PiDigits[69]);
payload << uint8(address[13]);
payload << uint8(Haiku[35]);
payload << uint8(PiDigits[103]);
payload << uint8(PiDigits[39]);
payload << uint8(hmac[5]);
payload << uint8(Haiku[4]);
payload << uint8(PiDigits[34]);
payload << uint8(PiDigits[56]);
payload << uint8((port >> 8) & 0xFF);
payload << uint8(hmac[10]);
payload << uint8(PiDigits[80]);
payload << uint8(PiDigits[130]);
payload << uint8(Haiku[12]);
payload << uint8(PiDigits[134]);
payload << uint8(PiDigits[33]);
payload << uint8(PiDigits[25]);
payload << uint8(PiDigits[73]);
payload << uint8(PiDigits[138]);
payload << uint8(PiDigits[9]);
payload << uint8(PiDigits[66]);
payload << uint8(PiDigits[1]);
payload << uint8(Haiku[45]);
payload << uint8(PiDigits[126]);
payload << uint8(PiDigits[67]);
payload << uint8(Haiku[33]);
payload << uint8(PiDigits[10]);
payload << uint8(hmac[4]);
payload << uint8(hmac[9]);
payload << uint8(Haiku[44]);
payload << uint8(PiDigits[60]);
payload << uint8(PiDigits[98]);
payload << uint8(PiDigits[91]);
payload << uint8(hmac[1]);
payload << uint8(addressType);
payload << uint8(PiDigits[11]);
payload << uint8(PiDigits[83]);
payload << uint8(hmac[0]);
payload << uint8(Haiku[52]);
payload << uint8(Haiku[43]);
payload << uint8(PiDigits[47]);
payload << uint8(Haiku[11]);
payload << uint8(PiDigits[129]);
payload << uint8(Haiku[0]);
payload << uint8(PiDigits[57]);
payload << uint8(PiDigits[7]);
payload << uint8(hmac[7]);
payload << uint8(Haiku[15]);
payload << uint8(Haiku[58]);
payload << uint8(Haiku[66]);
payload << uint8(PiDigits[127]);
payload << uint8(Haiku[41]);
payload << uint8(address[10]);
payload << uint8(Haiku[71]);
payload << uint8(PiDigits[99]);
payload << uint8(PiDigits[117]);
payload << uint8(PiDigits[62]);
payload << uint8(PiDigits[89]);
payload << uint8(Haiku[70]);
payload << uint8(hmac[6]);
payload << uint8(PiDigits[114]);
payload << uint8(PiDigits[106]);
payload << uint8(PiDigits[108]);
payload << uint8(Haiku[48]);
payload << uint8(Haiku[7]);
payload << uint8(PiDigits[2]);
payload << uint8(PiDigits[43]);
payload << uint8(Haiku[36]);
payload << uint8(PiDigits[45]);
payload << uint8(PiDigits[119]);
payload << uint8(Haiku[47]);
payload << uint8(Haiku[68]);
payload << uint8(hmac[16]);
payload << uint8(PiDigits[128]);
payload << uint8(address[15]);
payload << uint8(PiDigits[35]);
payload << uint8(PiDigits[84]);
BigNumber bnData;
bnData.SetBinary(payload.contents(), payload.size());
BigNumber m1 = (bnData % p).ModExp(dmp1, p);
BigNumber m2 = (bnData % q).ModExp(dmq1, q);
BigNumber h = (iqmp * (m1 - m2)) % p;
// Be sure to use the positive remainder
if (h.IsNegative())
h += p;
BigNumber m = m2 + h * q;
_worldPacket << uint64(Key);
_worldPacket << uint32(Serial);
_worldPacket.append(m.AsByteArray(256).get(), 256);
_worldPacket << uint8(Con);
return &_worldPacket;
}
@@ -0,0 +1,125 @@
/*
* Copyright (C) 2008-2019 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 AuthenticationPacketsWorld_h__
#define AuthenticationPacketsWorld_h__
#include "Packet.h"
#include "ObjectMgr.h"
#include "Util.h"
#include "BigNumber.h"
#include "SHA1.h"
#include <boost/asio/ip/tcp.hpp>
using boost::asio::ip::tcp;
namespace WorldPackets
{
namespace Auth
{
class AuthSession final : public ClientPacket
{
public:
AuthSession(WorldPacket&& packet) : ClientPacket(CMSG_AUTH_SESSION, std::move(packet))
{
memset(Digest, 0, SHA_DIGEST_LENGTH);
}
void Read() override;
uint32 BattlegroupID = 0;
int8 LoginServerType = 0; ///< Auth type used - 0 GRUNT, 1 battle.net
int8 BuildType = 0;
uint32 RealmID = 0;
uint16 Build = 0;
uint32 LocalChallenge = 0;
int32 LoginServerID = 0;
uint32 RegionID = 0;
uint64 DosResponse = 0;
uint8 Digest[SHA_DIGEST_LENGTH];
std::string Account;
bool UseIPv6 = false;
ByteBuffer AddonInfo;
};
class AuthContinuedSession final : public ClientPacket
{
public:
AuthContinuedSession(WorldPacket&& packet) : ClientPacket(CMSG_AUTH_CONTINUED_SESSION, std::move(packet))
{
memset(Digest, 0, SHA_DIGEST_LENGTH);
}
void Read() override;
uint64 DosResponse = 0;
uint64 Key = 0;
uint8 Digest[SHA_DIGEST_LENGTH];
};
class ResumeComms final : public ServerPacket
{
public:
ResumeComms(ConnectionType connection) : ServerPacket(SMSG_RESUME_COMMS, 0, connection) { }
WorldPacket const* Write() override { return &_worldPacket; }
};
enum class ConnectToSerial : uint32
{
None = 0,
Realm = 14,
WorldAttempt1 = 17,
WorldAttempt2 = 35,
WorldAttempt3 = 53,
WorldAttempt4 = 71,
WorldAttempt5 = 89
};
class ConnectTo final : public ServerPacket
{
static std::string const Haiku;
static uint8 const PiDigits[142];
struct ConnectPayload
{
tcp::endpoint Where;
uint32 Adler32 = 0;
uint8 XorMagic = 0x2A;
};
public:
ConnectTo();
WorldPacket const* Write() override;
uint64 Key = 0;
ConnectToSerial Serial = ConnectToSerial::None;
ConnectPayload Payload;
uint8 Con = 0;
private:
BigNumber p;
BigNumber q;
BigNumber dmp1;
BigNumber dmq1;
BigNumber iqmp;
};
}
}
#endif // AuthenticationPacketsWorld_h__
File diff suppressed because it is too large. Load diff
+131 -86
View File
@@ -26,7 +26,7 @@
#include "Define.h"
#include <string>
enum Opcodes : uint16
enum OpcodeClient : uint16
{
CMSG_ACCEPT_LEVEL_GRANT = 0x0205,
CMSG_ACCEPT_TRADE = 0x7110,
@@ -59,6 +59,7 @@ enum Opcodes : uint16
CMSG_AUCTION_PLACE_BID = 0x2306,
CMSG_AUCTION_REMOVE_ITEM = 0x6426,
CMSG_AUCTION_SELL_ITEM = 0x4A06,
CMSG_AUTH_CONTINUED_SESSION = 0x044D,
CMSG_AUTH_SESSION = 0x0449,
CMSG_AUTOBANK_ITEM = 0x2537,
CMSG_AUTOEQUIP_GROUND_ITEM = 0x0000,
@@ -445,7 +446,6 @@ enum Opcodes : uint16
CMSG_READ_ITEM = 0x2F16,
CMSG_REALM_SPLIT = 0x2906,
CMSG_RECLAIM_CORPSE = 0x4036,
CMSG_REDIRECTION_AUTH_PROOF = 0x044D,
CMSG_REFORGE_ITEM = 0x331A,
CMSG_REORDER_CHARACTERS = 0x0593,
CMSG_REPAIR_ITEM = 0x2917,
@@ -530,7 +530,7 @@ enum Opcodes : uint16
CMSG_SUBMIT_COMPLAIN = 0x2501,
CMSG_SUGGESTION_SUBMIT = 0x2512,
CMSG_SUMMON_RESPONSE = 0x6F27,
CMSG_SUSPEND_TOKEN = 0x046D,
CMSG_SUSPEND_TOKEN_RESPONSE = 0x046D,
CMSG_SWAP_INV_ITEM = 0x2614,
CMSG_SWAP_ITEM = 0x6326,
CMSG_SYNC_DANCE = 0x0036,
@@ -578,77 +578,10 @@ enum Opcodes : uint16
CMSG_WORLD_TELEPORT = 0x24B2,
CMSG_WRAP_ITEM = 0x4F06,
CMSG_ZONEUPDATE = 0x4F37,
MSG_AUCTION_HELLO = 0x2307,
MSG_CHANNEL_START = 0x0A15, // SMSG only?
MSG_CHANNEL_UPDATE = 0x2417, // SMSG only?
MSG_CORPSE_QUERY = 0x4336,
MSG_GM_BIND_OTHER = 0x0000,
MSG_GM_SHOWLABEL = 0x0000,
MSG_GM_SUMMON = 0x0000,
MSG_INSPECT_ARENA_TEAMS = 0x2704,
MSG_LIST_STABLED_PETS = 0x0834,
MSG_MINIMAP_PING = 0x6635,
MSG_MOVE_CHARM_TELEPORT_CHEAT = 0x7A08,
MSG_MOVE_FALL_LAND = 0x380A,
MSG_MOVE_HEARTBEAT = 0x3914,
MSG_MOVE_JUMP = 0x7A06,
MSG_MOVE_SET_ALL_SPEED_CHEAT = 0x0000,
MSG_MOVE_SET_COLLISION_HEIGHT = 0x0000,
MSG_MOVE_SET_FACING = 0x7914,
MSG_MOVE_SET_FLIGHT_SPEED_CHEAT = 0x0000,
MSG_MOVE_SET_PITCH = 0x7312,
MSG_MOVE_SET_RAW_POSITION_ACK = 0x0000,
MSG_MOVE_SET_RUN_BACK_SPEED_CHEAT = 0x0000,
MSG_MOVE_SET_RUN_MODE = 0x791A,
MSG_MOVE_SET_RUN_SPEED_CHEAT = 0x0000,
MSG_MOVE_SET_SWIM_BACK_SPEED_CHEAT = 0x0000,
MSG_MOVE_SET_SWIM_SPEED_CHEAT = 0x0000,
MSG_MOVE_SET_TURN_RATE_CHEAT = 0x0000,
MSG_MOVE_SET_WALK_MODE = 0x7002,
MSG_MOVE_SET_WALK_SPEED_CHEAT = 0x0000,
MSG_MOVE_START_ASCEND = 0x390A,
MSG_MOVE_START_BACKWARD = 0x330A,
MSG_MOVE_START_DESCEND = 0x3800,
MSG_MOVE_START_FORWARD = 0x7814,
MSG_MOVE_START_PITCH_DOWN = 0x3908,
MSG_MOVE_START_PITCH_UP = 0x3304,
MSG_MOVE_START_STRAFE_LEFT = 0x3A16,
MSG_MOVE_START_STRAFE_RIGHT = 0x3A02,
MSG_MOVE_START_SWIM = 0x3206,
MSG_MOVE_START_TURN_LEFT = 0x700C,
MSG_MOVE_START_TURN_RIGHT = 0x7000,
MSG_MOVE_STOP = 0x320A,
MSG_MOVE_STOP_ASCEND = 0x7B00,
MSG_MOVE_STOP_PITCH = 0x7216,
MSG_MOVE_STOP_STRAFE = 0x3002,
MSG_MOVE_STOP_SWIM = 0x3802,
MSG_MOVE_STOP_TURN = 0x331E,
MSG_MOVE_TELEPORT = 0x55A0,
MSG_MOVE_TELEPORT_ACK = 0x390C,
MSG_MOVE_TELEPORT_CHEAT = 0x3A10,
MSG_MOVE_TIME_SKIPPED = 0x19B3,
MSG_MOVE_TOGGLE_COLLISION_CHEAT = 0x7B04,
MSG_MOVE_TOGGLE_FALL_LOGGING = 0x0000,
MSG_MOVE_TOGGLE_LOGGING = 0x0000,
MSG_MOVE_UPDATE_MOUSE = 0x0000,
MSG_MOVE_WORLDPORT_ACK = 0x2411,
MSG_NOTIFY_PARTY_SQUELCH = 0x4D06,
MSG_PARTY_ASSIGNMENT = 0x0424,
MSG_PETITION_DECLINE = 0x4905,
MSG_PETITION_RENAME = 0x4005,
MSG_PVP_LOG_DATA = 0x0000,
MSG_QUERY_NEXT_MAIL_TIME = 0x0F04,
MSG_QUEST_PUSH_RESULT = 0x4515,
MSG_RAID_READY_CHECK = 0x2304,
MSG_RAID_READY_CHECK_CONFIRM = 0x4F05,
MSG_RAID_READY_CHECK_FINISHED = 0x2E15,
MSG_RAID_TARGET_UPDATE = 0x2C36,
MSG_RANDOM_ROLL = 0x0905,
MSG_SAVE_GUILD_EMBLEM = 0x2404,
MSG_SET_DUNGEON_DIFFICULTY = 0x4925,
MSG_SET_RAID_DIFFICULTY = 0x0614,
MSG_TABARDVENDOR_ACTIVATE = 0x6926,
MSG_TALENT_WIPE_CONFIRM = 0x0107,
};
enum OpcodeServer
{
SMSG_ACCOUNT_DATA_TIMES = 0x4B05,
SMSG_ACCOUNT_INFO_RESPONSE = 0x10A7,
SMSG_ACCOUNT_RESTRICTED_WARNING = 0x51A7,
@@ -851,7 +784,6 @@ enum Opcodes : uint16
SMSG_FORCED_DEATH_UPDATE = 0x2606,
SMSG_FORCE_ANIM = 0x4C05,
SMSG_FORCE_DISPLAY_UPDATE = 0x0000,
SMSG_FORCE_SEND_QUEUED_PACKETS = 0x0140,
SMSG_FORCE_SET_VEHICLE_REC_ID = 0x70A1,
SMSG_FORGE_MASTER_SET = 0x70B7,
SMSG_FRIEND_STATUS = 0x0717,
@@ -1208,6 +1140,7 @@ enum Opcodes : uint16
SMSG_RESET_FAILED_NOTIFY = 0x4616,
SMSG_RESISTLOG = 0x0000,
SMSG_RESPOND_INSPECT_ACHIEVEMENTS = 0x15B0,
SMSG_RESUME_COMMS = 0x0140,
SMSG_RESURRECT_FAILED = 0x6705,
SMSG_RESURRECT_REQUEST = 0x2905,
SMSG_RESYNC_RUNES = 0x6224,
@@ -1305,7 +1238,7 @@ enum Opcodes : uint16
SMSG_SUPERCEDED_SPELL = 0x35B0,
SMSG_SUPPRESS_NPC_GREETINGS = 0x74B1,
SMSG_SUSPEND_COMMS = 0x4140,
SMSG_SUSPEND_TOKEN_RESPONSE = 0x14B1,
SMSG_SUSPEND_TOKEN = 0x14B1,
SMSG_TALENTS_ERROR = 0x0916,
SMSG_TALENTS_INFO = 0x6F26,
SMSG_TALENTS_INVOLUNTARILY_RESET = 0x2C27,
@@ -1374,7 +1307,111 @@ enum Opcodes : uint16
SMSG_WORLD_SERVER_INFO = 0x31A2,
SMSG_WORLD_STATE_UI_TIMER_UPDATE = 0x4A14,
SMSG_XP_GAIN_ABORTED = 0x50B4,
SMSG_ZONE_UNDER_ATTACK = 0x0A06,
SMSG_ZONE_UNDER_ATTACK = 0x0A06
};
enum OpcodeServerClient
{
MSG_AUCTION_HELLO = 0x2307,
MSG_CHANNEL_START = 0x0A15, // SMSG only?
MSG_CHANNEL_UPDATE = 0x2417, // SMSG only?
MSG_CORPSE_QUERY = 0x4336,
MSG_GM_BIND_OTHER = 0x0000,
MSG_GM_SHOWLABEL = 0x0000,
MSG_GM_SUMMON = 0x0000,
MSG_INSPECT_ARENA_TEAMS = 0x2704,
MSG_LIST_STABLED_PETS = 0x0834,
MSG_MINIMAP_PING = 0x6635,
MSG_MOVE_CHARM_TELEPORT_CHEAT = 0x7A08,
MSG_MOVE_FALL_LAND = 0x380A,
MSG_MOVE_HEARTBEAT = 0x3914,
MSG_MOVE_JUMP = 0x7A06,
MSG_MOVE_SET_ALL_SPEED_CHEAT = 0x0000,
MSG_MOVE_SET_COLLISION_HEIGHT = 0x0000,
MSG_MOVE_SET_FACING = 0x7914,
MSG_MOVE_SET_FLIGHT_SPEED_CHEAT = 0x0000,
MSG_MOVE_SET_PITCH = 0x7312,
MSG_MOVE_SET_RAW_POSITION_ACK = 0x0000,
MSG_MOVE_SET_RUN_BACK_SPEED_CHEAT = 0x0000,
MSG_MOVE_SET_RUN_MODE = 0x791A,
MSG_MOVE_SET_RUN_SPEED_CHEAT = 0x0000,
MSG_MOVE_SET_SWIM_BACK_SPEED_CHEAT = 0x0000,
MSG_MOVE_SET_SWIM_SPEED_CHEAT = 0x0000,
MSG_MOVE_SET_TURN_RATE_CHEAT = 0x0000,
MSG_MOVE_SET_WALK_MODE = 0x7002,
MSG_MOVE_SET_WALK_SPEED_CHEAT = 0x0000,
MSG_MOVE_START_ASCEND = 0x390A,
MSG_MOVE_START_BACKWARD = 0x330A,
MSG_MOVE_START_DESCEND = 0x3800,
MSG_MOVE_START_FORWARD = 0x7814,
MSG_MOVE_START_PITCH_DOWN = 0x3908,
MSG_MOVE_START_PITCH_UP = 0x3304,
MSG_MOVE_START_STRAFE_LEFT = 0x3A16,
MSG_MOVE_START_STRAFE_RIGHT = 0x3A02,
MSG_MOVE_START_SWIM = 0x3206,
MSG_MOVE_START_TURN_LEFT = 0x700C,
MSG_MOVE_START_TURN_RIGHT = 0x7000,
MSG_MOVE_STOP = 0x320A,
MSG_MOVE_STOP_ASCEND = 0x7B00,
MSG_MOVE_STOP_PITCH = 0x7216,
MSG_MOVE_STOP_STRAFE = 0x3002,
MSG_MOVE_STOP_SWIM = 0x3802,
MSG_MOVE_STOP_TURN = 0x331E,
MSG_MOVE_TELEPORT = 0x55A0,
MSG_MOVE_TELEPORT_ACK = 0x390C,
MSG_MOVE_TELEPORT_CHEAT = 0x3A10,
MSG_MOVE_TIME_SKIPPED = 0x19B3,
MSG_MOVE_TOGGLE_COLLISION_CHEAT = 0x7B04,
MSG_MOVE_TOGGLE_FALL_LOGGING = 0x0000,
MSG_MOVE_TOGGLE_LOGGING = 0x0000,
MSG_MOVE_UPDATE_MOUSE = 0x0000,
MSG_MOVE_WORLDPORT_ACK = 0x2411,
MSG_NOTIFY_PARTY_SQUELCH = 0x4D06,
MSG_PARTY_ASSIGNMENT = 0x0424,
MSG_PETITION_DECLINE = 0x4905,
MSG_PETITION_RENAME = 0x4005,
MSG_PVP_LOG_DATA = 0x0000,
MSG_QUERY_NEXT_MAIL_TIME = 0x0F04,
MSG_QUEST_PUSH_RESULT = 0x4515,
MSG_RAID_READY_CHECK = 0x2304,
MSG_RAID_READY_CHECK_CONFIRM = 0x4F05,
MSG_RAID_READY_CHECK_FINISHED = 0x2E15,
MSG_RAID_TARGET_UPDATE = 0x2C36,
MSG_RANDOM_ROLL = 0x0905,
MSG_SAVE_GUILD_EMBLEM = 0x2404,
MSG_SET_DUNGEON_DIFFICULTY = 0x4925,
MSG_SET_RAID_DIFFICULTY = 0x0614,
MSG_TABARDVENDOR_ACTIVATE = 0x6926,
MSG_TALENT_WIPE_CONFIRM = 0x0107,
};
inline bool IsInstanceOnlyOpcode(uint32 opcode)
{
switch (opcode)
{
case SMSG_QUESTGIVER_STATUS: // ClientQuest
case SMSG_DUEL_REQUESTED: // Client
case SMSG_DUEL_INBOUNDS: // Client
case SMSG_QUERY_TIME_RESPONSE: // Client
case SMSG_DUEL_WINNER: // Client
case SMSG_DUEL_COMPLETE: // Client
case SMSG_DUEL_OUTOFBOUNDS: // Client
case SMSG_ATTACKSTOP: // Client
case SMSG_ATTACKSTART: // Client
case SMSG_MOUNTRESULT: // Client
return true;
default:
return false;
}
}
enum ConnectionType
{
CONNECTION_TYPE_REALM = 0,
CONNECTION_TYPE_INSTANCE = 1,
MAX_CONNECTION_TYPES,
CONNECTION_TYPE_DEFAULT = -1
};
enum OpcodeMisc : uint16
@@ -1386,8 +1423,8 @@ enum OpcodeMisc : uint16
COMPRESSED_OPCODE_MASK = 0x8000
};
typedef Opcodes OpcodeClient;
typedef Opcodes OpcodeServer;
typedef OpcodeClient OpcodeClient;
typedef OpcodeServer OpcodeServer;
/// Player state
enum SessionStatus
@@ -1434,8 +1471,10 @@ public:
class ServerOpcodeHandler : public OpcodeHandler
{
public:
ServerOpcodeHandler(char const* name, SessionStatus status)
: OpcodeHandler(name, status) { }
ServerOpcodeHandler(char const* name, SessionStatus status, ConnectionType conIdx)
: OpcodeHandler(name, status), ConnectionIndex(conIdx) { }
ConnectionType ConnectionIndex;
};
class OpcodeTable
@@ -1450,24 +1489,30 @@ public:
void Initialize();
ClientOpcodeHandler const* operator[](Opcodes index) const
ClientOpcodeHandler const* operator[](OpcodeClient index) const
{
return _internalTableClient[index];
}
ServerOpcodeHandler const* operator[](OpcodeServer index) const
{
return _internalTableServer[index];
}
private:
template<typename Handler, Handler HandlerFunction>
void ValidateAndSetClientOpcode(OpcodeClient opcode, char const* name, SessionStatus status, PacketProcessing processing);
void ValidateAndSetServerOpcode(OpcodeServer opcode, char const* name, SessionStatus status);
void ValidateAndSetServerOpcode(OpcodeServer opcode, char const* name, SessionStatus status, ConnectionType conIdx);
ClientOpcodeHandler* _internalTableClient[NUM_OPCODE_HANDLERS];
ServerOpcodeHandler* _internalTableServer[NUM_OPCODE_HANDLERS];
};
extern OpcodeTable opcodeTable;
TC_GAME_API extern OpcodeTable opcodeTable;
/// Lookup opcode name for human understandable logging
std::string GetOpcodeNameForLogging(Opcodes opcode);
std::string GetOpcodeNameForLogging(OpcodeClient opcode);
std::string GetOpcodeNameForLogging(OpcodeServer opcode);
#endif
/// @}
+6 -6
View File
@@ -24,14 +24,14 @@
//! Compresses packet in place
void WorldPacket::Compress(z_stream* compressionStream)
{
uint16 uncompressedOpcode = GetOpcode();
OpcodeServer uncompressedOpcode = OpcodeServer(GetOpcode());
if (uncompressedOpcode & COMPRESSED_OPCODE_MASK)
{
TC_LOG_ERROR("network", "Packet with opcode 0x%04X is already compressed!", uncompressedOpcode);
return;
}
Opcodes opcode = Opcodes(uncompressedOpcode | COMPRESSED_OPCODE_MASK);
uint32 opcode = uncompressedOpcode | COMPRESSED_OPCODE_MASK;
uint32 size = wpos();
uint32 destsize = compressBound(size);
@@ -47,7 +47,7 @@ void WorldPacket::Compress(z_stream* compressionStream)
*this << uint32(size);
append(&storage[0], destsize);
SetOpcode(opcode);
TC_LOG_INFO("network", "%s (len %u) successfully compressed to %04X (len %u)", GetOpcodeNameForLogging(Opcodes(uncompressedOpcode)).c_str(), size, opcode, destsize);
TC_LOG_INFO("network", "%s (len %u) successfully compressed to %04X (len %u)", GetOpcodeNameForLogging(uncompressedOpcode).c_str(), size, opcode, destsize);
}
//! Compresses another packet and stores it in self (source left intact)
@@ -55,14 +55,14 @@ void WorldPacket::Compress(z_stream* compressionStream, WorldPacket const* sourc
{
ASSERT(source != this);
uint16 uncompressedOpcode = source->GetOpcode();
OpcodeServer uncompressedOpcode = OpcodeServer(source->GetOpcode());
if (uncompressedOpcode & COMPRESSED_OPCODE_MASK)
{
TC_LOG_ERROR("network", "Packet with opcode 0x%04X is already compressed!", uncompressedOpcode);
return;
}
Opcodes opcode = Opcodes(uncompressedOpcode | COMPRESSED_OPCODE_MASK);
OpcodeServer opcode = OpcodeServer(uncompressedOpcode | COMPRESSED_OPCODE_MASK);
uint32 size = source->size();
uint32 destsize = compressBound(size);
@@ -79,7 +79,7 @@ void WorldPacket::Compress(z_stream* compressionStream, WorldPacket const* sourc
SetOpcode(opcode);
TC_LOG_INFO("network", "%s (len %u) successfully compressed to %04X (len %u)", GetOpcodeNameForLogging(Opcodes(uncompressedOpcode)).c_str(), size, opcode, destsize);
TC_LOG_INFO("network", "%s (len %u) successfully compressed to %04X (len %u)", GetOpcodeNameForLogging(uncompressedOpcode).c_str(), size, opcode, destsize);
}
void WorldPacket::Compress(void* dst, uint32 *dst_size, const void* src, int src_size)
+13 -8
View File
@@ -30,22 +30,22 @@ class WorldPacket : public ByteBuffer
{
public:
// just container for later use
WorldPacket() : ByteBuffer(0), m_opcode(UNKNOWN_OPCODE)
WorldPacket() : ByteBuffer(0), m_opcode(UNKNOWN_OPCODE), _connection(CONNECTION_TYPE_DEFAULT)
{
}
WorldPacket(uint16 opcode, size_t res = 200) : ByteBuffer(res),
m_opcode(opcode) { }
WorldPacket(uint16 opcode, size_t res = 200, ConnectionType connection = CONNECTION_TYPE_DEFAULT) : ByteBuffer(res),
m_opcode(opcode), _connection(connection) { }
WorldPacket(WorldPacket&& packet) : ByteBuffer(std::move(packet)), m_opcode(packet.m_opcode)
WorldPacket(WorldPacket&& packet) : ByteBuffer(std::move(packet)), m_opcode(packet.m_opcode), _connection(packet._connection)
{
}
WorldPacket(WorldPacket&& packet, std::chrono::steady_clock::time_point receivedTime) : ByteBuffer(std::move(packet)), m_opcode(packet.m_opcode), m_receivedTime(receivedTime)
WorldPacket(WorldPacket&& packet, std::chrono::steady_clock::time_point receivedTime) : ByteBuffer(std::move(packet)), m_opcode(packet.m_opcode), m_receivedTime(receivedTime), _connection(packet._connection)
{
}
WorldPacket(WorldPacket const& right) : ByteBuffer(right), m_opcode(right.m_opcode)
WorldPacket(WorldPacket const& right) : ByteBuffer(right), m_opcode(right.m_opcode), _connection(right._connection)
{
}
@@ -54,6 +54,7 @@ class WorldPacket : public ByteBuffer
if (this != &right)
{
m_opcode = right.m_opcode;
_connection = right._connection;
ByteBuffer::operator=(right);
}
@@ -65,19 +66,21 @@ class WorldPacket : public ByteBuffer
if (this != &right)
{
m_opcode = right.m_opcode;
_connection = right._connection;
ByteBuffer::operator=(std::move(right));
}
return *this;
}
WorldPacket(uint16 opcode, MessageBuffer&& buffer) : ByteBuffer(std::move(buffer)), m_opcode(opcode) { }
WorldPacket(uint16 opcode, MessageBuffer&& buffer, ConnectionType connection) : ByteBuffer(std::move(buffer)), m_opcode(opcode), _connection(connection) { }
void Initialize(uint16 opcode, size_t newres = 200)
void Initialize(uint16 opcode, size_t newres = 200, ConnectionType connection = CONNECTION_TYPE_DEFAULT)
{
clear();
_storage.reserve(newres);
m_opcode = opcode;
_connection = connection;
}
uint16 GetOpcode() const { return m_opcode; }
@@ -86,11 +89,13 @@ class WorldPacket : public ByteBuffer
void Compress(z_stream_s* compressionStream);
void Compress(z_stream_s* compressionStream, WorldPacket const* source);
ConnectionType GetConnection() const { return _connection; }
std::chrono::steady_clock::time_point GetReceivedTime() const { return m_receivedTime; }
protected:
uint16 m_opcode;
ConnectionType _connection;
void Compress(void* dst, uint32 *dst_size, const void* src, int src_size);
z_stream_s* _compressionStream;
std::chrono::steady_clock::time_point m_receivedTime; // only set for a specific set of opcodes, for performance reasons.
+96 -38
View File
@@ -23,6 +23,7 @@
#include "WorldSession.h"
#include "AccountMgr.h"
#include "AddonMgr.h"
#include "AuthenticationPackets.h"
#include "BattlegroundMgr.h"
#include "BattlenetServerManager.h"
#include "Common.h"
@@ -110,7 +111,6 @@ WorldSession::WorldSession(uint32 id, std::string&& name, uint32 battlenetAccoun
AntiDOS(this),
m_GUIDLow(0),
_player(nullptr),
m_Socket(sock),
_security(sec),
_accountId(id),
_accountName(std::move(name)),
@@ -119,7 +119,6 @@ WorldSession::WorldSession(uint32 id, std::string&& name, uint32 battlenetAccoun
_warden(nullptr),
_logoutTime(0),
m_inQueue(false),
m_playerLoading(false),
m_playerLogout(false),
m_playerRecentlyLogout(false),
m_playerSave(false),
@@ -150,15 +149,8 @@ WorldSession::WorldSession(uint32 id, std::string&& name, uint32 battlenetAccoun
LoginDatabase.PExecute("UPDATE account SET online = 1 WHERE id = %u;", GetAccountId()); // One-time query
}
_compressionStream = new z_stream();
_compressionStream->zalloc = (alloc_func)nullptr;
_compressionStream->zfree = (free_func)nullptr;
_compressionStream->opaque = (voidpf)nullptr;
_compressionStream->avail_in = 0;
_compressionStream->next_in = nullptr;
int32 z_res = deflateInit(_compressionStream, sWorld->getIntConfig(CONFIG_COMPRESSION));
if (z_res != Z_OK)
TC_LOG_ERROR("network", "Can't initialize packet compression (zlib: deflateInit) Error code: %i (%s)", z_res, zError(z_res));
m_Socket[CONNECTION_TYPE_REALM] = sock;
_instanceConnectKey.Raw = UI64LIT(0);
}
/// WorldSession destructor
@@ -166,13 +158,16 @@ WorldSession::~WorldSession()
{
///- unload player if not unloaded
if (_player)
LogoutPlayer (true);
LogoutPlayer(true);
/// - If have unclosed socket, close it
if (m_Socket)
for (uint8 i = 0; i < 2; ++i)
{
m_Socket->CloseSocket();
m_Socket = nullptr;
if (m_Socket[i])
{
m_Socket[i]->CloseSocket();
m_Socket[i].reset();
}
}
delete _warden;
@@ -184,12 +179,12 @@ WorldSession::~WorldSession()
delete packet;
LoginDatabase.PExecute("UPDATE account SET online = 0 WHERE id = %u;", GetAccountId()); // One-time query
}
int32 z_res = deflateEnd(_compressionStream);
if (z_res != Z_OK && z_res != Z_DATA_ERROR) // Z_DATA_ERROR signals that internal state was BUSY
TC_LOG_ERROR("network", "Can't close packet compression stream (zlib: deflateEnd) Error code: %i (%s)", z_res, zError(z_res));
delete _compressionStream;
bool WorldSession::PlayerDisconnected() const
{
return !(m_Socket[CONNECTION_TYPE_REALM] && m_Socket[CONNECTION_TYPE_REALM]->IsOpen() &&
m_Socket[CONNECTION_TYPE_INSTANCE] && m_Socket[CONNECTION_TYPE_INSTANCE]->IsOpen());
}
std::string const & WorldSession::GetPlayerName() const
@@ -219,9 +214,6 @@ ObjectGuid::LowType WorldSession::GetGUIDLow() const
/// Send a packet to the client
void WorldSession::SendPacket(WorldPacket const* packet, bool forced /*= false*/)
{
if (!m_Socket)
return;
if (packet->GetOpcode() == NULL_OPCODE)
{
TC_LOG_ERROR("network.opcode", "Prevented sending of NULL_OPCODE to %s", GetPlayerInfo().c_str());
@@ -233,12 +225,41 @@ void WorldSession::SendPacket(WorldPacket const* packet, bool forced /*= false*/
return;
}
ServerOpcodeHandler const* handler = opcodeTable[static_cast<OpcodeServer>(packet->GetOpcode())];
if (!handler)
{
TC_LOG_ERROR("network.opcode", "Prevented sending of opcode %u with non existing handler to %s", packet->GetOpcode(), GetPlayerInfo().c_str());
return;
}
// Default connection index defined in Opcodes.cpp table
ConnectionType conIdx = handler->ConnectionIndex;
// Override connection index
if (packet->GetConnection() != CONNECTION_TYPE_DEFAULT)
{
if (packet->GetConnection() != CONNECTION_TYPE_INSTANCE && IsInstanceOnlyOpcode(packet->GetOpcode()))
{
TC_LOG_ERROR("network.opcode", "Prevented sending of instance only opcode %u with connection type %u to %s", packet->GetOpcode(), packet->GetConnection(), GetPlayerInfo().c_str());
return;
}
conIdx = packet->GetConnection();
}
if (!m_Socket[conIdx])
{
TC_LOG_ERROR("network.opcode", "Prevented sending of %s to non existent socket %u to %s", GetOpcodeNameForLogging(static_cast<OpcodeServer>(packet->GetOpcode())).c_str(), conIdx, GetPlayerInfo().c_str());
return;
}
if (!forced)
{
OpcodeHandler const* handler = opcodeTable[static_cast<OpcodeClient>(packet->GetOpcode())];
OpcodeHandler const* handler = opcodeTable[static_cast<OpcodeServer>(packet->GetOpcode())];
if (!handler || handler->Status == STATUS_UNHANDLED)
{
TC_LOG_ERROR("network.opcode", "Prevented sending disabled opcode %s to %s", GetOpcodeNameForLogging(static_cast<OpcodeClient>(packet->GetOpcode())).c_str(), GetPlayerInfo().c_str());
TC_LOG_ERROR("network.opcode", "Prevented sending disabled opcode %s to %s", GetOpcodeNameForLogging(static_cast<OpcodeServer>(packet->GetOpcode())).c_str(), GetPlayerInfo().c_str());
return;
}
}
@@ -280,7 +301,7 @@ void WorldSession::SendPacket(WorldPacket const* packet, bool forced /*= false*/
sScriptMgr->OnPacketSend(this, *packet);
TC_LOG_TRACE("network.opcode", "S->C: %s %s", GetPlayerInfo().c_str(), GetOpcodeNameForLogging(static_cast<OpcodeClient>(packet->GetOpcode())).c_str());
m_Socket->SendPacket(*packet);
m_Socket[conIdx]->SendPacket(*packet);
}
/// Add an incoming packet to the queue
@@ -316,7 +337,7 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater)
///- Before we process anything:
/// If necessary, kick the player from the character select screen
if (IsConnectionIdle() && !HasPermission(rbac::RBAC_PERM_IGNORE_IDLE_CONNECTION))
m_Socket->CloseSocket();
m_Socket[CONNECTION_TYPE_REALM]->CloseSocket();
///- Retrieve packets from the receive queue and call the appropriate handlers
/// not process packets if socket already closed
@@ -327,7 +348,7 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater)
uint32 processedPackets = 0;
time_t currentTime = time(nullptr);
while (m_Socket && _recvQueue.next(packet, updater))
while (m_Socket[CONNECTION_TYPE_REALM] && _recvQueue.next(packet, updater))
{
ClientOpcodeHandler const* opHandle = opcodeTable[static_cast<OpcodeClient>(packet->GetOpcode())];
try
@@ -440,7 +461,7 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater)
_recvQueue.readd(requeuePackets.begin(), requeuePackets.end());
if (m_Socket && m_Socket->IsOpen() && _warden)
if (m_Socket[0] && m_Socket[0]->IsOpen() && _warden)
_warden->Update();
if (!updater.ProcessUnsafe()) // <=> updater is of type MapSessionFilter
@@ -463,23 +484,32 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater)
{
time_t currTime = time(nullptr);
///- If necessary, log the player out
if (ShouldLogOut(currTime) && !m_playerLoading)
if (ShouldLogOut(currTime) && m_playerLoading.IsEmpty())
LogoutPlayer(true);
if (m_Socket && GetPlayer() && _warden)
if (m_Socket[CONNECTION_TYPE_REALM] && GetPlayer() && _warden)
_warden->Update();
///- Cleanup socket pointer if need
if (m_Socket && !m_Socket->IsOpen())
if ((m_Socket[0] && !m_Socket[0]->IsOpen()) || (m_Socket[1] && !m_Socket[1]->IsOpen()))
{
expireTime -= expireTime > diff ? diff : expireTime;
if (expireTime < diff || forceExit || !GetPlayer())
{
m_Socket = nullptr;
if (m_Socket[CONNECTION_TYPE_REALM])
{
m_Socket[CONNECTION_TYPE_REALM]->CloseSocket();
m_Socket[CONNECTION_TYPE_REALM].reset();
}
if (m_Socket[CONNECTION_TYPE_INSTANCE])
{
m_Socket[CONNECTION_TYPE_INSTANCE]->CloseSocket();
m_Socket[CONNECTION_TYPE_INSTANCE].reset();
}
}
}
if (!m_Socket)
if (!m_Socket[CONNECTION_TYPE_REALM])
return false; //Will remove this session from the world session map
}
@@ -589,7 +619,7 @@ void WorldSession::LogoutPlayer(bool save)
// remove player from the group if he is:
// a) in group; b) not in raid group; c) logging out normally (not being kicked or disconnected)
if (_player->GetGroup() && !_player->GetGroup()->isRaidGroup() && m_Socket)
if (_player->GetGroup() && !_player->GetGroup()->isRaidGroup() && m_Socket[CONNECTION_TYPE_REALM])
_player->RemoveFromGroup();
//! Send update to group and reset stored max enchanting level
@@ -635,6 +665,12 @@ void WorldSession::LogoutPlayer(bool save)
CharacterDatabase.Execute(stmt);
}
if (m_Socket[CONNECTION_TYPE_INSTANCE])
{
m_Socket[CONNECTION_TYPE_INSTANCE]->CloseSocket();
m_Socket[CONNECTION_TYPE_INSTANCE].reset();
}
m_playerLogout = false;
m_playerSave = false;
m_playerRecentlyLogout = true;
@@ -644,10 +680,13 @@ void WorldSession::LogoutPlayer(bool save)
/// Kick a player out of the World
void WorldSession::KickPlayer()
{
if (m_Socket)
for (uint8 i = 0; i < 2; ++i)
{
m_Socket->CloseSocket();
forceExit = true;
if (m_Socket[i])
{
m_Socket[i]->CloseSocket();
forceExit = true;
}
}
}
@@ -726,6 +765,25 @@ void WorldSession::Handle_Deprecated(WorldPacket& recvPacket)
, GetOpcodeNameForLogging(static_cast<OpcodeClient>(recvPacket.GetOpcode())).c_str(), GetPlayerInfo().c_str());
}
void WorldSession::SendConnectToInstance(WorldPackets::Auth::ConnectToSerial serial)
{
boost::system::error_code ignored_error;
boost::asio::ip::tcp::endpoint instanceAddress = realm.GetAddressForClient(boost::asio::ip::make_address(GetRemoteAddress(), ignored_error));
instanceAddress.port(sWorld->getIntConfig(CONFIG_PORT_INSTANCE));
_instanceConnectKey.Fields.AccountId = GetAccountId();
_instanceConnectKey.Fields.ConnectionType = CONNECTION_TYPE_INSTANCE;
_instanceConnectKey.Fields.Key = urand(0, 0x7FFFFFFF);
WorldPackets::Auth::ConnectTo connectTo;
connectTo.Key = _instanceConnectKey.Raw;
connectTo.Serial = serial;
connectTo.Payload.Where = instanceAddress;
connectTo.Con = CONNECTION_TYPE_INSTANCE;
SendPacket(connectTo.Write());
}
void WorldSession::SendAuthWaitQue(uint32 position)
{
if (position == 0)
+29 -9
View File
@@ -56,7 +56,6 @@ struct DeclinedName;
struct ItemTemplate;
struct MovementInfo;
struct TradeStatusInfo;
struct z_stream_s;
namespace lfg
{
@@ -77,6 +76,11 @@ class RBACData;
namespace WorldPackets
{
namespace Auth
{
enum class ConnectToSerial : uint32;
}
namespace LFG
{
class LFGJoin;
@@ -332,17 +336,18 @@ class TC_GAME_API WorldSession
WorldSession(uint32 id, std::string&& name, uint32 battlenetAccountId, std::shared_ptr<WorldSocket> sock, AccountTypes sec, uint8 expansion, time_t mute_time, LocaleConstant locale, uint32 recruiter, bool isARecruiter);
~WorldSession();
bool PlayerLoading() const { return m_playerLoading; }
bool PlayerLoading() const { return !m_playerLoading.IsEmpty(); }
bool PlayerLogout() const { return m_playerLogout; }
bool PlayerLogoutWithSave() const { return m_playerLogout && m_playerSave; }
bool PlayerRecentlyLoggedOut() const { return m_playerRecentlyLogout; }
bool PlayerDisconnected() const { return !m_Socket; }
bool PlayerDisconnected() const;
void ReadAddonsInfo(ByteBuffer& data);
void SendAddonsInfo();
bool IsAddonRegistered(const std::string& prefix) const;
void SendPacket(WorldPacket const* packet, bool forced = false);
void AddInstanceConnection(std::shared_ptr<WorldSocket> sock) { m_Socket[1] = sock; }
void SendNotification(const char *format, ...) ATTR_PRINTF(2, 3);
void SendNotification(uint32 string_id, ...);
void SendPetNameInvalid(uint32 error, std::string const& name, DeclinedName *declinedName);
@@ -401,6 +406,7 @@ class TC_GAME_API WorldSession
void QueuePacket(WorldPacket* new_packet);
bool Update(uint32 diff, PacketFilter& updater);
void SendConnectToInstance(WorldPackets::Auth::ConnectToSerial serial);
/// Handle the authentication waiting queue (to be completed)
void SendAuthWaitQue(uint32 position);
@@ -513,8 +519,6 @@ class TC_GAME_API WorldSession
uint32 GetRecruiterId() const { return recruiterId; }
bool IsARecruiter() const { return isRecruiter; }
z_stream_s* GetCompressionStream() { return _compressionStream; }
// Time Synchronisation
void ResetTimeSync();
void SendTimeSync();
@@ -530,6 +534,7 @@ class TC_GAME_API WorldSession
void HandleCharDeleteOpcode(WorldPacket& recvPacket);
void HandleCharCreateOpcode(WorldPacket& recvPacket);
void HandlePlayerLoginOpcode(WorldPacket& recvPacket);
void HandleContinuePlayerLogin();
void HandleLoadScreenOpcode(WorldPacket& recvPacket);
void HandleCharEnum(PreparedQueryResult result);
void HandlePlayerLogin(LoginQueryHolder* holder);
@@ -1126,6 +1131,20 @@ class TC_GAME_API WorldSession
void HandleRequestResearchHistory(WorldPacket& recv_data);
int32 HandleEnableNagleAlgorithm();
union ConnectToKey
{
struct
{
uint64 AccountId : 32;
uint64 ConnectionType : 1;
uint64 Key : 31;
} Fields;
uint64 Raw;
};
uint64 GetConnectToInstanceKey() const { return _instanceConnectKey.Raw; }
public:
QueryCallbackProcessor& GetQueryProcessor() { return _queryProcessor; }
@@ -1194,7 +1213,7 @@ class TC_GAME_API WorldSession
ObjectGuid::LowType m_GUIDLow; // set logined or recently logout player (while m_playerRecentlyLogout set)
Player* _player;
std::shared_ptr<WorldSocket> m_Socket;
std::shared_ptr<WorldSocket> m_Socket[2];
std::string m_Address; // Current Remote Address
// std::string m_LAddress; // Last Attempted Remote Adress - we can not set attempted ip for a non-existing session!
@@ -1209,7 +1228,7 @@ class TC_GAME_API WorldSession
time_t _logoutTime;
bool m_inQueue; // session wait in auth.queue
bool m_playerLoading; // code processed in LoginPlayer
ObjectGuid m_playerLoading; // code processed in LoginPlayer
bool m_playerLogout; // code processed in LogoutPlayer
bool m_playerRecentlyLogout;
bool m_playerSave;
@@ -1245,7 +1264,6 @@ class TC_GAME_API WorldSession
uint32 recruiterId;
bool isRecruiter;
LockedQueue<WorldPacket*> _recvQueue;
z_stream_s* _compressionStream;
rbac::RBACData* _RBACData;
uint32 expireTime;
bool forceExit;
@@ -1259,6 +1277,8 @@ class TC_GAME_API WorldSession
uint32 _timeSyncNextCounter;
uint32 _timeSyncTimer;
ConnectToKey _instanceConnectKey;
WorldSession(WorldSession const& right) = delete;
WorldSession& operator=(WorldSession const& right) = delete;
};
+146 -64
View File
@@ -16,6 +16,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AuthenticationPackets.h"
#include "WorldSocket.h"
#include "BattlenetAccountMgr.h"
#include "BigNumber.h"
@@ -30,6 +31,7 @@
#include "ScriptMgr.h"
#include "SHA1.h"
#include "World.h"
#include <zlib.h>
#include <memory>
class EncryptablePacket : public WorldPacket
@@ -46,16 +48,25 @@ private:
using boost::asio::ip::tcp;
std::string const WorldSocket::ServerConnectionInitialize("WORLD OF WARCRAFT CONNECTION - SERVER TO CLIENT");
std::string const WorldSocket::ClientConnectionInitialize("WORLD OF WARCRAFT CONNECTION - CLIENT TO SERVER");
WorldSocket::WorldSocket(tcp::socket&& socket)
: Socket(std::move(socket)), _authSeed(rand32()), _OverSpeedPings(0), _worldSession(nullptr), _sendBufferSize(4096), _initialized(false)
WorldSocket::WorldSocket(tcp::socket&& socket) : Socket(std::move(socket)),
_authSeed(rand32()), _OverSpeedPings(0), _worldSession(nullptr), _authed(false),
_sendBufferSize(4096), _initialized(false), _type(CONNECTION_TYPE_REALM),
_compressionStream(nullptr)
{
_headerBuffer.Resize(2);
}
WorldSocket::~WorldSocket()
{
if (_compressionStream)
{
deflateEnd(_compressionStream);
delete _compressionStream;
}
}
void WorldSocket::Start()
{
std::string ip_address = GetRemoteIpAddress().to_string();
@@ -104,8 +115,8 @@ bool WorldSocket::Update()
MessageBuffer buffer(_sendBufferSize);
while (_bufferQueue.Dequeue(queued))
{
if (_worldSession && queued->size() > 0x400 && !queued->IsCompressed())
queued->Compress(_worldSession->GetCompressionStream());
if (queued->size() > 0x400 && !queued->IsCompressed())
queued->Compress(_compressionStream);
ServerPktHeader header(queued->size() + 2, queued->GetOpcode());
if (queued->NeedsEncryption())
@@ -150,13 +161,11 @@ bool WorldSocket::Update()
void WorldSocket::HandleSendAuthSession()
{
WorldPacket packet(SMSG_AUTH_CHALLENGE, 37);
BigNumber seed1;
seed1.SetRand(16 * 8);
packet.append(seed1.AsByteArray(16).get(), 16); // new encryption seeds
_encryptSeed.SetRand(16 * 8);
_decryptSeed.SetRand(16 * 8);
BigNumber seed2;
seed2.SetRand(16 * 8);
packet.append(seed2.AsByteArray(16).get(), 16); // new encryption seeds
packet.append(_encryptSeed.AsByteArray(16).get(), 16); // new encryption seeds
packet.append(_decryptSeed.AsByteArray(16).get(), 16); // new encryption seeds
packet << uint32(_authSeed);
packet << uint8(1);
@@ -232,6 +241,13 @@ void WorldSocket::ReadHandler()
AsyncRead();
}
void WorldSocket::SetWorldSession(WorldSession* session)
{
std::lock_guard<std::mutex> sessionGuard(_worldSessionLock);
_worldSession = session;
_authed = true;
}
bool WorldSocket::ReadHeaderHandler()
{
ASSERT(_headerBuffer.GetActiveSize() == (_initialized ? sizeof(ClientPktHeader) : 2));
@@ -338,7 +354,7 @@ WorldSocket::ReadDataHandlerResult WorldSocket::ReadDataHandler()
OpcodeClient opcode = static_cast<OpcodeClient>(header->cmd);
WorldPacket packet(opcode, std::move(_packetBuffer));
WorldPacket packet(opcode, std::move(_packetBuffer), GetConnectionType());
WorldPacket* packetToQueue;
if (sPacketLog->CanLogPacket())
@@ -364,7 +380,7 @@ WorldSocket::ReadDataHandlerResult WorldSocket::ReadDataHandler()
case CMSG_AUTH_SESSION:
{
LogOpcodeText(opcode, sessionGuard);
if (_worldSession)
if (_authed)
{
// locking just to safely log offending user is probably overkill but we are disconnecting him anyway
if (sessionGuard.try_lock())
@@ -374,7 +390,9 @@ WorldSocket::ReadDataHandlerResult WorldSocket::ReadDataHandler()
try
{
HandleAuthSession(packet);
WorldPackets::Auth::AuthSession authSession(std::move(packet));
authSession.Read();
HandleAuthSession(authSession);
return ReadDataHandlerResult::WaitingForQuery;
}
catch (ByteBufferException const&)
@@ -383,13 +401,37 @@ WorldSocket::ReadDataHandlerResult WorldSocket::ReadDataHandler()
TC_LOG_ERROR("network", "WorldSocket::ReadDataHandler(): client %s sent malformed CMSG_AUTH_SESSION", GetRemoteIpAddress().to_string().c_str());
return ReadDataHandlerResult::Error;
}
case CMSG_AUTH_CONTINUED_SESSION:
{
LogOpcodeText(opcode, sessionGuard);
if (_authed)
{
// locking just to safely log offending user is probably overkill but we are disconnecting him anyway
if (sessionGuard.try_lock())
TC_LOG_ERROR("network", "WorldSocket::ProcessIncoming: received duplicate CMSG_AUTH_CONTINUED_SESSION from %s", _worldSession->GetPlayerInfo().c_str());
return ReadDataHandlerResult::Error;
}
try
{
std::shared_ptr<WorldPackets::Auth::AuthContinuedSession> authSession = std::make_shared<WorldPackets::Auth::AuthContinuedSession>(std::move(packet));
authSession->Read();
HandleAuthContinuedSession(authSession);
return ReadDataHandlerResult::WaitingForQuery;
}
catch (ByteBufferException const&)
{
}
TC_LOG_ERROR("network", "WorldSocket::ReadDataHandler(): client %s sent malformed CMSG_AUTH_CONTINUED_SESSION", GetRemoteIpAddress().to_string().c_str());
return ReadDataHandlerResult::Error;
}
case CMSG_LOG_DISCONNECT:
packet.rfinish(); // contains uint32 disconnectReason;
TC_LOG_DEBUG("network", "%s", GetOpcodeNameForLogging(opcode).c_str());
LogOpcodeText(opcode, sessionGuard);
sScriptMgr->OnPacketReceive(_worldSession, packet);
return ReadDataHandlerResult::Ok;
case CMSG_ENABLE_NAGLE:
TC_LOG_DEBUG("network", "%s", GetOpcodeNameForLogging(opcode).c_str());
LogOpcodeText(opcode, sessionGuard);
sScriptMgr->OnPacketReceive(_worldSession, packet);
if (_worldSession)
_worldSession->HandleEnableNagleAlgorithm();
@@ -446,6 +488,20 @@ WorldSocket::ReadDataHandlerResult WorldSocket::ReadDataHandler()
return ReadDataHandlerResult::Error;
}
_compressionStream = new z_stream();
_compressionStream->zalloc = (alloc_func)nullptr;
_compressionStream->zfree = (free_func)nullptr;
_compressionStream->opaque = (voidpf)nullptr;
_compressionStream->avail_in = 0;
_compressionStream->next_in = nullptr;
int32 z_res = deflateInit(_compressionStream, sWorld->getIntConfig(CONFIG_COMPRESSION));
if (z_res != Z_OK)
{
TC_LOG_ERROR("network", "Can't initialize packet compression (zlib: deflateInit) Error code: %i (%s)", z_res, zError(z_res));
CloseSocket();
return ReadDataHandlerResult::Error;
}
_initialized = true;
_headerBuffer.Resize(sizeof(ClientPktHeader));
_packetBuffer.Reset();
@@ -485,58 +541,22 @@ void WorldSocket::SendPacket(WorldPacket const& packet)
_bufferQueue.Enqueue(new EncryptablePacket(packet, _authCrypt.IsInitialized()));
}
void WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
void WorldSocket::HandleAuthSession(WorldPackets::Auth::AuthSession& authSession)
{
uint32 addonSize;
std::shared_ptr<AuthSession> authSession = std::make_shared<AuthSession>();
recvPacket.read_skip<uint32>(); // ServerId - Used for GRUNT only
recvPacket.read_skip<uint32>(); // Battlegroup
recvPacket >> authSession->LoginServerType;
recvPacket >> authSession->Digest[10];
recvPacket >> authSession->Digest[18];
recvPacket >> authSession->Digest[12];
recvPacket >> authSession->Digest[5];
recvPacket.read_skip<uint64>();
recvPacket >> authSession->Digest[15];
recvPacket >> authSession->Digest[9];
recvPacket >> authSession->Digest[19];
recvPacket >> authSession->Digest[4];
recvPacket >> authSession->Digest[7];
recvPacket >> authSession->Digest[16];
recvPacket >> authSession->Digest[3];
recvPacket >> authSession->Build;
recvPacket >> authSession->Digest[8];
recvPacket >> authSession->RealmID;
recvPacket.read_skip<uint8>();
recvPacket >> authSession->Digest[17];
recvPacket >> authSession->Digest[6];
recvPacket >> authSession->Digest[0];
recvPacket >> authSession->Digest[1];
recvPacket >> authSession->Digest[11];
recvPacket >> authSession->LocalChallenge;
recvPacket >> authSession->Digest[2];
recvPacket.read_skip<uint32>(); // Region
recvPacket >> authSession->Digest[14];
recvPacket >> authSession->Digest[13];
recvPacket >> addonSize;
if (addonSize)
{
authSession->AddonInfo.resize(addonSize);
recvPacket.read((uint8*)authSession->AddonInfo.contents(), addonSize);
}
recvPacket.ReadBit(); // UseIPv6
uint32 accountNameLength = recvPacket.ReadBits(12);
authSession->Account = recvPacket.ReadString(accountNameLength);
std::shared_ptr<AuthSession> session = std::make_shared<AuthSession>();
session->AddonInfo = authSession.AddonInfo;
session->Account = authSession.Account;
session->Build = authSession.Build;
memcpy(session->Digest, authSession.Digest, SHA_DIGEST_LENGTH);
session->LocalChallenge = authSession.LocalChallenge;
session->LoginServerType = authSession.LoginServerType;
session->RealmID = authSession.RealmID;
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_INFO_BY_NAME);
stmt->setInt32(0, int32(realm.Id.Realm));
stmt->setString(1, authSession->Account);
stmt->setString(1, session->Account);
_queryProcessor.AddQuery(LoginDatabase.AsyncQuery(stmt).WithPreparedCallback(std::bind(&WorldSocket::HandleAuthSessionCallback, this, authSession, std::placeholders::_1)));
_queryProcessor.AddQuery(LoginDatabase.AsyncQuery(stmt).WithPreparedCallback(std::bind(&WorldSocket::HandleAuthSessionCallback, this, session, std::placeholders::_1)));
}
void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<AuthSession> authSession, PreparedQueryResult result)
@@ -686,6 +706,7 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<AuthSession> authSes
// At this point, we can safely hook a successful login
sScriptMgr->OnAccountLogin(account.Game.Id);
_authed = true;
_worldSession = new WorldSession(account.Game.Id, std::move(authSession->Account), account.BattleNet.Id, shared_from_this(), account.Game.Security,
account.Game.Expansion, mutetime, account.BattleNet.Locale, account.Game.Recruiter, account.Game.IsRecruiter);
_worldSession->ReadAddonsInfo(authSession->AddonInfo);
@@ -706,6 +727,67 @@ void WorldSocket::LoadSessionPermissionsCallback(PreparedQueryResult result)
sWorld->AddSession(_worldSession);
}
void WorldSocket::HandleAuthContinuedSession(std::shared_ptr<WorldPackets::Auth::AuthContinuedSession> authSession)
{
WorldSession::ConnectToKey key;
key.Raw = authSession->Key;
_type = ConnectionType(key.Fields.ConnectionType);
if (_type != CONNECTION_TYPE_INSTANCE)
{
SendAuthResponseError(AUTH_UNKNOWN_ACCOUNT);
DelayedCloseSocket();
return;
}
// Client switches packet headers after sending CMSG_AUTH_CONTINUED_SESSION
_headerBuffer.Resize(sizeof(ClientPktHeader));
uint32 accountId = uint32(key.Fields.AccountId);
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_INFO_CONTINUED_SESSION);
stmt->setUInt32(0, accountId);
_queryProcessor.AddQuery(LoginDatabase.AsyncQuery(stmt).WithPreparedCallback(std::bind(&WorldSocket::HandleAuthContinuedSessionCallback, this, authSession, std::placeholders::_1)));
}
void WorldSocket::HandleAuthContinuedSessionCallback(std::shared_ptr<WorldPackets::Auth::AuthContinuedSession> authSession, PreparedQueryResult result)
{
if (!result)
{
SendAuthResponseError(AUTH_UNKNOWN_ACCOUNT);
DelayedCloseSocket();
return;
}
WorldSession::ConnectToKey key;
key.Raw = authSession->Key;
uint32 accountId = uint32(key.Fields.AccountId);
Field* fields = result->Fetch();
std::string login = fields[0].GetString();
BigNumber k;
k.SetHexStr(fields[1].GetCString());
_authCrypt.Init(&k, _encryptSeed.AsByteArray().get(), _decryptSeed.AsByteArray().get());
SHA1Hash sha;
sha.UpdateData(login);
sha.UpdateBigNumbers(&k, nullptr);
sha.UpdateData((uint8*)&_authSeed, 4);
sha.Finalize();
if (memcmp(sha.GetDigest(), authSession->Digest, sha.GetLength()))
{
SendAuthResponseError(AUTH_UNKNOWN_ACCOUNT);
TC_LOG_ERROR("network", "WorldSocket::HandleAuthContinuedSession: Authentication failed for account: %u ('%s') address: %s", accountId, login.c_str(), GetRemoteIpAddress().to_string().c_str());
DelayedCloseSocket();
return;
}
sWorld->AddInstanceSocket(shared_from_this(), authSession->Key);
AsyncRead();
}
void WorldSocket::SendAuthResponseError(uint8 code)
{
WorldPacket packet(SMSG_AUTH_RESPONSE, 1);
+26 -4
View File
@@ -19,6 +19,7 @@
#ifndef __WORLDSOCKET_H__
#define __WORLDSOCKET_H__
#include "BigNumber.h"
#include "Common.h"
#include "WorldPacketCrypt.h"
#include "ServerPktHeader.h"
@@ -33,9 +34,17 @@
using boost::asio::ip::tcp;
class EncryptablePacket;
struct z_stream_s;
namespace WorldPackets
{
class ServerPacket;
namespace Auth
{
class AuthSession;
class AuthContinuedSession;
class ConnectToFailed;
}
}
#pragma pack(push, 1)
@@ -56,13 +65,13 @@ struct AuthSession;
class TC_GAME_API WorldSocket : public Socket<WorldSocket>
{
static std::string const ServerConnectionInitialize;
static std::string const ClientConnectionInitialize;
typedef Socket<WorldSocket> BaseSocket;
public:
WorldSocket(tcp::socket&& socket);
~WorldSocket();
WorldSocket(WorldSocket const& right) = delete;
WorldSocket& operator=(WorldSocket const& right) = delete;
@@ -71,9 +80,13 @@ public:
bool Update() override;
void SendPacket(WorldPacket const& packet);
void SetSendBufferSize(std::size_t sendBufferSize) { _sendBufferSize = sendBufferSize; }
ConnectionType GetConnectionType() const { return _type; }
void SendAuthResponseError(uint8 code);
void SetWorldSession(WorldSession* session);
protected:
void OnClose() override;
void ReadHandler() override;
@@ -97,24 +110,33 @@ private:
/// sends and logs network.opcode without accessing WorldSession
void SendPacketAndLogOpcode(WorldPacket& packet);
void HandleSendAuthSession();
void HandleAuthSession(WorldPacket& recvPacket);
void HandleAuthSession(WorldPackets::Auth::AuthSession& authSession);
void HandleAuthContinuedSession(std::shared_ptr<WorldPackets::Auth::AuthContinuedSession> authSession);
void HandleAuthContinuedSessionCallback(std::shared_ptr<WorldPackets::Auth::AuthContinuedSession> authSession, PreparedQueryResult result);
void HandleAuthSessionCallback(std::shared_ptr<AuthSession> authSession, PreparedQueryResult result);
void LoadSessionPermissionsCallback(PreparedQueryResult result);
void SendAuthResponseError(uint8 code);
bool HandlePing(WorldPacket& recvPacket);
ConnectionType _type;
uint32 _authSeed;
WorldPacketCrypt _authCrypt;
BigNumber _encryptSeed;
BigNumber _decryptSeed;
std::chrono::steady_clock::time_point _LastPingTime;
uint32 _OverSpeedPings;
std::mutex _worldSessionLock;
WorldSession* _worldSession;
bool _authed;
MessageBuffer _headerBuffer;
MessageBuffer _packetBuffer;
z_stream_s* _compressionStream;
MPSCQueue<EncryptablePacket> _bufferQueue;
std::size_t _sendBufferSize;
+33 -1
View File
@@ -44,10 +44,15 @@ public:
}
};
WorldSocketMgr::WorldSocketMgr() : BaseSocketMgr(), _socketSystemSendBufferSize(-1), _socketApplicationSendBufferSize(65536), _tcpNoDelay(true)
WorldSocketMgr::WorldSocketMgr() : BaseSocketMgr(), _instanceAcceptor(nullptr), _socketSystemSendBufferSize(-1), _socketApplicationSendBufferSize(65536), _tcpNoDelay(true)
{
}
WorldSocketMgr::~WorldSocketMgr()
{
ASSERT(!_instanceAcceptor, "StopNetwork must be called prior to WorldSocketMgr destruction");
}
WorldSocketMgr& WorldSocketMgr::Instance()
{
static WorldSocketMgr instance;
@@ -75,9 +80,30 @@ bool WorldSocketMgr::StartWorldNetwork(Trinity::Asio::IoContext& ioContext, std:
if (!BaseSocketMgr::StartNetwork(ioContext, bindIp, port, threadCount))
return false;
AsyncAcceptor* instanceAcceptor = nullptr;
try
{
instanceAcceptor = new AsyncAcceptor(ioContext, bindIp, sWorld->getIntConfig(CONFIG_PORT_INSTANCE));
}
catch (boost::system::system_error const& err)
{
TC_LOG_ERROR("network", "Exception caught in WorldSocketMgr::StartNetwork (%s:%u): %s", bindIp.c_str(), port, err.what());
return false;
}
if (!instanceAcceptor->Bind())
{
TC_LOG_ERROR("network", "StartNetwork failed to bind instance socket acceptor");
return false;
}
_instanceAcceptor = instanceAcceptor;
_acceptor->SetSocketFactory(std::bind(&BaseSocketMgr::GetSocketForAccept, this));
_instanceAcceptor->SetSocketFactory(std::bind(&BaseSocketMgr::GetSocketForAccept, this));
_acceptor->AsyncAcceptWithCallback<&OnSocketAccept>();
_instanceAcceptor->AsyncAcceptWithCallback<&OnSocketAccept>();
sScriptMgr->OnNetworkStart();
return true;
@@ -85,8 +111,14 @@ bool WorldSocketMgr::StartWorldNetwork(Trinity::Asio::IoContext& ioContext, std:
void WorldSocketMgr::StopNetwork()
{
if (_instanceAcceptor)
_instanceAcceptor->Close();
BaseSocketMgr::StopNetwork();
delete _instanceAcceptor;
_instanceAcceptor = nullptr;
sScriptMgr->OnNetworkStop();
}
+3
View File
@@ -35,6 +35,8 @@ class TC_GAME_API WorldSocketMgr : public SocketMgr<WorldSocket>
typedef SocketMgr<WorldSocket> BaseSocketMgr;
public:
~WorldSocketMgr();
static WorldSocketMgr& Instance();
/// Start network, listen at address:port .
@@ -53,6 +55,7 @@ protected:
NetworkThread<WorldSocket>* CreateThreads() const override;
private:
AsyncAcceptor* _instanceAcceptor;
int32 _socketSystemSendBufferSize;
int32 _socketApplicationSendBufferSize;
bool _tcpNoDelay;
+42 -1
View File
@@ -87,6 +87,7 @@
#include "WeatherMgr.h"
#include "WhoListStorage.h"
#include "WorldSession.h"
#include "WorldSocket.h"
#include <boost/asio/ip/address.hpp>
@@ -302,6 +303,11 @@ void World::AddSession(WorldSession* s)
addSessQueue.add(s);
}
void World::AddInstanceSocket(std::weak_ptr<WorldSocket> sock, uint64 connectToKey)
{
_linkSocketQueue.add(std::make_pair(sock, connectToKey));
}
void World::AddSession_(WorldSession* s)
{
ASSERT(s);
@@ -368,6 +374,30 @@ void World::AddSession_(WorldSession* s)
}
}
void World::ProcessLinkInstanceSocket(std::pair<std::weak_ptr<WorldSocket>, uint64> linkInfo)
{
if (std::shared_ptr<WorldSocket> sock = linkInfo.first.lock())
{
if (!sock->IsOpen())
return;
WorldSession::ConnectToKey key;
key.Raw = linkInfo.second;
WorldSession* session = FindSession(uint32(key.Fields.AccountId));
if (!session || session->GetConnectToInstanceKey() != linkInfo.second)
{
sock->SendAuthResponseError(AUTH_SESSION_EXPIRED);
sock->DelayedCloseSocket();
return;
}
sock->SetWorldSession(session);
session->AddInstanceConnection(sock);
session->HandleContinuePlayerLogin();
}
}
bool World::HasRecentlyDisconnected(WorldSession* session)
{
if (!session)
@@ -729,9 +759,16 @@ void World::LoadConfigSettings(bool reload)
uint32 val = sConfigMgr->GetIntDefault("WorldServerPort", 8085);
if (val != m_int_configs[CONFIG_PORT_WORLD])
TC_LOG_ERROR("server.loading", "WorldServerPort option can't be changed at worldserver.conf reload, using current value (%u).", m_int_configs[CONFIG_PORT_WORLD]);
val = sConfigMgr->GetIntDefault("InstanceServerPort", 8086);
if (val != m_int_configs[CONFIG_PORT_INSTANCE])
TC_LOG_ERROR("server.loading", "InstanceServerPort option can't be changed at worldserver.conf reload, using current value (%u).", m_int_configs[CONFIG_PORT_INSTANCE]);
}
else
{
m_int_configs[CONFIG_PORT_WORLD] = sConfigMgr->GetIntDefault("WorldServerPort", 8085);
m_int_configs[CONFIG_PORT_INSTANCE] = sConfigMgr->GetIntDefault("InstanceServerPort", 8086);
}
m_int_configs[CONFIG_SOCKET_TIMEOUTTIME] = sConfigMgr->GetIntDefault("SocketTimeOutTime", 900000);
m_int_configs[CONFIG_SESSION_ADD_DELAY] = sConfigMgr->GetIntDefault("SessionAddDelay", 10000);
@@ -3027,10 +3064,14 @@ void World::SendServerMessage(ServerMessageType type, const char *text, Player*
void World::UpdateSessions(uint32 diff)
{
std::pair<std::weak_ptr<WorldSocket>, uint64> linkInfo;
while (_linkSocketQueue.next(linkInfo))
ProcessLinkInstanceSocket(std::move(linkInfo));
///- Add new sessions
WorldSession* sess = nullptr;
while (addSessQueue.next(sess))
AddSession_ (sess);
AddSession_(sess);
///- Then send an update signal to remaining ones
for (SessionMap::iterator itr = m_sessions.begin(), next; itr != m_sessions.end(); itr = next)
+5
View File
@@ -223,6 +223,7 @@ enum WorldIntConfigs
CONFIG_INTERVAL_CHANGEWEATHER,
CONFIG_INTERVAL_DISCONNECT_TOLERANCE,
CONFIG_PORT_WORLD,
CONFIG_PORT_INSTANCE,
CONFIG_SOCKET_TIMEOUTTIME,
CONFIG_SESSION_ADD_DELAY,
CONFIG_GAME_TYPE,
@@ -613,6 +614,7 @@ class TC_GAME_API World
WorldSession* FindSession(uint32 id) const;
void AddSession(WorldSession* s);
void AddInstanceSocket(std::weak_ptr<WorldSocket> sock, uint64 connectToKey);
void SendAutoBroadcast();
bool RemoveSession(uint32 id);
/// Get the number of current active sessions
@@ -901,6 +903,9 @@ class TC_GAME_API World
void AddSession_(WorldSession* s);
LockedQueue<WorldSession*> addSessQueue;
void ProcessLinkInstanceSocket(std::pair<std::weak_ptr<WorldSocket>, uint64> linkInfo);
LockedQueue<std::pair<std::weak_ptr<WorldSocket>, uint64>> _linkSocketQueue;
// used versions
std::string m_DBVersion;
+1 -1
View File
@@ -362,7 +362,7 @@ public:
uint32 opcode;
parsedStream >> opcode;
WorldPacket data(Opcodes(opcode), 0);
WorldPacket data(opcode, 0);
while (!parsedStream.eof())
{
@@ -150,6 +150,13 @@ MaxPingTime = 30
WorldServerPort = 8085
#
# InstanceServerPort
# Description: TCP port to for second world connection.
# Default: 8086
InstanceServerPort = 8086
#
# BindIP
# Description: Bind world server to IP/hostname.