本文整理汇总了C++中WorldPacket::read方法的典型用法代码示例。如果您正苦于以下问题:C++ WorldPacket::read方法的具体用法?C++ WorldPacket::read怎么用?C++ WorldPacket::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorldPacket
的用法示例。
在下文中一共展示了WorldPacket::read方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleAuthSession
void WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
{
std::shared_ptr<AuthSession> authSession = std::make_shared<AuthSession>();
// Read the content of the packet
recvPacket >> authSession->Build;
recvPacket >> authSession->LoginServerID;
recvPacket >> authSession->Account;
recvPacket >> authSession->LoginServerType;
recvPacket >> authSession->LocalChallenge;
recvPacket >> authSession->RegionID;
recvPacket >> authSession->BattlegroupID;
recvPacket >> authSession->RealmID; // realmId from auth_database.realmlist table
recvPacket >> authSession->DosResponse;
recvPacket.read(authSession->Digest, 20);
authSession->AddonInfo.append(recvPacket.contents() + recvPacket.rpos(), recvPacket.size() - recvPacket.rpos());
// Get the account information from the auth database
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_INFO_BY_NAME);
stmt->setInt32(0, int32(realmID));
stmt->setString(1, authSession->Account);
{
std::lock_guard<std::mutex> guard(_queryLock);
_queryCallback = io_service().wrap(std::bind(&WorldSocket::HandleAuthSessionCallback, this, authSession, std::placeholders::_1));
_queryFuture = LoginDatabase.AsyncQuery(stmt);
}
}
示例2: PostPluginMessage
void PostPluginMessage(WorldPacket & data)
{
// we need to move this into a struct
PluginMessage * msg = new PluginMessage;
msg->DataLen = data.size();
msg->Data = new uint8[data.size()];
data.read((uint8*)msg->Data, data.size());
//msg->Data = new uint8[data.size()];
//memcpy((uint8*)msg->Data, data.contents(), data.size());
msg->Opcode = data.GetOpcode();
// tell scriptmgr to distribute it to all plugins
// (it will clean up memory)
sScriptMgr.PostMessageToPlugins(msg);
}
示例3: HandleAuthRequest
void WSSocket::HandleAuthRequest(WorldPacket & pck)
{
uint8 key[20];
uint32 build;
string ver;
pck.read(key, 20);
pck >> build;
pck >> ver;
Log.Notice("WSSocket", "Auth reply, server is %s build %u", ver.c_str(), build);
// accept it
WorldPacket data(ISMSG_AUTH_RESULT, 4);
data << uint32(1);
SendPacket(&data);
_authenticated = true;
}
示例4: Process
void CHandlerPlayersession::Process(WorldPacket &packet)
{
//to do implementation
// IME_LOG("playersession get packet size %u", packet.size());
char test[200];
std::string str;
packet.read((uint8_t *)test, 200);
IME_LOG("get data string %s", test);
WorldPacket info;
info << "I get the data packet";
SendPacket(&info);
WorldPacket pkg;
pkg << std::string("front send data to back hello backserver");
SendPacketToRelay(&pkg, 0);
SendPacketToRelay(&pkg, 1);
IME_DEBUG("send pkg to every backends");
}
示例5: HandleAuthSession
bool WorldSocket::HandleAuthSession(WorldPacket &recvPacket)
{
// NOTE: ATM the socket is singlethread, have this in mind ...
uint8 digest[20];
uint32 clientSeed, id, security;
uint32 ClientBuild;
LocaleConstant locale;
std::string account;
Sha1Hash sha1;
BigNumber v, s, g, N, K;
WorldPacket packet, SendAddonPacked;
// Read the content of the packet
recvPacket >> ClientBuild;
recvPacket.read_skip<uint32>();
recvPacket >> account;
recvPacket >> clientSeed;
recvPacket.read(digest, 20);
DEBUG_LOG("WorldSocket::HandleAuthSession: client build %u, account %s, clientseed %X",
ClientBuild,
account.c_str(),
clientSeed);
// Check the version of client trying to connect
if (!IsAcceptableClientBuild(ClientBuild))
{
packet.Initialize(SMSG_AUTH_RESPONSE, 1);
packet << uint8(AUTH_VERSION_MISMATCH);
SendPacket(packet);
sLog.outError("WorldSocket::HandleAuthSession: Sent Auth Response (version mismatch).");
return false;
}
// Get the account information from the realmd database
std::string safe_account = account; // Duplicate, else will screw the SHA hash verification below
LoginDatabase.escape_string(safe_account);
// No SQL injection, username escaped.
QueryResult* result =
LoginDatabase.PQuery("SELECT "
"id, " //0
"gmlevel, " //1
"sessionkey, " //2
"last_ip, " //3
"locked, " //4
"v, " //5
"s, " //6
"mutetime, " //7
"locale " //8
"FROM account "
"WHERE username = '%s'",
safe_account.c_str());
// Stop if the account is not found
if (!result)
{
packet.Initialize(SMSG_AUTH_RESPONSE, 1);
packet << uint8(AUTH_UNKNOWN_ACCOUNT);
SendPacket(packet);
sLog.outError("WorldSocket::HandleAuthSession: Sent Auth Response (unknown account).");
return false;
}
Field* fields = result->Fetch();
N.SetHexStr("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7");
g.SetDword(7);
v.SetHexStr(fields[5].GetString());
s.SetHexStr(fields[6].GetString());
m_s = s;
const char* sStr = s.AsHexStr(); // Must be freed by OPENSSL_free()
const char* vStr = v.AsHexStr(); // Must be freed by OPENSSL_free()
DEBUG_LOG("WorldSocket::HandleAuthSession: (s,v) check s: %s v: %s",
sStr,
vStr);
OPENSSL_free((void*) sStr);
OPENSSL_free((void*) vStr);
///- Re-check ip locking (same check as in realmd).
if (fields[4].GetUInt8() == 1) // if ip is locked
{
if (strcmp(fields[3].GetString(), GetRemoteAddress().c_str()))
{
packet.Initialize(SMSG_AUTH_RESPONSE, 1);
packet << uint8(AUTH_FAILED);
SendPacket(packet);
delete result;
BASIC_LOG("WorldSocket::HandleAuthSession: Sent Auth Response (Account IP differs).");
return false;
}
//.........这里部分代码省略.........
示例6: HandleAuthSession
void WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
{
uint8 digest[SHA_DIGEST_LENGTH];
uint32 clientSeed;
uint8 security;
uint32 id;
LocaleConstant locale;
std::string account;
bool isPremium = false;
SHA1Hash sha;
uint32 clientBuild;
uint32 serverId, loginServerType, region, battlegroup, realmIndex;
uint64 unk4;
WorldPacket packet, SendAddonPacked;
BigNumber k;
bool wardenActive = sWorld->getBoolConfig(CONFIG_WARDEN_ENABLED);
// Read the content of the packet
recvPacket >> clientBuild;
recvPacket >> serverId; // Used for GRUNT only
recvPacket >> account;
recvPacket >> loginServerType; // 0 GRUNT, 1 Battle.net
recvPacket >> clientSeed;
recvPacket >> region >> battlegroup; // Used for Battle.net only
recvPacket >> realmIndex; // realmId from auth_database.realmlist table
recvPacket >> unk4;
recvPacket.read(digest, 20);
TC_LOG_DEBUG("network", "WorldSocket::HandleAuthSession: client %u, serverId %u, account %s, loginServerType %u, clientseed %u, realmIndex %u",
clientBuild,
serverId,
account.c_str(),
loginServerType,
clientSeed,
realmIndex);
// Get the account information from the auth database
// 0 1 2 3 4 5 6 7 8
// SELECT id, sessionkey, last_ip, locked, expansion, mutetime, locale, recruiter, os FROM account WHERE username = ?
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_INFO_BY_NAME);
stmt->setString(0, account);
PreparedQueryResult result = LoginDatabase.Query(stmt);
// Stop if the account is not found
if (!result)
{
// We can not log here, as we do not know the account. Thus, no accountId.
SendAuthResponseError(AUTH_UNKNOWN_ACCOUNT);
TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: Sent Auth Response (unknown account).");
DelayedCloseSocket();
return;
}
Field* fields = result->Fetch();
uint8 expansion = fields[4].GetUInt8();
uint32 world_expansion = sWorld->getIntConfig(CONFIG_EXPANSION);
if (expansion > world_expansion)
expansion = world_expansion;
// For hook purposes, we get Remoteaddress at this point.
std::string address = GetRemoteIpAddress().to_string();
// As we don't know if attempted login process by ip works, we update last_attempt_ip right away
stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LAST_ATTEMPT_IP);
stmt->setString(0, address);
stmt->setString(1, account);
LoginDatabase.Execute(stmt);
// This also allows to check for possible "hack" attempts on account
// id has to be fetched at this point, so that first actual account response that fails can be logged
id = fields[0].GetUInt32();
k.SetHexStr(fields[1].GetCString());
// even if auth credentials are bad, try using the session key we have - client cannot read auth response error without it
_authCrypt.Init(&k);
// First reject the connection if packet contains invalid data or realm state doesn't allow logging in
if (sWorld->IsClosed())
{
SendAuthResponseError(AUTH_REJECT);
TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: World closed, denying client (%s).", GetRemoteIpAddress().to_string().c_str());
DelayedCloseSocket();
return;
}
if (realmIndex != realmID)
{
SendAuthResponseError(REALM_LIST_REALM_NOT_FOUND);
TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: Sent Auth Response (bad realm).");
DelayedCloseSocket();
return;
}
std::string os = fields[8].GetString();
//.........这里部分代码省略.........
示例7: HandleAuthSession
int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
{
// NOTE: ATM the socket is singlethread, have this in mind ...
uint8 digest[20];
uint32 clientSeed;
uint32 unk2;
uint32 BuiltNumberClient;
uint32 id, security;
//uint8 expansion = 0;
LocaleConstant locale;
std::string account;
Sha1Hash sha1;
BigNumber v, s, g, N;
WorldPacket packet, SendAddonPacked;
BigNumber K;
// Read the content of the packet
recvPacket >> BuiltNumberClient;
recvPacket >> unk2;
recvPacket >> account;
recvPacket >> clientSeed;
recvPacket.read (digest, 20);
DEBUG_LOG ("WorldSocket::HandleAuthSession: client %u, unk2 %u, account %s, clientseed %u",
BuiltNumberClient,
unk2,
account.c_str (),
clientSeed);
// Check the version of client trying to connect
if (!IsAcceptableClientBuild(BuiltNumberClient))
{
packet.Initialize (SMSG_AUTH_RESPONSE, 1);
packet << uint8 (AUTH_VERSION_MISMATCH);
SendPacket (packet);
sLog.outError ("WorldSocket::HandleAuthSession: Sent Auth Response (version mismatch).");
return -1;
}
// Get the account information from the realmd database
std::string safe_account = account; // Duplicate, else will screw the SHA hash verification below
LoginDatabase.escape_string (safe_account);
// No SQL injection, username escaped.
QueryResult_AutoPtr result = LoginDatabase.PQuery ("SELECT "
"id, " //0
"gmlevel, " //1
"sessionkey, " //2
"last_ip, " //3
"locked, " //4
"v, " //5
"s, " //6
"expansion, " //7
"mutetime, " //8
"locale " //9
"FROM account "
"WHERE username = '%s'",
safe_account.c_str ());
// Stop if the account is not found
if (!result)
{
packet.Initialize (SMSG_AUTH_RESPONSE, 1);
packet << uint8 (AUTH_UNKNOWN_ACCOUNT);
SendPacket (packet);
sLog.outError ("WorldSocket::HandleAuthSession: Sent Auth Response (unknown account).");
return -1;
}
Field* fields = result->Fetch ();
uint8 expansion = fields[7].GetUInt8();
uint32 world_expansion = sWorld.getConfig(CONFIG_EXPANSION);
if (expansion > world_expansion)
expansion = world_expansion;
//expansion = ((sWorld.getConfig(CONFIG_EXPANSION) > fields[7].GetUInt8()) ? fields[7].GetUInt8() : sWorld.getConfig(CONFIG_EXPANSION));
N.SetHexStr ("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7");
g.SetDword (7);
v.SetHexStr(fields[5].GetString());
s.SetHexStr (fields[6].GetString ());
const char* sStr = s.AsHexStr (); //Must be freed by OPENSSL_free()
const char* vStr = v.AsHexStr (); //Must be freed by OPENSSL_free()
DEBUG_LOG ("WorldSocket::HandleAuthSession: (s,v) check s: %s v: %s",
sStr,
vStr);
OPENSSL_free ((void*) sStr);
OPENSSL_free ((void*) vStr);
// Re-check ip locking (same check as in realmd).
//.........这里部分代码省略.........
示例8: InformationRetreiveCallback
void WorldSocket::InformationRetreiveCallback(WorldPacket & recvData, uint32 requestid)
{
if(requestid != mRequestID)
return;
uint32 error;
recvData >> error;
if(error != 0 || pAuthenticationPacket == NULL)
{
// something happened wrong @ the logon server
OutPacket(SMSG_AUTH_RESPONSE, 1, "\x0D");
return;
}
// Extract account information from the packet.
string AccountName;
const string * ForcedPermissions;
uint32 AccountID;
string GMFlags;
uint8 AccountFlags;
string lang = "enUS";
uint32 i;
recvData >> AccountID >> AccountName >> GMFlags >> AccountFlags;
ForcedPermissions = sLogonCommHandler.GetForcedPermissions(AccountName);
if( ForcedPermissions != NULL )
GMFlags.assign(ForcedPermissions->c_str());
sLog.outDebug( " >> got information packet from logon: `%s` ID %u (request %u)", AccountName.c_str(), AccountID, mRequestID);
// sLog.outColor(TNORMAL, "\n");
mRequestID = 0;
// Pull the session key.
uint8 K[40];
recvData.read(K, 40);
BigNumber BNK;
BNK.SetBinary(K, 40);
uint8 *key = new uint8[20];
WowCrypt::GenerateKey(key, K);
// Initialize crypto.
_crypt.SetKey(key, 20);
_crypt.Init();
delete [] key;
//checking if player is already connected
//disconnect corrent player and login this one(blizzlike)
if(recvData.rpos() != recvData.wpos())
recvData.read((uint8*)lang.data(), 4);
WorldSession *session = sWorld.FindSession( AccountID );
if( session)
{
// AUTH_FAILED = 0x0D
session->Disconnect();
// clear the logout timer so he times out straight away
session->SetLogoutTimer(1);
// we must send authentication failed here.
// the stupid newb can relog his client.
// otherwise accounts dupe up and disasters happen.
OutPacket(SMSG_AUTH_RESPONSE, 1, "\x15");
return;
}
Sha1Hash sha;
uint8 digest[20];
pAuthenticationPacket->read(digest, 20);
uint32 t = 0;
if( m_fullAccountName == NULL ) // should never happen !
sha.UpdateData(AccountName);
else
{
sha.UpdateData(*m_fullAccountName);
// this is unused now. we may as well free up the memory.
delete m_fullAccountName;
m_fullAccountName = NULL;
}
sha.UpdateData((uint8 *)&t, 4);
sha.UpdateData((uint8 *)&mClientSeed, 4);
sha.UpdateData((uint8 *)&mSeed, 4);
sha.UpdateBigNumbers(&BNK, NULL);
sha.Finalize();
if (memcmp(sha.GetDigest(), digest, 20))
{
// AUTH_UNKNOWN_ACCOUNT = 21
OutPacket(SMSG_AUTH_RESPONSE, 1, "\x15");
return;
}
//.........这里部分代码省略.........
示例9: _HandleAuthSession
/// Handle the client authentication packet
void WorldSocket::_HandleAuthSession(WorldPacket& recvPacket)
{
uint8 digest[20];
uint32 clientSeed;
uint32 unk2;
uint32 BuiltNumberClient;
uint32 id, security;
std::string account;
Sha1Hash I;
Sha1Hash sha1;
BigNumber v, s, g, N, x;
std::string password;
WorldPacket packet, SendAddonPacked;
BigNumber K;
///- Read the content of the packet
try
{
recvPacket >> BuiltNumberClient; // for now no use
recvPacket >> unk2;
recvPacket >> account;
recvPacket >> clientSeed;
recvPacket.read(digest, 20);
}
catch(ByteBuffer::error &)
{
sLog.outError("WorldSocket::_HandleAuthSession Get Incomplete packet");
return;
}
sLog.outDebug("Auth: client %u, unk2 %u, account %s, clientseed %u", BuiltNumberClient, unk2, account.c_str(), clientSeed);
///- Get the account information from the realmd database
std::string safe_account=account; // Duplicate, else will screw the SHA hash verification below
loginDatabase.escape_string(safe_account);
//No SQL injection, username escaped.
QueryResult *result = loginDatabase.PQuery("SELECT `id`,`gmlevel`,`sessionkey`,`last_ip`,`locked`, `password`, `v`, `s`, `banned` FROM `account` WHERE `username` = '%s'", safe_account.c_str());
///- Stop if the account is not found
if ( !result )
{
packet.Initialize( SMSG_AUTH_RESPONSE, 1 );
packet << uint8( AUTH_UNKNOWN_ACCOUNT );
SendPacket( &packet );
sLog.outDetail( "SOCKET: Sent Auth Response (unknown account)." );
return;
}
N.SetHexStr("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7");
g.SetDword(7);
password = (*result)[5].GetString();
std::transform(password.begin(), password.end(), password.begin(), std::towupper);
s.SetHexStr((*result)[7].GetString());
std::string sI = account + ":" + password;
I.UpdateData(sI);
I.Finalize();
sha1.UpdateData(s.AsByteArray(), s.GetNumBytes());
sha1.UpdateData(I.GetDigest(), 20);
sha1.Finalize();
x.SetBinary(sha1.GetDigest(), sha1.GetLength());
v = g.ModExp(x, N);
sLog.outDebug("SOCKET: (s,v) check s: %s v_old: %s v_new: %s", s.AsHexStr(), (*result)[6].GetString(), v.AsHexStr() );
loginDatabase.PQuery("UPDATE `account` SET `v` = '0', `s` = '0' WHERE `username` = '%s'", safe_account.c_str());
if ( strcmp(v.AsHexStr(),(*result)[6].GetString() ) )
{
packet.Initialize( SMSG_AUTH_RESPONSE, 1 );
packet << uint8( AUTH_UNKNOWN_ACCOUNT );
SendPacket( &packet );
sLog.outDetail( "SOCKET: User not logged.");
delete result;
return;
}
///- Re-check ip locking (same check as in realmd).
if((*result)[4].GetUInt8() == 1) // if ip is locked
{
if ( strcmp((*result)[3].GetString(),GetRemoteAddress().c_str()) )
{
packet.Initialize( SMSG_AUTH_RESPONSE, 1 );
packet << uint8( REALM_AUTH_ACCOUNT_FREEZED );
SendPacket( &packet );
sLog.outDetail( "SOCKET: Sent Auth Response (Account IP differs)." );
delete result;
return;
}
}
///- Re-check account ban (same check as in realmd).
if((*result)[8].GetUInt8() == 1) // if account banned
{
packet.Initialize( SMSG_AUTH_RESPONSE, 1 );
packet << uint8( AUTH_BANNED );
SendPacket( &packet );
sLog.outDetail( "SOCKET: Sent Auth Response (Account banned)." );
delete result;
//.........这里部分代码省略.........
示例10: InformationRetreiveCallback
void WorldSocket::InformationRetreiveCallback(WorldPacket & recvData, uint32 requestid)
{
if(requestid != mRequestID)
return;
uint32 error;
recvData >> error;
if(error != 0)
{
// something happened wrong @ the logon server
OutPacket(SMSG_AUTH_RESPONSE, 1, "\x0D");
printf("Information callback returns failure.\n");
return;
}
// Extract account information from the packet.
string AccountName;
uint32 AccountID;
string GMFlags;
uint8 AccountFlags;
recvData >> AccountID >> AccountName >> GMFlags >> AccountFlags;
printf( " >> got information packet from logon: `%s` ID %u (request %u)", AccountName.c_str(), AccountID, mRequestID);
// sLog.outColor(TNORMAL, "\n");
mRequestID = 0;
//Pull the session key.
recvData.read(K, 40);
_crypt.Init(K);
BigNumber BNK;
BNK.SetBinary(K, 40);
//checking if player is already connected
//disconnect current player and login this one(blizzlike)
string lang = "enUS";
if(recvData.rpos() != recvData.wpos())
recvData.read((uint8*)lang.data(), 4);
Session * session = sClientMgr.CreateSession(AccountID);
if(session == NULL)
{
/* we are already logged in. send auth failed. (if anyone has a better error lemme know :P) */
OutPacket(SMSG_AUTH_RESPONSE, 1, "\x0D");
printf("Duplicate client error.\n");
return;
}
m_session = session;
session->m_socket = this;
Sha1Hash sha;
uint8 digest[20];
pAuthenticationPacket->read(digest, 20);
uint32 t = 0;
if( m_fullAccountName == NULL ) // should never happen !
sha.UpdateData(AccountName);
else
{
sha.UpdateData(*m_fullAccountName);
// this is unused now. we may as well free up the memory.
delete m_fullAccountName;
m_fullAccountName = NULL;
}
sha.UpdateData((uint8 *)&t, 4);
sha.UpdateData((uint8 *)&mClientSeed, 4);
sha.UpdateData((uint8 *)&mSeed, 4);
sha.UpdateBigNumbers(&BNK, NULL);
sha.Finalize();
if (memcmp(sha.GetDigest(), digest, 20))
{
// AUTH_UNKNOWN_ACCOUNT = 21
OutPacket(SMSG_AUTH_RESPONSE, 1, "\x15");
return;
}
//_crypt.Init(digest);
// Allocate session
m_session->m_accountFlags = AccountFlags;
m_session->m_GMPermissions = GMFlags;
m_session->m_accountId = AccountID;
m_session->m_latency = _latency;
m_session->m_accountName = AccountName;
m_session->m_ClientBuild = mClientBuild;
Log.Notice("Auth", "%s from %s:%u [%ums]", AccountName.c_str(), GetRemoteIP().c_str(), GetRemotePort(), _latency);
Authenticate();
}
示例11: InformationRetreiveCallback
void WorldSocket::InformationRetreiveCallback(WorldPacket & recvData, uint32 requestid)
{
if(requestid != mRequestID)
return;
uint32 error;
recvData >> error;
if(error != 0 || pAuthenticationPacket == NULL)
{
// something happened wrong @ the logon server
OutPacket(SMSG_AUTH_RESPONSE, 1, "\x0D");
return;
}
// Extract account information from the packet.
string AccountName;
const string * ForcedPermissions;
uint32 AccountID;
string GMFlags;
uint8 AccountFlags;
string lang = "enUS";
uint32 i;
recvData >> AccountID >> AccountName >> GMFlags >> AccountFlags;
ForcedPermissions = sLogonCommHandler.GetForcedPermissions(AccountName);
if( ForcedPermissions != NULL )
GMFlags.assign(ForcedPermissions->c_str());
DEBUG_LOG( "WorldSocket","Received information packet from logon: `%s` ID %u (request %u)", AccountName.c_str(), AccountID, mRequestID);
mRequestID = 0;
// Pull the session key.
BigNumber BNK;
recvData.read(K, 40);
_crypt.Init(K);
BNK.SetBinary(K, 40);
//checking if player is already connected
//disconnect current player and login this one(blizzlike)
if(recvData.rpos() != recvData.wpos())
recvData.read((uint8*)lang.data(), 4);
WorldSession *session = NULL;
session = sWorld.FindSession( AccountID );
if( session != NULL )
{
if(session->_player != NULL && session->_player->GetMapMgr() == NULL)
{
DEBUG_LOG("WorldSocket","_player found without m_mapmgr during logon, trying to remove him [player %s, map %d, instance %d].", session->_player->GetName(), session->_player->GetMapId(), session->_player->GetInstanceID() );
if(objmgr.GetPlayer(session->_player->GetLowGUID()))
objmgr.RemovePlayer(session->_player);
session->LogoutPlayer(false);
}
// AUTH_FAILED = 0x0D
session->Disconnect();
// clear the logout timer so he times out straight away
session->SetLogoutTimer(1);
// we must send authentication failed here.
// the stupid newb can relog his client.
// otherwise accounts dupe up and disasters happen.
OutPacket(SMSG_AUTH_RESPONSE, 1, "\x15");
return;
}
Sha1Hash sha;
uint8 digest[20];
pAuthenticationPacket->read(digest, 20);
uint32 t = 0;
if( m_fullAccountName == NULL ) // should never happen !
sha.UpdateData(AccountName);
else
{
sha.UpdateData(*m_fullAccountName);
// this is unused now. we may as well free up the memory.
delete m_fullAccountName;
m_fullAccountName = NULL;
}
sha.UpdateData((uint8 *)&t, 4);
sha.UpdateData((uint8 *)&mClientSeed, 4);
sha.UpdateData((uint8 *)&mSeed, 4);
sha.UpdateBigNumbers(&BNK, NULL);
sha.Finalize();
if (memcmp(sha.GetDigest(), digest, 20))
{
// AUTH_UNKNOWN_ACCOUNT = 21
OutPacket(SMSG_AUTH_RESPONSE, 1, "\x15");
return;
}
// Allocate session
//.........这里部分代码省略.........
示例12: HandleAuthSession
int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
{
// NOTE: ATM the socket is singlethread, have this in mind ...
uint8 digest[20];
uint32 clientSeed;
uint32 serverId;
uint32 BuiltNumberClient;
uint32 id, security;
LocaleConstant locale;
std::string account, os;
BigNumber v, s, g, N, K;
WorldPacket packet, SendAddonPacked;
// Read the content of the packet
recvPacket >> BuiltNumberClient;
recvPacket >> serverId;
recvPacket >> account;
recvPacket >> clientSeed;
recvPacket.read(digest, 20);
DEBUG_LOG("WorldSocket::HandleAuthSession: client %u, serverId %u, account %s, clientseed %u",
BuiltNumberClient,
serverId,
account.c_str(),
clientSeed);
// Check the version of client trying to connect
if (!IsAcceptableClientBuild(BuiltNumberClient))
{
packet.Initialize(SMSG_AUTH_RESPONSE, 1);
packet << uint8(AUTH_VERSION_MISMATCH);
SendPacket(packet);
sLog.outError("WorldSocket::HandleAuthSession: Sent Auth Response (version mismatch).");
return -1;
}
// Get the account information from the realmd database
std::string safe_account = account; // Duplicate, else will screw the SHA hash verification below
LoginDatabase.escape_string(safe_account);
// No SQL injection, username escaped.
QueryResult *result = LoginDatabase.PQuery("SELECT a.id, aa.gmLevel, a.sessionkey, a.last_ip, a.locked, a.v, a.s, a.mutetime, a.locale, a.os, a.flags, "
"ab.unbandate > UNIX_TIMESTAMP() OR ab.unbandate = ab.bandate FROM account a LEFT JOIN account_access aa ON a.id = aa.id AND aa.RealmID IN (-1, %u) "
"LEFT JOIN account_banned ab ON a.id = ab.id AND ab.active = 1 WHERE a.username = '%s' ORDER BY aa.RealmID DESC LIMIT 1", realmID, safe_account.c_str());
// Stop if the account is not found
if (!result)
{
packet.Initialize(SMSG_AUTH_RESPONSE, 1);
packet << uint8(AUTH_UNKNOWN_ACCOUNT);
SendPacket(packet);
sLog.outError("WorldSocket::HandleAuthSession: Sent Auth Response (unknown account).");
return -1;
}
Field* fields = result->Fetch();
N.SetHexStr("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7");
g.SetDword(7);
v.SetHexStr(fields[5].GetString());
s.SetHexStr(fields[6].GetString());
const char* sStr = s.AsHexStr(); //Must be freed by OPENSSL_free()
const char* vStr = v.AsHexStr(); //Must be freed by OPENSSL_free()
DEBUG_LOG("WorldSocket::HandleAuthSession: (s,v) check s: %s v: %s",
sStr,
vStr);
OPENSSL_free((void*) sStr);
OPENSSL_free((void*) vStr);
///- Re-check ip locking (same check as in realmd).
if (fields[4].GetUInt8() == 1) // if ip is locked
{
if (strcmp(fields[3].GetString(), GetRemoteAddress().c_str()))
{
packet.Initialize(SMSG_AUTH_RESPONSE, 1);
packet << uint8(AUTH_FAILED);
SendPacket(packet);
delete result;
BASIC_LOG("WorldSocket::HandleAuthSession: Sent Auth Response (Account IP differs).");
return -1;
}
}
id = fields[0].GetUInt32();
security = sAccountMgr.GetSecurity(id); //fields[1].GetUInt16 ();
if (security > SEC_ADMINISTRATOR) // prevent invalid security settings in DB
security = SEC_ADMINISTRATOR;
K.SetHexStr(fields[2].GetString());
//.........这里部分代码省略.........
示例13: InformationRetreiveCallback
void WorldSocket::InformationRetreiveCallback(WorldPacket & recvData, uint32 requestid)
{
if(requestid != mRequestID)
return;
uint32 error;
recvData >> error;
if(error != 0)
{
// something happened wrong @ the logon server
OutPacket(SMSG_AUTH_RESPONSE, 1, "\x0D");
return;
}
// Extract account information from the packet.
string AccountName;
uint32 AccountID;
string GMFlags;
uint32 AccountFlags;
recvData >> AccountID >> AccountName >> GMFlags >> AccountFlags;
sLog.outDebug( " >> got information packet from logon: `%s` ID %u (request %u)", AccountName.c_str(), AccountID, mRequestID);
// sLog.outColor(TNORMAL, "\n");
mRequestID = 0;
// Pull the session key.
uint8 K[40];
recvData.read(K, 40);
BigNumber BNK;
BNK.SetBinary(K, 40);
// Initialize crypto.
_crypt.SetKey(K, 40);
_crypt.Init();
Session * session = sClientMgr.CreateSession(AccountID);
if(session == NULL)
{
/* we are already logged in. send auth failed. (if anyone has a better error lemme know :P) */
OutPacket(SMSG_AUTH_RESPONSE, 1, "\x0D");
return;
}
m_session = session;
session->m_socket = this;
Sha1Hash sha;
uint8 digest[20];
pAuthenticationPacket->read(digest, 20);
uint32 t = 0;
sha.UpdateData(AccountName);
sha.UpdateData((uint8 *)&t, 4);
sha.UpdateData((uint8 *)&mClientSeed, 4);
sha.UpdateData((uint8 *)&mSeed, 4);
sha.UpdateBigNumbers(&BNK, NULL);
sha.Finalize();
if (memcmp(sha.GetDigest(), digest, 20))
{
// AUTH_UNKNOWN_ACCOUNT = 21
OutPacket(SMSG_AUTH_RESPONSE, 1, "\x15");
return;
}
// Allocate session
m_session->m_accountFlags = AccountFlags;
m_session->m_GMPermissions = GMFlags;
m_session->m_accountId = AccountID;
m_session->m_latency = _latency;
m_session->m_accountName = AccountName;
Log.Notice("Auth", "%s from %s:%u [%ums]", AccountName.c_str(), GetRemoteIP().c_str(), GetRemotePort(), _latency);
Authenticate();
}
示例14: HandleAuthSession
int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
{
// NOTE: ATM the socket is singlethread, have this in mind ...
uint8 digest[20];
uint32 clientSeed;
uint32 unk2;
uint32 BuiltNumberClient;
uint32 id, security;
uint8 expansion = 0;
LocaleConstant locale;
std::string account;
Sha1Hash sha1;
BigNumber v, s, g, N, x, I;
WorldPacket packet, SendAddonPacked;
BigNumber K;
if (recvPacket.size () < (4 + 4 + 1 + 4 + 20))
{
sLog.outError ("WorldSocket::HandleAuthSession: wrong packet size");
return -1;
}
// Read the content of the packet
recvPacket >> BuiltNumberClient; // for now no use
recvPacket >> unk2;
recvPacket >> account;
if (recvPacket.size () < (4 + 4 + (account.size () + 1) + 4 + 20))
{
sLog.outError ("WorldSocket::HandleAuthSession: wrong packet size second check");
return -1;
}
recvPacket >> clientSeed;
recvPacket.read (digest, 20);
DEBUG_LOG ("WorldSocket::HandleAuthSession: client %u, unk2 %u, account %s, clientseed %u",
BuiltNumberClient,
unk2,
account.c_str (),
clientSeed);
// Get the account information from the realmd database
std::string safe_account = account; // Duplicate, else will screw the SHA hash verification below
loginDatabase.escape_string (safe_account);
// No SQL injection, username escaped.
QueryResult *result =
loginDatabase.PQuery ("SELECT "
"id, " //0
"gmlevel, " //1
"sessionkey, " //2
"last_ip, " //3
"locked, " //4
"sha_pass_hash, " //5
"v, " //6
"s, " //7
"expansion, " //8
"mutetime, " //9
"locale " //10
"FROM account "
"WHERE username = '%s'",
safe_account.c_str ());
// Stop if the account is not found
if (!result)
{
packet.Initialize (SMSG_AUTH_RESPONSE, 1);
packet << uint8 (AUTH_UNKNOWN_ACCOUNT);
SendPacket (packet);
sLog.outError ("WorldSocket::HandleAuthSession: Sent Auth Response (unknown account).");
return -1;
}
Field* fields = result->Fetch ();
expansion = fields[8].GetUInt8 () && sWorld.getConfig (CONFIG_EXPANSION) > 0;
N.SetHexStr ("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7");
g.SetDword (7);
I.SetHexStr (fields[5].GetString ());
//In case of leading zeros in the I hash, restore them
uint8 mDigest[SHA_DIGEST_LENGTH];
memset (mDigest, 0, SHA_DIGEST_LENGTH);
if (I.GetNumBytes () <= SHA_DIGEST_LENGTH)
memcpy (mDigest, I.AsByteArray (), I.GetNumBytes ());
std::reverse (mDigest, mDigest + SHA_DIGEST_LENGTH);
s.SetHexStr (fields[7].GetString ());
sha1.UpdateData (s.AsByteArray (), s.GetNumBytes ());
sha1.UpdateData (mDigest, SHA_DIGEST_LENGTH);
sha1.Finalize ();
x.SetBinary (sha1.GetDigest (), sha1.GetLength ());
v = g.ModExp (x, N);
//.........这里部分代码省略.........