rigidbody math corrections & ragdoll tweaks for stability
[carveJwlIkooP6JGAAIwe30JlM.git] / network.h
1 /*
2 * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
3 * All trademarks are property of their respective owners
4 */
5
6 #ifndef NETWORK_H
7 #define NETWORK_H
8
9 #include "vg/vg_stdint.h"
10 #include "steam.h"
11 #include "network_common.h"
12 #include "network_msg.h"
13 #include "addon_types.h"
14
15 #define NETWORK_MAX_REQUESTS 8
16
17 /*
18 * Interface
19 */
20
21 /* Call it at start; Connects us to the gameserver */
22 static void network_init(void);
23
24 /* Run this from main loop */
25 static void network_update(void);
26
27 /* Call it at shutdown */
28 static void network_end(void);
29
30 /*
31 * Can buffer up a bunch of these by calling many times, they will be
32 * sent at the next connection
33 */
34 static void network_submit_highscore( u32 trackid, u16 points, u16 time );
35
36 /*
37 * Game endpoints are provided with the same names to allow running without a
38 * network connection.
39 */
40
41 struct {
42 u8 app_symmetric_key[ 1024 ];
43 u32 app_key_length;
44 EServerMode auth_mode;
45
46 HSteamNetConnection remote;
47 ESteamNetworkingConnectionState state;
48 u32 remote_version;
49
50 f64 last_attempt, last_frame;
51 u32 retries;
52
53 i32 network_info;
54
55 struct network_request {
56 vg_pool_node poolnode;
57 void (*callback)( netmsg_request *res, vg_msg *body, u64 userdata );
58 f64 sendtime;
59 u64 userdata;
60 }
61 *request_buffer;
62 vg_pool request_pool;
63
64 char server_adress[64];
65
66 enum server_intent {
67 k_server_intent_offline,
68 k_server_intent_online
69 }
70 user_intent;
71 f64 last_intent_change;
72 f32 fintent; /* yeah this shit really shouldnt be here but oh well */
73 }
74 static network_client = {
75 .auth_mode = eServerModeAuthentication,
76 .state = k_ESteamNetworkingConnectionState_None,
77 .server_adress = "46.101.34.155",
78 .last_intent_change = -99999.9
79 };
80
81 static int packet_minsize( SteamNetworkingMessage_t *msg, u32 size );
82 static void network_send_item( enum netmsg_playeritem_type type );
83 static void network_request_scoreboard( const char *mod_uid,
84 const char *route_uid,
85 u32 week, u64 userdata );
86 static void network_publish_laptime( const char *mod_uid,
87 const char *route_uid, f64 lap_time );
88 static void chat_send_message( const char *message );
89 static void render_server_status_gui(void);
90 static void network_status_string( vg_str *str, u32 *colour );
91 static void network_send_region(void);
92
93 static int network_connected(void){
94 if( network_client.remote_version != NETWORK_SKATERIFT_VERSION ) return 0;
95 return network_client.state == k_ESteamNetworkingConnectionState_Connected;
96 }
97
98 #endif /* NETWORK_H */