From 3b42b1df9b00118a63e2880729c4de3a3293aca4 Mon Sep 17 00:00:00 2001 From: ShelbyZ Date: Thu, 19 Oct 2017 16:18:16 -0700 Subject: [PATCH 1/2] Fixing some type alignments via casting - static_cast for reasonable values - at least one stray float --- src/servers/Server_Common/Crypt/base64.cpp | 4 ++-- src/servers/Server_Lobby/client_http.hpp | 6 +++--- src/servers/Server_REST/main.cpp | 2 +- src/servers/Server_REST/server_http.hpp | 2 +- src/servers/Server_Zone/Actor/BattleNpc.cpp | 2 +- src/servers/Server_Zone/Actor/CalcBattle.cpp | 4 ++-- src/servers/Server_Zone/Actor/Player.cpp | 2 +- src/servers/Server_Zone/Actor/PlayerQuest.cpp | 2 +- src/servers/Server_Zone/Network/Handlers/ActionHandler.cpp | 4 ++-- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/servers/Server_Common/Crypt/base64.cpp b/src/servers/Server_Common/Crypt/base64.cpp index 3ad4db0d..c6c23efc 100644 --- a/src/servers/Server_Common/Crypt/base64.cpp +++ b/src/servers/Server_Common/Crypt/base64.cpp @@ -93,7 +93,7 @@ std::string Core::Util::base64_decode( std::string const& encoded_string ) { char_array_4[i++] = encoded_string[in_]; in_++; if( i == 4 ) { for( i = 0; i < 4; i++ ) - char_array_4[i] = base64_chars.find( char_array_4[i] ); + char_array_4[i] = static_cast( base64_chars.find( char_array_4[i] ) ); char_array_3[0] = ( char_array_4[0] << 2 ) + ( ( char_array_4[1] & 0x30 ) >> 4 ); char_array_3[1] = ( ( char_array_4[1] & 0xf ) << 4 ) + ( ( char_array_4[2] & 0x3c ) >> 2 ); @@ -110,7 +110,7 @@ std::string Core::Util::base64_decode( std::string const& encoded_string ) { char_array_4[j] = 0; for( j = 0; j < 4; j++ ) - char_array_4[j] = base64_chars.find( char_array_4[j] ); + char_array_4[j] = static_cast( base64_chars.find( char_array_4[j] ) ); char_array_3[0] = ( char_array_4[0] << 2 ) + ( ( char_array_4[1] & 0x30 ) >> 4 ); char_array_3[1] = ( ( char_array_4[1] & 0xf ) << 4 ) + ( ( char_array_4[2] & 0x3c ) >> 2 ); diff --git a/src/servers/Server_Lobby/client_http.hpp b/src/servers/Server_Lobby/client_http.hpp index c7b9137b..b099c74f 100644 --- a/src/servers/Server_Lobby/client_http.hpp +++ b/src/servers/Server_Lobby/client_http.hpp @@ -266,7 +266,7 @@ namespace SimpleWeb { if( content_length>num_additional_bytes ) { auto timer = get_timeout_timer(); boost::asio::async_read( *socket, response->content_buffer, - boost::asio::transfer_exactly( content_length - num_additional_bytes ), + boost::asio::transfer_exactly( static_cast( content_length - num_additional_bytes ) ), [this, timer]( const boost::system::error_code& ec, size_t /*bytes_transferred*/ ) { if( timer ) timer->cancel(); @@ -307,7 +307,7 @@ namespace SimpleWeb { line.pop_back(); std::streamsize length = stol( line, 0, 16 ); - auto num_additional_bytes = static_cast( response->content_buffer.size() - bytes_transferred ); + auto num_additional_bytes = response->content_buffer.size() - bytes_transferred; auto post_process = [this, &response, &streambuf, length] { std::ostream stream( &streambuf ); @@ -332,7 +332,7 @@ namespace SimpleWeb { if( ( 2 + length )>num_additional_bytes ) { auto timer = get_timeout_timer(); boost::asio::async_read( *socket, response->content_buffer, - boost::asio::transfer_exactly( 2 + length - num_additional_bytes ), + boost::asio::transfer_exactly( static_cast( 2 + length - num_additional_bytes ) ), [this, post_process, timer]( const boost::system::error_code& ec, size_t /*bytes_transferred*/ ) { if( timer ) timer->cancel(); diff --git a/src/servers/Server_REST/main.cpp b/src/servers/Server_REST/main.cpp index 7173db63..b509e9cf 100644 --- a/src/servers/Server_REST/main.cpp +++ b/src/servers/Server_REST/main.cpp @@ -149,7 +149,7 @@ bool loadSettings( int32_t argc, char* argv[] ) params.port = m_pConfig->getValue< uint16_t >( "Settings.General.Mysql.Port", 3306 ); params.username = m_pConfig->getValue< std::string >( "Settings.General.Mysql.Username", "root" ); - server.config.port = std::stoul( m_pConfig->getValue( "Settings.General.HttpPort", "80" ) ); + server.config.port = static_cast( std::stoul( m_pConfig->getValue( "Settings.General.HttpPort", "80" ) ) ); if( !g_database.initialize( params ) ) { diff --git a/src/servers/Server_REST/server_http.hpp b/src/servers/Server_REST/server_http.hpp index 82ee541a..64f10234 100644 --- a/src/servers/Server_REST/server_http.hpp +++ b/src/servers/Server_REST/server_http.hpp @@ -282,7 +282,7 @@ namespace SimpleWeb { //Set timeout on the following boost::asio::async-read or write function auto timer=this->get_timeout_timer(socket, config.timeout_content); boost::asio::async_read(*socket, request->streambuf, - boost::asio::transfer_exactly(content_length-num_additional_bytes), + boost::asio::transfer_exactly(static_cast(content_length-num_additional_bytes)), [this, socket, request, timer] (const boost::system::error_code& ec, size_t /*bytes_transferred*/) { if(timer) diff --git a/src/servers/Server_Zone/Actor/BattleNpc.cpp b/src/servers/Server_Zone/Actor/BattleNpc.cpp index d8f098e9..d9d62e36 100644 --- a/src/servers/Server_Zone/Actor/BattleNpc.cpp +++ b/src/servers/Server_Zone/Actor/BattleNpc.cpp @@ -451,7 +451,7 @@ void Core::Entity::BattleNpc::onDeath() // todo: this is actually retarded, we need real rand() - srand( time( NULL ) ); + srand( static_cast( time( NULL ) ) ); auto pPlayer = pHateEntry->m_pActor->getAsPlayer(); pPlayer->gainExp( exp ); diff --git a/src/servers/Server_Zone/Actor/CalcBattle.cpp b/src/servers/Server_Zone/Actor/CalcBattle.cpp index 5bc0d252..9687b02a 100644 --- a/src/servers/Server_Zone/Actor/CalcBattle.cpp +++ b/src/servers/Server_Zone/Actor/CalcBattle.cpp @@ -38,7 +38,7 @@ float CalcBattle::calculateBaseStat( PlayerPtr pPlayer ) // SB Base Stat Formula (Aligned) if ( level > 60 ) { - base = ( ( ( level == 61 ) ? 224 : 220 ) + ( level - 61 ) * 8); + base = static_cast( ( ( ( level == 61 ) ? 224 : 220 ) + ( level - 61 ) * 8) ); } // HW Base Stat Formula (Aligned) else if ( level > 50 ) @@ -77,7 +77,7 @@ uint32_t CalcBattle::calculateMaxHp( PlayerPtr pPlayer ) // These values are not precise. if ( level >= 60 ) - approxBaseHp = 2600 + ( level - 60 ) * 100; + approxBaseHp = static_cast( 2600 + ( level - 60 ) * 100 ); else if ( level >= 50 ) approxBaseHp = 1700 + ( ( level - 50 ) * ( 1700 * 1.04325f ) ); else diff --git a/src/servers/Server_Zone/Actor/Player.cpp b/src/servers/Server_Zone/Actor/Player.cpp index 39d5d709..349fc15e 100644 --- a/src/servers/Server_Zone/Actor/Player.cpp +++ b/src/servers/Server_Zone/Actor/Player.cpp @@ -345,7 +345,7 @@ void Core::Entity::Player::teleport( uint16_t aetheryteId, uint8_t type ) void Core::Entity::Player::forceZoneing( uint32_t zoneId ) { - m_queuedZoneing = boost::make_shared< QueuedZoning >( zoneId, getPos(), Util::getTimeMs(), 0 ); + m_queuedZoneing = boost::make_shared< QueuedZoning >( zoneId, getPos(), Util::getTimeMs(), 0.f ); //performZoning( zoneId, Common::ZoneingType::None, getPos() ); } diff --git a/src/servers/Server_Zone/Actor/PlayerQuest.cpp b/src/servers/Server_Zone/Actor/PlayerQuest.cpp index 668460a7..ab617d2e 100644 --- a/src/servers/Server_Zone/Actor/PlayerQuest.cpp +++ b/src/servers/Server_Zone/Actor/PlayerQuest.cpp @@ -1147,7 +1147,7 @@ bool Core::Entity::Player::giveQuestRewards( uint32_t questId, uint32_t optional exp = questInfo->reward_exp_factor; - uint16_t rewardItemCount = questInfo->reward_item.size(); + auto rewardItemCount = questInfo->reward_item.size(); uint16_t optionalItemCount = questInfo->reward_item_optional.size() > 0 ? 1 : 0; uint32_t gilReward = questInfo->reward_gil; diff --git a/src/servers/Server_Zone/Network/Handlers/ActionHandler.cpp b/src/servers/Server_Zone/Network/Handlers/ActionHandler.cpp index 9a6dcd6a..df033f74 100644 --- a/src/servers/Server_Zone/Network/Handlers/ActionHandler.cpp +++ b/src/servers/Server_Zone/Network/Handlers/ActionHandler.cpp @@ -216,8 +216,8 @@ void Core::Network::GameConnection::actionHandler( const Packets::GamePacket& in auto fromAetheryte = g_exdData.getAetheryteInfo( g_exdData.m_zoneInfoMap[pPlayer->getZoneId()].aetheryte_index ); // calculate cost - does not apply for favorite points or homepoints neither checks for aether tickets - auto cost = ( sqrt( pow( fromAetheryte->map_coord_x - targetAetheryte->map_coord_x, 2 ) + - pow( fromAetheryte->map_coord_y - targetAetheryte->map_coord_y, 2 ) ) / 2 ) + 100; + auto cost = static_cast ( ( sqrt( pow( fromAetheryte->map_coord_x - targetAetheryte->map_coord_x, 2 ) + + pow( fromAetheryte->map_coord_y - targetAetheryte->map_coord_y, 2 ) ) / 2 ) + 100 ); // cap at 999 gil cost = cost > 999 ? 999 : cost; From 54548e192842f5f7ee90381563261bc02896f3d0 Mon Sep 17 00:00:00 2001 From: ShelbyZ Date: Fri, 20 Oct 2017 14:12:24 -0700 Subject: [PATCH 2/2] Fixing spacing issues for casts --- src/servers/Server_Common/Crypt/base64.cpp | 4 ++-- src/servers/Server_Lobby/client_http.hpp | 4 ++-- src/servers/Server_REST/main.cpp | 2 +- src/servers/Server_REST/server_http.hpp | 2 +- src/servers/Server_Zone/Actor/BattleNpc.cpp | 2 +- src/servers/Server_Zone/Actor/CalcBattle.cpp | 4 ++-- src/servers/Server_Zone/Network/Handlers/ActionHandler.cpp | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/servers/Server_Common/Crypt/base64.cpp b/src/servers/Server_Common/Crypt/base64.cpp index c6c23efc..8037dec4 100644 --- a/src/servers/Server_Common/Crypt/base64.cpp +++ b/src/servers/Server_Common/Crypt/base64.cpp @@ -93,7 +93,7 @@ std::string Core::Util::base64_decode( std::string const& encoded_string ) { char_array_4[i++] = encoded_string[in_]; in_++; if( i == 4 ) { for( i = 0; i < 4; i++ ) - char_array_4[i] = static_cast( base64_chars.find( char_array_4[i] ) ); + char_array_4[i] = static_cast< uint8_t >( base64_chars.find( char_array_4[i] ) ); char_array_3[0] = ( char_array_4[0] << 2 ) + ( ( char_array_4[1] & 0x30 ) >> 4 ); char_array_3[1] = ( ( char_array_4[1] & 0xf ) << 4 ) + ( ( char_array_4[2] & 0x3c ) >> 2 ); @@ -110,7 +110,7 @@ std::string Core::Util::base64_decode( std::string const& encoded_string ) { char_array_4[j] = 0; for( j = 0; j < 4; j++ ) - char_array_4[j] = static_cast( base64_chars.find( char_array_4[j] ) ); + char_array_4[j] = static_cast< uint8_t >( base64_chars.find( char_array_4[j] ) ); char_array_3[0] = ( char_array_4[0] << 2 ) + ( ( char_array_4[1] & 0x30 ) >> 4 ); char_array_3[1] = ( ( char_array_4[1] & 0xf ) << 4 ) + ( ( char_array_4[2] & 0x3c ) >> 2 ); diff --git a/src/servers/Server_Lobby/client_http.hpp b/src/servers/Server_Lobby/client_http.hpp index b099c74f..656b8d01 100644 --- a/src/servers/Server_Lobby/client_http.hpp +++ b/src/servers/Server_Lobby/client_http.hpp @@ -266,7 +266,7 @@ namespace SimpleWeb { if( content_length>num_additional_bytes ) { auto timer = get_timeout_timer(); boost::asio::async_read( *socket, response->content_buffer, - boost::asio::transfer_exactly( static_cast( content_length - num_additional_bytes ) ), + boost::asio::transfer_exactly( static_cast< size_t >( content_length - num_additional_bytes ) ), [this, timer]( const boost::system::error_code& ec, size_t /*bytes_transferred*/ ) { if( timer ) timer->cancel(); @@ -332,7 +332,7 @@ namespace SimpleWeb { if( ( 2 + length )>num_additional_bytes ) { auto timer = get_timeout_timer(); boost::asio::async_read( *socket, response->content_buffer, - boost::asio::transfer_exactly( static_cast( 2 + length - num_additional_bytes ) ), + boost::asio::transfer_exactly( static_cast< size_t >( 2 + length - num_additional_bytes ) ), [this, post_process, timer]( const boost::system::error_code& ec, size_t /*bytes_transferred*/ ) { if( timer ) timer->cancel(); diff --git a/src/servers/Server_REST/main.cpp b/src/servers/Server_REST/main.cpp index b509e9cf..28f7c16d 100644 --- a/src/servers/Server_REST/main.cpp +++ b/src/servers/Server_REST/main.cpp @@ -149,7 +149,7 @@ bool loadSettings( int32_t argc, char* argv[] ) params.port = m_pConfig->getValue< uint16_t >( "Settings.General.Mysql.Port", 3306 ); params.username = m_pConfig->getValue< std::string >( "Settings.General.Mysql.Username", "root" ); - server.config.port = static_cast( std::stoul( m_pConfig->getValue( "Settings.General.HttpPort", "80" ) ) ); + server.config.port = static_cast< unsigned short >( std::stoul( m_pConfig->getValue( "Settings.General.HttpPort", "80" ) ) ); if( !g_database.initialize( params ) ) { diff --git a/src/servers/Server_REST/server_http.hpp b/src/servers/Server_REST/server_http.hpp index 64f10234..e946afe2 100644 --- a/src/servers/Server_REST/server_http.hpp +++ b/src/servers/Server_REST/server_http.hpp @@ -282,7 +282,7 @@ namespace SimpleWeb { //Set timeout on the following boost::asio::async-read or write function auto timer=this->get_timeout_timer(socket, config.timeout_content); boost::asio::async_read(*socket, request->streambuf, - boost::asio::transfer_exactly(static_cast(content_length-num_additional_bytes)), + boost::asio::transfer_exactly(static_cast< size_t >(content_length-num_additional_bytes)), [this, socket, request, timer] (const boost::system::error_code& ec, size_t /*bytes_transferred*/) { if(timer) diff --git a/src/servers/Server_Zone/Actor/BattleNpc.cpp b/src/servers/Server_Zone/Actor/BattleNpc.cpp index d9d62e36..6e64015a 100644 --- a/src/servers/Server_Zone/Actor/BattleNpc.cpp +++ b/src/servers/Server_Zone/Actor/BattleNpc.cpp @@ -451,7 +451,7 @@ void Core::Entity::BattleNpc::onDeath() // todo: this is actually retarded, we need real rand() - srand( static_cast( time( NULL ) ) ); + srand( static_cast< unsigned int> ( time( NULL ) ) ); auto pPlayer = pHateEntry->m_pActor->getAsPlayer(); pPlayer->gainExp( exp ); diff --git a/src/servers/Server_Zone/Actor/CalcBattle.cpp b/src/servers/Server_Zone/Actor/CalcBattle.cpp index 9687b02a..ce2e3a84 100644 --- a/src/servers/Server_Zone/Actor/CalcBattle.cpp +++ b/src/servers/Server_Zone/Actor/CalcBattle.cpp @@ -38,7 +38,7 @@ float CalcBattle::calculateBaseStat( PlayerPtr pPlayer ) // SB Base Stat Formula (Aligned) if ( level > 60 ) { - base = static_cast( ( ( ( level == 61 ) ? 224 : 220 ) + ( level - 61 ) * 8) ); + base = static_cast< float >( ( ( ( level == 61 ) ? 224 : 220 ) + ( level - 61 ) * 8) ); } // HW Base Stat Formula (Aligned) else if ( level > 50 ) @@ -77,7 +77,7 @@ uint32_t CalcBattle::calculateMaxHp( PlayerPtr pPlayer ) // These values are not precise. if ( level >= 60 ) - approxBaseHp = static_cast( 2600 + ( level - 60 ) * 100 ); + approxBaseHp = static_cast< float >( 2600 + ( level - 60 ) * 100 ); else if ( level >= 50 ) approxBaseHp = 1700 + ( ( level - 50 ) * ( 1700 * 1.04325f ) ); else diff --git a/src/servers/Server_Zone/Network/Handlers/ActionHandler.cpp b/src/servers/Server_Zone/Network/Handlers/ActionHandler.cpp index df033f74..0f53871d 100644 --- a/src/servers/Server_Zone/Network/Handlers/ActionHandler.cpp +++ b/src/servers/Server_Zone/Network/Handlers/ActionHandler.cpp @@ -216,7 +216,7 @@ void Core::Network::GameConnection::actionHandler( const Packets::GamePacket& in auto fromAetheryte = g_exdData.getAetheryteInfo( g_exdData.m_zoneInfoMap[pPlayer->getZoneId()].aetheryte_index ); // calculate cost - does not apply for favorite points or homepoints neither checks for aether tickets - auto cost = static_cast ( ( sqrt( pow( fromAetheryte->map_coord_x - targetAetheryte->map_coord_x, 2 ) + + auto cost = static_cast< uint16_t > ( ( sqrt( pow( fromAetheryte->map_coord_x - targetAetheryte->map_coord_x, 2 ) + pow( fromAetheryte->map_coord_y - targetAetheryte->map_coord_y, 2 ) ) / 2 ) + 100 ); // cap at 999 gil