|  | 
| 4 | 4 | using TMPro; | 
| 5 | 5 | using Unity.BossRoom.ConnectionManagement; | 
| 6 | 6 | using Unity.BossRoom.Infrastructure; | 
|  | 7 | +using Unity.Networking.Transport; | 
| 7 | 8 | using UnityEngine; | 
| 8 | 9 | using VContainer; | 
| 9 | 10 | 
 | 
| @@ -171,13 +172,32 @@ public void CancelConnectingWindow() | 
| 171 | 172 |         } | 
| 172 | 173 | 
 | 
| 173 | 174 |         /// <summary> | 
| 174 |  | -        /// Sanitize user port InputField box allowing only alphanumerics and '.' | 
|  | 175 | +        /// Sanitize user IP address InputField box allowing only numbers and '.'. This also prevents undesirable | 
|  | 176 | +        /// invisible characters from being copy-pasted accidentally. | 
| 175 | 177 |         /// </summary> | 
| 176 | 178 |         /// <param name="dirtyString"> string to sanitize. </param> | 
| 177 | 179 |         /// <returns> Sanitized text string. </returns> | 
| 178 |  | -        public static string Sanitize(string dirtyString) | 
|  | 180 | +        public static string SanitizeIP(string dirtyString) | 
| 179 | 181 |         { | 
| 180 |  | -            return Regex.Replace(dirtyString, "[^A-Za-z0-9.]", ""); | 
|  | 182 | +            return Regex.Replace(dirtyString, "[^0-9.]", ""); | 
|  | 183 | +        } | 
|  | 184 | + | 
|  | 185 | +        /// <summary> | 
|  | 186 | +        /// Sanitize user port InputField box allowing only numbers. This also prevents undesirable invisible characters | 
|  | 187 | +        /// from being copy-pasted accidentally. | 
|  | 188 | +        /// </summary> | 
|  | 189 | +        /// <param name="dirtyString"> string to sanitize. </param> | 
|  | 190 | +        /// <returns> Sanitized text string. </returns> | 
|  | 191 | +        public static string SanitizePort(string dirtyString) | 
|  | 192 | +        { | 
|  | 193 | + | 
|  | 194 | +            return Regex.Replace(dirtyString, "[^0-9]", ""); | 
|  | 195 | +        } | 
|  | 196 | + | 
|  | 197 | +        public static bool AreIpAddressAndPortValid(string ipAddress, string port) | 
|  | 198 | +        { | 
|  | 199 | +            var portValid = ushort.TryParse(port, out var portNum); | 
|  | 200 | +            return portValid && NetworkEndPoint.TryParse(ipAddress, portNum, out var networkEndPoint); | 
| 181 | 201 |         } | 
| 182 | 202 |     } | 
| 183 | 203 | } | 
0 commit comments