gameserver monitor initial work
[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
14 VG_STATIC int network_scores_updated = 0;
15
16 /*
17 * Interface
18 */
19 //#define SR_USE_LOCALHOST
20
21 /* Call it at start; Connects us to the gameserver */
22 VG_STATIC void network_init(void);
23
24 /* Run this from main loop */
25 VG_STATIC void network_update(void);
26
27 /* Call it at shutdown */
28 VG_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 VG_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 #ifdef SR_NETWORKED
41
42 struct {
43 u8 app_symmetric_key[ 1024 ];
44 u32 app_key_length;
45 EServerMode auth_mode;
46
47 int name_update;
48
49 HSteamNetConnection remote;
50 ESteamNetworkingConnectionState state;
51
52 f64 last_attempt, last_frame;
53 u32 retries;
54 }
55 static network_client = {
56 .state = k_ESteamNetworkingConnectionState_None,
57 .auth_mode = eServerModeAuthentication,
58 .name_update = 1
59 };
60
61 #else /* SR_NETWORKED */
62
63 VG_STATIC void network_init(void){}
64 VG_STATIC void network_update(void){}
65 VG_STATIC void network_end(void){}
66
67 #endif /* SR_NETWORKED */
68 #endif /* NETWORK_H */