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