OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
sc.h
1
3#ifndef __SC_H__
4#define __SC_H__
5
6
9#include "../common/gsCommon.h"
10#include "../common/gsRC4.h"
11#include "../common/gsAvailable.h"
12#include "../ghttp/ghttp.h"
13#include "../webservices/AuthService.h"
14
15
16#ifdef __cplusplus
17extern "C" {
18#endif // __cplusplus
19
20// optional to explicitly use __stdcall, __cdecl, __fastcall
21#define SC_CALL
22
23
26// Set this to define memory settings for the SDK
27#define SC_STATIC_MEM
28
29// The initial (or fixed, for static memory) report buffer size
30#define SC_REPORT_BUFFER_BYTES 65536
31
32// URL for sc services.
33#define SC_SERVICE_MAX_URL_LEN 128
34extern char scServiceURL[SC_SERVICE_MAX_URL_LEN];
35
36// Session GUID size - must match backend
37//#define SC_SESSION_GUID_SIZE 16
38#define SC_AUTHDATA_SIZE 16
39#define SC_SESSION_GUID_SIZE 40
40#define SC_CONNECTION_GUID_SIZE 40
41
42#define SC_GUID_BINARY_SIZE 16 // convert the 40 byte string guid into an int, 2 shorts and 8 bytes
43
44// Limit to the number of teams
45#define SC_MAX_NUM_TEAMS 64
46
47// OPTIONS flags - first two bits reserved for authoritative / final flags
48#define SC_OPTIONS_NONE 0
49
50
53// Result codes
54typedef enum
55{
56 SCResult_NO_ERROR = 0,
57 SCResult_NO_AVAILABILITY_CHECK,
58 SCResult_INVALID_PARAMETERS,
59 SCResult_NOT_INITIALIZED,
60 SCResult_CORE_NOT_INITIALIZED,
61 SCResult_OUT_OF_MEMORY,
62 SCResult_CALLBACK_PENDING,
63
64 SCResult_HTTP_ERROR,
65 SCResult_UNKNOWN_RESPONSE, // server reported an error which is unknown to us
66 SCResult_RESPONSE_INVALID,
67
68 SCResult_REPORT_INCOMPLETE,
69 SCResult_REPORT_INVALID,
70 SCResult_SUBMISSION_FAILED,
71
72 SCResult_UNKNOWN_ERROR,
73
74 SCResultMax
75} SCResult;
76
77
78// Game Results
79typedef enum
80{
81 SCGameResult_WIN,
82 SCGameResult_LOSS,
83 SCGameResult_DRAW,
84 SCGameResult_DISCONNECT,
85 SCGameResult_DESYNC,
86 SCGameResult_NONE,
87
88 SCGameResultMax
89} SCGameResult;
90
91
92// Game Status
93typedef enum
94{
95 SCGameStatus_COMPLETE,
96 SCGameStatus_PARTIAL,
97 SCGameStatus_BROKEN,
98
99 SCGameStatusMax
100} SCGameStatus;
101
102
105// Data types
106typedef void* SCInterfacePtr;
107typedef void* SCReportPtr;
108
109
110//typedef gsi_u32 SCTeamCount;
111//typedef gsi_u32 SCTeamIndex;
112
113//typedef gsi_u32 SCPlayerCount;
114//typedef gsi_u32 SCPlayerIndex;
115
116//typedef gsi_u16 SCKey;
117
118typedef char SCHiddenData[64];
119
120//typedef enum
121//{
122// SCReportKeyType_SERVER,
123// SCReportKeyType_TEAM,
124// SCReportKeyType_PLAYER
125//} SCReportKeyType;
126
127
130// Callbacks
131typedef void (*SCCreateSessionCallback)(const SCInterfacePtr theInterface,
132 GHTTPResult theHttpResult,
133 SCResult theResult,
134 void * theUserData);
135typedef void (*SCSetReportIntentionCallback)(const SCInterfacePtr theInterface,
136 GHTTPResult theHttpResult,
137 SCResult theResult,
138 void * theUserData);
139typedef void (*SCSubmitReportCallback)(const SCInterfacePtr theInterface,
140 GHTTPResult theHttpResult,
141 SCResult theResult,
142 void * theUserData);
143
144/*
145typedef void (*SCKeyCallback) (SCReportPtr theReport,
146 SCReportKeyType theKeyType,
147 gsi_u32 theIndex, // how many times this has been called
148 void* theUserParam);
149*/
150
153// Main interface functions
154SCResult SC_CALL scInitialize(int theGameId,
155 SCInterfacePtr * theInterfaceOut);
156SCResult SC_CALL scShutdown (SCInterfacePtr theInterface);
157SCResult SC_CALL scThink (SCInterfacePtr theInterface);
158
159SCResult SC_CALL scCreateSession(SCInterfacePtr theInterface,
160 const GSLoginCertificate * theCertificate,
161 const GSLoginPrivateData * thePrivateData,
162 SCCreateSessionCallback theCallback,
163 gsi_time theTimeoutMs,
164 void * theUserData);
165
166// This is a variation of scCreateSession that creates a "matchless" session.
167// "matchless" means incoming data will be scrutinized less, and applied to stats immediately instead of when the match is over.
168SCResult SC_CALL scCreateMatchlessSession(SCInterfacePtr theInterface,
169 const GSLoginCertificate * theCertificate,
170 const GSLoginPrivateData * thePrivateData,
171 SCCreateSessionCallback theCallback,
172 gsi_time theTimeoutMs,
173 void * theUserData);
174
175SCResult SC_CALL scSetReportIntention(const SCInterfacePtr theInterface,
176 const gsi_u8 theConnectionId[SC_CONNECTION_GUID_SIZE],
177 gsi_bool isAuthoritative,
178 const GSLoginCertificate * theCertificate,
179 const GSLoginPrivateData * thePrivateData,
180 SCSetReportIntentionCallback theCallback,
181 gsi_time theTimeoutMs,
182 void * theUserData);
183
184SCResult SC_CALL scSubmitReport (const SCInterfacePtr theInterface,
185 const SCReportPtr theReport,
186 gsi_bool isAuthoritative,
187 const GSLoginCertificate * theCertificate,
188 const GSLoginPrivateData * thePrivateData,
189 SCSubmitReportCallback theCallback,
190 gsi_time theTimeoutMs,
191 void * theUserData);
192
193//SCResult SC_CALL sc
194SCResult SC_CALL scSetSessionId(const SCInterfacePtr theInterface, const gsi_u8 theSessionId[SC_SESSION_GUID_SIZE]);
195
196const char * scGetSessionId (const SCInterfacePtr theInterface);
197const char * scGetConnectionId(const SCInterfacePtr theInterface);
198
199
202// Report generation functions
203
204// Create a new (empty) report
205// - Specify player and team count so we can allocate memory
206// and later sanity check against reported data
207SCResult SC_CALL scCreateReport(const SCInterfacePtr theInterface,
208 gsi_u32 theHeaderVersion,
209 gsi_u32 thePlayerCount,
210 gsi_u32 theTeamCount,
211 SCReportPtr * theReportOut);
212
213// - Write global data key/values
214SCResult SC_CALL scReportBeginGlobalData(SCReportPtr theReportData);
215SCResult SC_CALL scReportBeginPlayerData(SCReportPtr theReportData);
216SCResult SC_CALL scReportBeginTeamData (SCReportPtr theReportData);
217
218
219// - Write player auth info and key/values
220SCResult SC_CALL scReportBeginNewPlayer(SCReportPtr theReportData);
221SCResult SC_CALL scReportSetPlayerData (SCReportPtr theReport,
222 gsi_u32 thePlayerIndex,
223 const gsi_u8 thePlayerConnectionId[SC_CONNECTION_GUID_SIZE],
224 gsi_u32 thePlayerTeamId,
225 SCGameResult theResult,
226 gsi_u32 theProfileId,
227 const GSLoginCertificate * theCertificate,
228 const gsi_u8 theAuthData[16]);
229
230// - Write team info and key/values
231SCResult SC_CALL scReportBeginNewTeam(SCReportPtr theReportData);
232SCResult SC_CALL scReportSetTeamData (SCReportPtr theReport,
233 gsi_u32 theTeamId,
234 SCGameResult theResult);
235
236// - Call this when you're finished writing the report
237SCResult SC_CALL scReportEnd(SCReportPtr theReport,
238 gsi_bool isAuth,
239 SCGameStatus theStatus);
240
241// Call this to set the report as "matchless".
242// This is needed if the report is being submitted to a "matchless" game session.
243SCResult SC_CALL scReportSetAsMatchless(SCReportPtr theReport);
244
245
246// Utility to record key value pairs
247SCResult SC_CALL scReportAddIntValue(SCReportPtr theReportData,
248 gsi_u16 theKeyId,
249 gsi_i32 theValue);
250SCResult SC_CALL scReportAddInt64Value(SCReportPtr theReportData,
251 gsi_u16 theKeyId,
252 gsi_i64 theValue);
253SCResult SC_CALL scReportAddShortValue(SCReportPtr theReportData,
254 gsi_u16 theKeyId,
255 gsi_i16 theValue);
256SCResult SC_CALL scReportAddByteValue(SCReportPtr theReportData,
257 gsi_u16 theKeyId,
258 gsi_i8 theValue);
259SCResult SC_CALL scReportAddFloatValue(SCReportPtr theReportData,
260 gsi_u16 theKeyId,
261 float theValue);
262SCResult SC_CALL scReportAddStringValue(SCReportPtr theReportData,
263 gsi_u16 theKeyId,
264 const gsi_char * theValue);
265SCResult SC_CALL scDestroyReport(SCReportPtr theReport);
266
269// Peer to peer encryption utilities (Will probably be moved to common code)
270
271// A symmetric cipher key for peer-to-peer communication
272// Will usually have one key for sending and a second key for receiving
273typedef struct SCPeerCipher
274{
275 RC4Context mRC4;
276 gsi_u8 mKey[GS_CRYPT_RSA_BYTE_SIZE];
277 gsi_u32 mKeyLen;
278 gsi_bool mInitialized;
280
281typedef char SCPeerKeyExchangeMsg[GS_CRYPT_RSA_BYTE_SIZE];
282
283SCResult SC_CALL scPeerCipherInit(const GSLoginCertificate * theLocalCert, SCPeerCipher * theCipher);
284
285SCResult SC_CALL scPeerCipherCreateKeyExchangeMsg(const GSLoginCertificate * theRemoteCert,
286 const SCPeerCipher * theCipher,
287 SCPeerKeyExchangeMsg theMsgOut);
288
289SCResult SC_CALL scPeerCipherParseKeyExchangeMsg (const GSLoginCertificate * theLocalCert,
290 const GSLoginPrivateData * theCertPrivateData,
291 const SCPeerKeyExchangeMsg theMsg,
292 SCPeerCipher * theCipherOut);
293
294// Encrypt/Decrypt in place, also the RC4 context is modified everytime encryption/decryption take place
295SCResult SC_CALL scPeerCipherEncryptBuffer(SCPeerCipher * theCipher, gsi_u8 * theData, gsi_u32 theLen);
296SCResult SC_CALL scPeerCipherDecryptBuffer(SCPeerCipher * theCipher, gsi_u8 * theData, gsi_u32 theLen);
297
298// When using UDP (non-ordered) you must supply a message num
299// - This is less efficient then ecrypting an ordered stream
300SCResult SC_CALL scPeerCipherEncryptBufferIV(SCPeerCipher * theCipher, gsi_u32 theMessageNum, gsi_u8 * theData, gsi_u32 theLen);
301SCResult SC_CALL scPeerCipherDecryptBufferIV(SCPeerCipher * theCipher, gsi_u32 theMessageNum, gsi_u8 * theData, gsi_u32 theLen);
302
303
306
307#ifdef __cplusplus
308} // extern "C"
309#endif // __cplusplus
310
311
314#endif // __SC_H__
Definition AuthService.h:87
Definition gsRC4.h:18
Definition sc.h:274