File size: 18,469 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
class OnlineServices
{
	static ref ScriptInvoker												m_FriendsAsyncInvoker		= new ScriptInvoker();
	static ref ScriptInvoker												m_PermissionsAsyncInvoker	= new ScriptInvoker();
	static ref ScriptInvoker												m_ServersAsyncInvoker		= new ScriptInvoker();
	static ref ScriptInvoker												m_ServerAsyncInvoker		= new ScriptInvoker();
	static ref ScriptInvoker												m_MuteUpdateAsyncInvoker	= new ScriptInvoker(); // DEPRECATED
	static ref ScriptInvoker												m_ServerModLoadAsyncInvoker	= new ScriptInvoker();
	
	static ref BiosClientServices											m_ClientServices;
	static ref TrialService													m_TrialService;
	
	protected static string													m_InviteServerIP;
	protected static int													m_InviteServerPort;
	protected static string													m_CurrentServerIP;
	protected static int													m_CurrentServerPort;
	protected static ref GetServersResultRow								m_CurrentServerInfo;
	
	
	protected static ref map<string, ref BiosFriendInfo>					m_FriendsList;
	protected static ref map<string, bool>									m_MuteList;
	protected static ref map<string, ref BiosPrivacyPermissionResultArray>	m_PermissionsList;
	
	protected static bool													m_FirstFriendsLoad			= true;
	protected static bool													m_MultiplayState			= false;
	protected static ref array<string>										m_PendingInvites;

	protected static ref BiosUser											m_BiosUser;
	
	static void Init()
	{
		#ifdef PLATFORM_CONSOLE
			#ifndef PLATFORM_WINDOWS // if app is not on Windows with -XBOX parameter
			if ( !m_TrialService )
				m_TrialService = new TrialService;
			if ( !m_FriendsList )
				m_FriendsList = new map<string, ref BiosFriendInfo>;
			if ( !m_MuteList )
				m_MuteList = new map<string, bool>;
			if ( !m_PermissionsList )
				m_PermissionsList = new map<string, ref BiosPrivacyPermissionResultArray>;
			
			m_FriendsList.Clear();
			m_PermissionsList.Clear();
			m_MuteList.Clear();
			#endif
		#endif
		
		GetClientServices();
	}
	
	static bool IsInitialized()
	{
		return ( m_ClientServices != null );
	}
	
	static void GetClientServices()
	{
		BiosUserManager user_manager = GetGame().GetUserManager();
		if ( user_manager )
		{
			BiosUser selected_user = user_manager.GetSelectedUser();
			if ( selected_user )
			{
				m_ClientServices = selected_user.GetClientServices();
			}
			#ifdef PLATFORM_WINDOWS
				array<ref BiosUser> user_list = new array<ref BiosUser>;
				user_manager.GetUserList( user_list );
				if ( user_list.Count() > 0 )
				{
					m_ClientServices = user_list.Get( 0 ).GetClientServices();
				}
			#endif
		}
		else
		{
			Error( "BiosClientServices Error: Usermanager does not exist." );
		}
	}
	
	static bool ErrorCaught( EBiosError error )
	{
		switch ( error )
		{
			case EBiosError.OK:
			{
				return false;
			}
		}

		DebugPrint.LogErrorAndTrace( string.Format("BiosClientServices Error: %1", ErrorModuleHandler.GetClientMessage(ErrorCategory.BIOSError, error)) );
		return true;
	}
	
	static void LoadServers( notnull GetServersInput inputValues )
	{
		GetClientServices();
		if ( m_ClientServices )
		{
			m_ClientServices.GetLobbyService().GetServers( inputValues );
		}
		else
		{
			DebugPrint.LogErrorAndTrace( "BiosClientServices Error: Service reference does not exist." );
		}
	}

	static void GetFavoriteServers(TStringArray favServers)
	{
		m_ClientServices.GetLobbyService().GetFavoriteServers(favServers);
	}
	
	static void GetCachedFavServerInfo(array<ref CachedServerInfo> favServersInfoCache)
	{
		m_ClientServices.GetLobbyService().GetCachedFavoriteServerInfo(favServersInfoCache);
	}
	
	static void SetServerFavorited(string ipAddress, int port, int steamQueryPort, bool is_favorited )
	{
		GetClientServices();
		if ( m_ClientServices )
		{
			if ( is_favorited )
			{
				m_ClientServices.GetLobbyService().AddServerFavorite( ipAddress, port, steamQueryPort );
			}
			else
			{
				m_ClientServices.GetLobbyService().RemoveServerFavorite( ipAddress, port, steamQueryPort );
			}
		}
		else
		{
			DebugPrint.LogErrorAndTrace( "BiosClientServices Error: Service reference does not exist." );
		}
	}
	
