connection semantics
[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 //#define SR_USE_LOCALHOST
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
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 static network_client = {
67 .auth_mode = eServerModeAuthentication,
68 .state = k_ESteamNetworkingConnectionState_None,
69 .server_adress = "46.101.34.155:27402"
70 };
71
72 static int packet_minsize( SteamNetworkingMessage_t *msg, u32 size );
73 static void network_send_item( enum netmsg_playeritem_type type );
74 static void network_request_scoreboard( const char *mod_uid,
75 const char *route_uid,
76 u32 week, u64 userdata );
77 static void network_publish_laptime( const char *mod_uid,
78 const char *route_uid, f64 lap_time );
79
80 static int network_connected(void){
81 return network_client.state == k_ESteamNetworkingConnectionState_Connected;
82 }
83
84 #endif /* NETWORK_H */