From bdca621ba09a4611d9fb57f791e96172e376651a Mon Sep 17 00:00:00 2001 From: hgn Date: Sat, 25 Nov 2023 09:04:23 +0000 Subject: [PATCH] show error messages if trying to connect to server --- network.c | 67 ++++++++++++++++++++++++++----------------------- network.h | 1 + player_remote.c | 14 +++++++++++ 3 files changed, 50 insertions(+), 32 deletions(-) diff --git a/network.c b/network.c index ecd8587..67fae51 100644 --- a/network.c +++ b/network.c @@ -278,62 +278,65 @@ static void network_disconnect(void){ } } -static void render_server_status_gui(void){ - render_fb_bind( gpipeline.fb_workshop_preview, 0 ); - - /* HACK */ - vg_ui.cur_vert = 0; - vg_ui.cur_indice = 0; - vg_ui.vert_start = 0; - vg_ui.indice_start = 0; - - ui_rect r = { 0, 0, 128, 48 }; - - char buf[128]; - vg_str str; - vg_strnull( &str, buf, sizeof(buf) ); - - u32 bg = 0xff000000; - +static void network_status_string( vg_str *str, u32 *colour ){ if( steam_ready ){ if( network_client.user_intent == k_server_intent_offline ){ - vg_strcat( &str, "Offline" ); + vg_strcat( str, "Offline" ); } else { ESteamNetworkingConnectionState state = network_client.state; if( state == k_ESteamNetworkingConnectionState_None ) - vg_strcat( &str, "No Connection" ); + vg_strcat( str, "No Connection" ); else if( state == k_ESteamNetworkingConnectionState_Connecting ){ - vg_strcat( &str, "Connecting to:\nskaterift.com" ); + vg_strcat( str, "Connecting to:\nskaterift.com" ); if( network_client.retries ){ - vg_strcat( &str, "\n(" ); - vg_strcati32( &str, network_client.retries ); - vg_strcat( &str, " retries)" ); + vg_strcat( str, "\n(" ); + vg_strcati32( str, network_client.retries ); + vg_strcat( str, " retries)" ); } } else if( state == k_ESteamNetworkingConnectionState_Connected ){ - vg_strcat( &str, "Connected to:\nskaterift.com" ); - bg = 0xff00a020; + vg_strcat( str, "Connected to:\nskaterift.com" ); + *colour = 0xff00a020; } else if( state == k_ESteamNetworkingConnectionState_ClosedByPeer ) - vg_strcat( &str, "Connection Closed" ); + vg_strcat( str, "Connection Closed" ); else if( state == k_ESteamNetworkingConnectionState_FindingRoute ) - vg_strcat( &str, "Finding Route" ); + vg_strcat( str, "Finding Route" ); else if( state == k_ESteamNetworkingConnectionState_ProblemDetectedLocally){ - vg_strcat( &str, "Problem Detected\nLocally" ); - bg = 0xff0000a0; + vg_strcat( str, "Problem Detected\nLocally" ); + *colour = 0xff0000a0; } else - vg_strcat( &str, "???" ); + vg_strcat( str, "???" ); } } else { - vg_strcat( &str, "No Steam Connection" ); - bg = 0xff0000a0; + vg_strcat( str, "Steam Offline" ); + *colour = 0xff0000a0; } +} + +static void render_server_status_gui(void){ + render_fb_bind( gpipeline.fb_workshop_preview, 0 ); + + /* HACK */ + vg_ui.cur_vert = 0; + vg_ui.cur_indice = 0; + vg_ui.vert_start = 0; + vg_ui.indice_start = 0; + + ui_rect r = { 0, 0, 128, 48 }; + + char buf[128]; + vg_str str; + vg_strnull( &str, buf, sizeof(buf) ); + + u32 bg = 0xff000000; + network_status_string( &str, &bg ); ui_fill( r, bg ); ui_text( r, buf, 1, k_ui_align_center, 0 ); diff --git a/network.h b/network.h index 729029a..0c16fa7 100644 --- a/network.h +++ b/network.h @@ -88,6 +88,7 @@ static void network_publish_laptime( const char *mod_uid, const char *route_uid, f64 lap_time ); static void chat_send_message( const char *message ); static void render_server_status_gui(void); +static void network_status_string( vg_str *str, u32 *colour ); static int network_connected(void){ if( network_client.remote_version != NETWORK_SKATERIFT_VERSION ) return 0; diff --git a/player_remote.c b/player_remote.c index 0336624..ad1c2e5 100644 --- a/player_remote.c +++ b/player_remote.c @@ -368,6 +368,20 @@ static void remote_player_debug_update(void){ * Debugging information */ static void remote_player_network_imgui( m4x4f pv ){ + if( network_client.user_intent == k_server_intent_online ){ + if( !(steam_ready && + (network_client.state == k_ESteamNetworkingConnectionState_Connected))) + { + char buf[128]; + vg_str str; + vg_strnull( &str, buf, sizeof(buf) ); + u32 fg = 0; + network_status_string( &str, &fg ); + ui_text( (ui_rect){ vg.window_x - 200, 0, 200, 32 }, buf, 1, + k_ui_align_middle_center, fg ); + } + } + if( !network_client.network_info ) return; -- 2.25.1