2727#ifndef _STEAM_WRAP_H
2828#define _STEAM_WRAP_H
2929
30+ // -----------------------------------------------------------------------------
31+ // INCLUDES
32+ // -----------------------------------------------------------------------------
33+ #include " strtools.h"
34+
35+
3036// -----------------------------------------------------------------------------
3137// CLASSES
3238// -----------------------------------------------------------------------------
@@ -44,7 +50,7 @@ class CSteamIDExt
4450
4551 // Try SteamID2
4652 if (sscanf (input, " STEAM_%u:%u:%u" , &universe, &auth_server, &account_id) == 3 ) {
47- account_id = account_id * 2 | auth_server;
53+ account_id = account_id << 1 | auth_server;
4854
4955 // Some games represent the public universe as 0, others as 1
5056 if (universe == 0 )
@@ -141,6 +147,83 @@ class CSteamIDExt
141147 }
142148 return true ;
143149 }
150+
151+ static str ToSteamID2 (CSteamID* pSteamID)
152+ {
153+ char buffer[32 ];
154+ uint32 account_id = pSteamID->GetAccountID ();
155+ V_snprintf (buffer, 32 , " STEAM_%u:%u:%u" , pSteamID->GetEUniverse (), account_id & 1 , account_id >> 1 );
156+ return str (buffer);
157+ }
158+
159+ static bool AccountTypeToIdentifier (EAccountType account_type, EChatSteamIDInstanceFlags account_instance_flags, char & identifier)
160+ {
161+ if (account_type == k_EAccountTypeChat)
162+ {
163+ if (account_instance_flags == k_EChatInstanceFlagClan) {
164+ identifier = ' c' ;
165+ }
166+ else if (account_instance_flags == k_EChatInstanceFlagLobby) {
167+ identifier = ' L' ;
168+ }
169+ else {
170+ return false ;
171+ }
172+ }
173+
174+ switch (account_type)
175+ {
176+ case k_EAccountTypeInvalid:
177+ identifier = ' I' ;
178+ break ;
179+ case k_EAccountTypeIndividual:
180+ identifier = ' U' ;
181+ break ;
182+ case k_EAccountTypeMultiseat:
183+ identifier = ' M' ;
184+ break ;
185+ case k_EAccountTypeGameServer:
186+ identifier = ' G' ;
187+ break ;
188+ case k_EAccountTypeAnonGameServer:
189+ identifier = ' A' ;
190+ break ;
191+ case k_EAccountTypePending:
192+ identifier = ' P' ;
193+ break ;
194+ case k_EAccountTypeContentServer:
195+ identifier = ' C' ;
196+ break ;
197+ case k_EAccountTypeClan:
198+ identifier = ' g' ;
199+ break ;
200+ case k_EAccountTypeChat:
201+ identifier = ' T' ;
202+ break ;
203+ case 10 :
204+ identifier = ' a' ;
205+ break ;
206+ default :
207+ return false ;
208+ }
209+ return true ;
210+ }
211+
212+ static str ToSteamID3 (CSteamID* pSteamID)
213+ {
214+ char buffer[32 ];
215+
216+ char account_type_identifier;
217+ if (!AccountTypeToIdentifier (pSteamID->GetEAccountType (), (EChatSteamIDInstanceFlags) pSteamID->GetUnAccountInstance (), account_type_identifier))
218+ BOOST_RAISE_EXCEPTION (PyExc_ValueError, " Invalid account type '%u'." , pSteamID->GetEAccountType ())
219+
220+ if (pSteamID->GetUnAccountInstance () == 1 )
221+ V_snprintf (buffer, 32 , " [%c:%u:%u]" , account_type_identifier, pSteamID->GetEUniverse (), pSteamID->GetAccountID ());
222+ else
223+ V_snprintf (buffer, 32 , " [%c:%u:%u:%u]" , account_type_identifier, pSteamID->GetEUniverse (), pSteamID->GetAccountID (), pSteamID->GetUnAccountInstance ());
224+
225+ return str (buffer);
226+ }
144227};
145228
146229#endif // _STEAM_WRAP_H
0 commit comments