1 /*---------------------------------------------------------------------------*
2   Project:  RevolutionDWC public include file
3   File:     ./account/dwc_account.h
4 
5   Copyright 2005-2008 Nintendo. All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law. They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13  *---------------------------------------------------------------------------*/
14 
15 #ifndef DWC_ACCOUNT_H_
16 #define DWC_ACCOUNT_H_
17 
18 #ifdef __cplusplus
19 extern "C"
20 {
21 #endif // __cplusplus
22 
23 
24     /* --------------------------------------------------------------------
25       Private structures
26       ----------------------------------------------------------------------*/
27 
28 // Structure for checking flags
29     typedef struct DWCstAccFlag
30     {
31         u32         flags;
32         u32         reserved;
33         u32         reserved1;
34     }
35     DWCAccFlag;
36 
37 // Structure for storing LoginIDs
38     typedef struct DWCstAccLoginId
39     {
40         u32         id_data;
41         u32         userid_lo32;
42         u32         playerid;
43     }
44     DWCAccLoginId;
45 
46 // Structure for friend codes
47     typedef struct DWCstAccFriendKey
48     {
49         u32         id_data;
50         u32         friendkey_lo32;
51         u32         friendkey_hi32;
52     }
53     DWCAccFriendKey;
54 
55 // Structure for GS Profile IDs
56     typedef struct DWCstAccGsProfileId
57     {
58         u32         id_data;
59         int         id;
60         u32         reserved;
61     }
62     DWCAccGsProfileId;
63 
64 // 12-byte union for storing friend data
65     typedef union DWCstAccFriendData
66     {
67         DWCAccFlag          flags;
68         DWCAccLoginId       login_id;
69         DWCAccFriendKey     friend_key;
70         DWCAccGsProfileId   gs_profile_id;
71     } DWCAccFriendData;
72 
73 // 64-byte structure for storing data about this user
74     typedef struct DWCstAccUserData
75     {
76         int                 size;               // 4
77         DWCAccLoginId       pseudo;             // 12
78         DWCAccLoginId       authentic;          // 12
79         int                 gs_profile_id;      // 4
80         int                 flag;               // 4
81         u32                 gamecode;           // 4
82 
83         int                 reserved[5];        // 20
84         u32                 crc32;              // 4
85     }
86     DWCAccUserData;
87 
88     /* --------------------------------------------------------------------
89       Constant
90       ----------------------------------------------------------------------*/
91 #define DWC_ACC_USERDATA_BUFSIZE            64
92 
93 #define DWC_ACC_USERNAME_STRING_LENGTH      20
94 #define DWC_ACC_USERNAME_GSBRCD_OFFSET      9
95 #define DWC_ACC_USERNAME_STRING_BUFSIZE     (DWC_ACC_USERNAME_STRING_LENGTH + 1)
96 #define DWC_ACC_FRIENDKEY_STRING_LENGTH     12
97 #define DWC_ACC_FRIENDKEY_STRING_BUFSIZE    (DWC_ACC_FRIENDKEY_STRING_LENGTH + 1)
98 
99 #define DWC_ACC_FRIENDDATA_NODATA           0
100 #define DWC_ACC_FRIENDDATA_LOGIN_ID         1
101 #define DWC_ACC_FRIENDDATA_FRIEND_KEY       2
102 #define DWC_ACC_FRIENDDATA_GS_PROFILE_ID    3
103 
104     /* --------------------------------------------------------------------
105       Structure for storing user data
106       ----------------------------------------------------------------------*/
107 
108     /**
109      * Personal data for each player, including the player's Login ID and other information.
110      *
111      * Do not access this structure's members directly.
112      *
113      * See also:  DWCAccFriendData
114      */
115     typedef DWCAccUserData DWCUserData;
116 
117     /**
118      * This is a union for storing friend data.
119      *
120      * Do not access this union's members directly.
121      *
122      * See also:  DWCAccUserData
123      */
124     typedef DWCAccFriendData DWCFriendData;
125 
126 
127     /* --------------------------------------------------------------------
128       Constant Definitions
129       ----------------------------------------------------------------------*/
130 
131 //
132 // Since a description of the doxycomment constant is included in the description of the return value of DWC_GetFriendDataType, it is not given here.
133 //
134 //
135 #define DWC_FRIENDDATA_NODATA        DWC_ACC_FRIENDDATA_NODATA
136 #define DWC_FRIENDDATA_LOGIN_ID      DWC_ACC_FRIENDDATA_LOGIN_ID
137 #define DWC_FRIENDDATA_FRIEND_KEY    DWC_ACC_FRIENDDATA_FRIEND_KEY
138 #define DWC_FRIENDDATA_GS_PROFILE_ID DWC_ACC_FRIENDDATA_GS_PROFILE_ID
139 
140 
141 
142     /* --------------------------------------------------------------------
143       External definitions for functions
144       ----------------------------------------------------------------------*/
145 
146 // For creating and checking user data.
147     void    DWC_CreateUserData            ( DWCUserData* userdata );
148     BOOL    DWC_CheckUserData             ( const DWCUserData* userdata );
149     BOOL    DWC_CheckHasProfile           ( const DWCUserData* userdata );
150     BOOL    DWC_CheckValidConsole         ( const DWCUserData* userdata );
151     BOOL    DWC_CheckDirtyFlag            ( const DWCUserData* userdata );
152     void    DWC_ClearDirtyFlag            ( DWCUserData* userdata );
153 
154     BOOL    DWC_IsCompatibleUserData      ( const DWCUserData* userdata );
155 
156 // Friend relationships
157     u64     DWC_GetFriendKey              ( const DWCFriendData* frienddata );
158     u64     DWC_CreateFriendKey           ( const DWCUserData*   userdata );
159     u64     DWC_CreateFriendKeyLegacy     ( const DWCUserData*   userdata );
160     void    DWC_CreateExchangeToken       ( const DWCUserData*   userdata, DWCFriendData* token );
161     void    DWC_CreateFriendKeyToken      ( DWCFriendData* token,      u64 friend_key    );
162     void    DWC_SetGsProfileId            ( DWCFriendData* frienddata, int gs_profile_id );
163     BOOL    DWC_CheckFriendKey            ( const DWCUserData*   userdata, u64 friend_key );
164     BOOL    DWC_CheckFriendKeyLegacy      ( const DWCUserData*   userdata, u64 friend_key );
165     BOOL    DWC_IsEqualFriendData         ( const DWCFriendData* frienddata1, const DWCFriendData* frienddata2 );
166     BOOL    DWC_IsValidFriendData         ( const DWCFriendData* frienddata );
167     BOOL    DWC_IsBuddyFriendData         ( const DWCFriendData* frienddata );
168     int     DWC_GetFriendDataType         ( const DWCFriendData* frienddata );
169     void    DWC_ClearBuddyFlagFriendData  ( DWCFriendData*       frienddata );
170 
171 // Used to search for friends
172     int     DWC_GetGsProfileId            ( const DWCUserData* userdata, const DWCFriendData* frienddata );
173     void    DWC_LoginIdToUserName         ( const DWCUserData* userdata, const DWCFriendData* frienddata, char* username );
174 
175 // For debugging
176     void    DWC_ReportFriendData          ( const DWCUserData* userdata, const DWCFriendData* frienddata );
177     void    DWC_ReportUserData            ( const DWCUserData* userdata );
178 
179 
180 #ifdef __cplusplus
181 }
182 #endif // __cplusplus
183 
184 #endif // DWC_ACCOUNT_H_
185