Fix errrors in network.

(linux and windows C++ things arent the same [I HATE BOTH OF YOU WHY NOT STANDARDIZE!])
revert "&" checks on type instead of "=="
This commit is contained in:
Detanup01 2024-05-27 14:33:45 +02:00 committed by otavepto
parent 7c5b4e5325
commit e4f488bbdc
10 changed files with 43 additions and 35 deletions

View File

@ -109,8 +109,7 @@ static void log_exception(LPEXCEPTION_POINTERS ex_pointers)
auto now = std::chrono::system_clock::now();
auto t_now = std::chrono::system_clock::to_time_t(now);
auto gm_time = std::gmtime(&t_now);
auto asc_time = std::asctime(gm_time);
auto time = std::string(asc_time);
auto time = std::string(asc_time ? asc_time : "");
time.pop_back(); // remove the trailing '\n' added by asctime
common_helpers::write(file, "[" + time + "]");
{

View File

@ -870,11 +870,11 @@ bool Auth_Manager::endAuth(CSteamID id)
void Auth_Manager::Callback(Common_Message *msg)
{
if (msg->has_low_level()) {
if (msg->low_level().type() & Low_Level::CONNECT) {
if (msg->low_level().type() == Low_Level::CONNECT) {
}
if (msg->low_level().type() & Low_Level::DISCONNECT) {
if (msg->low_level().type() == Low_Level::DISCONNECT) {
PRINT_DEBUG("TICKET DISCONNECT");
auto t = std::begin(inbound);
while (t != std::end(inbound)) {
@ -889,7 +889,7 @@ void Auth_Manager::Callback(Common_Message *msg)
}
if (msg->has_auth_ticket()) {
if (msg->auth_ticket().type() & Auth_Ticket::CANCEL) {
if (msg->auth_ticket().type() == Auth_Ticket::CANCEL) {
PRINT_DEBUG("TICKET CANCEL " "%" PRIu64, msg->source_id());
uint32 number = msg->auth_ticket().number();
auto t = std::begin(inbound);

View File

@ -291,11 +291,16 @@ static int send_packet_to(sock_t sock, IP_PORT ip_port, char *data, unsigned lon
size_t addrsize = 0;
struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr;
addrsize = sizeof(struct sockaddr_in);
#if defined(STEAM_WIN32)
int addrsize = sizeof(struct sockaddr_in);
#else
socklen_t addrsize = sizeof(struct sockaddr_in);
#endif
addr4->sin_family = AF_INET;
addr4->sin_addr.s_addr = ip_port.ip;
addr4->sin_port = ip_port.port;
return sendto(sock, data, length, 0, (struct sockaddr *)&addr, static_cast<int>(addrsize));
return sendto(sock, data, length, 0, (struct sockaddr *)&addr, addrsize);
}
static int receive_packet(sock_t sock, IP_PORT *ip_port, char *data, unsigned long max_length)
@ -375,12 +380,16 @@ static bool bind_socket(sock_t sock, uint16 port)
size_t addrsize;
struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr;
addrsize = sizeof(struct sockaddr_in);
#if defined(STEAM_WIN32)
int addrsize = sizeof(struct sockaddr_in);
#else
socklen_t addrsize = sizeof(struct sockaddr_in);
#endif
addr4->sin_family = AF_INET;
addr4->sin_port = htons(port);
addr4->sin_addr.s_addr = 0;
return !bind(sock, (struct sockaddr *)&addr, static_cast<int>(addrsize));
return !bind(sock, (struct sockaddr *)&addr, addrsize);
}
static bool socket_reuseaddr(sock_t sock)
@ -470,7 +479,7 @@ static bool unbuffer_tcp(struct TCP_Socket &socket, Common_Message *msg)
static bool recv_tcp(struct TCP_Socket &socket)
{
if (is_socket_valid(socket.sock)) {
unsigned int size = receive_buffer_amount(socket.sock), old_size = static_cast<uint32>(socket.send_buffer.size());
unsigned int size = receive_buffer_amount(socket.sock), old_size = static_cast<uint32>(socket.recv_buffer.size());
int len;
socket.recv_buffer.resize(old_size + size);
if (size > 0) {
@ -707,7 +716,7 @@ bool Networking::handle_announce(Common_Message *msg, IP_PORT ip_port)
conn->last_received = std::chrono::high_resolution_clock::now();
if (msg->announce().type() & Announce::PING) {
if (msg->announce().type() == Announce::PING) {
Common_Message msg = create_announce(false);
size_t size = msg.ByteSizeLong();
char *buffer = new char[size];
@ -724,7 +733,7 @@ bool Networking::handle_announce(Common_Message *msg, IP_PORT ip_port)
send_packet_to(udp_socket, ip_port, buffer, static_cast<unsigned long>(size));
delete[] buffer;
}
} else if (msg->announce().type() & Announce::PONG) {
} else if (msg->announce().type() == Announce::PONG) {
conn->udp_ip_port = ip_port;
conn->udp_pinged = true;
}

View File

@ -877,7 +877,7 @@ void Steam_Controller::TriggerVibration( ControllerHandle_t controllerHandle, un
rumble_length_ms = 100;
#endif
unsigned gamepad_device = (static_cast<unsigned int>(controllerHandle) - 1);
unsigned gamepad_device = static_cast<unsigned int>(controllerHandle - 1);
if (gamepad_device > GAMEPAD_COUNT) return;
rumble_thread_data->rumble_mutex.lock();
rumble_thread_data->data[gamepad_device].new_data = true;

View File

@ -1199,7 +1199,7 @@ void Steam_Friends::RunCallbacks()
void Steam_Friends::Callback(Common_Message *msg)
{
if (msg->has_low_level()) {
if (msg->low_level().type() & Low_Level::DISCONNECT) {
if (msg->low_level().type() == Low_Level::DISCONNECT) {
PRINT_DEBUG("Disconnect");
uint64 id = msg->source_id();
auto f = std::find_if(friends.begin(), friends.end(), [&id](Friend const& item) { return item.id() == id; });
@ -1210,7 +1210,7 @@ void Steam_Friends::Callback(Common_Message *msg)
}
}
if (msg->low_level().type() & Low_Level::CONNECT) {
if (msg->low_level().type() == Low_Level::CONNECT) {
PRINT_DEBUG("Connect %llu", (uint64)msg->source_id());
Common_Message msg_;
msg_.set_source_id(settings->get_local_steam_id().ConvertToUint64());
@ -1254,7 +1254,7 @@ void Steam_Friends::Callback(Common_Message *msg)
}
if (msg->has_friend_messages()) {
if (msg->friend_messages().type() & Friend_Messages::LOBBY_INVITE) {
if (msg->friend_messages().type() == Friend_Messages::LOBBY_INVITE) {
PRINT_DEBUG("Got Lobby Invite");
Friend *f = find_friend((uint64)msg->source_id());
if (f) {
@ -1280,7 +1280,7 @@ void Steam_Friends::Callback(Common_Message *msg)
}
}
if (msg->friend_messages().type() & Friend_Messages::GAME_INVITE) {
if (msg->friend_messages().type() == Friend_Messages::GAME_INVITE) {
PRINT_DEBUG("Got Game Invite");
//TODO: I'm pretty sure that the user should accept the invite before this is posted but we do like above
if (overlay->Ready() && !settings->hasOverlayAutoAcceptInviteFromFriend(msg->source_id()))

View File

@ -641,7 +641,7 @@ void Steam_Matchmaking_Servers::server_details(Gameserver *g, gameserveritem_t *
g->set_num_players(ssq_a2s_info->players);
g->set_version(static_cast<uint32_t>(std::stoull(ssq_a2s_info->version, NULL, 0)));
if (ssq_info_has_port(ssq_a2s_info)) g->set_port(ssq_a2s_info->port);
if (ssq_info_has_gameid(ssq_a2s_info)) g->set_appid(static_cast<uint32_t>(ssq_a2s_info->gameid));
if (ssq_info_has_gameid(ssq_a2s_info)) g->set_appid(ssq_a2s_info->gameid);
else g->set_appid(ssq_a2s_info->id);
g->set_offline(false);
} else {

View File

@ -858,11 +858,11 @@ void Steam_Networking::Callback(Common_Message *msg)
PRINT_DEBUG("msg data: '%s'",
common_helpers::uint8_vector_to_hex_string(std::vector<uint8_t>(msg->network().data().begin(), msg->network().data().end())).c_str());
if (msg->network().type() & Network_pb::DATA) {
if (msg->network().type() == Network_pb::DATA) {
unprocessed_messages.push_back(Common_Message(*msg));
}
if (msg->network().type() & Network_pb::NEW_CONNECTION) {
if (msg->network().type() == Network_pb::NEW_CONNECTION) {
std::lock_guard<std::recursive_mutex> lock(messages_mutex);
auto msg_temp = std::begin(messages);
while (msg_temp != std::end(messages)) {
@ -878,7 +878,7 @@ void Steam_Networking::Callback(Common_Message *msg)
if (msg->has_network_old()) {
PRINT_DEBUG("got network socket msg %u", msg->network_old().type());
if (msg->network_old().type() & Network_Old::CONNECTION_REQUEST_IP) {
if (msg->network_old().type() == Network_Old::CONNECTION_REQUEST_IP) {
for (auto & listen : listen_sockets) {
if (listen.nPort == msg->network_old().port()) {
SNetSocket_t new_sock = create_connection_socket((uint64)msg->source_id(), 0, 0, msg->network_old().port(), listen.id, SOCKET_CONNECTED, static_cast<SNetSocket_t>(msg->network_old().connection_id_from()));
@ -892,7 +892,7 @@ void Steam_Networking::Callback(Common_Message *msg)
}
}
}
} else if (msg->network_old().type() & Network_Old::CONNECTION_REQUEST_STEAMID) {
} else if (msg->network_old().type() == Network_Old::CONNECTION_REQUEST_STEAMID) {
for (auto & listen : listen_sockets) {
if (listen.nVirtualP2PPort == msg->network_old().port()) {
SNetSocket_t new_sock = create_connection_socket((uint64)msg->source_id(), msg->network_old().port(), 0, 0, listen.id, SOCKET_CONNECTED, static_cast<SNetSocket_t>(msg->network_old().connection_id_from()));
@ -907,7 +907,7 @@ void Steam_Networking::Callback(Common_Message *msg)
}
}
} else if (msg->network_old().type() & Network_Old::CONNECTION_ACCEPTED) {
} else if (msg->network_old().type() == Network_Old::CONNECTION_ACCEPTED) {
struct steam_connection_socket *socket = get_connection_socket(static_cast<SNetSocket_t>(msg->network_old().connection_id()));
if (socket && socket->nPort && socket->status == SOCKET_CONNECTING && !socket->target.IsValid()) {
socket->target = (uint64)msg->source_id();
@ -923,7 +923,7 @@ void Steam_Networking::Callback(Common_Message *msg)
data.m_eSNetSocketState = k_ESNetSocketStateConnected; //TODO is this the right state?
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
}
} else if (msg->network_old().type() & Network_Old::CONNECTION_END) {
} else if (msg->network_old().type() == Network_Old::CONNECTION_END) {
struct steam_connection_socket *socket = get_connection_socket(static_cast<SNetSocket_t>(msg->network_old().connection_id()));
if (socket && socket->status == SOCKET_CONNECTED && msg->source_id() == socket->target.ConvertToUint64()) {
struct SocketStatusCallback_t data;
@ -943,7 +943,7 @@ void Steam_Networking::Callback(Common_Message *msg)
}
if (msg->has_low_level()) {
if (msg->low_level().type() & Low_Level::DISCONNECT) {
if (msg->low_level().type() == Low_Level::DISCONNECT) {
CSteamID source_id((uint64)msg->source_id());
if (connection_exists(source_id)) {
P2PSessionConnectFail_t data;
@ -965,7 +965,7 @@ void Steam_Networking::Callback(Common_Message *msg)
}
} else
if (msg->low_level().type() & Low_Level::CONNECT) {
if (msg->low_level().type() == Low_Level::CONNECT) {
}
}

View File

@ -382,18 +382,18 @@ void Steam_Networking_Messages::RunCallbacks()
void Steam_Networking_Messages::Callback(Common_Message *msg)
{
if (msg->has_low_level()) {
if (msg->low_level().type() & Low_Level::CONNECT) {
if (msg->low_level().type() == Low_Level::CONNECT) {
}
if (msg->low_level().type() & Low_Level::DISCONNECT) {
if (msg->low_level().type() == Low_Level::DISCONNECT) {
end_connection((uint64)msg->source_id());
}
}
if (msg->has_networking_messages()) {
PRINT_DEBUG("got network socket msg %u", msg->networking_messages().type());
if (msg->networking_messages().type() & Networking_Messages::CONNECTION_NEW) {
if (msg->networking_messages().type() == Networking_Messages::CONNECTION_NEW) {
SteamNetworkingIdentity identity;
identity.SetSteamID64(msg->source_id());
auto conn = find_or_create_message_connection(identity, true, false);
@ -401,18 +401,18 @@ void Steam_Networking_Messages::Callback(Common_Message *msg)
conn->second.dead = false;
}
if (msg->networking_messages().type() & Networking_Messages::CONNECTION_ACCEPT) {
if (msg->networking_messages().type() == Networking_Messages::CONNECTION_ACCEPT) {
auto conn = connections.find((uint64)msg->source_id());
if (conn != connections.end()) {
conn->second.remote_id = msg->networking_messages().id_from();
}
}
if (msg->networking_messages().type() & Networking_Messages::CONNECTION_END) {
if (msg->networking_messages().type() == Networking_Messages::CONNECTION_END) {
end_connection((uint64)msg->source_id());
}
if (msg->networking_messages().type() & Networking_Messages::DATA) {
if (msg->networking_messages().type() == Networking_Messages::DATA) {
incoming_data.push_back(Common_Message(*msg));
}
}

View File

@ -939,7 +939,7 @@ EResult Steam_Networking_Sockets::GetConnectionRealTimeStatus( HSteamNetConnecti
pStatus->m_flInPacketsPerSec = 0.0;
pStatus->m_flInBytesPerSec = 0.0;
pStatus->m_cbSentUnackedReliable = 0;
pStatus->m_usecQueueTime = static_cast<SteamNetworkingMicroseconds>(0.0f);
pStatus->m_usecQueueTime = 0;
//Note some games (volcanoids) might not allocate a struct the whole size of SteamNetworkingQuickConnectionStatus
//keep this in mind in future interface updates

View File

@ -715,11 +715,11 @@ void Steam_Networking_Utils::RunCallbacks()
void Steam_Networking_Utils::Callback(Common_Message *msg)
{
if (msg->has_low_level()) {
if (msg->low_level().type() & Low_Level::CONNECT) {
if (msg->low_level().type() == Low_Level::CONNECT) {
}
if (msg->low_level().type() & Low_Level::DISCONNECT) {
if (msg->low_level().type() == Low_Level::DISCONNECT) {
}
}