Do actual domain resolution
[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 #pragma once
7 #include "vg/vg_platform.h"
8 #include "vg/vg_steam_networking.h"
9 #include "steam.h"
10 #include "network_common.h"
11 #include "network_msg.h"
12 #include "addon_types.h"
13
14 #define NETWORK_MAX_REQUESTS 8
15
16 /*
17 * Interface
18 */
19
20 /* Call it at start; Connects us to the gameserver */
21 void network_init(void);
22
23 /* Run this from main loop */
24 void network_update(void);
25
26 /* Call it at shutdown */
27 void network_end(void);
28
29 /*
30 * Can buffer up a bunch of these by calling many times, they will be
31 * sent at the next connection
32 */
33 void network_submit_highscore( u32 trackid, u16 points, u16 time );
34
35 /*
36 * Game endpoints are provided with the same names to allow running without a
37 * network connection.
38 */
39
40 struct network_client
41 {
42 u8 app_symmetric_key[ 1024 ];
43 u32 app_key_length;
44 EServerMode auth_mode;
45
46 HSteamNetConnection remote;
47 ESteamNetworkingConnectionState state;
48 u32 remote_version;
49
50 f64 last_attempt, last_frame;
51 u32 retries;
52
53 i32 network_info;
54 i32 auto_connect;
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 SteamNetworkingIPAddr ip;
66 char host_port[8], host_adress[256];
67 bool ip_resolved;
68
69 enum server_intent {
70 k_server_intent_offline,
71 k_server_intent_online
72 }
73 user_intent;
74 f64 last_intent_change;
75 f32 fintent; /* yeah this shit really shouldnt be here but oh well */
76 }
77 extern network_client;
78
79 int packet_minsize( SteamNetworkingMessage_t *msg, u32 size );
80 void network_send_item( enum netmsg_playeritem_type type );
81 void network_request_scoreboard( const char *mod_uid,
82 const char *route_uid,
83 u32 week, u64 userdata );
84 void network_publish_laptime( const char *mod_uid,
85 const char *route_uid, f64 lap_time );
86 void chat_send_message( const char *message );
87 void render_server_status_gui(void);
88 void network_status_string( vg_str *str, u32 *colour );
89 void network_send_region(void);
90 void network_set_host( const char *host_str, const char *port_str );
91
92 static inline int network_connected(void)
93 {
94 if( network_client.remote_version != NETWORK_SKATERIFT_VERSION ) return 0;
95 return network_client.state == k_ESteamNetworkingConnectionState_Connected;
96 }