Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
serverbrowserfiltercontainer.c
Go to the documentation of this file.
1 class ServerBrowserFilterContainer extends ScriptedWidgetEventHandler
2 {
3  ref map<string, string> m_Options = new map<string, string>;
4 
5  protected EditBoxWidget m_SearchByName;
6  protected EditBoxWidget m_SearchByIP;
7  ref OptionSelectorMultistate m_CharacterAliveFilter;
8  ref OptionSelectorMultistate m_SortingFilter;
9  ref OptionSelectorMultistate m_RegionFilter;
10  ref OptionSelectorMultistate m_PingFilter;
11  ref OptionSelector m_DLCFilter;
12  ref OptionSelector m_FavoritedFilter;
13  ref OptionSelector m_FriendsPlayingFilter;
14  ref OptionSelector m_BattleyeFilter; // DEPRECATED
15  ref OptionSelector m_PasswordFilter;
16  ref OptionSelector m_WhitelistFilter;
17  ref OptionSelector m_KeyboardFilter;
18  ref OptionSelector m_PreviouslyPlayedFilter;
19  ref OptionSelector m_VersionMatchFilter;
20  ref OptionSelector m_FullServerFilter;
21  ref OptionSelector m_ThirdPersonFilter;
22  ref OptionSelector m_PublicFilter; // DEPRECATED
23  ref OptionSelector m_AcceleratedTimeFilter; // DEPRECATED
24  protected ServerBrowserTab m_Tab;
25 
26  void ServerBrowserFilterContainer( Widget root, ServerBrowserTab parent )
27  {
28  string player_name;
29  GetGame().GetPlayerName( player_name );
30  m_Tab = parent;
31 
32  array<string> character_name_options ={ "#server_browser_disabled", player_name };
33  array<string> region_options = { "#server_browser_all", "#server_browser_americas", "#server_browser_europe", "#server_browser_asia" };
34  array<string> sort_options = { "#server_browser_column_host A-Z", "#server_browser_column_host Z-A", "#players_title >", "#players_title <" };
35  array<string> ping_options = { "#server_browser_disabled", "<30", "<50", "<100", "<200", "<300", "<500" };
36  array<string> two_options = { "#server_browser_disabled", "#server_browser_show" };
37 
38  m_SearchByName = EditBoxWidget.Cast( root.FindAnyWidget( "search_name_setting_option" ) );
39 
40  m_RegionFilter = new OptionSelectorMultistate( root.FindAnyWidget( "region_setting_option" ), 0, this, false, region_options );
41  m_PingFilter = new OptionSelectorMultistate( root.FindAnyWidget( "ping_setting_option" ), 0, this, false, ping_options );
42  #ifdef PLATFORM_CONSOLE
43  m_FavoritedFilter = new OptionSelectorMultistate( root.FindAnyWidget( "favorites_setting_option" ), 0, this, false, two_options );
44  #else
45  m_FavoritedFilter = new OptionSelector( root.FindAnyWidget( "favorites_setting_option" ), 0, this, false );
46  #endif
47 
48  m_DLCFilter = new OptionSelector( root.FindAnyWidget( "dlc_setting_option" ), 0, this, false );
49  m_FriendsPlayingFilter = new OptionSelector( root.FindAnyWidget( "friends_setting_option" ), 0, this, false );
50  m_PreviouslyPlayedFilter = new OptionSelector( root.FindAnyWidget( "prev_played_setting_option" ), 0, this, false );
51  m_FullServerFilter = new OptionSelector( root.FindAnyWidget( "full_server_setting_option" ), 0, this, false );
52  m_ThirdPersonFilter = new OptionSelector( root.FindAnyWidget( "tps_setting_option" ), 0, this, false );
53  m_PasswordFilter = new OptionSelector( root.FindAnyWidget( "password_setting_option" ), 0, this, false );
54  m_WhitelistFilter = new OptionSelector( root.FindAnyWidget( "whitelist_setting_option" ), 0, this, false );
55 
56  m_DLCFilter.m_OptionChanged.Insert( OnFilterChanged );
57  m_RegionFilter.m_OptionChanged.Insert( OnFilterChanged );
58  m_PingFilter.m_OptionChanged.Insert( OnFilterChanged );
59  m_FavoritedFilter.m_OptionChanged.Insert( OnFilterChanged );
60  m_FriendsPlayingFilter.m_OptionChanged.Insert( OnFilterChanged );
61  m_PreviouslyPlayedFilter.m_OptionChanged.Insert( OnFilterChanged );
62  m_FullServerFilter.m_OptionChanged.Insert( OnFilterChanged );
63  m_ThirdPersonFilter.m_OptionChanged.Insert( OnFilterChanged );
64  m_PasswordFilter.m_OptionChanged.Insert( OnFilterChanged );
65  m_WhitelistFilter.m_OptionChanged.Insert( OnFilterChanged );
66 
67  #ifdef PLATFORM_CONSOLE
68  m_SortingFilter = new OptionSelectorMultistate( root.FindAnyWidget( "sort_setting_option" ), 0, this, false, sort_options );
69  m_KeyboardFilter = new OptionSelector( root.FindAnyWidget( "keyboard_setting_option" ), 0, this, false );
70 
71  m_SortingFilter.m_OptionChanged.Insert( OnSortChanged );
72  m_SortingFilter.m_OptionChanged.Insert( OnFilterChanged );
73  m_KeyboardFilter.m_OptionChanged.Insert( OnFilterChanged );
74 
75  m_PingFilter.Disable();
76  m_FriendsPlayingFilter.Disable();
77  #endif
78 
79  #ifdef PLATFORM_WINDOWS
80  #ifndef PLATFORM_CONSOLE
81  m_SearchByIP = EditBoxWidget.Cast( root.FindAnyWidget( "search_ip_setting_option" ) );
82 
83  m_SearchByName.SetHandler( this );
84  m_SearchByIP.SetHandler( this );
85 
86  m_CharacterAliveFilter = new OptionSelectorMultistate( root.FindAnyWidget( "restrict_char_setting_option" ), 0, this, false, character_name_options );
87  m_VersionMatchFilter = new OptionSelector( root.FindAnyWidget( "ver_match_setting_option" ), 0, this, false );
88 
89  m_CharacterAliveFilter.m_OptionChanged.Insert( OnFilterChanged );
90  m_VersionMatchFilter.m_OptionChanged.Insert( OnFilterChanged );
91  #endif
92  #endif
93  LoadFilters();
94  }
95 
96  void OnFilterChanged()
97  {
98  m_Tab.OnFilterChanged();
99  }
100 
101  void LoadFilters()
102  {
103  string data;
104  if (m_Tab.GetTabType() == TabType.LAN || m_Tab.GetTabType() == TabType.FAVORITE)
105  return;
106 
107  GetGame().GetProfileString("SB_Filter_" + m_Tab.GetTabType(), data);
108 
109  m_Options.Clear();
110 
111  if (data != "")
112  {
113  string errorMessage;
114  if (!JsonFileLoader<ref map<string, string>>.LoadData(data, m_Options, errorMessage))
115  ErrorEx(errorMessage);
116  }
117 
118  if (m_Options && m_Options.Count() >= 6)
119  {
120  m_SearchByName.SetText( m_Options.Get( "m_SearchByName" ) );
121  m_DLCFilter.SetStringOption( m_Options.Get( "m_DLCFilter" ) );
122  m_RegionFilter.SetStringOption( m_Options.Get( "m_RegionFilter" ), false );
123  m_PingFilter.SetStringOption( m_Options.Get( "m_PingFilter" ), false );
124  m_FriendsPlayingFilter.SetStringOption( m_Options.Get( "m_FriendsPlayingFilter" ), false );
125  m_PreviouslyPlayedFilter.SetStringOption( m_Options.Get( "m_PreviouslyPlayedFilter" ), false );
126  m_FullServerFilter.SetStringOption( m_Options.Get( "m_FullServerFilter" ), false );
127  m_ThirdPersonFilter.SetStringOption( m_Options.Get( "m_ThirdPersonFilter" ), false );
128  m_PasswordFilter.SetStringOption( m_Options.Get( "m_PasswordFilter" ), false );
129  m_WhitelistFilter.SetStringOption( m_Options.Get( "m_WhitelistFilter" ), false );
130 
131  #ifdef PLATFORM_CONSOLE
132  m_SortingFilter.SetStringOption( m_Options.Get( "m_SortingFilter" ), false );
133  m_KeyboardFilter.SetStringOption( m_Options.Get( "m_KeyboardFilter" ), false );
134  #else
135  m_FavoritedFilter.SetStringOption( m_Options.Get( "m_FavoritedFilter" ), false );
136  #endif
137 
138  if (m_Options.Count() >= 12)
139  {
140  #ifdef PLATFORM_WINDOWS
141  #ifndef PLATFORM_CONSOLE
142  m_SearchByIP.SetText( m_Options.Get( "m_SearchByIP" ) );
143  m_CharacterAliveFilter.SetStringOption( m_Options.Get( "m_CharacterAliveFilter" ), false );
144  m_VersionMatchFilter.SetStringOption( m_Options.Get( "m_VersionMatchFilter" ), false );
145  #endif
146  #endif
147  }
148  }
149  }
150 
151  void SaveFilters()
152  {
153  m_Options.Clear();
154 
155  m_Options.Insert( "m_SearchByName", m_SearchByName.GetText() );
156  m_Options.Insert( "m_DLCFilter", m_DLCFilter.GetStringValue() );
157  m_Options.Insert( "m_RegionFilter", m_RegionFilter.GetStringValue() );
158  m_Options.Insert( "m_PingFilter", m_PingFilter.GetStringValue() );
159  m_Options.Insert( "m_FriendsPlayingFilter", m_FriendsPlayingFilter.GetStringValue() );
160  m_Options.Insert( "m_PreviouslyPlayedFilter", m_PreviouslyPlayedFilter.GetStringValue() );
161  m_Options.Insert( "m_FullServerFilter", m_FullServerFilter.GetStringValue() );
162  m_Options.Insert( "m_ThirdPersonFilter", m_ThirdPersonFilter.GetStringValue() );
163  m_Options.Insert( "m_PasswordFilter", m_PasswordFilter.GetStringValue() );
164  m_Options.Insert( "m_WhitelistFilter", m_WhitelistFilter.GetStringValue() );
165 
166  #ifdef PLATFORM_CONSOLE
167  m_Options.Insert( "m_SortingFilter", m_SortingFilter.GetStringValue() );
168  m_Options.Insert( "m_KeyboardFilter", m_KeyboardFilter.GetStringValue() );
169  #else
170  m_Options.Insert( "m_FavoritedFilter", m_FavoritedFilter.GetStringValue() );
171  #endif
172 
173  #ifdef PLATFORM_WINDOWS
174  #ifndef PLATFORM_CONSOLE
175  m_Options.Insert( "m_SearchByIP", m_SearchByIP.GetText() );
176  m_Options.Insert( "m_CharacterAliveFilter", m_CharacterAliveFilter.GetStringValue() );
177  m_Options.Insert( "m_VersionMatchFilter", m_VersionMatchFilter.GetStringValue() );
178  #endif
179  #endif
180 
181  string data, errorMessage;
182  if (!JsonFileLoader<ref map<string, string>>.MakeData(m_Options, data, errorMessage))
183  ErrorEx(errorMessage);
184 
185  GetGame().SetProfileString("SB_Filter_" + m_Tab.GetTabType(), data);
186  }
187 
188  void ResetFilters()
189  {
190  m_SearchByName.SetText( "" );
191  m_RegionFilter.Reset();
192  m_DLCFilter.Reset();
193  m_PingFilter.Reset();
194  m_FavoritedFilter.Reset();
195  m_FriendsPlayingFilter.Reset();
196  m_PreviouslyPlayedFilter.Reset();
197  m_FullServerFilter.Reset();
198  m_ThirdPersonFilter.Reset();
199  m_PasswordFilter.Reset();
200  m_WhitelistFilter.Reset();
201 
202  #ifdef PLATFORM_CONSOLE
203  m_SortingFilter.Reset();
204  m_KeyboardFilter.Reset();
205  #endif
206 
207  #ifdef PLATFORM_WINDOWS
208  #ifndef PLATFORM_CONSOLE
209  m_SearchByIP.SetText( "" );
210  m_CharacterAliveFilter.Reset();
211  m_VersionMatchFilter.Reset();
212  #endif
213  #endif
214  SaveFilters();
215  }
216 
217  bool PingIsSet()
218  {
219  return ( m_Options["m_PingFilter"] != m_PingFilter.GetOptions()[0] );
220  }
221 
222  bool FavoriteIsSet()
223  {
224  return ( m_Options["m_FavoritedFilter"] != m_FavoritedFilter.GetOptions()[0] );
225  }
226 
227  bool PreviouslyIsSet()
228  {
229  return ( m_Options["m_PreviouslyPlayedFilter"] != m_PreviouslyPlayedFilter.GetOptions()[0] );
230  }
231 
233  bool ProcessIntoIPAddress(out string potential_ip)
234  {
235  bool was_text_changed = false;
236  int length = potential_ip.Length();
237 
238  // Filter out incompatible characters
239  for ( int i = length - 1 ; i >= 0; --i )
240  {
241  string character = potential_ip.Get(i);
242 
243  if ( character.ToInt() == 0 && character != "0" && character != "." && character != ":" )
244  {
245  potential_ip = potential_ip.SubstringInverted(potential_ip, i, i + 1);
246  was_text_changed = true;
247  }
248  }
249 
250  bool text_was_shortened = LimitTextBoxCharacterCount( potential_ip, 21 );
251 
252  return (was_text_changed || text_was_shortened);
253  }
254 
256  bool LimitTextBoxCharacterCount( out string text, int max_length )
257  {
258  int length = text.Length();
259  bool was_text_changed = false;
260 
261  if ( length > max_length )
262  {
263  text = text.Substring(0, max_length);
264  was_text_changed = true;
265  }
266 
267  return was_text_changed;
268  }
269 
271  string GenerateValidIP(string potential_ip)
272  {
273  string correct_ip_format;
274 
275  TStringArray array_ip_and_port = new TStringArray;
276  potential_ip.Split( ":", array_ip_and_port );
277 
278  string ip_entries;
279  int port;
280 
281  if( array_ip_and_port.Count() > 0 )
282  {
283  ip_entries = array_ip_and_port.Get( 0 );
284  TStringArray array_ip = new TStringArray;
285  ip_entries.Split( ".", array_ip );
286 
287  string ip_string;
288  int ip_entries_count = array_ip.Count();
289 
290  if (ip_entries_count <= 3 || ip_entries_count > 4)
291  return "";
292 
293  for ( int i = 0; i < 4; i++ )
294  {
295  int ip_entry = array_ip.Get(i).ToInt();
296 
297  // Check if the entry is a valid number
298  if ( ip_entry > 255 || ip_entry < 0 )
299  ip_entry = 0;
300 
301  ip_string = ip_string + ip_entry.ToString();
302 
303  if ( i < ip_entries_count - 1 )
304  ip_string = ip_string + ".";
305  ;
306  }
307 
308  correct_ip_format = ip_string;
309  }
310  else
311  {
312  ip_entries = "";
313  correct_ip_format = ip_entries;
314  }
315 
316  if ( correct_ip_format == "" )
317  return ""; // Input string was not recognized as a valid IP address. Thus return an empty string.
318 
319  // The input string was recognized as a valid IP address. Thus continue with port number.
320 
321  if( array_ip_and_port.Count() > 1 )
322  {
323  port = array_ip_and_port.Get( 1 ).ToInt();
324 
325  if ( port > 65535 | port < 0 ) // max port value is 65535
326  port = 2302;
327 
328 
329  if ( port >= 0 )
330  correct_ip_format = correct_ip_format + ":" + port.ToString();
331 
332  }
333  else
334  {
335  port = 2302;
336  correct_ip_format = correct_ip_format + ":" + port.ToString();
337  }
338 
339  return correct_ip_format;
340  }
341 
343  bool GenerateValidFilter(out string potential_filter)
344  {
345  return LimitTextBoxCharacterCount( potential_filter, 16 );
346  }
347 
348  void OnSortChanged( int value )
349  {
350  switch( value )
351  {
352  case 0:
353  {
354  m_Tab.SetSort( ESortType.HOST, ESortOrder.ASCENDING );
355  break;
356  }
357  case 1:
358  {
359  m_Tab.SetSort( ESortType.HOST, ESortOrder.DESCENDING );
360  break;
361  }
362  case 2:
363  {
364  m_Tab.SetSort( ESortType.POPULATION, ESortOrder.DESCENDING );
365  break;
366  }
367  case 3:
368  {
369  m_Tab.SetSort( ESortType.POPULATION, ESortOrder.ASCENDING );
370  break;
371  }
372  }
373  }
374 
375  void Focus()
376  {
377  SetFocus( m_SearchByName );
378  /*
379  #ifdef PLATFORM_CONSOLE
380  m_SortingFilter.Focus();
381  #else
382  #ifdef PLATFORM_WINDOWS
383  SetFocus( m_SearchByName );
384  #endif
385  #endif
386  */
387  }
388 
389  override bool OnChange( Widget w, int x, int y, bool finished )
390  {
391  if( w )
392  {
393  if( w == m_SearchByName )
394  {
395  string input_name = m_SearchByName.GetText();
396 
397  if ( GenerateValidFilter( input_name ) )
398  m_SearchByName.SetText( input_name ); // Warning! Using SetText() causes the cursor to move at the end of the text box!
399 
400  OnFilterChanged();
401  SetFocus( m_SearchByName );
402 
403  return true;
404  }
405  else if( w == m_SearchByIP )
406  {
407  string input_ip = m_SearchByIP.GetText();
408 
409  if ( ProcessIntoIPAddress( input_ip ) )
410  m_SearchByIP.SetText( input_ip ); // Warning! Using SetText() causes the cursor to move at the end of the text box!
411 
412  OnFilterChanged();
413  SetFocus( m_SearchByIP );
414 
415  return true;
416  }
417  }
418  return false;
419  }
420 
421  override bool OnFocus( Widget w, int x, int y )
422  {
423  m_Tab.OnFilterFocus( w );
424  return false;
425  }
426 
427  override bool OnMouseEnter( Widget w, int x, int y )
428  {
429  return m_Tab.OnMouseEnter( w, x, y );
430  }
431 
432  override bool OnMouseLeave( Widget w, Widget enterW, int x, int y )
433  {
434  return m_Tab.OnMouseLeave( w, enterW, x, y );
435  }
436 
437  GetServersInput GetFilterOptionsPC()
438  {
439  GetServersInput input = new GetServersInput();
440 
441  input.m_RowsPerPage = SERVER_BROWSER_PAGE_SIZE;
442  input.m_Platform = 1;
443 
444  if (m_SearchByName)
445  {
446  string name_text = m_SearchByName.GetText();
447  if ( name_text != "" )
448  {
449  input.SetNameFilter( name_text);
450  }
451  }
452 
453  if (m_DLCFilter.IsSet())
454  {
455  input.SetIsDLC( m_DLCFilter.IsEnabled());
456  }
457 
458  if (m_FullServerFilter.IsSet())
459  {
460  input.SetFullServer( m_FullServerFilter.IsEnabled());
461  }
462 
463  if (m_ThirdPersonFilter.IsSet())
464  {
465  input.SetThirdPerson( m_ThirdPersonFilter.IsEnabled());
466  }
467 
468  if (m_PasswordFilter.IsSet())
469  {
470  input.SetPassworded( m_PasswordFilter.IsEnabled());
471  }
472 
473  if (m_WhitelistFilter.IsSet())
474  {
475  input.SetWhitelistEnabled( m_WhitelistFilter.IsEnabled());
476  }
477 
478  #ifndef PLATFORM_CONSOLE
479  if (m_SearchByIP)
480  {
481  string ip_text = m_SearchByIP.GetText();
482  if (ip_text != "")
483  {
484  input.SetHostIp( ip_text);
485  }
486  }
487 
488  if (m_PingFilter.IsSet())
489  {
490  string str_ping = m_PingFilter.GetStringValue();
491  int ping = str_ping.Substring(1, str_ping.Length() - 1).ToInt();
492  input.SetPingFilter( ping);
493  }
494 
495  if (m_FriendsPlayingFilter.IsSet())
496  {
497  input.SetFriendsPlaying( m_FriendsPlayingFilter.IsEnabled());
498  }
499 
500  if (m_PreviouslyPlayedFilter.IsSet())
501  {
502  input.SetPreviouslyPlayed( m_PreviouslyPlayedFilter.IsEnabled());
503  }
504 
505  if (m_VersionMatchFilter.IsSet())
506  {
507  input.SetProperVersionMatch( m_VersionMatchFilter.IsEnabled());
508  }
509  #endif
510 
511  return input;
512  }
513 
514  GetServersInput GetFilterOptionsConsoles()
515  {
516  GetServersInput input = new GetServersInput();
517 
518  input.m_RowsPerPage = SERVER_BROWSER_PAGE_SIZE;
519 
520  #ifdef PLATFORM_XBOX
521  input.m_Platform = 2;
522  #endif
523  #ifdef PLATFORM_PS4
524  input.m_Platform = 3;
525  #endif
526 
527  if (m_SearchByName)
528  {
529  string name_text = m_SearchByName.GetText();
530  if( name_text != "" )
531  {
532  input.SetNameFilter(name_text);
533  }
534  }
535 
536  if (m_RegionFilter.IsSet())
537  {
538  input.SetRegionIdFilter(m_RegionFilter.GetValue());
539  }
540 
541  if (m_DLCFilter.IsSet())
542  {
543  input.SetIsDLC(m_DLCFilter.IsEnabled());
544  }
545 
546  if (m_FullServerFilter.IsSet())
547  {
548  input.SetFullServer(m_FullServerFilter.IsEnabled());
549  if (m_FullServerFilter.IsEnabled())
550  {
551  input.SetFreeSlotsMax(1);
552  }
553  else
554  {
555  input.SetFreeSlotsMin(1);
556  }
557  }
558 
559  if (m_ThirdPersonFilter.IsSet())
560  {
561  // modeId is used to specify whether third person is allowed on CONSOLE servers
562  // ALLOW third person: modeId = 0
563  // BLOCK third person: modeId = 1
564  input.SetModeIdFilter(!m_ThirdPersonFilter.IsEnabled());
565  }
566 
567  if (m_PasswordFilter.IsSet())
568  {
569  input.SetIsPasswordProtectedFilter(m_PasswordFilter.IsEnabled());
570  }
571 
572  if (m_WhitelistFilter.IsSet())
573  {
574  input.SetWhitelistEnabled(m_WhitelistFilter.IsEnabled());
575  }
576 
577  if (m_KeyboardFilter.IsSet())
578  {
579  input.SetMouseAndKeyboardEnabled( m_KeyboardFilter.IsEnabled());
580  }
581 
582  return input;
583  }
584 }
GetGame
proto native CGame GetGame()
TabType
TabType
Definition: serverbrowsertab.c:1
Focus
void Focus()
Definition: serverbrowsertab.c:181
TStringArray
array< string > TStringArray
Definition: enscript.c:685
OptionSelector
Definition: optionselectormultistate.c:1
EditBoxWidget
Definition: enwidgets.c:353
y
Icon y
ErrorEx
enum ShapeType ErrorEx
OnMouseLeave
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition: uihintpanel.c:276
ESortType
ESortType
Definition: bioslobbyservice.c:6
map
map
Definition: controlsxboxnew.c:3
ServerBrowserTab
Definition: serverbrowsertabconsole.c:1
SERVER_BROWSER_PAGE_SIZE
const int SERVER_BROWSER_PAGE_SIZE
Definition: serverbrowsermenunew.c:6
ResetFilters
void ResetFilters()
Definition: serverbrowsertab.c:392
OnFilterChanged
void OnFilterChanged()
Definition: serverbrowsertab.c:202
ESortOrder
ESortOrder
Definition: bioslobbyservice.c:18
array< string >
SetFocus
proto native void SetFocus(Widget w)
x
Icon x
GetServersInput
GetServersInput the input structure of the GetServers operation.
Definition: bioslobbyservice.c:234
OnFocus
override bool OnFocus(Widget w, int x, int y)
Definition: serverbrowsertab.c:217
OnChange
bool OnChange(Widget w, int x, int y, bool finished)
Definition: huddebug.c:336
Widget
Definition: enwidgets.c:189
OnMouseEnter
override bool OnMouseEnter(Widget w, int x, int y)
Definition: uihintpanel.c:267
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650