refactor(Core/Game): restyle game lib with astyle (#3466)

This commit is contained in:
Kargatum
2020-10-12 15:08:15 +07:00
committed by GitHub
parent e99b526e17
commit a2b26272d2
338 changed files with 52196 additions and 50944 deletions

View File

@@ -51,23 +51,23 @@ struct ServerPktHeader
*/
ServerPktHeader(uint32 size, uint16 cmd) : size(size)
{
uint8 headerIndex=0;
uint8 headerIndex = 0;
if (isLargePacket())
{
sLog->outDebug(LOG_FILTER_NETWORKIO, "initializing large server to client packet. Size: %u, cmd: %u", size, cmd);
header[headerIndex++] = 0x80|(0xFF &(size>>16));
header[headerIndex++] = 0x80 | (0xFF & (size >> 16));
}
header[headerIndex++] = 0xFF &(size>>8);
header[headerIndex++] = 0xFF &size;
header[headerIndex++] = 0xFF & (size >> 8);
header[headerIndex++] = 0xFF & size;
header[headerIndex++] = 0xFF & cmd;
header[headerIndex++] = 0xFF & (cmd>>8);
header[headerIndex++] = 0xFF & (cmd >> 8);
}
uint8 getHeaderLength()
{
// cmd = 2 bytes, size= 2||3bytes
return 2+(isLargePacket()?3:2);
return 2 + (isLargePacket() ? 3 : 2);
}
bool isLargePacket() const
@@ -92,15 +92,15 @@ struct ClientPktHeader
#endif
WorldSocket::WorldSocket(void): WorldHandler(),
m_LastPingTime(SystemTimePoint::min()), m_OverSpeedPings(0), m_Session(0),
m_RecvWPct(0), m_RecvPct(), m_Header(sizeof (ClientPktHeader)),
m_OutBuffer(0), m_OutBufferSize(65536), m_OutActive(false),
m_Seed(static_cast<uint32> (rand32()))
m_LastPingTime(SystemTimePoint::min()), m_OverSpeedPings(0), m_Session(0),
m_RecvWPct(0), m_RecvPct(), m_Header(sizeof (ClientPktHeader)),
m_OutBuffer(0), m_OutBufferSize(65536), m_OutActive(false),
m_Seed(static_cast<uint32> (rand32()))
{
reference_counting_policy().value (ACE_Event_Handler::Reference_Counting_Policy::ENABLED);
msg_queue()->high_water_mark(8*1024*1024);
msg_queue()->low_water_mark(8*1024*1024);
msg_queue()->high_water_mark(8 * 1024 * 1024);
msg_queue()->low_water_mark(8 * 1024 * 1024);
}
WorldSocket::~WorldSocket(void)
@@ -158,7 +158,7 @@ int WorldSocket::SendPacket(WorldPacket const& pct)
if (sPacketLog->CanLogPacket())
sPacketLog->LogPacket(pct, SERVER_TO_CLIENT);
ServerPktHeader header(pct.size()+2, pct.GetOpcode());
ServerPktHeader header(pct.size() + 2, pct.GetOpcode());
m_Crypt.EncryptSend ((uint8*)header.header, header.getHeaderLength());
if (m_OutBuffer->space() >= pct.size() + header.getHeaderLength() && msg_queue()->is_empty())
@@ -204,7 +204,7 @@ long WorldSocket::RemoveReference(void)
return static_cast<long> (remove_reference());
}
int WorldSocket::open(void *a)
int WorldSocket::open(void* a)
{
ACE_UNUSED_ARG (a);
@@ -282,29 +282,29 @@ int WorldSocket::handle_input(ACE_HANDLE)
switch (handle_input_missing_data())
{
case -1 :
{
if ((errno == EWOULDBLOCK) ||
(errno == EAGAIN))
{
return Update(); // interesting line, isn't it ?
if ((errno == EWOULDBLOCK) ||
(errno == EAGAIN))
{
return Update(); // interesting line, isn't it ?
}
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outStaticDebug("WorldSocket::handle_input: Peer error closing connection errno = %s", ACE_OS::strerror (errno));
#endif
errno = ECONNRESET;
return -1;
}
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outStaticDebug("WorldSocket::handle_input: Peer error closing connection errno = %s", ACE_OS::strerror (errno));
#endif
errno = ECONNRESET;
return -1;
}
case 0:
{
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outStaticDebug("WorldSocket::handle_input: Peer has closed connection");
sLog->outStaticDebug("WorldSocket::handle_input: Peer has closed connection");
#endif
errno = ECONNRESET;
return -1;
}
errno = ECONNRESET;
return -1;
}
case 1:
return 1;
default:
@@ -533,12 +533,12 @@ int WorldSocket::handle_input_missing_data(void)
char buf [4096];
ACE_Data_Block db (sizeof (buf),
ACE_Message_Block::MB_DATA,
buf,
0,
0,
ACE_Message_Block::DONT_DELETE,
0);
ACE_Message_Block::MB_DATA,
buf,
0,
0,
ACE_Message_Block::DONT_DELETE,
0);
ACE_Message_Block message_block(&db,
ACE_Message_Block::DONT_DELETE,
@@ -547,7 +547,7 @@ int WorldSocket::handle_input_missing_data(void)
const size_t recv_size = message_block.space();
const ssize_t n = peer().recv (message_block.wr_ptr(),
recv_size);
recv_size);
if (n <= 0)
return int(n);
@@ -627,7 +627,7 @@ int WorldSocket::cancel_wakeup_output(GuardType& g)
g.release();
if (reactor()->cancel_wakeup
(this, ACE_Event_Handler::WRITE_MASK) == -1)
(this, ACE_Event_Handler::WRITE_MASK) == -1)
{
// would be good to store errno from reactor with errno guard
sLog->outError("WorldSocket::cancel_wakeup_output");
@@ -647,7 +647,7 @@ int WorldSocket::schedule_wakeup_output(GuardType& g)
g.release();
if (reactor()->schedule_wakeup
(this, ACE_Event_Handler::WRITE_MASK) == -1)
(this, ACE_Event_Handler::WRITE_MASK) == -1)
{
sLog->outError("WorldSocket::schedule_wakeup_output");
return -1;
@@ -677,15 +677,15 @@ int WorldSocket::ProcessIncoming(WorldPacket* new_pct)
switch (opcode)
{
case CMSG_PING:
{
try
{
return HandlePing(*new_pct);
try
{
return HandlePing(*new_pct);
}
catch (ByteBufferPositionException const&) {}
sLog->outError("WorldSocket::ReadDataHandler(): client sent malformed CMSG_PING");
return -1;
}
catch (ByteBufferPositionException const&) {}
sLog->outError("WorldSocket::ReadDataHandler(): client sent malformed CMSG_PING");
return -1;
}
case CMSG_AUTH_SESSION:
if (m_Session)
{
@@ -693,36 +693,36 @@ int WorldSocket::ProcessIncoming(WorldPacket* new_pct)
return -1;
}
return HandleAuthSession (*new_pct);
case CMSG_KEEP_ALIVE:
case CMSG_KEEP_ALIVE:
if (m_Session)
m_Session->ResetTimeOutTime(true);
return 0;
default:
{
ACE_GUARD_RETURN (LockType, Guard, m_SessionLock, -1);
if (m_Session != nullptr)
{
// Our Idle timer will reset on any non PING opcodes.
// Catches people idling on the login screen and any lingering ingame connections.
m_Session->ResetTimeOutTime(false);
ACE_GUARD_RETURN (LockType, Guard, m_SessionLock, -1);
// OK, give the packet to WorldSession
aptr.release();
m_Session->QueuePacket (new_pct);
return 0;
if (m_Session != nullptr)
{
// Our Idle timer will reset on any non PING opcodes.
// Catches people idling on the login screen and any lingering ingame connections.
m_Session->ResetTimeOutTime(false);
// OK, give the packet to WorldSession
aptr.release();
m_Session->QueuePacket (new_pct);
return 0;
}
else
{
sLog->outError("WorldSocket::ProcessIncoming: Client not authed opcode = %u", uint32(opcode));
return -1;
}
}
else
{
sLog->outError("WorldSocket::ProcessIncoming: Client not authed opcode = %u", uint32(opcode));
return -1;
}
}
}
}
catch (ByteBufferException const&)
{
sLog->outError("WorldSocket::ProcessIncoming ByteBufferException occured while parsing an instant handled packet (opcode: %u) from client %s, accountid=%i. Disconnected client.", opcode, GetRemoteAddress().c_str(), m_Session?m_Session->GetAccountId():-1);
sLog->outError("WorldSocket::ProcessIncoming ByteBufferException occured while parsing an instant handled packet (opcode: %u) from client %s, accountid=%i. Disconnected client.", opcode, GetRemoteAddress().c_str(), m_Session ? m_Session->GetAccountId() : -1);
if (sLog->IsOutDebug())
{
sLog->outDebug(LOG_FILTER_NETWORKIO, "Dumping error causing packet:");
@@ -940,9 +940,9 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
uint32 seed = m_Seed;
sha.UpdateData (account);
sha.UpdateData ((uint8 *) & t, 4);
sha.UpdateData ((uint8 *) & clientSeed, 4);
sha.UpdateData ((uint8 *) & seed, 4);
sha.UpdateData ((uint8*) & t, 4);
sha.UpdateData ((uint8*) & clientSeed, 4);
sha.UpdateData ((uint8*) & seed, 4);
sha.UpdateBigNumbers (&k, nullptr);
sha.Finalize();
@@ -959,8 +959,8 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outStaticDebug("WorldSocket::HandleAuthSession: Client '%s' authenticated successfully from %s.",
account.c_str(),
address.c_str());
account.c_str(),
address.c_str());
#endif
// Check if this user is by any chance a recruiter
stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_RECRUITER);
@@ -1005,7 +1005,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
SendPacket(packet);
sLog->outError("WorldSocket::HandleAuthSession: Client %s requested connecting with realm id %u but this realm has id %u set in config.",
address.c_str(), realm, realmID);
address.c_str(), realm, realmID);
sScriptMgr->OnFailedAccountLogin(id);
return -1;
}
@@ -1044,7 +1044,7 @@ int WorldSocket::HandlePing(WorldPacket& recvPacket)
else
{
auto now = std::chrono::system_clock::now();
Seconds seconds = std::chrono::duration_cast<Seconds>(now - m_LastPingTime);
Seconds seconds = std::chrono::duration_cast<Seconds>(now - m_LastPingTime);
m_LastPingTime = now;
if (seconds.count() < 27)
@@ -1061,10 +1061,10 @@ int WorldSocket::HandlePing(WorldPacket& recvPacket)
{
Player* _player = m_Session->GetPlayer();
sLog->outError("WorldSocket::HandlePing: Player (account: %u, GUID: %u, name: %s) kicked for over-speed pings (address: %s)",
m_Session->GetAccountId(),
_player ? _player->GetGUIDLow() : 0,
_player ? _player->GetName().c_str() : "<none>",
GetRemoteAddress().c_str());
m_Session->GetAccountId(),
_player ? _player->GetGUIDLow() : 0,
_player ? _player->GetName().c_str() : "<none>",
GetRemoteAddress().c_str());
return -1;
}
@@ -1086,10 +1086,10 @@ int WorldSocket::HandlePing(WorldPacket& recvPacket)
else
{
sLog->outError("WorldSocket::HandlePing: peer sent CMSG_PING, "
"but is not authenticated or got recently kicked, "
" address = %s",
GetRemoteAddress().c_str());
return -1;
"but is not authenticated or got recently kicked, "
" address = %s",
GetRemoteAddress().c_str());
return -1;
}
}