DayZ 1.24
Loading...
Searching...
No Matches
OnlineServices.c
Go to the documentation of this file.
2{
9
12
13 protected static string m_InviteServerIP;
14 protected static int m_InviteServerPort;
15 protected static string m_CurrentServerIP;
16 protected static int m_CurrentServerPort;
18
19
23
24 protected static bool m_FirstFriendsLoad = true;
25 protected static bool m_MultiplayState = false;
27
28 protected static ref BiosUser m_BiosUser;
29
30 static void Init()
31 {
32#ifdef PLATFORM_CONSOLE
33#ifndef PLATFORM_WINDOWS // if app is not on Windows with -XBOX parameter
34 if (!m_TrialService)
36 if (!m_FriendsList)
38 if (!m_MuteList)
42
43 m_FriendsList.Clear();
44 m_PermissionsList.Clear();
45 m_MuteList.Clear();
46#endif
47#endif
48
50 }
51
52 static bool IsInitialized()
53 {
54 return (m_ClientServices != null);
55 }
56
57 static void GetClientServices()
58 {
59 BiosUserManager user_manager = GetGame().GetUserManager();
60 if (user_manager)
61 {
62 BiosUser selected_user = user_manager.GetSelectedUser();
63 if (selected_user)
64 m_ClientServices = selected_user.GetClientServices();
65#ifdef PLATFORM_WINDOWS
67 user_manager.GetUserList(user_list);
68 if (user_list.Count() > 0)
69 m_ClientServices = user_list.Get(0).GetClientServices();
70#endif
71 }
72 else
73 Error("BiosClientServices Error: Usermanager does not exist.");
74 }
75
77 {
78 switch (error)
79 {
80 case EBiosError.OK:
81 {
82 return false;
83 }
84 }
85
86 DebugPrint.LogErrorAndTrace(string.Format("BiosClientServices Error: %1", ErrorModuleHandler.GetClientMessage(ErrorCategory.BIOSError, error)));
87 return true;
88 }
89
91 {
94 m_ClientServices.GetLobbyService().GetServers(inputValues);
95 else
96 DebugPrint.LogErrorAndTrace("BiosClientServices Error: Service reference does not exist.");
97 }
98
100 {
101 m_ClientServices.GetLobbyService().GetFavoriteServers(favServers);
102 }
103
105 {
106 m_ClientServices.GetLobbyService().GetCachedFavoriteServerInfo(favServersInfoCache);
107 }
108
109 static void SetServerFavorited(string ipAddress, int port, int steamQueryPort, bool is_favorited)
110 {
113 {
114 if (is_favorited)
115 m_ClientServices.GetLobbyService().AddServerFavorite(ipAddress, port, steamQueryPort);
116 else
117 m_ClientServices.GetLobbyService().RemoveServerFavorite(ipAddress, port, steamQueryPort);
118 }
119 else
120 DebugPrint.LogErrorAndTrace("BiosClientServices Error: Service reference does not exist.");
121 }
122
123 static void GetCurrentServerInfo(string ip, int port)
124 {
126
129
131
132 inputValues.SetHostIp(ip);
133 inputValues.SetHostPort(port);
134 inputValues.m_Page = 0;
135 inputValues.m_RowsPerPage = 10;
136 inputValues.m_Platform = 1;
137
138#ifdef PLATFORM_XBOX
139 inputValues.m_Platform = 2;
140#endif
141#ifdef PLATFORM_PS4
142 inputValues.m_Platform = 3;
143#endif
144
146 m_ClientServices.GetLobbyService().GetServers(inputValues);
147 }
148
150 {
152 return m_CurrentServerInfo;
153 else
154 return g_Game.GetHostData();
155 }
156
158 {
162 }
163
164 static void SetInviteServerInfo(string ip, int port)
165 {
168 }
169
170 static void GetInviteServerInfo(out string ip, out int port)
171 {
174 }
175
177 {
178 if (!ErrorCaught(error))
179 {
180 if (m_CurrentServerIP != "" && m_CurrentServerPort > 0)
181 {
182 foreach (GetServersResultRow result : result_list.m_Results)
183 {
184 if (result.m_HostIp == m_CurrentServerIP && result.m_HostPort == m_CurrentServerPort)
185 {
189 }
190 }
191 }
192
193 // todo: remove
194 //foreach( GetServersResultRow res : result_list.m_Results )
195 //{
196 // Print("OnLoadServersAsync: result id: " + res.m_Id + "modded: " + res.m_Modded);
197 //}
198
199 // just for example execute the retrieving of extended info for the first server entry in the list
200 //if (result_list.m_Results.Count() > 0)
201 //{
202 //GetServersResultRow re = result_list.m_Results[0];
203 //EBiosError er = m_ClientServices.GetLobbyService().GetServerModList(re.m_Id);
204 //Print("OnLoadServersAsync GetServerModList returns:" + er);
205 //}
206
208 }
209 else
210 m_ServersAsyncInvoker.Invoke(null, error, "");
211 }
212
213
214 static void LoadFriends()
215 {
218 m_ClientServices.GetSocialService().GetFriendsAsync();
219 else
220 DebugPrint.LogErrorAndTrace("BiosClientServices Error: Service reference does not exist.");
221 }
222
223 static void ShowUserProfile(string uid)
224 {
227 m_ClientServices.GetSocialService().ShowUserProfileAsync(uid);
228 else
229 DebugPrint.LogErrorAndTrace("BiosClientServices Error: Service reference does not exist.");
230 }
231
233 {
235 }
236
238 {
239 if (!ErrorCaught(error))
240 {
242
244 for (int i = 0; i < friend_list.Count(); ++i)
245 {
246 string uid = friend_list[i].m_Uid;
249
250 if (storedBfi)
251 {
253 friends_simple.Insert(newBfi.m_Uid);
255 }
256 else
257 {
258 m_FriendsList.Insert(uid, newBfi);
259 friends_simple.Insert(newBfi.m_Uid);
260 }
261 }
262
264 {
265 if (ClientData.m_LastNewPlayers && ClientData.m_LastNewPlayers.m_PlayerList.Count() > 0)
266 {
267 foreach (SyncPlayer player : ClientData.m_LastNewPlayers.m_PlayerList)
268 {
269 if (m_FriendsList.Contains(player.m_UID))
270 NotificationSystem.AddNotification(NotificationType.FRIEND_CONNECTED, NotificationSystem.DEFAULT_TIME_DISPLAYED, player.m_PlayerName + " " + "#ps4_invite_has_joined_your_session");
271 }
272 ClientData.m_LastNewPlayers.m_PlayerList.Clear();
273 }
274 }
275 m_FirstFriendsLoad = false;
276 }
277 }
278
280 {
283 {
285 perms.Insert(EBiosPrivacyPermission.COMMUNICATE_VOICE);
286
287 ErrorCaught(m_ClientServices.GetPrivacyService().GetPermissionsAsync(player_list, perms));
288 }
289 else
290 DebugPrint.LogErrorAndTrace("BiosClientServices Error: Service reference does not exist.");
291 }
292
294 {
295 if (!ErrorCaught(error))
296 {
298
299 for (int i = 0; i < result_list.Count(); i++)
300 {
302 string uid = result.m_Uid;
306 {
308 {
309 new_list.Insert(result);
311 }
312 }
313 else
314 {
316 new_list.Insert(result);
317 }
318 }
320 }
321 }
322
323 static bool IsPlayerMuted(string id)
324 {
325 if (m_MuteList.Contains(id))
326 return m_MuteList.Get(id);
327 return false;
328 }
329
330 static bool MutePlayer(string id, bool mute)
331 {
332 if (m_MuteList.Contains(id))
333 m_MuteList.Set(id, mute);
334 else
335 m_MuteList.Insert(id, mute);
336
337 // notify server
340 ctx.Write(id);
341 ctx.Write(mute);
342 ctx.Send();
343
344 return true;
345 }
346
348 {
349 return m_MuteList;
350 }
351
352 static void ShowInviteScreen()
353 {
354#ifdef PLATFORM_CONSOLE
357 {
358 string addr;
359 int port;
360 if (GetGame().GetHostAddress(addr, port))
361 ErrorCaught(m_ClientServices.GetSessionService().ShowInviteToGameplaySessionAsync(addr, port));
362 }
363 else
364 DebugPrint.LogErrorAndTrace("BiosClientServices Error: Service reference does not exist.");
365#endif
366 }
367
368 static void LoadMPPrivilege()
369 {
370#ifdef PLATFORM_CONSOLE
373 ErrorCaught(m_ClientServices.GetPrivacyService().GetPrivilegeAsync(EBiosPrivacyPrivilege.MULTIPLAYER_GAMEPLAY, true));
374 else
375 DebugPrint.LogErrorAndTrace("BiosClientServices Error: Service reference does not exist.");
376#else
378#endif
379 }
380
381 static void LoadVoicePrivilege()
382 {
385 ErrorCaught(m_ClientServices.GetPrivacyService().GetPrivilegeAsync(EBiosPrivacyPrivilege.COMMUNICATE_VOICE, true));
386 else
387 DebugPrint.LogErrorAndTrace("BiosClientServices Error: Service reference does not exist.");
388 }
389
391 {
392 if (!ErrorCaught(err))
393 g_Game.TryConnect();
394 else
395 {
396 if (g_Game.GetGameState() != DayZGameState.MAIN_MENU)
397 g_Game.MainMenuLaunch();
398 else
399 {
400 g_Game.SetLoadState(DayZLoadState.MAIN_MENU_START);
401 g_Game.GamepadCheck();
402 }
403 }
404 }
405
407 {
408 if (g_Game.GetGameState() == DayZGameState.IN_GAME)
409 {
410#ifdef PLATFORM_PS4
411 GetGame().GetWorld().DisableReceiveVoN(ErrorCaught(err));
412#endif
413 GetGame().GetWorld().DisableTransmitVoN(ErrorCaught(err));
414 }
415 }
416
417 static void SetSessionHandle(string handle)
418 {
421 m_ClientServices.GetSessionService().m_CurrentHandle = handle;
422 }
423
424 static string GetSessionHandle()
425 {
428 return m_ClientServices.GetSessionService().m_CurrentHandle;
429 return "";
430 }
431
432 static void GetSession()
433 {
436 m_ClientServices.GetSessionService().TryGetSession(GetSessionHandle());
437 }
438
440 {
441 return m_BiosUser;
442 }
443
445 {
447 }
448
449
450 static bool GetMultiplayState()
451 {
452 return m_MultiplayState;
453 }
454
455 static void SetMultiplayState(bool state)
456 {
458 bool is_multiplay;
461
463 m_ClientServices.GetSessionService().SetMultiplayState(is_multiplay);
464 }
465
467 {
468 string addr;
469 int port;
470 if (GetGame().GetHostAddress(addr, port))
471 {
474 {
475 m_ClientServices.GetSessionService().EnterGameplaySessionAsync(addr, port);
476 SetMultiplayState(true);
477 }
478 }
479 }
480
482 {
485 {
487
489 m_ClientServices.GetSessionService().LeaveGameplaySessionAsync(currentServerInfo.m_HostIp, currentServerInfo.m_HostPort);
490 else if (m_CurrentServerIP != "")
491 m_ClientServices.GetSessionService().LeaveGameplaySessionAsync(m_CurrentServerIP, m_CurrentServerPort);
492
493 SetMultiplayState(false);
494 m_FirstFriendsLoad = true;
495
496 if (m_FriendsList)
497 m_FriendsList.Clear();
498 }
499 }
500
502 {
503 string addr;
504 int port;
505 if (GetGame().GetHostAddress(addr, port))
506 {
509 m_ClientServices.GetSessionService().SetGameplayActivityAsync(addr, port);
510 }
511 }
512
514 {
515 string addr;
516 int port;
517 if (GetGame().GetHostAddress(addr, port))
518 {
521 {
523 m_ClientServices.GetSessionService().InviteToGameplaySessionAsync(addr, port, GetPendingInviteList());
524 }
525 }
526 else
528 }
529
531 {
534 {
536 foreach (string invitee : m_PendingInvites)
537 {
538 if (already_on_server.Find(invitee) == -1)
539 new_to_server.Insert(invitee);
540 }
541 return new_to_server;
542 }
543 else
544 return m_PendingInvites;
545 }
546
548 {
549 delete m_PendingInvites;
550 }
551
552 static int m_AutoConnectTries = 0;
554 {
557 {
560 input.SetOfficial(true);
561 m_ClientServices.GetLobbyService().GetFirstServerWithEmptySlot(input);
562 }
563 }
564
566 {
569
570 if (results && results.m_Result && results.m_Result.m_Results && results.m_Result.m_Results.Count() > 0)
571 {
572 foreach (GetServersResultRow result_temp : results.m_Result.m_Results)
573 {
574 if (result_temp.m_FreeSlots > 0)
576 }
577 }
578
579 return results_free.GetRandomElement();
580 }
581
583 {
584 if (!ErrorCaught(error))
585 {
587 if (result)
588 {
589 g_Game.ConnectFromServerBrowser(result.m_HostIp, result.m_HostPort);
591 return;
592 }
593 else
594 GetGame().GetUIManager().ShowDialog("#str_xbox_authentification_fail_title", "#str_xbox_authentification_fail", 232, DBT_OK, DBB_NONE, DMT_INFO, GetGame().GetUIManager().GetMenu());
595 }
596
597 if (m_AutoConnectTries < 3)
598 {
601 input.SetOfficial(true);
602 m_ClientServices.GetLobbyService().GetFirstServerWithEmptySlot(input);
603 }
604 else
605 GetGame().GetUIManager().ShowDialog("#str_xbox_authentification_fail_title", "#xbox_authentification_fail", 232, DBT_OK, DBB_NONE, DMT_INFO, GetGame().GetUIManager().GetMenu());
606 }
607
608 static void GetServerModList(string server_id)
609 {
612 m_ClientServices.GetLobbyService().GetServerModList(server_id);
613 }
614
620
621 static bool IsGameTrial(bool sim)
622 {
623#ifdef PLATFORM_XBOX
624#ifndef PLATFORM_WINDOWS
625 if (m_TrialService)
626 return m_TrialService.IsGameTrial(sim);
627#endif
628#endif
629 return false;
630 }
631
632 static bool IsGameActive(bool sim)
633 {
634#ifdef PLATFORM_XBOX
635#ifndef PLATFORM_WINDOWS
636 if (m_TrialService)
637 return m_TrialService.IsGameActive(sim);
638#endif
639#endif
640 return false;
641 }
642
643 static bool CheckUpdate()
644 {
647 {
648 EBiosError error = m_ClientServices.GetPackageService().CheckUpdateAsync();
649
650 if (!error)
651 return true;
652 }
653
654 return false;
655 }
656
657 static void PromptUpdate()
658 {
661 m_ClientServices.GetPackageService().PromptUpdateAsync();
662 }
663}
const int INPUT_UDT_USER_MUTE_XBOX
Definition _constants.c:13
EBiosError
Possible Error codes for bios API. This is the list of errors that can be returned from bios API....
array< ref BiosPrivacyUidResult > BiosPrivacyUidResultArray
EBiosPrivacyPermission
EBiosPrivacyPermission represents possible privacy permissions.
EBiosPrivacyPrivilege
EBiosPrivacyPrivilege represents possible privacy privileges.
DayZGame g_Game
Definition DayZGame.c:3528
ErrorCategory
ErrorCategory - To decide what ErrorHandlerModule needs to be called and easily identify where it cam...
NotificationType
DEPRECATED (moved into NotificationSystem)
BiosClientServices class provides individual online services.
BiosFriendInfo represents friend information.
static bool Compare(BiosFriendInfo a, BiosFriendInfo b)
BiosPrivacyPermissionResult represents the per permission result of the GetPermissionsAsync reqeust.
static bool Compare(BiosPrivacyPermissionResult a, BiosPrivacyPermissionResult b)
BiosPrivacyUidResult represents the per user result of the GetPermissionsAsync request.
static array< string > GetSimplePlayerList()
Definition ClientData.c:84
static ref SyncPlayerList m_LastNewPlayers
Definition ClientData.c:9
static void LogErrorAndTrace(string msg)
Prints debug message as error message and prints stack trace of calls.
Definition DebugPrint.c:124
The error handler itself, for managing and distributing errors to modules Manages the ErrorHandlerMod...
static proto string GetClientMessage(ErrorCategory category, int code, string additionalInfo="")
Gets the Client Message for specified error.
GetServersInput the input structure of the GetServers operation.
GetServersInput the input structure of the GetServers operation.
GetServersResult the output structure of the GetServers operation.
static void AddNotification(NotificationType type, float show_time, string detail_text="")
Send notification from default types to local player.
static ref ScriptInvoker m_PermissionsAsyncInvoker
static void GetClientServices()
static void PromptUpdate()
static void OnUserProfileAsync(EBiosError error)
static void OnLoadServersAsync(GetServersResult result_list, EBiosError error, string response)
static bool IsPlayerMuted(string id)
static void LoadVoicePrivilege()
static void SetSessionHandle(string handle)
static void LeaveGameplaySession()
static void OnPermissionsAsync(BiosPrivacyUidResultArray result_list, EBiosError error)
static string m_InviteServerIP
static void OnGetServerModList(GetServerModListResult result_list, EBiosError error)
static ref ScriptInvoker m_ServersAsyncInvoker
static ref GetServersResultRow m_CurrentServerInfo
static void SetPendingInviteList(array< string > invitees)
static bool GetMultiplayState()
static void AutoConnectToEmptyServer()
static void ShowInviteScreen()
static void LoadFriends()
static bool IsGameActive(bool sim)
static void ShowUserProfile(string uid)
static void GetServerModList(string server_id)
static GetServersResultRow GetCurrentServerInfo()
static int m_InviteServerPort
static void GetSession()
static BiosUser GetBiosUser()
static ref ScriptInvoker m_ServerAsyncInvoker
static ref ScriptInvoker m_MuteUpdateAsyncInvoker
static int m_AutoConnectTries
static bool CheckUpdate()
static ref ScriptInvoker m_ServerModLoadAsyncInvoker
static void SetServerFavorited(string ipAddress, int port, int steamQueryPort, bool is_favorited)
static void GetCurrentServerInfo(string ip, int port)
static string GetSessionHandle()
static bool IsGameTrial(bool sim)
static void SetBiosUser(BiosUser user)
static ref TrialService m_TrialService
static ref map< string, ref BiosPrivacyPermissionResultArray > m_PermissionsList
static ref map< string, bool > m_MuteList
static GetServersResultRow GetRandomFreeResult(GetFirstServerWithEmptySlotResult results)
static ref BiosClientServices m_ClientServices
static void LoadPermissions(array< string > player_list)
static bool IsInitialized()
static void LoadServers(notnull GetServersInput inputValues)
static string m_CurrentServerIP
static map< string, bool > GetMuteList()
static array< string > GetPendingInviteList()
static void EnterGameplaySession()
static ref ScriptInvoker m_FriendsAsyncInvoker
static ref array< string > m_PendingInvites
static ref map< string, ref BiosFriendInfo > m_FriendsList
static bool m_MultiplayState
static int m_CurrentServerPort
static bool ErrorCaught(EBiosError error)
static void OnLoadVoicePrivilege(EBiosError err)
static void ClearPendingInviteList(array< string > invitees)
static void SetMultiplayState(bool state)
static bool m_FirstFriendsLoad
static void LoadMPPrivilege()
static void Init()
static void OnAutoConnectToEmptyServer(GetFirstServerWithEmptySlotResult result_list, EBiosError error)
static void GetInviteServerInfo(out string ip, out int port)
static void SetGameplayActivity()
static bool MutePlayer(string id, bool mute)
static void OnFriendsAsync(BiosFriendInfoArray friend_list, EBiosError error)
static void OnLoadMPPrivilege(EBiosError err)
static void GetFavoriteServers(TStringArray favServers)
static ref BiosUser m_BiosUser
static void ClearCurrentServerInfo()
static void GetCachedFavServerInfo(array< ref CachedServerInfo > favServersInfoCache)
static void SetInviteServerInfo(string ip, int port)
ScriptInvoker Class provide list of callbacks usage:
Definition tools.c:116
TrialService is used to query if the game is trial version or not.
Definition TrialService.c:4
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90