11 protected string m_sFormatMessage;
17 bool IsFormatValid(
string str)
23 string GetFormatMessage()
41 protected int m_iMinRange;
44 protected int m_iMaxRange;
49 return BellowMin(str) && OverMax(str);
53 protected bool BellowMin(
string str)
55 return str.Length() < m_iMinRange;
59 protected bool OverMax(
string str)
61 return str.Length() >= m_iMaxRange;
82 protected const string HINT_RANGE =
"#AR-ServerHosting_ValidRangeHint";
85 protected float m_fMinRange;
88 protected float m_fMaxRange;
91 override bool IsFormatValid(
string str)
96 float number = str.ToFloat();
99 if (number == 0 && str !=
"0")
108 void SetMaxRange(
float max)
126 static const string LAN_VALUE =
"local";
127 protected static int ADDRESS_VALUES_COUNT = 4;
129 protected const string HINT_RANGE =
"#AR-ServerHosting_ValidRangeHint";
130 protected const string HINT_PRIVATE =
"#AR-ServerHosting_PrivateIPHint";
132 protected bool m_bIsValidated;
133 protected bool m_bIsPrivate;
138 m_bIsValidated =
false;
141 if (str ==
string.Empty)
145 if (str == LAN_VALUE)
149 array<string> values =
new array<string>();
150 str.Split(
".", values,
true);
151 int valueCount = values.Count();
155 for (
int i = 0, len = str.Length(); i < len; i++)
162 if (valueCount != 4 || dots != 3)
165 int zeroElements = 0;
168 for (
int i = 0; i < 4; i++)
174 int strLen = values[i].Length();
175 for (
int j = 0; j < strLen; j++)
178 string char = values[i].Get(j);
179 int asciiValue =
char.ToAscii();
180 if (asciiValue >= 48 && asciiValue <= 57)
186 int value = values[i].ToInt();
190 if (value >= 0 && value <= 255)
202 m_bIsValidated =
true;
207 protected bool IsPrivate(
string address)
209 int decAddress = AddressToDecimal(address,
false);
212 if (IsAddressInRange(address,
"10.0.0.0",
"10.255.255.255",
false))
216 if (IsAddressInRange(address,
"172.16.0.0",
"172.31.255.255",
false))
220 if (IsAddressInRange(address,
"192.168.0.0",
"192.168.255.255",
false))
228 static bool IsAddressInRange(
string address,
string min,
string max,
bool validCheck =
true)
230 int decAddress = AddressToDecimal(address, validCheck);
231 int decMin = AddressToDecimal(min, validCheck);
232 int decMax = AddressToDecimal(max, validCheck);
234 return decMin <= decAddress && decAddress <= decMax;
239 static int AddressToDecimal(
string address,
bool validCheck =
true)
246 array<string> values =
new array<string>();
247 address.Split(
".", values,
true);
250 for (
int i = ADDRESS_VALUES_COUNT - 1; i >= 0; i--)
252 int decimal = Math.Pow(256, ADDRESS_VALUES_COUNT - i - 1);
253 decimal *= values[i].ToInt();
264 return m_bIsValidated;
279 protected const string HINT_SHORT =
"#AR-ServerHosting_ShortTextWarning";
280 protected const string HINT_LONG =
"";
281 protected const string HINT_WRONG_INPUT =
"";
284 override bool IsFormatValid(
string str)