	static void GetCurrentServerInfo( string ip, int port )
	{
		GetClientServices();
		
		m_CurrentServerIP = ip;
		m_CurrentServerPort = port;
		
		GetServersInput inputValues = new GetServersInput;
		
		inputValues.SetHostIp( ip );
		inputValues.SetHostPort( port );
		inputValues.m_Page = 0;
		inputValues.m_RowsPerPage = 10;
		inputValues.m_Platform = 1;

		#ifdef PLATFORM_XBOX
			inputValues.m_Platform = 2;
		#endif
		#ifdef PLATFORM_PS4
			inputValues.m_Platform = 3;
		#endif
		
		if ( m_ClientServices )
		{
			m_ClientServices.GetLobbyService().GetServers( inputValues );
		}
	}
	
	static GetServersResultRow GetCurrentServerInfo()
	{
		if (m_CurrentServerInfo)
			return m_CurrentServerInfo;
		else
			return g_Game.GetHostData();
	}
	
	static void ClearCurrentServerInfo()
	{
		m_CurrentServerInfo	= null;
		m_CurrentServerIP	= "";
		m_CurrentServerPort	= 0;
	}
	
	static void SetInviteServerInfo( string ip, int port )
	{
		m_InviteServerIP = ip;
		m_InviteServerPort = port;
	}
	
	static void GetInviteServerInfo( out string ip, out int port )
	{
		ip = m_InviteServerIP;
		port = m_InviteServerPort;
	}
	
	static void OnLoadServersAsync( GetServersResult result_list, EBiosError error, string response )
	{
		if ( !ErrorCaught( error ) )
		{
			if ( m_CurrentServerIP != "" && m_CurrentServerPort > 0 )
			{
				foreach ( GetServersResultRow result : result_list.m_Results )
				{
					if ( result.m_HostIp == m_CurrentServerIP && result.m_HostPort == m_CurrentServerPort )
					{
						m_CurrentServerInfo	= result;
						m_CurrentServerIP	= "";
						m_CurrentServerPort	= 0;
					}
				}
			}
			
			// todo: remove
			//foreach( GetServersResultRow res : result_list.m_Results )
			//{
			//	Print("OnLoadServersAsync: result id: " + res.m_Id + "modded: " + res.m_Modded);
			//}
			
			// just for example execute the retrieving of extended info for the first server entry in the list
			//if (result_list.m_Results.Count() > 0)
			//{
				//GetServersResultRow re = result_list.m_Results[0];
				//EBiosError er = m_ClientServices.GetLobbyService().GetServerModList(re.m_Id);
				//Print("OnLoadServersAsync GetServerModList returns:" + er);
			//}
			
			m_ServersAsyncInvoker.Invoke( result_list, error, response );
		}
		else
		{
			m_ServersAsyncInvoker.Invoke( null, error, "" );
		}
	}

	
	static void LoadFriends()
	{
		GetClientServices();
		if ( m_ClientServices )
		{
			m_ClientServices.GetSocialService().GetFriendsAsync();
		}
		else
		{
			DebugPrint.LogErrorAndTrace( "BiosClientServices Error: Service reference does not exist." );
		}
	}
	
	static void ShowUserProfile( string uid )
	{
		GetClientServices();
		if ( m_ClientServices )
		{
			m_ClientServices.GetSocialService().ShowUserProfileAsync( uid );
		}
		else
		{
			DebugPrint.LogErrorAndTrace( "BiosClientServices Error: Service reference does not exist." );
		}
	}
	
	static void OnUserProfileAsync(EBiosError error)
	{
		ErrorCaught( error );
	}
	
