fixed all printf warnings for Linux & Windows

This commit is contained in:
otavepto 2023-12-21 03:20:32 +02:00 committed by otavepto
parent 13bc94ad75
commit 1b04526d9d
10 changed files with 36 additions and 31 deletions

View File

@ -168,6 +168,9 @@ static inline void reset_LastError()
// PRINT_DEBUG definition
// notice the extra call to WSASetLastError(0) in Windows def
#ifndef EMU_RELEASE_BUILD
// we need this for printf specifiers for intptr_t such as PRIdPTR
#include <inttypes.h>
//#define PRINT_DEBUG(...) fprintf(stdout, __VA_ARGS__)
extern const std::string dbg_log_file;
extern const std::chrono::time_point<std::chrono::high_resolution_clock> startup_counter;

View File

@ -6697,7 +6697,8 @@ STEAMAPI_API void *SteamAPI_ISteamGameServer_GetPublicIP( intptr_t instancePtr,
get_steam_client()->steam_gameserver->GetPublicIP_fix((SteamIPAddress_t *)instancePtr);
return (void *)instancePtr;
} else {
return (void *)((ISteamGameServer012 *)instancePtr)->GetPublicIP_old();
// (char*)0 will silence the compiler warning
return (void *)( (char*)0 + ((ISteamGameServer012 *)instancePtr)->GetPublicIP_old() );
}
}

View File

