Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_WidgetEditFormat.c
Go to the documentation of this file.
1 
5 //------------------------------------------------------------------------------------------------
6 [BaseContainerProps(configRoot: true)]
8 {
9  // String for storing message of current problem
10  // Useful when format has multiple state
11  protected string m_sFormatMessage;
12 
13  protected EditBoxFilterComponent m_EditBoxFilter;
14 
15  //------------------------------------------------------------------------------------------------
17  bool IsFormatValid(string str)
18  {
19 
20  }
21 
22  //------------------------------------------------------------------------------------------------
23  string GetFormatMessage()
24  {
25  return m_sFormatMessage;
26  }
27 
28  //------------------------------------------------------------------------------------------------
29  void SetEditBoxFilter(EditBoxFilterComponent filter)
30  {
31  m_EditBoxFilter = filter;
32  }
33 }
34 
35 //------------------------------------------------------------------------------------------------
37 [BaseContainerProps(configRoot: true)]
38 class SCR_WidgetEditFormatRange : SCR_WidgetEditFormat
39 {
40  [Attribute("0")]
41  protected int m_iMinRange;
42 
43  [Attribute("0")]
44  protected int m_iMaxRange;
45 
46  //------------------------------------------------------------------------------------------------
47  override bool IsFormatValid(string str)
48  {
49  return BellowMin(str) && OverMax(str);
50  }
51 
52  //------------------------------------------------------------------------------------------------
53  protected bool BellowMin(string str)
54  {
55  return str.Length() < m_iMinRange;
56  }
57 
58  //------------------------------------------------------------------------------------------------
59  protected bool OverMax(string str)
60  {
61  return str.Length() >= m_iMaxRange;
62  }
63 
64  //------------------------------------------------------------------------------------------------
65  int GetMinRange()
66  {
67  return m_iMinRange;
68  }
69 
70  //------------------------------------------------------------------------------------------------
71  int GetMaxRange()
72  {
73  return m_iMaxRange;
74  }
75 }
76 
77 //------------------------------------------------------------------------------------------------
79 [BaseContainerProps(configRoot: true)]
81 {
82  protected const string HINT_RANGE = "#AR-ServerHosting_ValidRangeHint";
83 
84  [Attribute("0")]
85  protected float m_fMinRange;
86 
87  [Attribute("0")]
88  protected float m_fMaxRange;
89 
90  //------------------------------------------------------------------------------------------------
91  override bool IsFormatValid(string str)
92  {
93  if (str.IsEmpty())
94  return false;
95 
96  float number = str.ToFloat();
97 
98  // Save check
99  if (number == 0 && str != "0")
100  return false;
101 
102  m_sFormatMessage = WidgetManager.Translate(HINT_RANGE, m_fMinRange.ToString(), m_fMaxRange.ToString());
103 
104  return (m_fMinRange <= number) && (number <= m_fMaxRange);
105  }
106 
107  //------------------------------------------------------------------------------------------------
108  void SetMaxRange(float max)
109  {
110  m_fMaxRange = max;
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  float GetMaxRange()
115  {
116  return m_fMaxRange;
117  }
118 
119 }
120 
121 //------------------------------------------------------------------------------------------------
123 [BaseContainerProps(configRoot: true)]
124 class SCR_WidgetEditFormatIP : SCR_WidgetEditFormat
125 {
126  static const string LAN_VALUE = "local";
127  protected static int ADDRESS_VALUES_COUNT = 4;
128 
129  protected const string HINT_RANGE = "#AR-ServerHosting_ValidRangeHint";
130  protected const string HINT_PRIVATE = "#AR-ServerHosting_PrivateIPHint";
131 
132  protected bool m_bIsValidated;
133  protected bool m_bIsPrivate;
134 
135  //------------------------------------------------------------------------------------------------
136  override bool IsFormatValid(string str)
137  {
138  m_bIsValidated = false;
139  m_sFormatMessage = WidgetManager.Translate(HINT_RANGE, "0.0.0.0", "255.255.255.255");
140 
141  if (str == string.Empty)
142  return false;
143 
144  // local string check
145  if (str == LAN_VALUE)
146  return true;
147 
148  // IP format check
149  array<string> values = new array<string>();
150  str.Split(".", values, true);
151  int valueCount = values.Count();
152 
153  // Count dots
154  int dots = 0;
155  for (int i = 0, len = str.Length(); i < len; i++)
156  {
157  if (str[i] == ".")
158  dots++;
159  }
160 
161  // 0.1.2.3 = 4 values
162  if (valueCount != 4 || dots != 3)
163  return false;
164 
165  int zeroElements = 0;
166 
167  // check if values are ok
168  for (int i = 0; i < 4; i++)
169  {
170  // Iterate through all tokens parsed between '.'
171  // if all of the characters are digit (ascii 48-57)
172  // it then checks if each value is within 0-255 range
173  // if anything fails, returns false
174  int strLen = values[i].Length();
175  for (int j = 0; j < strLen; j++)
176  {
177  // Check if it's a valid digit
178  string char = values[i].Get(j);
179  int asciiValue = char.ToAscii();
180  if (asciiValue >= 48 && asciiValue <= 57)
181  continue;
182  else
183  return false;
184  }
185 
186  int value = values[i].ToInt();
187  if (value == 0)
188  zeroElements++;
189 
190  if (value >= 0 && value <= 255)
191  continue;
192  else
193  return false;
194  }
195 
196  /*
197  m_bIsPrivate = IsPrivate(str);
198  if (m_bIsPrivate)
199  m_sFormatMessage = HINT_PRIVATE;
200  */
201 
202  m_bIsValidated = true;
203  return true;
204  }
205 
206  //------------------------------------------------------------------------------------------------
207  protected bool IsPrivate(string address)
208  {
209  int decAddress = AddressToDecimal(address, false);
210 
211  // Class A
212  if (IsAddressInRange(address, "10.0.0.0", "10.255.255.255", false))
213  return true;
214 
215  // CLass B
216  if (IsAddressInRange(address, "172.16.0.0", "172.31.255.255", false))
217  return true;
218 
219  // Class C
220  if (IsAddressInRange(address, "192.168.0.0", "192.168.255.255", false))
221  return true;
222 
223  return false;
224  }
225 
226  //------------------------------------------------------------------------------------------------
228  static bool IsAddressInRange(string address, string min, string max, bool validCheck = true)
229  {
230  int decAddress = AddressToDecimal(address, validCheck);
231  int decMin = AddressToDecimal(min, validCheck);
232  int decMax = AddressToDecimal(max, validCheck);
233 
234  return decMin <= decAddress && decAddress <= decMax;
235  }
236 
237  //------------------------------------------------------------------------------------------------
239  static int AddressToDecimal(string address, bool validCheck = true)
240  {
241  if (validCheck && !IsFormatValid(address))
242  return -1;
243 
244  int value = 0;
245 
246  array<string> values = new array<string>();
247  address.Split(".", values, true);
248 
249  // check if values are ok
250  for (int i = ADDRESS_VALUES_COUNT - 1; i >= 0; i--)
251  {
252  int decimal = Math.Pow(256, ADDRESS_VALUES_COUNT - i - 1);
253  decimal *= values[i].ToInt();
254 
255  value += decimal;
256  }
257 
258  return value;
259  }
260 
261  //------------------------------------------------------------------------------------------------
262  bool IsValidated()
263  {
264  return m_bIsValidated;
265  }
266 
267  //------------------------------------------------------------------------------------------------
268  bool IsPrivate()
269  {
270  return m_bIsPrivate;
271  }
272 }
273 
274 //------------------------------------------------------------------------------------------------
276 [BaseContainerProps(configRoot: true)]
277 class SCR_WidgetEditFormatName : SCR_WidgetEditFormatRange
278 {
279  protected const string HINT_SHORT = "#AR-ServerHosting_ShortTextWarning";
280  protected const string HINT_LONG = "";
281  protected const string HINT_WRONG_INPUT = "";
282 
283  //------------------------------------------------------------------------------------------------
284  override bool IsFormatValid(string str)
285  {
286  // Invalid input
287  if (!m_EditBoxFilter.IsLastInputValid())
288  {
289  m_sFormatMessage = HINT_WRONG_INPUT;
290  return false;
291  }
292 
293  // Min
294  if (BellowMin(str))
295  {
296  m_sFormatMessage = WidgetManager.Translate(HINT_SHORT, m_iMinRange);
297  return false;
298  }
299 
300  // Max
301  if (OverMax(str))
302  {
303  m_sFormatMessage = HINT_LONG;
304  return false;
305  }
306 
307  m_sFormatMessage = "";
308  return true;
309  }
310 }
m_EditBoxFilter
protected EditBoxFilterComponent m_EditBoxFilter
Definition: SCR_WidgetEditFormat.c:6
HINT_RANGE
const protected string HINT_RANGE
Definition: SCR_WidgetEditFormat.c:2
SCR_WidgetEditFormat
Definition: SCR_WidgetEditFormat.c:7
m_sFormatMessage
protected string m_sFormatMessage
Definition: SCR_WidgetEditFormat.c:4
GetMaxRange
float GetMaxRange()
Definition: SCR_WidgetEditFormat.c:34
SCR_WidgetEditFormatName
Format for name with specific messages and variable limitations.
Definition: SCR_WidgetEditFormat.c:277
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_fMaxRange
protected float m_fMaxRange
Definition: SCR_WidgetEditFormat.c:8
IsFormatValid
bool IsFormatValid(string str)
Method ready for overr to verifying that format is correct.
Definition: SCR_WidgetEditFormat.c:10
m_fMinRange
protected float m_fMinRange
Definition: SCR_WidgetEditFormat.c:5
BaseContainerProps
class SCR_WidgetEditFormat BaseContainerProps(configRoot:true)
Is string of count.
Definition: SCR_WidgetEditFormat.c:37
SCR_WidgetEditFormatNumberRange
Is string of count.
Definition: SCR_WidgetEditFormat.c:80
EditBoxFilterComponent
Definition: EditBoxFilterComponent.c:5