Merge all features from glider feature branch
[carveJwlIkooP6JGAAIwe30JlM.git] / network.h
index f97cfbc8f5fdfeb3d50b4009b03c51fb07306e07..6770d323a0e0b7fd7b788172eac54b86a1bd3d20 100644 (file)
--- a/network.h
+++ b/network.h
@@ -1,8 +1,98 @@
+/*
+ * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
+ * All trademarks are property of their respective owners
+ */
+
 #ifndef NETWORK_H
 #define NETWORK_H
 
 #include "vg/vg_stdint.h"
+#include "steam.h"
+#include "network_common.h"
+#include "network_msg.h"
+#include "addon_types.h"
+
+#define NETWORK_MAX_REQUESTS 8
+
+/* 
+ * Interface
+ */
+
+/* Call it at start; Connects us to the gameserver */
+static void network_init(void);
+
+/* Run this from main loop */
+static void network_update(void);
+
+/* Call it at shutdown */
+static void network_end(void);
+
+/* 
+ * Can buffer up a bunch of these by calling many times, they will be
+ * sent at the next connection 
+ */
+static void network_submit_highscore( u32 trackid, u16 points, u16 time );
+
+/*
+ * Game endpoints are provided with the same names to allow running without a
+ * network connection.
+ */
+
+struct {
+   u8 app_symmetric_key[ 1024 ];
+   u32 app_key_length;
+   EServerMode auth_mode;
+
+   HSteamNetConnection remote;
+   ESteamNetworkingConnectionState state;
+   u32 remote_version;
+
+   f64 last_attempt, last_frame;
+   u32 retries;
+
+   i32 network_info;
+
+   struct network_request {
+      vg_pool_node poolnode;
+      void (*callback)( netmsg_request *res, vg_msg *body, u64 userdata );
+      f64 sendtime;
+      u64 userdata;
+   }
+   *request_buffer;
+   vg_pool request_pool;
+
+   char server_adress[64];
+
+   enum server_intent {
+      k_server_intent_offline,
+      k_server_intent_online
+   }
+   user_intent;
+   f64 last_intent_change;
+   f32 fintent; /* yeah this shit really shouldnt be here but oh well */
+}
+static network_client = {
+   .auth_mode = eServerModeAuthentication,
+   .state = k_ESteamNetworkingConnectionState_None,
+   .server_adress = "46.101.34.155",
+   .last_intent_change = -99999.9
+};
 
+static int packet_minsize( SteamNetworkingMessage_t *msg, u32 size );
+static void network_send_item( enum netmsg_playeritem_type type );
+static void network_request_scoreboard( const char *mod_uid, 
+                                        const char *route_uid,
+                                        u32 week, u64 userdata );
+static void network_publish_laptime( const char *mod_uid, 
+                                     const char *route_uid, f64 lap_time );
+static void chat_send_message( const char *message );
+static void render_server_status_gui(void);
+static void network_status_string( vg_str *str, u32 *colour );
+static void network_send_region(void);
 
+static int network_connected(void){
+   if( network_client.remote_version != NETWORK_SKATERIFT_VERSION ) return 0;
+   return network_client.state == k_ESteamNetworkingConnectionState_Connected;
+}
 
 #endif /* NETWORK_H */