Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_WidgetEditFormat.c
Go to the documentation of this file.
4
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
14
15 //------------------------------------------------------------------------------------------------
17 bool IsFormatValid(string str)
18 {
19
20 }
21
22 //------------------------------------------------------------------------------------------------
24 {
25 return m_sFormatMessage;
26 }
27
28 //------------------------------------------------------------------------------------------------
30 {
31 m_EditBoxFilter = filter;
32 }
33}
34
35//------------------------------------------------------------------------------------------------
37[BaseContainerProps(configRoot: true)]
38class SCR_WidgetEditFormatRange : SCR_WidgetEditFormat
39{
40 [Attribute("0")]
41 protected int m_iMinRange;
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 //------------------------------------------------------------------------------------------------
115 {
116 return m_fMaxRange;
117 }
118
119}
120
121//------------------------------------------------------------------------------------------------
123[BaseContainerProps(configRoot: true)]
124class 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++)
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)]
277class 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 if (!m_EditBoxFilter)
287 return true;
288
289 // Invalid input
290 if (!m_EditBoxFilter.IsLastInputValid())
291 {
293 return false;
294 }
295
296 // Min
297 if (BellowMin(str))
298 {
299 m_sFormatMessage = WidgetManager.Translate(HINT_SHORT, m_iMinRange);
300 return false;
301 }
302
303 // Max
304 if (OverMax(str))
305 {
307 return false;
308 }
309
310 m_sFormatMessage = "";
311 return true;
312 }
313}
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
bool IsPrivate()
float GetMaxRange()
const string HINT_RANGE
string m_sFormatMessage
EditBoxFilterComponent m_EditBoxFilter
bool IsFormatValid(string str)
Method ready for overr to verifying that format is correct.
bool IsFormatValid(string str)
Method ready for overr to verifying that format is correct.
void SetEditBoxFilter(EditBoxFilterComponent filter)
EditBoxFilterComponent m_EditBoxFilter
Format for name with specific messages and variable limitations.
override bool IsFormatValid(string str)
override bool IsFormatValid(string str)
SCR_FieldOfViewSettings Attribute