Skip to content

Commit

Permalink
initial network session refactor
Browse files Browse the repository at this point in the history
* game life cycle updates
* fix shell flag, fix map load status reporting regression
  • Loading branch information
nukeulater authored Dec 24, 2024
1 parent 543b988 commit 412617c
Show file tree
Hide file tree
Showing 29 changed files with 596 additions and 516 deletions.
23 changes: 13 additions & 10 deletions xlive/Blam/Engine/cartographer/discord/discord_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "cseries/cseries_strings.h"
#include "main/main_game.h"
#include "game/game.h"
#include "networking/Session/NetworkSession.h"
#include "networking/logic/life_cycle_manager.h"

/* constants */

Expand Down Expand Up @@ -232,11 +232,11 @@ void discord_interface_zero_player_count(void)

void discord_interface_set_player_counts(void)
{
c_network_session* session = nullptr;
if (NetworkSession::GetActiveNetworkSession(&session))
c_network_session* session = NULL;
if (network_life_cycle_in_squad_session(&session))
{
g_discord_globals.activity.party.size.current_size = session->membership[0].player_count;
g_discord_globals.activity.party.size.max_size = session->parameters[0].max_party_players;
g_discord_globals.activity.party.size.current_size = session->m_session_membership.player_count;
g_discord_globals.activity.party.size.max_size = session->m_session_parameters.max_party_players;
}
else
{
Expand Down Expand Up @@ -325,17 +325,20 @@ void discord_rich_presence_update(s_discord_data* discord)
g_discord_globals.activity.application_id = k_discord_client_id;
g_discord_globals.activity.supported_platforms = DiscordActivitySupportedPlatformFlags_Desktop;

c_network_session* network_session = NetworkSession::GetActiveNetworkSession();
if (network_session && (network_session->session_host_peer_index != NONE && network_session->local_session_state != _network_session_state_peer_leaving))
c_network_session* network_session = NULL;
if (network_life_cycle_in_squad_session(&network_session)
&& (network_session->m_session_host_peer_index != NONE
&& network_session->m_local_state != _network_session_state_peer_leaving))
{
bool not_session_host = !NetworkSession::LocalPeerIsSessionHost();
bool session_host = network_session->is_host();

XSESSION_INFO session;
const int32 observer_index = NetworkSession::GetPeerObserverChannel(network_session->session_host_peer_index)->observer_index;
const int32 observer_index = network_session->get_session_peer(network_session->m_session_host_peer_index)->observer_channel_index;

session.sessionID = network_session->session_id;
session.keyExchangeKey = network_session->xnkey;
session.hostAddress = (not_session_host ? network_session->p_network_observer->observer_channels[observer_index].xnaddr : network_session->virtual_couch[0].xsession_info.hostAddress);
session.hostAddress =
(session_host ? network_session->m_session_virtual_couch.xsession_info.hostAddress : network_session->m_network_observer->m_observer_channels[observer_index].xnaddr);

XUID host;
XUserGetXUID(0, &host);
Expand Down
10 changes: 5 additions & 5 deletions xlive/Blam/Engine/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void game_time_get_date_and_time(s_date_and_time* date_and_time)

void game_direct_connect_to_session(XNKID kid, XNKEY key, const XNADDR* addr, int8 exe_type, int32 exe_version, int32 comp_version)
{
auto handler = (c_game_life_cycle_handler_joining*)c_game_life_cycle_manager::get()->life_cycle_handlers[e_game_life_cycle::_life_cycle_joining];
auto handler = (c_game_life_cycle_handler_joining*)c_game_life_cycle_manager::get()->m_life_cycle_handlers[_life_cycle_joining];
handler->joining_xnkid = kid;
handler->joining_xnkey = key;
handler->joining_xnaddr = *addr;
Expand All @@ -161,7 +161,7 @@ void game_direct_connect_to_session(XNKID kid, XNKEY key, const XNADDR* addr, in
wchar_t local_usernames[k_number_of_users][XUSER_NAME_SIZE] = {};
s_player_identifier local_identifiers[k_number_of_users];
int valid_local_player_count = 0;
for (auto i = 0; i < 4; i++)
for (int32 i = 0; i < k_number_of_users; i++)
{
s_player_identifier temp_identifier;
s_player_properties temp_properties;
Expand All @@ -173,7 +173,7 @@ void game_direct_connect_to_session(XNKID kid, XNKEY key, const XNADDR* addr, in
}
}
user_interface_networking_reset_player_counts();
network_session_init_session(2, 1);
network_globals_switch_environment(2, 1);
csmemset(&handler->player_identifiers, 0, sizeof(handler->player_identifiers));
csmemcpy(&handler->player_identifiers, local_identifiers, sizeof(s_player_identifier) * valid_local_player_count);
csmemcpy(&handler->player_names, local_usernames, sizeof(wchar_t) * 16 * valid_local_player_count);
Expand Down Expand Up @@ -202,7 +202,7 @@ void __cdecl game_initialize(void)
real_math_reset_precision();

s_game_systems* g_game_systems = get_game_systems();
for (size_t i = 0; i < 70; ++i)
for (int32 i = 0; i < 70; ++i)
{
g_game_systems[i].initialize_proc();
}
Expand Down Expand Up @@ -306,7 +306,7 @@ void __cdecl game_initialize_for_new_map(s_game_options* options)
game_info_initialize_for_new_map(options);

s_game_systems* g_game_systems = get_game_systems();
for (uint32 i = 0; i < 70; i++)
for (int32 i = 0; i < 70; i++)
{
if (g_game_systems[i].reset_proc)
{
Expand Down
2 changes: 1 addition & 1 deletion xlive/Blam/Engine/game/game_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ struct s_simulation_player_netdebug_data
int16 client_rtt_msec;
int16 client_packet_rate;
int16 client_throughput;
int16 client_packet_loss;
int16 client_packet_loss_percentage;
};
ASSERT_STRUCT_SIZE(s_simulation_player_netdebug_data, 16);

Expand Down
2 changes: 1 addition & 1 deletion xlive/Blam/Engine/game/game_options.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "networking/Session/NetworkSession.h"
#include "networking/logic/life_cycle_manager.h"
#include "saved_games/game_variant.h"
#include "simulation/machine_id.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "interface/user_interface_globals.h"
#include "main/levels.h"
#include "main/level_definitions.h"
#include "networking/Session/NetworkSession.h"
#include "networking/logic/life_cycle_manager.h"
#include "saved_games/game_variant.h"
#include "tag_files/global_string_ids.h"
#include "tag_files/tag_loader/tag_injection.h"
Expand Down
70 changes: 38 additions & 32 deletions xlive/Blam/Engine/networking/NetworkMessageTypeCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ void __stdcall handle_channel_message_hook(void* thisx, int network_channel_inde
LOG_TRACE_NETWORK(" - network address: {:x}", ntohl(addr.address.ipv4));

int32 peer_index = NetworkSession::GetPeerIndexFromNetworkAddress(&addr);
c_network_session* session = NetworkSession::GetActiveNetworkSession();
if (peer_index != NONE && !NetworkSession::IsPeerIndexLocal(peer_index))
c_network_session* session = NULL;
network_life_cycle_in_squad_session(&session);
if (peer_index != NONE && !session->is_peer_local(peer_index))
{
s_custom_map_filename data;
ZeroMemory(&data, sizeof(s_custom_map_filename));
Expand All @@ -163,10 +164,11 @@ void __stdcall handle_channel_message_hook(void* thisx, int network_channel_inde
received_data->player_id,
peer_index, map_filename.c_str(), received_data->map_download_id);

c_network_observer* observer = session->p_network_observer;
s_session_observer_channel* observer_channel = NetworkSession::GetPeerObserverChannel(peer_index);
c_network_observer* observer = session->m_network_observer;
s_session_peer* peer = session->get_session_peer(peer_index);

observer->send_message(session->session_index, observer_channel->observer_index, false, _custom_map_filename, sizeof(s_custom_map_filename), &data);
if (peer->is_remote_peer)
observer->send_message(session->m_session_index, peer->observer_channel_index, false, _custom_map_filename, sizeof(s_custom_map_filename), &data);
}
else
{
Expand Down Expand Up @@ -290,63 +292,67 @@ void __stdcall handle_channel_message_hook(void* thisx, int network_channel_inde

void NetworkMessage::SendRequestMapFilename(int mapDownloadId)
{
c_network_session* session = NetworkSession::GetActiveNetworkSession();
c_network_session* session = NULL;
network_life_cycle_in_squad_session(&session);

if (session->local_session_state == _network_session_state_peer_established)
if (session->established()
&& !session->is_host())
{
s_request_map_filename data;
XUserGetXUID(0, &data.player_id);
data.map_download_id = mapDownloadId;

c_network_observer* observer = session->p_network_observer;
s_session_observer_channel* observer_channel = NetworkSession::GetPeerObserverChannel(session->session_host_peer_index);
c_network_observer* observer = session->m_network_observer;
s_session_peer* peer = session->get_session_peer(session->m_session_host_peer_index);

if (observer_channel->field_1) {
observer->send_message(session->session_index, observer_channel->observer_index, false, _request_map_filename, sizeof(s_request_map_filename), &data);
if (peer->is_remote_peer) {
observer->send_message(session->m_session_index, peer->observer_channel_index, false, _request_map_filename, sizeof(s_request_map_filename), &data);

LOG_TRACE_NETWORK("{} session host peer index: {}, observer index {}, observer bool unk: {}, session index: {}",
LOG_TRACE_NETWORK("{} session host peer index: {}, observer index {}, observer is remote peer: {}, session index: {}",
__FUNCTION__,
session->session_host_peer_index,
observer_channel->observer_index,
observer_channel->field_1,
session->session_index);
session->m_session_host_peer_index,
peer->observer_channel_index,
peer->is_remote_peer,
session->m_session_index);
}
}
}

void NetworkMessage::SendRankChange(int peerIdx, BYTE rank)
void NetworkMessage::SendRankChange(int peer_index, BYTE rank)
{
c_network_session* session = NetworkSession::GetActiveNetworkSession();
if (NetworkSession::LocalPeerIsSessionHost())
c_network_session* session = NULL;
network_life_cycle_in_squad_session(&session);
if (session->is_host())
{
s_rank_change data;
data.rank = rank;

c_network_observer* observer = session->p_network_observer;
s_session_observer_channel* observer_channel = NetworkSession::GetPeerObserverChannel(peerIdx);
c_network_observer* observer = session->m_network_observer;
s_session_peer* peer = session->get_session_peer(peer_index);

if (peerIdx != NONE && !NetworkSession::IsPeerIndexLocal(peerIdx))
if (peer_index != NONE && !session->is_peer_local(peer_index))
{
if (observer_channel->field_1) {
observer->send_message(session->session_index, observer_channel->observer_index, false, _rank_change, sizeof(s_rank_change), &data);
if (peer->is_remote_peer) {
observer->send_message(session->m_session_index, peer->observer_channel_index, false, _rank_change, sizeof(s_rank_change), &data);
}
}
}
}
void NetworkMessage::SendAntiCheat(int peerIdx)
void NetworkMessage::SendAntiCheat(int peer_index)
{
c_network_session* session = NetworkSession::GetActiveNetworkSession();
c_network_session* session = NULL;
network_life_cycle_in_squad_session(&session);

if (NetworkSession::LocalPeerIsSessionHost())
if (session->is_host())
{
c_network_observer* observer = session->p_network_observer;
s_session_observer_channel* observer_channel = NetworkSession::GetPeerObserverChannel(peerIdx);
c_network_observer* observer = session->m_network_observer;
s_session_peer* peer = session->get_session_peer(peer_index);

s_anti_cheat data;
data.enabled = g_twizzler_status;
if (peerIdx != NONE && !NetworkSession::IsPeerIndexLocal(peerIdx)) {
if (observer_channel->field_1) {
observer->send_message(session->session_index, observer_channel->observer_index, false, _anti_cheat, sizeof(s_anti_cheat), &data);
if (peer_index != NONE && !session->is_peer_local(peer_index)) {
if (peer->is_remote_peer) {
observer->send_message(session->m_session_index, peer->observer_channel_index, false, _anti_cheat, sizeof(s_anti_cheat), &data);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions xlive/Blam/Engine/networking/NetworkMessageTypeCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,6 @@ namespace NetworkMessage
{
void ApplyGamePatches();
void SendRequestMapFilename(int mapDownloadId);
void SendRankChange(int peerIdx, BYTE rank);
void SendAntiCheat(int peerIdx);
void SendRankChange(int peer_index, BYTE rank);
void SendAntiCheat(int peer_index);
}
Loading

0 comments on commit 412617c

Please sign in to comment.