biosusermanager.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. enum EBiosJoinType
  2. {
  3. INVITE,
  4. ACTIVITY,
  5. };
  6. class BiosUser
  7. {
  8. proto native owned string GetName();
  9. proto native owned string GetUid();
  10. proto native BiosClientServices GetClientServices();
  11. proto native bool IsOnline();
  12. };
  13. class BiosUserManager
  14. {
  15. //! Gets the initiatior of the title
  16. /*!
  17. @return BiosUser the initiator. May be NULL.
  18. */
  19. proto native BiosUser GetTitleInitiator();
  20. //! Gets the currently present list of users
  21. /*!
  22. Fills in the array.
  23. Expected errors:
  24. BAD_PARAMETER - user_list is NULL,
  25. @return EBiosError indicating if the operation is done.
  26. */
  27. proto native EBiosError GetUserList(array<ref BiosUser> user_list);
  28. //! Display a system dependant ui for log-on
  29. proto native EBiosError LogOnUserAsync(BiosUser user);
  30. //! Display a system dependant account picket
  31. /*!
  32. Xbox: The async result is returned in the OnUserPicked callback.
  33. @return EBiosError indicating if the async operation is pending.
  34. */
  35. proto native EBiosError PickUserAsync();
  36. //! Parse the join data from from command line parameters.
  37. /*!
  38. The async result is returned in the OnJoin callback.
  39. The OnJoin callback is called also during runtime when a join is accepted.
  40. Expected errors:
  41. BAD_PARAMETER - join_data could not be parsed,
  42. @param join_data the startup join data from command line parameters.
  43. @return EBiosError indicating if the async operation is pending.
  44. */
  45. proto native EBiosError ParseJoinAsync(string join_data);
  46. //! Parse the party data from from command line parameters.
  47. /*!
  48. The async result is returned in the OnPartyHost callback.
  49. The OnPartyHost callback is called also during runtime when a player hosts a game for the party.
  50. Expected errors:
  51. BAD_PARAMETER - join_data could not be parsed,
  52. @param party_data the startup party data from command line parameters.
  53. @return EBiosError indicating if the async operation is pending.
  54. */
  55. proto native EBiosError ParsePartyAsync(string party_data);
  56. //! Informs the engine about the current selected user.
  57. /*!
  58. Must be called to ensure proper authentication etc.
  59. @param user the user to select.
  60. */
  61. proto native bool SelectUser(BiosUser user);
  62. //! Returns the currently selected user.
  63. /*!
  64. @return BiosUser the selected user. May be NULL.
  65. */
  66. proto native BiosUser GetSelectedUser();
  67. //! Call async function to get database ID
  68. /*!
  69. @return EBiosError indicating if the async operation is pending. If active user is not set, then return NOT_FOUND
  70. */
  71. proto native EBiosError GetUserDatabaseIdAsync();
  72. bool SelectUserEx(BiosUser user)
  73. {
  74. bool success = false;
  75. BiosUser selectedUser = GetSelectedUser();
  76. if (selectedUser && selectedUser != user && g_Game.GetGameState() != DayZGameState.MAIN_MENU)
  77. {
  78. success = SelectUser(user);
  79. g_Game.DisconnectSessionEx(DISCONNECT_SESSION_FLAGS_FORCE & ~DisconnectSessionFlags.SELECT_USER);
  80. }
  81. else
  82. success = SelectUser(user);
  83. if (!success)
  84. {
  85. NotificationSystem.AddNotification(NotificationType.GENERIC_ERROR, NotificationSystem.DEFAULT_TIME_DISPLAYED);
  86. }
  87. return success;
  88. }
  89. //! Callback function.
  90. /*!
  91. @param dbID user database ID. If something went wrong, then it is empty string.
  92. @param error indicating correct state.
  93. */
  94. void OnUserDatabaseId(string dbID, EBiosError error)
  95. {
  96. if ( !OnlineServices.ErrorCaught( error ) )
  97. {
  98. g_Game.SetDatabaseID( dbID );
  99. }
  100. }
  101. //! Callback function.
  102. /*!
  103. @param error error indicating success or fail of the async operation.
  104. */
  105. void OnUserLoggedOn(EBiosError error)
  106. {
  107. if ( OnlineServices.ErrorCaught( error ) )
  108. {
  109. GetGame().GetInput().ResetActiveGamepad();
  110. g_Game.DisconnectSessionEx(DISCONNECT_SESSION_FLAGS_FORCE);
  111. }
  112. }
  113. //! Callback function.
  114. /*!
  115. @param user picked user. NULL on fail.
  116. @param error error indicating success or fail of the async operation.
  117. */
  118. void OnUserPicked(BiosUser user, EBiosError error)
  119. {
  120. if ( !user )
  121. {
  122. GetGame().GetInput().ResetActiveGamepad();
  123. g_Game.GamepadCheck();
  124. }
  125. else if ( !OnlineServices.ErrorCaught( error ) )
  126. {
  127. if (SelectUserEx( user ))
  128. {
  129. if ( GetGame().GetMission() )
  130. GetGame().GetMission().Reset();
  131. OnGameNameChanged( user );
  132. g_Game.SelectUser(GetGame().GetInput().GetUserGamepad(user));
  133. }
  134. }
  135. }
  136. //! Callback function.
  137. void OnLoggedOn(BiosUser user)
  138. {
  139. if ( user && GetSelectedUser() == user )
  140. g_Game.SelectUser(GetGame().GetInput().GetUserGamepad(user));
  141. }
  142. //! Callback function.
  143. void OnLoggedOff(BiosUser user)
  144. {
  145. OnSignedOut( user );
  146. }
  147. //! Callback function.
  148. /*!
  149. Called when a new user signed in
  150. @param user the user that signed in. Cannot be NULL.
  151. */
  152. void OnSignedIn(BiosUser user)
  153. {
  154. }
  155. //! Callback function.
  156. /*!
  157. Called when a new user signed out
  158. @param user the user that signed out. Cannot be NULL.
  159. */
  160. void OnSignedOut(BiosUser user)
  161. {
  162. if ( user == GetSelectedUser() )
  163. {
  164. SelectUserEx( null );
  165. GetGame().GetInput().ResetActiveGamepad();
  166. g_Game.DisconnectSessionEx(DISCONNECT_SESSION_FLAGS_FORCE & ~DisconnectSessionFlags.SELECT_USER);
  167. }
  168. }
  169. //! Callback function.
  170. /*!
  171. Called when a join is parsed or when a runtime join is accepted from the system UI.
  172. @param type the type of join. Undefined on error.
  173. @param joiner the user that is joining. NULL on error.
  174. @param handle join handle for a session. Empty on error.
  175. @param joinee uid of the user that is being joined. Empty on error.
  176. @param error indicating if parsing failed. OK if not a result of ParseJoinAsync.
  177. */
  178. void OnJoin(EBiosJoinType type, BiosUser joiner, string handle, string joinee, EBiosError error)
  179. {
  180. if ( !OnlineServices.ErrorCaught( error ) )
  181. {
  182. OnlineServices.SetBiosUser( joiner );
  183. SelectUserEx( joiner );
  184. OnlineServices.SetSessionHandle( handle );
  185. if ( g_Game.GetGameState() == DayZGameState.IN_GAME )
  186. {
  187. g_Game.SetLoadState( DayZLoadState.JOIN_START );
  188. OnlineServices.GetSession();
  189. }
  190. else
  191. {
  192. if ( GetGame().GetUIManager() && GetGame().GetInput().IsActiveGamepadSelected() )
  193. {
  194. GetGame().GetUIManager().CloseMenu( MENU_TITLE_SCREEN );
  195. GetGame().GetInput().IdentifyGamepad( GamepadButton.BUTTON_NONE );
  196. }
  197. g_Game.SetLoadState( DayZLoadState.JOIN_START );
  198. g_Game.GamepadCheck();
  199. }
  200. }
  201. else
  202. {
  203. g_Game.DisconnectSessionEx(DISCONNECT_SESSION_FLAGS_JOIN);
  204. }
  205. }
  206. //! Callback function.
  207. /*!
  208. Called when a party is parsed or when a party is hosted from the system UI.
  209. @param host the user that is hosting the party. NULL on error.
  210. @param invitee_list list of party members.
  211. @param error indicating if parsing failed. OK if not a result of ParsePartyAsync.
  212. */
  213. void OnPartyHost(BiosUser host, array<string> invitee_list, EBiosError error)
  214. {
  215. #ifdef PLATFORM_PS4
  216. if (host)
  217. #endif
  218. {
  219. SelectUserEx(host);
  220. #ifdef PLATFORM_PS4
  221. if (!host.IsOnline())
  222. {
  223. LogOnUserAsync( host );
  224. }
  225. #endif
  226. }
  227. if (GetGame().GetUIManager())
  228. {
  229. GetGame().GetUIManager().CloseMenu(MENU_TITLE_SCREEN);
  230. }
  231. OnlineServices.SetPendingInviteList( invitee_list );
  232. if (g_Game.GetGameState() != DayZGameState.IN_GAME && g_Game.GetGameState() != DayZGameState.CONNECTING)
  233. {
  234. if (!GetGame().GetUIManager().GetMenu() || GetGame().GetUIManager().GetMenu().GetID() != MENU_MAIN)
  235. {
  236. GetGame().GetUIManager().EnterScriptedMenu(MENU_MAIN, GetGame().GetUIManager().GetMenu());
  237. }
  238. g_Game.SetGameState( DayZGameState.PARTY );
  239. g_Game.SetLoadState( DayZLoadState.PARTY_START );
  240. g_Game.GamepadCheck();
  241. }
  242. }
  243. //! Callback function.
  244. /*!
  245. Called when display info of a signed in user changed.
  246. @param user the user affected by the change.
  247. */
  248. void OnGameNameChanged(BiosUser user)
  249. {
  250. if ( user == GetSelectedUser() )
  251. {
  252. g_Game.SetPlayerName( user.GetName() );
  253. #ifdef PLATFORM_CONSOLE
  254. g_Game.SetPlayerGameName( user.GetName() );
  255. #endif
  256. if ( GetGame().GetUIManager().GetMenu() )
  257. {
  258. GetGame().GetUIManager().GetMenu().Refresh();
  259. }
  260. }
  261. }
  262. BiosUser GetUser( string user_id )
  263. {
  264. array<ref BiosUser> user_list = new array<ref BiosUser>;
  265. GetUserList( user_list );
  266. foreach ( BiosUser user : user_list )
  267. {
  268. if ( user.GetUid() == user_id )
  269. {
  270. return user;
  271. }
  272. }
  273. return null;
  274. }
  275. };