lap timing publish and store, username store in db
[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 static int network_scores_updated = 0;
18
19 /*
20 * Interface
21 */
22 //#define SR_USE_LOCALHOST
23
24 /* Call it at start; Connects us to the gameserver */
25 static void network_init(void);
26
27 /* Run this from main loop */
28 static void network_update(void);
29
30 /* Call it at shutdown */
31 static void network_end(void);
32
33 /*
34 * Can buffer up a bunch of these by calling many times, they will be
35 * sent at the next connection
36 */
37 static void network_submit_highscore( u32 trackid, u16 points, u16 time );
38
39 /*
40 * Game endpoints are provided with the same names to allow running without a
41 * network connection.
42 */
43
44 struct {
45 u8 app_symmetric_key[ 1024 ];
46 u32 app_key_length;
47 EServerMode auth_mode;
48
49 HSteamNetConnection remote;
50 ESteamNetworkingConnectionState state;
51
52 f64 last_attempt, last_frame;
53 u32 retries;
54
55 i32 network_info;
56
57 struct network_request {
58 vg_pool_node poolnode;
59 void (*callback)( netmsg_request *res, vg_msg *body );
60 f64 sendtime;
61 }
62 *request_buffer;
63 vg_pool request_pool;
64 }
65 static network_client = {
66 .auth_mode = eServerModeAuthentication,
67 .state = k_ESteamNetworkingConnectionState_None,
68 };
69
70 static int packet_minsize( SteamNetworkingMessage_t *msg, u32 size );
71 static void network_send_item( enum netmsg_playeritem_type type );
72 static void network_request_scoreboard( const char *mod_uid,
73 const char *route_uid,
74 u32 week );
75 static void network_publish_laptime( const char *mod_uid,
76 const char *route_uid, f64 lap_time );
77
78 #endif /* NETWORK_H */