	static void OnFriendsAsync( BiosFriendInfoArray friend_list, EBiosError error )
	{
		if ( !ErrorCaught( error ) )
		{
			m_FriendsAsyncInvoker.Invoke( friend_list );
			
			array<string> friends_simple = new array<string>;
			for ( int i = 0; i < friend_list.Count(); ++i )
			{
				string uid = friend_list[i].m_Uid;
				BiosFriendInfo storedBfi = m_FriendsList[uid];
				BiosFriendInfo newBfi = friend_list[i];
				
				if (storedBfi)
				{
					if ( !BiosFriendInfo.Compare( storedBfi, newBfi ) )
					{
						friends_simple.Insert( newBfi.m_Uid );
					}
					m_FriendsList.Set( uid, newBfi );
				}
				else
				{
					m_FriendsList.Insert( uid, newBfi );
					friends_simple.Insert( newBfi.m_Uid );
				}
			}
			
			if ( !m_FirstFriendsLoad )
			{
				if ( ClientData.m_LastNewPlayers && ClientData.m_LastNewPlayers.m_PlayerList.Count() > 0 )
				{
					foreach ( SyncPlayer player : ClientData.m_LastNewPlayers.m_PlayerList )
					{
						if ( m_FriendsList.Contains( player.m_UID ) )
						{
							NotificationSystem.AddNotification( NotificationType.FRIEND_CONNECTED, NotificationSystem.DEFAULT_TIME_DISPLAYED, player.m_PlayerName + " " + "#ps4_invite_has_joined_your_session" );
						}
					}
					ClientData.m_LastNewPlayers.m_PlayerList.Clear();
				}
			}
			m_FirstFriendsLoad = false;
		}
	}
	
	static void LoadPermissions( array<string> player_list )
	{
		GetClientServices();
		if ( m_ClientServices )
		{
			array<EBiosPrivacyPermission> perms = new array<EBiosPrivacyPermission>;
			perms.Insert( EBiosPrivacyPermission.COMMUNICATE_VOICE );
			
			ErrorCaught( m_ClientServices.GetPrivacyService().GetPermissionsAsync( player_list, perms ) );
		}
		else
		{
			DebugPrint.LogErrorAndTrace( "BiosClientServices Error: Service reference does not exist." );
		}
	}
	
	static void OnPermissionsAsync( BiosPrivacyUidResultArray result_list, EBiosError error )
	{
		if ( !ErrorCaught( error ) )
		{
			BiosPrivacyUidResultArray new_list = new BiosPrivacyUidResultArray;
			
			for ( int i = 0; i < result_list.Count(); i++ )
			{
				BiosPrivacyUidResult result = result_list.Get( i );
				string uid = result.m_Uid;
				BiosPrivacyPermissionResultArray result_array = m_PermissionsList.Get( uid );
				BiosPrivacyPermissionResultArray result_array2 = result.m_Results;
				if ( result_array && result_array2 )
				{
					if ( !BiosPrivacyPermissionResult.Compare( result_array.Get( 0 ), result_array2.Get( 0 ) ) )
					{
						new_list.Insert( result );
						m_PermissionsList.Set( uid, result_array2 );
					}
				}
				else
				{
					m_PermissionsList.Insert( uid, result_array2 );
					new_list.Insert( result );
				}
			}
			m_PermissionsAsyncInvoker.Invoke( new_list );
		}
	}
	
	static bool IsPlayerMuted( string id )
	{
		if ( m_MuteList.Contains( id ) )
		{
			return m_MuteList.Get( id );
		}
		return false;
	}
	
	static bool MutePlayer( string id, bool mute )
	{
		if ( m_MuteList.Contains( id ) )
		{
			m_MuteList.Set( id, mute );
		}
		else
		{
			m_MuteList.Insert( id, mute );
		}
		
		// notify server
		ScriptInputUserData ctx = new ScriptInputUserData();
		ctx.Write( INPUT_UDT_USER_MUTE_XBOX );
		ctx.Write( id );
		ctx.Write( mute );
		ctx.Send();
		
		return true;
	}
	
	static map<string, bool> GetMuteList()
	{
		return m_MuteList;
	}
	
	static void ShowInviteScreen()
	{
		#ifdef PLATFORM_CONSOLE
			GetClientServices();
			if ( m_ClientServices )
			{
				string addr;
				int port;
				if ( GetGame().GetHostAddress( addr, port ) )
				{
					ErrorCaught( m_ClientServices.GetSessionService().ShowInviteToGameplaySessionAsync( addr, port ) );
				}
			}
			else
			{
				DebugPrint.LogErrorAndTrace( "BiosClientServices Error: Service reference does not exist." );
			}
		#endif
	}
	
	static void LoadMPPrivilege()
	{
		#ifdef PLATFORM_CONSOLE
			GetClientServices();
			if ( m_ClientServices )
			{
				ErrorCaught( m_ClientServices.GetPrivacyService().GetPrivilegeAsync( EBiosPrivacyPrivilege.MULTIPLAYER_GAMEPLAY, true ) );
			}
			else
			{
				DebugPrint.LogErrorAndTrace( "BiosClientServices Error: Service reference does not exist." );
			}
		#else
			OnLoadMPPrivilege( EBiosError.OK );
		#endif
	}
	
