show friends in yellow, dont show out-of-world people
[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_msg.h"
12 #include "highscores.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
49 f64 last_attempt, last_frame;
50 u32 retries;
51
52 i32 network_info;
53
54 struct network_request {
55 vg_pool_node poolnode;
56 void (*callback)( netmsg_request *res, vg_msg *body, u64 userdata );
57 f64 sendtime;
58 u64 userdata;
59 }
60 *request_buffer;
61 vg_pool request_pool;
62
63 char server_adress[64];
64 }
65 static network_client = {
66 .auth_mode = eServerModeAuthentication,
67 .state = k_ESteamNetworkingConnectionState_None,
68 .server_adress = "46.101.34.155"
69 };
70
71 static int packet_minsize( SteamNetworkingMessage_t *msg, u32 size );
72 static void network_send_item( enum netmsg_playeritem_type type );
73 static void network_request_scoreboard( const char *mod_uid,
74 const char *route_uid,
75 u32 week, u64 userdata );
76 static void network_publish_laptime( const char *mod_uid,
77 const char *route_uid, f64 lap_time );
78
79 static int network_connected(void){
80 return network_client.state == k_ESteamNetworkingConnectionState_Connected;
81 }
82
83 #endif /* NETWORK_H */