@ -459,7 +459,7 @@ static bool unbuffer_tcp(struct TCP_Socket &socket, Common_Message *msg)
socket.recv_buffer.erase(socket.recv_buffer.begin(), socket.recv_buffer.begin() + sizeof(l) + l);
return true;
} else {
PRINT_DEBUG("BAD TCP DATA %lu %zu %zu %hhu\n", l, socket.recv_buffer.size(), sizeof(uint32), *((char *)&(socket.recv_buffer[sizeof(uint32)])));
PRINT_DEBUG("BAD TCP DATA %u %zu %zu %hhu\n", l, socket.recv_buffer.size(), sizeof(uint32), *((char *)&(socket.recv_buffer[sizeof(uint32)])));
kill_tcp_socket(socket);
}
@ -514,7 +514,8 @@ std::set<IP_PORT> Networking::resolve_ip(std::string dns)
if (getaddrinfo(dns.c_str(), NULL, NULL, &result) == 0) {
for (struct addrinfo *res = result; res != NULL; res = res->ai_next) {
PRINT_DEBUG("%zu %u\n", res->ai_addrlen, res->ai_family);
// cast to size_t because on Linux 'ai_addrlen' is defined as unsigned int and clang complains
PRINT_DEBUG("%zu %u\n", (size_t)res->ai_addrlen, res->ai_family);
if (res->ai_family == AF_INET) {
struct sockaddr_in *ipv4 = (struct sockaddr_in *)res->ai_addr;
uint32 ip;
@ -675,7 +676,7 @@ bool Networking::handle_announce(Common_Message *msg, IP_PORT ip_port)
PRINT_DEBUG("New Connection Created\n");
}
PRINT_DEBUG("Handle Announce: %lu, %llu, %lu, %u\n", conn->appid, msg->source_id(), msg->announce().appid(), msg->announce().type());
PRINT_DEBUG("Handle Announce: %u, " "%" PRIu64 ", %u, %u\n", conn->appid, msg->source_id(), msg->announce().appid(), msg->announce().type());
conn->tcp_ip_port = ip_port;
conn->tcp_ip_port.port = htons(msg->announce().tcp_port());
conn->appid = msg->announce().appid();
@ -692,7 +693,7 @@ bool Networking::handle_announce(Common_Message *msg, IP_PORT ip_port)
}
Connection *conn = find_connection((uint64)msg->announce().peers(i).id(), msg->announce().peers(i).appid());
PRINT_DEBUG("%p %lu %lu %llu\n", conn, conn ? conn->appid : 0, msg->announce().peers(i).appid(), msg->announce().peers(i).id());
PRINT_DEBUG("%p %u %u " "%" PRIu64 "\n", conn, conn ? conn->appid : (uint32)0, msg->announce().peers(i).appid(), msg->announce().peers(i).id());
if (!conn || conn->appid != msg->announce().peers(i).appid()) {
Common_Message msg_ = create_announce(true);
@ -882,7 +883,7 @@ Common_Message Networking::create_announce(bool request)
} else {
announce->set_type(Announce::PONG);
for (auto &conn: connections) {
PRINT_DEBUG("Connection %u %llu %lu\n", conn.udp_pinged, conn.ids[0].ConvertToUint64(), conn.appid);
PRINT_DEBUG("Connection %u %llu %u\n", conn.udp_pinged, conn.ids[0].ConvertToUint64(), conn.appid);
if (conn.udp_pinged) {
Announce_Other_Peers *peer = announce->add_peers();
peer->set_id(conn.ids[0].ConvertToUint64());

View File

@ -412,7 +412,7 @@ bool GetFriendGamePlayed( CSteamID steamIDFriend, STEAM_OUT_STRUCT() FriendGameI
pFriendGameInfo->m_usGamePort = 0;
pFriendGameInfo->m_usQueryPort = 0;
pFriendGameInfo->m_steamIDLobby = CSteamID((uint64)f->lobby_id());
PRINT_DEBUG("%u %llu\n", f->appid(), f->lobby_id());
PRINT_DEBUG("%u " "%" PRIu64 "\n", f->appid(), f->lobby_id());
}
ret = true;
@ -1206,7 +1206,7 @@ void Callback(Common_Message *msg)
}
if (msg->has_friend_()) {
PRINT_DEBUG("Steam_Friends Friend %llu %llu\n", msg->friend_().id(), msg->friend_().lobby_id());
PRINT_DEBUG("Steam_Friends Friend " "%" PRIu64 " " "%" PRIu64 "\n", msg->friend_().id(), msg->friend_().lobby_id());
Friend *f = find_friend((uint64)msg->friend_().id());
if (!f) {
if (msg->friend_().id() != settings->get_local_steam_id().ConvertToUint64()) {

View File

@ -127,7 +127,7 @@ void send_lobby_data()
for(auto & l: lobbies) {
if (get_lobby_member(&l, settings->get_local_steam_id()) && l.owner() == settings->get_local_steam_id().ConvertToUint64() && !l.deleted()) {
PRINT_DEBUG("Sending lobby %llu\n", l.room_id());
PRINT_DEBUG("Sending lobby " "%" PRIu64 "\n", l.room_id());
Common_Message msg = Common_Message();
msg.set_source_id(settings->get_local_steam_id().ConvertToUint64());
msg.set_allocated_lobby(new Lobby(l));
@ -264,7 +264,7 @@ void remove_lobbies()
auto g = std::begin(lobbies);
while (g != std::end(lobbies)) {
if (g->members().size() == 0 || (g->deleted() && (g->time_deleted() + LOBBY_DELETED_TIMEOUT < current_time))) {
PRINT_DEBUG("REMOVING LOBBY %llu\n", g->room_id());
PRINT_DEBUG("REMOVING LOBBY " "%" PRIu64 "\n", g->room_id());
self_lobby_member_data.erase(g->room_id());
g = lobbies.erase(g);
} else {
@ -372,7 +372,7 @@ bool GetFavoriteGame( int iGame, AppId_t *pnAppID, uint32 *pnIP, uint16 *pnConnP
// adds the game server to the local list; updates the time played of the server if it already exists in the list
int AddFavoriteGame( AppId_t nAppID, uint32 nIP, uint16 nConnPort, uint16 nQueryPort, uint32 unFlags, uint32 rTime32LastPlayedOnServer )
{
PRINT_DEBUG("AddFavoriteGame %lu %lu %hu %hu %lu %lu\n", nAppID, nIP, nConnPort, nQueryPort, unFlags, rTime32LastPlayedOnServer);
PRINT_DEBUG("AddFavoriteGame %u %u %hu %hu %u %u\n", nAppID, nIP, nConnPort, nQueryPort, unFlags, rTime32LastPlayedOnServer);
std::string file_path;
unsigned long long file_size;
@ -1406,7 +1406,7 @@ void RunCallbacks()
}
}
PRINT_DEBUG("Lobby %llu use %u\n", l.room_id(), use);
PRINT_DEBUG("Lobby " "%" PRIu64 " use %u\n", l.room_id(), use);
if (use) PUSH_BACK_IF_NOT_IN(filtered_lobbies, (uint64)l.room_id());
if (filtered_lobbies.size() >= filter_max_results_copy) {
searching = false;
@ -1501,7 +1501,7 @@ void RunCallbacks()
void Callback(Common_Message *msg)
{
if (msg->has_lobby()) {
PRINT_DEBUG("GOT A LOBBY appid: %lu\n", msg->lobby().appid());
PRINT_DEBUG("GOT A LOBBY appid: %u\n", msg->lobby().appid());
if (msg->lobby().owner() != settings->get_local_steam_id().ConvertToUint64() && msg->lobby().appid() == settings->get_local_game_id().AppID()) {
Lobby *lobby = get_lobby((uint64)msg->lobby().room_id());
if (!lobby) {
@ -1588,7 +1588,7 @@ void Callback(Common_Message *msg)
if (msg->has_lobby_messages()) {
PRINT_DEBUG("LOBBY MESSAGE %u %llu\n", msg->lobby_messages().type(), msg->lobby_messages().id());
PRINT_DEBUG("LOBBY MESSAGE %u " "%" PRIu64 "\n", msg->lobby_messages().type(), msg->lobby_messages().id());
Lobby *lobby = get_lobby((uint64)msg->lobby_messages().id());
if (lobby && !lobby->deleted()) {
bool we_are_in_lobby = !!get_lobby_member(lobby, settings->get_local_steam_id());
@ -1620,7 +1620,7 @@ void Callback(Common_Message *msg)
}
if (msg->lobby_messages().type() == Lobby_Messages::LEAVE) {
PRINT_DEBUG("LOBBY MESSAGE: LEAVE %llu\n", msg->source_id());
PRINT_DEBUG("LOBBY MESSAGE: LEAVE " "%" PRIu64 "\n", msg->source_id());
leave_lobby(lobby, (uint64)msg->source_id());
if (we_are_in_lobby) trigger_lobby_member_join_leave((uint64)lobby->room_id(), (uint64)msg->source_id(), true, true, 0.2);
}

View File

@ -48,7 +48,7 @@ HServerListRequest Steam_Matchmaking_Servers::RequestServerList(AppId_t iApp, IS
request.type = type;
requests.push_back(request);
++server_list_request;
requests[requests.size() - 1].id = (void *)server_list_request;
requests[requests.size() - 1].id = (char *)0 + server_list_request; // (char *)0 silences the compiler warning
HServerListRequest id = requests[requests.size() - 1].id;
PRINT_DEBUG("request id: %p\n", id);
@ -420,7 +420,7 @@ void Steam_Matchmaking_Servers::server_details(Gameserver *g, gameserveritem_t *
server->m_nServerVersion = g->version();
server->SetName(g->server_name().c_str());
server->m_steamID = CSteamID((uint64)g->id());
PRINT_DEBUG("server_details %llu\n", g->id());
PRINT_DEBUG("server_details " "%" PRIu64 "\n", g->id());
strncpy(server->m_szGameTags, g->tags().c_str(), k_cbMaxGameServerTags - 1);
server->m_szGameTags[k_cbMaxGameServerTags - 1] = 0;
@ -457,7 +457,7 @@ void Steam_Matchmaking_Servers::server_details_players(Gameserver *g, Steam_Matc
if (ssq != NULL) ssq_server_free(ssq);
}
PRINT_DEBUG("server_details_players %llu\n", g->id());
PRINT_DEBUG("server_details_players " "%" PRIu64 "\n", g->id());
}
void Steam_Matchmaking_Servers::server_details_rules(Gameserver *g, Steam_Matchmaking_Servers_Direct_IP_Request *r)
@ -491,7 +491,7 @@ void Steam_Matchmaking_Servers::server_details_rules(Gameserver *g, Steam_Matchm
if (ssq != NULL) ssq_server_free(ssq);
}
PRINT_DEBUG("server_details_rules %llu\n", g->id());
PRINT_DEBUG("server_details_rules " "%" PRIu64 "\n", g->id());
}
// Get details on a given server in the list, you can get the valid range of index
@ -746,9 +746,9 @@ void Steam_Matchmaking_Servers::RunCallbacks()
}
for (auto &r : direct_ip_requests_temp) {
PRINT_DEBUG("dip request: %lu:%hu\n", r.ip, r.port);
PRINT_DEBUG("dip request: %u:%hu\n", r.ip, r.port);
for (auto &g : gameservers) {
PRINT_DEBUG("server: %lu:%hu\n", g.server.ip(), g.server.query_port());
PRINT_DEBUG("server: %u:%u\n", g.server.ip(), g.server.query_port());
uint16 query_port = g.server.query_port();
if (query_port == 0xFFFF) {
query_port = g.server.port();
@ -785,7 +785,7 @@ void Steam_Matchmaking_Servers::RunCallbacks()
void Steam_Matchmaking_Servers::Callback(Common_Message *msg)
{
if (msg->has_gameserver() && msg->gameserver().type() != eFriendsServer) {
PRINT_DEBUG("got SERVER %llu, offline:%u\n", msg->gameserver().id(), msg->gameserver().offline());
PRINT_DEBUG("got SERVER " "%" PRIu64 ", offline:%u\n", msg->gameserver().id(), msg->gameserver().offline());
if (msg->gameserver().offline()) {
for (auto &g : gameservers) {
if (g.server.id() == msg->gameserver().id()) {

View File

@ -317,7 +317,7 @@ bool IsP2PPacketAvailable( uint32 *pcubMsgSize, int nChannel)
if (connection_exists((uint64)msg.source_id()) && msg.mutable_network()->channel() == nChannel && msg.network().processed()) {
uint32 size = msg.mutable_network()->data().size();
if (pcubMsgSize) *pcubMsgSize = size;
PRINT_DEBUG("available with size: %lu\n", size);
PRINT_DEBUG("available with size: %u\n", size);
return true;
}
}
@ -362,7 +362,7 @@ bool ReadP2PPacket( void *pubDest, uint32 cubDest, uint32 *pcubMsgSize, CSteamID
}PRINT_DEBUG("\n");
#endif
*psteamIDRemote = CSteamID((uint64)msg->source_id());
PRINT_DEBUG("Steam_Networking::ReadP2PPacket len %u channel: %u from: %llu\n", msg_size, nChannel, msg->source_id());
PRINT_DEBUG("Steam_Networking::ReadP2PPacket len %u channel: %u from: " "%" PRIu64 "\n", msg_size, nChannel, msg->source_id());
msg = messages.erase(msg);
return true;
}
@ -907,7 +907,7 @@ void Callback(Common_Message *msg)
{
if (msg->has_network()) {
#ifndef EMU_RELEASE_BUILD
PRINT_DEBUG("Steam_Networking: got msg from: %llu to: %llu size %zu type %u | messages %p: %zu\n", msg->source_id(), msg->dest_id(), msg->network().data().size(), msg->network().type(), &messages, messages.size());
PRINT_DEBUG("Steam_Networking: got msg from: " "%" PRIu64 " to: " "%" PRIu64 " size %zu type %u | messages %p: %zu\n", msg->source_id(), msg->dest_id(), msg->network().data().size(), msg->network().type(), &messages, messages.size());
for (int i = 0; i < msg->network().data().size(); ++i) {
PRINT_DEBUG("%02hhX", msg->network().data().data()[i]);
}PRINT_DEBUG("\n");

View File

@ -881,7 +881,7 @@ SteamNetworkingMessage_t *get_steam_message_connection(HSteamNetConnection hConn
pMsg->m_pfnRelease = &delete_steam_message;
pMsg->m_nChannel = 0;
connect_socket->second.data.pop();
PRINT_DEBUG("get_steam_message_connection %u %lu, %I64\n", hConn, size, pMsg->m_nMessageNumber);
PRINT_DEBUG("get_steam_message_connection %u %lu, %llu\n", hConn, size, pMsg->m_nMessageNumber);
return pMsg;
}
@ -2054,7 +2054,7 @@ void Callback(Common_Message *msg)
}
if (msg->has_networking_sockets()) {
PRINT_DEBUG("Steam_Networking_Sockets: got network socket msg %u %llu\n", msg->networking_sockets().type(), msg->source_id());
PRINT_DEBUG("Steam_Networking_Sockets: got network socket msg %u " "%" PRIu64 "\n", msg->networking_sockets().type(), msg->source_id());
if (msg->networking_sockets().type() == Networking_Sockets::CONNECTION_REQUEST) {
int virtual_port = msg->networking_sockets().virtual_port();
int real_port = msg->networking_sockets().real_port();
@ -2093,13 +2093,13 @@ void Callback(Common_Message *msg)
auto connect_socket = s->connect_sockets.find(msg->networking_sockets().connection_id());
if (connect_socket != s->connect_sockets.end()) {
if (connect_socket->second.remote_identity.GetSteamID64() == msg->source_id() && (connect_socket->second.status == CONNECT_SOCKET_CONNECTED)) {
PRINT_DEBUG("Steam_Networking_Sockets: got data len %zu, num %I64u on connection %u\n", msg->networking_sockets().data().size(), msg->networking_sockets().message_number(), connect_socket->first);
PRINT_DEBUG("Steam_Networking_Sockets: got data len %zu, num " "%" PRIu64 " on connection %u\n", msg->networking_sockets().data().size(), msg->networking_sockets().message_number(), connect_socket->first);
connect_socket->second.data.push(msg->networking_sockets());
}
} else {
connect_socket = std::find_if(s->connect_sockets.begin(), s->connect_sockets.end(), [msg](const auto &in) {return in.second.remote_identity.GetSteamID64() == msg->source_id() && (in.second.status == CONNECT_SOCKET_NOT_ACCEPTED || in.second.status == CONNECT_SOCKET_CONNECTED) && in.second.remote_id == msg->networking_sockets().connection_id_from();});
if (connect_socket != s->connect_sockets.end()) {
PRINT_DEBUG("Steam_Networking_Sockets: got data len %zu, num %I64u on not accepted connection %u\n", msg->networking_sockets().data().size(), msg->networking_sockets().message_number(), connect_socket->first);
PRINT_DEBUG("Steam_Networking_Sockets: got data len %zu, num " "%" PRIu64 " on not accepted connection %u\n", msg->networking_sockets().data().size(), msg->networking_sockets().message_number(), connect_socket->first);
connect_socket->second.data.push(msg->networking_sockets());
}
}

View File

@ -358,7 +358,7 @@ bool SetConnectionConfigValueString( HSteamNetConnection hConn, ESteamNetworking
bool SetConfigValue( ESteamNetworkingConfigValue eValue, ESteamNetworkingConfigScope eScopeType, intptr_t scopeObj,
ESteamNetworkingConfigDataType eDataType, const void *pArg )
{
PRINT_DEBUG("Steam_Networking_Utils::SetConfigValue %i %i %tf %i %p\n", eValue, eScopeType, scopeObj, eDataType, pArg);
PRINT_DEBUG("Steam_Networking_Utils::SetConfigValue %i %i " "%" PRIdPTR " %i %p\n", eValue, eScopeType, scopeObj, eDataType, pArg);
return true;
}

View File

@ -72,7 +72,7 @@ uint32 GetServerRealTime()
{
PRINT_DEBUG("GetServerRealTime\n");
uint32 server_time = std::chrono::duration_cast<std::chrono::duration<uint32>>(std::chrono::system_clock::now().time_since_epoch()).count();
PRINT_DEBUG("Time %lu\n", server_time);
PRINT_DEBUG("Time %u\n", server_time);
return server_time;
}