Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ServerConfigAdvancedComponent.c
Go to the documentation of this file.
2 {
3  protected const string HOST_LOCALY = "lan";
4  protected const string BIND_IP = "bindAddress";
5  protected const string BIND_PORT = "bindPort";
6  protected const string PUBLIC_IP = "publicAddress";
7  protected const string PUBLIC_PORT = "publicPort";
8 
9  protected SCR_WidgetListEntrySpinBox m_HostLocalyCheck;
10  protected SCR_WidgetListEntryEditBox m_PublicAddress;
11  protected SCR_WidgetListEntryEditBox m_PublicPortEdit;
12  protected SCR_WidgetListEntryEditBox m_BindPortEdit;
13 
14  protected bool m_bWasPortEdited = false;
15 
16  // Invokers
17  protected ref ScriptInvoker<string> m_OnPortChanged;
18 
19  //------------------------------------------------------------------------------------------------
20  ScriptInvoker GetOnPortChanged()
21  {
22  if (!m_OnPortChanged)
23  m_OnPortChanged = new ScriptInvoker();
24 
25  return m_OnPortChanged;
26  }
27 
28  //-------------------------------------------------------------------------------------------
29  override void HandlerAttached(Widget w)
30  {
31  super.HandlerAttached(w);
32 
33  // Find widges
34  m_PublicAddress = SCR_WidgetListEntryEditBox.Cast(FindEntry(PUBLIC_IP));
35 
36  m_HostLocalyCheck = SCR_WidgetListEntrySpinBox.Cast(FindEntry(HOST_LOCALY));
37  if (m_HostLocalyCheck)
38  m_HostLocalyCheck.GetSpinBox().m_OnChanged.Insert(OnHostLocalyChanged);
39 
40  m_PublicPortEdit = SCR_WidgetListEntryEditBox.Cast(FindEntry(PUBLIC_PORT));
41  if (m_PublicPortEdit)
42  m_PublicPortEdit.GetEditBoxComponent().m_OnChanged.Insert(OnPublicPortChanged);
43 
44  m_BindPortEdit = SCR_WidgetListEntryEditBox.Cast(FindEntry(BIND_PORT));
45  if (m_BindPortEdit)
46  m_BindPortEdit.GetEditBoxComponent().m_OnChanged.Insert(OnBindPortChanged);
47  }
48 
49  //-------------------------------------------------------------------------------------------
50  protected void OnHostLocalyChanged(SCR_SpinBoxComponent spinBox, int option)
51  {
52  bool selected = option == 1;
53 
54  // Set public ip to local
55  m_PublicAddress.SetInteractive(!selected);
56 
57  if (selected) // True
58  {
59  // Set public ip to local
60  m_PublicAddress.SetValue(SCR_WidgetEditFormatIP.LAN_VALUE);
61  }
62  else
63  {
64  // Clear public ip edit
65  m_PublicAddress.SetValue("");
66  }
67  }
68 
69  //-------------------------------------------------------------------------------------------
70  protected void OnBindPortChanged(SCR_EditBoxComponent edit, string text)
71  {
72  // Registed port edited
73  if (!m_bWasPortEdited && !text.IsEmpty())
74  {
75  m_bWasPortEdited = true;
76  }
77  else if (m_bWasPortEdited && text.IsEmpty())
78  {
79  m_bWasPortEdited = false;
80  }
81  }
82 
83  //-------------------------------------------------------------------------------------------
84  protected void OnPublicPortChanged(SCR_EditBoxComponent edit, string text)
85  {
86  // Edit bind by public port
87  if (!m_bWasPortEdited && m_BindPortEdit)
88  {
89  m_BindPortEdit.SetValue(text);
90  m_BindPortEdit.ClearInvalidInput();
91  }
92 
93  if (m_OnPortChanged)
94  m_OnPortChanged.Invoke(text);
95  }
96 
97  //-------------------------------------------------------------------------------------------
99  void FillFromDSConfig(notnull SCR_DSConfig config)
100  {
101  FindEntry(HOST_LOCALY).SetValue(SCR_JsonApiStructHandler.BoolToString(config.publicAddress == SCR_WidgetEditFormatIP.LAN_VALUE));
102  FindEntry(PUBLIC_IP).SetValue(config.publicAddress);
103  FindEntry(PUBLIC_PORT).SetValue(config.publicPort.ToString());
104  FindEntry(BIND_IP).SetValue(config.bindAddress);
105  FindEntry(BIND_PORT).SetValue(config.bindPort.ToString());
106  }
107 
108  //-------------------------------------------------------------------------------------------
109  void SetIPPort(DSConfig config)
110  {
111  FindEntry(PUBLIC_IP).SetValue(config.publicAddress);
112  FindEntry(PUBLIC_PORT).SetValue(config.publicPort.ToString());
113  FindEntry(BIND_IP).SetValue(config.bindAddress);
114  FindEntry(BIND_PORT).SetValue(config.bindPort.ToString());
115  }
116 
117  //-------------------------------------------------------------------------------------------
118  void SetPorts(string port)
119  {
120  m_PublicPortEdit.SetValue(port);
121  m_BindPortEdit.SetValue(port);
122  }
123 }
SCR_ConfigListComponent
Definition: SCR_ConfigListComponent.c:5
SCR_ServerConfigAdvancedComponent
Definition: SCR_ServerConfigAdvancedComponent.c:1
SCR_WidgetListEntryEditBox
Configurable widget list entry for various value that can be typed - numbers, strings,...
Definition: SCR_WidgetListEntry.c:333
SCR_JsonApiStructHandler
Handler for json api struct values.
Definition: SCR_JsonApiStructHandler.c:8
SCR_SpinBoxComponent
Definition: SCR_SpinBoxComponent.c:1
SCR_DSConfig
Definition: SCR_DSConfig.c:5
SCR_WidgetListEntrySpinBox
Configurable widget list entry selection specific for spinbox.
Definition: SCR_WidgetListEntry.c:772
SCR_EditBoxComponent
Definition: SCR_EditBoxComponent.c:8