[svn] Merge from Mangos:
3c7ac5bd3e20c33a22ac57c5c3bac23a0798dc9e 2008-10-23 19:06:27 Some endianess related fixes and cleanups. By VladimirMangos. --HG-- branch : trunk
This commit is contained in:
@@ -10,12 +10,12 @@
|
|||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TRINITY_BYTECONVERTER_H
|
#ifndef TRINITY_BYTECONVERTER_H
|
||||||
@@ -48,12 +48,18 @@ namespace ByteConverter
|
|||||||
|
|
||||||
#if TRINITY_ENDIAN == TRINITY_BIGENDIAN
|
#if TRINITY_ENDIAN == TRINITY_BIGENDIAN
|
||||||
template<typename T> inline void EndianConvert(T& val) { ByteConverter::apply<T>(&val); }
|
template<typename T> inline void EndianConvert(T& val) { ByteConverter::apply<T>(&val); }
|
||||||
|
template<typename T> inline void EndianConvertReverse(T&) { }
|
||||||
#else
|
#else
|
||||||
template<typename T> inline void EndianConvert(T&) { }
|
template<typename T> inline void EndianConvert(T&) { }
|
||||||
|
template<typename T> inline void EndianConvertReverse(T& val) { ByteConverter::apply<T>(&val); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<typename T> inline void EndianConvert(T*) { }
|
template<typename T> void EndianConvert(T*); // will generate link error
|
||||||
|
template<typename T> void EndianConvertReverse(T*); // will generate link error
|
||||||
|
|
||||||
inline void EndianConvert(uint8&) { }
|
inline void EndianConvert(uint8&) { }
|
||||||
inline void EndianConvert( int8&) { }
|
inline void EndianConvert( int8&) { }
|
||||||
|
inline void EndianConvertReverse(uint8&) { }
|
||||||
|
inline void EndianConvertReverse( int8&) { }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+82
-81
@@ -182,67 +182,67 @@ bool World::RemoveSession(uint32 id)
|
|||||||
|
|
||||||
void World::AddSession(WorldSession* s)
|
void World::AddSession(WorldSession* s)
|
||||||
{
|
{
|
||||||
addSessQueue.add(s);
|
addSessQueue.add(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
World::AddSession_ (WorldSession* s)
|
World::AddSession_ (WorldSession* s)
|
||||||
{
|
{
|
||||||
ASSERT (s);
|
ASSERT (s);
|
||||||
|
|
||||||
//NOTE - Still there is race condition in WorldSession* being used in the Sockets
|
//NOTE - Still there is race condition in WorldSession* being used in the Sockets
|
||||||
|
|
||||||
///- kick already loaded player with same account (if any) and remove session
|
///- kick already loaded player with same account (if any) and remove session
|
||||||
///- if player is in loading and want to load again, return
|
///- if player is in loading and want to load again, return
|
||||||
if (!RemoveSession (s->GetAccountId ()))
|
if (!RemoveSession (s->GetAccountId ()))
|
||||||
{
|
{
|
||||||
s->KickPlayer ();
|
s->KickPlayer ();
|
||||||
m_kicked_sessions.insert (s);
|
m_kicked_sessions.insert (s);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldSession* old = m_sessions[s->GetAccountId ()];
|
WorldSession* old = m_sessions[s->GetAccountId ()];
|
||||||
m_sessions[s->GetAccountId ()] = s;
|
m_sessions[s->GetAccountId ()] = s;
|
||||||
|
|
||||||
// if session already exist, prepare to it deleting at next world update
|
// if session already exist, prepare to it deleting at next world update
|
||||||
// NOTE - KickPlayer() should be called on "old" in RemoveSession()
|
// NOTE - KickPlayer() should be called on "old" in RemoveSession()
|
||||||
if (old)
|
if (old)
|
||||||
m_kicked_sessions.insert (old);
|
m_kicked_sessions.insert (old);
|
||||||
|
|
||||||
uint32 Sessions = GetActiveAndQueuedSessionCount ();
|
uint32 Sessions = GetActiveAndQueuedSessionCount ();
|
||||||
uint32 pLimit = GetPlayerAmountLimit ();
|
uint32 pLimit = GetPlayerAmountLimit ();
|
||||||
uint32 QueueSize = GetQueueSize (); //number of players in the queue
|
uint32 QueueSize = GetQueueSize (); //number of players in the queue
|
||||||
bool inQueue = false;
|
bool inQueue = false;
|
||||||
//so we don't count the user trying to
|
//so we don't count the user trying to
|
||||||
//login as a session and queue the socket that we are using
|
//login as a session and queue the socket that we are using
|
||||||
--Sessions;
|
--Sessions;
|
||||||
|
|
||||||
if (pLimit > 0 && Sessions >= pLimit && s->GetSecurity () == SEC_PLAYER )
|
if (pLimit > 0 && Sessions >= pLimit && s->GetSecurity () == SEC_PLAYER )
|
||||||
{
|
{
|
||||||
AddQueuedPlayer (s);
|
AddQueuedPlayer (s);
|
||||||
UpdateMaxSessionCounters ();
|
UpdateMaxSessionCounters ();
|
||||||
sLog.outDetail ("PlayerQueue: Account id %u is in Queue Position (%u).", s->GetAccountId (), ++QueueSize);
|
sLog.outDetail ("PlayerQueue: Account id %u is in Queue Position (%u).", s->GetAccountId (), ++QueueSize);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldPacket packet(SMSG_AUTH_RESPONSE, 1 + 4 + 1 + 4 + 1);
|
WorldPacket packet(SMSG_AUTH_RESPONSE, 1 + 4 + 1 + 4 + 1);
|
||||||
packet << uint8 (AUTH_OK);
|
packet << uint8 (AUTH_OK);
|
||||||
packet << uint32 (0); // unknown random value...
|
packet << uint32 (0); // unknown random value...
|
||||||
packet << uint8 (0);
|
packet << uint8 (0);
|
||||||
packet << uint32 (0);
|
packet << uint32 (0);
|
||||||
packet << uint8 (s->Expansion () ? 1 : 0); // 0 - normal, 1 - TBC, must be set in database manually for each account
|
packet << uint8 (s->Expansion()); // 0 - normal, 1 - TBC, must be set in database manually for each account
|
||||||
s->SendPacket (&packet);
|
s->SendPacket (&packet);
|
||||||
|
|
||||||
UpdateMaxSessionCounters ();
|
UpdateMaxSessionCounters ();
|
||||||
|
|
||||||
// Updates the population
|
// Updates the population
|
||||||
if (pLimit > 0)
|
if (pLimit > 0)
|
||||||
{
|
{
|
||||||
float popu = GetActiveSessionCount (); //updated number of users on the server
|
float popu = GetActiveSessionCount (); //updated number of users on the server
|
||||||
popu /= pLimit;
|
popu /= pLimit;
|
||||||
popu *= 2;
|
popu *= 2;
|
||||||
loginDatabase.PExecute ("UPDATE realmlist SET population = '%f' WHERE id = '%d'", popu, realmID);
|
loginDatabase.PExecute ("UPDATE realmlist SET population = '%f' WHERE id = '%d'", popu, realmID);
|
||||||
sLog.outDetail ("Server Population (%f).", popu);
|
sLog.outDetail ("Server Population (%f).", popu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2282,32 +2282,32 @@ BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, std::string dura
|
|||||||
QueryResult *resultAccounts = NULL; //used for kicking
|
QueryResult *resultAccounts = NULL; //used for kicking
|
||||||
|
|
||||||
///- Update the database with ban information
|
///- Update the database with ban information
|
||||||
switch(mode)
|
switch(mode)
|
||||||
{
|
{
|
||||||
case BAN_IP:
|
case BAN_IP:
|
||||||
//No SQL injection as strings are escaped
|
//No SQL injection as strings are escaped
|
||||||
resultAccounts = loginDatabase.PQuery("SELECT id FROM account WHERE last_ip = '%s'",nameOrIP.c_str());
|
resultAccounts = loginDatabase.PQuery("SELECT id FROM account WHERE last_ip = '%s'",nameOrIP.c_str());
|
||||||
loginDatabase.PExecute("INSERT INTO ip_banned VALUES ('%s',UNIX_TIMESTAMP(),UNIX_TIMESTAMP()+%u,'%s','%s')",nameOrIP.c_str(),duration_secs,safe_author.c_str(),reason.c_str());
|
loginDatabase.PExecute("INSERT INTO ip_banned VALUES ('%s',UNIX_TIMESTAMP(),UNIX_TIMESTAMP()+%u,'%s','%s')",nameOrIP.c_str(),duration_secs,safe_author.c_str(),reason.c_str());
|
||||||
break;
|
break;
|
||||||
case BAN_ACCOUNT:
|
case BAN_ACCOUNT:
|
||||||
//No SQL injection as string is escaped
|
//No SQL injection as string is escaped
|
||||||
resultAccounts = loginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'",nameOrIP.c_str());
|
resultAccounts = loginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'",nameOrIP.c_str());
|
||||||
break;
|
break;
|
||||||
case BAN_CHARACTER:
|
case BAN_CHARACTER:
|
||||||
//No SQL injection as string is escaped
|
//No SQL injection as string is escaped
|
||||||
resultAccounts = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'",nameOrIP.c_str());
|
resultAccounts = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'",nameOrIP.c_str());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return BAN_SYNTAX_ERROR;
|
return BAN_SYNTAX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!resultAccounts)
|
if(!resultAccounts)
|
||||||
{
|
{
|
||||||
if(mode==BAN_IP)
|
if(mode==BAN_IP)
|
||||||
return BAN_SUCCESS;
|
return BAN_SUCCESS; // ip correctly banned but nobody affected (yet)
|
||||||
else
|
else
|
||||||
return BAN_NOTFOUND; // Nobody to ban
|
return BAN_NOTFOUND; // Nobody to ban
|
||||||
}
|
}
|
||||||
|
|
||||||
///- Disconnect all affected players (for IP it can be several)
|
///- Disconnect all affected players (for IP it can be several)
|
||||||
do
|
do
|
||||||
@@ -2316,11 +2316,11 @@ BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, std::string dura
|
|||||||
uint32 account = fieldsAccount->GetUInt32();
|
uint32 account = fieldsAccount->GetUInt32();
|
||||||
|
|
||||||
if(mode!=BAN_IP)
|
if(mode!=BAN_IP)
|
||||||
{
|
{
|
||||||
//No SQL injection as strings are escaped
|
//No SQL injection as strings are escaped
|
||||||
loginDatabase.PExecute("INSERT INTO account_banned VALUES ('%u', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()+%u, '%s', '%s', '1')",
|
loginDatabase.PExecute("INSERT INTO account_banned VALUES ('%u', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()+%u, '%s', '%s', '1')",
|
||||||
account,duration_secs,safe_author.c_str(),reason.c_str());
|
account,duration_secs,safe_author.c_str(),reason.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WorldSession* sess = FindSession(account))
|
if (WorldSession* sess = FindSession(account))
|
||||||
if(std::string(sess->GetPlayerName()) != author)
|
if(std::string(sess->GetPlayerName()) != author)
|
||||||
@@ -2342,13 +2342,13 @@ bool World::RemoveBanAccount(BanMode mode, std::string nameOrIP)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint32 account=0;
|
uint32 account = 0;
|
||||||
if (mode == BAN_ACCOUNT)
|
if (mode == BAN_ACCOUNT)
|
||||||
account = accmgr.GetId (nameOrIP);
|
account = accmgr.GetId (nameOrIP);
|
||||||
else if (mode == BAN_CHARACTER)
|
else if (mode == BAN_CHARACTER)
|
||||||
account = objmgr.GetPlayerAccountIdByPlayerName (nameOrIP);
|
account = objmgr.GetPlayerAccountIdByPlayerName (nameOrIP);
|
||||||
|
|
||||||
if(!account)
|
if (!account)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//NO SQL injection as account is uint32
|
//NO SQL injection as account is uint32
|
||||||
@@ -2433,7 +2433,7 @@ void World::ShutdownMsg(bool show, Player* player)
|
|||||||
uint32 msgid = (m_ShutdownMask & SHUTDOWN_MASK_RESTART) ? SERVER_MSG_RESTART_TIME : SERVER_MSG_SHUTDOWN_TIME;
|
uint32 msgid = (m_ShutdownMask & SHUTDOWN_MASK_RESTART) ? SERVER_MSG_RESTART_TIME : SERVER_MSG_SHUTDOWN_TIME;
|
||||||
|
|
||||||
SendServerMessage(msgid,str.c_str(),player);
|
SendServerMessage(msgid,str.c_str(),player);
|
||||||
outstring_log("Server will %s in %s", (m_ShutdownMask & SHUTDOWN_MASK_RESTART ? "restart" : "shutdown"), str.c_str());
|
DEBUG_LOG("Server is %s in %s",(m_ShutdownMask & SHUTDOWN_MASK_RESTART ? "restart" : "shuttingdown"),str.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2504,17 +2504,18 @@ void World::UpdateSessions( time_t diff )
|
|||||||
void World::ProcessCliCommands()
|
void World::ProcessCliCommands()
|
||||||
{
|
{
|
||||||
if (cliCmdQueue.empty())
|
if (cliCmdQueue.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CliCommandHolder::Print* zprint;
|
CliCommandHolder::Print* zprint;
|
||||||
|
|
||||||
while (!cliCmdQueue.empty())
|
while (!cliCmdQueue.empty())
|
||||||
{
|
{
|
||||||
sLog.outDebug("CLI command under processing...");
|
sLog.outDebug("CLI command under processing...");
|
||||||
CliCommandHolder *command = cliCmdQueue.next();
|
CliCommandHolder *command = cliCmdQueue.next();
|
||||||
|
|
||||||
zprint = command->m_print;
|
zprint = command->m_print;
|
||||||
|
|
||||||
CliHandler(zprint).ParseCommands(command->m_command);
|
CliHandler(zprint).ParseCommands(command->m_command);
|
||||||
|
|
||||||
delete command;
|
delete command;
|
||||||
}
|
}
|
||||||
@@ -2622,14 +2623,14 @@ void World::UpdateMaxSessionCounters()
|
|||||||
|
|
||||||
void World::LoadDBVersion()
|
void World::LoadDBVersion()
|
||||||
{
|
{
|
||||||
QueryResult* result = WorldDatabase.Query("SELECT version FROM db_version LIMIT 1");
|
QueryResult* result = WorldDatabase.Query("SELECT version FROM db_version LIMIT 1");
|
||||||
if(result)
|
if(result)
|
||||||
{
|
{
|
||||||
Field* fields = result->Fetch();
|
Field* fields = result->Fetch();
|
||||||
|
|
||||||
m_DBVersion = fields[0].GetString();
|
m_DBVersion = fields[0].GetString();
|
||||||
delete result;
|
delete result;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_DBVersion = "unknown world database";
|
m_DBVersion = "unknown world database";
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-29
@@ -10,12 +10,12 @@
|
|||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** \file
|
/** \file
|
||||||
@@ -50,35 +50,34 @@ _player(NULL), m_Socket(sock),_security(sec), _accountId(id), m_expansion(expans
|
|||||||
m_sessionDbcLocale(sWorld.GetAvailableDbcLocale(locale)), m_sessionDbLocaleIndex(objmgr.GetIndexForLocale(locale)),
|
m_sessionDbcLocale(sWorld.GetAvailableDbcLocale(locale)), m_sessionDbLocaleIndex(objmgr.GetIndexForLocale(locale)),
|
||||||
_logoutTime(0), m_playerLoading(false), m_playerLogout(false), m_playerRecentlyLogout(false), m_latency(0)
|
_logoutTime(0), m_playerLoading(false), m_playerLogout(false), m_playerRecentlyLogout(false), m_latency(0)
|
||||||
{
|
{
|
||||||
if (sock)
|
if (sock)
|
||||||
{
|
{
|
||||||
m_Address = sock->GetRemoteAddress ();
|
m_Address = sock->GetRemoteAddress ();
|
||||||
sock->AddReference ();
|
sock->AddReference ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// WorldSession destructor
|
/// WorldSession destructor
|
||||||
WorldSession::~WorldSession()
|
WorldSession::~WorldSession()
|
||||||
{
|
{
|
||||||
///- unload player if not unloaded
|
///- unload player if not unloaded
|
||||||
if(_player)
|
if (_player)
|
||||||
LogoutPlayer(true);
|
LogoutPlayer (true);
|
||||||
|
|
||||||
/// - If have unclosed socket, close it
|
/// - If have unclosed socket, close it
|
||||||
if (m_Socket)
|
if (m_Socket)
|
||||||
{
|
{
|
||||||
m_Socket->CloseSocket ();
|
m_Socket->CloseSocket ();
|
||||||
m_Socket->RemoveReference ();
|
m_Socket->RemoveReference ();
|
||||||
m_Socket = NULL;
|
m_Socket = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
///- empty incoming packet queue
|
///- empty incoming packet queue
|
||||||
while(!_recvQueue.empty())
|
while(!_recvQueue.empty())
|
||||||
{
|
{
|
||||||
WorldPacket *packet = _recvQueue.next();
|
WorldPacket *packet = _recvQueue.next ();
|
||||||
delete packet;
|
delete packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldSession::SizeError(WorldPacket const& packet, uint32 size) const
|
void WorldSession::SizeError(WorldPacket const& packet, uint32 size) const
|
||||||
@@ -133,10 +132,10 @@ void WorldSession::SendPacket(WorldPacket const* packet)
|
|||||||
sendLastPacketBytes = packet->wpos(); // wpos is real written size
|
sendLastPacketBytes = packet->wpos(); // wpos is real written size
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !TRINITY_DEBUG
|
#endif // !MANGOS_DEBUG
|
||||||
|
|
||||||
if (m_Socket->SendPacket (*packet) == -1)
|
if (m_Socket->SendPacket (*packet) == -1)
|
||||||
m_Socket->CloseSocket ();
|
m_Socket->CloseSocket ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add an incoming packet to the queue
|
/// Add an incoming packet to the queue
|
||||||
@@ -157,11 +156,11 @@ void WorldSession::logUnexpectedOpcode(WorldPacket* packet, const char *reason)
|
|||||||
/// Update the WorldSession (triggered by World update)
|
/// Update the WorldSession (triggered by World update)
|
||||||
bool WorldSession::Update(uint32 /*diff*/)
|
bool WorldSession::Update(uint32 /*diff*/)
|
||||||
{
|
{
|
||||||
if (m_Socket && m_Socket->IsClosed ())
|
if (m_Socket && m_Socket->IsClosed ())
|
||||||
{
|
{
|
||||||
m_Socket->RemoveReference ();
|
m_Socket->RemoveReference ();
|
||||||
m_Socket = NULL;
|
m_Socket = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldPacket *packet;
|
WorldPacket *packet;
|
||||||
|
|
||||||
@@ -284,7 +283,7 @@ void WorldSession::LogoutPlayer(bool Save)
|
|||||||
|
|
||||||
// give honor to all attackers from set like group case
|
// give honor to all attackers from set like group case
|
||||||
for(std::set<Player*>::const_iterator itr = aset.begin(); itr != aset.end(); ++itr)
|
for(std::set<Player*>::const_iterator itr = aset.begin(); itr != aset.end(); ++itr)
|
||||||
(*itr)->RewardHonor(_player, aset.size(), -1, true);
|
(*itr)->RewardHonor(_player,aset.size());
|
||||||
|
|
||||||
// give bg rewards and update counters like kill by first from attackers
|
// give bg rewards and update counters like kill by first from attackers
|
||||||
// this can't be called for all attackers.
|
// this can't be called for all attackers.
|
||||||
@@ -402,7 +401,7 @@ void WorldSession::LogoutPlayer(bool Save)
|
|||||||
///- Since each account can only have one online character at any given time, ensure all characters for active account are marked as offline
|
///- Since each account can only have one online character at any given time, ensure all characters for active account are marked as offline
|
||||||
//No SQL injection as AccountId is uint32
|
//No SQL injection as AccountId is uint32
|
||||||
CharacterDatabase.PExecute("UPDATE characters SET online = 0 WHERE account = '%u'",
|
CharacterDatabase.PExecute("UPDATE characters SET online = 0 WHERE account = '%u'",
|
||||||
GetAccountId());
|
GetAccountId());
|
||||||
sLog.outDebug( "SESSION: Sent SMSG_LOGOUT_COMPLETE Message" );
|
sLog.outDebug( "SESSION: Sent SMSG_LOGOUT_COMPLETE Message" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,8 +413,8 @@ void WorldSession::LogoutPlayer(bool Save)
|
|||||||
/// Kick a player out of the World
|
/// Kick a player out of the World
|
||||||
void WorldSession::KickPlayer()
|
void WorldSession::KickPlayer()
|
||||||
{
|
{
|
||||||
if (m_Socket)
|
if (m_Socket)
|
||||||
m_Socket->CloseSocket ();
|
m_Socket->CloseSocket ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Cancel channeling handler
|
/// Cancel channeling handler
|
||||||
@@ -521,7 +520,3 @@ void WorldSession::SendAuthWaitQue(uint32 position)
|
|||||||
SendPacket(&packet);
|
SendPacket(&packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+650
-694
File diff suppressed because it is too large
Load Diff
+104
-104
@@ -10,12 +10,12 @@
|
|||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** \addtogroup u2w User to World Communication
|
/** \addtogroup u2w User to World Communication
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _WORLDSOCKET_H
|
#ifndef _WORLDSOCKET_H
|
||||||
#define _WORLDSOCKET_H
|
#define _WORLDSOCKET_H
|
||||||
|
|
||||||
#include <ace/Basic_Types.h>
|
#include <ace/Basic_Types.h>
|
||||||
#include <ace/Synch_Traits.h>
|
#include <ace/Synch_Traits.h>
|
||||||
@@ -90,146 +90,146 @@ typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> WorldHandler;
|
|||||||
*/
|
*/
|
||||||
class WorldSocket : protected WorldHandler
|
class WorldSocket : protected WorldHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Declare some friends
|
/// Declare some friends
|
||||||
friend class ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR >;
|
friend class ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR >;
|
||||||
friend class WorldSocketMgr;
|
friend class WorldSocketMgr;
|
||||||
friend class ReactorRunnable;
|
friend class ReactorRunnable;
|
||||||
|
|
||||||
/// Declare the acceptor for this class
|
/// Declare the acceptor for this class
|
||||||
typedef ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR > Acceptor;
|
typedef ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR > Acceptor;
|
||||||
|
|
||||||
/// Mutex type used for various syncronizations.
|
/// Mutex type used for various syncronizations.
|
||||||
typedef ACE_Thread_Mutex LockType;
|
typedef ACE_Thread_Mutex LockType;
|
||||||
typedef ACE_Guard<LockType> GuardType;
|
typedef ACE_Guard<LockType> GuardType;
|
||||||
|
|
||||||
/// Queue for storing packets for which there is no space.
|
/// Queue for storing packets for which there is no space.
|
||||||
typedef ACE_Unbounded_Queue< WorldPacket* > PacketQueueT;
|
typedef ACE_Unbounded_Queue< WorldPacket* > PacketQueueT;
|
||||||
|
|
||||||
/// Check if socket is closed.
|
/// Check if socket is closed.
|
||||||
bool IsClosed (void) const;
|
bool IsClosed (void) const;
|
||||||
|
|
||||||
/// Close the socket.
|
/// Close the socket.
|
||||||
void CloseSocket (void);
|
void CloseSocket (void);
|
||||||
|
|
||||||
/// Get address of connected peer.
|
/// Get address of connected peer.
|
||||||
const std::string& GetRemoteAddress (void) const;
|
const std::string& GetRemoteAddress (void) const;
|
||||||
|
|
||||||
/// Send A packet on the socket, this function is reentrant.
|
/// Send A packet on the socket, this function is reentrant.
|
||||||
/// @param pct packet to send
|
/// @param pct packet to send
|
||||||
/// @return -1 of failure
|
/// @return -1 of failure
|
||||||
int SendPacket (const WorldPacket& pct);
|
int SendPacket (const WorldPacket& pct);
|
||||||
|
|
||||||
/// Add refference to this object.
|
/// Add refference to this object.
|
||||||
long AddReference (void);
|
long AddReference (void);
|
||||||
|
|
||||||
/// Remove refference to this object.
|
/// Remove refference to this object.
|
||||||
long RemoveReference (void);
|
long RemoveReference (void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// things called by ACE framework.
|
/// things called by ACE framework.
|
||||||
WorldSocket (void);
|
WorldSocket (void);
|
||||||
virtual ~WorldSocket (void);
|
virtual ~WorldSocket (void);
|
||||||
|
|
||||||
/// Called on open ,the void* is the acceptor.
|
/// Called on open ,the void* is the acceptor.
|
||||||
virtual int open (void *);
|
virtual int open (void *);
|
||||||
|
|
||||||
/// Called on failures inside of the acceptor, don't call from your code.
|
/// Called on failures inside of the acceptor, don't call from your code.
|
||||||
virtual int close (int);
|
virtual int close (int);
|
||||||
|
|
||||||
/// Called when we can read from the socket.
|
/// Called when we can read from the socket.
|
||||||
virtual int handle_input (ACE_HANDLE = ACE_INVALID_HANDLE);
|
virtual int handle_input (ACE_HANDLE = ACE_INVALID_HANDLE);
|
||||||
|
|
||||||
/// Called when the socket can write.
|
/// Called when the socket can write.
|
||||||
virtual int handle_output (ACE_HANDLE = ACE_INVALID_HANDLE);
|
virtual int handle_output (ACE_HANDLE = ACE_INVALID_HANDLE);
|
||||||
|
|
||||||
/// Called when connection is closed or error happens.
|
/// Called when connection is closed or error happens.
|
||||||
virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE,
|
virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE,
|
||||||
ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
|
ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
|
||||||
|
|
||||||
/// Called by WorldSocketMgr/ReactorRunnable.
|
/// Called by WorldSocketMgr/ReactorRunnable.
|
||||||
int Update (void);
|
int Update (void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Helper functions for processing incoming data.
|
/// Helper functions for processing incoming data.
|
||||||
int handle_input_header (void);
|
int handle_input_header (void);
|
||||||
int handle_input_payload (void);
|
int handle_input_payload (void);
|
||||||
int handle_input_missing_data (void);
|
int handle_input_missing_data (void);
|
||||||
|
|
||||||
/// Help functions to mark/unmark the socket for output.
|
/// Help functions to mark/unmark the socket for output.
|
||||||
/// @param g the guard is for m_OutBufferLock, the function will release it
|
/// @param g the guard is for m_OutBufferLock, the function will release it
|
||||||
int cancel_wakeup_output (GuardType& g);
|
int cancel_wakeup_output (GuardType& g);
|
||||||
int schedule_wakeup_output (GuardType& g);
|
int schedule_wakeup_output (GuardType& g);
|
||||||
|
|
||||||
/// process one incoming packet.
|
/// process one incoming packet.
|
||||||
/// @param new_pct received packet ,note that you need to delete it.
|
/// @param new_pct received packet ,note that you need to delete it.
|
||||||
int ProcessIncoming (WorldPacket* new_pct);
|
int ProcessIncoming (WorldPacket* new_pct);
|
||||||
|
|
||||||
/// Called by ProcessIncoming() on CMSG_AUTH_SESSION.
|
/// Called by ProcessIncoming() on CMSG_AUTH_SESSION.
|
||||||
int HandleAuthSession (WorldPacket& recvPacket);
|
int HandleAuthSession (WorldPacket& recvPacket);
|
||||||
|
|
||||||
/// Called by ProcessIncoming() on CMSG_PING.
|
/// Called by ProcessIncoming() on CMSG_PING.
|
||||||
int HandlePing (WorldPacket& recvPacket);
|
int HandlePing (WorldPacket& recvPacket);
|
||||||
|
|
||||||
/// Try to write WorldPacket to m_OutBuffer ,return -1 if no space
|
/// Try to write WorldPacket to m_OutBuffer ,return -1 if no space
|
||||||
/// Need to be called with m_OutBufferLock lock held
|
/// Need to be called with m_OutBufferLock lock held
|
||||||
int iSendPacket (const WorldPacket& pct);
|
int iSendPacket (const WorldPacket& pct);
|
||||||
|
|
||||||
/// Flush m_PacketQueue if there are packets in it
|
/// Flush m_PacketQueue if there are packets in it
|
||||||
/// Need to be called with m_OutBufferLock lock held
|
/// Need to be called with m_OutBufferLock lock held
|
||||||
/// @return true if it wrote to the buffer ( AKA you need
|
/// @return true if it wrote to the buffer ( AKA you need
|
||||||
/// to mark the socket for output ).
|
/// to mark the socket for output ).
|
||||||
bool iFlushPacketQueue ();
|
bool iFlushPacketQueue ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Time in which the last ping was received
|
/// Time in which the last ping was received
|
||||||
ACE_Time_Value m_LastPingTime;
|
ACE_Time_Value m_LastPingTime;
|
||||||
|
|
||||||
/// Keep track of overspeed pings ,to prevent ping flood.
|
/// Keep track of overspeed pings ,to prevent ping flood.
|
||||||
uint32 m_OverSpeedPings;
|
uint32 m_OverSpeedPings;
|
||||||
|
|
||||||
/// Address of the remote peer
|
/// Address of the remote peer
|
||||||
std::string m_Address;
|
std::string m_Address;
|
||||||
|
|
||||||
/// Class used for managing encryption of the headers
|
/// Class used for managing encryption of the headers
|
||||||
AuthCrypt m_Crypt;
|
AuthCrypt m_Crypt;
|
||||||
|
|
||||||
/// Mutex lock to protect m_Session
|
/// Mutex lock to protect m_Session
|
||||||
LockType m_SessionLock;
|
LockType m_SessionLock;
|
||||||
|
|
||||||
/// Session to which recieved packets are routed
|
/// Session to which recieved packets are routed
|
||||||
WorldSession* m_Session;
|
WorldSession* m_Session;
|
||||||
|
|
||||||
/// here are stored the fragmens of the recieved data
|
/// here are stored the fragmens of the recieved data
|
||||||
WorldPacket* m_RecvWPct;
|
WorldPacket* m_RecvWPct;
|
||||||
|
|
||||||
/// This block actually refers to m_RecvWPct contents,
|
/// This block actually refers to m_RecvWPct contents,
|
||||||
/// which alows easy and safe writing to it.
|
/// which alows easy and safe writing to it.
|
||||||
/// It wont free memory when its deleted. m_RecvWPct takes care of freeing.
|
/// It wont free memory when its deleted. m_RecvWPct takes care of freeing.
|
||||||
ACE_Message_Block m_RecvPct;
|
ACE_Message_Block m_RecvPct;
|
||||||
|
|
||||||
/// Fragment of the recieved header.
|
/// Fragment of the recieved header.
|
||||||
ACE_Message_Block m_Header;
|
ACE_Message_Block m_Header;
|
||||||
|
|
||||||
/// Mutex for protecting otuput related data.
|
/// Mutex for protecting otuput related data.
|
||||||
LockType m_OutBufferLock;
|
LockType m_OutBufferLock;
|
||||||
|
|
||||||
/// Buffer used for writing output.
|
/// Buffer used for writing output.
|
||||||
ACE_Message_Block *m_OutBuffer;
|
ACE_Message_Block *m_OutBuffer;
|
||||||
|
|
||||||
/// Size of the m_OutBuffer.
|
/// Size of the m_OutBuffer.
|
||||||
size_t m_OutBufferSize;
|
size_t m_OutBufferSize;
|
||||||
|
|
||||||
/// Here are stored packets for which there was no space on m_OutBuffer,
|
/// Here are stored packets for which there was no space on m_OutBuffer,
|
||||||
/// this alows not-to kick player if its buffer is overflowed.
|
/// this alows not-to kick player if its buffer is overflowed.
|
||||||
PacketQueueT m_PacketQueue;
|
PacketQueueT m_PacketQueue;
|
||||||
|
|
||||||
/// True if the socket is registered with the reactor for output
|
/// True if the socket is registered with the reactor for output
|
||||||
bool m_OutActive;
|
bool m_OutActive;
|
||||||
|
|
||||||
uint32 m_Seed;
|
uint32 m_Seed;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _WORLDSOCKET_H */
|
#endif /* _WORLDSOCKET_H */
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|||||||
Reference in New Issue
Block a user