	static void LoadVoicePrivilege()
	{
		GetClientServices();
		if ( m_ClientServices )
		{
			ErrorCaught( m_ClientServices.GetPrivacyService().GetPrivilegeAsync( EBiosPrivacyPrivilege.COMMUNICATE_VOICE, true ) );
		}
		else
		{
			DebugPrint.LogErrorAndTrace( "BiosClientServices Error: Service reference does not exist." );
		}
	}
	
	static void OnLoadMPPrivilege( EBiosError err )
	{
		if ( !ErrorCaught( err ) )
		{
			g_Game.TryConnect();
		}
		else
		{
			if ( g_Game.GetGameState() != DayZGameState.MAIN_MENU )
			{
				g_Game.MainMenuLaunch();
			}
			else
			{
				g_Game.SetLoadState( DayZLoadState.MAIN_MENU_START );
				g_Game.GamepadCheck();
			}
		}
	}
	
	static void OnLoadVoicePrivilege( EBiosError err )
	{
		if ( g_Game.GetGameState() == DayZGameState.IN_GAME )
		{
			#ifdef PLATFORM_PS4
			GetGame().GetWorld().DisableReceiveVoN( ErrorCaught( err ) );
			#endif
			GetGame().GetWorld().DisableTransmitVoN( ErrorCaught( err ) );
		}
	}
	
	static void SetSessionHandle( string handle )
	{
		GetClientServices();
		if ( m_ClientServices )
		{
			m_ClientServices.GetSessionService().m_CurrentHandle = handle;
		}
	}
	
	static string GetSessionHandle()
	{
		GetClientServices();
		if ( m_ClientServices )
		{
			return m_ClientServices.GetSessionService().m_CurrentHandle;
		}
		return "";
	}
	
	static void GetSession()
	{
		GetClientServices();
		if ( m_ClientServices )
		{
			m_ClientServices.GetSessionService().TryGetSession( GetSessionHandle() );
		}
	}

	static BiosUser GetBiosUser()
	{
		return m_BiosUser;
	}

	static void SetBiosUser(BiosUser user)
	{
		m_BiosUser = user;
	}

	
	static bool GetMultiplayState()
	{
		return m_MultiplayState;
	}
	
	static void SetMultiplayState( bool state )
	{
		m_MultiplayState = state;
		bool is_multiplay;
		if ( ClientData.GetSimplePlayerList() )
			is_multiplay = state && ( ClientData.GetSimplePlayerList().Count() > 1 );

		if ( m_ClientServices )
			m_ClientServices.GetSessionService().SetMultiplayState(is_multiplay);
	}
	
	static void EnterGameplaySession()
	{
		string addr;
		int port;
		if ( GetGame().GetHostAddress( addr, port ) )
		{
			GetClientServices();
			if ( m_ClientServices )
			{
				m_ClientServices.GetSessionService().EnterGameplaySessionAsync( addr, port );
				SetMultiplayState(true);
			}
		}
	}
	
	static void LeaveGameplaySession()
	{
		GetClientServices();
		if ( m_ClientServices )
		{
			GetServersResultRow currentServerInfo = GetCurrentServerInfo();
			
			if ( currentServerInfo )
				m_ClientServices.GetSessionService().LeaveGameplaySessionAsync(currentServerInfo.m_HostIp, currentServerInfo.m_HostPort);
			else if ( m_CurrentServerIP != "" )
				m_ClientServices.GetSessionService().LeaveGameplaySessionAsync(m_CurrentServerIP, m_CurrentServerPort);
				
			SetMultiplayState(false);
			m_FirstFriendsLoad = true;
			
			if ( m_FriendsList )
				m_FriendsList.Clear();
		}
	}
	
	static void SetGameplayActivity()
	{
		string addr;
		int port;
		if ( GetGame().GetHostAddress( addr, port ) )
		{
			GetClientServices();
			if ( m_ClientServices )
			{
				m_ClientServices.GetSessionService().SetGameplayActivityAsync( addr, port );
			}
		}
	}
	
	static void SetPendingInviteList( array<string> invitees )
	{
		string addr;
		int port;
		if ( GetGame().GetHostAddress( addr, port ) )
		{
			GetClientServices();
			if ( m_ClientServices )
			{
				m_PendingInvites = invitees;
				m_ClientServices.GetSessionService().InviteToGameplaySessionAsync( addr, port, GetPendingInviteList() );
			}
		}
		else
		{
			m_PendingInvites = invitees;
		}
	}
	
