scoreboards
[carveJwlIkooP6JGAAIwe30JlM.git] / steam.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 STEAM_H
7 #define STEAM_H
8
9 #include "vg/vg_steam.h"
10 #include "vg/vg_steam_utils.h"
11 #include "vg/vg_steam_networking.h"
12 #include "vg/vg_steam_auth.h"
13 #include "vg/vg_steam_http.h"
14 #include "vg/vg_steam_friends.h"
15
16 /*
17 * We only want to use steamworks if building for the networked version,
18 * theres not much point otherwise. We mainly want steamworks for setting
19 * achievements etc.. so that includes our own server too.
20 *
21 * This file also wraps the functions and interfaces that we want to use to
22 * make them a bit easier to read, since they are the flat API they have very
23 * long names. in non-networked builds they will return default errors or do
24 * nothing.
25 */
26
27 static char steam_username_at_startup[128];
28
29 static void recv_steam_warning( int severity, const char *msg )
30 {
31 if( severity == 0 )
32 vg_low( "%s\n", msg );
33 else
34 vg_info( "%s\n", msg );
35 }
36
37 static int steam_ready = 0;
38 static void *hSteamNetworkingSockets,
39 *hSteamUser;
40
41 static HSteamPipe hSteamClientPipe;
42
43 static int steam_init(void)
44 {
45 const char *username = NULL;
46
47 #ifdef SR_NETWORKED
48 vg_info( "Initializing steamworks\n" );
49
50 if( !SteamAPI_Init() )
51 {
52 printf("\n");
53 vg_error( "Steamworks failed to initialize\n" );
54 return 1;
55 }
56
57 steam_ready = 1;
58
59 SteamAPI_ManualDispatch_Init();
60
61 /* Connect interfaces */
62 hSteamClientPipe = SteamAPI_GetHSteamPipe();
63 hSteamNetworkingSockets = SteamAPI_SteamNetworkingSockets_SteamAPI();
64 hSteamUser = SteamAPI_SteamUser();
65
66 ISteamUtils *utils = SteamAPI_SteamUtils();
67 SteamAPI_ISteamUtils_SetWarningMessageHook( utils, recv_steam_warning );
68
69 printf("\n");
70 vg_success( "\nSteamworks API running\n" );
71
72 ISteamFriends *hSteamFriends = SteamAPI_SteamFriends();
73 username = SteamAPI_ISteamFriends_GetPersonaName( hSteamFriends );
74 #endif
75
76 /* TODO: On username update callback */
77 str_utf8_collapse( username, steam_username_at_startup,
78 vg_list_size(steam_username_at_startup) );
79
80 return 1;
81 }
82
83 static void steam_update(void)
84 {
85 if( steam_ready )
86 steamworks_event_loop( hSteamClientPipe );
87 }
88
89 static void steam_end(void *nothing)
90 {
91 if( steam_ready )
92 {
93 vg_info( "Shutting down\n..." );
94 SteamAPI_Shutdown();
95 }
96 }
97
98 #endif /* STEAM_H */