From 71aba6c4108d99f39379f54b04bb71a6d2dc09b5 Mon Sep 17 00:00:00 2001 From: hgn Date: Sat, 30 Sep 2023 08:16:59 +0100 Subject: [PATCH] test network 4 --- gameserver.c | 2 +- network.c | 19 ++++++++++++------- player_remote.c | 34 ++++++++++++++++++++++------------ 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/gameserver.c b/gameserver.c index e2082cb..818b22d 100644 --- a/gameserver.c +++ b/gameserver.c @@ -77,7 +77,7 @@ static void gameserver_player_join( int index ){ SteamAPI_ISteamNetworkingSockets_SendMessageToConnection( hSteamNetworkingSockets, joiner->connection, - &join, sizeof(join), k_nSteamNetworkingSend_Reliable, NULL ); + &init, sizeof(init), k_nSteamNetworkingSend_Reliable, NULL ); } } diff --git a/network.c b/network.c index 4042ef4..a35ead4 100644 --- a/network.c +++ b/network.c @@ -157,6 +157,16 @@ static void network_send_username(void){ k_nSteamNetworkingSend_Reliable, NULL ); } +static void network_disconnect(void){ + SteamAPI_ISteamNetworkingSockets_CloseConnection( + hSteamNetworkingSockets, network_client.remote, 0, NULL, 0 ); + network_client.remote = 0; + + for( int i=0; im_pubParam; vg_info( " Connection status changed for %lu\n", info->m_hConn ); @@ -193,16 +203,11 @@ static void on_server_connect_status( CallbackMsg_t *msg ){ k_ESteamNetConnectionEnd_Remote_Max ){ network_client.retries = 40; } - - SteamAPI_ISteamNetworkingSockets_CloseConnection( - hSteamNetworkingSockets, info->m_hConn, 0, NULL, 0 ); - network_client.remote = 0; + network_disconnect(); } else if( info->m_info.m_eState == k_ESteamNetworkingConnectionState_ProblemDetectedLocally ){ - SteamAPI_ISteamNetworkingSockets_CloseConnection( - hSteamNetworkingSockets, info->m_hConn, 0, NULL, 0 ); - network_client.remote = 0; + network_disconnect(); } } else{ diff --git a/player_remote.c b/player_remote.c index d1bb149..69f148f 100644 --- a/player_remote.c +++ b/player_remote.c @@ -81,7 +81,12 @@ static void remote_player_network_imgui(void){ struct { enum ESteamNetworkingConnectionState state; const char *str; } states[] = { { k_ESteamNetworkingConnectionState_None, "None" }, - { k_ESteamNetworkingConnectionState_Connecting, "Connecting" }, + { k_ESteamNetworkingConnectionState_Connecting, + (const char *[]){"Connecting -", + "Connecting /", + "Connecting |", + "Connecting \\", + }[(u32)(vg.time_real/0.25) & 0x3 ] }, { k_ESteamNetworkingConnectionState_FindingRoute, "Finding Route" }, { k_ESteamNetworkingConnectionState_Connected, "Connected" }, { k_ESteamNetworkingConnectionState_ClosedByPeer, "Closed by peer" }, @@ -100,19 +105,24 @@ static void remote_player_network_imgui(void){ snprintf( buf, 512, "Network: %s", netstatus ); ui_info( panel, buf ); ui_info( panel, "---------------------" ); - ui_info( panel, "#-1: localplayer" ); - for( u32 i=0; iactive ){ - const char *sysname = "invalid"; - - if( (player->subsystem >= 0) && - (player->subsystem < k_player_subsystem_max) ){ - sysname = player_subsystems[ player->subsystem ]->name; + if( network_client.state == k_ESteamNetworkingConnectionState_Connected ){ + ui_info( panel, "#-1: localplayer" ); + for( u32 i=0; iactive ){ + const char *sysname = "invalid"; + + if( (player->subsystem >= 0) && + (player->subsystem < k_player_subsystem_max) ){ + sysname = player_subsystems[ player->subsystem ]->name; + } + snprintf( buf, 512, "#%u: %s [%s]", i, player->username, sysname ); + ui_info( panel, buf ); } - snprintf( buf, 512, "#%u: %s [%s]", i, player->username, sysname ); - ui_info( panel, buf ); } } + else { + ui_info( panel, "offline" ); + } } -- 2.25.1