X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=network.h;h=6af51af6ccf94de2896f35e056ed803d8400c34b;hb=ea41214530c8f3517b59ccbf7fad9f3bb159684a;hp=b643a1b7da9f96641972d352417c3569d3ba2577;hpb=8090b8da9ce1397ba47d7e2d91b4f1716f708f25;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/network.h b/network.h index b643a1b..6af51af 100644 --- a/network.h +++ b/network.h @@ -1,16 +1,16 @@ /* - * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved + * Copyright (C) 2021-2024 Mt.ZERO Software, Harry Godden - All Rights Reserved * All trademarks are property of their respective owners */ -#ifndef NETWORK_H -#define NETWORK_H - -#include "vg/vg_stdint.h" +#pragma once +#include "vg/vg_platform.h" +#include "vg/vg_steam_networking.h" +#include "vg/vg_mem_pool.h" +#include "vg/vg_msg.h" #include "steam.h" #include "network_common.h" #include "network_msg.h" -#include "highscores.h" #include "addon_types.h" #define NETWORK_MAX_REQUESTS 8 @@ -20,26 +20,27 @@ */ /* Call it at start; Connects us to the gameserver */ -static void network_init(void); +void network_init(void); /* Run this from main loop */ -static void network_update(void); +void network_update(void); /* Call it at shutdown */ -static void network_end(void); +void network_end(void); /* * Can buffer up a bunch of these by calling many times, they will be * sent at the next connection */ -static void network_submit_highscore( u32 trackid, u16 points, u16 time ); +void network_submit_highscore( u32 trackid, u16 points, u16 time ); /* * Game endpoints are provided with the same names to allow running without a * network connection. */ -struct { +struct network_client +{ u8 app_symmetric_key[ 1024 ]; u32 app_key_length; EServerMode auth_mode; @@ -52,6 +53,7 @@ struct { u32 retries; i32 network_info; + i32 auto_connect; struct network_request { vg_pool_node poolnode; @@ -62,26 +64,35 @@ struct { *request_buffer; vg_pool request_pool; - char server_adress[64]; + SteamNetworkingIPAddr ip; + char host_port[8], host_adress[256]; + bool ip_resolved; + + enum server_intent { + k_server_intent_offline, + k_server_intent_online + } + user_intent; + f64 last_intent_change; + f32 fintent; /* yeah this shit really shouldnt be here but oh well */ } -static network_client = { - .auth_mode = eServerModeAuthentication, - .state = k_ESteamNetworkingConnectionState_None, - .server_adress = "46.101.34.155" -}; - -static int packet_minsize( SteamNetworkingMessage_t *msg, u32 size ); -static void network_send_item( enum netmsg_playeritem_type type ); -static void network_request_scoreboard( const char *mod_uid, - const char *route_uid, - u32 week, u64 userdata ); -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 int network_connected(void){ +extern network_client; + +int packet_minsize( SteamNetworkingMessage_t *msg, u32 size ); +void network_send_item( enum netmsg_playeritem_type type ); +void network_request_scoreboard( const char *mod_uid, + const char *route_uid, + u32 week, u64 userdata ); +void network_publish_laptime( const char *mod_uid, + const char *route_uid, f64 lap_time ); +void chat_send_message( const char *message ); +void render_server_status_gui(void); +void network_status_string( vg_str *str, u32 *colour ); +void network_send_region(void); +void network_set_host( const char *host_str, const char *port_str ); + +static inline int network_connected(void) +{ if( network_client.remote_version != NETWORK_SKATERIFT_VERSION ) return 0; return network_client.state == k_ESteamNetworkingConnectionState_Connected; } - -#endif /* NETWORK_H */