biossessionservice.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. class BiosSessionService
  2. {
  3. protected int m_GetSessionAttempts;
  4. string m_CurrentHandle;
  5. //! Enter a gameplay session
  6. /*!
  7. The async result is returned in the OnEnterGameplaySession callback.
  8. Expected errors:
  9. LOGICAL - if the user is currently in an active gameplay session.
  10. @param session_address server IP address.
  11. @param session_port server port.
  12. @return EBiosError indicating if the async operation is pending.
  13. */
  14. proto native EBiosError EnterGameplaySessionAsync(string session_address, int session_port);
  15. //! Leave a gameplay session
  16. /*!
  17. The async result is returned in the OnLeaveGameplaySession callback.
  18. If there is an unexpected error the state is cleared.
  19. Expected errors:
  20. ERR_NOT_FOUND - when attempting to leave a gameplay session the user is not part of.
  21. ERR_LOGICAL - when the user is not in a gameplay session.
  22. @param session_address server IP address.
  23. @param session_port server port.
  24. @return EBiosError indicating if the async operation is pending.
  25. */
  26. proto native EBiosError LeaveGameplaySessionAsync(string session_address, int session_port);
  27. //! Alerts engine that players in current session have changed
  28. /*!
  29. @param newPlayers players that have just joined the server. When player joins a server, ALL players already on server count as new players.
  30. */
  31. proto native void OnSessionPlayerListUpdate(array<string> newPlayers);
  32. //! Gets a session from a join handle
  33. /*!
  34. The async result is returned in the OnGetGameplaySession, OnGetLobbySession or OnGetSessionError callback,
  35. dependinng on the type of session, or error.
  36. Expected errors:
  37. @param join_handle the parsed join handle.
  38. @return EBiosError indicating if the async operation is pending.
  39. */
  40. void TryGetSession( string join_handle = "" )
  41. {
  42. if ( join_handle != "" )
  43. {
  44. m_GetSessionAttempts = 0;
  45. m_CurrentHandle = join_handle;
  46. }
  47. if ( m_GetSessionAttempts < 10 )
  48. GetSessionAsync( m_CurrentHandle );
  49. else
  50. g_Game.DisconnectSessionEx(DISCONNECT_SESSION_FLAGS_JOIN);
  51. }
  52. //! Gets a session from a join handle
  53. /*!
  54. The async result is returned in the OnGetGameplaySession, OnGetLobbySession or OnGetSessionError callback,
  55. dependinng on the type of session, or error.
  56. Expected errors:
  57. @param join_handle the parsed join handle.
  58. @return EBiosError indicating if the async operation is pending.
  59. */
  60. proto native EBiosError GetSessionAsync(string join_handle);
  61. //! Sets the activity to a gameplay session
  62. /*!
  63. The async result is returned in the OnSetActivity callback.
  64. Expected errors:
  65. ERR_NOT_FOUND - when attempting to set a gameplay session activity the user is not part of.
  66. @param session_address server IP address.
  67. @param session_port server port.
  68. @return EBiosError indicating if the async operation is pending.
  69. */
  70. proto native EBiosError SetGameplayActivityAsync(string session_address, int session_port);
  71. //! not implemented
  72. //proto native EBiosError SetLobbyActivityAsync(...);
  73. //! Clears the current activity
  74. /*!
  75. The async result is returned in the OnClearActivity callback.
  76. Expected errors:
  77. @return EBiosError indicating if the async operation is pending.
  78. */
  79. proto native EBiosError ClearActivityAsync();
  80. //! Show system UI to invite friends to current gameplay session
  81. /*!
  82. The async result is returned in the OnShowInviteToGameplaySession callback.
  83. On Xbox, if session with session_address and session_port does not exist, then xbox show
  84. message "We could not send the invite".
  85. @param session_address server IP address.
  86. @param session_port server port.
  87. @return EBiosError indicating if the async operation is pending.
  88. */
  89. proto native EBiosError ShowInviteToGameplaySessionAsync(string session_address, int session_port);
  90. //! Send invite to list of users
  91. /*!
  92. The async result is returned in the OnInviteToGameplaySession callback.
  93. The user must be inside the session. That means, OnEnterGameplaySession must be called with no errors.
  94. @param session_address server IP address.
  95. @param session_port server port.
  96. @param invitee_list list of users to invite
  97. @return EBiosError indicating if the async operation is pending.
  98. */
  99. proto native EBiosError InviteToGameplaySessionAsync(string session_address, int session_port, array<string> invitee_list);
  100. //! Notifiy about interactive multiplayer state
  101. proto native void SetMultiplayState(bool is_active);
  102. //! Callback function
  103. /*!
  104. @param error error indicating success or fail of the async operation.
  105. */
  106. void OnSetActivity(EBiosError error)
  107. {
  108. OnlineServices.ErrorCaught( error );
  109. }
  110. //! Callback function
  111. /*!
  112. @param error error indicating success or fail of the async operation.
  113. */
  114. void OnClearActivity(EBiosError error)
  115. {
  116. }
  117. //! Callback function
  118. /*!
  119. @param session_address server IP address.
  120. @param session_port server port.
  121. */
  122. void OnGetGameplaySession(string session_address, int session_port)
  123. {
  124. m_GetSessionAttempts = 0;
  125. switch (g_Game.GetGameState())
  126. {
  127. case DayZGameState.IN_GAME:
  128. {
  129. string addr;
  130. int port;
  131. bool found = GetGame().GetHostAddress( addr, port );
  132. if (addr != session_address || port != session_port )
  133. {
  134. if (found)
  135. {
  136. OnlineServices.SetInviteServerInfo( session_address, session_port );
  137. g_Game.GetUIManager().CloseAll();
  138. if (!g_Game.GetUIManager().EnterScriptedMenu( MENU_INVITE_TIMER, null ))
  139. {
  140. NotificationSystem.AddNotification( NotificationType.CONNECT_FAIL_GENERIC, NotificationSystem.DEFAULT_TIME_DISPLAYED );
  141. }
  142. }
  143. else
  144. {
  145. NotificationSystem.AddNotification( NotificationType.JOIN_FAIL_GET_SESSION, NotificationSystem.DEFAULT_TIME_DISPLAYED );
  146. }
  147. }
  148. else
  149. {
  150. NotificationSystem.AddNotification( NotificationType.INVITE_FAIL_SAME_SERVER, NotificationSystem.DEFAULT_TIME_DISPLAYED, "#ps4_already_in_session" );
  151. }
  152. break;
  153. }
  154. case DayZGameState.CONNECTING:
  155. {
  156. g_Game.DisconnectSessionEx(DISCONNECT_SESSION_FLAGS_FORCE);
  157. // Intentionally no break, fall through to connecting
  158. }
  159. default:
  160. {
  161. g_Game.ConnectFromJoin( session_address, session_port );
  162. break;
  163. }
  164. }
  165. }
  166. //! //! Callback function, not implemented
  167. /*void OnGetLobbySession(...)
  168. {
  169. }*/
  170. //! Callback function
  171. /*!
  172. @param error error indicating fail of the async operation. Cannot be OK.
  173. */
  174. void OnGetSessionError(EBiosError error)
  175. {
  176. OnlineServices.ErrorCaught( error );
  177. m_GetSessionAttempts++;
  178. #ifdef PLATFORM_XBOX
  179. GetGame().GetCallQueue( CALL_CATEGORY_SYSTEM ).CallLater( TryGetSession, 100, false, "" );
  180. #endif
  181. #ifdef PLATFORM_PS4
  182. g_Game.DisconnectSessionEx(DISCONNECT_SESSION_FLAGS_JOIN);
  183. #endif
  184. }
  185. //! Callback function
  186. /*!
  187. @param session_address server IP address. Empty if failed.
  188. @param session_port server port. 0 if failed.
  189. @param error error indicating success or fail of the async operation.
  190. */
  191. void OnEnterGameplaySession(string session_address, int session_port, EBiosError error)
  192. {
  193. if ( !OnlineServices.ErrorCaught( error ) )
  194. {
  195. SetGameplayActivityAsync( session_address, session_port );
  196. if ( OnlineServices.GetPendingInviteList() )
  197. InviteToGameplaySessionAsync( session_address, session_port, OnlineServices.GetPendingInviteList() );
  198. //OnlineServices.GetCurrentServerInfo(session_address, session_port);
  199. }
  200. }
  201. //! Callback function
  202. /*!
  203. @param error error indicating success or fail of the async operation.
  204. */
  205. void OnLeaveGameplaySession(EBiosError error)
  206. {
  207. }
  208. //! Callback function
  209. /*!
  210. @param error indicating success or fail of the async operation.
  211. */
  212. void OnShowInviteToGameplaySession(EBiosError error)
  213. {
  214. OnlineServices.ErrorCaught( error );
  215. }
  216. //! Callback function
  217. /*!
  218. @param error indicating success or fail of the async operation.
  219. */
  220. void OnInviteToGameplaySession(EBiosError error)
  221. {
  222. }
  223. array<string> GetSessionPlayerList()
  224. {
  225. return ClientData.GetSimplePlayerList();
  226. }
  227. //! Native callback function to retrieve the session player list.
  228. /*!
  229. @param outPlayerList Output list of players in the session.
  230. */
  231. void GetSessionPlayerListEx(TStringArray outPlayerList)
  232. {
  233. TStringArray playerList = GetSessionPlayerList();
  234. outPlayerList.Copy(playerList);
  235. }
  236. };