	static array<string> GetPendingInviteList()
	{
		array<string> already_on_server = ClientData.GetSimplePlayerList();
		if ( already_on_server && m_PendingInvites )
		{
			array<string> new_to_server = new array<string>;
			foreach ( string invitee : m_PendingInvites )
			{
				if ( already_on_server.Find( invitee ) == -1 )
				{
					new_to_server.Insert( invitee );
				}
			}
			return new_to_server;
		}
		else
		{
			return m_PendingInvites;
		}
	}
	
	static void ClearPendingInviteList( array<string> invitees )
	{
		delete m_PendingInvites;
	}
	
	static int m_AutoConnectTries = 0;
	static void AutoConnectToEmptyServer()
	{
		GetClientServices();
		if ( m_ClientServices && m_AutoConnectTries == 0 )
		{
			m_AutoConnectTries = 1;
			GetFirstServerWithEmptySlotInput input = new GetFirstServerWithEmptySlotInput;
			input.SetOfficial( true );
			m_ClientServices.GetLobbyService().GetFirstServerWithEmptySlot( input );
		}
	}
	
	static GetServersResultRow GetRandomFreeResult( GetFirstServerWithEmptySlotResult results )
	{
		GetServersResultRow result;
		array<ref GetServersResultRow> results_free = new array<ref GetServersResultRow>;
		
		if ( results && results.m_Result && results.m_Result.m_Results && results.m_Result.m_Results.Count() > 0 )
		{
			foreach ( GetServersResultRow result_temp : results.m_Result.m_Results )
			{
				if ( result_temp.m_FreeSlots > 0 )
				{
					results_free.Insert( result_temp );
				}
			}
		}
		
		return results_free.GetRandomElement();
	}
	
	static void OnAutoConnectToEmptyServer( GetFirstServerWithEmptySlotResult result_list, EBiosError error )
	{
		if ( !ErrorCaught( error ) )
		{
			GetServersResultRow result = GetRandomFreeResult( result_list );
			if ( result )
			{
				g_Game.ConnectFromServerBrowser( result.m_HostIp, result.m_HostPort );
				m_AutoConnectTries = 0;
				return;
			}
			else
			{
				GetGame().GetUIManager().ShowDialog( "#str_xbox_authentification_fail_title", "#str_xbox_authentification_fail", 232, DBT_OK, DBB_NONE, DMT_INFO, GetGame().GetUIManager().GetMenu() );
			}
		}
		
		if ( m_AutoConnectTries < 3 )
		{
			m_AutoConnectTries++;
			GetFirstServerWithEmptySlotInput input = new GetFirstServerWithEmptySlotInput;
			input.SetOfficial( true );
			m_ClientServices.GetLobbyService().GetFirstServerWithEmptySlot( input );
		}
		else
		{
			GetGame().GetUIManager().ShowDialog( "#str_xbox_authentification_fail_title", "#xbox_authentification_fail", 232, DBT_OK, DBB_NONE, DMT_INFO, GetGame().GetUIManager().GetMenu() );
		}
	}
	
	static void GetServerModList( string server_id )
	{
		GetClientServices();
		if ( m_ClientServices )
		{
			m_ClientServices.GetLobbyService().GetServerModList( server_id );
		}
	}
	
	static void OnGetServerModList( GetServerModListResult result_list, EBiosError error )
	{
		if ( !ErrorCaught( error ) )
		{
			m_ServerModLoadAsyncInvoker.Invoke( result_list );
		}
	}
	
	static bool IsGameTrial( bool sim )
	{
		#ifdef PLATFORM_XBOX
		#ifndef PLATFORM_WINDOWS
		if ( m_TrialService )
			return m_TrialService.IsGameTrial( sim );
		#endif
		#endif
		return false;
	}
	
	static bool IsGameActive( bool sim )
	{
		#ifdef PLATFORM_XBOX
		#ifndef PLATFORM_WINDOWS
		if ( m_TrialService )
			return m_TrialService.IsGameActive( sim );
		#endif
		#endif
		return false;
	}
	
	static bool CheckUpdate()
	{
		GetClientServices();
		if ( m_ClientServices )
		{
			EBiosError error = m_ClientServices.GetPackageService().CheckUpdateAsync();
			
			if ( !error )
			{
				return true;
			}
		}
		
		return false;
	}
	
	static void PromptUpdate()
	{
		GetClientServices();
		if ( m_ClientServices )
		{
			m_ClientServices.GetPackageService().PromptUpdateAsync();
		}
	}
}